From 690e562bf4aec0febbae48c16662e9ed5d2a5884 Mon Sep 17 00:00:00 2001 From: Deodate-Lawson Date: Sun, 30 Aug 2026 15:25:59 -0400 Subject: [PATCH 1/2] feat(artifacts): import and manage Claude artifacts in the workspace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new Claude Artifacts app at /employer/artifacts, modeled on the mindmap precedent: a company-scoped pdr_ai_v2_claude_artifacts table (content stored inline, 10 MB cap, soft delete), a companyId-scoped repository, and /api/artifacts routes behind requireWorkspaceContext. Import takes three routes: paste, file upload, or a server-side fetch of a public URL through the existing SSRF guard. claude.ai share links are refused up front with a structured 422 (code "claude_share_link") — the public artifact page is a client-rendered shell behind bot protection, so a server fetch can never capture the artifact; the dialog steers to paste/upload and keeps the link as sourceUrl provenance. Artifact type (html/svg/markdown/mermaid/react/code) and title are detected from the body by shared helpers in ~/lib/artifact-content. Viewing is the codebase's first untrusted-HTML surface: html/svg render in a srcDoc iframe sandboxed without allow-same-origin (scripts run in an opaque origin, cut off from the app session), markdown/mermaid render natively, react/code show as source. The raw download route serves attachment-only with a sandbox CSP. Management mirrors mindmaps: search, folders, star, inline rename, type override, trash/restore/purge, with Studio-menu and command-palette entries. Includes a /dev/artifacts harness (in-memory fetch stub, seeded types) following the dev-preview pattern, unit tests for the detection helpers, and route tests for the import endpoint. Co-Authored-By: Claude Fable 5 --- .../api/artifacts/artifacts-import.test.ts | 167 + .../__tests__/lib/artifact-content.test.ts | 109 + .../20260829203458_claude_artifacts.sql | 28 + .../drizzle/meta/20260829203458_snapshot.json | 7215 +++++++++++++++++ apps/web/drizzle/meta/_journal.json | 7 + .../src/app/api/artifacts/[id]/raw/route.ts | 69 + apps/web/src/app/api/artifacts/[id]/route.ts | 143 + apps/web/src/app/api/artifacts/route.ts | 188 + .../app/dev/artifacts/ArtifactsPreview.tsx | 237 + apps/web/src/app/dev/artifacts/page.tsx | 8 + .../src/app/employer/artifacts/[id]/page.tsx | 40 + .../employer/artifacts/_artifacts/lib/api.ts | 119 + .../_artifacts/ui/ArtifactGallery.tsx | 298 + .../_artifacts/ui/ArtifactPreview.tsx | 155 + .../_artifacts/ui/ArtifactViewer.tsx | 330 + .../_artifacts/ui/ImportArtifactDialog.tsx | 269 + .../artifacts/_artifacts/ui/artifact-meta.tsx | 43 + .../web/src/app/employer/artifacts/layout.tsx | 11 + apps/web/src/app/employer/artifacts/page.tsx | 17 + .../employer/documents/_workspace/types.ts | 17 +- apps/web/src/lib/artifact-content.ts | 113 + apps/web/src/lib/validation.ts | 41 + apps/web/src/server/artifacts/repository.ts | 143 + apps/web/src/server/db/schema/artifacts.ts | 88 + apps/web/src/server/db/schema/index.ts | 1 + 25 files changed, 9855 insertions(+), 1 deletion(-) create mode 100644 apps/web/__tests__/api/artifacts/artifacts-import.test.ts create mode 100644 apps/web/__tests__/lib/artifact-content.test.ts create mode 100644 apps/web/drizzle/20260829203458_claude_artifacts.sql create mode 100644 apps/web/drizzle/meta/20260829203458_snapshot.json create mode 100644 apps/web/src/app/api/artifacts/[id]/raw/route.ts create mode 100644 apps/web/src/app/api/artifacts/[id]/route.ts create mode 100644 apps/web/src/app/api/artifacts/route.ts create mode 100644 apps/web/src/app/dev/artifacts/ArtifactsPreview.tsx create mode 100644 apps/web/src/app/dev/artifacts/page.tsx create mode 100644 apps/web/src/app/employer/artifacts/[id]/page.tsx create mode 100644 apps/web/src/app/employer/artifacts/_artifacts/lib/api.ts create mode 100644 apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactGallery.tsx create mode 100644 apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactPreview.tsx create mode 100644 apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactViewer.tsx create mode 100644 apps/web/src/app/employer/artifacts/_artifacts/ui/ImportArtifactDialog.tsx create mode 100644 apps/web/src/app/employer/artifacts/_artifacts/ui/artifact-meta.tsx create mode 100644 apps/web/src/app/employer/artifacts/layout.tsx create mode 100644 apps/web/src/app/employer/artifacts/page.tsx create mode 100644 apps/web/src/lib/artifact-content.ts create mode 100644 apps/web/src/server/artifacts/repository.ts create mode 100644 apps/web/src/server/db/schema/artifacts.ts diff --git a/apps/web/__tests__/api/artifacts/artifacts-import.test.ts b/apps/web/__tests__/api/artifacts/artifacts-import.test.ts new file mode 100644 index 000000000..4459f35dd --- /dev/null +++ b/apps/web/__tests__/api/artifacts/artifacts-import.test.ts @@ -0,0 +1,167 @@ +import { POST } from "~/app/api/artifacts/route"; +import { db } from "~/server/db"; + +const mockRequireWorkspaceContext = jest.fn(); + +jest.mock("~/lib/require-workspace-context", () => ({ + ...jest.requireActual("~/lib/require-workspace-context"), + requireWorkspaceContext: () => mockRequireWorkspaceContext(), +})); + +// Rate limiting is exercised by its own tests; here it just passes through. +jest.mock("~/lib/rate-limit-middleware", () => ({ + withRateLimit: (_req: Request, _preset: unknown, handler: () => Promise) => handler(), +})); + +const mockAssertPublicHttpUrl = jest.fn(); +const mockFetchPublicUrl = jest.fn(); + +jest.mock("~/server/security/url-guard", () => { + class UrlGuardError extends Error {} + return { + UrlGuardError, + assertPublicHttpUrl: (url: string) => mockAssertPublicHttpUrl(url), + fetchPublicUrl: (url: string, init?: RequestInit) => mockFetchPublicUrl(url, init), + }; +}); + +jest.mock("~/server/db", () => ({ + db: { insert: jest.fn() }, +})); + +function mockCtx() { + mockRequireWorkspaceContext.mockResolvedValue({ + success: true, + data: { + authUserId: "user-123", + userPk: BigInt(7), + companyId: BigInt(42), + role: "owner", + status: "verified", + }, + }); +} + +/** Captures the inserted values and echoes them back as the returned row. */ +function mockInsert() { + let captured: Record = {}; + (db.insert as jest.Mock).mockReturnValue({ + values: jest.fn().mockImplementation((values: Record) => { + captured = values; + return { + returning: jest.fn().mockImplementation(() => + Promise.resolve([ + { + id: 1, + description: null, + updatedByUserId: null, + deletedAt: null, + starred: false, + createdAt: new Date(), + updatedAt: new Date(), + ...captured, + }, + ]) + ), + }; + }), + }); + return () => captured; +} + +function importRequest(body: unknown) { + return new Request("http://localhost/api/artifacts", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body), + }); +} + +describe("POST /api/artifacts", () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it("imports pasted content with a detected type and derived title", async () => { + mockCtx(); + const inserted = mockInsert(); + + const response = await POST( + importRequest({ + content: "Churn Report", + sourceUrl: "https://claude.ai/public/artifacts/abc", + }) + ); + const json = (await response.json()) as { artifact: { title: string } }; + + expect(response.status).toBe(201); + expect(json.artifact.title).toBe("Churn Report"); + const values = inserted(); + expect(values.companyId).toBe(BigInt(42)); + expect(values.createdByUserId).toBe("user-123"); + expect(values.artifactType).toBe("html"); + expect(values.importMethod).toBe("paste"); + expect(values.sourceUrl).toBe("https://claude.ai/public/artifacts/abc"); + expect(values.contentHash).toMatch(/^[0-9a-f]{64}$/); + expect(mockFetchPublicUrl).not.toHaveBeenCalled(); + }); + + it("refuses to fetch claude.ai share links with a structured 422", async () => { + mockCtx(); + + const response = await POST( + importRequest({ + fetchFromUrl: true, + sourceUrl: "https://claude.ai/public/artifacts/abc", + }) + ); + const json = (await response.json()) as { code?: string }; + + expect(response.status).toBe(422); + expect(json.code).toBe("claude_share_link"); + expect(mockFetchPublicUrl).not.toHaveBeenCalled(); + expect(db.insert).not.toHaveBeenCalled(); + }); + + it("fetches other URLs through the SSRF guard", async () => { + mockCtx(); + const inserted = mockInsert(); + mockAssertPublicHttpUrl.mockResolvedValue(new URL("https://example.com/page")); + mockFetchPublicUrl.mockResolvedValue( + new Response("Docs", { + status: 200, + headers: { "Content-Type": "text/html" }, + }) + ); + + const response = await POST( + importRequest({ fetchFromUrl: true, sourceUrl: "https://example.com/page" }) + ); + + expect(response.status).toBe(201); + expect(mockAssertPublicHttpUrl).toHaveBeenCalledWith("https://example.com/page"); + expect(mockFetchPublicUrl).toHaveBeenCalled(); + expect(inserted().importMethod).toBe("url"); + }); + + it("rejects a body with neither content nor a fetchable URL", async () => { + mockCtx(); + + const response = await POST(importRequest({ title: "No body" })); + + expect(response.status).toBe(400); + expect(db.insert).not.toHaveBeenCalled(); + }); + + it("passes the workspace-context failure response through", async () => { + mockRequireWorkspaceContext.mockResolvedValue({ + success: false, + response: new Response(JSON.stringify({ error: "Unauthorized" }), { status: 401 }), + }); + + const response = await POST(importRequest({ content: "# hi" })); + + expect(response.status).toBe(401); + expect(db.insert).not.toHaveBeenCalled(); + }); +}); diff --git a/apps/web/__tests__/lib/artifact-content.test.ts b/apps/web/__tests__/lib/artifact-content.test.ts new file mode 100644 index 000000000..66200e348 --- /dev/null +++ b/apps/web/__tests__/lib/artifact-content.test.ts @@ -0,0 +1,109 @@ +import { + artifactFileExtension, + artifactSearchText, + deriveArtifactTitle, + detectArtifactType, + isClaudeHostedUrl, +} from "~/lib/artifact-content"; + +describe("detectArtifactType", () => { + it("classifies full HTML documents by prefix", () => { + expect(detectArtifactType("hi")).toBe("html"); + expect(detectArtifactType(" ")).toBe("html"); + }); + + it("classifies fragments with structural tags as html", () => { + expect(detectArtifactType('
')).toBe("html"); + }); + + it("classifies svg, including with an xml prolog", () => { + expect(detectArtifactType('')).toBe("svg"); + expect(detectArtifactType('\n')).toBe("svg"); + }); + + it("classifies mermaid sources, including with an init directive", () => { + expect(detectArtifactType("flowchart TD\n A --> B")).toBe("mermaid"); + expect(detectArtifactType("sequenceDiagram\n A->>B: hi")).toBe("mermaid"); + expect(detectArtifactType("%%{init: {'theme':'dark'}}%%\ngraph LR\nA-->B")).toBe("mermaid"); + }); + + it("classifies React components", () => { + expect( + detectArtifactType('import React from "react";\nexport default function App() {}') + ).toBe("react"); + expect( + detectArtifactType('export default function App() {\n return ;\n}') + ).toBe("react"); + }); + + it("classifies plain code without markup", () => { + expect(detectArtifactType("def main():\n print('hi')")).toBe("code"); + expect(detectArtifactType("const x = 1;\nconsole.log(x);")).toBe("code"); + }); + + it("falls back to markdown for prose", () => { + expect(detectArtifactType("# Design review\n\nSome *notes* here.")).toBe("markdown"); + expect(detectArtifactType("Just a paragraph of text.")).toBe("markdown"); + }); +}); + +describe("deriveArtifactTitle", () => { + it("uses for html", () => { + expect( + deriveArtifactTitle( + "<html><head><title> Churn Dashboard ", + "html" + ) + ).toBe("Churn Dashboard"); + }); + + it("falls back to

