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/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/docs/superpowers/specs/2026-07-17-messaging-sdk-design.md b/docs/superpowers/specs/2026-07-17-messaging-sdk-design.md new file mode 100644 index 0000000..335b891 --- /dev/null +++ b/docs/superpowers/specs/2026-07-17-messaging-sdk-design.md @@ -0,0 +1,240 @@ +# Messaging UI SDK — Design + +**Date:** 2026-07-17 +**Status:** Approved, pending implementation plan + +## Problem + +Messaging UI is rewritten from scratch in every app that needs it. `lynkeduppro-crm` +has a rich, working messenger — conversation list, thread view, bubbles, reactions, +reply threading, typing, read receipts — built as 352 lines in +`src/components/dashboard/messenger.tsx` over 371 lines in `src/lib/messenger-api.ts`. +None of it is reusable. + +### Why not just use `@insignia/iios-message-web`? + +Because it does not solve this problem, and the CRM already rejected it. + +`iios-message-web` is 109 lines across 2 files. It is fully headless: its only JSX is +the context provider element itself. It exports `MessageProvider`, `useThread`, +`useMessages` and a `Message` type — nothing more. It ships no components, no CSS, no +theming. + +It also guessed its API wrong. `useMessages.send` narrows the options bag to +`{ contentRef? }`, while the underlying `MessageSocket.sendMessage` accepts +`parentInteractionId`, `mentions`, and `attachment`. Threading, mentions and +attachments are unreachable through its public API. The socket is held in a +module-private context with no escape hatch. It has zero consumers outside the iios +repo, and its own docs reference a `useSendMessage` hook that does not exist. + +The CRM consequently bypassed it and depends on `@insignia/iios-kernel-client` +directly. + +**The lesson drives this design:** the headless layer is already an SDK +(`iios-kernel-client` — sockets, threads, receipts, typing, published, consumed). A +second headless package saves no app any work. The unsolved part is the UI. + +### Why tower is not a consumer + +Tower's messaging is a WhatsApp group ingest → moderate → forward pipeline, not chat. +There is no `Conversation` model; `Message` is a captured group post keyed by +`senderJid` + `sourceGroupId` with a moderation `status` enum +(`RAW/PENDING/APPROVED/...`) — no recipient, no delivery state. "Send" is a BullMQ job +rate-limited to 20 forwards/minute to avoid WhatsApp bans. There is no +socket.io/websocket/SSE in the browser anywhere in the repo. Its `threads` and +`drafts` mean different things than a chat SDK's would. + +Tower would pay the abstraction cost for realtime machinery it never turns on. It is +explicitly out of scope. + +## Constraint: one real consumer + +`lynkeduppro-crm` is the only consumer. Genericity is not achievable by intent — it is +forced by a second consumer. This design therefore ports only what is already proven +in production and refuses to invent abstraction for imagined needs. `iios-message-web` +is the cautionary example of the opposite approach. + +## Architecture + +One package, `@insignia/messaging-ui`, published to the existing Gitea registry +(`https://git.lynkedup.cloud/api/packages/insignia/npm/`). React as a peer dependency. + +``` +@insignia/messaging-ui + . → components + provider + hooks + ./styles.css → structural CSS + token defaults + ./adapters/kernel → optional iios-kernel-client adapter + ./adapters/mock → in-memory adapter for demos/tests +``` + +**The core has zero transport knowledge.** `iios-kernel-client` is reachable only via +the optional `./adapters/kernel` subpath, so an app on a different backend never pulls +socket code. This is the specific mistake `iios-message-web` made by welding itself to +`MessageSocket`. + +This boundary is load-bearing for the actual consumer: the CRM does **not** talk to +iios directly. It routes messaging through be-crm's data door (`crm.messenger.*`) via +`@abe-kap/appshell-sdk`, socket-primary with a 4s REST poll fallback. An SDK that +hardcoded `iios-kernel-client` could not be adopted by the only app that wants it. + +## The adapter contract + +Lifted from the existing `MessengerData`/`ThreadData` interfaces in +`src/lib/messenger-api.ts`, which already survived two implementations (live + mock). +Two implementations is the minimum real evidence that a seam is genuine rather than +imagined. This contract was not designed for an SDK — it earned its shape. + +```ts +interface MessagingAdapter { + listConversations(): Promise; + openThread(p: { participantIds: string[]; subject?: string }): Promise<{ threadId: string }>; + history(threadId: string): Promise; + send(threadId: string, content: string, opts?: SendOpts): Promise; + subscribe(threadId: string, cb: (e: MessageEvent) => void): Unsubscribe; + sendTyping(threadId: string): void; + markRead(threadId: string, messageId: string): Promise; + react?(messageId: string, emoji: string): Promise; + upload?(file: File): Promise<{ url: string; mime: string; name: string }>; + currentActorId(): string | null; +} + +interface SendOpts { + parentInteractionId?: string; + attachment?: { url: string; mime: string; name: string }; +} +``` + +### Graceful degradation + +`react` and `upload` are optional. When an adapter omits them the UI hides the +reaction picker or the attach button respectively. This is how one component set +serves both a full CRM messenger and a stripped-down widget without a `mode` prop. + +### `currentActorId` fixes a live bug + +Today the CRM infers the current actor id by scanning for a message you sent: + +```ts +// src/lib/messenger-socket.tsx — current behaviour +const mine = socketMsgs.find((m) => m.mine && m.actorId); +if (mine?.actorId && mine.actorId !== myActorId) setMyActorId(mine.actorId); +``` + +Until you have sent a message in a thread, `myActorId` is `null`. Because the REST +poll fallback computes `mine: !!myActorId && m.actorId === myActorId`, **every message +renders as not-yours** in that state. The root cause is that the kernel's receipt +event carries no `threadId`, making it a global stream the CRM compensates for. + +Making identity an explicit adapter responsibility eliminates this class of bug rather +than porting it. The two-tier socket/poll fallback stays in the adapter, not the SDK — +the CRM's adapter keeps its 4s poll; a socket-only app implements `subscribe` and +never polls. + +## Components + +Composable primitives plus one all-in-one for drop-in use: + +```tsx + + {/* all-in-one: list + thread */} + + {/* ...or compose: */} + + + + +``` + +Hooks remain exported (`useConversations`, `useThread`, `useMessages`) so a host +wanting entirely custom UI can use the SDK headlessly. This makes `iios-message-web`'s +use case a strict subset of this package rather than a competitor. + +### Explicitly out of scope + +- **Inbox.** Coupled to iios semantics, not chat transport. Items are projected + server-side by iios from domain events (`MENTION`, `NEEDS_REPLY`, `SUPPORT_UPDATE`, + `CRM_OWNER_INTEREST`); authz is OPA policy. A chat SDK cannot own this. +- **People picker / directory.** Fed by `crm.messenger.directory`. "Who exists and who + may I message" is host and tenant territory. `` takes an `onNewChat` + callback; the host renders its own picker. +- **Presence.** No consumer needs it. + +## Theming + +Structural CSS with token defaults, overridden by the host. No Tailwind, no CSS-in-JS, +no build coupling — the CRM has no shadcn and near-zero Tailwind (its real styling is +1142 lines of hand-rolled `dashboard.css` plus inline style objects), so a +Tailwind-based SDK would force a restyle of the only consumer. + +```css +:root { + --msg-font; --msg-radius; --msg-gap; + --msg-bubble-own-bg; --msg-bubble-other-bg; + --msg-accent; --msg-muted; --msg-surface; --msg-border; +} +``` + +Every component accepts `className`; `` accepts a `classNames` slot map for +per-part overrides. The CRM's existing `#6366f1 → #8b5cf6` group-avatar gradient +becomes a token value rather than a hardcode. + +## Attachments + +The SDK renders attachments (image thumbnail, file chip, download) and calls +`adapter.upload(file)`, passing the result into `send`. **Storage, auth, and +size/mime limits are host concerns** — baking in an upload target would break the next +app. The attach button is hidden when `upload` is absent. + +`MessageSocket.sendMessage` already accepts an `attachment` field, so this exercises +an existing wire contract rather than inventing one. No consumer has exercised it yet; +the CRM has no file upload anywhere today. + +## Data flow + +1. Host constructs an adapter (CRM: wrapping appshell data door + socket). +2. `MessagingProvider` holds the adapter in context. +3. `useConversations` calls `listConversations`; `useMessages(threadId)` calls + `history` then `subscribe`. +4. `Composer` calls `send` with optimistic append; on rejection the optimistic message + is rolled back and the input text restored (matching current CRM behaviour). +5. `subscribe` events reconcile against optimistic state by message id. + +## Error handling + +- Adapter method rejection surfaces via hook `error` state; components render an + inline error affordance, never throw. +- Optimistic send failure restores composer text — the CRM's current behaviour, kept. +- `subscribe` disconnect is the adapter's problem, not the SDK's. The SDK renders a + `connected: boolean` from the adapter as a banner (the CRM's existing "Demo mode" + banner generalises to this). + +## Validation + +The migration is the validation. There is no second app, so the honest bar is: + +1. Rewrite the CRM's `messenger.tsx` to consume the SDK; its data-door implementation + becomes `CrmMessagingAdapter`. **Success = identical behaviour with the 352-line + component deleted**, and the mock adapter preserving demo-mode fallback. +2. Then `support.tsx`'s `MessageCenter` — currently pure `setTimeout` theatre with no + backend — becomes a zero-risk second surface. + +Two surfaces in one app is not a true second consumer. It is the best honest test +available of the adapter boundary, and it should be understood as such. **The design +should be revisited when a genuine second app appears** rather than treated as settled. + +## Testing + +- **Component tests against the mock adapter** — no network. This is the payoff of the + injected seam. +- **`CrmMessagingAdapter` tested against the contract** independently of UI. +- **A shared adapter conformance suite** any adapter can run, so the kernel and CRM + adapters are verified against one definition of correct. +- Explicit regression test for the `currentActorId` bug: messages render as own before + the user has sent anything in the thread. + +## Open questions + +- Package name: `@insignia/messaging-ui` assumed, not confirmed. +- Whether `CrmMessagingAdapter` lives in the CRM repo or ships as + `./adapters/crm`. Preference: the CRM repo — it depends on appshell-sdk, which the + SDK must not. diff --git a/next.config.ts b/next.config.ts index aa1c5aa..f5d7ece 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,8 +1,9 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - // The SDK ships ESM/TS; let Next transpile it. - transpilePackages: ["@abe-kap/appshell-sdk"], + // 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 3a0245f..f0cfac7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,16 +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.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", @@ -480,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", @@ -551,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" } @@ -1012,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", @@ -1026,6 +1086,21 @@ "socket.io-client": "^4.8.1" } }, + "node_modules/@insignia/iios-messaging-ui": { + "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", + "react-dom": ">=18" + }, + "peerDependenciesMeta": { + "@insignia/iios-kernel-client": { + "optional": true + } + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", @@ -1287,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", @@ -1664,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", @@ -1682,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", @@ -1696,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", @@ -1726,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", @@ -2345,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", @@ -2381,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", @@ -2398,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" @@ -2614,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", @@ -2669,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", @@ -2708,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", @@ -2857,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", @@ -2876,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", @@ -2889,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" @@ -2902,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", @@ -2968,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", @@ -3096,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", @@ -3114,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", @@ -3128,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", @@ -3151,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", @@ -3411,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", @@ -3457,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" @@ -3477,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" @@ -3901,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", @@ -4113,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", @@ -4136,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", @@ -4145,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", @@ -4217,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", @@ -4298,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", @@ -4315,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", @@ -4347,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", @@ -4364,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" @@ -4374,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" @@ -4415,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" @@ -4506,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", @@ -4564,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", @@ -4644,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", @@ -4747,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", @@ -4773,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", @@ -4958,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", @@ -5119,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", @@ -5178,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", @@ -5469,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", @@ -5476,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", @@ -5518,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", @@ -5634,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", @@ -5681,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", @@ -5790,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", @@ -5825,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" @@ -5933,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", @@ -6075,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", @@ -6136,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", @@ -6271,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", @@ -6292,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", @@ -6347,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", @@ -6458,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", @@ -6468,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", @@ -6507,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", @@ -6583,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", @@ -6627,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" }, @@ -6767,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", @@ -6797,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", @@ -6911,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", @@ -6961,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" @@ -7014,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", @@ -7084,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", @@ -7142,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", @@ -7294,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": { @@ -7385,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", @@ -7403,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", @@ -7518,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", @@ -7547,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", @@ -7554,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", @@ -7567,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", @@ -7589,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 726f655..83f029c 100644 --- a/package.json +++ b/package.json @@ -6,20 +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.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 82eee53..434eef4 100644 --- a/src/app/dashboard/dashboard.css +++ b/src/app/dashboard/dashboard.css @@ -133,6 +133,21 @@ .dash-content { padding: 22px 28px 40px; width: 100%; } .sec-title { font-size: 15px; font-weight: 700; margin: 6px 0 14px; } + + /* Host for @insignia/iios-messaging-ui: a fixed-height card that maps the SDK's --miu-* tokens + onto the CRM design system, so the drop-in SDK matches the rest of the app. */ + .dash-root .miu-host { height: 620px; border: 1px solid var(--border); border-radius: 16px; overflow: hidden; } + .dash-root .miu-host .miu-messenger, + .dash-root .miu-host .miu-inbox { + --miu-bg: var(--bg); + --miu-panel: var(--panel); + --miu-panel-2: var(--panel-2); + --miu-border: var(--border); + --miu-text: var(--text); + --miu-muted: var(--muted); + --miu-accent: var(--orange); + --miu-accent-text: #1a1206; + } /* ---- grid helpers ---- */ .grid { display: grid; gap: 16px; } @@ -1383,4 +1398,123 @@ .dash-root .nl-grid { grid-template-columns: 1fr; } .dash-root .lv-stats { grid-template-columns: repeat(2, 1fr); } } - \ No newline at end of file + +/* ========================================================================= + 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; } + .dash-root .settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; } + .dash-root .settings-card { border: 1px solid var(--border); background: var(--panel); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 16px; } + .dash-root .settings-card.is-soon { opacity: 0.6; } + .dash-root .settings-card-head { display: flex; align-items: flex-start; gap: 12px; } + .dash-root .settings-card-ic { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; background: color-mix(in srgb, var(--orange) 14%, transparent); color: var(--orange); } + .dash-root .settings-card-titles { flex: 1 1 auto; min-width: 0; } + .dash-root .settings-card-name { font-size: 15px; font-weight: 700; color: var(--text); } + .dash-root .settings-card-sub { font-weight: 500; color: var(--muted); } + .dash-root .settings-card-desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; } + .dash-root .settings-card-body { display: flex; flex-direction: column; gap: 12px; } + .dash-root .settings-kv { display: grid; gap: 10px; margin: 0; } + .dash-root .settings-kv > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; } + .dash-root .settings-kv > div:last-child { border-bottom: 0; padding-bottom: 0; } + .dash-root .settings-kv dt { font-size: 12.5px; color: var(--muted); } + .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 b2a0b7c..e821bbe 100644 --- a/src/components/dashboard/dashboard.tsx +++ b/src/components/dashboard/dashboard.tsx @@ -15,8 +15,12 @@ import { Support } from "./support"; import { Rules } from "./rules"; import { AiAssistant } from "./ai-assistant"; import { TeamManagement } from "./team-management"; -import { Messenger } from "./messenger"; -import { Inbox } from "./inbox"; +import { MessengerSdk } from "./messenger-sdk"; +import { InboxSdk } from "./inbox-sdk"; +import { Settings } from "./settings"; +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"; @@ -24,12 +28,38 @@ 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,17 +70,21 @@ 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" ? @@ -58,6 +92,7 @@ export function Dashboard() {
+
); } 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 new file mode 100644 index 0000000..2a2f672 --- /dev/null +++ b/src/components/dashboard/inbox-sdk.tsx @@ -0,0 +1,48 @@ +"use client"; + +// The CRM Inbox, rendered by @insignia/iios-messaging-ui instead of the bespoke in-CRM inbox. +// Live = the be-crm data door (CrmInboxAdapter over crm.inbox.* + crm.mail.*); demo = the SDK's +// MockInboxAdapter. + +import { useMemo } from "react"; +import { useAppShell } from "@abe-kap/appshell-sdk/react"; +import { InboxProvider, Inbox as SdkInbox, type InboxAdapter } from "@insignia/iios-messaging-ui"; +import { MockInboxAdapter } from "@insignia/iios-messaging-ui/adapters/mock-inbox"; +import "@insignia/iios-messaging-ui/styles.css"; +import { isShellConfigured } from "@/lib/appshell"; +import { CrmInboxAdapter } from "@/lib/crm-inbox-adapter"; +import type { DataDoor } from "@/lib/crm-messaging-adapter"; + +const SHELL = isShellConfigured(); + +export function InboxSdk({ focusThreadId }: { focusThreadId?: string | null } = {}) { + return ( +
+ {!SHELL && ( +
+ Demo mode — running on the SDK's mock inbox adapter. +
+ )} +
{SHELL ? : }
+
+ ); +} + +function DemoInbox({ focusThreadId }: { focusThreadId?: string | null }) { + const adapter = useMemo(() => new MockInboxAdapter(), []); + return ( + + + + ); +} + +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/inbox.tsx b/src/components/dashboard/inbox.tsx deleted file mode 100644 index c79ac1c..0000000 --- a/src/components/dashboard/inbox.tsx +++ /dev/null @@ -1,152 +0,0 @@ -"use client"; - -// ============================================================ -// Inbox — the ONE unified communication surface. It lists everything -// IIOS surfaces for you (mentions, needs-reply, system alerts, support -// updates, …) AND the mail behind them: click an item tied to a thread -// and its conversation opens on the right to read + reply. Compose new -// mail from here too. Items come from crm.inbox.*; threads from crm.mail.*. -// ============================================================ - -import { useEffect, useState } from "react"; -import { Btn, Icon, PageHead, Pill, useToast } from "./ui"; -import { useInboxData, type InboxState, type UiInboxItem } from "@/lib/inbox-api"; -import { MailReader, NewMailModal } from "./mail"; - -const KIND_LABEL: Record = { - MAIL: "Mail", - MENTION: "Mention", NEEDS_REPLY: "Needs reply", NEEDS_REVIEW: "Needs review", NEEDS_APPROVAL: "Needs approval", - SUPPORT_UPDATE: "Support", MEETING_FOLLOWUP: "Meeting", DIGEST: "Digest", SYSTEM_ALERT: "Alert", CRM_OWNER_INTEREST: "Owner", -}; -const FILTERS: { value: InboxState; label: string }[] = [ - { value: "OPEN", label: "Open" }, { value: "SNOOZED", label: "Snoozed" }, { value: "DONE", label: "Done" }, { value: "ARCHIVED", label: "Archived" }, -]; - -export function Inbox() { - const [filter, setFilter] = useState("OPEN"); - const inbox = useInboxData(filter); - const toast = useToast(); - const [selectedId, setSelectedId] = useState(null); - const [newOpen, setNewOpen] = useState(false); - - useEffect(() => { - if ((!selectedId || !inbox.items.some((i) => i.id === selectedId)) && inbox.items[0]) setSelectedId(inbox.items[0].id); - }, [inbox.items, selectedId]); - - const selected = inbox.items.find((i) => i.id === selectedId) ?? null; - - return ( -
- setNewOpen(true)}>New mail} - /> - {!inbox.live && ( -
- Demo mode — running on mock data. It goes live once the Shell + be-crm are connected. -
- )} - -
- {FILTERS.map((f) => ( - setFilter(f.value)}>{f.label} - ))} -
- -
- {/* Left — the unified item list */} - - - {/* Right — read the mail behind the item, or the item detail */} -
- {selected ? ( - toast.push({ tone: "error", title: "Failed", desc: m })} - onDone={() => inbox.transition(selected.id, "DONE")} - onSnooze={() => inbox.transition(selected.id, "SNOOZED")} - onArchive={() => inbox.transition(selected.id, "ARCHIVED")} - /> - ) : ( -
-

Select an item to read

-
- )} -
-
- - setNewOpen(false)} - onSent={() => { setNewOpen(false); inbox.refetch(); toast.push({ tone: "success", title: "Sent" }); }} - onError={(m) => toast.push({ tone: "error", title: "Couldn't send", desc: m })} - /> -
- ); -} - -function ItemRow({ it, active, onClick }: { it: UiInboxItem; active: boolean; onClick: () => void }) { - const isMention = it.kind === "MENTION"; - return ( - - ); -} - -function Detail({ it, onError, onDone, onSnooze, onArchive }: { - it: UiInboxItem; onError: (m: string) => void; onDone: () => void; onSnooze: () => void; onArchive: () => void; -}) { - return ( - <> - {/* Item actions bar — only for real inbox work-items. Mail isn't an inbox item - (no crm.inbox.transition), so it gets read/reply only, no Done/Snooze/Archive. */} - {it.state === "OPEN" && it.kind !== "MAIL" && ( -
- Snooze - Done - Archive -
- )} - - {it.threadId ? ( - // A message/mail item → open the conversation to read + reply. - // key by threadId: the SDK's useQuery only refetches when the ACTION changes, not the - // variables — so switching items must remount MailReader to load the new thread's history. -
- -
- ) : ( - // A non-threaded item (e.g. a system alert) → show its detail. -
-
{it.title}
- {it.summary &&
{it.summary}
} -
- )} - - ); -} diff --git a/src/components/dashboard/mail.tsx b/src/components/dashboard/mail.tsx deleted file mode 100644 index 9ee09da..0000000 --- a/src/components/dashboard/mail.tsx +++ /dev/null @@ -1,231 +0,0 @@ -"use client"; - -// ============================================================ -// Mail components used INSIDE the Inbox (not a separate tab). -// The Inbox is the one unified surface — mentions, system messages -// and mail all live there. These render the mail body + reply, and -// compose a new message. HTML bodies render in a sandboxed iframe. -// ============================================================ - -import { type CSSProperties, useEffect, useRef, useState } from "react"; -import { Avatar, Btn, Field, Icon, Modal, Pill } from "./ui"; -import { useMailThread, useMailCompose, type MailAttachment, type MailPerson } from "@/lib/mail-api"; -import { useUploadAttachment, useDownloadUrl, isImage, type UploadedAttachment } from "@/lib/media-api"; - -const timeOf = (iso?: string) => { - if (!iso) return ""; - const d = new Date(iso); - return Number.isNaN(+d) ? "" : d.toLocaleString([], { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }); -}; -const CUSTOMER_GRAD = "linear-gradient(135deg,#10b981,#059669)"; -const inputStyle: CSSProperties = { - width: "100%", padding: "9px 12px", borderRadius: 10, border: "1px solid var(--border)", - background: "var(--panel)", color: "var(--text)", fontSize: 14, outline: "none", -}; - -function fmtBytes(n: number): string { - if (!n) return ""; - if (n < 1024) return `${n} B`; - if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)} KB`; - return `${(n / (1024 * 1024)).toFixed(1)} MB`; -} - -/** Resolves a signed URL for a stored attachment and renders it inline (image) or as a file chip. */ -function MailAttachmentView({ att }: { att: MailAttachment }) { - const getUrl = useDownloadUrl(); - const [url, setUrl] = useState(null); - useEffect(() => { - let alive = true; - getUrl(att.contentRef, att.mimeType).then((u) => { if (alive) setUrl(u); }).catch(() => {}); - return () => { alive = false; }; - }, [att.contentRef, att.mimeType, getUrl]); - - const label = att.filename || "Attachment"; - if (isImage(att.mimeType)) { - return url - ? {label} - :
Loading image…
; - } - return ( - - - {label} - {att.sizeBytes > 0 && {fmtBytes(att.sizeBytes)}} - - ); -} - -/** A small staged-file chip shown in a composer before send, with a remove button. */ -function StagedChip({ file, onRemove }: { file: UploadedAttachment; onRemove: () => void }) { - return ( -
- - {file.filename} - {fmtBytes(file.sizeBytes)} - -
- ); -} - -/** Reader + reply for one mail thread. Used in the Inbox detail pane when an item has a threadId. */ -export function MailReader({ threadId, subject, onError }: { threadId: string; subject: string; onError: (m: string) => void }) { - const t = useMailThread(threadId); - const upload = useUploadAttachment(); - const [draft, setDraft] = useState(""); - const [sending, setSending] = useState(false); - const [staged, setStaged] = useState(null); - const [uploading, setUploading] = useState(false); - const fileRef = useRef(null); - - async function onPickFile(e: React.ChangeEvent) { - const file = e.target.files?.[0]; - e.target.value = ""; - if (!file) return; - setUploading(true); - try { setStaged(await upload(file)); } - catch (err) { onError((err as Error).message); } - finally { setUploading(false); } - } - - async function reply() { - const text = draft.trim(); - if ((!text && !staged) || sending) return; - const att = staged ?? undefined; - setDraft(""); setStaged(null); setSending(true); - try { await t.reply(text, att); } - catch (e) { setDraft(text); setStaged(att ?? null); onError((e as Error).message); } - finally { setSending(false); } - } - - return ( -
-
-
{subject || "(no subject)"}
-
-
- {t.loading && t.messages.length === 0 &&
Loading…
} - {!t.loading && t.messages.length === 0 &&
No messages.
} - {t.messages.map((m) => ( -
-
- {m.kind === "EMAIL" ? "Email" : "Reply"}{m.actorId ? ` · ${m.actorId.replace(/^(pp_|cust_)/, "").slice(0, 8)}` : ""} - {timeOf(m.occurredAt)} -
- {m.html - ?