diff --git a/.env.local.example b/.env.local.example index e002499..6295e28 100644 --- a/.env.local.example +++ b/.env.local.example @@ -14,3 +14,83 @@ BFF_ORIGIN=http://localhost:4000 # Installing @abe-kap/appshell-sdk (GitHub Packages) needs a read:packages token: # locally: export NODE_AUTH_TOKEN= before npm install # Vercel: set NODE_AUTH_TOKEN as a project env var + + +# =========================================================================== +# SMART GALLERY — AI routes (/api/gallery/ai/*). Full docs: docs/SMART_GALLERY.md +# =========================================================================== +# +# AUTH: these routes are session-gated. When NEXT_PUBLIC_SUPABASE_URL above is +# SET, every AI request is verified against ${BFF_ORIGIN}/api/session/context and +# a non-200 is rejected. When it is UNSET the app is in local demo mode and the +# AI routes are UNAUTHENTICATED — never expose such a deployment publicly while +# RUNPOD_API_KEY is set, or anyone can spend your GPU budget. +# +# NOTHING below is required to run the gallery: object detection, faces, OCR and +# semantic search all run FREE in-browser with no key. Only generative editing, +# transcription, denoise and tilt need RunPod. + +# --- RunPod credentials ----------------------------------------------------- +# Server-side ONLY. Never prefix with NEXT_PUBLIC_ — that would ship the key to +# the browser. Read exclusively by src/lib/server/runpod/client.ts. +RUNPOD_API_KEY=rpa_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + +# --- Per-model endpoint URLs (deploy each so the URL ends in /runsync) ------- +# Several models can share one endpoint id — that is expected, not a mistake. +RUNPOD_SD_IMG2IMG_URL=https://api.runpod.ai/v2//runsync # #10 prompt / colorize (img2img) +RUNPOD_SD_INPAINT_URL=https://api.runpod.ai/v2//runsync # #9 replace-sky / magic-eraser / generative-fill / outpaint (masked) +RUNPOD_YOLO_URL=https://api.runpod.ai/v2//runsync # #1 object detection → /api/gallery/ai/classify +RUNPOD_UPSCALE_URL=https://api.runpod.ai/v2//runsync # #7 restore / upscale (Real-ESRGAN) +RUNPOD_STT_URL=https://api.runpod.ai/v2//runsync # #3 speech-to-text → /api/gallery/ai/transcribe +RUNPOD_BG_REMOVE_URL=https://api.runpod.ai/v2//runsync # #6 background removal (U²-Net) +RUNPOD_AUDIO_DENOISE_URL=https://api.runpod.ai/v2//runsync # #12 audio denoise → /api/gallery/ai/denoise +# Optional, only if you deploy them: +# RUNPOD_TILT_URL=https://api.runpod.ai/v2//runsync # #2 camera tilt → /api/gallery/ai/tilt (needs the switch below) +# RUNPOD_COLORIZE_URL=https://api.runpod.ai/v2//runsync # #8 DDColor (currently unused — colorize goes through img2img) + +# --- Which backend serves /api/gallery/ai/edit ------------------------------ +# auto = first configured of: runpod → local → huggingface → gemini +# runpod = the RUNPOD_*_URL endpoints above (recommended) +# local = your own Stable Diffusion (A1111/Forge/SD.Next); needs LOCAL_SD_URL +# huggingface = HF Inference API; needs HF_API_TOKEN (+ optional HF_IMAGE_MODEL) +# gemini = Google Gemini; needs GEMINI_API_KEY (image output requires a BILLED key) +# none = disable generative editing entirely (503 with a clear message) +AI_EDIT_PROVIDER=runpod + +# Alternative backends (only read when AI_EDIT_PROVIDER selects them): +# LOCAL_SD_URL=http://127.0.0.1:7860 +# LOCAL_SD_DENOISE=0.55 +# LOCAL_SD_STEPS=25 +# LOCAL_SD_SAMPLER=Euler a +# HF_API_TOKEN=hf_xxxxxxxx +# HF_IMAGE_MODEL=timbrooks/instruct-pix2pix +# GEMINI_API_KEY= +# GEMINI_IMAGE_MODEL=gemini-2.5-flash-image + +# Optional Stable Diffusion tuning (defaults in src/lib/server/runpod/endpoints.ts): +# RUNPOD_SD_STEPS=35 +# RUNPOD_SD_STRENGTH=0.8 +# RUNPOD_SD_GUIDANCE=7 +# RUNPOD_SD_NEGATIVE_PROMPT= + +# --- Client-side capability switches (NEXT_PUBLIC_, inlined at BUILD time) --- +# Each must be the literal string "true" to enable; anything else is off. Because +# they are inlined at build time, changing one requires a rebuild, not a restart. +# +# false/unset = object detection runs FREE in-browser (COCO-SSD). true = use the +# RunPod YOLO classifier via /api/gallery/ai/classify (COCO-SSD stays the fallback). +# NEXT_PUBLIC_APG_RUNPOD_DETECT=false +# +# false/unset = background removal runs in-browser (@imgly WASM, no key). +# true = use the RunPod U²-Net endpoint, falling back to @imgly on failure. +NEXT_PUBLIC_APG_RUNPOD_BG=true +# +# true = show the editor's Auto-straighten button and call /api/gallery/ai/tilt. +# Only enable this if RUNPOD_TILT_URL is actually deployed. +# NEXT_PUBLIC_APG_RUNPOD_TILT=false + +# NOTE: the photo-gallery SDK also reads a family of NEXT_PUBLIC_APG_* THEMING +# vars (NEXT_PUBLIC_APG_THEME / _ACCENT / _RADIUS / _BG_DARK / _SIDEBAR_BG_* …) +# in its standalone demo. Those are NOT used here — the CRM passes `themeTokens` +# to the gallery component directly so the gallery inherits the dashboard's +# design tokens. Setting them in this file has no effect. diff --git a/.gitignore b/.gitignore index 393e8b8..450ed98 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,7 @@ next-env.d.ts .vercel .env*.local + +certificates +AI_ASSISTANT_BACKEND_PLAN.md +TEAM_MANAGEMENT_BACKEND_PLAN.md \ No newline at end of file diff --git a/LEADS_BACKEND_REQUIREMENTS.md b/LEADS_BACKEND_REQUIREMENTS.md new file mode 100644 index 0000000..1c9b1ea --- /dev/null +++ b/LEADS_BACKEND_REQUIREMENTS.md @@ -0,0 +1,827 @@ +# Leads & Lead Verification — Backend Requirements + +**Project:** LynkedUp Pro CRM (`lynkeduppro-crm`) +**Domain service:** `be-crm` (the CRM "data door") +**Modules covered:** `Leads`, `Lead Verification` +**Document status:** Implementation-ready. Derived entirely from the current frontend. +**Author basis:** Reverse-engineered from the completed frontend + the existing backend integration conventions already used by the Team, Mail, Inbox, Messenger, Media and Account modules. + +--- + +> ## ⚠️ Read this first — current state of the frontend +> +> Both modules are **fully built on the UI side but wired to client-side mock data only**. There is **no live backend call anywhere** in `leads.tsx`, `leads-data.ts`, `verify.tsx`, or `verify-data.ts`. Every "write" today (Create Lead, Verify, Mark Unverified, Change Assignee, Update Status, Call, Email, Refresh) only pushes a **toast notification** — no persistence, no network request. +> +> This means the **entire** Leads and Lead Verification backend is greenfield. However, the frontend precisely defines the required **fields, enums, filters, sub-statuses, actions and workflows**, so this document treats the mock shapes as the authoritative contract. +> +> Wherever a control exists visually but has no behaviour yet, it is tagged **`[Frontend Placeholder / Backend Pending]`** so you know it is a real requirement even though the UI does not call it yet. +> +> The design below deliberately **reuses the existing `be-crm` architecture** (query/command data door, not REST). Do **not** invent a REST API — see §11 (Existing Backend Integration) for the mandatory conventions. + +--- + +## Table of Contents + +1. [Module Overview](#1-module-overview) +2. [Existing Frontend Features (exhaustive)](#2-existing-frontend-features-exhaustive) +3. [User Flows](#3-user-flows) +4. [Database Models](#4-database-models) +5. [Entity Relationships](#5-entity-relationships) +6. [API Contract — Actions (Queries & Commands)](#6-api-contract--actions-queries--commands) +7. [Validation Rules](#7-validation-rules) +8. [Reference / Enum Data](#8-reference--enum-data) +9. [Backend Services](#9-backend-services) +10. [Error Handling](#10-error-handling) +11. [Existing Backend Integration (mandatory conventions)](#11-existing-backend-integration-mandatory-conventions) +12. [Gaps, Discrepancies & Backend-Pending Items](#12-gaps-discrepancies--backend-pending-items) + +--- + +## 1. Module Overview + +### 1.1 Leads module + +**Purpose:** The **Leads** module is the storm-restoration sales pipeline board. It holds prospective roofing jobs (door-knocked, referred, storm-chased, etc.) inside a hail-storm territory (the demo is the Plano, TX hail zone, storm event `2026-04-28`). Each lead is a rich record combining **contact**, **property**, **job details**, **insurance** and **assignment** information, and moves through a sales status pipeline. + +**Frontend surface:** `src/components/dashboard/leads.tsx` (+ `leads-data.ts`), rendered inside the dashboard shell when the `leads` nav key is active. + +**Core capabilities visible in the UI:** +- A **stat strip** (Total / New / Contacted / Appointed / Closed counts). +- A **board of lead cards** (avatar, priority ring, status pill, address, primary phone, source, canvasser, "updated" relative time). +- **Search** (by name / address / city / source / canvasser) and **status filter tabs**. +- A **lead detail modal** (Contact, Property, Job Details, Insurance, Assignment, storm banner). +- A **New Lead intake** with two modes: **Quick** (single condensed form) and **Full Form** (a 5-step wizard: Contact → Property → Job Details → Insurance → Assignment). + +### 1.2 Lead Verification module + +**Purpose:** The **Lead Verification** module is the verification desk that sits **upstream of Leads**. Freshly captured leads (door-knock / web form / storm canvass / referral / call-in) must pass an **identity + insurance + ownership + damage** verification workflow before they become working sales leads. The desk's terminal success action is literally *"Verified and pushed to New Leads"* — i.e., a verified verification record becomes a Lead with status `new`. + +**Frontend surface:** `src/components/dashboard/verify.tsx` (+ `verify-data.ts`), rendered when the `verify` nav key is active. + +**Core capabilities visible in the UI:** +- **Clickable stat tiles** (Verified / In Progress / Assigned / Pending / Unverified) that also act as status filters. +- A **data table** (Lead ID · Customer · Phone · Source · Assigned To · Status · Verification sub-status · Created · Actions). +- **Search** + **status / source / assignee** dropdown filters. +- A **row action set** (View, Verify, and a `⋯` menu: View Details, Verify Lead, Mark Unverified, Change Assignee, Reassign → In Progress, Move to Pending). +- A **verification detail modal** (Contact, Assignment, Verification Notes, and an **Activity timeline**). +- A **Refresh** button. + +### 1.3 Relationship between the two modules + +``` + Intake sources Lead Verification desk Leads pipeline + (door knock, web form, ─────► verify identity / ownership / ─────► status = "new" + storm canvass, referral, insurance / damage → contacted → appointed + call-in) (verified | in_progress | → closed + assigned | pending | unverified) +``` + +- A **Lead Verification** record is the *pre-lead*. When it reaches `verified`, the system **creates / promotes** it into a **Lead** (`status = "new"`). This is the single hard link between the two modules and the most important cross-module command to implement (see `crm.leadVerification.verify` in §6). +- Both modules are gated by the **same** CRM permission: **`leads.manage`** (see `NAV_PERMISSION` in `sidebar.tsx`). There is no separate verification permission in the frontend. +- Both are **tenant-scoped** — every record belongs to the signed-in user's organization/tenant (the demo boots as `tenant-acme-01`). + +### 1.4 User journey (end-to-end) + +1. A lead is **captured** at an intake source and lands in the **Verification** queue as `pending` (unassigned) or `assigned`. +2. A **verification specialist** (Wade Hollis, Darlene Brooks, Roy Schaefer in the mock) is assigned and works the record through sub-statuses (`Verifying Identity` → `Confirming Ownership` → `Reviewing Insurance` → `Confirming Damage`). +3. The specialist either **Verifies** it (→ becomes a Lead, `status = new`) or **Marks Unverified**. +4. In the **Leads** module, a sales rep / canvasser works the new lead: **Contacted** → **Appointed** → **Closed**, updating status, priority, follow-up date, insurance/claim details and assignment along the way. + +--- + +## 2. Existing Frontend Features (exhaustive) + +Only features actually present in the code are listed. Each is tagged **Wired** (has real logic, even if only client-side state) or **`[Placeholder / Backend Pending]`** (UI exists, no behaviour beyond a toast). + +### 2.1 Leads module features + +| # | Feature | State | Notes / source | +|---|---------|-------|----------------| +| L1 | Lead board / card list | Wired (mock) | `LEADS` array rendered as `LeadCard`s | +| L2 | Header stat strip (Total, New, Contacted, Appointed, Closed) | Wired (mock) | `countByStatus`; `TOTAL_LEADS = 35` shown as total | +| L3 | Text search (name, address, city, source, canvasser) | Wired (mock) | `filtered` memo, case-insensitive substring | +| L4 | Status filter tabs (All / New / Contacted / Appointed / Closed) | Wired (mock) | `STATUS_TABS` | +| L5 | Lead detail modal (Contact, Property, Job, Insurance, Assignment, storm banner) | Wired (mock, read-only) | `LeadDetail` | +| L6 | Create Lead — Quick mode | **Placeholder** | `submit()` only validates name then toasts; no persistence | +| L7 | Create Lead — Full Form wizard (5 steps) | **Placeholder** | steps: Contact / Property / Job / Insurance / Assignment | +| L8 | Multiple phone numbers (with type Mobile/Home/Work + primary) | Wired (form state) | `addPhone/setPhone/removePhone` | +| L9 | Multiple email addresses | Wired (form state) | `addEmail/setEmail/removeEmail` | +| L10 | Site photos upload | **Placeholder** | `addPhoto()` just appends a label string `"Photo N"` — no real upload | +| L11 | Conditional field: Referral note (source = Referral) | Wired (form state) | `f.source === "Referral"` | +| L12 | Conditional field: Canvasser search (source = Door Knock) | Wired (form state) | `CanvasserSearch` typeahead over `REPS` | +| L13 | Priority picker (Low / Medium / High) | Wired (form state) | `PriorityPicker` | +| L14 | Urgency picker (Standard / High / Emergency) | Wired (form state) | `UrgencyPicker` | +| L15 | Rep assignment select (incl. "Unassigned") | Wired (form state) | `RepSelect`, options from `REPS` | +| L16 | Detail action: **Update Status** | **Placeholder** | footer button, no handler | +| L17 | Detail action: **Call** / **Email** | **Placeholder** | footer buttons, no handler | +| L18 | Empty state ("No leads match") | Wired | shown when `filtered.length === 0` | + +**Not present in Leads (do not build unless requested):** edit-existing-lead form, delete, archive, bulk actions, tags editor (only a single static `tag` string exists), notes/comments thread, per-lead activity timeline, attachments list, pagination controls, sorting controls, export. + +### 2.2 Lead Verification module features + +| # | Feature | State | Notes / source | +|---|---------|-------|----------------| +| V1 | Stat tiles (Verified / In Progress / Assigned / Pending / Unverified) | Wired (mock) | `STAT_ORDER`, counts from `V_LEADS` | +| V2 | Stat tile click = status filter toggle | Wired (mock) | `setStatus(status === s ? "all" : s)` | +| V3 | Verification table (9 columns) | Wired (mock) | see column list in §1.2 | +| V4 | Text search (name, lead ID, phone, source, address) | Wired (mock) | `rows` memo | +| V5 | Status filter dropdown | Wired (mock) | mirrors stat tiles | +| V6 | Source filter dropdown | Wired (mock) | `V_SOURCES` | +| V7 | Assignee filter dropdown | Wired (mock) | `V_ASSIGNEES` | +| V8 | Row action: **View details** | Wired (mock) | opens `VerifyDetail` | +| V9 | Row action: **Verify** (quick) | **Placeholder** | toast only | +| V10 | Row `⋯` menu | Wired (open/close) | portalled dropdown | +| V11 | Menu: Verify Lead | **Placeholder** | toast only | +| V12 | Menu: Mark Unverified | **Placeholder** | toast only | +| V13 | Menu: Change Assignee | **Placeholder** | toast only | +| V14 | Menu: Reassign (→ In Progress) | **Placeholder** | toast only | +| V15 | Menu: Move to Pending | **Placeholder** | toast only | +| V16 | Detail modal — Contact / Assignment sections | Wired (mock, read) | `VerifyDetail` | +| V17 | Detail modal — Verification Notes | Wired (mock, read) | shown when `notes` present | +| V18 | Detail modal — Activity timeline | Wired (mock, read + derived) | `buildActivity()` synthesizes when absent | +| V19 | Detail footer: Verify Lead / Call | **Placeholder** | buttons, no handler | +| V20 | Refresh button | **Placeholder** | toast only ("Queue refreshed") | +| V21 | Row count "X of Y leads" | Wired (mock) | implies server total vs filtered count | +| V22 | Derived email / created-at when absent | Wired (mock) | `deriveEmail`, `deriveCreatedAt` | + +**Not present in Verification (do not build unless requested):** create-verification-from-UI (records arrive via intake, never created here — mirrors the Inbox "items are never created here" pattern), delete, bulk verify, attachments, document upload, editable contact fields. + +--- + +## 3. User Flows + +### 3.1 Lead Verification status flow + +Statuses (`VStatus`): `unverified`, `pending`, `assigned`, `in_progress`, `verified`. +Each status also carries a human **sub-status** string (`verification`). + +``` + intake (door knock / web form / storm canvass / referral / call-in) + │ + ▼ + ┌──────────── pending ("Pending Review", unassigned) ────────────┐ + │ │ │ + │ [Change Assignee] │ + │ ▼ │ + │ assigned ("Assigned") │ + │ │ │ + │ [Reassign / start work] │ + │ ▼ │ + │ in_progress ("Verifying Identity" / │ + │ "Confirming Ownership" / │ + │ "Reviewing Insurance" / │ + │ "Confirming Damage") │ + │ │ │ │ + │ [Verify]│ │[Mark Unverified] │ + │ ▼ ▼ │ + │ verified unverified ◄─────────────────────┘ + │ ("Verified") ("Unverified") + │ │ + │ ▼ + │ ┌───────────────────────────────┐ + └────►│ PROMOTE → create Lead(status = │ + │ "new") + activity "Verified │ + │ and pushed to New Leads." │ + └───────────────────────────────┘ + + [Move to Pending] can send an assigned/in_progress record back to pending. +``` + +**Allowed transitions (enforce server-side):** + +| From | To | Trigger command | +|------|----|-----------------| +| `pending` | `assigned` | `assign` (set assignee) | +| `pending` / `assigned` / `in_progress` | `in_progress` | `reassign` / `setInProgress` | +| `assigned` / `in_progress` | `pending` | `moveToPending` | +| `pending` / `assigned` / `in_progress` | `verified` | `verify` (→ promotes to Lead) | +| `pending` / `assigned` / `in_progress` | `unverified` | `markUnverified` | +| any | (assignee change) | `assign` / `changeAssignee` | + +> The frontend does not restrict transitions (every action is available on every row), so treat the table above as the **recommended** guard set; at minimum, forbid transitions out of a terminal `verified` record except via an explicit re-open (backend-pending, not in UI). + +### 3.2 Lead sales status flow + +Statuses (`LeadStatus`): `new`, `contacted`, `appointed`, `closed`. + +``` + (created directly OR promoted from a verified verification) + │ + ▼ + new + │ [Update Status] / rep works the lead + ▼ + contacted + │ + ▼ + appointed (adjuster / inspection appointment set) + │ + ▼ + closed (won/installed/paid — mock leans "won") +``` + +`priority` (`high` / `medium` / `low`) and `job.urgency` (`Standard` / `High` / `Emergency`) are independent of status and set at creation / update. + +### 3.3 Create Lead (Full Form wizard) flow + +``` + Step 1 Contact → firstName*, lastName, phones[] (type + primary), emails[] + Step 2 Property → address, city, state (default "TX"), zip, propertyType, photos[] + Step 3 Job → source, leadType, workType, tradeType, urgency, notes + (source=Referral → referralNote; source=Door Knock → canvasser) + Step 4 Insurance → insCompany, claimNumber, claimStatus, adjusterName, + adjusterPhone, policyNumber + Step 5 Assignment→ assignRep (or Unassigned), priority, followUp date + → [Create Lead] → crm.lead.create +``` + +Quick mode collects a condensed subset (firstName*, lastName, phone[0], address, city, state, zip, source, [referralNote|canvasser], priority, followUp) and submits the same `crm.lead.create`. + +`*` = the only field the frontend currently enforces is a non-empty **name** (first or last). + +--- + +## 4. Database Models + +Storage assumptions follow the existing `be-crm` domain service (relational, multi-tenant). **Every table carries `tenant_id`** and is always filtered by it. Primary keys are opaque server IDs; the human-facing **codes** (`SAL-001`, `LD-V-001`) are separate, per-tenant, monotonic display identifiers. + +Timestamps are stored as `timestamptz` (UTC, ISO-8601 on the wire). Relative strings like `"3d ago"` and pretty dates like `"Jun 4, 2026"` seen in the mock are **presentation-only** — the API returns ISO timestamps and the client formats them (see `relTime()` in `team-api.ts`). + +### 4.1 `leads` + +**Purpose:** One row per sales lead (the Leads board card + detail modal). + +| Field | Type | Null | Default | Notes | +|-------|------|------|---------|-------| +| `id` | uuid / string PK | no | gen | opaque server id | +| `tenant_id` | uuid/string FK → organizations | no | — | tenant scope; **indexed** | +| `code` | text | no | seq | display code `SAL-001`; **unique per tenant** | +| `first_name` | text | no | — | | +| `last_name` | text | yes | null | name = `first + last`, trimmed | +| `status` | enum `lead_status` | no | `'new'` | `new` \| `contacted` \| `appointed` \| `closed` | +| `priority` | enum `lead_priority` | no | `'medium'` | `high` \| `medium` \| `low` (UI Quick default = Medium) | +| `tag` | text | yes | `'Storm Zone'` | single label chip | +| `property_address` | text | yes | null | | +| `property_city` | text | yes | null | | +| `property_state` | text | yes | `'TX'` | 2-letter; UI default TX | +| `property_zip` | text | yes | null | | +| `property_type` | text | yes | null | see `PROPERTY_TYPES` enum | +| `source` | text | yes | null | see `LEAD_SOURCES` enum | +| `referral_note` | text | yes | null | only when `source = 'Referral'` | +| `lead_type` | text | yes | null | see §12 note on the enum conflict | +| `work_type` | text | yes | null | see `WORK_TYPES` | +| `trade_type` | text | yes | null | see `TRADE_TYPES` | +| `urgency` | enum `lead_urgency` | no | `'Standard'` | `Standard` \| `High` \| `Emergency` | +| `job_notes` | text | yes | null | "Field Notes" | +| `canvasser_id` | FK → members | yes | null | door-knock canvasser (REP id, e.g. `LUP-1040`) | +| `insurance_company` | text | yes | null | | +| `insurance_claim_status` | enum `claim_status` | yes | null | `Not Filed`\|`Filed`\|`Approved`\|`Paid`\|`Denied` | +| `insurance_claim_number` | text | yes | null | | +| `insurance_policy_number` | text | yes | null | | +| `insurance_adjuster_name` | text | yes | null | | +| `insurance_adjuster_phone` | text | yes | null | | +| `assigned_to_id` | FK → members | yes | null | rep working the lead | +| `follow_up_date` | date | yes | null | | +| `storm_zone` | text | yes | null | e.g. "E Plano / Spring Creek Pkwy" | +| `storm_date` | date | yes | null | e.g. `2026-04-28` | +| `storm_detail` | text | yes | null | e.g. `2.5" hail (severe)` | +| `source_verification_id` | FK → lead_verifications | yes | null | set when promoted from a verification | +| `created_by_id` | FK → members | yes | null | | +| `created_at` | timestamptz | no | now() | | +| `updated_at` | timestamptz | no | now() | drives "updated 3d ago" | + +**Indexes:** `(tenant_id)`, `(tenant_id, status)`, `(tenant_id, code)` unique, `(tenant_id, assigned_to_id)`, `(tenant_id, source)`, `(tenant_id, updated_at desc)`. +**Search:** the board search covers name + property address + city + source + canvasser → back with a `tsvector` / trigram index over those columns. + +**Example row (from `SAL-001`):** +```json +{ + "id": "ld_9f2c…", "code": "SAL-001", + "firstName": "John", "lastName": "Martinez", + "status": "contacted", "priority": "high", "tag": "Storm Zone", + "propertyAddress": "4821 Spring Creek Pkwy", "propertyCity": "Plano", + "propertyState": "TX", "propertyZip": "75023", "propertyType": "Single Family", + "source": "Door Knock", "leadType": "Insurance", + "workType": "Roof Replacement", "tradeType": "Roofing", "urgency": "High", + "jobNotes": "Homeowner showed significant granule loss…", + "canvasserId": "LUP-1040", + "insuranceCompany": "State Farm", "insuranceClaimStatus": "Filed", + "insuranceClaimNumber": "CLM-2026-1000", "insurancePolicyNumber": "POL-080000", + "insuranceAdjusterName": "Marcus Powell", "insuranceAdjusterPhone": "(972) 700-3000", + "assignedToId": "LUP-…", "followUpDate": "2026-06-04", + "stormZone": "E Plano / Spring Creek Pkwy", "stormDate": "2026-04-28", + "stormDetail": "2.5\" hail (severe)", + "createdById": "LUP-1040", "createdAt": "2026-05-28T15:00:00Z", "updatedAt": "…" +} +``` + +### 4.2 `lead_phones` + +**Purpose:** A lead has 1..N phone numbers, one primary. + +| Field | Type | Null | Default | Notes | +|-------|------|------|---------|-------| +| `id` | PK | no | gen | | +| `tenant_id` | FK | no | — | | +| `lead_id` | FK → leads | no | — | **on delete cascade** | +| `number` | text | no | — | free-form display, e.g. `(469) 500-1000` | +| `type` | enum `phone_type` | no | `'Mobile'` | `Mobile` \| `Home` \| `Work` | +| `is_primary` | bool | no | false | exactly one true per lead (enforce) | +| `position` | int | no | 0 | display order | + +**Indexes:** `(lead_id)`. **Constraint:** partial unique `(lead_id) where is_primary` to guarantee a single primary. + +### 4.3 `lead_emails` + +| Field | Type | Null | Default | Notes | +|-------|------|------|---------|-------| +| `id` | PK | no | gen | | +| `tenant_id` | FK | no | — | | +| `lead_id` | FK → leads | no | — | cascade | +| `address` | text | no | — | validate email format | +| `type` | text | yes | null | optional label | +| `is_primary` | bool | no | false | | +| `position` | int | no | 0 | | + +### 4.4 `lead_attachments` (site photos) — `[Backend Pending]` + +**Purpose:** Backs the "Site Photos" uploader (L10). The frontend currently only stores placeholder labels; the real implementation must use the existing media presign flow (§11.5). + +| Field | Type | Null | Default | Notes | +|-------|------|------|---------|-------| +| `id` | PK | no | gen | | +| `tenant_id` | FK | no | — | | +| `lead_id` | FK → leads | no | — | cascade | +| `content_ref` | text | no | — | IIOS object key from `crm.media.presignUpload` | +| `mime_type` | text | no | — | | +| `size_bytes` | bigint | no | — | ≤ `26_214_400` (25 MB) | +| `filename` | text | yes | null | | +| `uploaded_by_id` | FK → members | yes | null | | +| `created_at` | timestamptz | no | now() | | + +### 4.5 `lead_status_history` (audit) — recommended + +**Purpose:** Backs "Update Status" auditing (no dedicated Leads timeline UI exists yet, but status changes must be auditable and this feeds a future timeline). Mirrors the verification activity concept. + +| Field | Type | Null | Notes | +|-------|------|------|-------| +| `id` | PK | no | | +| `tenant_id` | FK | no | | +| `lead_id` | FK → leads | no | cascade | +| `from_status` | enum | yes | null on create | +| `to_status` | enum | no | | +| `actor_id` | FK → members | yes | | +| `note` | text | yes | | +| `created_at` | timestamptz | no | | + +### 4.6 `lead_verifications` + +**Purpose:** One row per verification-desk record (the Verification table row + detail). + +| Field | Type | Null | Default | Notes | +|-------|------|------|---------|-------| +| `id` | PK | no | gen | | +| `tenant_id` | FK | no | — | indexed | +| `code` | text | no | seq | display code `LD-V-001`; **unique per tenant** | +| `name` | text | no | — | customer full name (single field in UI) | +| `phone` | text | yes | null | | +| `email` | text | yes | null | derived client-side when absent (see `deriveEmail`) | +| `address` | text | yes | null | single-line address string in UI | +| `source` | text | no | — | see `V_SOURCES` (`Door Knock`, `Web Form`, `Storm Canvass`, `Referral`, `Call-In`) | +| `status` | enum `verification_status` | no | `'pending'` | `verified`\|`in_progress`\|`assigned`\|`pending`\|`unverified` | +| `sub_status` | text | no | `'Pending Review'` | the `verification` label, see §8.6 | +| `assignee_id` | FK → members | yes | null | verification specialist | +| `notes` | text | yes | null | "Verification Notes" | +| `promoted_lead_id` | FK → leads | yes | null | set when verified → Lead created | +| `verified_at` | timestamptz | yes | null | | +| `created_at` | timestamptz | no | now() | drives "Created" column | +| `updated_at` | timestamptz | no | now() | | + +**Indexes:** `(tenant_id)`, `(tenant_id, status)`, `(tenant_id, source)`, `(tenant_id, assignee_id)`, `(tenant_id, code)` unique, `(tenant_id, created_at desc)`. +**Search:** name + code + phone + source + address → trigram/tsvector. + +**Example rows (from `LD-V-001` and a lean one):** +```json +{ "id":"lv_1…","code":"LD-V-001","name":"Kevin Hartley", + "phone":"(972) 413-8902","email":"kevin.hartley@gmail.com", + "address":"2814 Ravenswood Dr, Plano, TX 75023","source":"Door Knock", + "status":"verified","subStatus":"Verified","assigneeId":"…Wade…", + "notes":"Ownership confirmed via county records…", + "verifiedAt":"2026-05-16T19:55:00Z","createdAt":"2026-05-14T14:40:00Z" } + +{ "id":"lv_11…","code":"LD-V-011","name":"Aaron Blake", + "phone":"(469) 471-3350","address":"1188 Alma Dr, Plano, TX 75075", + "source":"Door Knock","status":"pending","subStatus":"Pending Review", + "assigneeId":null,"createdAt":"2026-05-27T…" } +``` + +### 4.7 `lead_verification_activities` + +**Purpose:** The Activity timeline in the verification detail (V18). The frontend synthesizes these when absent (`buildActivity`), but the backend should persist real ones. + +| Field | Type | Null | Notes | +|-------|------|------|-------| +| `id` | PK | no | | +| `tenant_id` | FK | no | | +| `verification_id` | FK → lead_verifications | no | cascade | +| `text` | text | no | e.g. "Assigned to Wade Hollis." | +| `actor_id` | FK → members | yes | maps to `who` (name shown; "System" when null) | +| `actor_label` | text | yes | denormalized display name / "System" | +| `occurred_at` | timestamptz | no | maps to `time` | +| `kind` | text | yes | optional: `submitted`\|`assigned`\|`in_progress`\|`verified`\|`unverified`\|`note` | + +**Index:** `(verification_id, occurred_at)`. + +### 4.8 Referenced existing tables (do **not** recreate) + +- **`organizations` / tenant** — tenant scope (`tenant_id`). Established at boot / registration (`crm.account.register`). +- **`members`** — CRM team members (reps, canvassers, verification specialists). Already served by `crm.team.member.search` and carry ids like `LUP-1040` plus `principalId`. Leads/verifications reference members for `assigned_to`, `canvasser`, `assignee`, `created_by`, and activity `actor`. In the mock these are free-text names — the backend must resolve them to member ids (see §12). +- **Account/permissions** — `crm.account.me` drives `leads.manage` gating. + +--- + +## 5. Entity Relationships + +``` +organizations (tenant) + 1 ──────────────< leads + 1 ──────────────< lead_verifications + 1 ──────────────< members + +members + 1 ──< leads.assigned_to_id + 1 ──< leads.canvasser_id + 1 ──< leads.created_by_id + 1 ──< lead_verifications.assignee_id + 1 ──< lead_verification_activities.actor_id + 1 ──< lead_status_history.actor_id + +leads + 1 ──< lead_phones (cascade) + 1 ──< lead_emails (cascade) + 1 ──< lead_attachments (cascade) [backend-pending] + 1 ──< lead_status_history (cascade) + +lead_verifications + 1 ──< lead_verification_activities (cascade) + 1 ──0..1 leads (promotion: lead_verifications.promoted_lead_id + ⇆ leads.source_verification_id) +``` + +**Cardinality summary** + +| Relationship | Type | Notes | +|--------------|------|-------| +| tenant → lead | 1‑to‑many | all leads tenant-scoped | +| tenant → verification | 1‑to‑many | | +| lead → phones | 1‑to‑many | ≥1, exactly one primary | +| lead → emails | 1‑to‑many | 0..N | +| lead → attachments | 1‑to‑many | 0..N (pending) | +| lead → status history | 1‑to‑many | audit | +| verification → activities | 1‑to‑many | timeline | +| verification → lead | 1‑to‑(0..1) | promotion link, bidirectional FK | +| member → lead (assigned/canvasser/creator) | many‑to‑1 each | nullable | +| member → verification (assignee) | many‑to‑1 | nullable | + +**Embedded value objects (not separate tables — stored as columns on `leads`):** `storm { zone, date, detail }`, `property { … }`, `job { … }`, `insurance { … }`, `assignment { … }`. They are grouped only for UI sectioning; there is no reuse that justifies separate tables. Phones and emails **are** separate tables because they are 1‑to‑many. + +--- + +## 6. API Contract — Actions (Queries & Commands) + +> **Transport & style (mandatory):** These are **not REST routes**. They are `be-crm` **data-door actions** invoked through the AppShell SDK exactly like every other module: +> - **Reads:** `useQuery("", variables)` → resolves to `T` (or `null` while loading). Errors surface as an `Error` with `.message`. +> - **Writes:** `sdk.command("", variables)` → resolves to `T`. Commands carry an auto-generated idempotency key. +> - **Action naming:** `crm..` — dot-namespaced, camelCase segments (matches `crm.team.member.setRoles`, `crm.inbox.transition`, `crm.mail.reply`). +> - **Collection reads** return either a bare array (like `crm.mail.list`, `crm.inbox.list`) or `{ items: T[], meta }` (like `crm.team.member.search`). For Leads/Verification use **`{ items, meta }`** because the UI needs totals + pagination (§6.1). + +### 6.1 Standard collection envelope + +```ts +interface Meta { total: number; page: number; perPage: number; } +interface Page { items: T[]; meta: Meta; } +``` +- `verify.tsx` renders `"{rows.length} of {V_LEADS.length} leads"` → `rows.length` is the filtered page length, `meta.total` is the (filtered or overall) count. Return the **filtered** total so the "X of Y" reads correctly, plus the unfiltered stat counts via the dedicated `*.stats` action. +- `leads.tsx` shows `TOTAL_LEADS = 35` while only rendering 5 cards → the board is paginated/capped server-side; provide `perPage` (UI has no pager control yet, so default a sensible `perPage`, e.g. 50, and return `meta.total` for the header). + +### 6.2 Leads — Queries + +| Action | Variables | Returns | Backs | +|--------|-----------|---------|-------| +| `crm.lead.search` | `{ query?, status?, priority?, source?, assigneeId?, page?, perPage? }` | `Page` | board list L1, search L3, tabs L4 | +| `crm.lead.get` | `{ id }` | `LeadDTO` (full detail incl. phones/emails/attachments) | detail modal L5 | +| `crm.lead.stats` | `{}` | `{ total: number, byStatus: { new, contacted, appointed, closed } }` | stat strip L2 | + +`LeadCardDTO` (list projection — only what the card needs): +```ts +{ id, code, name, initials, gradient, priority, status, tag, + primaryPhone, propertyAddress, propertyCity, propertyState, + source, canvasserName, updatedAt } +``` +`LeadDTO` (detail projection): all §4.1 columns + `phones: Phone[]` + `emails: Email[]` + `attachments: Attachment[]` + resolved assignee/canvasser/creator display names + `storm`, `property`, `job`, `insurance`, `assignment` groupings. + +### 6.3 Leads — Commands + +| Action | Variables | Returns | Backs | +|--------|-----------|---------|-------| +| `crm.lead.create` | full create payload (below) | `LeadDTO` | Create Lead L6/L7 | +| `crm.lead.update` | `{ id, patch: Partial }` | `LeadDTO` | edit (backend-pending; UI edit form not built) | +| `crm.lead.updateStatus` | `{ id, status, note? }` | `LeadDTO` | detail "Update Status" L16 | +| `crm.lead.assign` | `{ id, assigneeId \| null }` | `LeadDTO` | rep assignment L15 | +| `crm.lead.attachment.add` | `{ id, attachment: { contentRef, mimeType, sizeBytes, filename } }` | `LeadDTO` | site photos L10 (pending) | +| `crm.lead.attachment.remove` | `{ id, attachmentId }` | `LeadDTO` | pending | +| `crm.lead.archive` | `{ id }` | `{ id }` | **pending** — no UI yet; include only if requested | +| `crm.lead.delete` | `{ id }` | `{ id }` | **pending** — no UI yet; include only if requested | + +**`crm.lead.create` payload** (union of Quick + Full form, all optional except `firstName`/`lastName` where at least one non-empty): +```ts +{ + firstName: string, lastName?: string, + phones: { number: string, type: "Mobile"|"Home"|"Work", primary?: boolean }[], + emails?: { address: string, primary?: boolean }[], + property?: { address?, city?, state?, zip?, type? }, + photos?: { contentRef, mimeType, sizeBytes, filename }[], // real uploads (pending) + job?: { source?, referralNote?, canvasserId?, leadType?, workType?, tradeType?, + urgency?: "Standard"|"High"|"Emergency", notes? }, + insurance?: { company?, claimNumber?, claimStatus?, adjusterName?, + adjusterPhone?, policyNumber? }, + assignment?: { assigneeId?: string|null, priority?: "Low"|"Medium"|"High", + followUp?: string /* ISO date */ } +} +``` +> Note the **priority casing mismatch**: the create form emits `"Low"|"Medium"|"High"` (title-case) while list/detail data uses `"low"|"medium"|"high"`. Normalize to lowercase on write (see §12). + +### 6.4 Lead Verification — Queries + +| Action | Variables | Returns | Backs | +|--------|-----------|---------|-------| +| `crm.leadVerification.search` | `{ query?, status?, source?, assigneeId?, page?, perPage? }` | `Page` | table V3, search V4, filters V5–V7 | +| `crm.leadVerification.get` | `{ id }` | `VerificationDTO` (+ activities) | detail V16–V18 | +| `crm.leadVerification.stats` | `{}` | `{ verified, in_progress, assigned, pending, unverified }` | stat tiles V1 | +| `crm.leadVerification.activity.list` | `{ id }` | `VerificationActivity[]` | timeline V18 (or embed in `.get`) | + +`VerificationRowDTO`: +```ts +{ id, code, name, initials, address, phone, source, + assignee: { id, initials, name } | null, + status, verification /* sub_status */, createdAt } +``` +`VerificationDTO`: adds `email`, `notes`, `verifiedAt`, `promotedLeadId`, `activities[]`. + +### 6.5 Lead Verification — Commands + +| Action | Variables | Returns | Backs | +|--------|-----------|---------|-------| +| `crm.leadVerification.verify` | `{ id, notes? }` | `{ verification: VerificationDTO, lead: LeadDTO }` | Verify V9/V11/V19 — **promotes to Lead** | +| `crm.leadVerification.markUnverified` | `{ id, reason? }` | `VerificationDTO` | Mark Unverified V12 | +| `crm.leadVerification.assign` | `{ id, assigneeId }` | `VerificationDTO` | Change Assignee V13 | +| `crm.leadVerification.reassign` | `{ id, assigneeId? }` | `VerificationDTO` | Reassign → In Progress V14 | +| `crm.leadVerification.moveToPending` | `{ id }` | `VerificationDTO` | Move to Pending V15 | +| `crm.leadVerification.updateStatus` | `{ id, status, subStatus? }` | `VerificationDTO` | generic status set (covers sub-status changes) | +| `crm.leadVerification.note.add` | `{ id, text }` | `VerificationDTO` | verification notes (pending edit UI) | + +**`crm.leadVerification.verify` behaviour (the critical cross-module command):** +1. Load verification; guard status is not already `verified`. +2. Set `status = 'verified'`, `sub_status = 'Verified'`, `verified_at = now()`, persist `notes` if provided. +3. **Create a `leads` row** (`status = 'new'`) from the verification's contact/address/source, linking `leads.source_verification_id = verification.id` and `verification.promoted_lead_id = lead.id`. +4. Append activity: `"Verified and pushed to New Leads."` (actor = current user). +5. Return both records so the UI can refresh both queues. +6. Idempotent: a second call with the same idempotency key must not create a duplicate Lead. + +### 6.6 Shared / reused actions (already exist — reuse, don't rebuild) + +| Action | Use in Leads/Verification | +|--------|---------------------------| +| `crm.account.me` | `leads.manage` permission gate for both modules | +| `crm.team.member.search { perPage }` | rep / canvasser / assignee pickers (`REPS`, `V_ASSIGNEES`) | +| `crm.media.presignUpload { mime, sizeBytes }` → `{ objectKey, uploadUrl }` | site-photo upload (browser PUTs bytes directly) | +| `crm.media.presignDownload { contentRef }` → `{ url }` | render/download a lead photo | + +--- + +## 7. Validation Rules + +### 7.1 `crm.lead.create` / `crm.lead.update` + +| Field | Required | Rule | +|-------|----------|------| +| name (`firstName`/`lastName`) | **Yes** (at least one non-empty after trim) | matches the only current UI guard: `` `${first} ${last}`.trim() `` must be non-empty → else error `name_required` | +| `phones[].number` | No | free-form; if present, strip to digits server-side for storage/dedupe (form already does `phone.replace(/\D/g,"")` in registration) | +| `phones[].type` | with phone | enum `Mobile\|Home\|Work` | +| `phones` primary | — | at most one `primary: true`; if none set, mark the first as primary | +| `emails[].address` | No | RFC-5322-ish email format when present | +| `property.state` | No | 2-letter US state; default `TX` | +| `property.zip` | No | 5-digit (or ZIP+4) when present | +| `property.type` | No | one of `PROPERTY_TYPES` (§8.4) | +| `source` | No | one of `LEAD_SOURCES` (§8.1) | +| `referralNote` | Conditional | accept only when `source = 'Referral'` (UI shows it only then) | +| `canvasserId` | Conditional | resolve to a member; UI surfaces the picker only when `source = 'Door Knock'`, but accept whenever provided | +| `leadType` | No | see §12 enum conflict — accept the UI's `Residential\|Commercial\|Multi-Family` **and** the data model's `Insurance\|Retail`; store raw, do not hard-reject | +| `workType` | No | one of `WORK_TYPES` | +| `tradeType` | No | one of `TRADE_TYPES` | +| `urgency` | No | enum `Standard\|High\|Emergency`; default `Standard` | +| `insurance.claimStatus` | No | enum `Not Filed\|Filed\|Approved\|Paid\|Denied` | +| `priority` | No | accept `Low\|Medium\|High` (form) → normalize to `low\|medium\|high`; default `medium` | +| `assignment.followUp` | No | valid ISO date; may be null/`"—"` | +| `assignment.assigneeId` | No | resolve to a member or `null` (Unassigned) | + +**Business validations:** +- `code` (`SAL-###`) is server-generated, unique per tenant — never accepted from the client. +- Duplicate detection (recommended, not in UI): warn (not block) if an active lead exists with the same primary phone **or** same property address within the tenant. +- All member references (`assigneeId`, `canvasserId`) must belong to the same tenant. + +### 7.2 Verification commands + +| Command | Rule | +|---------|------| +| `verify` | reject if already `verified` (`already_verified`); require the record exists in tenant; create exactly one Lead (idempotent) | +| `assign` / `reassign` | `assigneeId` must be a tenant member; `assign` moves `pending → assigned` (or updates assignee); `reassign` sets `in_progress` | +| `markUnverified` | allowed from any non-terminal state; optional `reason` recorded as activity | +| `moveToPending` | allowed from `assigned` / `in_progress`; clears/keeps assignee per product choice (UI does not specify — keep assignee, set `status=pending`, `sub_status='Pending Review'`) | +| `updateStatus` | `status ∈ verification_status`; if `subStatus` omitted, default it from the status (§8.6 mapping) | +| `note.add` | `text` non-empty, trimmed, reasonable max length (e.g. 5 000 chars) | + +**Enums must be validated server-side even though the frontend does not enforce them** — the frontend is permissive (free selects), so the backend is the source of truth. + +--- + +## 8. Reference / Enum Data + +Exact values, copied from `leads-data.ts` and `verify-data.ts`. Provide these either as DB enums or as a reference-data query (`crm.lead.options` — optional) so the UI selects stay in sync. + +### 8.1 `LEAD_SOURCES` +`Door Knock`, `Referral`, `Storm Chase`, `Mailer / Postcard`, `Sign Call`, `Insurance Agent Referral`, `Repeat Customer`, `Social Media`, `Other` + +### 8.2 `WORK_TYPES` +`Roof Replacement`, `Roof Repair`, `Inspection`, `Gutter Install` + +### 8.3 `TRADE_TYPES` +`Roofing`, `Gutters`, `Siding`, `Windows` + +### 8.4 `PROPERTY_TYPES` +`Single Family`, `Multi Family`, `Commercial` +*(the Full-form Property step also offers `Residential`, `Commercial`, `Multi-Family`, `Industrial` via `PROPERTY_TYPE_OPTS` — accept the superset; see §12)* + +### 8.5 `CLAIM_STATUSES` +`Not Filed`, `Filed`, `Approved`, `Paid`, `Denied` + +### 8.6 Verification statuses → default sub-status label + +| `status` | default `sub_status` | other observed sub-status labels | +|----------|----------------------|----------------------------------| +| `verified` | `Verified` | — | +| `in_progress` | `Verifying Identity` | `Reviewing Insurance`, `Confirming Ownership`, `Confirming Damage` | +| `assigned` | `Assigned` | — | +| `pending` | `Pending Review` | — | +| `unverified` | `Unverified` | — | + +### 8.7 Verification sources (`V_SOURCES`) +`Door Knock`, `Web Form`, `Storm Canvass`, `Referral`, `Call-In` +*(note: different set from Lead sources §8.1 — keep them as separate reference lists)* + +### 8.8 Lead statuses / priorities / urgency +- `lead_status`: `new`, `contacted`, `appointed`, `closed` +- `lead_priority`: `high`, `medium`, `low` (create form emits title-case `Low`/`Medium`/`High`) +- `lead_urgency`: `Standard`, `High`, `Emergency` +- `phone_type`: `Mobile`, `Home`, `Work` +- `lead_type`: **conflicting** — `Insurance`/`Retail` (data) vs `Residential`/`Commercial`/`Multi-Family` (form). See §12. + +### 8.9 Seed members (reps / canvassers / verification specialists) + +Reps (`REPS`, ids are real member codes): `LUP-1040 Cody Tatum`, `LUP-1041 Hannah Reyes`, `LUP-1042 Travis Boone`, `LUP-1043 Shelby Greer`, `LUP-1044 Dalton Pruitt`. +Verification specialists (`V_ASSIGNEES`): `Wade Hollis`, `Darlene Brooks`, `Roy Schaefer`. + +--- + +## 9. Backend Services + +Break the implementation into services mirroring the existing `be-crm` module layout (one bounded context per data-door namespace). + +| Service | Namespace | Responsibilities | +|---------|-----------|------------------| +| **LeadService** | `crm.lead.*` | CRUD + search + stats for leads; owns phones/emails child collections; code generation (`SAL-###`); status transitions; assignment. | +| **LeadVerificationService** | `crm.leadVerification.*` | Verification queue search/stats; status & sub-status transitions; assign/reassign/pending; note management; code generation (`LD-V-###`). | +| **LeadPromotionService** (or a method on LeadVerificationService) | part of `crm.leadVerification.verify` | The cross-module promotion: verified verification → new Lead, bidirectional linking, idempotency. Owns the transaction that touches both `leads` and `lead_verifications`. | +| **LeadActivityService** | activities/history | Append + list `lead_verification_activities` and `lead_status_history`; generates the timeline the UI reads (replaces the client-side `buildActivity` synthesis). | +| **LeadAssignmentService** | assignment concerns | Resolve member ids for `assignedTo` / `canvasser` / `assignee`; validate tenant membership; (future) round-robin. Can be a thin helper over the existing member/team module rather than a standalone service. | +| **MediaService (existing — reuse)** | `crm.media.*` | Presign upload/download for site photos. **Do not reimplement** — see media-api.ts. | +| **Account/AccessService (existing — reuse)** | `crm.account.me` | `leads.manage` authorization for every action here. | +| **NotificationService** — `[Backend Pending]` | — | The frontend today only toasts locally. No server notification is required for parity, but promotion/verify events are natural triggers if/when the Inbox projection (`crm.inbox.*`) should surface them. Do not build unless requested. | + +**Layering convention (match existing modules):** Controller/handler (validates action variables, applies auth) → Service (business rules, transitions) → Repository (tenant-scoped data access). DTO projections are shaped for the UI (list vs detail) exactly as the current modules return purpose-built DTOs (e.g. `MemberDTO`, `MailThread`). + +--- + +## 10. Error Handling + +Errors propagate to the UI as a thrown `Error`; the SDK hooks expose `error.message` (see `q.error?.message ?? null` throughout the API layer). Permission failures use the SDK's `PermissionError` (OPA). Provide a **stable machine `code` + human `message`**; the UI currently shows the message in a toast/inline state. + +| Scenario | When | Suggested code | HTTP-equivalent | UI effect | +|----------|------|----------------|-----------------|-----------| +| Unauthenticated | no/expired session | `unauthenticated` | 401 | `auth-gate` redirects to `/portal/login` | +| Forbidden | member lacks `leads.manage` | `forbidden` / `PermissionError` | 403 | nav item hidden; action rejected | +| Validation — name required | create with empty name | `name_required` | 422 | matches current client guard toast | +| Validation — bad enum | invalid status/source/type | `invalid_value` | 422 | inline/toast | +| Validation — bad email/zip/phone | format fails | `invalid_format` | 422 | | +| Not found | unknown `id` / wrong tenant | `not_found` | 404 | toast; row disappears on refetch | +| Conflict — already verified | `verify` on a verified record | `already_verified` | 409 | toast | +| Conflict — invalid transition | disallowed status change | `invalid_state_transition` | 409 | toast | +| Conflict — duplicate lead | dup phone/address (if enforced) | `duplicate_lead` | 409 | warn (prefer soft-warn, not block) | +| Conflict — duplicate code | code collision (should be internal) | `duplicate_code` | 409 | internal retry | +| Assignee invalid | assignee not a tenant member | `invalid_assignee` | 422 | toast | +| Upload too large | photo > 25 MB | `file_too_large` | 413 | matches media-api guard ("max 25 MB") | +| Upload failed | presigned PUT fails | `upload_failed` | 502 | toast | +| Rate / idempotency replay | duplicate command key | (return original result) | 200 | no-op, safe | +| Server error | unexpected | `internal_error` | 500 | generic toast | + +**Error envelope (recommended, consistent with a thrown Error carrying structured data):** +```json +{ "error": { "code": "already_verified", + "message": "This lead has already been verified.", + "details": { "verificationId": "lv_1…" } } } +``` + +--- + +## 11. Existing Backend Integration (mandatory conventions) + +The new backend **must** follow the patterns already used by Team, Mail, Inbox, Messenger, Media and Account. Never invent a different architecture. + +### 11.1 Data door, not REST +The frontend never calls REST endpoints. It calls **actions** through the AppShell SDK: +```ts +// read +const q = useQuery>("crm.lead.search", { status, query, page, perPage }); +// write +await sdk.command("crm.leadVerification.verify", { id, notes }); +``` +`DataClient.query(action, variables)` and `DataClient.command(action, variables)` call the **Shell BFF's cookie-authed `/data` proxy**; the BFF attaches the session token server-side and forwards to `be-crm`. Apps never hold a token, set an `Authorization` header, or know the domain endpoint. + +### 11.2 Transport path +``` +browser (SDK) ──► Next rewrite /shell/:path* ──► BFF (BFF_ORIGIN, default http://localhost:4000)/api/:path* ──► be-crm domain API +``` +(from `next.config.ts` `rewrites()` and `providers.tsx` `bffBaseUrl = "/shell"`). The session is an **HttpOnly cookie**; that is why the same-origin `/shell` prefix is used (never `/api`, to avoid clobbering the local `/api/geo` route). + +### 11.3 Authentication & authorization +- Auth is Supabase-backed via the SDK (`appId: "crm-web"`); the BFF exchanges it for a domain session. When `NEXT_PUBLIC_SUPABASE_URL` is unset the app runs in **mock mode** (see §11.6). +- Authorization is **permission-based** via `crm.account.me` → `{ registered, isMember, roleSlugs, permissions, isSuperadmin }`. Both modules require **`leads.manage`** (already declared in `access.ts` `ALL_CRM_PERMISSIONS` and mapped in `sidebar.tsx` `NAV_PERMISSION`). Enforce it on **every** `crm.lead.*` and `crm.leadVerification.*` action — the frontend gate is UX-only ("be-crm still enforces every action"). +- OPA/IIOS may additionally gate row visibility; keep everything **tenant-scoped**. + +### 11.4 Response & naming conventions +- **Actions:** `crm..` dot-namespaced; segments camelCase (e.g. `member.setRoles`, `invitation.create`, `inbox.transition`, `mail.reply`). Use `search`/`list` for reads, imperative verbs for writes. +- **DTOs:** server returns UI-shaped DTOs (list vs detail projections). Fields are **camelCase**. Timestamps are **ISO-8601 strings**; the client formats relative/pretty (`relTime`). Nullable fields are `null`, not omitted, where the UI reads them. +- **Collections:** `{ items: T[], meta: { total, page, perPage } }` for paginated sets (Team pattern) — used here for `search`. Bare arrays are acceptable for small always-full lists (Mail/Inbox pattern) but Leads/Verification use the envelope for totals. +- **Commands** are idempotent (idempotency key auto-attached); write-then-refetch is the client norm (`cmd(...)` then `refetch()`), so commands should return the updated entity to allow optimistic UI too. + +### 11.5 Media / attachments (reuse exactly) +Site photos must use the existing two-step flow (from `media-api.ts`): +1. `sdk.command("crm.media.presignUpload", { mime, sizeBytes })` → `{ objectKey, uploadUrl }`. +2. Browser `PUT`s the file bytes **directly** to `uploadUrl` (IIOS storage) — be-crm only mints the URL. +3. Store `{ contentRef: objectKey, mimeType, sizeBytes, filename }` on the lead via `crm.lead.attachment.add`. +4. Display via `crm.media.presignDownload { contentRef }` → `{ url }`. +Enforce the **25 MB** cap (`MAX_ATTACHMENT_BYTES = 26_214_400`). + +### 11.6 Mock-mode parity (important) +Every existing data-layer file (`team-api`, `mail-api`, `inbox-api`, `messenger-api`, `access`) chooses **mock vs live at module load** via `isShellConfigured()` (`Boolean(process.env.NEXT_PUBLIC_SUPABASE_URL)`). When you wire Leads/Verification to the live door, follow the same shape: create `src/lib/leads-api.ts` and `src/lib/verify-api.ts` exposing one hook per module that returns `{ live, loading, error, …data, …commands, refetch }`, serving the current mock (`LEADS`, `V_LEADS`) when the Shell isn't configured and the live `crm.lead.*` / `crm.leadVerification.*` actions when it is. This keeps the demo working and matches the established convention. *(Frontend wiring task — noted for completeness; the backend itself only needs to implement the live actions.)* + +### 11.7 DTO / repository / service pattern summary +- **DTO:** dedicated interfaces per projection (`LeadCardDTO`, `LeadDTO`, `VerificationRowDTO`, `VerificationDTO`) — do not leak raw table rows. +- **Repository:** always parameterize by `tenantId`; never a query without tenant scope. +- **Service:** owns transitions, code generation, promotion transaction, activity emission. +- **Controller/handler:** maps the action name + variables to a service call, validates, applies auth. One handler per action, matching the `crm..` registry the BFF forwards to. + +--- + +## 12. Gaps, Discrepancies & Backend-Pending Items + +Explicitly flagged so the backend developer is not surprised. + +1. **Everything is mock today.** No `crm.lead.*` or `crm.leadVerification.*` action is called anywhere yet. All actions in §6 are new. Frontend wiring (§11.6) is a separate follow-up task. + +2. **`leadType` enum conflict.** `leads-data.ts` defines `LEAD_TYPES = ["Insurance","Retail"]` and mock rows use `"Insurance"`, but the Full-form Job step's `LEAD_TYPE_OPTS = ["Residential","Commercial","Multi-Family"]`. **Recommendation:** store `lead_type` as free text (do not hard-reject), accept both sets, and raise with product which taxonomy is canonical. **[Needs product decision]** + +3. **`propertyType` superset.** `PROPERTY_TYPES` (data) = `Single Family / Multi Family / Commercial`; the form offers `Residential / Commercial / Multi-Family / Industrial`. Accept the union. + +4. **Priority casing.** Create form emits `Low/Medium/High`; list/detail use `low/medium/high`. **Normalize to lowercase** on write; return lowercase. + +5. **Assignee/canvasser/creator are free-text names in the mock** (`"Jesus Gonzales"`, `"Cody Tatum"`, `"Wade Hollis"`). The backend must model these as **member FKs** and resolve display names in DTOs. The verification specialists (`Wade Hollis`, `Darlene Brooks`, `Roy Schaefer`) are not in the `REPS` list — they must exist as members/records too. **[Seed/link required]** + +6. **Site photos are placeholders.** `addPhoto()` stores label strings (`"Photo 1"`). Real upload via the media presign flow (§11.5) is **backend-pending** but fully specified. + +7. **Detail actions are inert.** Leads "Call / Email / Update Status" and Verification "Call / Verify" footer buttons have **no handlers**. `updateStatus`, `verify` etc. are specified in §6 but the buttons must be wired (frontend task). + +8. **Activity timeline is client-synthesized.** `buildActivity()` fabricates timeline entries when a verification lacks `activity[]`. The backend should persist **real** activities (`lead_verification_activities`) and the client should stop synthesizing once live. + +9. **No pagination controls in the UI**, yet `TOTAL_LEADS = 35` (only 5 loaded) and the verification footer shows "X of Y". Implement server pagination + `meta.total`; pick a sane default `perPage`. A pager UI is a future frontend task. + +10. **No edit / delete / archive / bulk / tags-editor / sort UI.** Endpoints for update/archive/delete are included as **optional/pending** — implement `crm.lead.update` (needed for status/assignment) but treat `archive`/`delete`/bulk as **do-not-build-unless-requested**. + +11. **Verification records are never created from the UI** (like the Inbox, they "arrive"). Provide an intake ingestion path (webhook / internal command) **outside** these two module screens — its exact source is not defined by the frontend. **[Needs definition]** + +12. **Single-line vs structured address.** Leads store structured address (address/city/state/zip); verifications store a single `address` string (`"2814 Ravenswood Dr, Plano, TX 75023"`). When promoting a verification → lead, parse or carry the single string into `property_address` (best-effort parse; keep the raw string too). **[Parsing rule needed]** + +--- + +*End of document.* diff --git a/docs/SMART_GALLERY.md b/docs/SMART_GALLERY.md new file mode 100644 index 0000000..b68b8fd --- /dev/null +++ b/docs/SMART_GALLERY.md @@ -0,0 +1,230 @@ +# Smart Gallery — AI route surface + +The Smart Gallery embeds `@photo-gallery/sdk` into the CRM. The SDK never talks to a +model directly: it calls a pluggable `AIProvider`, which the CRM supplies via +`createCrmAIProvider()` in [`src/lib/gallery-ai.ts`](../src/lib/gallery-ai.ts). + +Roughly half the intelligence runs **in the browser** for free, and the other half is +proxied through **five server routes** under `/api/gallery/ai/*` so the RunPod API key +never reaches the client. + +--- + +## 1. Where each capability runs + +| Capability | Where | Backend | Needs a key? | +| --- | --- | --- | --- | +| Object detection (default) | Browser | TensorFlow.js COCO-SSD (80 COCO classes) | No | +| Object detection (opt-in) | **Server** | RunPod YOLO → `/classify` | Yes | +| Face detection + recognition | Browser | `@vladmandic/face-api` (128-D descriptors → People) | No | +| OCR / document search | Browser | `tesseract.js` | No | +| Semantic ("beach photos") search | Browser | CLIP via `@huggingface/transformers` | No | +| Background removal (default) | Browser | `@imgly/background-removal` (WASM) | No | +| Background removal (opt-in) | **Server** | RunPod U²-Net → `/edit` | Yes | +| Generative edits, restore, upscale, outpaint | **Server** | `/edit` | Yes | +| Speech-to-text | **Server** | `/transcribe` | Yes | +| Audio denoise | **Server** | `/denoise` | Yes | +| Camera tilt / auto-straighten | **Server** | `/tilt` | Yes | + +Every in-browser model is loaded with `await import(...)` on first use, so none of it +lands in the initial bundle. **Every capability degrades gracefully** — a model that +fails to load returns `[]` / `''` / `null` with a `console.warn` rather than throwing, +so a blocked CDN never breaks the gallery UI. + +--- + +## 2. Auth model + +All five routes share one gate: `requireGallerySession()` in +[`src/lib/server/session.ts`](../src/lib/server/session.ts). + +These routes proxy a **paid, rate-limited GPU backend** using a secret held only on the +server. An unauthenticated route here is not just an information leak — it is an open +invitation to spend the operator's GPU budget. (The upstream SDK demo's routes are +completely unauthenticated; that is the single biggest thing this port fixes.) + +**When the Shell is configured** (`NEXT_PUBLIC_SUPABASE_URL` is set): the incoming +`cookie` header is forwarded to `${BFF_ORIGIN}/api/session/context` and only a `200` +is accepted. + +- `401` upstream → `401 { error: "Not signed in" }` +- any other non-200, or a network/timeout failure → `503 { error: "Session service unavailable" }` + (**fail closed** — if we cannot prove a session, we do not spend GPU budget) +- **Nothing is cached.** A cached "yes" would keep a revoked session alive, so every AI + request costs one BFF round trip. Correctness over latency for a spend gate. +- The BFF is trusted absolutely — `BFF_ORIGIN` must only ever point at an origin the + operator controls. + +**When the Shell is NOT configured** (local demo mode): the request is allowed and a +warning is logged once. **Never deploy to a public origin with the Shell unconfigured +and a real `RUNPOD_API_KEY` present** — that combination is an open, billable endpoint. + +This is authentication only, not authorization. Per-resource gallery policy lives in +be-crm behind the `crm.gallery` resource. + +--- + +## 3. Rate limits + +[`src/lib/server/rate-limit.ts`](../src/lib/server/rate-limit.ts) — a fixed-window +counter keyed by the authenticated principal when known, otherwise the first hop of +`x-forwarded-for`. Each route has its own namespace, so spending your `edit` budget +does not consume your `classify` budget. Exceeding it returns +`429 { error: "Too many requests — slow down." }` with a `Retry-After` header. + +| Route | Limit | +| --- | --- | +| `/classify` | 30 / min | +| `/tilt` | 30 / min | +| `/transcribe` | 20 / min | +| `/denoise` | 20 / min | +| `/edit` | 12 / min (most expensive) | + +> **This limiter is per-instance and in-memory.** With N instances behind a load +> balancer a caller gets up to N x the budget, and a restart clears all counters. It is +> a cost guard, not a security boundary. **Replace it with Redis before running more +> than one instance.** The `x-forwarded-for` key is also client-controlled unless a +> trusted proxy overwrites it — the session gate, not this, is the security boundary. + +--- + +## 4. The routes + +All five are `POST` only, and all declare `runtime = "nodejs"`, `maxDuration = 60`, +`dynamic = "force-dynamic"`. Failures always return `{ error: string }`. + +Shared status codes: `400` invalid body/params · `401` not signed in · `413` payload too +large · `429` rate limited · `500` server misconfigured (e.g. missing `RUNPOD_API_KEY`) · +`502` upstream failed · `503` not configured / session service unavailable · +`504` upstream timed out (the RunPod client's budget is 55s, under the 60s cap). + +Upstream error bodies are truncated to a **160-character excerpt**; the RunPod key is +never included in any response. + +### `POST /api/gallery/ai/classify` — object detection +Backed by `RUNPOD_YOLO_URL`. Max ~4 MB of base64. Returns boxes as **fractions 0..1** +of the image, matching the SDK's `DetectedObject`. + +```jsonc +// request +{ "imageBase64": "…", "width": 1280, "height": 853 } +// response +{ "objects": [ { "label": "excavator", "confidence": 0.91, + "box": { "x": 0.12, "y": 0.30, "width": 0.25, "height": 0.40 } } ] } +``` + +### `POST /api/gallery/ai/edit` — generative image editing +The backend is pluggable via `AI_EDIT_PROVIDER` (`auto` | `runpod` | `local` | +`huggingface` | `gemini` | `none`). Image + mask are budgeted **together** against the +~4 MB cap. Prompts come from an allow-listed op set — arbitrary server-side prompts are +never accepted, and free-text is clamped to 500 chars. + +```jsonc +// request +{ "imageBase64": "…", "mimeType": "image/jpeg", + "op": { "type": "restore" }, // or prompt | colorize | replace-sky | + // magic-eraser | generative-fill | upscale | + // remove-background + "maskBase64": "…", // required for magic-eraser / generative-fill + "params": { "strength": 0.8 } } +// response +{ "imageBase64": "…", "mimeType": "image/png" } +``` + +Op → RunPod endpoint: `restore`/`upscale` → `RUNPOD_UPSCALE_URL` · +`prompt`/`colorize` → `RUNPOD_SD_IMG2IMG_URL` · `replace-sky`/`magic-eraser`/ +`generative-fill` → `RUNPOD_SD_INPAINT_URL` · `remove-background` → +`RUNPOD_BG_REMOVE_URL`. `upscale`, `magic-eraser` and `generative-fill` are RunPod-only +and return `400` under another backend. Outpaint is client-side padding plus a +`generative-fill` call — it needs no separate route. + +### `POST /api/gallery/ai/tilt` — camera tilt +Backed by `RUNPOD_TILT_URL`. Max ~4 MB (`413` over). Only reachable when +`NEXT_PUBLIC_APG_RUNPOD_TILT=true`, which also reveals the editor's Auto-straighten button. + +```jsonc +{ "image": "…" } → { "rollDegrees": -2.4, "pitchDegrees": 1.1, "fovDegrees": 68.2 } +``` + +### `POST /api/gallery/ai/transcribe` — speech to text +Backed by `RUNPOD_STT_URL`. Expects base64 **WAV 16 kHz mono PCM16**. Max ~8 MB (`413`). + +```jsonc +{ "audio": "…", "language": "en" } +→ { "transcript": "…", "segments": [ { "text": "…", "startSec": 0, "endSec": 1.8 } ] } +``` + +### `POST /api/gallery/ai/denoise` — audio noise removal +Backed by `RUNPOD_AUDIO_DENOISE_URL`. Expects base64 **WAV 48 kHz mono PCM16**. Max +~12 MB (`413`). Used before transcription on noisy sites. + +```jsonc +{ "audio": "…" } → { "audio": "…" } +``` + +--- + +## 5. Environment variables + +See [`.env.local.example`](../.env.local.example) for the fully commented template. + +| Var | Backs | +| --- | --- | +| `RUNPOD_API_KEY` | all five routes (server-only — never `NEXT_PUBLIC_`) | +| `RUNPOD_YOLO_URL` | `/classify` | +| `RUNPOD_SD_IMG2IMG_URL` | `/edit` — prompt, colorize, maskless replace-sky | +| `RUNPOD_SD_INPAINT_URL` | `/edit` — magic-eraser, generative-fill, outpaint, masked replace-sky | +| `RUNPOD_UPSCALE_URL` | `/edit` — restore, upscale | +| `RUNPOD_BG_REMOVE_URL` | `/edit` — remove-background | +| `RUNPOD_STT_URL` | `/transcribe` | +| `RUNPOD_AUDIO_DENOISE_URL` | `/denoise` | +| `RUNPOD_TILT_URL` | `/tilt` | +| `AI_EDIT_PROVIDER` | which backend `/edit` uses | +| `BFF_ORIGIN` | the session gate | + +Client switches (`NEXT_PUBLIC_`, **inlined at build time** — a change needs a rebuild, +and each must be the literal string `"true"`): +`NEXT_PUBLIC_APG_RUNPOD_DETECT`, `NEXT_PUBLIC_APG_RUNPOD_BG`, `NEXT_PUBLIC_APG_RUNPOD_TILT`. + +> The SDK's standalone demo also reads a family of `NEXT_PUBLIC_APG_*` **theming** vars +> (`_THEME`, `_ACCENT`, `_RADIUS`, `_BG_DARK`, `_SIDEBAR_BG_*`, …). Those are **not used +> here** — the CRM passes `themeTokens` to the gallery directly so it inherits the +> dashboard's design tokens. Setting them in this app has no effect. + +--- + +## 6. CSP / CDN hosts + +**The CRM ships no Content-Security-Policy today**, so the in-browser models load +without any allow-listing. This section is what would need to be permitted **if a CSP +is ever added** — miss any of these and the affected capability silently degrades +(returns empty + `console.warn`) rather than erroring visibly, which makes it easy to +misdiagnose. + +| Host | Needed by | Directive | +| --- | --- | --- | +| `https://cdn.jsdelivr.net` | face-api models; tesseract worker, WASM core **and** language data | `script-src`, `connect-src`, `worker-src` | +| `https://huggingface.co`, `https://cdn-lfs.huggingface.co` | CLIP model weights (transformers.js) | `connect-src` | +| `https://storage.googleapis.com` | TensorFlow.js COCO-SSD model | `connect-src` | +| `https://staticimgly.com` | `@imgly/background-removal` WASM + assets | `connect-src`, `worker-src` | + +Also required by the ML runtimes themselves: + +- **`wasm-unsafe-eval` in `script-src`** — ONNX Runtime (CLIP), tesseract-core and the + `@imgly` remover are all WebAssembly. Without it, semantic search, OCR and in-browser + background removal all fail. +- **`blob:` in `worker-src`/`child_src`** — tesseract and the WASM runtimes spawn + workers from blob URLs. +- **`data:` and `blob:` in `img-src`** — canvas round-trips and generated results. + +Notes: +- All three tesseract assets (worker, core, tessdata) are pinned to **jsDelivr** on + purpose. Left at its defaults, tesseract fetches language data from + `tessdata.projectnaptha.com`, which would be a second host to allow-list. +- `tesseract.js` is pinned to **exactly `5.1.1`** (no caret) in `package.json` because + the worker CDN URL embeds the version — a floating range would let the worker drift + out of sync with the installed main-thread code. +- The tfjs providers prefer the **WebGL** backend, which avoids `eval` and is therefore + CSP-friendly; they fall back to the default backend if WebGL is unavailable. +- The SDK's own demo app runs a strict per-request nonce CSP with these hosts already + allow-listed — see that repo's middleware for a working reference. diff --git a/next.config.ts b/next.config.ts index 976f677..f5d7ece 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,8 +1,9 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - // The SDKs ship ESM; let Next transpile them. - transpilePackages: ["@abe-kap/appshell-sdk", "@insignia/iios-messaging-ui"], + // The SDKs ship ESM/TS source (their `exports` point at src/), so Next must + // transpile them rather than treat them as prebuilt CJS. + transpilePackages: ["@abe-kap/appshell-sdk", "@insignia/iios-messaging-ui", "@photo-gallery/sdk"], // The browser calls the Shell BFF same-origin under /shell (so the HttpOnly // session cookie flows). We deliberately use /shell (NOT /api) to avoid // clobbering the existing /api/geo route. Point BFF_ORIGIN at the deployed BFF. diff --git a/package-lock.json b/package-lock.json index cad99b6..f0cfac7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,17 +9,26 @@ "version": "0.1.0", "dependencies": { "@abe-kap/appshell-sdk": "^0.2.6", + "@huggingface/transformers": "^4.2.0", + "@imgly/background-removal": "^1.7.0", "@insignia/iios-kernel-client": "^0.1.4", - "@insignia/iios-messaging-ui": "^0.1.2", + "@insignia/iios-messaging-ui": "^0.1.7", + "@photo-gallery/sdk": "file:./vendor/photo-gallery-sdk", + "@tensorflow-models/coco-ssd": "^2.2.3", + "@tensorflow/tfjs": "^4.22.0", + "@vladmandic/face-api": "^1.7.15", "clsx": "^2.1.1", + "leaflet": "^1.9.4", "lucide-react": "^1.21.0", "next": "16.2.9", "react": "19.2.4", "react-dom": "19.2.4", - "tailwind-merge": "^3.6.0" + "tailwind-merge": "^3.6.0", + "tesseract.js": "5.1.1" }, "devDependencies": { "@tailwindcss/postcss": "^4", + "@types/leaflet": "^1.9.21", "@types/node": "^20", "@types/react": "^19", "@types/react-dom": "^19", @@ -481,6 +490,34 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@huggingface/jinja": { + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/@huggingface/jinja/-/jinja-0.5.9.tgz", + "integrity": "sha512-uWTG+l3VJRsl7EXxYizuL3P+cCPoc3cRqbWWRcQN0FhejRfbdq0RNhCmbY/YDtnTcz9icdLYuLDjsnz4d8JMuw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/@huggingface/tokenizers": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@huggingface/tokenizers/-/tokenizers-0.1.3.tgz", + "integrity": "sha512-8rF/RRT10u+kn7YuUbUg0OF30K8rjTc78aHpxT+qJ1uWSqxT1MHi8+9ltwYfkFYJzT/oS+qw3JVfHtNMGAdqyA==", + "license": "Apache-2.0" + }, + "node_modules/@huggingface/transformers": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@huggingface/transformers/-/transformers-4.2.0.tgz", + "integrity": "sha512-8BRCoBMH0XsWaEIamuR0LrJGAfftgHAfb2Vrffy0VKlSAE/MnUJ5/h/zTfEP3fDIft+nk7TqB8xXEyABGitBjQ==", + "license": "Apache-2.0", + "dependencies": { + "@huggingface/jinja": "^0.5.6", + "@huggingface/tokenizers": "^0.1.3", + "onnxruntime-node": "1.24.3", + "onnxruntime-web": "1.26.0-dev.20260416-b7804b056c", + "sharp": "^0.34.5" + } + }, "node_modules/@humanfs/core": { "version": "0.19.2", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.2.tgz", @@ -552,7 +589,6 @@ "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", "integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==", "license": "MIT", - "optional": true, "engines": { "node": ">=18" } @@ -1013,6 +1049,29 @@ "url": "https://opencollective.com/libvips" } }, + "node_modules/@imgly/background-removal": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@imgly/background-removal/-/background-removal-1.7.0.tgz", + "integrity": "sha512-/1ZryrMYg2ckIvJKoTu5Np50JfYMVffDMlVmppw/BdbN3pBTN7e6stI5/7E/LVh9DDzz6J588s7sWqul3fy5wA==", + "license": "SEE LICENSE IN LICENSE.md", + "dependencies": { + "lodash-es": "^4.17.21", + "ndarray": "~1.0.0", + "zod": "^3.23.8" + }, + "peerDependencies": { + "onnxruntime-web": "1.21.0" + } + }, + "node_modules/@imgly/background-removal/node_modules/zod": { + "version": "3.25.76", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", + "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, "node_modules/@insignia/iios-contracts": { "version": "0.1.0", "resolved": "https://git.lynkedup.cloud/api/packages/insignia/npm/%40insignia%2Fiios-contracts/-/0.1.0/iios-contracts-0.1.0.tgz", @@ -1028,9 +1087,9 @@ } }, "node_modules/@insignia/iios-messaging-ui": { - "version": "0.1.2", - "resolved": "https://git.lynkedup.cloud/api/packages/insignia/npm/%40insignia%2Fiios-messaging-ui/-/0.1.2/iios-messaging-ui-0.1.2.tgz", - "integrity": "sha512-YsoTM9vmjQ+dk6Hch5nXuqMFAdybd3luAZepfaliOw727ylc8FPAtwTMMcIWQ3WOQPa2eKeGLiEpo61QCO0GrA==", + "version": "0.1.7", + "resolved": "https://git.lynkedup.cloud/api/packages/insignia/npm/%40insignia%2Fiios-messaging-ui/-/0.1.7/iios-messaging-ui-0.1.7.tgz", + "integrity": "sha512-ZE4fLeSTSa5AFZnvSRT7G/TEaw+Jm5qH8rWaDjns6Vu9zBnDTVYdF8CMEisBrtgSDj+jDQBo9xlwZmr++5qehw==", "peerDependencies": { "@insignia/iios-kernel-client": "*", "react": ">=18", @@ -1303,6 +1362,67 @@ "node": ">=12.4.0" } }, + "node_modules/@photo-gallery/sdk": { + "resolved": "vendor/photo-gallery-sdk", + "link": true + }, + "node_modules/@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/codegen": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.5.tgz", + "integrity": "sha512-zgXFLzW3Ap33e6d0Wlj4MGIm6Ce8O89n/apUaGNB/jx+hw+ruWEp7EwGUshdLKVRCxZW12fp9r40E1mQrf/34g==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/eventemitter": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.1.tgz", + "integrity": "sha512-vW1GmwMZNnL+gMRaovlh9yZX74kc+TTU3FObkkurpMaRtBfLP3ldjS9KQWlwZgraRE0+dheEEoAxdzcJQ8eXZg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/fetch": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.1.tgz", + "integrity": "sha512-GpptLrs57adMSuHi3VNj0mAF8dwh36LMaYF6XyJ6JMWlVsc+t42tm1HSEDmOs3A8fC9yyeisgLhsTVQokOZ0zw==", + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.1" + } + }, + "node_modules/@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/utf8": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.2.tgz", + "integrity": "sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==", + "license": "BSD-3-Clause" + }, "node_modules/@rtsao/scc": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz", @@ -1680,6 +1800,171 @@ "tailwindcss": "4.3.1" } }, + "node_modules/@tanstack/react-virtual": { + "version": "3.14.8", + "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.14.8.tgz", + "integrity": "sha512-O39GJQpAYEJcIu3uN1//YtmhjSEOyw75vg9CKCatBDPiD5hKtZQoJHfferyrB/LdOD3UWaoMLWtdEjarwIwdDw==", + "license": "MIT", + "dependencies": { + "@tanstack/virtual-core": "3.17.6" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, + "node_modules/@tanstack/virtual-core": { + "version": "3.17.6", + "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.17.6.tgz", + "integrity": "sha512-h0/Ebo18CkOrChlQIhNtQkM5ySUnh/GumQ/D1st3hG2HWUPEF+ILUc2k29UtivCi/9G7w7G3/f7Xyd5cCFbKBw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tensorflow-models/coco-ssd": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/@tensorflow-models/coco-ssd/-/coco-ssd-2.2.3.tgz", + "integrity": "sha512-iCLGktG/XhHbP6h2FWxqCKMp/Px0lCp6MZU1fjNhjDHeaWEC9G7S7cZrnPXsfH+NewCM53YShlrHnknxU3SQig==", + "license": "Apache-2.0", + "peerDependencies": { + "@tensorflow/tfjs-converter": "^4.10.0", + "@tensorflow/tfjs-core": "^4.10.0" + } + }, + "node_modules/@tensorflow/tfjs": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/@tensorflow/tfjs/-/tfjs-4.22.0.tgz", + "integrity": "sha512-0TrIrXs6/b7FLhLVNmfh8Sah6JgjBPH4mZ8JGb7NU6WW+cx00qK5BcAZxw7NCzxj6N8MRAIfHq+oNbPUNG5VAg==", + "license": "Apache-2.0", + "dependencies": { + "@tensorflow/tfjs-backend-cpu": "4.22.0", + "@tensorflow/tfjs-backend-webgl": "4.22.0", + "@tensorflow/tfjs-converter": "4.22.0", + "@tensorflow/tfjs-core": "4.22.0", + "@tensorflow/tfjs-data": "4.22.0", + "@tensorflow/tfjs-layers": "4.22.0", + "argparse": "^1.0.10", + "chalk": "^4.1.0", + "core-js": "3.29.1", + "regenerator-runtime": "^0.13.5", + "yargs": "^16.0.3" + }, + "bin": { + "tfjs-custom-module": "dist/tools/custom_module/cli.js" + } + }, + "node_modules/@tensorflow/tfjs-backend-cpu": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-4.22.0.tgz", + "integrity": "sha512-1u0FmuLGuRAi8D2c3cocHTASGXOmHc/4OvoVDENJayjYkS119fcTcQf4iHrtLthWyDIPy3JiPhRrZQC9EwnhLw==", + "license": "Apache-2.0", + "dependencies": { + "@types/seedrandom": "^2.4.28", + "seedrandom": "^3.0.5" + }, + "engines": { + "yarn": ">= 1.3.2" + }, + "peerDependencies": { + "@tensorflow/tfjs-core": "4.22.0" + } + }, + "node_modules/@tensorflow/tfjs-backend-webgl": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-4.22.0.tgz", + "integrity": "sha512-H535XtZWnWgNwSzv538czjVlbJebDl5QTMOth4RXr2p/kJ1qSIXE0vZvEtO+5EC9b00SvhplECny2yDewQb/Yg==", + "license": "Apache-2.0", + "dependencies": { + "@tensorflow/tfjs-backend-cpu": "4.22.0", + "@types/offscreencanvas": "~2019.3.0", + "@types/seedrandom": "^2.4.28", + "seedrandom": "^3.0.5" + }, + "engines": { + "yarn": ">= 1.3.2" + }, + "peerDependencies": { + "@tensorflow/tfjs-core": "4.22.0" + } + }, + "node_modules/@tensorflow/tfjs-converter": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/@tensorflow/tfjs-converter/-/tfjs-converter-4.22.0.tgz", + "integrity": "sha512-PT43MGlnzIo+YfbsjM79Lxk9lOq6uUwZuCc8rrp0hfpLjF6Jv8jS84u2jFb+WpUeuF4K33ZDNx8CjiYrGQ2trQ==", + "license": "Apache-2.0", + "peerDependencies": { + "@tensorflow/tfjs-core": "4.22.0" + } + }, + "node_modules/@tensorflow/tfjs-core": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/@tensorflow/tfjs-core/-/tfjs-core-4.22.0.tgz", + "integrity": "sha512-LEkOyzbknKFoWUwfkr59vSB68DMJ4cjwwHgicXN0DUi3a0Vh1Er3JQqCI1Hl86GGZQvY8ezVrtDIvqR1ZFW55A==", + "license": "Apache-2.0", + "dependencies": { + "@types/long": "^4.0.1", + "@types/offscreencanvas": "~2019.7.0", + "@types/seedrandom": "^2.4.28", + "@webgpu/types": "0.1.38", + "long": "4.0.0", + "node-fetch": "~2.6.1", + "seedrandom": "^3.0.5" + }, + "engines": { + "yarn": ">= 1.3.2" + } + }, + "node_modules/@tensorflow/tfjs-core/node_modules/@types/offscreencanvas": { + "version": "2019.7.3", + "resolved": "https://registry.npmjs.org/@types/offscreencanvas/-/offscreencanvas-2019.7.3.tgz", + "integrity": "sha512-ieXiYmgSRXUDeOntE1InxjWyvEelZGP63M+cGuquuRLuIKKT1osnkXjxev9B7d1nXSug5vpunx+gNlbVxMlC9A==", + "license": "MIT" + }, + "node_modules/@tensorflow/tfjs-data": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/@tensorflow/tfjs-data/-/tfjs-data-4.22.0.tgz", + "integrity": "sha512-dYmF3LihQIGvtgJrt382hSRH4S0QuAp2w1hXJI2+kOaEqo5HnUPG0k5KA6va+S1yUhx7UBToUKCBHeLHFQRV4w==", + "license": "Apache-2.0", + "dependencies": { + "@types/node-fetch": "^2.1.2", + "node-fetch": "~2.6.1", + "string_decoder": "^1.3.0" + }, + "peerDependencies": { + "@tensorflow/tfjs-core": "4.22.0", + "seedrandom": "^3.0.5" + } + }, + "node_modules/@tensorflow/tfjs-layers": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/@tensorflow/tfjs-layers/-/tfjs-layers-4.22.0.tgz", + "integrity": "sha512-lybPj4ZNj9iIAPUj7a8ZW1hg8KQGfqWLlCZDi9eM/oNKCCAgchiyzx8OrYoWmRrB+AM6VNEeIT+2gZKg5ReihA==", + "license": "Apache-2.0 AND MIT", + "peerDependencies": { + "@tensorflow/tfjs-core": "4.22.0" + } + }, + "node_modules/@tensorflow/tfjs/node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "license": "MIT", + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, + "node_modules/@tensorflow/tfjs/node_modules/sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", + "license": "BSD-3-Clause" + }, "node_modules/@tybys/wasm-util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.3.tgz", @@ -1698,6 +1983,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/geojson": { + "version": "7946.0.16", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.16.tgz", + "integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -1712,16 +2004,47 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/leaflet": { + "version": "1.9.21", + "resolved": "https://registry.npmjs.org/@types/leaflet/-/leaflet-1.9.21.tgz", + "integrity": "sha512-TbAd9DaPGSnzp6QvtYngntMZgcRk+igFELwR2N99XZn7RXUdKgsXMR+28bUO0rPsWp8MIu/f47luLIQuSLYv/w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/geojson": "*" + } + }, + "node_modules/@types/long": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", + "integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==", + "license": "MIT" + }, "node_modules/@types/node": { "version": "20.19.43", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.43.tgz", "integrity": "sha512-6oYBAi5ikg4Pl+kGsoYtawUMBT2zZMCvPNF7pVLnHZfd1zf38DRiWn/gT01RYCdUqkv7Fhr+C9ot4/tb+2sVvA==", - "dev": true, "license": "MIT", "dependencies": { "undici-types": "~6.21.0" } }, + "node_modules/@types/node-fetch": { + "version": "2.6.13", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.13.tgz", + "integrity": "sha512-QGpRVpzSaUs30JBSGPjOg4Uveu384erbHBoT1zeONvyCfwQxIkUshLAOqN/k9EjGviPRmWTTe6aH2qySWKTVSw==", + "license": "MIT", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.4" + } + }, + "node_modules/@types/offscreencanvas": { + "version": "2019.3.0", + "resolved": "https://registry.npmjs.org/@types/offscreencanvas/-/offscreencanvas-2019.3.0.tgz", + "integrity": "sha512-esIJx9bQg+QYF0ra8GnvfianIY8qWB0GBx54PK5Eps6m+xTj86KLavHv6qDhzKcu5UUOgNfJ2pWaIIV7TRUd9Q==", + "license": "MIT" + }, "node_modules/@types/react": { "version": "19.2.17", "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.17.tgz", @@ -1742,6 +2065,12 @@ "@types/react": "^19.2.0" } }, + "node_modules/@types/seedrandom": { + "version": "2.4.34", + "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-2.4.34.tgz", + "integrity": "sha512-ytDiArvrn/3Xk6/vtylys5tlY6eo7Ane0hvcx++TKo6RxQXuVfW0AF/oeWqAj9dN29SyhtawuXstgmPlwNcv/A==", + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.62.0.tgz", @@ -2361,6 +2690,21 @@ "win32" ] }, + "node_modules/@vladmandic/face-api": { + "version": "1.7.15", + "resolved": "https://registry.npmjs.org/@vladmandic/face-api/-/face-api-1.7.15.tgz", + "integrity": "sha512-WDMmK3CfNLo8jylWqMoQgf4nIst3M0fzx1dnac96wv/dvMTN4DxC/Pq1DGtduDk1lktCamQ3MIDXFnvrdHTXDw==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@webgpu/types": { + "version": "0.1.38", + "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.38.tgz", + "integrity": "sha512-7LrhVKz2PRh+DD7+S+PVaFd5HxaWQvoMqBbsV9fNJO1pjUs1P8bM2vQVNfk+3URTqbuTI7gkXi0rfsN0IadoBA==", + "license": "BSD-3-Clause" + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -2397,6 +2741,15 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/adm-zip": { + "version": "0.5.18", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.18.tgz", + "integrity": "sha512-ufJnssQGbxzLNS1Ho9bCtX4rQKCCvoVuDLHoJyc3F9dOGDB4BkWs2Ci0kv53lqocAEQ/Cbi+I2XCsNYGqVYqng==", + "license": "MIT", + "engines": { + "node": ">=12.0" + } + }, "node_modules/ajv": { "version": "6.15.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz", @@ -2414,11 +2767,19 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "license": "MIT", "dependencies": { "color-convert": "^2.0.1" @@ -2630,6 +2991,12 @@ "node": ">= 0.4" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -2685,6 +3052,12 @@ "node": ">=6.0.0" } }, + "node_modules/bmp-js": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz", + "integrity": "sha512-vHdS19CnY3hwiNdkaqk93DvjVLfbEcI8mys4UjuWrlX1haDmroo8o4xCzh4wD6DGV6HxRCyauwhHRqMTfERtjw==", + "license": "MIT" + }, "node_modules/body-parser": { "version": "1.20.6", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.6.tgz", @@ -2724,6 +3097,13 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "license": "MIT" }, + "node_modules/boolean": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.2.0.tgz", + "integrity": "sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==", + "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.", + "license": "MIT" + }, "node_modules/brace-expansion": { "version": "1.1.15", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.15.tgz", @@ -2873,7 +3253,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", @@ -2892,6 +3271,17 @@ "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==", "license": "MIT" }, + "node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, "node_modules/clsx": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", @@ -2905,7 +3295,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "license": "MIT", "dependencies": { "color-name": "~1.1.4" @@ -2918,9 +3307,20 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true, "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2984,6 +3384,17 @@ "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", "license": "MIT" }, + "node_modules/core-js": { + "version": "3.29.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.29.1.tgz", + "integrity": "sha512-+jwgnhg6cQxKYIIjGtAHq2nwUOolo9eoFZ4sHfUH09BLXBgxnH4gA0zEd+t+BO2cNB8idaBtZFcFTRjQJRJmAw==", + "hasInstallScript": true, + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/cors": { "version": "2.8.6", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", @@ -3112,7 +3523,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", @@ -3130,7 +3540,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", - "dev": true, "license": "MIT", "dependencies": { "define-data-property": "^1.0.1", @@ -3144,6 +3553,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -3167,12 +3585,17 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", - "devOptional": true, "license": "Apache-2.0", "engines": { "node": ">=8" } }, + "node_modules/detect-node": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz", + "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==", + "license": "MIT" + }, "node_modules/doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", @@ -3427,7 +3850,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -3473,11 +3895,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/es6-error": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", + "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", + "license": "MIT" + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -3493,7 +3920,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, "license": "MIT", "engines": { "node": ">=10" @@ -3917,6 +4343,12 @@ "node": ">= 0.6" } }, + "node_modules/exifr": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/exifr/-/exifr-7.1.3.tgz", + "integrity": "sha512-g/aje2noHivrRSLbAUtBPWFbxKdKhgj/xr1vATDdUXPOFYJlQ62Ft0oy+72V6XLIpDJfHs6gXLbBLAolqOXYRw==", + "license": "MIT" + }, "node_modules/express": { "version": "4.22.2", "resolved": "https://registry.npmjs.org/express/-/express-4.22.2.tgz", @@ -4129,6 +4561,12 @@ "node": ">=16" } }, + "node_modules/flatbuffers": { + "version": "25.9.23", + "resolved": "https://registry.npmjs.org/flatbuffers/-/flatbuffers-25.9.23.tgz", + "integrity": "sha512-MI1qs7Lo4Syw0EOzUl0xjs2lsoeqFku44KpngfIduHBYvzm8h2+7K8YMQh1JtVVVrUvhLpNwqVi4DERegUJhPQ==", + "license": "Apache-2.0" + }, "node_modules/flatted": { "version": "3.4.2", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.2.tgz", @@ -4152,6 +4590,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/form-data": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", + "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.4", + "mime-types": "^2.1.35" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -4161,6 +4615,33 @@ "node": ">= 0.6" } }, + "node_modules/framer-motion": { + "version": "11.18.2", + "resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-11.18.2.tgz", + "integrity": "sha512-5F5Och7wrvtLVElIpclDT0CBzMVg3dL22B64aZwHtsIY8RB4mXICLrkajK4G9R+ieSAGcgrLeae2SeUTg2pr6w==", + "license": "MIT", + "dependencies": { + "motion-dom": "^11.18.1", + "motion-utils": "^11.18.1", + "tslib": "^2.4.0" + }, + "peerDependencies": { + "@emotion/is-prop-valid": "*", + "react": "^18.0.0 || ^19.0.0", + "react-dom": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@emotion/is-prop-valid": { + "optional": true + }, + "react": { + "optional": true + }, + "react-dom": { + "optional": true + } + } + }, "node_modules/fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", @@ -4233,6 +4714,15 @@ "node": ">=6.9.0" } }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "license": "ISC", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, "node_modules/get-intrinsic": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", @@ -4314,6 +4804,35 @@ "node": ">=10.13.0" } }, + "node_modules/global-agent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-3.0.0.tgz", + "integrity": "sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q==", + "license": "BSD-3-Clause", + "dependencies": { + "boolean": "^3.0.1", + "es6-error": "^4.1.1", + "matcher": "^3.0.0", + "roarr": "^2.15.3", + "semver": "^7.3.2", + "serialize-error": "^7.0.1" + }, + "engines": { + "node": ">=10.0" + } + }, + "node_modules/global-agent/node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/globals": { "version": "14.0.0", "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", @@ -4331,7 +4850,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.4.tgz", "integrity": "sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ==", - "dev": true, "license": "MIT", "dependencies": { "define-properties": "^1.2.1", @@ -4363,6 +4881,12 @@ "dev": true, "license": "ISC" }, + "node_modules/guid-typescript": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/guid-typescript/-/guid-typescript-1.0.9.tgz", + "integrity": "sha512-Y8T4vYhEfwJOTbouREvG+3XDsjr8E3kIr7uf+JZ0BYloFsttiHU0WfvANVsR7TxNUJa/WpCnw/Ino/p+DeBhBQ==", + "license": "ISC" + }, "node_modules/has-bigints": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.1.0.tgz", @@ -4380,7 +4904,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -4390,7 +4913,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0" @@ -4431,7 +4953,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" @@ -4522,6 +5043,12 @@ "node": ">=0.10.0" } }, + "node_modules/idb-keyval": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/idb-keyval/-/idb-keyval-6.3.0.tgz", + "integrity": "sha512-um+2dgAWmYsu615EXpWVwSmapJhON0G43t3Ka/EVaohzPQXSMqKEqeDK/oIW3Ow+BXaF2PvSc+oBTFp793A5Ow==", + "license": "Apache-2.0" + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -4580,6 +5107,12 @@ "node": ">= 0.4" } }, + "node_modules/iota-array": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/iota-array/-/iota-array-1.0.0.tgz", + "integrity": "sha512-pZ2xT+LOHckCatGQ3DcG/a+QuEqvoxqkiL7tvE8nn3uuu+f6i1TtpB5/FtWFbxUuVr5PZCx8KskuGatbJDXOWA==", + "license": "MIT" + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -4660,6 +5193,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "license": "MIT" + }, "node_modules/is-bun-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-bun-module/-/is-bun-module-2.0.0.tgz", @@ -4763,6 +5302,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-electron": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-electron/-/is-electron-2.2.2.tgz", + "integrity": "sha512-FO/Rhvz5tuw4MCWkpMzHFKWD2LsfHzIb7i6MdPYZ/KW7AlxawyLkqdy+jPZP1WubqEADE3O4FUENlJHDfQASRg==", + "license": "MIT" + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -4789,6 +5334,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/is-generator-function": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.2.tgz", @@ -4974,6 +5528,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-url": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz", + "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==", + "license": "MIT" + }, "node_modules/is-weakmap": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.2.tgz", @@ -5135,6 +5695,12 @@ "dev": true, "license": "MIT" }, + "node_modules/json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", + "license": "ISC" + }, "node_modules/json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", @@ -5194,6 +5760,12 @@ "node": ">=0.10" } }, + "node_modules/leaflet": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.4.tgz", + "integrity": "sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==", + "license": "BSD-2-Clause" + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -5485,6 +6057,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash-es": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.18.1.tgz", + "integrity": "sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==", + "license": "MIT" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -5492,6 +6070,12 @@ "dev": true, "license": "MIT" }, + "node_modules/long": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", + "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==", + "license": "Apache-2.0" + }, "node_modules/loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -5534,6 +6118,18 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/matcher": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz", + "integrity": "sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==", + "license": "MIT", + "dependencies": { + "escape-string-regexp": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -5650,6 +6246,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/motion-dom": { + "version": "11.18.1", + "resolved": "https://registry.npmjs.org/motion-dom/-/motion-dom-11.18.1.tgz", + "integrity": "sha512-g76KvA001z+atjfxczdRtw/RXOM3OMSdd1f4DL77qCTF/+avrRJiawSG4yDibEQ215sr9kpinSlX2pCTJ9zbhw==", + "license": "MIT", + "dependencies": { + "motion-utils": "^11.18.1" + } + }, + "node_modules/motion-utils": { + "version": "11.18.1", + "resolved": "https://registry.npmjs.org/motion-utils/-/motion-utils-11.18.1.tgz", + "integrity": "sha512-49Kt+HKjtbJKLtgO/LKj9Ld+6vw9BjH5d9sc40R/kVyH8GLAXgT42M2NnuPcJNuA3s9ZfZBUcwIgpmZWGEE+hA==", + "license": "MIT" + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -5697,6 +6308,16 @@ "dev": true, "license": "MIT" }, + "node_modules/ndarray": { + "version": "1.0.19", + "resolved": "https://registry.npmjs.org/ndarray/-/ndarray-1.0.19.tgz", + "integrity": "sha512-B4JHA4vdyZU30ELBw3g7/p9bZupyew5a7tX1Y/gGeF2hafrPaQZhgrGQfsvgfYbgdFZjYwuEcnaobeM/WMW+HQ==", + "license": "MIT", + "dependencies": { + "iota-array": "^1.0.0", + "is-buffer": "^1.0.2" + } + }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -5806,6 +6427,26 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/node-fetch": { + "version": "2.6.13", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.13.tgz", + "integrity": "sha512-StxNAxh15zr77QvvkmveSQ8uCQ4+v5FkvNTj0OESmiHu+VRi/gXArXtkWMElOsOUNLtUEvI4yS+rdtOHZTwlQA==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-releases": { "version": "2.0.50", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.50.tgz", @@ -5841,7 +6482,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -5949,6 +6589,64 @@ "node": ">= 0.8" } }, + "node_modules/onnxruntime-common": { + "version": "1.24.3", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.24.3.tgz", + "integrity": "sha512-GeuPZO6U/LBJXvwdaqHbuUmoXiEdeCjWi/EG7Y1HNnDwJYuk6WUbNXpF6luSUY8yASul3cmUlLGrCCL1ZgVXqA==", + "license": "MIT" + }, + "node_modules/onnxruntime-node": { + "version": "1.24.3", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.24.3.tgz", + "integrity": "sha512-JH7+czbc8ALA819vlTgcV+Q214/+VjGeBHDjX81+ZCD0PCVCIFGFNtT0V4sXG/1JXypKPgScQcB3ij/hk3YnTg==", + "hasInstallScript": true, + "license": "MIT", + "os": [ + "win32", + "darwin", + "linux" + ], + "dependencies": { + "adm-zip": "^0.5.16", + "global-agent": "^3.0.0", + "onnxruntime-common": "1.24.3" + } + }, + "node_modules/onnxruntime-web": { + "version": "1.26.0-dev.20260416-b7804b056c", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.26.0-dev.20260416-b7804b056c.tgz", + "integrity": "sha512-MD6Ss4GSpQBo6zqoJzyT9LRbKYs7x/JVN23FT24EcEvlqF4VuzPOeH6X38orZPKHQDbprn7K+SBpu0/mj2CQiw==", + "license": "MIT", + "dependencies": { + "flatbuffers": "^25.1.24", + "guid-typescript": "^1.0.9", + "long": "^5.2.3", + "onnxruntime-common": "1.24.0-dev.20251116-b39e144322", + "platform": "^1.3.6", + "protobufjs": "^7.2.4" + } + }, + "node_modules/onnxruntime-web/node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, + "node_modules/onnxruntime-web/node_modules/onnxruntime-common": { + "version": "1.24.0-dev.20251116-b39e144322", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.24.0-dev.20251116-b39e144322.tgz", + "integrity": "sha512-BOoomdHYmNRL5r4iQ4bMvsl2t0/hzVQ3OM3PHD0gxeXu1PmggqBv3puZicEUVOA3AtHHYmqZtjMj9FOfGrATTw==", + "license": "MIT" + }, + "node_modules/opencollective-postinstall": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", + "integrity": "sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==", + "license": "MIT", + "bin": { + "opencollective-postinstall": "index.js" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -6091,6 +6789,12 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/platform": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", + "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", + "license": "MIT" + }, "node_modules/possible-typed-array-names": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz", @@ -6152,6 +6856,35 @@ "react-is": "^16.13.1" } }, + "node_modules/protobufjs": { + "version": "7.6.5", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.5.tgz", + "integrity": "sha512-/FPD0nUc9jH6rfFjji9IBqOz4pcSE3CsT1m7Ep6Mdb0LxSUMj8hgl6GomOvZzpNpAqqGaXA0P3VSrZLFzIhQrw==", + "hasInstallScript": true, + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.5", + "@protobufjs/eventemitter": "^1.1.1", + "@protobufjs/fetch": "^1.1.1", + "@protobufjs/float": "^1.0.2", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.1", + "@types/node": ">=13.7.0", + "long": "^5.3.2" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/protobufjs/node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -6287,6 +7020,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/regenerator-runtime": { + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", + "license": "MIT" + }, "node_modules/regexp.prototype.flags": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz", @@ -6308,6 +7047,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/resolve": { "version": "2.0.0-next.7", "resolved": "https://registry.npmjs.org/resolve/-/resolve-2.0.0-next.7.tgz", @@ -6363,6 +7111,23 @@ "node": ">=0.10.0" } }, + "node_modules/roarr": { + "version": "2.15.4", + "resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz", + "integrity": "sha512-CHhPh+UNHD2GTXNYhPWLnU8ONHdI+5DI+4EYIAOaiD63rHeYlZvyh8P+in5999TTSFgUYuKUAjzRI4mdh/p+2A==", + "license": "BSD-3-Clause", + "dependencies": { + "boolean": "^3.0.1", + "detect-node": "^2.0.4", + "globalthis": "^1.0.1", + "json-stringify-safe": "^5.0.1", + "semver-compare": "^1.0.0", + "sprintf-js": "^1.1.2" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -6474,6 +7239,12 @@ "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==", "license": "MIT" }, + "node_modules/seedrandom": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz", + "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==", + "license": "MIT" + }, "node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", @@ -6484,6 +7255,12 @@ "semver": "bin/semver.js" } }, + "node_modules/semver-compare": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", + "integrity": "sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==", + "license": "MIT" + }, "node_modules/send": { "version": "0.19.2", "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", @@ -6523,6 +7300,21 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "license": "MIT" }, + "node_modules/serialize-error": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-7.0.1.tgz", + "integrity": "sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==", + "license": "MIT", + "dependencies": { + "type-fest": "^0.13.1" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/serve-static": { "version": "1.16.3", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", @@ -6599,7 +7391,6 @@ "integrity": "sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg==", "hasInstallScript": true, "license": "Apache-2.0", - "optional": true, "dependencies": { "@img/colour": "^1.0.0", "detect-libc": "^2.1.2", @@ -6643,7 +7434,6 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", "license": "ISC", - "optional": true, "bin": { "semver": "bin/semver.js" }, @@ -6783,6 +7573,12 @@ "node": ">=0.10.0" } }, + "node_modules/sprintf-js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", + "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", + "license": "BSD-3-Clause" + }, "node_modules/stable-hash": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stable-hash/-/stable-hash-0.0.5.tgz", @@ -6813,6 +7609,35 @@ "node": ">= 0.4" } }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT" + }, "node_modules/string.prototype.includes": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/string.prototype.includes/-/string.prototype.includes-2.0.1.tgz", @@ -6927,6 +7752,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -6977,7 +7814,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "license": "MIT", "dependencies": { "has-flag": "^4.0.0" @@ -7030,6 +7866,31 @@ "url": "https://opencollective.com/webpack" } }, + "node_modules/tesseract.js": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tesseract.js/-/tesseract.js-5.1.1.tgz", + "integrity": "sha512-lzVl/Ar3P3zhpUT31NjqeCo1f+D5+YfpZ5J62eo2S14QNVOmHBTtbchHm/YAbOOOzCegFnKf4B3Qih9LuldcYQ==", + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "bmp-js": "^0.1.0", + "idb-keyval": "^6.2.0", + "is-electron": "^2.2.2", + "is-url": "^1.2.4", + "node-fetch": "^2.6.9", + "opencollective-postinstall": "^2.0.3", + "regenerator-runtime": "^0.13.3", + "tesseract.js-core": "^5.1.1", + "wasm-feature-detect": "^1.2.11", + "zlibjs": "^0.3.1" + } + }, + "node_modules/tesseract.js-core": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tesseract.js-core/-/tesseract.js-core-5.1.1.tgz", + "integrity": "sha512-KX3bYSU5iGcO1XJa+QGPbi+Zjo2qq6eBhNjSGR5E5q0JtzkoipJKOUQD7ph8kFyteCEfEQ0maWLu8MCXtvX5uQ==", + "license": "Apache-2.0" + }, "node_modules/tinyglobby": { "version": "0.2.17", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", @@ -7100,6 +7961,12 @@ "node": ">=0.6" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/ts-api-utils": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz", @@ -7158,6 +8025,18 @@ "node": ">= 0.8.0" } }, + "node_modules/type-fest": { + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz", + "integrity": "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -7310,7 +8189,6 @@ "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", - "dev": true, "license": "MIT" }, "node_modules/unpipe": { @@ -7401,6 +8279,15 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz", + "integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", @@ -7419,6 +8306,28 @@ "node": ">= 0.8" } }, + "node_modules/wasm-feature-detect": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/wasm-feature-detect/-/wasm-feature-detect-1.8.0.tgz", + "integrity": "sha512-zksaLKM2fVlnB5jQQDqKXXwYHLQUVH9es+5TOOHwGOVJOCeRBCiPjwSg+3tN2AdTCzjgli4jijCH290kXb/zWQ==", + "license": "Apache-2.0" + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -7534,6 +8443,23 @@ "node": ">=0.10.0" } }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/ws": { "version": "8.21.1", "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.1.tgz", @@ -7563,6 +8489,15 @@ "node": ">=0.4.0" } }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "license": "ISC", + "engines": { + "node": ">=10" + } + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", @@ -7570,6 +8505,33 @@ "dev": true, "license": "ISC" }, + "node_modules/yargs": { + "version": "16.2.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.2.tgz", + "integrity": "sha512-Nt9ZJjXTv5R8MHbqby/wXQ6Gi0Bb3TcYZkR1bzuL4yB2OxWPkXknz513gEF0GoA6tn00UpbPvERW8rzCuWCA6w==", + "license": "MIT", + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs-parser": { + "version": "20.2.9", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", + "license": "ISC", + "engines": { + "node": ">=10" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -7583,6 +8545,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/zlibjs": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/zlibjs/-/zlibjs-0.3.1.tgz", + "integrity": "sha512-+J9RrgTKOmlxFSDHo0pI1xM6BLVUv+o0ZT9ANtCxGkjIVCCUdx9alUF8Gm+dGLKbkkkidWIHFDZHDMpfITt4+w==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/zod": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", @@ -7605,6 +8576,70 @@ "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" } + }, + "node_modules/zustand": { + "version": "4.5.7", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.7.tgz", + "integrity": "sha512-CHOUy7mu3lbD6o6LJLfllpjkzhHXSBlX8B9+qPddUsIfeF5S/UZ5q0kmCsnRqT1UHFQZchNFDDzMbQsuesHWlw==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, + "vendor/photo-gallery-sdk": { + "name": "@photo-gallery/sdk", + "version": "0.1.0", + "license": "MIT", + "dependencies": { + "@tanstack/react-virtual": "^3.10.8", + "clsx": "^2.1.1", + "exifr": "^7.1.3", + "framer-motion": "^11.11.9", + "leaflet": "^1.9.4", + "nanoid": "^5.0.7", + "zustand": "^4.5.5" + }, + "peerDependencies": { + "react": ">=18", + "react-dom": ">=18" + } + }, + "vendor/photo-gallery-sdk/node_modules/nanoid": { + "version": "5.1.16", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.1.16.tgz", + "integrity": "sha512-kVrnsrJqMR8+oLJnGEmSWw9BivK5mt7H3FZatVRjrc5wGqFYuBxX1yG7+A7Gi5AefkX6t/oCkizcQgpu0cY1dQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.js" + }, + "engines": { + "node": "^18 || >=20" + } } } } diff --git a/package.json b/package.json index 4053860..83f029c 100644 --- a/package.json +++ b/package.json @@ -6,21 +6,31 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "eslint" + "lint": "eslint", + "sync:gallery-sdk": "node scripts/sync-gallery-sdk.mjs" }, "dependencies": { "@abe-kap/appshell-sdk": "^0.2.6", + "@huggingface/transformers": "^4.2.0", + "@imgly/background-removal": "^1.7.0", "@insignia/iios-kernel-client": "^0.1.4", - "@insignia/iios-messaging-ui": "^0.1.2", + "@insignia/iios-messaging-ui": "^0.1.7", + "@photo-gallery/sdk": "file:./vendor/photo-gallery-sdk", + "@tensorflow-models/coco-ssd": "^2.2.3", + "@tensorflow/tfjs": "^4.22.0", + "@vladmandic/face-api": "^1.7.15", "clsx": "^2.1.1", + "leaflet": "^1.9.4", "lucide-react": "^1.21.0", "next": "16.2.9", "react": "19.2.4", "react-dom": "19.2.4", - "tailwind-merge": "^3.6.0" + "tailwind-merge": "^3.6.0", + "tesseract.js": "5.1.1" }, "devDependencies": { "@tailwindcss/postcss": "^4", + "@types/leaflet": "^1.9.21", "@types/node": "^20", "@types/react": "^19", "@types/react-dom": "^19", diff --git a/public/push-sw.js b/public/push-sw.js new file mode 100644 index 0000000..a5330f1 --- /dev/null +++ b/public/push-sw.js @@ -0,0 +1,50 @@ +/* Web Push service worker for CRM offline notifications. + * + * Receives push payloads from IIOS (WebPushDelivery), shows a system notification, and on click + * focuses an open CRM tab (or opens one) and posts the thread to deep-link to. The payload shape is + * IIOS's NotificationPayload: { title, body, data: { threadId, interactionId? } }. + * + * Served from /public at /push-sw.js → root scope ('/'), so it controls the whole app. + */ + +self.addEventListener("push", (event) => { + let payload = {}; + try { + payload = event.data ? event.data.json() : {}; + } catch { + payload = { title: "New notification", body: event.data ? event.data.text() : "" }; + } + const title = payload.title || "New message"; + const threadId = payload.data && payload.data.threadId; + event.waitUntil( + self.registration.showNotification(title, { + body: payload.body || "", + // Coalesce repeated pings for the same thread into one notification. + tag: threadId ? `thread:${threadId}` : undefined, + renotify: Boolean(threadId), + data: payload.data || {}, + icon: "/icons/i_bell.svg", + }), + ); +}); + +self.addEventListener("notificationclick", (event) => { + event.notification.close(); + const threadId = event.notification.data && event.notification.data.threadId; + event.waitUntil( + (async () => { + const all = await self.clients.matchAll({ type: "window", includeUncontrolled: true }); + // Prefer an already-open CRM tab: focus it and tell the app which thread to open. + for (const client of all) { + if ("focus" in client) { + await client.focus(); + client.postMessage({ type: "notif-click", threadId: threadId || null }); + return; + } + } + // No tab open — launch one deep-linked via the query string. + const url = threadId ? `/dashboard?thread=${encodeURIComponent(threadId)}` : "/dashboard"; + if (self.clients.openWindow) await self.clients.openWindow(url); + })(), + ); +}); diff --git a/scripts/sync-gallery-sdk.mjs b/scripts/sync-gallery-sdk.mjs new file mode 100644 index 0000000..307aa9c --- /dev/null +++ b/scripts/sync-gallery-sdk.mjs @@ -0,0 +1,73 @@ +#!/usr/bin/env node +/** + * Re-sync the vendored @photo-gallery/sdk from the sibling SDK checkout. + * + * The SDK is not published to a registry yet, so it is vendored into `vendor/photo-gallery-sdk` + * and depended on as `file:./vendor/photo-gallery-sdk` — a path INSIDE this repo, so CI and Vercel + * (which only ever check out this repo) can resolve it. See vendor/README.md. + * + * npm run sync:gallery-sdk + * git add vendor/photo-gallery-sdk && git commit -m "chore: sync @photo-gallery/sdk" + * + * Only what the package would publish is copied. Its `node_modules` is deliberately left behind: + * without it the SDK's sources resolve `@types/react` from this repo (React 19) instead of the + * pnpm workspace's React 18, which is what lets them type-check here. + */ + +import { cp, readFile, rm, stat, writeFile } from "node:fs/promises"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const source = + process.env.GALLERY_SDK_PATH ?? + resolve(root, "../advance-photo-gallery-web-sdk/packages/photo-sdk"); +const target = resolve(root, "vendor/photo-gallery-sdk"); + +const ENTRIES = ["src", "package.json", "README.md"]; + +const exists = async (p) => { + try { + await stat(p); + return true; + } catch { + return false; + } +}; + +if (!(await exists(source))) { + console.error(`[sync:gallery-sdk] SDK checkout not found at ${source}`); + console.error(" Clone advance-photo-gallery-web-sdk beside this repo, or set GALLERY_SDK_PATH."); + process.exit(1); +} + +for (const entry of ENTRIES) { + const from = resolve(source, entry); + if (!(await exists(from))) continue; + const to = resolve(target, entry); + await rm(to, { recursive: true, force: true }); + await cp(from, to, { recursive: true }); + console.log(`[sync:gallery-sdk] ${entry}`); +} + +/* + * Strip devDependencies + scripts from the vendored manifest. + * + * npm never installs a published package's devDependencies, but it DOES install them for a local + * `file:` path package. Left in place, the SDK's `@types/react@18` lands in + * vendor/photo-gallery-sdk/node_modules and its sources then type-check against React 18 inside a + * React 19 program — "Type 'bigint' is not assignable to type 'ReactNode'". Removing them makes the + * vendored copy behave exactly like the tarball it stands in for. + */ +const manifestPath = resolve(target, "package.json"); +const manifest = JSON.parse(await readFile(manifestPath, "utf8")); +delete manifest.devDependencies; +delete manifest.scripts; +manifest._vendored = { + from: "advance-photo-gallery-web-sdk/packages/photo-sdk", + note: "Generated by scripts/sync-gallery-sdk.mjs — do not hand-edit. See vendor/README.md.", +}; +await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8"); +console.log("[sync:gallery-sdk] package.json (devDependencies + scripts stripped)"); + +console.log("[sync:gallery-sdk] done — commit vendor/photo-gallery-sdk, then restart the dev server."); diff --git a/src/app/api/gallery/ai/_guard.ts b/src/app/api/gallery/ai/_guard.ts new file mode 100644 index 0000000..2a88ebf --- /dev/null +++ b/src/app/api/gallery/ai/_guard.ts @@ -0,0 +1,61 @@ +/** + * Shared entry gate for every /api/gallery/ai/* route: authenticate, then + * throttle. Lives in a `_`-prefixed file so the App Router never treats it as a + * route (only `route.ts` defines an endpoint). + * + * Order matters: we authenticate FIRST so the rate limit can be keyed by + * principal rather than by a spoofable `x-forwarded-for` hop wherever possible. + * The session check is one cheap BFF round trip; the work it guards is a GPU + * call, so paying it before throttling is the right trade. + * + * SERVER-ONLY. + */ + +import { NextResponse } from "next/server"; + +import { limit } from "@/lib/server/rate-limit"; +import { rateLimitKey, requireGallerySession } from "@/lib/server/session"; + +/** Per-minute budgets, per the Smart Gallery route contract. */ +export const RATE_LIMITS = { + classify: 30, + edit: 12, + tilt: 30, + transcribe: 20, + denoise: 20, +} as const; + +const WINDOW_MS = 60_000; + +export type GuardResult = + | { ok: true; principalId?: string } + /** Ready-to-return error response — the route should return it unchanged. */ + | { ok: false; response: NextResponse }; + +/** + * @param route Which budget to apply (also namespaces the limiter key so a + * caller's `edit` spend does not consume their `classify` budget). + */ +export async function guard(req: Request, route: keyof typeof RATE_LIMITS): Promise { + const session = await requireGallerySession(req); + if (!session.ok) { + return { + ok: false, + response: NextResponse.json({ error: session.error }, { status: session.status }), + }; + } + + const key = `${route}:${rateLimitKey(req, session.principalId)}`; + const { ok, retryAfter } = limit(key, RATE_LIMITS[route], WINDOW_MS); + if (!ok) { + return { + ok: false, + response: NextResponse.json( + { error: "Too many requests — slow down." }, + { status: 429, headers: { "Retry-After": String(retryAfter) } }, + ), + }; + } + + return { ok: true, principalId: session.principalId }; +} diff --git a/src/app/api/gallery/ai/classify/route.ts b/src/app/api/gallery/ai/classify/route.ts new file mode 100644 index 0000000..3aeb216 --- /dev/null +++ b/src/app/api/gallery/ai/classify/route.ts @@ -0,0 +1,71 @@ +import { type NextRequest, NextResponse } from "next/server"; + +import { RunpodError } from "@/lib/server/runpod/client"; +import { rpDetect } from "@/lib/server/runpod/endpoints"; + +import { guard } from "../_guard"; + +export const runtime = "nodejs"; +export const maxDuration = 60; +export const dynamic = "force-dynamic"; + +/** + * Object-detection proxy for the RunPod YOLO construction-material classifier (#1). + * The key + endpoint URL stay server-side. The client calls this only when + * NEXT_PUBLIC_APG_RUNPOD_DETECT is on; otherwise detection runs fully in-browser + * (COCO-SSD) with no server round-trip. Returns the SDK's DetectedObject[] shape + * (box as 0..1 fractions) so it drops straight into the Objects browser / smart + * albums / search. + * + * POST { imageBase64, width, height } -> { objects: [{ label, confidence, box }] } + * Auth: session-gated (see lib/server/session.ts). Rate limit: 30/min. + */ + +const MAX_BASE64 = 4_000_000; // ~3 MB decoded — under serverless body limits + +export async function POST(req: NextRequest) { + const gate = await guard(req, "classify"); + if (!gate.ok) return gate.response; + + if (!process.env.RUNPOD_API_KEY || !process.env.RUNPOD_YOLO_URL) { + return NextResponse.json( + { error: "RunPod detection is not configured (set RUNPOD_API_KEY + RUNPOD_YOLO_URL)." }, + { status: 503 }, + ); + } + + let body: unknown; + try { + body = await req.json(); + } catch { + return NextResponse.json({ error: "Invalid request body." }, { status: 400 }); + } + + const { imageBase64, width, height } = (body ?? {}) as { + imageBase64?: unknown; + width?: unknown; + height?: unknown; + }; + if ( + typeof imageBase64 !== "string" || + imageBase64.length === 0 || + imageBase64.length > MAX_BASE64 + ) { + return NextResponse.json({ error: "Invalid or oversized image." }, { status: 400 }); + } + const w = Number(width); + const h = Number(height); + + try { + const objects = await rpDetect( + imageBase64, + Number.isFinite(w) && w > 0 ? w : 1, + Number.isFinite(h) && h > 0 ? h : 1, + ); + return NextResponse.json({ objects }); + } catch (err) { + const message = err instanceof Error ? err.message : "Detection failed."; + const status = err instanceof RunpodError ? err.status : 502; + return NextResponse.json({ error: message }, { status }); + } +} diff --git a/src/app/api/gallery/ai/denoise/route.ts b/src/app/api/gallery/ai/denoise/route.ts new file mode 100644 index 0000000..95dc649 --- /dev/null +++ b/src/app/api/gallery/ai/denoise/route.ts @@ -0,0 +1,48 @@ +import { type NextRequest, NextResponse } from "next/server"; + +import { RunpodError } from "@/lib/server/runpod/client"; +import { rpDenoiseAudio } from "@/lib/server/runpod/endpoints"; + +import { guard } from "../_guard"; + +export const runtime = "nodejs"; +export const maxDuration = 60; // cold-start denoise worker can take a while +export const dynamic = "force-dynamic"; + +/** + * Audio noise-removal proxy. Accepts base64 WAV (48 kHz mono PCM16, produced + * in-browser) and returns a cleaned base64 WAV. Calls the RunPod audio-denoise + * endpoint (RUNPOD_AUDIO_DENOISE_URL) — key stays server-side. Used before + * transcription on noisy sites. + * + * POST { audio } -> { audio } + * Auth: session-gated. Rate limit: 20/min. + */ + +const MAX_BASE64 = 12_000_000; // ~9 MB decoded WAV + +export async function POST(req: NextRequest) { + const gate = await guard(req, "denoise"); + if (!gate.ok) return gate.response; + + let body: { audio?: unknown }; + try { + body = await req.json(); + } catch { + return NextResponse.json({ error: "Invalid JSON body." }, { status: 400 }); + } + + const audio = typeof body.audio === "string" ? body.audio : ""; + if (!audio) return NextResponse.json({ error: "Missing audio." }, { status: 400 }); + if (audio.length > MAX_BASE64) { + return NextResponse.json({ error: "Audio too long — keep it under ~30s." }, { status: 413 }); + } + + try { + const { audioB64 } = await rpDenoiseAudio(audio); + return NextResponse.json({ audio: audioB64 }); + } catch (e) { + const msg = e instanceof RunpodError ? e.message : e instanceof Error ? e.message : "Denoise failed."; + return NextResponse.json({ error: msg }, { status: 502 }); + } +} diff --git a/src/app/api/gallery/ai/edit/route.ts b/src/app/api/gallery/ai/edit/route.ts new file mode 100644 index 0000000..2b70aae --- /dev/null +++ b/src/app/api/gallery/ai/edit/route.ts @@ -0,0 +1,419 @@ +import { type NextRequest, NextResponse } from "next/server"; + +import { RunpodError } from "@/lib/server/runpod/client"; +import { + rpImg2Img, + rpInpaint, + rpRemoveBackground, + rpUpscale, +} from "@/lib/server/runpod/endpoints"; + +import { guard } from "../_guard"; + +export const runtime = "nodejs"; +export const maxDuration = 60; // SD / cold-start models can take a while +export const dynamic = "force-dynamic"; + +/** + * Generative image-edit proxy. The BACKEND is pluggable — pick one with env + * `AI_EDIT_PROVIDER` (default `auto`): + * + * - `runpod` → RunPod serverless GPU endpoints (one per model). Maps each + * op → endpoint: restore/upscale → Real-ESRGAN (#7), colorize + * → img2img (#10), replace-sky / magic-eraser / generative-fill + * → SD 3.5 masked inpaint (#9), prompt → SD 3.5 img2img (#10). + * Env: RUNPOD_API_KEY + per-model RUNPOD_*_URL. Key stays + * server-side. + * - `local` → your own Stable Diffusion server (Automatic1111 / Forge / + * SD.Next img2img API). Env: LOCAL_SD_URL. + * - `huggingface` → Hugging Face Inference API. Env: HF_API_TOKEN, HF_IMAGE_MODEL. + * - `gemini` → Google Gemini image model (needs a billed key for image output). + * Env: GEMINI_API_KEY, GEMINI_IMAGE_MODEL. + * - `auto` → first configured of: runpod → local → huggingface → gemini. + * + * NOTE: `remove-background` runs in-browser by default (@imgly, no key), so it + * usually never reaches here. Object detection uses its own route (./classify). + * + * POST { imageBase64, mimeType?, op, maskBase64?, params? } -> { imageBase64, mimeType } + * Auth: session-gated. Rate limit: 12/min (the most expensive route). + */ + +const OP_PROMPTS: Record = { + restore: + "Restore and enhance this photograph: improve sharpness and clarity, correct exposure and white balance, reduce noise and compression artifacts, recover detail. Keep it natural and photorealistic.", + colorize: "Colorize this image with natural, realistic, well-balanced colors.", + "replace-sky": + "Replace the sky with a dramatic, beautiful golden-hour sky with soft clouds. Keep the foreground subject unchanged and the result photorealistic.", +}; + +const MAX_BASE64 = 4_000_000; // ~3 MB decoded — stays under serverless body limits + +type Provider = "runpod" | "local" | "huggingface" | "gemini" | "none"; + +function resolveProvider(): Provider { + const explicit = (process.env.AI_EDIT_PROVIDER || "auto").toLowerCase(); + if ( + explicit === "runpod" || + explicit === "local" || + explicit === "huggingface" || + explicit === "gemini" + ) + return explicit; + if (explicit === "none") return "none"; + // auto: prefer RunPod GPU endpoints, then a private local server, then HF, then Gemini. + // Detect RunPod when the key + ANY image endpoint URL is set (an upscale/colorize-only + // deployment is valid — not just the SD ones). + if ( + process.env.RUNPOD_API_KEY && + (process.env.RUNPOD_SD_IMG2IMG_URL || + process.env.RUNPOD_SD_INPAINT_URL || + process.env.RUNPOD_UPSCALE_URL || + process.env.RUNPOD_COLORIZE_URL || + process.env.RUNPOD_BG_REMOVE_URL) + ) + return "runpod"; + if (process.env.LOCAL_SD_URL) return "local"; + if (process.env.HF_API_TOKEN) return "huggingface"; + if (process.env.GEMINI_API_KEY) return "gemini"; + return "none"; +} + +/** Ops that only the RunPod (mask/fixed-function) backend can serve. */ +const RUNPOD_ONLY_OPS = new Set(["upscale", "magic-eraser", "generative-fill"]); + +interface EditResult { + imageBase64: string; + mimeType: string; +} + +export async function POST(req: NextRequest) { + const gate = await guard(req, "edit"); + if (!gate.ok) return gate.response; + + const provider = resolveProvider(); + if (provider === "none") { + return NextResponse.json( + { + error: + "AI image editing is not configured. Set AI_EDIT_PROVIDER=runpod + RUNPOD_API_KEY + the per-model RUNPOD_*_URL vars (RunPod GPU), or LOCAL_SD_URL (own Stable Diffusion), HF_API_TOKEN (Hugging Face), or GEMINI_API_KEY. Background removal and all analysis still work with no key.", + }, + { status: 503 }, + ); + } + + let body: unknown; + try { + body = await req.json(); + } catch { + return NextResponse.json({ error: "Invalid request body." }, { status: 400 }); + } + + const { imageBase64, mimeType, op, maskBase64, params } = (body ?? {}) as { + imageBase64?: unknown; + mimeType?: unknown; + op?: { type?: string; prompt?: string; factor?: number }; + maskBase64?: unknown; + params?: unknown; + }; + + if (typeof imageBase64 !== "string" || imageBase64.length === 0) { + return NextResponse.json({ error: "Invalid image." }, { status: 400 }); + } + const hasMask = typeof maskBase64 === "string" && maskBase64.length > 0; + // Image + mask share one request body — budget them together against the cap. + if (imageBase64.length + (hasMask ? (maskBase64 as string).length : 0) > MAX_BASE64) { + return NextResponse.json( + { error: "Image (plus mask) is too large — try a smaller image." }, + { status: 400 }, + ); + } + const safeMime = + typeof mimeType === "string" && /^image\/(jpeg|png|webp)$/.test(mimeType) + ? mimeType + : "image/jpeg"; + + const opType = op?.type ?? ""; + if (provider !== "runpod" && RUNPOD_ONLY_OPS.has(opType)) { + return NextResponse.json( + { error: "This edit needs the RunPod backend (set AI_EDIT_PROVIDER=runpod)." }, + { status: 400 }, + ); + } + + // Build the instruction from an allow-listed op (never trust arbitrary server prompts). + let instruction = ""; + if (opType === "prompt" || opType === "generative-fill") { + const p = typeof op?.prompt === "string" ? op.prompt.trim() : ""; + if (!p) return NextResponse.json({ error: "Empty prompt." }, { status: 400 }); + instruction = p.slice(0, 500); + } else if (opType === "replace-sky") { + instruction = + typeof op?.prompt === "string" && op.prompt.trim() + ? `Replace the sky with: ${op.prompt.trim().slice(0, 300)}. Keep the foreground unchanged and photorealistic.` + : OP_PROMPTS["replace-sky"]!; + } else if (opType === "magic-eraser") { + instruction = + "Fill the selected region with a clean, seamless, plausible background. Photorealistic."; + } else if (OP_PROMPTS[opType]) { + instruction = OP_PROMPTS[opType]!; + } else if (opType !== "upscale" && opType !== "remove-background") { + return NextResponse.json({ error: "Unsupported operation." }, { status: 400 }); + } + + try { + let result: EditResult; + if (provider === "runpod") + result = await editRunPod( + op ?? {}, + imageBase64, + instruction, + hasMask ? (maskBase64 as string) : undefined, + params, + ); + else if (provider === "local") result = await editLocal(instruction, imageBase64); + else if (provider === "huggingface") result = await editHuggingFace(instruction, imageBase64); + else result = await editGemini(instruction, imageBase64, safeMime); + return NextResponse.json(result); + } catch (err) { + const message = err instanceof Error ? err.message : "AI request failed."; + const status = err instanceof AiError || err instanceof RunpodError ? err.status : 502; + return NextResponse.json({ error: message }, { status }); + } +} + +// --------------------------------------------------------------------------- +// Backend: RunPod serverless GPU endpoints (one model per endpoint). +// Each op maps to its endpoint; the API key + URLs stay server-side. +// --------------------------------------------------------------------------- +interface SdParams { + negativePrompt?: string; + strength?: number; + steps?: number; + seed?: number; + guidanceScale?: number; +} + +function sanitizeParams(raw: unknown): SdParams { + const p = (raw ?? {}) as Record; + const out: SdParams = {}; + if (typeof p.negativePrompt === "string" && p.negativePrompt.trim()) + out.negativePrompt = p.negativePrompt.trim().slice(0, 300); + const strength = Number(p.strength); + if (Number.isFinite(strength)) out.strength = Math.max(0, Math.min(1, strength)); + const steps = Number(p.steps); + if (Number.isFinite(steps)) out.steps = Math.max(1, Math.min(60, Math.round(steps))); + const guidance = Number(p.guidanceScale); + if (Number.isFinite(guidance)) out.guidanceScale = Math.max(1, Math.min(20, guidance)); + const seed = Number(p.seed); + if (Number.isFinite(seed)) out.seed = Math.max(0, Math.min(2_147_483_647, Math.round(seed))); + return out; +} + +async function editRunPod( + op: { type?: string; prompt?: string; factor?: number }, + imageBase64: string, + instruction: string, + maskBase64: string | undefined, + rawParams: unknown, +): Promise { + const params = sanitizeParams(rawParams); + switch (op.type) { + case "remove-background": + // U²-Net via rembg (#6) — a real endpoint replacing the flaky in-browser remover. + return rpRemoveBackground(imageBase64); + case "restore": + // Real-ESRGAN (#7) with the GFPGAN face pass = "Restore & Enhance". + return rpUpscale(imageBase64, 4, true); + case "upscale": + return rpUpscale(imageBase64, op.factor === 4 ? 4 : 2, false); + case "colorize": + // The dedicated DDColor endpoint kept hard-crashing (modelscope). Route + // colorize through the img2img model as an instruction instead. + return rpImg2Img({ imageB64: imageBase64, prompt: instruction, ...params }); + case "prompt": + return rpImg2Img({ imageB64: imageBase64, prompt: instruction, ...params }); // SD 3.5 img2img (#10) + case "replace-sky": + // True sky replacement is masked inpaint (#9). Without a mask (no in-app sky + // segmentation yet) degrade to a low-strength img2img (#10) so the foreground + // is mostly preserved. + if (maskBase64) + return rpInpaint({ + imageB64: imageBase64, + maskB64: maskBase64, + prompt: instruction, + ...params, + }); + return rpImg2Img({ + imageB64: imageBase64, + prompt: instruction, + ...params, + strength: params.strength ?? 0.4, + }); + case "magic-eraser": + case "generative-fill": + // SD 3.5 masked inpaint (#9) — white in the mask = the region to regenerate. + if (!maskBase64) throw new AiError("This edit needs a mask/selection.", 400); + return rpInpaint({ + imageB64: imageBase64, + maskB64: maskBase64, + prompt: instruction, + ...params, + }); + default: + throw new AiError("Unsupported operation.", 400); + } +} + +class AiError extends Error { + status: number; + constructor(message: string, status = 502) { + super(message); + this.status = status; + } +} + +// --------------------------------------------------------------------------- +// Backend: local Stable Diffusion (Automatic1111 / Forge / SD.Next img2img API) +// --------------------------------------------------------------------------- +async function editLocal(instruction: string, imageBase64: string): Promise { + const base = process.env.LOCAL_SD_URL; + if (!base || !/^https?:\/\//i.test(base)) { + throw new AiError("LOCAL_SD_URL is not a valid http(s) URL.", 500); + } + const url = `${base.replace(/\/$/, "")}/sdapi/v1/img2img`; + let res: Response; + try { + res = await fetch(url, { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ + init_images: [imageBase64], + prompt: instruction, + denoising_strength: Number(process.env.LOCAL_SD_DENOISE ?? 0.55), + steps: Number(process.env.LOCAL_SD_STEPS ?? 25), + cfg_scale: 7, + sampler_name: process.env.LOCAL_SD_SAMPLER || "Euler a", + }), + cache: "no-store", + }); + } catch { + throw new AiError("Could not reach your local Stable Diffusion server (LOCAL_SD_URL).", 502); + } + if (!res.ok) { + throw new AiError(`Local SD server error (${res.status}).`, 502); + } + const data = (await res.json().catch(() => null)) as { images?: string[] } | null; + const out = data?.images?.[0]; + if (!out) throw new AiError("Local SD server did not return an image.", 502); + // A1111 returns raw base64 PNG (no data: prefix). + return { imageBase64: out.includes(",") ? out.split(",")[1]! : out, mimeType: "image/png" }; +} + +// --------------------------------------------------------------------------- +// Backend: Hugging Face Inference API — instruction image editing. +// --------------------------------------------------------------------------- +async function editHuggingFace(instruction: string, imageBase64: string): Promise { + const token = process.env.HF_API_TOKEN; + if (!token) throw new AiError("HF_API_TOKEN is not set.", 500); + const model = process.env.HF_IMAGE_MODEL || "timbrooks/instruct-pix2pix"; + let res: Response; + try { + res = await fetch(`https://api-inference.huggingface.co/models/${model}`, { + method: "POST", + headers: { + authorization: `Bearer ${token}`, + "content-type": "application/json", + // Wait for the model to warm up instead of a fast 503. + "x-wait-for-model": "true", + }, + body: JSON.stringify({ + inputs: imageBase64, + parameters: { prompt: instruction, guidance_scale: 7, image_guidance_scale: 1.5 }, + }), + cache: "no-store", + }); + } catch { + throw new AiError("Could not reach the Hugging Face Inference API.", 502); + } + if (!res.ok) { + // Truncated on purpose — never surface a full upstream body. + const detail = (await res.text().catch(() => "")).slice(0, 160); + if (res.status === 503) throw new AiError("The model is loading — try again in ~20s.", 503); + throw new AiError(`Hugging Face error (${res.status}). ${detail}`, 502); + } + // Success returns raw image bytes. + const outMime = res.headers.get("content-type") || "image/png"; + if (outMime.startsWith("application/json")) { + const j = (await res.json().catch(() => null)) as { error?: string } | null; + throw new AiError( + j?.error ? `Hugging Face: ${j.error}` : "Hugging Face returned no image.", + 502, + ); + } + const buf = await res.arrayBuffer(); + return { imageBase64: Buffer.from(buf).toString("base64"), mimeType: outMime }; +} + +// --------------------------------------------------------------------------- +// Backend: Google Gemini image model (needs a billed key for image output). +// --------------------------------------------------------------------------- +async function editGemini( + instruction: string, + imageBase64: string, + safeMime: string, +): Promise { + const apiKey = process.env.GEMINI_API_KEY; + if (!apiKey) throw new AiError("GEMINI_API_KEY is not set.", 500); + const model = process.env.GEMINI_IMAGE_MODEL || "gemini-2.5-flash-image"; + const prompt = `Edit this image as follows: ${instruction}. Preserve realism unless explicitly asked otherwise.`; + let res: Response; + try { + res = await fetch( + `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`, + { + method: "POST", + headers: { "content-type": "application/json", "x-goog-api-key": apiKey }, + body: JSON.stringify({ + contents: [ + { + role: "user", + parts: [ + { inlineData: { mimeType: safeMime, data: imageBase64 } }, + { text: prompt }, + ], + }, + ], + generationConfig: { responseModalities: ["IMAGE"] }, + }), + cache: "no-store", + }, + ); + } catch { + throw new AiError("Could not reach the AI service.", 502); + } + if (!res.ok) { + // Truncated on purpose — never surface a full upstream body. + const detail = (await res.text().catch(() => "")).slice(0, 160); + throw new AiError(`AI service error (${res.status}). ${detail}`, 502); + } + const data = (await res.json().catch(() => null)) as GeminiResponse | null; + const parts = data?.candidates?.[0]?.content?.parts ?? []; + const imgPart = parts.find((p) => p.inlineData?.data || p.inline_data?.data); + const out = imgPart?.inlineData?.data ?? imgPart?.inline_data?.data; + if (!out) + throw new AiError( + "The model did not return an image (the free Gemini tier has no image output — use LOCAL_SD_URL or HF_API_TOKEN instead).", + 502, + ); + const outMime = imgPart?.inlineData?.mimeType ?? imgPart?.inline_data?.mime_type ?? "image/png"; + return { imageBase64: out, mimeType: outMime }; +} + +interface GeminiPart { + text?: string; + inlineData?: { mimeType?: string; data?: string }; + inline_data?: { mime_type?: string; data?: string }; +} +interface GeminiResponse { + candidates?: Array<{ content?: { parts?: GeminiPart[] } }>; +} diff --git a/src/app/api/gallery/ai/tilt/route.ts b/src/app/api/gallery/ai/tilt/route.ts new file mode 100644 index 0000000..03cb300 --- /dev/null +++ b/src/app/api/gallery/ai/tilt/route.ts @@ -0,0 +1,48 @@ +import { type NextRequest, NextResponse } from "next/server"; + +import { RunpodError } from "@/lib/server/runpod/client"; +import { rpTilt } from "@/lib/server/runpod/endpoints"; + +import { guard } from "../_guard"; + +export const runtime = "nodejs"; +export const maxDuration = 60; // cold-start tilt worker can take a while +export const dynamic = "force-dynamic"; + +/** + * Camera-tilt estimation proxy. Accepts a base64 image and returns + * {rollDegrees, pitchDegrees, fovDegrees} from the RunPod tilt endpoint + * (RUNPOD_TILT_URL) so the editor can auto-straighten. + * + * POST { image } -> { rollDegrees, pitchDegrees, fovDegrees } + * Auth: session-gated. Rate limit: 30/min. + */ + +const MAX_BASE64 = 4_000_000; // ~3 MB decoded + +export async function POST(req: NextRequest) { + const gate = await guard(req, "tilt"); + if (!gate.ok) return gate.response; + + let body: { image?: unknown }; + try { + body = await req.json(); + } catch { + return NextResponse.json({ error: "Invalid JSON body." }, { status: 400 }); + } + + const image = typeof body.image === "string" ? body.image : ""; + if (!image) return NextResponse.json({ error: "Missing image." }, { status: 400 }); + if (image.length > MAX_BASE64) { + return NextResponse.json({ error: "Image too large." }, { status: 413 }); + } + + try { + const tilt = await rpTilt(image); + return NextResponse.json(tilt); + } catch (e) { + const msg = + e instanceof RunpodError ? e.message : e instanceof Error ? e.message : "Tilt estimate failed."; + return NextResponse.json({ error: msg }, { status: 502 }); + } +} diff --git a/src/app/api/gallery/ai/transcribe/route.ts b/src/app/api/gallery/ai/transcribe/route.ts new file mode 100644 index 0000000..8428024 --- /dev/null +++ b/src/app/api/gallery/ai/transcribe/route.ts @@ -0,0 +1,49 @@ +import { type NextRequest, NextResponse } from "next/server"; + +import { RunpodError } from "@/lib/server/runpod/client"; +import { rpTranscribe } from "@/lib/server/runpod/endpoints"; + +import { guard } from "../_guard"; + +export const runtime = "nodejs"; +export const maxDuration = 60; // cold-start STT worker can take a while +export const dynamic = "force-dynamic"; + +/** + * Speech-to-text proxy for voice annotations. Accepts base64 WAV (16 kHz mono + * PCM16, produced in-browser) and returns the transcript. Calls the RunPod + * voice-to-text endpoint (RUNPOD_STT_URL) — the key stays server-side. + * + * POST { audio, language? } -> { transcript, segments? } + * Auth: session-gated. Rate limit: 20/min. + */ + +const MAX_BASE64 = 8_000_000; // ~6 MB decoded WAV — stays under serverless body limits + +export async function POST(req: NextRequest) { + const gate = await guard(req, "transcribe"); + if (!gate.ok) return gate.response; + + let body: { audio?: unknown; language?: unknown }; + try { + body = await req.json(); + } catch { + return NextResponse.json({ error: "Invalid JSON body." }, { status: 400 }); + } + + const audio = typeof body.audio === "string" ? body.audio : ""; + const language = typeof body.language === "string" ? body.language : undefined; + if (!audio) return NextResponse.json({ error: "Missing audio." }, { status: 400 }); + if (audio.length > MAX_BASE64) { + return NextResponse.json({ error: "Audio too long — keep it under ~30s." }, { status: 413 }); + } + + try { + const { transcript, segments } = await rpTranscribe(audio, { language, punctuation: true }); + return NextResponse.json({ transcript, segments }); + } catch (e) { + const msg = + e instanceof RunpodError ? e.message : e instanceof Error ? e.message : "Transcription failed."; + return NextResponse.json({ error: msg }, { status: 502 }); + } +} diff --git a/src/app/dashboard/dashboard.css b/src/app/dashboard/dashboard.css index 801cd9c..ffd7d21 100644 --- a/src/app/dashboard/dashboard.css +++ b/src/app/dashboard/dashboard.css @@ -1190,6 +1190,326 @@ .dash-root .proj-detail-row span { color: var(--muted); } .dash-root .proj-detail-row b { color: var(--text); font-weight: 700; } + /* ========================================================== */ + /* Leads — pipeline board + rich detail popup */ + /* ========================================================== */ + + /* ---- stat strip ---- */ + .dash-root .leads-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; } + .dash-root .leads-stat { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 16px; border: 1px solid var(--border); background: var(--card-grad); box-shadow: var(--card-hi); position: relative; overflow: hidden; } + .dash-root .leads-stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--orange); } + .dash-root .leads-stat.tone-blue::before { background: var(--blue); } + .dash-root .leads-stat.tone-purple::before { background: var(--purple); } + .dash-root .leads-stat.tone-green::before { background: var(--green); } + .dash-root .leads-stat.tone-orange::before { background: var(--orange); } + .dash-root .leads-stat-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: color-mix(in srgb, var(--orange) 14%, transparent); color: var(--orange); flex: 0 0 auto; } + .dash-root .leads-stat.tone-blue .leads-stat-ic { background: color-mix(in srgb, var(--blue) 16%, transparent); color: #6f9bff; } + .dash-root .leads-stat.tone-purple .leads-stat-ic { background: color-mix(in srgb, var(--purple) 16%, transparent); color: #b07bf2; } + .dash-root .leads-stat.tone-green .leads-stat-ic { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); } + .dash-root .leads-stat-val { font-size: 22px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; } + .dash-root .leads-stat-lbl { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 4px; } + + /* ---- toolbar ---- */ + .dash-root .leads-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; } + .dash-root .leads-search { display: flex; align-items: center; gap: 9px; flex: 1 1 260px; min-width: 220px; height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); } + .dash-root .leads-search:focus-within { border-color: color-mix(in srgb, var(--orange) 55%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 14%, transparent); } + .dash-root .leads-search input { flex: 1; border: 0; background: none; outline: none; color: var(--text); font-family: inherit; font-size: 13.5px; } + .dash-root .leads-search input::placeholder { color: var(--muted); } + .dash-root .leads-search-x { border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; padding: 2px; border-radius: 6px; } + .dash-root .leads-search-x:hover { color: var(--text); background: var(--panel-3); } + .dash-root .leads-tabs { display: inline-flex; gap: 3px; padding: 4px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); } + .dash-root .leads-tab { border: 0; background: none; color: var(--muted); font-family: inherit; font-size: 12.5px; font-weight: 600; padding: 7px 13px; border-radius: 9px; cursor: pointer; transition: 0.14s; } + .dash-root .leads-tab:hover { color: var(--text-2); } + .dash-root .leads-tab.active { background: var(--orange); color: #1a1205; box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--orange) 60%, transparent); } + + /* ---- board ---- */ + .dash-root .leads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; } + .dash-root .lead-card { text-align: left; width: 100%; cursor: pointer; display: flex; flex-direction: column; gap: 11px; padding: 16px 17px; border-radius: 18px; border: 1px solid var(--border); background: var(--card-grad); box-shadow: var(--card-hi), 0 1px 2px rgba(0,0,0,0.18); font-family: inherit; color: var(--text); transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease; } + .dash-root .lead-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--orange) 40%, var(--border)); box-shadow: var(--shadow), 0 14px 34px -20px color-mix(in srgb, var(--orange) 50%, transparent); } + .dash-root .lead-card-top { display: flex; align-items: center; gap: 12px; } + .dash-root .lead-ava { position: relative; border-radius: 50%; padding: 3px; display: inline-flex; } + .dash-root .lead-ava.prio-high { box-shadow: 0 0 0 2px color-mix(in srgb, var(--red) 70%, transparent); } + .dash-root .lead-ava.prio-medium { box-shadow: 0 0 0 2px color-mix(in srgb, var(--orange) 70%, transparent); } + .dash-root .lead-ava.prio-low { box-shadow: 0 0 0 2px var(--border-2); } + .dash-root .lead-card-id { flex: 1; min-width: 0; } + .dash-root .lead-card-name { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; } + .dash-root .lead-card-sub { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--muted); margin-top: 2px; } + .dash-root .lead-card-sub svg { color: var(--orange); } + .dash-root .lead-code { font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-2); } + .dash-root .lead-card-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); } + .dash-root .lead-card-row svg { color: var(--muted); flex: 0 0 auto; } + .dash-root .lead-card-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + .dash-root .lead-card-foot { display: flex; align-items: center; gap: 8px; margin-top: 3px; padding-top: 11px; border-top: 1px solid var(--border); } + .dash-root .lead-source { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); } + .dash-root .lead-card-spacer { flex: 1; } + .dash-root .lead-rep { font-size: 11.5px; color: var(--text-2); font-weight: 600; } + .dash-root .lead-updated { font-size: 10.5px; color: var(--faint, var(--muted)); } + + .dash-root .leads-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 48px 20px; color: var(--muted); } + .dash-root .leads-empty svg { color: var(--muted); margin-bottom: 6px; } + .dash-root .leads-empty h3 { font-size: 16px; color: var(--text); } + + /* ---- detail popup ---- */ + .dash-root .lead-detail { display: flex; flex-direction: column; gap: 16px; } + .dash-root .ld-identity { display: flex; align-items: center; gap: 14px; } + .dash-root .ld-identity-name { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; } + .dash-root .ld-identity-pills { display: flex; gap: 6px; margin-top: 6px; } + .dash-root .ld-storm { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--orange) 30%, var(--border)); background: color-mix(in srgb, var(--orange) 9%, transparent); } + .dash-root .ld-storm-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); flex: 0 0 auto; } + .dash-root .ld-storm-zone { font-size: 13.5px; font-weight: 700; } + .dash-root .ld-storm-meta { font-size: 12px; color: var(--muted); margin-top: 2px; } + + .dash-root .ld-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } + .dash-root .ld-section { border: 1px solid var(--border); border-radius: 14px; background: var(--panel-2); padding: 14px 15px; } + .dash-root .ld-section.wide { grid-column: 1 / -1; } + .dash-root .ld-section-head { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--orange); margin-bottom: 12px; } + .dash-root .ld-section-body { display: flex; flex-direction: column; gap: 3px; } + .dash-root .ld-dl { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); } + .dash-root .ld-dl:last-child { border-bottom: 0; } + .dash-root .ld-dl-k { font-size: 12px; color: var(--muted); flex: 0 0 auto; } + .dash-root .ld-dl-v { font-size: 12.5px; color: var(--text); font-weight: 600; text-align: right; } + .dash-root .ld-assign { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; } + .dash-root .ld-sublabel { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint, var(--muted)); font-weight: 700; margin: 8px 0 6px; } + .dash-root .ld-sublabel:first-child { margin-top: 0; } + .dash-root .ld-contact-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 12.5px; color: var(--text); } + .dash-root .ld-contact-row svg { color: var(--muted); flex: 0 0 auto; } + .dash-root .ld-contact-val { font-weight: 600; } + .dash-root .ld-contact-tag { font-size: 10.5px; color: var(--muted); padding: 2px 7px; border-radius: 99px; background: var(--panel-3); } + .dash-root .ld-notes p { font-size: 12.5px; color: var(--text-2); line-height: 1.5; margin-top: 2px; } + + /* ---- New Lead form ---- */ + .dash-root .nl-form { display: flex; flex-direction: column; gap: 16px; } + .dash-root .nl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; } + .dash-root .nl-grid .ds-field { margin-bottom: 0; } + .dash-root .nl-grid > .ds-field, .dash-root .nl-grid > .nl-full { margin-bottom: 14px; } + .dash-root .nl-full { grid-column: 1 / -1; } + .dash-root .nl-full .ds-field { margin-bottom: 0; } + .dash-root .nl-prio { display: flex; gap: 8px; } + .dash-root .nl-prio-btn { flex: 1; height: 42px; border-radius: 11px; border: 1px solid var(--border-2); background: var(--panel-2); color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer; transition: 0.14s; } + .dash-root .nl-prio-btn:hover { color: var(--text-2); border-color: var(--muted); } + .dash-root .nl-prio-btn.active.low { background: color-mix(in srgb, var(--muted) 22%, transparent); color: var(--text); border-color: var(--muted); } + .dash-root .nl-prio-btn.active.medium { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); border-color: color-mix(in srgb, var(--orange) 55%, transparent); } + .dash-root .nl-prio-btn.active.high { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); border-color: color-mix(in srgb, var(--red) 55%, transparent); } + .dash-root .nl-prio-btn.urg.active.standard { background: color-mix(in srgb, var(--muted) 20%, transparent); color: var(--text); border-color: var(--muted); } + .dash-root .nl-prio-btn.urg.active.high { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); border-color: color-mix(in srgb, var(--orange) 55%, transparent); } + .dash-root .nl-prio-btn.urg.active.emergency { background: color-mix(in srgb, var(--red) 20%, transparent); color: var(--red); border-color: color-mix(in srgb, var(--red) 60%, transparent); } + + /* multi-value rows (phones / emails) */ + .dash-root .nl-multirow { display: flex; gap: 8px; margin-bottom: 8px; } + .dash-root .nl-multirow .ds-input { flex: 1; } + .dash-root .nl-typesel { flex: 0 0 108px; width: 108px; } + .dash-root .nl-rowx { flex: 0 0 auto; width: 42px; border-radius: 11px; border: 1px solid var(--border-2); background: var(--panel-2); color: var(--muted); cursor: pointer; display: grid; place-items: center; transition: 0.14s; } + .dash-root .nl-rowx:hover { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); } + .dash-root .nl-add { display: inline-flex; align-items: center; gap: 6px; margin-top: 2px; padding: 8px 13px; border-radius: 10px; border: 1px dashed var(--border-2); background: none; color: var(--orange); font-family: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; transition: 0.14s; } + .dash-root .nl-add:hover { background: color-mix(in srgb, var(--orange) 10%, transparent); border-color: color-mix(in srgb, var(--orange) 45%, transparent); } + .dash-root .nl-empty { font-size: 12.5px; color: var(--faint, var(--muted)); padding: 8px 0 10px; } + + /* site photos dropzone */ + .dash-root .nl-photos { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 22px; border-radius: 14px; border: 1.5px dashed var(--border-2); background: var(--panel-2); color: var(--muted); cursor: pointer; transition: 0.14s; } + .dash-root .nl-photos:hover { border-color: color-mix(in srgb, var(--orange) 50%, transparent); color: var(--orange); background: color-mix(in srgb, var(--orange) 7%, transparent); } + .dash-root .nl-photos-t { font-size: 13px; font-weight: 700; color: var(--text-2); } + .dash-root .nl-photos:hover .nl-photos-t { color: var(--orange); } + .dash-root .nl-photos-s { font-size: 11px; } + .dash-root .nl-photo-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; } + .dash-root .nl-photo-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 5px 10px; border-radius: 99px; background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); } + .dash-root .ds-select.is-placeholder { color: var(--faint, var(--muted)); } + + /* Canvasser search (Door Knock source) */ + .dash-root .nl-canvasser { position: relative; } + .dash-root .nl-canvasser-menu { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30; max-height: 220px; overflow-y: auto; border: 1px solid var(--border-2); border-radius: 12px; background: var(--panel); box-shadow: 0 12px 32px rgba(0,0,0,0.28); padding: 5px; } + .dash-root .nl-canvasser-opt { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 9px; border: none; border-radius: 9px; background: transparent; color: var(--text); font-family: inherit; font-size: 13px; text-align: left; cursor: pointer; transition: 0.12s; } + .dash-root .nl-canvasser-opt:hover { background: var(--panel-2); } + .dash-root .nl-canvasser-name { font-weight: 700; } + .dash-root .nl-canvasser-email { color: var(--muted); font-size: 12px; } + .dash-root .nl-canvasser-opt .nl-canvasser-email { margin-left: auto; } + .dash-root .nl-canvasser-empty { padding: 10px; color: var(--muted); font-size: 12.5px; text-align: center; } + .dash-root .nl-canvasser-chip { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border: 1px solid var(--border-2); border-radius: 12px; background: var(--panel-2); } + .dash-root .nl-canvasser-chip .nl-canvasser-email { margin-left: 2px; } + .dash-root .nl-canvasser-clear { margin-left: auto; display: grid; place-items: center; width: 26px; height: 26px; border: none; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; transition: 0.12s; } + .dash-root .nl-canvasser-clear:hover { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); } + + /* ========================================================== */ + /* Lead Verification — stat tiles + filters + table */ + /* ========================================================== */ + .dash-root .lv-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; } + .dash-root .lv-stat { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px 16px; border-radius: 16px; border: 1px solid var(--border); background: var(--card-grad); box-shadow: var(--card-hi); cursor: pointer; text-align: left; font-family: inherit; transition: 0.15s; position: relative; } + .dash-root .lv-stat:hover { border-color: var(--border-2); transform: translateY(-2px); } + .dash-root .lv-stat.active { border-color: color-mix(in srgb, var(--accent, var(--orange)) 60%, transparent); box-shadow: var(--card-hi), 0 0 0 1px color-mix(in srgb, var(--accent, var(--orange)) 40%, transparent); } + .dash-root .lv-stat-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; margin-bottom: 6px; } + .dash-root .lv-stat-val { font-size: 22px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; } + .dash-root .lv-stat-lbl { font-size: 11.5px; color: var(--muted); font-weight: 600; } + .dash-root .lv-stat.tone-green { --accent: var(--green); } .dash-root .lv-stat.tone-green .lv-stat-ic { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); } + .dash-root .lv-stat.tone-orange { --accent: var(--orange); } .dash-root .lv-stat.tone-orange .lv-stat-ic { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); } + .dash-root .lv-stat.tone-blue { --accent: var(--blue); } .dash-root .lv-stat.tone-blue .lv-stat-ic { background: color-mix(in srgb, var(--blue) 18%, transparent); color: #6f9bff; } + .dash-root .lv-stat.tone-purple { --accent: var(--purple); } .dash-root .lv-stat.tone-purple .lv-stat-ic { background: color-mix(in srgb, var(--purple) 18%, transparent); color: #b07bf2; } + .dash-root .lv-stat.tone-red { --accent: var(--red); } .dash-root .lv-stat.tone-red .lv-stat-ic { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); } + + .dash-root .lv-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; } + .dash-root .lv-search { display: flex; align-items: center; gap: 9px; flex: 1 1 240px; min-width: 200px; height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); } + .dash-root .lv-search:focus-within { border-color: color-mix(in srgb, var(--orange) 55%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 14%, transparent); } + .dash-root .lv-search input { flex: 1; border: 0; background: none; outline: none; color: var(--text); font-family: inherit; font-size: 13.5px; } + .dash-root .lv-search input::placeholder { color: var(--muted); } + .dash-root .lv-search-x { border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; padding: 2px; border-radius: 6px; } + .dash-root .lv-search-x:hover { color: var(--text); background: var(--panel-3); } + .dash-root .lv-filter { height: 42px; flex: 0 0 auto; width: auto; min-width: 150px; } + + .dash-root .lv-tablewrap { border: 1px solid var(--border); border-radius: 18px; background: var(--card-grad); box-shadow: var(--card-hi); overflow-x: auto; } + .dash-root .lv-table { width: 100%; border-collapse: collapse; min-width: 940px; } + .dash-root .lv-table thead th { text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 14px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; } + .dash-root .lv-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 12.5px; vertical-align: middle; } + .dash-root .lv-table tbody tr:last-child td { border-bottom: 0; } + .dash-root .lv-table tbody tr { transition: background 0.12s; } + .dash-root .lv-table tbody tr:hover { background: color-mix(in srgb, var(--orange) 5%, transparent); } + .dash-root .lv-id { font-family: ui-monospace, monospace; font-size: 12px; font-weight: 700; color: var(--text); white-space: nowrap; } + .dash-root .lv-id-date { font-size: 10.5px; color: var(--faint, var(--muted)); margin-top: 2px; } + .dash-root .lv-cust { display: flex; align-items: center; gap: 10px; min-width: 210px; } + .dash-root .lv-cust-name { font-weight: 700; font-size: 13px; color: var(--text); } + .dash-root .lv-cust-addr { font-size: 11px; color: var(--muted); margin-top: 1px; } + .dash-root .lv-phone { color: var(--text-2); white-space: nowrap; } + .dash-root .lv-source { display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--text-2); padding: 4px 10px; border-radius: 99px; background: var(--panel-3); white-space: nowrap; } + .dash-root .lv-assignee { display: flex; align-items: center; gap: 8px; white-space: nowrap; } + .dash-root .lv-assignee span { font-weight: 600; color: var(--text-2); font-size: 12px; } + .dash-root .lv-unassigned { font-size: 11.5px; color: var(--faint, var(--muted)); } + .dash-root .lv-verif { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; white-space: nowrap; color: var(--muted); } + .dash-root .lv-verif.v-verified { color: var(--green); } + .dash-root .lv-verif.v-in_progress { color: var(--orange); } + .dash-root .lv-verif.v-assigned { color: #6f9bff; } + .dash-root .lv-verif.v-pending { color: #b07bf2; } + .dash-root .lv-verif.v-unverified { color: var(--red); } + .dash-root .lv-created { color: var(--muted); white-space: nowrap; } + .dash-root .lv-rowacts { display: flex; gap: 6px; } + .dash-root .lv-act { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--panel-2); color: var(--muted); cursor: pointer; display: grid; place-items: center; transition: 0.14s; } + .dash-root .lv-act:hover { color: var(--text); border-color: var(--muted); } + .dash-root .lv-act.primary:hover { color: var(--green); border-color: color-mix(in srgb, var(--green) 50%, transparent); background: color-mix(in srgb, var(--green) 10%, transparent); } + .dash-root .lv-empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 13px; } + .dash-root .lv-count { font-size: 11.5px; color: var(--muted); margin-top: 12px; text-align: right; } + + /* ---- row actions dropdown (portalled to body) ---- */ + .lv-menu-scrim { position: fixed; inset: 0; z-index: 90; } + .lv-menu { position: fixed; z-index: 91; width: 188px; padding: 6px; border-radius: 12px; border: 1px solid var(--border-2, rgba(255,255,255,0.12)); background: var(--panel, #0e0e13); box-shadow: 0 18px 44px -18px rgba(0,0,0,0.7); animation: ds-rise 0.13s ease; } + .lv-menu-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 10px; border: 0; border-radius: 9px; background: none; color: var(--text-2, #eaeaea); font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; text-align: left; } + .lv-menu-item:hover { background: var(--panel-3, #1b1b22); color: var(--text, #fff); } + .lv-menu-item svg { color: var(--muted, #8c8c8c); flex: 0 0 auto; } + .lv-menu-item:hover svg { color: var(--orange, #fda913); } + + /* ---- verification detail popup ---- */ + .dash-root .lv-detail { display: flex; flex-direction: column; gap: 16px; } + .dash-root .lv-d-identity { display: flex; align-items: center; gap: 14px; } + .dash-root .lv-d-name { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; } + .dash-root .lv-d-pills { display: flex; align-items: center; gap: 8px; margin-top: 6px; } + .dash-root .lv-d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } + .dash-root .lv-d-section, .dash-root .lv-d-notes, .dash-root .lv-d-activity { border: 1px solid var(--border); border-radius: 14px; background: var(--panel-2); padding: 14px 15px; } + .dash-root .lv-d-head { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--orange); margin-bottom: 12px; } + .dash-root .lv-d-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); } + .dash-root .lv-d-row:last-child { border-bottom: 0; } + .dash-root .lv-d-k { font-size: 12px; color: var(--muted); flex: 0 0 auto; } + .dash-root .lv-d-v { font-size: 12.5px; color: var(--text); font-weight: 600; text-align: right; } + .dash-root .lv-d-notes p { font-size: 12.5px; color: var(--text-2); line-height: 1.55; margin-top: 2px; } + + .dash-root .lv-timeline { list-style: none; margin: 0; padding: 0; } + .dash-root .lv-tl-item { position: relative; display: flex; gap: 12px; padding: 0 0 16px 4px; } + .dash-root .lv-tl-item::before { content: ""; position: absolute; left: 8px; top: 14px; bottom: -2px; width: 1.5px; background: var(--border-2); } + .dash-root .lv-tl-item:last-child { padding-bottom: 0; } + .dash-root .lv-tl-item:last-child::before { display: none; } + .dash-root .lv-tl-dot { position: relative; z-index: 1; flex: 0 0 auto; width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 20%, transparent); } + .dash-root .lv-tl-text { font-size: 12.5px; color: var(--text); font-weight: 600; } + .dash-root .lv-tl-meta { font-size: 11px; color: var(--muted); margin-top: 2px; } + + @media (max-width: 900px) { + .dash-root .lv-d-grid { grid-template-columns: 1fr; } + } + + @media (max-width: 900px) { + .dash-root .leads-stats { grid-template-columns: repeat(2, 1fr); } + .dash-root .ld-grid { grid-template-columns: 1fr; } + .dash-root .ld-assign { grid-template-columns: 1fr; } + .dash-root .lv-stats { grid-template-columns: repeat(3, 1fr); } + .dash-root .lv-filter { flex: 1 1 45%; } + } + @media (max-width: 560px) { + .dash-root .leads-stats { grid-template-columns: 1fr; } + .dash-root .leads-grid { grid-template-columns: 1fr; } + .dash-root .nl-grid { grid-template-columns: 1fr; } + .dash-root .lv-stats { grid-template-columns: repeat(2, 1fr); } + } + +/* ========================================================================= + Smart Gallery — the embedded @photo-gallery/sdk surface. + The SDK is themed entirely through the token map in lib/gallery-api.ts + (--apg-* -> this file's own vars), so the rules below only handle the + host chrome: sizing, the demo banner, and the load/error placeholders. + ========================================================================= */ + +/* The gallery is the one view that wants the whole viewport: it has its own sidebar, toolbar and + scrollers, so any height we leave on the table is wasted chrome. The old big PageHead cost ~90px; + a slim header (~40px) + compact banner + tight gaps hand almost all of that back to the shell. + 96px = the dashboard's top padding + the slim header row; `.gal-shell` (flex:1; min-height:0) + consumes whatever is left after the header and the optional demo banner. */ +.dash-root .gal { display: flex; flex-direction: column; gap: 10px; height: calc(100vh - 96px); min-height: 700px; } + +/* Slim inline header — replaces the tall PageHead. One row, ~40px, so the shell keeps the height. */ +.dash-root .gal-head { display: flex; align-items: center; gap: 10px; min-height: 36px; flex: 0 0 auto; } +.dash-root .gal-head-ic { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; color: #fff; background: var(--grad-brand); box-shadow: var(--glow-orange); flex: 0 0 auto; } +.dash-root .gal-head-title { font-size: 16px; font-weight: 700; line-height: 1.1; margin: 0; } +.dash-root .gal-head-sub { color: var(--muted); font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; } +@media (max-width: 720px) { .dash-root .gal-head-sub { display: none; } } + +/* `.view` sets `z-index: 1`, which makes it a stacking context and traps the SDK's + full-screen overlays (lightbox z1000, editors z1050, camera z1080, modals z1100) + underneath the topbar's `z-index: 20`. Opting this one view out of the stacking + context lets those overlays cover the whole dashboard, as they must. The view still + paints above the ambient `.dash-content::before` glow because it follows it in the DOM. */ +.dash-root .view.gal { z-index: auto; } + +/* Compact single-line demo banner (~34px). Truncates rather than wrapping so it never steals a + second row of height from the shell. */ +.dash-root .gal-banner { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 6px 12px; border-radius: 11px; border: 1px solid var(--border); background: color-mix(in srgb, var(--orange) 9%, var(--panel-2)); color: var(--text-2); font-size: 12px; font-weight: 500; flex: 0 0 auto; white-space: nowrap; overflow: hidden; } +.dash-root .gal-banner span { overflow: hidden; text-overflow: ellipsis; } +.dash-root .gal-banner svg { color: var(--orange); flex: 0 0 auto; } + +/* The gallery's own viewport. `overflow: hidden` keeps the SDK's internal scrollers + in charge; its full-screen overlays (lightbox/editor/camera) are position:fixed + and deliberately escape this box to cover the whole dashboard. */ +.dash-root .gal-shell { flex: 1; min-height: 0; position: relative; border-radius: 18px; border: 1px solid var(--border); background: var(--panel-2); overflow: hidden; box-shadow: var(--card-hi), 0 1px 2px rgba(0, 0, 0, 0.18); } +.dash-root[data-theme="dark"] .gal-shell { border: 0.5px solid #452b1a; border-radius: 20px; } + +/* The SDK's embedded root fills this box. (--apg-overlay-top is set from the + component's `style` prop — the SDK writes an inline default that a stylesheet + rule could not override.) */ +.dash-root .gal-shell .apg { height: 100%; } + +/* ---- Fullscreen (the SDK puts `.apg--fullscreen` on its root: position:fixed; inset:0) ---- + A position:fixed box is only clipped by an ancestor that is its CONTAINING BLOCK, which + `overflow`/`border-radius`/`box-shadow` alone never create — only transform / filter / + perspective / backdrop-filter / will-change / contain do. Nothing on the path + (.dash-content > .view.gal > .gal-shell) uses any of those: `.view`'s `ds-fade` animates + opacity only, and `.view.gal` already drops the `z-index: 1` stacking context. So the + fullscreen root does escape today — these rules make that survive an edit above. */ + +/* `.dash-root .gal-shell .apg` (0,3,0) would otherwise out-specify the SDK's own sizing; with + inset:0 driving the box, height must get out of the way. */ +.dash-root .gal-shell .apg.apg--fullscreen { + height: auto; + /* Above the topbar (z-index: 20) and the sidebar, below the SDK's own overlays (1000+). */ + z-index: 900; +} + +/* Belt and braces: if a future rule ever DOES make `.gal-shell` a containing block, an + `overflow: hidden` on it would crop the fullscreen root to the embedded box. Drop the clip + (and the rounded corner it exists to enforce) for exactly as long as fullscreen is on. */ +.dash-root .gal-shell:has(.apg--fullscreen) { overflow: visible; } + +.dash-root .gal-placeholder { height: 100%; min-height: 320px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 28px; } +.dash-root .gal-placeholder-ic { width: 66px; height: 66px; border-radius: 20px; display: grid; place-items: center; color: #fff; background: var(--grad-brand); box-shadow: var(--glow-orange); } +.dash-root .gal-placeholder p { color: var(--muted); font-size: 13px; max-width: 420px; } +.dash-root .gal-placeholder h3 { font-size: 16px; font-weight: 700; } +.dash-root .gal-placeholder-error .gal-placeholder-ic { background: color-mix(in srgb, var(--red) 88%, #000); box-shadow: 0 10px 28px -12px color-mix(in srgb, var(--red) 60%, transparent); } + +@media (max-width: 920px) { + /* Narrower chrome: a little less top offset, and a smaller floor so short viewports still work. */ + .dash-root .gal { height: calc(100vh - 84px); min-height: 560px; } +} + /* ---- Org Settings → Integrations ---- */ .dash-root .settings-section { margin-top: 8px; } .dash-root .settings-section-title { font-size: 13px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); margin: 0 0 14px; } @@ -1210,3 +1530,25 @@ .dash-root .settings-kv dd { margin: 0; font-size: 13px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; } .dash-root .settings-card-actions { display: flex; gap: 8px; align-items: center; margin-top: 2px; } .dash-root .settings-card-note { font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; } + .dash-root .settings-check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; } + + /* ---- Global conversation search (topbar) ---- */ + .dash-root .gs-wrap { position: relative; } + .dash-root .gs-field { display: flex; align-items: center; gap: 8px; height: 40px; width: 300px; max-width: 42vw; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); } + .dash-root .gs-field:focus-within { border-color: var(--orange); } + .dash-root .gs-input { flex: 1 1 auto; border: 0; background: none; outline: none; color: var(--text); font-size: 13.5px; } + .dash-root .gs-input::placeholder { color: var(--muted); } + .dash-root .gs-pop { position: absolute; top: calc(100% + 6px); right: 0; width: 420px; max-width: 90vw; max-height: 420px; overflow-y: auto; padding: 6px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel); box-shadow: 0 24px 60px -20px rgba(0,0,0,0.55); z-index: 60; } + .dash-root .gs-empty { padding: 14px; font-size: 13px; color: var(--muted); text-align: center; } + .dash-root .gs-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 11px; border: 0; background: none; border-radius: 10px; cursor: pointer; text-align: left; color: var(--text); } + .dash-root .gs-row:hover { background: var(--panel-2); } + .dash-root .gs-ic { flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: color-mix(in srgb, var(--orange) 14%, transparent); color: var(--orange); } + .dash-root .gs-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; } + .dash-root .gs-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + .dash-root .gs-snippet { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + .dash-root .gs-snippet em { color: var(--orange); font-style: normal; font-weight: 600; } + .dash-root .gs-surface { flex: 0 0 auto; font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); } + @media (max-width: 720px) { .dash-root .gs-field { width: 160px; } } + + .dash-root .ds-toast.is-clickable .ds-toast-body { cursor: pointer; } + .dash-root .ds-toast.is-clickable .ds-toast-body:hover .ds-toast-title { color: var(--orange); } diff --git a/src/components/dashboard/dashboard.tsx b/src/components/dashboard/dashboard.tsx index 8710104..75ba542 100644 --- a/src/components/dashboard/dashboard.tsx +++ b/src/components/dashboard/dashboard.tsx @@ -19,17 +19,48 @@ import { MessengerSdk } from "./messenger-sdk"; import { InboxSdk } from "./inbox-sdk"; import { Settings } from "./settings"; import { Projects } from "./projects"; +import { NotificationCenter } from "./notification-center"; +import { RealtimeProvider } from "@/lib/realtime"; +import { SmartGallery } from "./smart-gallery"; +import { Leads } from "./leads"; +import { Verify } from "./verify"; import "../../app/dashboard/dashboard.css"; export function Dashboard() { const [theme, setTheme] = useState<"dark" | "light">("dark"); const [active, setActive] = useState("dashboard"); + // Deep link from global search: which conversation to focus once we switch tabs. + const [deepLink, setDeepLink] = useState<{ surface: "messenger" | "inbox"; threadId: string } | null>(null); + + function navigateToConversation(surface: "messenger" | "inbox", threadId: string) { + setActive(surface); + setDeepLink({ surface, threadId }); + } useEffect(() => { // Sync the persisted theme from localStorage (an external system) on mount. // eslint-disable-next-line react-hooks/set-state-in-effect try { const t = localStorage.getItem("lup_dash_theme"); if (t === "light" || t === "dark") setTheme(t); } catch {} }, []); + + // Deep-link from a clicked push notification. Two paths from the service worker: + // - a tab was already open → it postMessages { type: 'notif-click', threadId } to focus here + // - no tab was open → it opens /dashboard?thread=, which we read once on mount + useEffect(() => { + try { + const t = new URLSearchParams(window.location.search).get("thread"); + if (t) { + navigateToConversation("messenger", t); + window.history.replaceState({}, "", window.location.pathname); + } + } catch {} + if (!("serviceWorker" in navigator)) return; + const onMessage = (e: MessageEvent) => { + if (e.data?.type === "notif-click" && e.data.threadId) navigateToConversation("messenger", e.data.threadId); + }; + navigator.serviceWorker.addEventListener("message", onMessage); + return () => navigator.serviceWorker.removeEventListener("message", onMessage); + }, []); function toggle() { setTheme((t) => { const n = t === "dark" ? "light" : "dark"; try { localStorage.setItem("lup_dash_theme", n); } catch {} return n; }); } @@ -40,24 +71,30 @@ export function Dashboard() { return (
+
- +
+ {active === "profile" ? : active === "support" ? : active === "rules" ? : active === "ai" ? - : active === "messenger" ? - : active === "inbox" ? + : active === "messenger" ? + : active === "inbox" ? : active === "settings" ? + : active === "gallery" ? + : active === "leads" ? + : active === "verify" ? : active === "team" ? : active === "projects" ? : }
+
); } diff --git a/src/components/dashboard/global-search.tsx b/src/components/dashboard/global-search.tsx new file mode 100644 index 0000000..71a7624 --- /dev/null +++ b/src/components/dashboard/global-search.tsx @@ -0,0 +1,86 @@ +"use client"; + +// Global conversation search in the topbar: type → debounced crm.search → dropdown of hits; click a +// hit to deep-link to exactly where it lives (mail → Inbox, chat → Messenger, on that thread). + +import { useEffect, useRef, useState } from "react"; +import { Icon } from "./ui"; +import { useGlobalSearch, type SearchResult } from "@/lib/search-api"; + +/** Escape HTML but keep the engine's highlight tags — so a match snippet can't inject markup. */ +function safeSnippet(s: string): string { + const esc = s.replace(/&/g, "&").replace(//g, ">"); + return esc.replace(/<em>/g, "").replace(/<\/em>/g, ""); +} + +export function GlobalSearch({ onNavigate }: { onNavigate: (surface: "messenger" | "inbox", threadId: string) => void }) { + const search = useGlobalSearch(); + const [open, setOpen] = useState(false); + const [q, setQ] = useState(""); + const [results, setResults] = useState([]); + const [loading, setLoading] = useState(false); + const wrapRef = useRef(null); + + useEffect(() => { + const term = q.trim(); + if (!term) { + setResults([]); + return; + } + let alive = true; + setLoading(true); + const t = setTimeout(() => { + search(term) + .then((r) => { if (alive) setResults(r); }) + .catch(() => { if (alive) setResults([]); }) + .finally(() => { if (alive) setLoading(false); }); + }, 220); + return () => { alive = false; clearTimeout(t); }; + }, [q, search]); + + useEffect(() => { + function onDown(e: MouseEvent) { + if (!wrapRef.current?.contains(e.target as Node)) setOpen(false); + } + document.addEventListener("mousedown", onDown); + return () => document.removeEventListener("mousedown", onDown); + }, []); + + function pick(r: SearchResult) { + onNavigate(r.surface, r.threadId); + setOpen(false); + setQ(""); + } + + return ( +
+
+ + setOpen(true)} + onChange={(e) => { setQ(e.target.value); setOpen(true); }} + aria-label="Search conversations" + /> +
+ {open && q.trim() ? ( +
+ {loading && results.length === 0 ?
Searching…
: null} + {!loading && results.length === 0 ?
No matches.
: null} + {results.map((r) => ( + + ))} +
+ ) : null} +
+ ); +} diff --git a/src/components/dashboard/inbox-sdk.tsx b/src/components/dashboard/inbox-sdk.tsx index 1c0fbed..2a2f672 100644 --- a/src/components/dashboard/inbox-sdk.tsx +++ b/src/components/dashboard/inbox-sdk.tsx @@ -15,7 +15,7 @@ import type { DataDoor } from "@/lib/crm-messaging-adapter"; const SHELL = isShellConfigured(); -export function InboxSdk() { +export function InboxSdk({ focusThreadId }: { focusThreadId?: string | null } = {}) { return (
{!SHELL && ( @@ -23,26 +23,26 @@ export function InboxSdk() { Demo mode — running on the SDK's mock inbox adapter.
)} -
{SHELL ? : }
+
{SHELL ? : }
); } -function DemoInbox() { +function DemoInbox({ focusThreadId }: { focusThreadId?: string | null }) { const adapter = useMemo(() => new MockInboxAdapter(), []); return ( - + ); } -function LiveInbox() { +function LiveInbox({ focusThreadId }: { focusThreadId?: string | null }) { const { sdk } = useAppShell(); const adapter = useMemo(() => new CrmInboxAdapter(sdk as unknown as DataDoor), [sdk]); return ( - + ); } diff --git a/src/components/dashboard/leads-data.ts b/src/components/dashboard/leads-data.ts new file mode 100644 index 0000000..a4a5a82 --- /dev/null +++ b/src/components/dashboard/leads-data.ts @@ -0,0 +1,220 @@ +// ============================================================ +// LynkedUp Pro — Leads mock data. +// A storm-restoration roofing pipeline: door-knocked leads in +// the Plano, TX hail zone. Each lead carries a rich detail +// record (contact, property, job, insurance, assignment) that +// powers the lead-detail popup. All client-side so the screen +// is fully interactive without a backend. +// ============================================================ + +export type LeadStatus = "new" | "contacted" | "appointed" | "closed"; +export type LeadPriority = "high" | "medium" | "low"; + +export type Phone = { number: string; type: "Mobile" | "Home" | "Work"; primary?: boolean }; +export type Email = { address: string; type?: string; primary?: boolean }; + +export type Lead = { + id: string; // SAL-001 + initials: string; + name: string; + gradient: string; + priority: LeadPriority; + status: LeadStatus; + tag: string; // "Storm Zone" + updated: string; // "3d ago" + setter: string; // compact chip name + + // storm banner + storm: { zone: string; date: string; detail: string }; + + // contact + phones: Phone[]; + emails: Email[]; + + // property + property: { address: string; city: string; state: string; zip: string; type: string }; + + // job details + job: { + source: string; leadType: string; workType: string; tradeType: string; + urgency: string; canvasser: string; notes: string; + }; + + // insurance + insurance: { + company: string; claimStatus: string; claimNumber: string; + policyNumber: string; adjusterName: string; adjusterPhone: string; + }; + + // assignment + assignment: { + assignedTo: string; priority: string; followUp: string; + createdBy: string; createdAt: string; + }; +}; + +const G = { + orange: "linear-gradient(135deg,#fda913,#fd6d13)", + blue: "linear-gradient(135deg,#4f8cff,#2c5cff)", + purple: "linear-gradient(135deg,#b07bf2,#7b53e0)", + green: "linear-gradient(135deg,#33c98a,#1fa46c)", + cyan: "linear-gradient(135deg,#34c9d6,#1f9aa4)", +}; + +export const LEADS: Lead[] = [ + { + id: "SAL-001", initials: "JM", name: "John Martinez", gradient: G.orange, + priority: "high", status: "contacted", tag: "Storm Zone", updated: "3d ago", setter: "Cody", + storm: { zone: "E Plano / Spring Creek Pkwy", date: "2026-04-28", detail: '2.5" hail (severe)' }, + phones: [ + { number: "(469) 500-1000", type: "Mobile", primary: true }, + { number: "(214) 600-2000", type: "Home" }, + ], + emails: [{ address: "john.martinez@gmail.com", primary: true }], + property: { address: "4821 Spring Creek Pkwy", city: "Plano", state: "TX", zip: "75023", type: "Single Family" }, + job: { + source: "Door Knock", leadType: "Insurance", workType: "Roof Replacement", tradeType: "Roofing", + urgency: "High", canvasser: "Cody Tatum", + notes: "Homeowner showed significant granule loss on south-facing slopes; agreed to inspection.", + }, + insurance: { + company: "State Farm", claimStatus: "Filed", claimNumber: "CLM-2026-1000", + policyNumber: "POL-080000", adjusterName: "Marcus Powell", adjusterPhone: "(972) 700-3000", + }, + assignment: { + assignedTo: "Jesus Gonzales", priority: "High", followUp: "Jun 4, 2026", + createdBy: "Cody Tatum", createdAt: "May 28, 2026", + }, + }, + { + id: "SAL-002", initials: "SK", name: "Sarah Kim", gradient: G.purple, + priority: "high", status: "appointed", tag: "Storm Zone", updated: "2d ago", setter: "Shelby", + storm: { zone: "E Plano / Custer Rd", date: "2026-04-28", detail: '2.5" hail (severe)' }, + phones: [ + { number: "(972) 501-1037", type: "Mobile", primary: true }, + { number: "(214) 601-2044", type: "Home" }, + ], + emails: [{ address: "sarah.kim@outlook.com", primary: true }], + property: { address: "4905 Custer Rd", city: "Plano", state: "TX", zip: "75023", type: "Single Family" }, + job: { + source: "Door Knock", leadType: "Insurance", workType: "Roof Replacement", tradeType: "Roofing", + urgency: "High", canvasser: "Hannah Reyes", + notes: "Visible mat exposure on rear elevation. Appointment set for adjuster meet.", + }, + insurance: { + company: "Allstate", claimStatus: "Approved", claimNumber: "CLM-2026-1037", + policyNumber: "POL-081037", adjusterName: "Dana Whitfield", adjusterPhone: "(972) 700-3037", + }, + assignment: { + assignedTo: "Hannah Reyes", priority: "High", followUp: "Jun 6, 2026", + createdBy: "Shelby Greer", createdAt: "May 29, 2026", + }, + }, + { + id: "SAL-003", initials: "RC", name: "Robert Chen", gradient: G.green, + priority: "high", status: "closed", tag: "Storm Zone", updated: "2d ago", setter: "Dalton", + storm: { zone: "E Plano / Independence Pkwy", date: "2026-04-28", detail: '2.5" hail (severe)' }, + phones: [ + { number: "(469) 502-1074", type: "Mobile", primary: true }, + ], + emails: [{ address: "robert.chen@gmail.com", primary: true }], + property: { address: "5012 Independence Pkwy", city: "Plano", state: "TX", zip: "75023", type: "Single Family" }, + job: { + source: "Door Knock", leadType: "Insurance", workType: "Roof Replacement", tradeType: "Roofing", + urgency: "High", canvasser: "Travis Boone", + notes: "Full replacement approved and installed. Final invoice cleared.", + }, + insurance: { + company: "Farmers", claimStatus: "Paid", claimNumber: "CLM-2026-1074", + policyNumber: "POL-081074", adjusterName: "Leah Ortiz", adjusterPhone: "(972) 700-3074", + }, + assignment: { + assignedTo: "Travis Boone", priority: "High", followUp: "—", + createdBy: "Dalton Pruitt", createdAt: "May 20, 2026", + }, + }, + { + id: "SAL-004", initials: "MG", name: "Maria Garcia", gradient: G.cyan, + priority: "high", status: "closed", tag: "Storm Zone", updated: "2d ago", setter: "Hannah", + storm: { zone: "E Plano / Alma Dr", date: "2026-04-28", detail: '2.5" hail (severe)' }, + phones: [ + { number: "(972) 503-1111", type: "Mobile", primary: true }, + ], + emails: [{ address: "maria.garcia@gmail.com", primary: true }], + property: { address: "4720 Alma Dr", city: "Plano", state: "TX", zip: "75023", type: "Single Family" }, + job: { + source: "Door Knock", leadType: "Insurance", workType: "Roof Replacement", tradeType: "Roofing", + urgency: "High", canvasser: "Shelby Greer", + notes: "Signed contract; build complete. Awaiting review request.", + }, + insurance: { + company: "USAA", claimStatus: "Paid", claimNumber: "CLM-2026-1111", + policyNumber: "POL-081111", adjusterName: "Grant Mueller", adjusterPhone: "(972) 700-3111", + }, + assignment: { + assignedTo: "Shelby Greer", priority: "High", followUp: "—", + createdBy: "Hannah Reyes", createdAt: "May 18, 2026", + }, + }, + { + id: "SAL-005", initials: "DT", name: "David Thompson", gradient: G.blue, + priority: "high", status: "appointed", tag: "Storm Zone", updated: "1d ago", setter: "Travis", + storm: { zone: "E Plano / Spring Creek Pkwy", date: "2026-04-28", detail: '2.5" hail (severe)' }, + phones: [ + { number: "(469) 504-1148", type: "Mobile", primary: true }, + { number: "(214) 604-2148", type: "Work" }, + ], + emails: [{ address: "david.thompson@gmail.com", primary: true }], + property: { address: "5130 Spring Creek Pkwy", city: "Plano", state: "TX", zip: "75023", type: "Single Family" }, + job: { + source: "Door Knock", leadType: "Insurance", workType: "Roof Replacement", tradeType: "Roofing", + urgency: "High", canvasser: "Dalton Pruitt", + notes: "Adjuster appointment confirmed for next week. Bring hail map + photos.", + }, + insurance: { + company: "Liberty Mutual", claimStatus: "Filed", claimNumber: "CLM-2026-1148", + policyNumber: "POL-081148", adjusterName: "Priya Nair", adjusterPhone: "(972) 700-3148", + }, + assignment: { + assignedTo: "Dalton Pruitt", priority: "High", followUp: "Jun 9, 2026", + createdBy: "Travis Boone", createdAt: "May 30, 2026", + }, + }, +]; + +// Header stat — the full book is larger than the loaded page. +export const TOTAL_LEADS = 35; + +export const STATUS_META: Record = { + new: { label: "New", tone: "blue" }, + contacted: { label: "Contacted", tone: "orange" }, + appointed: { label: "Appointed", tone: "purple" }, + closed: { label: "Closed", tone: "green" }, +}; + +export const PRIORITY_META: Record = { + high: { label: "High", tone: "red" }, + medium: { label: "Medium", tone: "orange" }, + low: { label: "Low", tone: "muted" }, +}; + +/* ---------------------------------------------------------- */ +/* Reps + option lists — power the New Lead form */ +/* ---------------------------------------------------------- */ + +export type Rep = { id: string; initials: string; name: string; email: string }; + +export const REPS: Rep[] = [ + { id: "LUP-1040", initials: "CT", name: "Cody Tatum", email: "cody.tatum@lynkeduppro.com" }, + { id: "LUP-1041", initials: "HR", name: "Hannah Reyes", email: "hannah.reyes@lynkeduppro.com" }, + { id: "LUP-1042", initials: "TB", name: "Travis Boone", email: "travis.boone@lynkeduppro.com" }, + { id: "LUP-1043", initials: "SG", name: "Shelby Greer", email: "shelby.greer@lynkeduppro.com" }, + { id: "LUP-1044", initials: "DP", name: "Dalton Pruitt", email: "dalton.pruitt@lynkeduppro.com" }, +]; + +export const LEAD_SOURCES = ["Door Knock", "Referral", "Storm Chase", "Mailer / Postcard", "Sign Call", "Insurance Agent Referral", "Repeat Customer", "Social Media", "Other"]; +export const LEAD_TYPES = ["Insurance", "Retail"]; +export const WORK_TYPES = ["Roof Replacement", "Roof Repair", "Inspection", "Gutter Install"]; +export const TRADE_TYPES = ["Roofing", "Gutters", "Siding", "Windows"]; +export const PROPERTY_TYPES = ["Single Family", "Multi Family", "Commercial"]; +export const CLAIM_STATUSES = ["Not Filed", "Filed", "Approved", "Paid", "Denied"]; diff --git a/src/components/dashboard/leads.tsx b/src/components/dashboard/leads.tsx new file mode 100644 index 0000000..c55fd82 --- /dev/null +++ b/src/components/dashboard/leads.tsx @@ -0,0 +1,615 @@ +"use client"; + +// ============================================================ +// Leads — storm-restoration pipeline board. +// · Hero head : storm banner + headline stats (by status) +// · Toolbar : search + status filter tabs +// · Board : lead cards (avatar, priority ring, status, +// address, phone, source, rep, updated) +// · Detail : click a lead → rich popup with Contact, +// Property, Job Details, Insurance, Assignment +// Data comes from leads-data.ts (client-side mock). +// ============================================================ + +import { useMemo, useState, type ReactNode } from "react"; +import { Avatar, Btn, Field, Icon, Modal, PageHead, Pill, Segmented, SegTabs, useToast } from "./ui"; +import { + LEADS, TOTAL_LEADS, STATUS_META, PRIORITY_META, + REPS, LEAD_SOURCES, WORK_TYPES, TRADE_TYPES, CLAIM_STATUSES, + type Lead, type LeadStatus, +} from "./leads-data"; + +const STATUS_TABS: { value: "all" | LeadStatus; label: string }[] = [ + { value: "all", label: "All" }, + { value: "new", label: "New" }, + { value: "contacted", label: "Contacted" }, + { value: "appointed", label: "Appointed" }, + { value: "closed", label: "Closed" }, +]; + +export function Leads() { + const toast = useToast(); + const [query, setQuery] = useState(""); + const [filter, setFilter] = useState<"all" | LeadStatus>("all"); + const [selected, setSelected] = useState(null); + const [newOpen, setNewOpen] = useState(false); + + const countByStatus = useMemo(() => { + const m: Record = {}; + for (const l of LEADS) m[l.status] = (m[l.status] ?? 0) + 1; + return m; + }, []); + + const filtered = useMemo(() => { + const q = query.trim().toLowerCase(); + return LEADS.filter((l) => { + const matchStatus = filter === "all" || l.status === filter; + const hay = `${l.name} ${l.property.address} ${l.property.city} ${l.job.source} ${l.job.canvasser}`.toLowerCase(); + return matchStatus && (!q || hay.includes(q)); + }); + }, [query, filter]); + + return ( +
+ setNewOpen(true)}>New Lead} + /> + + {/* ---- stat strip ---------------------------------------- */} +
+ + + + + +
+ + {/* ---- toolbar ------------------------------------------- */} +
+
+ + setQuery(e.target.value)} + placeholder="Search by name, address, source…" + aria-label="Search leads" + /> + {query && } +
+
+ {STATUS_TABS.map((t) => ( + + ))} +
+
+ + {/* ---- board --------------------------------------------- */} + {filtered.length === 0 ? ( +
+ +

No leads match

+

Try a different search or clear the status filter.

+
+ ) : ( +
+ {filtered.map((l) => ( + setSelected(l)} /> + ))} +
+ )} + + setSelected(null)} /> + setNewOpen(false)} /> +
+ ); +} + +/* ---------------------------------------------------------- */ +/* Stat card */ +/* ---------------------------------------------------------- */ + +function StatCard({ label, value, icon, tone }: { label: string; value: number; icon: string; tone: string }) { + return ( +
+ +
+
{value}
+
{label}
+
+
+ ); +} + +/* ---------------------------------------------------------- */ +/* Lead card */ +/* ---------------------------------------------------------- */ + +function LeadCard({ lead, onOpen }: { lead: Lead; onOpen: () => void }) { + const status = STATUS_META[lead.status]; + const priority = PRIORITY_META[lead.priority]; + const primaryPhone = lead.phones.find((p) => p.primary) ?? lead.phones[0]; + + return ( + + ); +} + +/* ---------------------------------------------------------- */ +/* Lead detail popup */ +/* ---------------------------------------------------------- */ + +function LeadDetail({ lead, onClose }: { lead: Lead | null; onClose: () => void }) { + if (!lead) return null; + const status = STATUS_META[lead.status]; + const priority = PRIORITY_META[lead.priority]; + + return ( + + Call + Email + Update Status + + } + > +
+ {/* identity strip */} +
+ +
+
{lead.name}
+
+ {status.label} + {priority.label} +
+
+
+ + {/* storm banner */} +
+ +
+
{lead.storm.zone}
+
{lead.storm.date} · {lead.storm.detail}
+
+
+ +
+ {/* Contact */} +
+
Phone Numbers
+ {lead.phones.map((p, i) => ( +
+ + {p.number} + {p.type} + {p.primary && Primary} +
+ ))} +
Email Addresses
+ {lead.emails.map((e, i) => ( +
+ + {e.address} + {e.primary && Primary} +
+ ))} +
+ + {/* Property */} +
+
+
+
+
+
+
+ + {/* Job Details */} +
+
+
+
+
+
+
+
+
Field Notes
+

{lead.job.notes}

+
+
+ + {/* Insurance */} +
+
+
+
+
+
+
+
+ + {/* Assignment */} +
+
+
+
+
+
+
+
+
+
+
+
+ ); +} + +function Section({ title, icon, children, wide }: { title: string; icon: string; children: ReactNode; wide?: boolean }) { + return ( +
+
{title}
+
{children}
+
+ ); +} + +function Dl({ label, value }: { label: string; value: string }) { + return ( +
+ {label} + {value} +
+ ); +} + +/* ---------------------------------------------------------- */ +/* New Lead — Quick / Full Form intake */ +/* ---------------------------------------------------------- */ + +type Priority = "Low" | "Medium" | "High"; +type Urgency = "Standard" | "High" | "Emergency"; +type PhoneRow = { number: string; type: string }; +type EmailRow = { address: string }; + +const FULL_STEPS = [ + { value: "contact", label: "Contact", icon: "user" }, + { value: "property", label: "Property", icon: "owners" }, + { value: "job", label: "Job Details", icon: "projects" }, + { value: "insurance", label: "Insurance", icon: "shield" }, + { value: "assignment", label: "Assignment", icon: "team" }, +]; + +const LEAD_TYPE_OPTS = ["Residential", "Commercial", "Multi-Family"]; +const PROPERTY_TYPE_OPTS = ["Residential", "Commercial", "Multi-Family", "Industrial"]; + +const BLANK = { + firstName: "", lastName: "", + phones: [{ number: "", type: "Mobile" }] as PhoneRow[], + emails: [] as EmailRow[], + address: "", city: "", state: "TX", zip: "", propertyType: "", + photos: [] as string[], + source: "", referralNote: "", canvasser: "", leadType: "", workType: "", tradeType: "", urgency: "Standard" as Urgency, notes: "", + insCompany: "", claimNumber: "", claimStatus: "", adjusterName: "", adjusterPhone: "", policyNumber: "", + assignRep: "", priority: "Medium" as Priority, followUp: "", +}; + +function NewLead({ open, onClose }: { open: boolean; onClose: () => void }) { + const toast = useToast(); + const [mode, setMode] = useState<"quick" | "full">("quick"); + const [section, setSection] = useState("contact"); + const [f, setF] = useState({ ...BLANK }); + + const set = (k: string) => (e: { target: { value: string } }) => + setF((s) => ({ ...s, [k]: e.target.value }) as typeof BLANK); + + // multi-value handlers + const addPhone = () => setF((s) => ({ ...s, phones: [...s.phones, { number: "", type: "Mobile" }] })); + const setPhone = (i: number, key: "number" | "type", v: string) => setF((s) => ({ ...s, phones: s.phones.map((p, j) => (j === i ? { ...p, [key]: v } : p)) })); + const removePhone = (i: number) => setF((s) => ({ ...s, phones: s.phones.filter((_, j) => j !== i) })); + const addEmail = () => setF((s) => ({ ...s, emails: [...s.emails, { address: "" }] })); + const setEmail = (i: number, v: string) => setF((s) => ({ ...s, emails: s.emails.map((e, j) => (j === i ? { address: v } : e)) })); + const removeEmail = (i: number) => setF((s) => ({ ...s, emails: s.emails.filter((_, j) => j !== i) })); + const addPhoto = () => setF((s) => ({ ...s, photos: [...s.photos, `Photo ${s.photos.length + 1}`] })); + + function reset() { setF({ ...BLANK, phones: [{ number: "", type: "Mobile" }], emails: [], photos: [] }); setMode("quick"); setSection("contact"); } + function close() { reset(); onClose(); } + + function submit() { + const name = `${f.firstName} ${f.lastName}`.trim(); + if (!name) { toast.push({ tone: "error", title: "Name required", desc: "Enter the homeowner's first or last name." }); return; } + toast.push({ tone: "success", title: "Lead created", desc: `${name} added to the Plano pipeline.` }); + close(); + } + + const repOptions = [{ id: "", initials: "—", name: "Unassigned" }, ...REPS]; + + const stepIdx = FULL_STEPS.findIndex((s) => s.value === section); + const isFirstStep = stepIdx <= 0; + const isLastStep = stepIdx === FULL_STEPS.length - 1; + const goNext = () => { if (!isLastStep) setSection(FULL_STEPS[stepIdx + 1].value); }; + const goBack = () => { if (!isFirstStep) setSection(FULL_STEPS[stepIdx - 1].value); }; + + return ( + + Cancel + {!isFirstStep && Back} + {isLastStep + ? Create Lead + : Next} + + ) : ( + <> + Cancel + Create Lead + + ) + } + > +
+ setMode(v as "quick" | "full")} + options={[{ value: "quick", label: "Quick", icon: "star" }, { value: "full", label: "Full Form", icon: "edit" }]} + /> + + {mode === "quick" ? ( +
+ + + setPhone(0, "number", e.target.value)} placeholder="(555) 000-0000" /> +
+ + + +