for html without a title", () => { + expect(deriveArtifactTitle("

Quarterly Plan

", "html")).toBe( + "Quarterly Plan" + ); + }); + + it("uses the first heading for markdown", () => { + expect(deriveArtifactTitle("intro\n\n## Roadmap\n\nbody", "markdown")).toBe("Roadmap"); + }); + + it("returns null when nothing usable exists", () => { + expect(deriveArtifactTitle("plain text", "markdown")).toBeNull(); + expect(deriveArtifactTitle("
x
", "html")).toBeNull(); + }); +}); + +describe("isClaudeHostedUrl", () => { + it("matches claude.ai and subdomains", () => { + expect(isClaudeHostedUrl("https://claude.ai/public/artifacts/abc")).toBe(true); + expect(isClaudeHostedUrl("https://www.claude.ai/code/artifact/abc")).toBe(true); + expect(isClaudeHostedUrl("https://claude.site/artifacts/abc")).toBe(true); + }); + + it("rejects other hosts, including look-alikes", () => { + expect(isClaudeHostedUrl("https://example.com/page")).toBe(false); + expect(isClaudeHostedUrl("https://notclaude.ai/artifacts")).toBe(false); + expect(isClaudeHostedUrl("https://claude.ai.evil.com/x")).toBe(false); + expect(isClaudeHostedUrl("not a url")).toBe(false); + }); +}); + +describe("artifactSearchText", () => { + it("strips scripts, styles, and tags", () => { + const text = artifactSearchText( + "

Hello

world

" + ); + expect(text).toBe("Hello world"); + }); +}); + +describe("artifactFileExtension", () => { + it("maps each type to a sensible extension", () => { + expect(artifactFileExtension("html")).toBe("html"); + expect(artifactFileExtension("svg")).toBe("svg"); + expect(artifactFileExtension("markdown")).toBe("md"); + expect(artifactFileExtension("mermaid")).toBe("mmd"); + expect(artifactFileExtension("react")).toBe("tsx"); + expect(artifactFileExtension("code")).toBe("txt"); + }); +}); diff --git a/apps/web/drizzle/20260829203458_claude_artifacts.sql b/apps/web/drizzle/20260829203458_claude_artifacts.sql new file mode 100644 index 000000000..2306be4b0 --- /dev/null +++ b/apps/web/drizzle/20260829203458_claude_artifacts.sql @@ -0,0 +1,28 @@ +CREATE TABLE "pdr_ai_v2_claude_artifacts" ( + "id" bigserial PRIMARY KEY NOT NULL, + "company_id" bigint NOT NULL, + "created_by_user_id" varchar(256) NOT NULL, + "updated_by_user_id" varchar(256), + "title" varchar(300) NOT NULL, + "description" text, + "folder" varchar(256) DEFAULT 'Unfiled' NOT NULL, + "artifact_type" varchar(32) DEFAULT 'html' NOT NULL, + "source_url" varchar(2048), + "import_method" varchar(32) DEFAULT 'paste' NOT NULL, + "content" text NOT NULL, + "size_bytes" integer DEFAULT 0 NOT NULL, + "content_hash" varchar(64) DEFAULT '' NOT NULL, + "search_text" text, + "starred" boolean DEFAULT false NOT NULL, + "deleted_at" timestamp with time zone, + "opened_at" timestamp with time zone, + "created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + "updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL +); +--> statement-breakpoint +ALTER TABLE "pdr_ai_v2_claude_artifacts" ADD CONSTRAINT "pdr_ai_v2_claude_artifacts_company_id_pdr_ai_v2_company_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."pdr_ai_v2_company"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "claude_artifacts_company_idx" ON "pdr_ai_v2_claude_artifacts" USING btree ("company_id");--> statement-breakpoint +CREATE INDEX "claude_artifacts_company_updated_idx" ON "pdr_ai_v2_claude_artifacts" USING btree ("company_id","updated_at");--> statement-breakpoint +CREATE INDEX "claude_artifacts_creator_idx" ON "pdr_ai_v2_claude_artifacts" USING btree ("created_by_user_id");--> statement-breakpoint +CREATE INDEX "claude_artifacts_folder_idx" ON "pdr_ai_v2_claude_artifacts" USING btree ("company_id","folder");--> statement-breakpoint +CREATE INDEX "claude_artifacts_deleted_idx" ON "pdr_ai_v2_claude_artifacts" USING btree ("deleted_at"); \ No newline at end of file diff --git a/apps/web/drizzle/meta/20260829203458_snapshot.json b/apps/web/drizzle/meta/20260829203458_snapshot.json new file mode 100644 index 000000000..fd43cba36 --- /dev/null +++ b/apps/web/drizzle/meta/20260829203458_snapshot.json @@ -0,0 +1,7215 @@ +{ + "id": "46000df2-a740-49b1-98be-4345c6df17fc", + "prevId": "46f8505e-5fc0-4deb-9653-fe98a9734ecd", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.pdr_ai_v2_agent_ai_chatbot_chat": { + "name": "pdr_ai_v2_agent_ai_chatbot_chat", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'private'" + }, + "agent_mode": { + "name": "agent_mode", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'interactive'" + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "ai_style": { + "name": "ai_style", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'concise'" + }, + "ai_persona": { + "name": "ai_persona", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'general'" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_document": { + "name": "pdr_ai_v2_agent_ai_chatbot_document", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'text'" + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "task_id": { + "name": "task_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_document_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_document_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_document", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_agent_ai_chatbot_document_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_document_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_document", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_task", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pdr_ai_v2_agent_ai_chatbot_document_id_created_at_pk": { + "name": "pdr_ai_v2_agent_ai_chatbot_document_id_created_at_pk", + "columns": [ + "id", + "created_at" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_execution_step": { + "name": "pdr_ai_v2_agent_ai_chatbot_execution_step", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "step_number": { + "name": "step_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "step_type": { + "name": "step_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reasoning": { + "name": "reasoning", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "agent_execution_step_task_step_idx": { + "name": "agent_execution_step_task_step_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "step_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_execution_step_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_execution_step_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_execution_step", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_task", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_memory": { + "name": "pdr_ai_v2_agent_ai_chatbot_memory", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "memory_type": { + "name": "memory_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "importance": { + "name": "importance", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5 + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "accessed_at": { + "name": "accessed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "agent_memory_chat_idx": { + "name": "agent_memory_chat_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agent_memory_chat_type_idx": { + "name": "agent_memory_chat_type_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "memory_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_memory_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_memory_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_memory", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_message": { + "name": "pdr_ai_v2_agent_ai_chatbot_message", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "message_type": { + "name": "message_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'text'" + }, + "parent_message_id": { + "name": "parent_message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_message_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_message_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_message", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_suggestion": { + "name": "pdr_ai_v2_agent_ai_chatbot_suggestion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "document_created_at": { + "name": "document_created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "original_text": { + "name": "original_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "suggested_text": { + "name": "suggested_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_resolved": { + "name": "is_resolved", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_suggestion_document_id_document_created_at_pdr_ai_v2_agent_ai_chatbot_document_id_created_at_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_suggestion_document_id_document_created_at_pdr_ai_v2_agent_ai_chatbot_document_id_created_at_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_suggestion", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_document", + "columnsFrom": [ + "document_id", + "document_created_at" + ], + "columnsTo": [ + "id", + "created_at" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_task": { + "name": "pdr_ai_v2_agent_ai_chatbot_task", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "objective": { + "name": "objective", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_task_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_task_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_task", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_tool_call": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_call", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "tool_name": { + "name": "tool_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "tool_input": { + "name": "tool_input", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "tool_output": { + "name": "tool_output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "execution_time_ms": { + "name": "execution_time_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_tool_call_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_call_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_tool_call", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_agent_ai_chatbot_tool_call_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_call_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_tool_call", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_task", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_tool_registry": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_registry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "schema": { + "name": "schema", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "is_enabled": { + "name": "is_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "required_permissions": { + "name": "required_permissions", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "rate_limit": { + "name": "rate_limit", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pdr_ai_v2_agent_ai_chatbot_tool_registry_name_unique": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_registry_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_vote": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote", + "schema": "", + "columns": { + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "is_upvoted": { + "name": "is_upvoted", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "feedback": { + "name": "feedback", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_vote", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_agent_ai_chatbot_vote_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_vote", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_message_id_pk": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_message_id_pk", + "columns": [ + "chat_id", + "message_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_claude_artifacts": { + "name": "pdr_ai_v2_claude_artifacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "updated_by_user_id": { + "name": "updated_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "folder": { + "name": "folder", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "'Unfiled'" + }, + "artifact_type": { + "name": "artifact_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'html'" + }, + "source_url": { + "name": "source_url", + "type": "varchar(2048)", + "primaryKey": false, + "notNull": false + }, + "import_method": { + "name": "import_method", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'paste'" + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "content_hash": { + "name": "content_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "search_text": { + "name": "search_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "starred": { + "name": "starred", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "opened_at": { + "name": "opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "claude_artifacts_company_idx": { + "name": "claude_artifacts_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_company_updated_idx": { + "name": "claude_artifacts_company_updated_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_creator_idx": { + "name": "claude_artifacts_creator_idx", + "columns": [ + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_folder_idx": { + "name": "claude_artifacts_folder_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "folder", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_deleted_idx": { + "name": "claude_artifacts_deleted_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_claude_artifacts_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_claude_artifacts_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_claude_artifacts", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_account": { + "name": "pdr_ai_v2_auth_account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "issuer": { + "name": "issuer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_account_user_id_idx": { + "name": "auth_account_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_account_issuer_account_idx": { + "name": "auth_account_issuer_account_idx", + "columns": [ + { + "expression": "issuer", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_account_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_account_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_account", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_session": { + "name": "pdr_ai_v2_auth_session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_session_token_unique": { + "name": "auth_session_token_unique", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_session_user_id_idx": { + "name": "auth_session_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_session_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_session_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_session", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_user": { + "name": "pdr_ai_v2_auth_user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_user_email_unique": { + "name": "auth_user_email_unique", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_verification": { + "name": "pdr_ai_v2_auth_verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_verification_identifier_idx": { + "name": "auth_verification_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_agent_persona": { + "name": "pdr_ai_v2_collab_agent_persona", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "system_prompt": { + "name": "system_prompt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "node_id": { + "name": "node_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "route": { + "name": "route", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "temperature_x100": { + "name": "temperature_x100", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "max_turn_chars": { + "name": "max_turn_chars", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "accent": { + "name": "accent", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "collab_persona_company_key_idx": { + "name": "collab_persona_company_key_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_agent_persona_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_agent_persona_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_agent_persona", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_channel": { + "name": "pdr_ai_v2_collab_channel", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "varchar(96)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "topic": { + "name": "topic", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "collab_channel_company_slug_idx": { + "name": "collab_channel_company_slug_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "collab_channel_company_idx": { + "name": "collab_channel_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_channel_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_channel_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_channel", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_meeting": { + "name": "pdr_ai_v2_collab_meeting", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "objective": { + "name": "objective", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agenda": { + "name": "agenda", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "participants": { + "name": "participants", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "turn_policy": { + "name": "turn_policy", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'round_robin'" + }, + "moderator_persona_id": { + "name": "moderator_persona_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "max_turns": { + "name": "max_turns", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 12 + }, + "completion_marker": { + "name": "completion_marker", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'scheduled'" + }, + "turn_index": { + "name": "turn_index", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_speaker_id": { + "name": "next_speaker_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "controller": { + "name": "controller", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "slack_mirror_enabled": { + "name": "slack_mirror_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "slack_use_agent_identity": { + "name": "slack_use_agent_identity", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "collab_meeting_company_idx": { + "name": "collab_meeting_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "collab_meeting_channel_idx": { + "name": "collab_meeting_channel_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_meeting_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_meeting_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_meeting", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_collab_meeting_channel_id_pdr_ai_v2_collab_channel_id_fk": { + "name": "pdr_ai_v2_collab_meeting_channel_id_pdr_ai_v2_collab_channel_id_fk", + "tableFrom": "pdr_ai_v2_collab_meeting", + "tableTo": "pdr_ai_v2_collab_channel", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_message": { + "name": "pdr_ai_v2_collab_message", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "author_kind": { + "name": "author_kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "author_name": { + "name": "author_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "on_behalf_of_persona_id": { + "name": "on_behalf_of_persona_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'chat'" + }, + "thread_id": { + "name": "thread_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "slack_ts": { + "name": "slack_ts", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "meta": { + "name": "meta", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "collab_message_channel_seq_idx": { + "name": "collab_message_channel_seq_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "collab_message_channel_created_idx": { + "name": "collab_message_channel_created_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_message_channel_id_pdr_ai_v2_collab_channel_id_fk": { + "name": "pdr_ai_v2_collab_message_channel_id_pdr_ai_v2_collab_channel_id_fk", + "tableFrom": "pdr_ai_v2_collab_message", + "tableTo": "pdr_ai_v2_collab_channel", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_node": { + "name": "pdr_ai_v2_collab_node", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "persona_ids": { + "name": "persona_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_remote_address": { + "name": "last_remote_address", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "collab_node_company_idx": { + "name": "collab_node_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_node_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_node_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_node", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_accounts": { + "name": "pdr_ai_v2_token_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "balance_tokens": { + "name": "balance_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lifetime_tokens_purchased": { + "name": "lifetime_tokens_purchased", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lifetime_tokens_granted": { + "name": "lifetime_tokens_granted", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lifetime_tokens_used": { + "name": "lifetime_tokens_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "token_accounts_company_id_idx": { + "name": "token_accounts_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_accounts_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_accounts_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_accounts", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_grants": { + "name": "pdr_ai_v2_token_grants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "grant_type": { + "name": "grant_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "granted_by": { + "name": "granted_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "token_grants_company_id_idx": { + "name": "token_grants_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_grants_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_grants_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_grants", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_transactions": { + "name": "pdr_ai_v2_token_transactions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "balance_after": { + "name": "balance_after", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "service": { + "name": "service", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "token_tx_company_created_idx": { + "name": "token_tx_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "token_tx_company_service_idx": { + "name": "token_tx_company_service_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "service", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_transactions_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_transactions_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_transactions", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_usage_daily": { + "name": "pdr_ai_v2_token_usage_daily", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "service": { + "name": "service", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "operation_count": { + "name": "operation_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "tokens_used": { + "name": "tokens_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "token_usage_daily_company_date_service_idx": { + "name": "token_usage_daily_company_date_service_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "service", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_usage_daily_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_usage_daily_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_usage_daily", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_chat_history": { + "name": "pdr_ai_v2_chat_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_title": { + "name": "document_title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "question": { + "name": "question", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "response": { + "name": "response", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "query_type": { + "name": "query_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'simple'" + }, + "pages": { + "name": "pages", + "type": "integer[]", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "chat_history_user_id_idx": { + "name": "chat_history_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_history_user_id_created_at_idx": { + "name": "chat_history_user_id_created_at_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_history_document_id_idx": { + "name": "chat_history_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_chat_history_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_chat_history_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_chat_history", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_reference_resolutions": { + "name": "pdr_ai_v2_document_reference_resolutions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "reference_name": { + "name": "reference_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "resolved_in_document_id": { + "name": "resolved_in_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "resolution_details": { + "name": "resolution_details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "document_reference_resolutions_company_ref_idx": { + "name": "document_reference_resolutions_company_ref_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_reference_resolutions_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_document_reference_resolutions_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_document_reference_resolutions", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_views": { + "name": "pdr_ai_v2_document_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "viewed_at": { + "name": "viewed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "document_views_document_id_idx": { + "name": "document_views_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_views_company_id_idx": { + "name": "document_views_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_views_user_id_idx": { + "name": "document_views_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_views_company_id_viewed_at_idx": { + "name": "document_views_company_id_viewed_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "viewed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_views_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_document_views_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_document_views", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_views_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_document_views_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_document_views", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_generated_documents": { + "name": "pdr_ai_v2_generated_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "citations": { + "name": "citations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "generated_documents_user_id_idx": { + "name": "generated_documents_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "generated_documents_company_id_idx": { + "name": "generated_documents_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "generated_documents_company_user_idx": { + "name": "generated_documents_company_user_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_generated_documents_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_generated_documents_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_generated_documents", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_predictive_document_analysis_results": { + "name": "pdr_ai_v2_predictive_document_analysis_results", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "analysis_type": { + "name": "analysis_type", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "include_related_docs": { + "name": "include_related_docs", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "result_json": { + "name": "result_json", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "version_id": { + "name": "version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "predictive_analysis_document_id_idx": { + "name": "predictive_analysis_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "predictive_analysis_document_version_idx": { + "name": "predictive_analysis_document_version_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_predictive_document_analysis_results_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_predictive_document_analysis_results_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_predictive_document_analysis_results", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_predictive_document_analysis_results_version_id_pdr_ai_v2_document_versions_id_fk": { + "name": "pdr_ai_v2_predictive_document_analysis_results_version_id_pdr_ai_v2_document_versions_id_fk", + "tableFrom": "pdr_ai_v2_predictive_document_analysis_results", + "tableTo": "pdr_ai_v2_document_versions", + "columnsFrom": [ + "version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_note_embeddings": { + "name": "pdr_ai_v2_document_note_embeddings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "note_id": { + "name": "note_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "document_id": { + "name": "document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "version_id": { + "name": "version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "embedding_short": { + "name": "embedding_short", + "type": "vector(512)", + "primaryKey": false, + "notNull": false + }, + "model_version": { + "name": "model_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "doc_note_emb_note_id_idx": { + "name": "doc_note_emb_note_id_idx", + "columns": [ + { + "expression": "note_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_user_id_idx": { + "name": "doc_note_emb_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_document_id_idx": { + "name": "doc_note_emb_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_company_id_idx": { + "name": "doc_note_emb_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_embedding_short_idx": { + "name": "doc_note_emb_embedding_short_idx", + "columns": [ + { + "expression": "embedding_short", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_notes": { + "name": "pdr_ai_v2_document_notes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "document_id": { + "name": "document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "version_id": { + "name": "version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content_rich": { + "name": "content_rich", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "content_markdown": { + "name": "content_markdown", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "anchor": { + "name": "anchor", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "anchor_status": { + "name": "anchor_status", + "type": "varchar(24)", + "primaryKey": false, + "notNull": false, + "default": "'resolved'" + }, + "tags": { + "name": "tags", + "type": "text[]", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "document_notes_user_idx": { + "name": "document_notes_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_document_idx": { + "name": "document_notes_document_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_company_idx": { + "name": "document_notes_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_version_idx": { + "name": "document_notes_version_idx", + "columns": [ + { + "expression": "version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_anchor_status_idx": { + "name": "document_notes_anchor_status_idx", + "columns": [ + { + "expression": "anchor_status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_note_links": { + "name": "pdr_ai_v2_note_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "source_note_id": { + "name": "source_note_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + }, + "target_note_id": { + "name": "target_note_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "target_document_id": { + "name": "target_document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "target_title": { + "name": "target_title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "note_links_source_idx": { + "name": "note_links_source_idx", + "columns": [ + { + "expression": "source_note_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "note_links_target_note_idx": { + "name": "note_links_target_note_idx", + "columns": [ + { + "expression": "target_note_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "note_links_target_document_idx": { + "name": "note_links_target_document_idx", + "columns": [ + { + "expression": "target_document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "note_links_company_title_idx": { + "name": "note_links_company_title_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_title", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_invite_codes": { + "name": "pdr_ai_v2_invite_codes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "invite_codes_code_idx": { + "name": "invite_codes_code_idx", + "columns": [ + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "invite_codes_company_id_idx": { + "name": "invite_codes_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_invite_codes_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_invite_codes_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_invite_codes", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pdr_ai_v2_invite_codes_code_unique": { + "name": "pdr_ai_v2_invite_codes_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_user_company_memberships": { + "name": "pdr_ai_v2_user_company_memberships", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "user_company_memberships_user_company_unique": { + "name": "user_company_memberships_user_company_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_company_memberships_user_id_idx": { + "name": "user_company_memberships_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_company_memberships_company_id_idx": { + "name": "user_company_memberships_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_user_company_memberships_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_user_company_memberships_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_user_company_memberships", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_user_company_memberships_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_user_company_memberships_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_user_company_memberships", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_users": { + "name": "pdr_ai_v2_users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "last_active_at": { + "name": "last_active_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_company_id_idx": { + "name": "users_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_user_id_idx": { + "name": "users_user_id_idx", + "columns": [ + { + "expression": "userId", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_users_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_users_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_users", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pdr_ai_v2_users_userId_unique": { + "name": "pdr_ai_v2_users_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mindmap_presence": { + "name": "pdr_ai_v2_mindmap_presence", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "mindmap_id": { + "name": "mindmap_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "page_id": { + "name": "page_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "cursor_x": { + "name": "cursor_x", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cursor_y": { + "name": "cursor_y", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "selection": { + "name": "selection", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "revision_seen": { + "name": "revision_seen", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "mindmap_presence_map_user_idx": { + "name": "mindmap_presence_map_user_idx", + "columns": [ + { + "expression": "mindmap_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmap_presence_seen_idx": { + "name": "mindmap_presence_seen_idx", + "columns": [ + { + "expression": "mindmap_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_seen_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mindmap_presence_mindmap_id_pdr_ai_v2_mindmaps_id_fk": { + "name": "pdr_ai_v2_mindmap_presence_mindmap_id_pdr_ai_v2_mindmaps_id_fk", + "tableFrom": "pdr_ai_v2_mindmap_presence", + "tableTo": "pdr_ai_v2_mindmaps", + "columnsFrom": [ + "mindmap_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mindmap_revisions": { + "name": "pdr_ai_v2_mindmap_revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "mindmap_id": { + "name": "mindmap_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc": { + "name": "doc", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "author_user_id": { + "name": "author_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "node_count": { + "name": "node_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "mindmap_revisions_map_idx": { + "name": "mindmap_revisions_map_idx", + "columns": [ + { + "expression": "mindmap_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmap_revisions_created_idx": { + "name": "mindmap_revisions_created_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mindmap_revisions_mindmap_id_pdr_ai_v2_mindmaps_id_fk": { + "name": "pdr_ai_v2_mindmap_revisions_mindmap_id_pdr_ai_v2_mindmaps_id_fk", + "tableFrom": "pdr_ai_v2_mindmap_revisions", + "tableTo": "pdr_ai_v2_mindmaps", + "columnsFrom": [ + "mindmap_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mindmaps": { + "name": "pdr_ai_v2_mindmaps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "updated_by_user_id": { + "name": "updated_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "template_id": { + "name": "template_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "folder": { + "name": "folder", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "'Unfiled'" + }, + "doc": { + "name": "doc", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "doc_version": { + "name": "doc_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "thumbnail": { + "name": "thumbnail", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "search_text": { + "name": "search_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "node_count": { + "name": "node_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "edge_count": { + "name": "edge_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "starred": { + "name": "starred", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "published_document_id": { + "name": "published_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "opened_at": { + "name": "opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "mindmaps_company_idx": { + "name": "mindmaps_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_company_updated_idx": { + "name": "mindmaps_company_updated_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_creator_idx": { + "name": "mindmaps_creator_idx", + "columns": [ + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_folder_idx": { + "name": "mindmaps_folder_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "folder", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_deleted_idx": { + "name": "mindmaps_deleted_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mindmaps_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_mindmaps_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_mindmaps", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_trend_search_jobs": { + "name": "pdr_ai_v2_trend_search_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "query": { + "name": "query", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "company_context": { + "name": "company_context", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "results": { + "name": "results", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "trend_search_jobs_company_id_idx": { + "name": "trend_search_jobs_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "trend_search_jobs_status_idx": { + "name": "trend_search_jobs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "trend_search_jobs_company_status_idx": { + "name": "trend_search_jobs_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_trend_search_jobs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_trend_search_jobs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_trend_search_jobs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_trend_search_cache": { + "name": "pdr_ai_v2_trend_search_cache", + "schema": "", + "columns": { + "cache_key": { + "name": "cache_key", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_client_prospector_jobs": { + "name": "pdr_ai_v2_client_prospector_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "query": { + "name": "query", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "company_context": { + "name": "company_context", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "location_lat": { + "name": "location_lat", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "location_lng": { + "name": "location_lng", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "radius": { + "name": "radius", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5000 + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "results": { + "name": "results", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "client_prospector_jobs_company_id_idx": { + "name": "client_prospector_jobs_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "client_prospector_jobs_status_idx": { + "name": "client_prospector_jobs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "client_prospector_jobs_company_status_idx": { + "name": "client_prospector_jobs_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_client_prospector_jobs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_client_prospector_jobs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_client_prospector_jobs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_company_metadata": { + "name": "pdr_ai_v2_company_metadata", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "schema_version": { + "name": "schema_version", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'1.0.0'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "last_extraction_document_id": { + "name": "last_extraction_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "company_metadata_company_id_unique": { + "name": "company_metadata_company_id_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_company_metadata_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_company_metadata_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_company_metadata_last_extraction_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_company_metadata_last_extraction_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "last_extraction_document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_company_metadata_history": { + "name": "pdr_ai_v2_company_metadata_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "change_type": { + "name": "change_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "diff": { + "name": "diff", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "changed_by": { + "name": "changed_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "company_metadata_history_company_id_idx": { + "name": "company_metadata_history_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "company_metadata_history_document_id_idx": { + "name": "company_metadata_history_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "company_metadata_history_created_at_idx": { + "name": "company_metadata_history_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "company_metadata_history_change_type_idx": { + "name": "company_metadata_history_change_type_idx", + "columns": [ + { + "expression": "change_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_company_metadata_history_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_company_metadata_history_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata_history", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_company_metadata_history_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_company_metadata_history_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata_history", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_marketing_content_history": { + "name": "pdr_ai_v2_marketing_content_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "platform": { + "name": "platform", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "angle": { + "name": "angle", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "content_type": { + "name": "content_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'post'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "impressions": { + "name": "impressions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "engagements": { + "name": "engagements", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "clicks": { + "name": "clicks", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "post_id": { + "name": "post_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "post_url": { + "name": "post_url", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "mch_company_id_idx": { + "name": "mch_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mch_platform_idx": { + "name": "mch_platform_idx", + "columns": [ + { + "expression": "platform", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_founder_weekly_review_dispatches": { + "name": "pdr_ai_v2_founder_weekly_review_dispatches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "operation_key": { + "name": "operation_key", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "generation_job_id": { + "name": "generation_job_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "generation_claim_id": { + "name": "generation_claim_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "available_at": { + "name": "available_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "dispatched_at": { + "name": "dispatched_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error_code": { + "name": "last_error_code", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "founder_weekly_review_dispatches_run_operation_key_unique": { + "name": "founder_weekly_review_dispatches_run_operation_key_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_dispatches_event_id_unique": { + "name": "founder_weekly_review_dispatches_event_id_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_dispatches_pending_idx": { + "name": "founder_weekly_review_dispatches_pending_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "available_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_dispatches_company_run_idx": { + "name": "founder_weekly_review_dispatches_company_run_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_founder_weekly_review_dispatches_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_dispatches_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_dispatches", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_founder_weekly_review_dispatches_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_dispatches_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_dispatches", + "tableTo": "pdr_ai_v2_founder_weekly_review_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_founder_weekly_review_operations": { + "name": "pdr_ai_v2_founder_weekly_review_operations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "request_key": { + "name": "request_key", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "source_failure_sequence": { + "name": "source_failure_sequence", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "founder_weekly_review_operations_run_type_request_key_unique": { + "name": "founder_weekly_review_operations_run_type_request_key_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "request_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_operations_company_run_created_at_idx": { + "name": "founder_weekly_review_operations_company_run_created_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_operations_run_type_created_at_idx": { + "name": "founder_weekly_review_operations_run_type_created_at_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_founder_weekly_review_operations_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_operations_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_operations", + "tableTo": "pdr_ai_v2_founder_weekly_review_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_founder_weekly_review_operations_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_operations_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_operations", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_founder_weekly_review_runs": { + "name": "pdr_ai_v2_founder_weekly_review_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "request_key": { + "name": "request_key", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "reporting_period_start": { + "name": "reporting_period_start", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "reporting_period_end": { + "name": "reporting_period_end", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "review_payload": { + "name": "review_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "review_schema_version": { + "name": "review_schema_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "evidence_snapshot": { + "name": "evidence_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "evidence_schema_version": { + "name": "evidence_schema_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "model_metadata": { + "name": "model_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_by_actor_id": { + "name": "created_by_actor_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "retry_count": { + "name": "retry_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "failure_sequence": { + "name": "failure_sequence", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "generation_attempt": { + "name": "generation_attempt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "generation_claim_id": { + "name": "generation_claim_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "generation_job_id": { + "name": "generation_job_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "queued_at": { + "name": "queued_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "generation_started_at": { + "name": "generation_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "generated_at": { + "name": "generated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "collection_input": { + "name": "collection_input", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "collection_claim_id": { + "name": "collection_claim_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "collection_started_at": { + "name": "collection_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "evidence_collected_at": { + "name": "evidence_collected_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "founder_weekly_review_runs_company_request_key_unique": { + "name": "founder_weekly_review_runs_company_request_key_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "request_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_company_created_at_idx": { + "name": "founder_weekly_review_runs_company_created_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_company_status_created_at_idx": { + "name": "founder_weekly_review_runs_company_status_created_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_company_period_idx": { + "name": "founder_weekly_review_runs_company_period_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reporting_period_start", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reporting_period_end", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_claim_idx": { + "name": "founder_weekly_review_runs_claim_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation_claim_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_collection_claim_idx": { + "name": "founder_weekly_review_runs_collection_claim_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "collection_claim_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_founder_weekly_review_runs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_runs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_runs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_campaign_approvals": { + "name": "pdr_ai_v2_email_campaign_approvals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "template_version_id": { + "name": "template_version_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "approved_by": { + "name": "approved_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "approved_by_email": { + "name": "approved_by_email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": false + }, + "approved_by_kind": { + "name": "approved_by_kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'human'" + }, + "review_verdict": { + "name": "review_verdict", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "override_reason": { + "name": "override_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_campaign_approvals_campaign_idx": { + "name": "email_campaign_approvals_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_campaign_approvals_version_idx": { + "name": "email_campaign_approvals_version_idx", + "columns": [ + { + "expression": "template_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_campaign_approvals_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_campaign_approvals_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_campaign_approvals", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_campaign_approvals_template_version_id_pdr_ai_v2_email_template_versions_id_fk": { + "name": "pdr_ai_v2_email_campaign_approvals_template_version_id_pdr_ai_v2_email_template_versions_id_fk", + "tableFrom": "pdr_ai_v2_email_campaign_approvals", + "tableTo": "pdr_ai_v2_email_template_versions", + "columnsFrom": [ + "template_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_campaigns": { + "name": "pdr_ai_v2_email_campaigns", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "goal": { + "name": "goal", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "approved_version_id": { + "name": "approved_version_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "automation_key": { + "name": "automation_key", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_campaigns_company_idx": { + "name": "email_campaigns_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_campaigns_company_status_idx": { + "name": "email_campaigns_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_campaigns_company_automation_key_uq": { + "name": "email_campaigns_company_automation_key_uq", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "automation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_campaigns_approved_version_id_pdr_ai_v2_email_template_versions_id_fk": { + "name": "pdr_ai_v2_email_campaigns_approved_version_id_pdr_ai_v2_email_template_versions_id_fk", + "tableFrom": "pdr_ai_v2_email_campaigns", + "tableTo": "pdr_ai_v2_email_template_versions", + "columnsFrom": [ + "approved_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_recipients": { + "name": "pdr_ai_v2_email_recipients", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "company": { + "name": "company", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "context_notes": { + "name": "context_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vars": { + "name": "vars", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "frozen_at": { + "name": "frozen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_recipients_campaign_idx": { + "name": "email_recipients_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_recipients_campaign_email_uq": { + "name": "email_recipients_campaign_email_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_recipients_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_recipients_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_recipients", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_send_attempts": { + "name": "pdr_ai_v2_email_send_attempts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "template_version_id": { + "name": "template_version_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "mode": { + "name": "mode", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'dry_run'" + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "requested_by": { + "name": "requested_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "heartbeat_at": { + "name": "heartbeat_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "recipient_count": { + "name": "recipient_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "sent_count": { + "name": "sent_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "failed_count": { + "name": "failed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "suppressed_count": { + "name": "suppressed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "skipped_count": { + "name": "skipped_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "email_send_attempts_campaign_idx": { + "name": "email_send_attempts_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_send_attempts_campaign_key_uq": { + "name": "email_send_attempts_campaign_key_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "idempotency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_send_attempts_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_send_attempts_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_send_attempts", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_send_attempts_template_version_id_pdr_ai_v2_email_template_versions_id_fk": { + "name": "pdr_ai_v2_email_send_attempts_template_version_id_pdr_ai_v2_email_template_versions_id_fk", + "tableFrom": "pdr_ai_v2_email_send_attempts", + "tableTo": "pdr_ai_v2_email_template_versions", + "columnsFrom": [ + "template_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_sends": { + "name": "pdr_ai_v2_email_sends", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attempt_id": { + "name": "attempt_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "recipient_id": { + "name": "recipient_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "recipient_email": { + "name": "recipient_email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "provider_message_id": { + "name": "provider_message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "provider_idempotency_key": { + "name": "provider_idempotency_key", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_sends_campaign_idx": { + "name": "email_sends_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_sends_attempt_recipient_uq": { + "name": "email_sends_attempt_recipient_uq", + "columns": [ + { + "expression": "attempt_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "recipient_email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_sends_campaign_recipient_delivery_uq": { + "name": "email_sends_campaign_recipient_delivery_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "recipient_email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "status IN ('queued', 'sent')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_sends_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_sends_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_sends", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_sends_attempt_id_pdr_ai_v2_email_send_attempts_id_fk": { + "name": "pdr_ai_v2_email_sends_attempt_id_pdr_ai_v2_email_send_attempts_id_fk", + "tableFrom": "pdr_ai_v2_email_sends", + "tableTo": "pdr_ai_v2_email_send_attempts", + "columnsFrom": [ + "attempt_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_sends_recipient_id_pdr_ai_v2_email_recipients_id_fk": { + "name": "pdr_ai_v2_email_sends_recipient_id_pdr_ai_v2_email_recipients_id_fk", + "tableFrom": "pdr_ai_v2_email_sends", + "tableTo": "pdr_ai_v2_email_recipients", + "columnsFrom": [ + "recipient_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_suppressions": { + "name": "pdr_ai_v2_email_suppressions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'unsubscribe'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_suppressions_company_email_uq": { + "name": "email_suppressions_company_email_uq", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_template_versions": { + "name": "pdr_ai_v2_email_template_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "variables": { + "name": "variables", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ai_generated'" + }, + "goal": { + "name": "goal", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "prompt_version": { + "name": "prompt_version", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "review_verdict": { + "name": "review_verdict", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "review": { + "name": "review", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_template_versions_campaign_idx": { + "name": "email_template_versions_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_template_versions_campaign_version_uq": { + "name": "email_template_versions_campaign_version_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_template_versions_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_template_versions_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_template_versions", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/web/drizzle/meta/_journal.json b/apps/web/drizzle/meta/_journal.json index 5a5b87844..9d16281e7 100644 --- a/apps/web/drizzle/meta/_journal.json +++ b/apps/web/drizzle/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1788032041550, "tag": "20260829193401_lowly_silverclaw", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1788035698409, + "tag": "20260829203458_claude_artifacts", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/web/src/app/api/artifacts/[id]/raw/route.ts b/apps/web/src/app/api/artifacts/[id]/raw/route.ts new file mode 100644 index 000000000..d6ad286fd --- /dev/null +++ b/apps/web/src/app/api/artifacts/[id]/raw/route.ts @@ -0,0 +1,69 @@ +/** + * Download an artifact's body as a file. + * + * Always `Content-Disposition: attachment`: an imported artifact is untrusted + * HTML, and serving it inline from this origin would run its scripts with the + * user's session. In-app preview instead renders through a sandboxed iframe + * (`srcDoc` without `allow-same-origin`, so scripts run in an opaque origin). + * The `sandbox` CSP is a second lock on the same door for anything that + * ignores the disposition. + */ + +import { NextResponse } from "next/server"; + +import { artifactFileExtension, type ArtifactType } from "~/lib/artifact-content"; +import { requireWorkspaceContext } from "~/lib/require-workspace-context"; +import { serverError } from "~/lib/validation"; +import { getArtifact } from "~/server/artifacts/repository"; + +const CONTENT_TYPE_BY_ARTIFACT: Record = { + html: "text/html; charset=utf-8", + svg: "image/svg+xml; charset=utf-8", + markdown: "text/markdown; charset=utf-8", + mermaid: "text/plain; charset=utf-8", + react: "text/plain; charset=utf-8", + code: "text/plain; charset=utf-8", +}; + +function sanitizeForFilename(value: string): string { + return ( + value + .replace(/[^a-zA-Z0-9._-]/g, "-") + .replace(/-+/g, "-") + .replace(/^-|-$/g, "") + .slice(0, 80) || "artifact" + ); +} + +export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) { + try { + const ctx = await requireWorkspaceContext(); + if (!ctx.success) return ctx.response; + + const id = Number.parseInt((await params).id, 10); + if (!Number.isInteger(id) || id <= 0) { + return NextResponse.json({ error: "Invalid id" }, { status: 400 }); + } + + const row = await getArtifact(id, ctx.data.companyId); + if (!row) return NextResponse.json({ error: "Artifact not found" }, { status: 404 }); + + const extension = artifactFileExtension(row.artifactType as ArtifactType); + const filename = `${sanitizeForFilename(row.title)}.${extension}`; + + return new NextResponse(row.content, { + status: 200, + headers: { + "Content-Type": + CONTENT_TYPE_BY_ARTIFACT[row.artifactType] ?? "text/plain; charset=utf-8", + "Content-Disposition": `attachment; filename="${filename}"`, + "X-Content-Type-Options": "nosniff", + "Content-Security-Policy": "sandbox", + "Cache-Control": "private, no-store", + }, + }); + } catch (error) { + console.error("[artifacts] download failed:", error); + return serverError("Failed to download artifact"); + } +} diff --git a/apps/web/src/app/api/artifacts/[id]/route.ts b/apps/web/src/app/api/artifacts/[id]/route.ts new file mode 100644 index 000000000..1493334c1 --- /dev/null +++ b/apps/web/src/app/api/artifacts/[id]/route.ts @@ -0,0 +1,143 @@ +/** + * Single artifact — read, update, trash. + * + * Updating `content` re-derives the size, hash, and search text, and re-runs + * type detection unless the request pins `artifactType` explicitly — an edit + * that turns a Markdown note into an HTML page should follow it. + */ + +import { createHash } from "node:crypto"; + +import { NextResponse } from "next/server"; +import { and, eq } from "drizzle-orm"; + +import { artifactSearchText, detectArtifactType } from "~/lib/artifact-content"; +import { requireWorkspaceContext } from "~/lib/require-workspace-context"; +import { serverError, UpdateArtifactSchema, validateRequestBody } from "~/lib/validation"; +import { db } from "~/server/db"; +import { claudeArtifacts } from "~/server/db/schema"; +import { getArtifact, toDetail } from "~/server/artifacts/repository"; + +function parseId(raw: string): number | null { + const id = Number.parseInt(raw, 10); + return Number.isInteger(id) && id > 0 ? id : null; +} + +function notFound() { + return NextResponse.json({ error: "Artifact not found" }, { status: 404 }); +} + +export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) { + try { + const ctx = await requireWorkspaceContext(); + if (!ctx.success) return ctx.response; + + const id = parseId((await params).id); + if (id === null) return NextResponse.json({ error: "Invalid id" }, { status: 400 }); + + const row = await getArtifact(id, ctx.data.companyId); + if (!row) return notFound(); + + // Best-effort recency stamp — a failure here must never stop the + // artifact from opening. + void db + .update(claudeArtifacts) + .set({ openedAt: new Date() }) + .where(eq(claudeArtifacts.id, id)) + .catch((err: unknown) => console.error("[artifacts] openedAt stamp failed:", err)); + + return NextResponse.json({ artifact: toDetail(row) }, { status: 200 }); + } catch (error) { + console.error("[artifacts] fetch failed:", error); + return serverError("Failed to load artifact"); + } +} + +export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) { + try { + const ctx = await requireWorkspaceContext(); + if (!ctx.success) return ctx.response; + + const id = parseId((await params).id); + if (id === null) return NextResponse.json({ error: "Invalid id" }, { status: 400 }); + + const validation = await validateRequestBody(request, UpdateArtifactSchema); + if (!validation.success) return validation.response; + const body = validation.data; + + const current = await getArtifact(id, ctx.data.companyId); + if (!current) return notFound(); + + const patch: Partial = { + updatedByUserId: ctx.data.authUserId, + updatedAt: new Date(), + }; + if (body.title !== undefined) patch.title = body.title.trim(); + if (body.description !== undefined) patch.description = body.description; + if (body.folder !== undefined) patch.folder = body.folder.trim(); + if (body.starred !== undefined) patch.starred = body.starred; + if (body.sourceUrl !== undefined) patch.sourceUrl = body.sourceUrl; + if (body.artifactType !== undefined) patch.artifactType = body.artifactType; + if (body.restore) patch.deletedAt = null; + if (body.content !== undefined) { + patch.content = body.content; + patch.sizeBytes = Buffer.byteLength(body.content, "utf-8"); + patch.contentHash = createHash("sha256").update(body.content).digest("hex"); + patch.searchText = artifactSearchText(body.content); + if (body.artifactType === undefined) { + patch.artifactType = detectArtifactType(body.content); + } + } + + const [row] = await db + .update(claudeArtifacts) + .set(patch) + .where( + and(eq(claudeArtifacts.id, id), eq(claudeArtifacts.companyId, ctx.data.companyId)) + ) + .returning(); + + if (!row) return notFound(); + return NextResponse.json({ artifact: toDetail(row) }, { status: 200 }); + } catch (error) { + console.error("[artifacts] update failed:", error); + return serverError("Failed to update artifact"); + } +} + +export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) { + try { + const ctx = await requireWorkspaceContext(); + if (!ctx.success) return ctx.response; + + const id = parseId((await params).id); + if (id === null) return NextResponse.json({ error: "Invalid id" }, { status: 400 }); + + const scope = and( + eq(claudeArtifacts.id, id), + eq(claudeArtifacts.companyId, ctx.data.companyId) + ); + const purge = new URL(request.url).searchParams.get("purge") === "1"; + + if (purge) { + const [row] = await db + .delete(claudeArtifacts) + .where(scope) + .returning({ id: claudeArtifacts.id }); + if (!row) return notFound(); + return NextResponse.json({ deleted: true, purged: true }, { status: 200 }); + } + + const [row] = await db + .update(claudeArtifacts) + .set({ deletedAt: new Date(), updatedByUserId: ctx.data.authUserId }) + .where(scope) + .returning({ id: claudeArtifacts.id }); + if (!row) return notFound(); + + return NextResponse.json({ deleted: true, purged: false }, { status: 200 }); + } catch (error) { + console.error("[artifacts] delete failed:", error); + return serverError("Failed to delete artifact"); + } +} diff --git a/apps/web/src/app/api/artifacts/route.ts b/apps/web/src/app/api/artifacts/route.ts new file mode 100644 index 000000000..45f571e2b --- /dev/null +++ b/apps/web/src/app/api/artifacts/route.ts @@ -0,0 +1,188 @@ +/** + * Claude artifacts collection endpoint — list and import. + * + * Artifacts are workspace-scoped, not user-scoped: anyone in the company can + * open an artifact a colleague imported, matching how Sources behave. + * + * Import accepts the body directly (paste or file upload) or fetches it from a + * public URL through the SSRF guard. claude.ai share links are refused with a + * structured 422: those pages render the artifact client-side behind bot + * protection, so a server fetch would only ever capture an empty app shell — + * the dialog tells the user to paste or upload the artifact instead. + */ + +import { createHash } from "node:crypto"; + +import { NextResponse } from "next/server"; + +import { + artifactSearchText, + deriveArtifactTitle, + detectArtifactType, + isClaudeHostedUrl, + MAX_ARTIFACT_BYTES, + type ArtifactType, +} from "~/lib/artifact-content"; +import { requireWorkspaceContext } from "~/lib/require-workspace-context"; +import { withRateLimit } from "~/lib/rate-limit-middleware"; +import { RateLimitPresets } from "~/lib/rate-limiter"; +import { ImportArtifactSchema, serverError, validateRequestBody } from "~/lib/validation"; +import { db } from "~/server/db"; +import { claudeArtifacts } from "~/server/db/schema"; +import { assertPublicHttpUrl, fetchPublicUrl, UrlGuardError } from "~/server/security/url-guard"; +import { listArtifacts, listFolders, toDetail } from "~/server/artifacts/repository"; + +const FETCH_TIMEOUT_MS = 30_000; + +/** Content types an artifact URL may serve; anything else is not an artifact. */ +const TEXT_CONTENT_TYPES = /(text\/|application\/(xhtml\+xml|xml|json|javascript)|image\/svg)/i; + +/** Trimmed value, or `undefined` when missing or blank (`??` can't do blank). */ +function nonEmpty(value: string | null | undefined): string | undefined { + const trimmed = value?.trim(); + if (trimmed === undefined || trimmed === "") return undefined; + return trimmed; +} + +/** + * Fetch an artifact body with timeout, size cap, and content-type check. + * Guard rejections are rethrown so the route answers 400, not a generic 502. + */ +async function fetchArtifactBody(url: string): Promise { + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS); + try { + const response = await fetchPublicUrl(url, { + signal: controller.signal, + headers: { + "User-Agent": "Mozilla/5.0 (compatible; LaunchStack-ArtifactImport/1.0)", + Accept: "text/html,image/svg+xml,text/markdown,text/plain;q=0.9,*/*;q=0.8", + }, + }); + clearTimeout(timeout); + + if (!response.ok) return null; + const contentType = response.headers.get("content-type") ?? ""; + if (contentType && !TEXT_CONTENT_TYPES.test(contentType)) return null; + + const arrayBuf = await response.arrayBuffer(); + if (arrayBuf.byteLength > MAX_ARTIFACT_BYTES) return null; + + return Buffer.from(arrayBuf).toString("utf-8"); + } catch (err) { + clearTimeout(timeout); + if (err instanceof UrlGuardError) throw err; + return null; + } +} + +export async function GET(request: Request) { + try { + const ctx = await requireWorkspaceContext(); + if (!ctx.success) return ctx.response; + + const { searchParams } = new URL(request.url); + const scope = searchParams.get("scope") === "trash" ? "trash" : "active"; + + const [items, folders] = await Promise.all([ + listArtifacts({ + companyId: ctx.data.companyId, + scope, + folder: searchParams.get("folder") ?? undefined, + search: nonEmpty(searchParams.get("q")), + starredOnly: searchParams.get("starred") === "1", + limit: Number(searchParams.get("limit")) || undefined, + }), + listFolders(ctx.data.companyId), + ]); + + return NextResponse.json({ artifacts: items, folders }, { status: 200 }); + } catch (error) { + console.error("[artifacts] list failed:", error); + return serverError("Failed to load artifacts"); + } +} + +export async function POST(request: Request) { + const ctx = await requireWorkspaceContext(); + if (!ctx.success) return ctx.response; + + // The strict preset because the URL path makes an outbound fetch. + return withRateLimit(request, RateLimitPresets.strict, async () => { + try { + const validation = await validateRequestBody(request, ImportArtifactSchema); + if (!validation.success) return validation.response; + const body = validation.data; + + let content = body.content; + let importMethod: "paste" | "upload" | "url" = body.fetchFromUrl ? "url" : "paste"; + + if (content === undefined) { + // fetchFromUrl mode — the schema guarantees sourceUrl is set. + const sourceUrl = body.sourceUrl!; + if (isClaudeHostedUrl(sourceUrl)) { + return NextResponse.json( + { + error: "claude.ai pages can't be fetched server-side — they render the artifact in the browser behind bot protection. Copy the artifact's code (or download it) in Claude and paste or upload it here; the link is kept as the source.", + code: "claude_share_link", + }, + { status: 422 } + ); + } + + let parsedUrl: URL; + try { + parsedUrl = await assertPublicHttpUrl(sourceUrl); + } catch (err) { + if (err instanceof UrlGuardError) { + return NextResponse.json({ error: err.message }, { status: 400 }); + } + throw err; + } + + const fetched = await fetchArtifactBody(parsedUrl.href); + if (!fetched?.trim()) { + return NextResponse.json( + { error: "Couldn't fetch that URL, or it didn't return text content" }, + { status: 502 } + ); + } + content = fetched; + } else { + importMethod = body.importMethod ?? "paste"; + } + + const artifactType: ArtifactType = body.artifactType ?? detectArtifactType(content); + const title = + nonEmpty(body.title) ?? + deriveArtifactTitle(content, artifactType) ?? + "Untitled artifact"; + + const [row] = await db + .insert(claudeArtifacts) + .values({ + companyId: ctx.data.companyId, + createdByUserId: ctx.data.authUserId, + updatedByUserId: ctx.data.authUserId, + title, + description: body.description ?? null, + folder: nonEmpty(body.folder) ?? "Unfiled", + artifactType, + sourceUrl: body.sourceUrl ?? null, + importMethod, + content, + sizeBytes: Buffer.byteLength(content, "utf-8"), + contentHash: createHash("sha256").update(content).digest("hex"), + searchText: artifactSearchText(content), + openedAt: new Date(), + }) + .returning(); + + if (!row) return serverError("Failed to import artifact"); + return NextResponse.json({ artifact: toDetail(row) }, { status: 201 }); + } catch (error) { + console.error("[artifacts] import failed:", error); + return serverError("Failed to import artifact"); + } + }); +} diff --git a/apps/web/src/app/dev/artifacts/ArtifactsPreview.tsx b/apps/web/src/app/dev/artifacts/ArtifactsPreview.tsx new file mode 100644 index 000000000..ad1d175ce --- /dev/null +++ b/apps/web/src/app/dev/artifacts/ArtifactsPreview.tsx @@ -0,0 +1,237 @@ +"use client"; + +import { useEffect, useState } from "react"; + +import { DriftShell } from "~/app/employer/_chrome/DriftShell"; +import { ToolsStudioShell } from "~/app/employer/_chrome/ToolsStudioShell"; +import { ArtifactGallery } from "~/app/employer/artifacts/_artifacts/ui/ArtifactGallery"; +import { ArtifactViewer } from "~/app/employer/artifacts/_artifacts/ui/ArtifactViewer"; +import { detectArtifactType } from "~/lib/artifact-content"; + +/** + * Local harness for the Artifacts app. It reproduces the real chrome chain — + * DriftShell → ToolsStudioShell → gallery/viewer — so layout work here is + * layout work there, but skips auth so the pages can be driven without a + * session. Gated to non-production by the server page. + * + * `?view=viewer&id=N` opens the viewer on a seeded artifact (1 html, 2 svg, + * 3 markdown, 4 mermaid, 5 code); the default is the gallery. The stub keeps + * an in-memory store so import, rename, star, folder moves, and trash all + * round-trip for real. + */ + +interface StubArtifact { + id: number; + title: string; + description: string | null; + folder: string; + artifactType: string; + sourceUrl: string | null; + importMethod: string; + content: string; + sizeBytes: number; + contentHash: string; + starred: boolean; + createdByUserId: string; + updatedByUserId: string | null; + deletedAt: string | null; + openedAt: string | null; + createdAt: string; + updatedAt: string; +} + +const SEED_HTML = ` +Churn Dashboard +

Churn Dashboard

Interactive artifact — scripts run sandboxed.

+ +
+ +`; + +const SEED_SVG = ` + Funnel + + + +`; + +const SEED_MD = `# Rollout plan + +A **markdown** artifact imported from Claude. + +- Phase 1: internal dogfood +- Phase 2: design partners +- Phase 3: GA + +| Week | Milestone | +| ---- | --------- | +| 1 | Flag on | +| 3 | Review | +`; + +const SEED_MERMAID = `flowchart TD + A[Import artifact] --> B{Type?} + B -->|html/svg| C[Sandboxed iframe] + B -->|markdown| D[Rendered prose] + B -->|mermaid| E[Diagram] + B -->|react/code| F[Source view]`; + +const SEED_CODE = `def churn_rate(cancelled: int, total: int) -> float: + if total == 0: + return 0.0 + return cancelled / total +`; + +function seed(id: number, title: string, folder: string, content: string): StubArtifact { + const now = new Date().toISOString(); + return { + id, + title, + description: null, + folder, + artifactType: detectArtifactType(content), + sourceUrl: id === 1 ? "https://claude.ai/public/artifacts/example" : null, + importMethod: "paste", + content, + sizeBytes: new Blob([content]).size, + contentHash: String(id).repeat(8), + starred: id === 1, + createdByUserId: "dev-user", + updatedByUserId: null, + deletedAt: null, + openedAt: now, + createdAt: now, + updatedAt: now, + }; +} + +/** + * `/api/artifacts/*` is session-guarded, so every call here would 401. + * Answering them from an in-memory store lets the whole management flow run. + * Installed at module scope: an effect would let the first load through. + */ +let stubbed = false; +function stubArtifactsApi() { + if (stubbed || typeof window === "undefined") return; + stubbed = true; + + const store: StubArtifact[] = [ + seed(1, "Churn Dashboard", "Dashboards", SEED_HTML), + seed(2, "Funnel diagram", "Dashboards", SEED_SVG), + seed(3, "Rollout plan", "Unfiled", SEED_MD), + seed(4, "Import flow", "Unfiled", SEED_MERMAID), + seed(5, "churn.py", "Snippets", SEED_CODE), + ]; + let nextId = 6; + + const real = window.fetch.bind(window); + const json = (body: unknown, status = 200) => + new Response(JSON.stringify(body), { + status, + headers: { "Content-Type": "application/json" }, + }); + const folders = () => [...new Set(store.filter(a => !a.deletedAt).map(a => a.folder))].sort(); + + window.fetch = async (input, init) => { + const url = + typeof input === "string" ? input : input instanceof URL ? input.href : input.url; + if (!url.includes("/api/artifacts")) return real(input, init); + + const method = init?.method ?? "GET"; + const idMatch = /\/api\/artifacts\/(\d+)/.exec(url); + + if (!idMatch && method === "GET") { + const scope = new URL(url, window.location.origin).searchParams.get("scope"); + const items = store + .filter(a => (scope === "trash" ? a.deletedAt : !a.deletedAt)) + .map(({ content: _content, ...summary }) => summary); + return json({ artifacts: items, folders: folders() }); + } + if (!idMatch && method === "POST") { + const body = JSON.parse(typeof init?.body === "string" ? init.body : "{}") as { + title?: string; + folder?: string; + content?: string; + sourceUrl?: string; + fetchFromUrl?: boolean; + }; + if (body.fetchFromUrl) { + return json( + { + error: "claude.ai pages can't be fetched server-side — they render the artifact in the browser behind bot protection. Copy the artifact's code (or download it) in Claude and paste or upload it here; the link is kept as the source.", + code: "claude_share_link", + }, + 422 + ); + } + const created = seed( + nextId++, + body.title ?? "Untitled artifact", + body.folder ?? "Unfiled", + body.content ?? "" + ); + created.starred = false; + created.sourceUrl = body.sourceUrl ?? null; + store.unshift(created); + return json({ artifact: created }, 201); + } + + const artifact = idMatch ? store.find(a => a.id === Number(idMatch[1])) : undefined; + if (!artifact) return json({ error: "Artifact not found" }, 404); + + if (method === "PATCH") { + const body = JSON.parse( + typeof init?.body === "string" ? init.body : "{}" + ) as Partial & { restore?: boolean }; + if (body.restore) artifact.deletedAt = null; + if (body.title !== undefined) artifact.title = body.title; + if (body.description !== undefined) artifact.description = body.description; + if (body.folder !== undefined) artifact.folder = body.folder; + if (body.starred !== undefined) artifact.starred = body.starred; + if (body.artifactType !== undefined) artifact.artifactType = body.artifactType; + if (body.content !== undefined) artifact.content = body.content; + artifact.updatedAt = new Date().toISOString(); + return json({ artifact }); + } + if (method === "DELETE") { + if (url.includes("purge=1")) { + store.splice(store.indexOf(artifact), 1); + return json({ deleted: true, purged: true }); + } + artifact.deletedAt = new Date().toISOString(); + return json({ deleted: true, purged: false }); + } + return json({ artifact }); + }; +} + +stubArtifactsApi(); + +export function ArtifactsPreview() { + // Client-only so the stub is installed before anything mounts. + const [query, setQuery] = useState(null); + + useEffect(() => { + setQuery(new URLSearchParams(window.location.search)); + }, []); + + if (!query) return null; + + const viewerId = query.get("view") === "viewer" ? Number(query.get("id") ?? 1) : null; + + return ( + + + {viewerId !== null ? : } + + + ); +} diff --git a/apps/web/src/app/dev/artifacts/page.tsx b/apps/web/src/app/dev/artifacts/page.tsx new file mode 100644 index 000000000..90b535276 --- /dev/null +++ b/apps/web/src/app/dev/artifacts/page.tsx @@ -0,0 +1,8 @@ +import { notFound } from "next/navigation"; + +import { ArtifactsPreview } from "./ArtifactsPreview"; + +export default function ArtifactsPreviewPage() { + if (process.env.NODE_ENV === "production") notFound(); + return ; +} diff --git a/apps/web/src/app/employer/artifacts/[id]/page.tsx b/apps/web/src/app/employer/artifacts/[id]/page.tsx new file mode 100644 index 000000000..c0590bf5e --- /dev/null +++ b/apps/web/src/app/employer/artifacts/[id]/page.tsx @@ -0,0 +1,40 @@ +"use client"; + +import { use } from "react"; +import Link from "next/link"; +import { ArrowLeft } from "lucide-react"; + +import { Button } from "~/components/ui/button"; + +import { useSetBreadcrumbs } from "../../_chrome/BreadcrumbContext"; +import { ArtifactViewer } from "../_artifacts/ui/ArtifactViewer"; + +/** + * The viewer route. The artifact is fetched client-side by the viewer — the + * body can be megabytes of untrusted HTML, and server-rendering it would + * serialise all of that into the page payload only to hand it to a client + * component anyway. + */ +export default function ArtifactViewerPage({ params }: { params: Promise<{ id: string }> }) { + const { id } = use(params); + useSetBreadcrumbs(["Drift", "Artifacts"]); + + const numeric = Number.parseInt(id, 10); + if (!Number.isInteger(numeric) || numeric <= 0) { + return ( +
+

+ That artifact link isn't valid. +

+ +
+ ); + } + + return ; +} diff --git a/apps/web/src/app/employer/artifacts/_artifacts/lib/api.ts b/apps/web/src/app/employer/artifacts/_artifacts/lib/api.ts new file mode 100644 index 000000000..591fff370 --- /dev/null +++ b/apps/web/src/app/employer/artifacts/_artifacts/lib/api.ts @@ -0,0 +1,119 @@ +/** + * Typed fetch wrappers for the artifacts API. Mirrors the serializers in + * ~/server/artifacts/repository — keep the two in sync. + */ + +import type { ArtifactType } from "~/lib/artifact-content"; + +export interface ArtifactSummary { + id: number; + title: string; + description: string | null; + folder: string; + artifactType: string; + sourceUrl: string | null; + importMethod: string; + sizeBytes: number; + contentHash: string; + starred: boolean; + createdByUserId: string; + updatedByUserId: string | null; + deletedAt: string | null; + openedAt: string | null; + createdAt: string; + updatedAt: string; +} + +export interface ArtifactDetail extends ArtifactSummary { + content: string; +} + +export interface ImportArtifactInput { + title?: string; + description?: string; + folder?: string; + sourceUrl?: string; + content?: string; + artifactType?: ArtifactType; + importMethod?: "paste" | "upload"; + fetchFromUrl?: boolean; +} + +export interface UpdateArtifactInput { + title?: string; + description?: string | null; + folder?: string; + starred?: boolean; + sourceUrl?: string | null; + artifactType?: ArtifactType; + content?: string; + restore?: boolean; +} + +/** Error carrying the server's structured `code`, e.g. `claude_share_link`. */ +export class ArtifactApiError extends Error { + constructor( + message: string, + public readonly code?: string, + public readonly status?: number + ) { + super(message); + this.name = "ArtifactApiError"; + } +} + +async function request(input: string, init?: RequestInit): Promise { + const res = await fetch(input, init); + if (!res.ok) { + const body = (await res.json().catch(() => ({}))) as { + error?: string; + message?: string; + code?: string; + }; + throw new ArtifactApiError( + body.message ?? body.error ?? `Request failed (HTTP ${res.status})`, + body.code, + res.status + ); + } + return (await res.json()) as T; +} + +export async function listArtifacts( + params: { scope?: "active" | "trash"; folder?: string } = {} +): Promise<{ artifacts: ArtifactSummary[]; folders: string[] }> { + const query = new URLSearchParams(); + if (params.scope) query.set("scope", params.scope); + if (params.folder) query.set("folder", params.folder); + return request(`/api/artifacts?${query.toString()}`); +} + +export async function importArtifact(input: ImportArtifactInput): Promise { + const body = await request<{ artifact: ArtifactDetail }>("/api/artifacts", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(input), + }); + return body.artifact; +} + +export async function getArtifact(id: number): Promise { + const body = await request<{ artifact: ArtifactDetail }>(`/api/artifacts/${id}`); + return body.artifact; +} + +export async function updateArtifact( + id: number, + patch: UpdateArtifactInput +): Promise { + const body = await request<{ artifact: ArtifactDetail }>(`/api/artifacts/${id}`, { + method: "PATCH", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(patch), + }); + return body.artifact; +} + +export async function deleteArtifact(id: number, purge = false): Promise { + await request(`/api/artifacts/${id}${purge ? "?purge=1" : ""}`, { method: "DELETE" }); +} diff --git a/apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactGallery.tsx b/apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactGallery.tsx new file mode 100644 index 000000000..19388a7df --- /dev/null +++ b/apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactGallery.tsx @@ -0,0 +1,298 @@ +"use client"; + +import React, { useCallback, useEffect, useMemo, useState } from "react"; +import { useRouter } from "next/navigation"; +import { Download, Folder, Import, Loader2, RotateCcw, Search, Star, Trash2 } from "lucide-react"; +import { toast } from "sonner"; + +import { Button } from "~/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "~/components/ui/dropdown-menu"; +import { Input } from "~/components/ui/input"; +import { cn } from "~/lib/utils"; + +import { deleteArtifact, listArtifacts, updateArtifact, type ArtifactSummary } from "../lib/api"; +import { artifactTypeMeta, formatBytes } from "./artifact-meta"; +import { ImportArtifactDialog } from "./ImportArtifactDialog"; + +/** + * The Artifacts home: everything the workspace has imported from Claude, + * with folders, search, star, trash — the same management verbs as Mindmap. + */ + +type Scope = "active" | "trash"; + +export function ArtifactGallery() { + const router = useRouter(); + const [items, setItems] = useState([]); + const [folders, setFolders] = useState([]); + const [loading, setLoading] = useState(true); + const [importOpen, setImportOpen] = useState(false); + const [query, setQuery] = useState(""); + const [scope, setScope] = useState("active"); + const [folder, setFolder] = useState(null); + + const load = useCallback(async () => { + setLoading(true); + try { + const body = await listArtifacts({ scope, folder: folder ?? undefined }); + setItems(body.artifacts); + setFolders(body.folders); + } catch { + toast.error("Couldn't load your artifacts"); + } finally { + setLoading(false); + } + }, [folder, scope]); + + useEffect(() => { + void load(); + }, [load]); + + const visible = useMemo(() => { + const q = query.trim().toLowerCase(); + if (!q) return items; + return items.filter(item => item.title.toLowerCase().includes(q)); + }, [items, query]); + + const mutate = async ( + id: number, + action: "star" | "unstar" | "trash" | "restore" | "purge" + ) => { + try { + if (action === "trash" || action === "purge") { + await deleteArtifact(id, action === "purge"); + toast.success(action === "purge" ? "Deleted permanently" : "Moved to trash"); + } else if (action === "restore") { + await updateArtifact(id, { restore: true }); + toast.success("Restored"); + } else { + await updateArtifact(id, { starred: action === "star" }); + } + await load(); + } catch { + toast.error("That didn't work — try again"); + } + }; + + return ( +
+
+

+ Claude Artifacts +

+

+ Pages, diagrams, and snippets built in Claude — imported here so they outlive + the conversation and the whole workspace can use them. +

+
+ +
+
+

+ {scope === "trash" ? "Trash" : "Your artifacts"} +

+ {visible.length} + + +
+ + setQuery(e.target.value)} + placeholder="Search…" + className="h-8 w-52 pl-8 text-[13px]" + /> +
+ + + + + + + setFolder(null)}> + All folders + + {folders.map(name => ( + setFolder(name)}> + {name} + + ))} + + + + + + +
+ + {loading ? ( +
+ + Loading… +
+ ) : visible.length === 0 ? ( +
+

+ {scope === "trash" + ? "Nothing in the trash." + : "No artifacts yet — import one from Claude to get started."} +

+ {scope === "active" && ( + + )} +
+ ) : ( +
+ {visible.map(item => { + const meta = artifactTypeMeta(item.artifactType); + return ( +
+ + +
+ {scope === "active" ? ( + <> + + void mutate( + item.id, + item.starred ? "unstar" : "star" + ) + } + > + + + + window.open( + `/api/artifacts/${item.id}/raw`, + "_blank" + ) + } + > + + + void mutate(item.id, "trash")} + > + + + + ) : ( + <> + void mutate(item.id, "restore")} + > + + + void mutate(item.id, "purge")} + > + + + + )} +
+
+ ); + })} +
+ )} +
+ + void load()} + /> +
+ ); +} + +function IconAction({ + title, + onClick, + children, +}: { + title: string; + onClick: () => void; + children: React.ReactNode; +}) { + return ( + + ); +} diff --git a/apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactPreview.tsx b/apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactPreview.tsx new file mode 100644 index 000000000..d8d5d0061 --- /dev/null +++ b/apps/web/src/app/employer/artifacts/_artifacts/ui/ArtifactPreview.tsx @@ -0,0 +1,155 @@ +"use client"; + +import { useEffect, useRef, useState } from "react"; +import { Loader2 } from "lucide-react"; + +import MarkdownMessage from "~/app/_components/MarkdownMessage"; + +/** + * Renders an imported artifact. + * + * HTML and SVG go through a sandboxed `srcDoc` iframe. The sandbox + * deliberately omits `allow-same-origin`: the artifact is untrusted code, and + * an opaque origin means its scripts can run freely without ever reaching this + * app's cookies, storage, or DOM. This is the app's first untrusted-HTML + * surface — keep the sandbox list tight if you extend it. + */ +export function ArtifactPreview({ type, content }: { type: string; content: string }) { + switch (type) { + case "html": + return ; + case "svg": + return ; + case "markdown": + return ( +
+ +
+ ); + case "mermaid": + return ; + default: + return ; + } +} + +/** Plain source text — the fallback view and the "Source" tab. */ +export function SourceView({ content }: { content: string }) { + return ( +
+            {content}
+        
+ ); +} + +function SandboxFrame({ + content, + allowScripts = false, +}: { + content: string; + allowScripts?: boolean; +}) { + const [loading, setLoading] = useState(true); + return ( +
+ {loading && ( +
+ + Rendering… +
+ )} +