DefectRAG phase 5: incremental real-model application migration
Browse files- backend/gallery.py +218 -0
- backend/main.py +13 -1
- deployment/space/app.py +9 -1
- frontend/dist/assets/TeamWorkspace-BTKzGjaI.js +41 -0
- frontend/dist/assets/TeamWorkspace-D9wVcLaF.js +41 -0
- frontend/dist/assets/TeamWorkspace-DBuMBxqK.js +41 -0
- frontend/dist/assets/index-BhrFTP_4.js +0 -0
- frontend/dist/assets/index-CXC_txue.js +0 -0
- frontend/dist/assets/index-DyHDnvjh.js +0 -0
- frontend/dist/index.html +1 -1
backend/gallery.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Explicit-consent public snapshots. Never expose private inspection identifiers."""
|
| 2 |
+
import base64
|
| 3 |
+
import hashlib
|
| 4 |
+
import hmac
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
import json
|
| 7 |
+
import math
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import re
|
| 11 |
+
import sqlite3
|
| 12 |
+
import threading
|
| 13 |
+
import uuid
|
| 14 |
+
from urllib.parse import urlparse
|
| 15 |
+
|
| 16 |
+
import httpx
|
| 17 |
+
from fastapi import HTTPException, Query
|
| 18 |
+
from PIL import Image
|
| 19 |
+
from pydantic import BaseModel, ConfigDict, StrictBool
|
| 20 |
+
|
| 21 |
+
from .config import CATEGORIES
|
| 22 |
+
from .storage import now
|
| 23 |
+
|
| 24 |
+
FIELDS = ('category', 'verdict', 'score', 'threshold', 'uncertainty_margin',
|
| 25 |
+
'model_id', 'localization', 'scope')
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def public_measurement(record):
|
| 29 |
+
result = {key: record[key] for key in FIELDS if key in record}
|
| 30 |
+
if result.get('category') not in CATEGORIES or result.get('verdict') not in ('Good','Anomalous','Uncertain'):
|
| 31 |
+
raise HTTPException(422, 'A completed supported inspection is required.')
|
| 32 |
+
for key in ('score','threshold','uncertainty_margin'):
|
| 33 |
+
value=result.get(key)
|
| 34 |
+
if key=='uncertainty_margin' and value is None:
|
| 35 |
+
continue
|
| 36 |
+
if isinstance(value,bool) or not isinstance(value,(float,int)) or not math.isfinite(value):
|
| 37 |
+
raise HTTPException(422, 'Inspection measurements are invalid.')
|
| 38 |
+
return result
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def thumbnail(content):
|
| 42 |
+
with Image.open(BytesIO(content)) as source:
|
| 43 |
+
image=source.convert('RGB')
|
| 44 |
+
image.thumbnail((512,512))
|
| 45 |
+
out=BytesIO()
|
| 46 |
+
# A new JPEG drops EXIF, original filename and embedded image metadata.
|
| 47 |
+
image.save(out,format='JPEG',quality=70,optimize=True)
|
| 48 |
+
if len(out.getvalue())>120000:
|
| 49 |
+
raise HTTPException(422,'Public preview is too large.')
|
| 50 |
+
return base64.b64encode(out.getvalue()).decode('ascii')
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class LocalGallery:
|
| 54 |
+
"""Durable on local disk only; deliberately NOT the hosted storage fallback."""
|
| 55 |
+
def __init__(self,path,key):
|
| 56 |
+
self.path=Path(path); self.path.parent.mkdir(parents=True,exist_ok=True)
|
| 57 |
+
self.key=key.encode(); self.lock=threading.RLock()
|
| 58 |
+
with self.connect() as db:
|
| 59 |
+
db.execute('CREATE TABLE IF NOT EXISTS entries(id TEXT PRIMARY KEY,created_at TEXT,owner TEXT,source TEXT,payload TEXT,image TEXT,heatmap TEXT,visible INTEGER,UNIQUE(owner,source))')
|
| 60 |
+
|
| 61 |
+
def connect(self):
|
| 62 |
+
db=sqlite3.connect(self.path,timeout=20); db.row_factory=sqlite3.Row
|
| 63 |
+
return db
|
| 64 |
+
|
| 65 |
+
def identity(self,value):
|
| 66 |
+
return hmac.new(self.key,value.encode(),'sha256').hexdigest()
|
| 67 |
+
|
| 68 |
+
def read(self,identifier=None,offset=0):
|
| 69 |
+
with self.connect() as db:
|
| 70 |
+
if identifier:
|
| 71 |
+
rows=db.execute('SELECT * FROM entries WHERE id=? AND visible=1',(identifier,)).fetchall()
|
| 72 |
+
else:
|
| 73 |
+
rows=db.execute('SELECT * FROM entries WHERE visible=1 ORDER BY created_at DESC,id DESC LIMIT 12 OFFSET ?',(offset,)).fetchall()
|
| 74 |
+
return [dict(id=r['id'],created_at=r['created_at'],measurement=json.loads(r['payload']),
|
| 75 |
+
**({'image':r['image'],'heatmap':r['heatmap']} if identifier else {})) for r in rows]
|
| 76 |
+
|
| 77 |
+
def write(self,action,owner,source='',payload=None,image='',heatmap='',identifier=None,moderator=False):
|
| 78 |
+
with self.lock,self.connect() as db:
|
| 79 |
+
if action=='status':
|
| 80 |
+
row=db.execute('SELECT id,visible FROM entries WHERE owner=? AND source=?',(owner,source)).fetchone()
|
| 81 |
+
return dict(row) if row else None
|
| 82 |
+
if action=='remove':
|
| 83 |
+
cursor=db.execute('UPDATE entries SET visible=0 WHERE id=? AND (owner=? OR ?=1)',(identifier,owner,int(moderator)))
|
| 84 |
+
if not cursor.rowcount:raise HTTPException(404,'Published item is unavailable or belongs to another browser/account.')
|
| 85 |
+
return {'removed':True}
|
| 86 |
+
existing=db.execute('SELECT id,visible FROM entries WHERE owner=? AND source=?',(owner,source)).fetchone()
|
| 87 |
+
if existing:return dict(existing)
|
| 88 |
+
if db.execute('SELECT count(*) FROM entries').fetchone()[0]>=100 or db.execute('SELECT count(*) FROM entries WHERE owner=?',(owner,)).fetchone()[0]>=5:
|
| 89 |
+
raise HTTPException(429,'Demo gallery capacity reached (100 total, 5 per publisher).')
|
| 90 |
+
identifier=uuid.uuid4().hex
|
| 91 |
+
db.execute('INSERT INTO entries VALUES(?,?,?,?,?,?,?,1)',(identifier,now(),owner,source,json.dumps(payload),image,heatmap))
|
| 92 |
+
return {'id':identifier,'visible':True}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class SupabaseGallery:
|
| 96 |
+
def __init__(self,config,key):
|
| 97 |
+
if not re.fullmatch('[a-f0-9]{64}',key):
|
| 98 |
+
raise ValueError('DEFECTRAG_GALLERY_KEY must be a dedicated 64-character lowercase hex secret.')
|
| 99 |
+
self.config=config; self.key=key.encode()
|
| 100 |
+
|
| 101 |
+
identity=LocalGallery.identity
|
| 102 |
+
|
| 103 |
+
def rpc(self,name,payload):
|
| 104 |
+
try:
|
| 105 |
+
with httpx.Client(timeout=25,trust_env=False) as client:
|
| 106 |
+
response=client.post(self.config['url']+'/rest/v1/rpc/'+name,
|
| 107 |
+
headers={'apikey':self.config['key']},json=payload)
|
| 108 |
+
except httpx.HTTPError:
|
| 109 |
+
raise HTTPException(503,'Gallery storage is unavailable. Private inspection remains saved.') from None
|
| 110 |
+
if not response.is_success:
|
| 111 |
+
# Do not forward request bodies, secret, SQL details or database exceptions.
|
| 112 |
+
code=response.json().get('code') if response.headers.get('content-type','').startswith('application/json') else None
|
| 113 |
+
if code=='P0001':
|
| 114 |
+
raise HTTPException(409,'Gallery operation declined: item withdrawn, publisher limit or gallery capacity reached.')
|
| 115 |
+
raise HTTPException(503,'Gallery setup or storage is unavailable. Private inspection remains saved.')
|
| 116 |
+
return response.json()
|
| 117 |
+
|
| 118 |
+
def read(self,identifier=None,offset=0):
|
| 119 |
+
return self.rpc('defectrag_gallery_read',{'p_id':identifier,'p_offset':offset})
|
| 120 |
+
|
| 121 |
+
def write(self,action,owner,source='',payload=None,image='',heatmap='',identifier=None,moderator=False):
|
| 122 |
+
return self.rpc('defectrag_gallery_write',{'p_key':self.key.decode(),'p_action':action,
|
| 123 |
+
'p_owner':owner,'p_source':source,'p_payload':payload or {},'p_image':image,
|
| 124 |
+
'p_heatmap':heatmap,'p_id':identifier,'p_moderator':moderator})
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
class PublishConsent(BaseModel):
|
| 128 |
+
model_config=ConfigDict(extra='forbid')
|
| 129 |
+
consent: StrictBool
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def mount_gallery(app,repo,artifacts,gallery=None,owner=lambda:'local-operator',cloud_origin=''):
|
| 133 |
+
def ready():
|
| 134 |
+
if gallery is None:raise HTTPException(503,'Community gallery is awaiting its separate Supabase setup. Private inspections are unaffected.')
|
| 135 |
+
return gallery
|
| 136 |
+
|
| 137 |
+
def principal():
|
| 138 |
+
current=repo.current() if hasattr(repo,'current') else repo
|
| 139 |
+
staff=getattr(current,'staff',None)
|
| 140 |
+
user=getattr(current,'user',None)
|
| 141 |
+
return ('staff:'+user['id'] if user else 'browser:'+owner()), bool(staff)
|
| 142 |
+
|
| 143 |
+
def keys(identifier):
|
| 144 |
+
actor,staff=principal()
|
| 145 |
+
return ready().identity(actor),ready().identity('inspection:'+identifier),staff
|
| 146 |
+
|
| 147 |
+
def saved(identifier):
|
| 148 |
+
if not re.fullmatch('[a-f0-9]{32}',identifier):raise HTTPException(404,'Inspection not found')
|
| 149 |
+
record=repo.get(identifier)
|
| 150 |
+
if not record:raise HTTPException(404,'Inspection not found')
|
| 151 |
+
return record
|
| 152 |
+
|
| 153 |
+
@app.get('/api/gallery')
|
| 154 |
+
def listing(offset:int=Query(0,ge=0,le=100)):
|
| 155 |
+
if gallery is None:return {'data':{'enabled':False,'items':[]}}
|
| 156 |
+
return {'data':{'enabled':True,'items':gallery.read(offset=offset)}}
|
| 157 |
+
|
| 158 |
+
@app.get('/api/gallery/{identifier}')
|
| 159 |
+
def detail(identifier:str):
|
| 160 |
+
try:uuid.UUID(identifier)
|
| 161 |
+
except ValueError:raise HTTPException(404,'Gallery item not found') from None
|
| 162 |
+
rows=ready().read(identifier)
|
| 163 |
+
if not rows:raise HTTPException(404,'Gallery item not found or withdrawn')
|
| 164 |
+
return {'data':rows[0]}
|
| 165 |
+
|
| 166 |
+
@app.get('/api/inspections/{identifier}/publication')
|
| 167 |
+
def publication(identifier:str):
|
| 168 |
+
if gallery is None:return {'data':{'enabled':False,'publication':None}}
|
| 169 |
+
saved(identifier);actor,source,_=keys(identifier)
|
| 170 |
+
return {'data':{'enabled':True,'publication':gallery.write('status',actor,source)}}
|
| 171 |
+
|
| 172 |
+
@app.post('/api/inspections/{identifier}/publication')
|
| 173 |
+
def publish(identifier:str,body:PublishConsent):
|
| 174 |
+
ready()
|
| 175 |
+
if body.consent is not True:raise HTTPException(422,'Explicit public publication consent is required.')
|
| 176 |
+
record=saved(identifier);actor,source,_=keys(identifier)
|
| 177 |
+
if record.get('storage')=='supabase':
|
| 178 |
+
current=repo.current()
|
| 179 |
+
if record.get('owner_id')!=current.user['id']:
|
| 180 |
+
raise HTTPException(403,'Only the original staff uploader can publish this inspection.')
|
| 181 |
+
measurement=public_measurement(record)
|
| 182 |
+
previews=[]
|
| 183 |
+
for kind,suffix in (('image',''),('heatmap','_heatmap')):
|
| 184 |
+
path=Path(artifacts)/f'{identifier}{suffix}.jpg'
|
| 185 |
+
if record.get('storage')!='supabase':
|
| 186 |
+
if not path.is_file():raise HTTPException(409,'Saved image is unavailable. Nothing was published.')
|
| 187 |
+
content=path.read_bytes()
|
| 188 |
+
else:
|
| 189 |
+
url=record.get(kind+'_url','')
|
| 190 |
+
if not cloud_origin or urlparse(url).netloc!=urlparse(cloud_origin).netloc or not url.startswith('https://'):
|
| 191 |
+
raise HTTPException(403,'Saved image origin is not authorized.')
|
| 192 |
+
try:
|
| 193 |
+
with httpx.Client(timeout=20,trust_env=False,follow_redirects=False) as client:
|
| 194 |
+
with client.stream('GET',url) as response:
|
| 195 |
+
response.raise_for_status(); chunks=[];size=0
|
| 196 |
+
for chunk in response.iter_bytes():
|
| 197 |
+
size+=len(chunk)
|
| 198 |
+
if size>5*1024*1024:raise HTTPException(413,'Saved image exceeds gallery limit.')
|
| 199 |
+
chunks.append(chunk)
|
| 200 |
+
content=b''.join(chunks)
|
| 201 |
+
except httpx.HTTPError:raise HTTPException(503,'Saved image is temporarily unavailable.') from None
|
| 202 |
+
previews.append(thumbnail(content))
|
| 203 |
+
return {'data':gallery.write('publish',actor,source,measurement,*previews)}
|
| 204 |
+
|
| 205 |
+
@app.post('/api/gallery/{identifier}/withdraw')
|
| 206 |
+
def withdraw(identifier:str):
|
| 207 |
+
try:uuid.UUID(identifier)
|
| 208 |
+
except ValueError:raise HTTPException(404,'Gallery item not found') from None
|
| 209 |
+
actor,_,_=keys('withdraw')
|
| 210 |
+
return {'data':gallery.write('remove',actor,identifier=identifier)}
|
| 211 |
+
|
| 212 |
+
@app.post('/api/gallery/{identifier}/moderate')
|
| 213 |
+
def moderate(identifier:str):
|
| 214 |
+
try:uuid.UUID(identifier)
|
| 215 |
+
except ValueError:raise HTTPException(404,'Gallery item not found') from None
|
| 216 |
+
actor,_,staff=keys('moderate')
|
| 217 |
+
if not staff:raise HTTPException(403,'Approved staff access is required for gallery moderation.')
|
| 218 |
+
return {'data':gallery.write('remove',actor,identifier=identifier,moderator=True)}
|
backend/main.py
CHANGED
|
@@ -23,7 +23,7 @@ from .rag import KnowledgeIndex, EvidenceWorkflow
|
|
| 23 |
|
| 24 |
log=logging.getLogger('defectrag')
|
| 25 |
|
| 26 |
-
def create_app(settings=None, detector=None, workflow=None, repository=None):
|
| 27 |
settings=settings or Settings()
|
| 28 |
settings.data.mkdir(parents=True,exist_ok=True)
|
| 29 |
artifacts=settings.data/'artifacts'; artifacts.mkdir(exist_ok=True)
|
|
@@ -34,6 +34,18 @@ def create_app(settings=None, detector=None, workflow=None, repository=None):
|
|
| 34 |
app=FastAPI(title='DefectRAG',version='2.1.0',description='Industrial inspection and evidence workspace')
|
| 35 |
app.state.repo=repo; app.state.detector=detector; app.state.workflow=workflow
|
| 36 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
origins=[o.strip() for o in os.getenv('DEFECTRAG_CORS','http://localhost:5173,http://127.0.0.1:5173').split(',')]
|
| 38 |
app.add_middleware(CORSMiddleware,allow_origins=origins,allow_methods=['GET','POST'],allow_headers=['Content-Type'])
|
| 39 |
|
|
|
|
| 23 |
|
| 24 |
log=logging.getLogger('defectrag')
|
| 25 |
|
| 26 |
+
def create_app(settings=None, detector=None, workflow=None, repository=None, gallery=None):
|
| 27 |
settings=settings or Settings()
|
| 28 |
settings.data.mkdir(parents=True,exist_ok=True)
|
| 29 |
artifacts=settings.data/'artifacts'; artifacts.mkdir(exist_ok=True)
|
|
|
|
| 34 |
app=FastAPI(title='DefectRAG',version='2.1.0',description='Industrial inspection and evidence workspace')
|
| 35 |
app.state.repo=repo; app.state.detector=detector; app.state.workflow=workflow
|
| 36 |
import os
|
| 37 |
+
from .gallery import LocalGallery, mount_gallery
|
| 38 |
+
if gallery is None and os.getenv('DEFECTRAG_GALLERY_ENABLED')=='1' and not hasattr(repo,'current'):
|
| 39 |
+
import secrets
|
| 40 |
+
key_path=settings.data/'gallery.key'
|
| 41 |
+
if not key_path.exists():key_path.write_text(secrets.token_hex(32))
|
| 42 |
+
gallery=LocalGallery(settings.data/'gallery.sqlite3',key_path.read_text().strip())
|
| 43 |
+
if hasattr(repo,'current'):
|
| 44 |
+
from deployment.space.sessions import NAMESPACE
|
| 45 |
+
gallery_owner=lambda:NAMESPACE.get() or ''
|
| 46 |
+
else:gallery_owner=lambda:'local-operator'
|
| 47 |
+
mount_gallery(app,repo,artifacts,gallery,owner=gallery_owner,
|
| 48 |
+
cloud_origin=(getattr(repo,'cloud_config',None) or {}).get('url',''))
|
| 49 |
origins=[o.strip() for o in os.getenv('DEFECTRAG_CORS','http://localhost:5173,http://127.0.0.1:5173').split(',')]
|
| 50 |
app.add_middleware(CORSMiddleware,allow_origins=origins,allow_methods=['GET','POST'],allow_headers=['Content-Type'])
|
| 51 |
|
deployment/space/app.py
CHANGED
|
@@ -93,7 +93,13 @@ if os.getenv('DEFECTRAG_LIVE_RAG')=='1':
|
|
| 93 |
WORKFLOW=EvidenceWorkflow(Settings(),INDEX,generator=generate_text if ZERO else None)
|
| 94 |
else:
|
| 95 |
WORKFLOW=None
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
server = Server(title='DefectRAG')
|
| 98 |
server.exception_handlers.update(cpu_app.exception_handlers)
|
| 99 |
|
|
@@ -112,6 +118,7 @@ async def cloud_storage_error(request,exc):
|
|
| 112 |
async def workspace_access(request, call_next):
|
| 113 |
path = request.url.path
|
| 114 |
public = path in ('/api/health', '/api/models', '/api/evaluation', '/api/benchmark/official', '/api/samples') or path.startswith('/api/samples/')
|
|
|
|
| 115 |
if not path.startswith('/api/') or public:
|
| 116 |
return await call_next(request)
|
| 117 |
try:
|
|
@@ -218,6 +225,7 @@ def health():
|
|
| 218 |
return {'data':{'status':'ok','mode':'cloud_session_workspace','models':list(CARDS.values()),
|
| 219 |
'encoder_configured':True,'llm_model':'Qwen3-4B-Instruct-2507' if WORKFLOW and ZERO else 'Qwen2.5:3b (local Ollama)' if WORKFLOW else 'generation migration in progress','zero_gpu':ZERO,
|
| 220 |
'staff_persistence_enabled':CLOUD_CONFIG is not None,
|
|
|
|
| 221 |
'history':'anonymous browser history is temporary; signed-in approved staff use Supabase' if CLOUD_CONFIG else 'anonymous browser history is temporary; staff backend disabled'}}
|
| 222 |
|
| 223 |
|
|
|
|
| 93 |
WORKFLOW=EvidenceWorkflow(Settings(),INDEX,generator=generate_text if ZERO else None)
|
| 94 |
else:
|
| 95 |
WORKFLOW=None
|
| 96 |
+
GALLERY=None
|
| 97 |
+
if os.getenv('DEFECTRAG_GALLERY_ENABLED')=='1' and CLOUD_CONFIG:
|
| 98 |
+
from backend.gallery import SupabaseGallery
|
| 99 |
+
gallery_key=os.getenv('DEFECTRAG_GALLERY_KEY','')
|
| 100 |
+
if re.fullmatch('[a-f0-9]{64}',gallery_key):
|
| 101 |
+
GALLERY=SupabaseGallery(CLOUD_CONFIG,gallery_key)
|
| 102 |
+
cpu_app = create_app(Settings(), detector=MetadataDetector(), repository=REPO,workflow=WORKFLOW,gallery=GALLERY)
|
| 103 |
server = Server(title='DefectRAG')
|
| 104 |
server.exception_handlers.update(cpu_app.exception_handlers)
|
| 105 |
|
|
|
|
| 118 |
async def workspace_access(request, call_next):
|
| 119 |
path = request.url.path
|
| 120 |
public = path in ('/api/health', '/api/models', '/api/evaluation', '/api/benchmark/official', '/api/samples') or path.startswith('/api/samples/')
|
| 121 |
+
public = public or (request.method=='GET' and (path=='/api/gallery' or re.fullmatch(r'/api/gallery/[a-f0-9-]{32,36}',path)))
|
| 122 |
if not path.startswith('/api/') or public:
|
| 123 |
return await call_next(request)
|
| 124 |
try:
|
|
|
|
| 225 |
return {'data':{'status':'ok','mode':'cloud_session_workspace','models':list(CARDS.values()),
|
| 226 |
'encoder_configured':True,'llm_model':'Qwen3-4B-Instruct-2507' if WORKFLOW and ZERO else 'Qwen2.5:3b (local Ollama)' if WORKFLOW else 'generation migration in progress','zero_gpu':ZERO,
|
| 227 |
'staff_persistence_enabled':CLOUD_CONFIG is not None,
|
| 228 |
+
'community_gallery_enabled':GALLERY is not None,
|
| 229 |
'history':'anonymous browser history is temporary; signed-in approved staff use Supabase' if CLOUD_CONFIG else 'anonymous browser history is temporary; staff backend disabled'}}
|
| 230 |
|
| 231 |
|
frontend/dist/assets/TeamWorkspace-BTKzGjaI.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import{c as E,r as n,a as ne,b as d,R as e,L as le,S as se,A as ce,d as oe,e as ie,w as _,p as Y,f as de}from"./index-BhrFTP_4.js";/**
|
| 2 |
+
* @license lucide-react v0.468.0 - ISC
|
| 3 |
+
*
|
| 4 |
+
* This source code is licensed under the ISC license.
|
| 5 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 6 |
+
*/const me=E("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/**
|
| 7 |
+
* @license lucide-react v0.468.0 - ISC
|
| 8 |
+
*
|
| 9 |
+
* This source code is licensed under the ISC license.
|
| 10 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 11 |
+
*/const q=E("Cloud",[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]);/**
|
| 12 |
+
* @license lucide-react v0.468.0 - ISC
|
| 13 |
+
*
|
| 14 |
+
* This source code is licensed under the ISC license.
|
| 15 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 16 |
+
*/const ue=E("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
|
| 17 |
+
* @license lucide-react v0.468.0 - ISC
|
| 18 |
+
*
|
| 19 |
+
* This source code is licensed under the ISC license.
|
| 20 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 21 |
+
*/const pe=E("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/**
|
| 22 |
+
* @license lucide-react v0.468.0 - ISC
|
| 23 |
+
*
|
| 24 |
+
* This source code is licensed under the ISC license.
|
| 25 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 26 |
+
*/const he=E("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/**
|
| 27 |
+
* @license lucide-react v0.468.0 - ISC
|
| 28 |
+
*
|
| 29 |
+
* This source code is licensed under the ISC license.
|
| 30 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 31 |
+
*/const Ee=E("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
| 32 |
+
* @license lucide-react v0.468.0 - ISC
|
| 33 |
+
*
|
| 34 |
+
* This source code is licensed under the ISC license.
|
| 35 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 36 |
+
*/const ye=E("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
|
| 37 |
+
* @license lucide-react v0.468.0 - ISC
|
| 38 |
+
*
|
| 39 |
+
* This source code is licensed under the ISC license.
|
| 40 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 41 |
+
*/const fe=E("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function we({onOpenInspection:P}){var K;const v=n.useRef(0),z=n.useRef(null),[c,U]=n.useState(null),[s,O]=n.useState(null),[g,I]=n.useState([]),[S,Z]=n.useState({}),[C,J]=n.useState(""),[j,D]=n.useState(""),[i,T]=n.useState(!1),[F,w]=n.useState(""),[y,Q]=n.useState(!1),[l,b]=n.useState(null),[X,$]=n.useState([]),[R,ee]=n.useState([]),[A,H]=n.useState(""),[te,B]=n.useState(!1),[W,V]=n.useState(""),[ae,x]=n.useState(!1),M=ne();async function m(t){T(!0),w("");try{await t()}catch(r){w(r.message||"Team request failed.")}finally{T(!1)}}async function k(){const{client:t,staff:r}=await de();O(r);let a=t.from("shared_inspections").select("*").order("created_at",{ascending:!1}).limit(200);a=y?a.not("archived_at","is",null):a.is("archived_at",null);const[{data:u,error:p},{data:o,error:f}]=await Promise.all([a,t.from("staff_members").select("*")]);if(p)throw p;if(f)throw f;I(u||[]),Z(Object.fromEntries((o||[]).map(h=>[h.user_id,h.display_name])))}n.useEffect(()=>{if(!M)return;let t=!1,r;return d().then(async a=>{r=a.auth.onAuthStateChange((p,o)=>{var f;if(!t){const h=((f=o==null?void 0:o.user)==null?void 0:f.id)||null;z.current!==h&&(v.current++,b(null),z.current=h),U((o==null?void 0:o.user)||null),p==="PASSWORD_RECOVERY"&&B(!0)}}).data.subscription;const{data:u}=await a.auth.getUser();t||U(u.user)}).catch(a=>{t||w(a.message)}),()=>{t=!0,v.current++,r==null||r.unsubscribe()}},[M]),n.useEffect(()=>{if(!c)return;let t=!1;k().catch(a=>{t||w(a.message)});const r=setInterval(()=>k().catch(a=>{t||w(a.message)}),15e3);return()=>{t=!0,clearInterval(r)}},[c==null?void 0:c.id,y]);async function L(t){const r=++v.current;await m(async()=>{const a=await d(),u=a.storage.from("team-inspections"),[{data:p,error:o},{data:f,error:h}]=await Promise.all([a.from("shared_inspections").select("*").eq("id",t.id).single(),a.from("staff_notes").select("*").eq("inspection_id",t.id).order("created_at")]);if(o)throw o;if(h)throw h;const G=await Promise.all([p.image_path,p.heatmap_path].map(N=>u.createSignedUrl(N,900)));if(G.some(N=>N.error))throw new Error("Private images could not be loaded. Check staff/storage policies.");r===v.current&&(b(p),$(G.map(N=>N.data.signedUrl)),ee(f||[]))})}async function re(){await m(async()=>{const t=await d(),r=g.filter(a=>a.owner_id===c.id).map(a=>a.id);if(r.length){const{error:a}=await t.rpc("archive_team_inspections",{p_ids:r});if(a)throw a}v.current++,b(null),x(!1),await k(),_()})}return M?e.createElement(e.Fragment,null,e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,e.createElement(fe,{size:21})," Staff workspace"),e.createElement("p",null,"Signed-in staff share saved inspections and review notes. Live AI runs on the connected inspection backend.")),e.createElement("span",{className:"subtle-tag"},e.createElement(q,{size:13})," SUPABASE")),F&&e.createElement("div",{className:"error",role:"alert"},F),c?e.createElement(e.Fragment,null,e.createElement("div",{className:"team-toolbar"},e.createElement("div",null,e.createElement(se,{size:18}),e.createElement("strong",null,(s==null?void 0:s.display_name)||c.email),e.createElement("span",{className:"subtle-tag"},(s==null?void 0:s.role)||"CHECKING MEMBERSHIP")),e.createElement("button",{className:"secondary",disabled:i,onClick:()=>m(k)},e.createElement(Ee,{size:16})," Refresh"),e.createElement("button",{className:"secondary",onClick:()=>m(async()=>{await(await d()).auth.signOut(),I([]),b(null),O(null)})},e.createElement(he,{size:16})," Sign out")),te&&e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.auth.updateUser({password:W});if(a)throw a;V(""),B(!1)})}},e.createElement("label",{className:"field"},"Set a new password",e.createElement("input",{type:"password",minLength:12,autoComplete:"new-password",value:W,onChange:t=>V(t.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:i},"Save password")),e.createElement("div",{className:"team-toolbar"},e.createElement("span",null,"Latest ",g.length," shared records · refreshes every 15 seconds"),(s==null?void 0:s.role)==="developer"&&e.createElement("button",{className:"secondary",onClick:()=>{Q(!y),b(null)}},e.createElement(me,{size:16}),y?"Active history":"Developer recovery"),!y&&e.createElement("button",{className:"secondary danger",disabled:i||!g.some(t=>t.owner_id===c.id),onClick:()=>x(!0)},e.createElement(ce,{size:16})," Archive my visible history")),ae&&e.createElement("div",{className:"note"},e.createElement("div",null,e.createElement("strong",null,"Archive your visible records?"),e.createElement("p",null,"They will leave the shared active history. Original files and conversations remain recoverable by a developer. Other staff members’ records will stay active."),e.createElement("div",{className:"button-row"},e.createElement("button",{className:"primary",disabled:i,onClick:re},"Archive my records"),e.createElement("button",{className:"secondary",onClick:()=>x(!1)},"Cancel")))),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Inspection"),e.createElement("th",null,"Product"),e.createElement("th",null,"Result"),e.createElement("th",null,"Shared by"),e.createElement("th",null,"Saved"),e.createElement("th",null))),e.createElement("tbody",null,g.map(t=>{var r;return e.createElement("tr",{key:t.id},e.createElement("td",null,e.createElement("strong",null,t.id.slice(0,8))),e.createElement("td",null,t.payload.category),e.createElement("td",null,e.createElement("span",{className:"badge "+((r=t.payload.verdict)==null?void 0:r.toLowerCase())},t.payload.verdict)),e.createElement("td",null,S[t.owner_id]||"Staff member"),e.createElement("td",null,new Date(t.created_at).toLocaleString()),e.createElement("td",null,e.createElement("button",{className:"text-button",onClick:()=>L(t)},"Review"),y&&(s==null?void 0:s.role)==="developer"&&e.createElement("button",{className:"text-button",disabled:i,onClick:()=>m(async()=>{const a=await d(),{error:u}=await a.rpc("restore_team_inspections",{p_ids:[t.id]});if(u)throw u;await k(),_()})},"Restore")))}))),!g.length&&e.createElement("div",{className:"empty"},e.createElement(q,{size:30}),e.createElement("p",null,y?"No archived records to recover.":"No shared inspections yet. Open an inspection result and select Share with staff.")))):e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.auth.signInWithPassword({email:C,password:j});if(a)throw a;D("")})}},e.createElement("label",{className:"field"},"Work email",e.createElement("input",{type:"email",autoComplete:"username",value:C,onChange:t=>J(t.target.value),required:!0})),e.createElement("label",{className:"field"},"Password",e.createElement("input",{type:"password",autoComplete:"current-password",value:j,onChange:t=>D(t.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:i},i?e.createElement(le,{className:"spin",size:17}):e.createElement(pe,{size:17})," Sign in"),e.createElement("button",{type:"button",className:"text-button",disabled:!C||i,onClick:()=>m(async()=>{const t=await d(),{error:r}=await t.auth.resetPasswordForEmail(C,{redirectTo:location.origin+location.pathname});if(r)throw r;w("Password reset requested. Check your email.")})},"Reset password"),e.createElement("p",{className:"caption"},"Accounts must be invited and approved by your workspace developer. Signing up alone does not grant staff access."))),c&&l&&e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,"Shared inspection · ",l.id.slice(0,8)),e.createElement("p",null,"Saved snapshot from ",S[l.owner_id]||"a colleague",". This page does not run a new prediction.")),e.createElement("div",{className:"button-row"},P&&!l.archived_at&&e.createElement("button",{className:"secondary",onClick:()=>P(l)},"Open inspection & assistant"),e.createElement("button",{className:"text-button",onClick:()=>{v.current++,b(null)}},"Close"))),e.createElement("div",{className:"shared-images"},X.map((t,r)=>e.createElement("img",{key:t,src:t,alt:r?"Saved anomaly heatmap":"Saved inspected product"}))),e.createElement("div",{className:"observation"},e.createElement("strong",null,"SAVED MEASUREMENTS"),e.createElement("span",null,l.payload.verdict," · score ",Number(l.payload.score).toFixed(5)," · threshold ",Number(l.payload.threshold).toFixed(5))),e.createElement("h3",{className:"section-gap"},"Recorded evidence"),(K=l.conversation)!=null&&K.length?l.conversation.map((t,r)=>e.createElement("p",{className:"cloud-message",key:r},e.createElement("strong",null,t.role==="user"?"Inspector":"Evidence Assistant",": "),t.question||t.answer)):e.createElement("p",{className:"caption"},"No conversation was included when this inspection was shared."),!l.archived_at&&e.createElement(oe,{key:l.id+String(R.length),current:R.map(t=>Y(t,S)).filter(Boolean).at(-1),disabled:i,onSave:async t=>{const r=await d(),{error:a}=await r.from("staff_notes").insert({inspection_id:l.id,author_id:c.id,body:ie(t.status,t.decision,t.note)});if(a)throw a;await L(l),_()}}),e.createElement("h3",{className:"section-gap"},"Staff review notes"),R.filter(t=>!Y(t,S)).map(t=>e.createElement("div",{className:"cloud-message",key:t.id},e.createElement("strong",null,S[t.author_id]||"Staff member"),e.createElement("p",null,t.body),e.createElement("small",null,new Date(t.created_at).toLocaleString()))),!l.archived_at&&e.createElement("form",{className:"question-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.from("staff_notes").insert({inspection_id:l.id,author_id:c.id,body:A.trim()});if(a)throw a;H(""),await L(l),_()})}},e.createElement("input",{"aria-label":"Staff review note",maxLength:2e3,placeholder:"Add a review note for your colleagues…",value:A,onChange:t=>H(t.target.value)}),e.createElement("button",{className:"primary",disabled:i||!A.trim()},e.createElement(ye,{size:16})," Add note")))):e.createElement("section",{className:"card cloud-setup"},e.createElement("div",{className:"setup-icon"},e.createElement(q,{size:32})),e.createElement("span",{className:"eyebrow"},"TEAM WORKSPACE"),e.createElement("h2",null,"One shared view of inspection."),e.createElement("p",null,"The staff workspace is ready to connect to your own Supabase project. No cloud project or account has been created for you."),e.createElement("div",{className:"setup-grid"},[["01","Create a free project","Use your Supabase account and select an eligible Free plan."],["02","Set up staff access","Run the supplied schema, add your developer account and invite colleagues."],["03","Connect this dashboard","Add the project URL and publishable key to config.js, then reload."]].map(([t,r,a])=>e.createElement("div",{key:t},e.createElement("b",null,t),e.createElement("h3",null,r),e.createElement("p",null,a)))),e.createElement("a",{className:"primary",href:"https://supabase.com/dashboard",target:"_blank",rel:"noreferrer"},"Open Supabase ",e.createElement(ue,{size:16})),e.createElement("p",{className:"caption"},"Setup files: deployment/SUPABASE_SETUP.md and deployment/supabase.sql. Never place a service-role key in the browser. Local inspection works without cloud setup."))}export{we as default};
|
frontend/dist/assets/TeamWorkspace-D9wVcLaF.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import{c as E,r as n,a as ne,b as d,R as e,L as le,S as se,A as ce,d as oe,e as ie,w as _,p as Y,f as de}from"./index-DyHDnvjh.js";/**
|
| 2 |
+
* @license lucide-react v0.468.0 - ISC
|
| 3 |
+
*
|
| 4 |
+
* This source code is licensed under the ISC license.
|
| 5 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 6 |
+
*/const me=E("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/**
|
| 7 |
+
* @license lucide-react v0.468.0 - ISC
|
| 8 |
+
*
|
| 9 |
+
* This source code is licensed under the ISC license.
|
| 10 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 11 |
+
*/const q=E("Cloud",[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]);/**
|
| 12 |
+
* @license lucide-react v0.468.0 - ISC
|
| 13 |
+
*
|
| 14 |
+
* This source code is licensed under the ISC license.
|
| 15 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 16 |
+
*/const ue=E("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
|
| 17 |
+
* @license lucide-react v0.468.0 - ISC
|
| 18 |
+
*
|
| 19 |
+
* This source code is licensed under the ISC license.
|
| 20 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 21 |
+
*/const pe=E("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/**
|
| 22 |
+
* @license lucide-react v0.468.0 - ISC
|
| 23 |
+
*
|
| 24 |
+
* This source code is licensed under the ISC license.
|
| 25 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 26 |
+
*/const he=E("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/**
|
| 27 |
+
* @license lucide-react v0.468.0 - ISC
|
| 28 |
+
*
|
| 29 |
+
* This source code is licensed under the ISC license.
|
| 30 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 31 |
+
*/const Ee=E("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
| 32 |
+
* @license lucide-react v0.468.0 - ISC
|
| 33 |
+
*
|
| 34 |
+
* This source code is licensed under the ISC license.
|
| 35 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 36 |
+
*/const ye=E("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
|
| 37 |
+
* @license lucide-react v0.468.0 - ISC
|
| 38 |
+
*
|
| 39 |
+
* This source code is licensed under the ISC license.
|
| 40 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 41 |
+
*/const fe=E("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function we({onOpenInspection:P}){var K;const v=n.useRef(0),z=n.useRef(null),[c,U]=n.useState(null),[s,O]=n.useState(null),[g,I]=n.useState([]),[S,Z]=n.useState({}),[C,J]=n.useState(""),[j,D]=n.useState(""),[i,T]=n.useState(!1),[F,w]=n.useState(""),[y,Q]=n.useState(!1),[l,b]=n.useState(null),[X,$]=n.useState([]),[R,ee]=n.useState([]),[A,H]=n.useState(""),[te,B]=n.useState(!1),[W,V]=n.useState(""),[ae,x]=n.useState(!1),M=ne();async function m(t){T(!0),w("");try{await t()}catch(r){w(r.message||"Team request failed.")}finally{T(!1)}}async function k(){const{client:t,staff:r}=await de();O(r);let a=t.from("shared_inspections").select("*").order("created_at",{ascending:!1}).limit(200);a=y?a.not("archived_at","is",null):a.is("archived_at",null);const[{data:u,error:p},{data:o,error:f}]=await Promise.all([a,t.from("staff_members").select("*")]);if(p)throw p;if(f)throw f;I(u||[]),Z(Object.fromEntries((o||[]).map(h=>[h.user_id,h.display_name])))}n.useEffect(()=>{if(!M)return;let t=!1,r;return d().then(async a=>{r=a.auth.onAuthStateChange((p,o)=>{var f;if(!t){const h=((f=o==null?void 0:o.user)==null?void 0:f.id)||null;z.current!==h&&(v.current++,b(null),z.current=h),U((o==null?void 0:o.user)||null),p==="PASSWORD_RECOVERY"&&B(!0)}}).data.subscription;const{data:u}=await a.auth.getUser();t||U(u.user)}).catch(a=>{t||w(a.message)}),()=>{t=!0,v.current++,r==null||r.unsubscribe()}},[M]),n.useEffect(()=>{if(!c)return;let t=!1;k().catch(a=>{t||w(a.message)});const r=setInterval(()=>k().catch(a=>{t||w(a.message)}),15e3);return()=>{t=!0,clearInterval(r)}},[c==null?void 0:c.id,y]);async function L(t){const r=++v.current;await m(async()=>{const a=await d(),u=a.storage.from("team-inspections"),[{data:p,error:o},{data:f,error:h}]=await Promise.all([a.from("shared_inspections").select("*").eq("id",t.id).single(),a.from("staff_notes").select("*").eq("inspection_id",t.id).order("created_at")]);if(o)throw o;if(h)throw h;const G=await Promise.all([p.image_path,p.heatmap_path].map(N=>u.createSignedUrl(N,900)));if(G.some(N=>N.error))throw new Error("Private images could not be loaded. Check staff/storage policies.");r===v.current&&(b(p),$(G.map(N=>N.data.signedUrl)),ee(f||[]))})}async function re(){await m(async()=>{const t=await d(),r=g.filter(a=>a.owner_id===c.id).map(a=>a.id);if(r.length){const{error:a}=await t.rpc("archive_team_inspections",{p_ids:r});if(a)throw a}v.current++,b(null),x(!1),await k(),_()})}return M?e.createElement(e.Fragment,null,e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,e.createElement(fe,{size:21})," Staff workspace"),e.createElement("p",null,"Signed-in staff share saved inspections and review notes. Live AI runs on the connected inspection backend.")),e.createElement("span",{className:"subtle-tag"},e.createElement(q,{size:13})," SUPABASE")),F&&e.createElement("div",{className:"error",role:"alert"},F),c?e.createElement(e.Fragment,null,e.createElement("div",{className:"team-toolbar"},e.createElement("div",null,e.createElement(se,{size:18}),e.createElement("strong",null,(s==null?void 0:s.display_name)||c.email),e.createElement("span",{className:"subtle-tag"},(s==null?void 0:s.role)||"CHECKING MEMBERSHIP")),e.createElement("button",{className:"secondary",disabled:i,onClick:()=>m(k)},e.createElement(Ee,{size:16})," Refresh"),e.createElement("button",{className:"secondary",onClick:()=>m(async()=>{await(await d()).auth.signOut(),I([]),b(null),O(null)})},e.createElement(he,{size:16})," Sign out")),te&&e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.auth.updateUser({password:W});if(a)throw a;V(""),B(!1)})}},e.createElement("label",{className:"field"},"Set a new password",e.createElement("input",{type:"password",minLength:12,autoComplete:"new-password",value:W,onChange:t=>V(t.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:i},"Save password")),e.createElement("div",{className:"team-toolbar"},e.createElement("span",null,"Latest ",g.length," shared records · refreshes every 15 seconds"),(s==null?void 0:s.role)==="developer"&&e.createElement("button",{className:"secondary",onClick:()=>{Q(!y),b(null)}},e.createElement(me,{size:16}),y?"Active history":"Developer recovery"),!y&&e.createElement("button",{className:"secondary danger",disabled:i||!g.some(t=>t.owner_id===c.id),onClick:()=>x(!0)},e.createElement(ce,{size:16})," Archive my visible history")),ae&&e.createElement("div",{className:"note"},e.createElement("div",null,e.createElement("strong",null,"Archive your visible records?"),e.createElement("p",null,"They will leave the shared active history. Original files and conversations remain recoverable by a developer. Other staff members’ records will stay active."),e.createElement("div",{className:"button-row"},e.createElement("button",{className:"primary",disabled:i,onClick:re},"Archive my records"),e.createElement("button",{className:"secondary",onClick:()=>x(!1)},"Cancel")))),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Inspection"),e.createElement("th",null,"Product"),e.createElement("th",null,"Result"),e.createElement("th",null,"Shared by"),e.createElement("th",null,"Saved"),e.createElement("th",null))),e.createElement("tbody",null,g.map(t=>{var r;return e.createElement("tr",{key:t.id},e.createElement("td",null,e.createElement("strong",null,t.id.slice(0,8))),e.createElement("td",null,t.payload.category),e.createElement("td",null,e.createElement("span",{className:"badge "+((r=t.payload.verdict)==null?void 0:r.toLowerCase())},t.payload.verdict)),e.createElement("td",null,S[t.owner_id]||"Staff member"),e.createElement("td",null,new Date(t.created_at).toLocaleString()),e.createElement("td",null,e.createElement("button",{className:"text-button",onClick:()=>L(t)},"Review"),y&&(s==null?void 0:s.role)==="developer"&&e.createElement("button",{className:"text-button",disabled:i,onClick:()=>m(async()=>{const a=await d(),{error:u}=await a.rpc("restore_team_inspections",{p_ids:[t.id]});if(u)throw u;await k(),_()})},"Restore")))}))),!g.length&&e.createElement("div",{className:"empty"},e.createElement(q,{size:30}),e.createElement("p",null,y?"No archived records to recover.":"No shared inspections yet. Open an inspection result and select Share with staff.")))):e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.auth.signInWithPassword({email:C,password:j});if(a)throw a;D("")})}},e.createElement("label",{className:"field"},"Work email",e.createElement("input",{type:"email",autoComplete:"username",value:C,onChange:t=>J(t.target.value),required:!0})),e.createElement("label",{className:"field"},"Password",e.createElement("input",{type:"password",autoComplete:"current-password",value:j,onChange:t=>D(t.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:i},i?e.createElement(le,{className:"spin",size:17}):e.createElement(pe,{size:17})," Sign in"),e.createElement("button",{type:"button",className:"text-button",disabled:!C||i,onClick:()=>m(async()=>{const t=await d(),{error:r}=await t.auth.resetPasswordForEmail(C,{redirectTo:location.origin+location.pathname});if(r)throw r;w("Password reset requested. Check your email.")})},"Reset password"),e.createElement("p",{className:"caption"},"Accounts must be invited and approved by your workspace developer. Signing up alone does not grant staff access."))),c&&l&&e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,"Shared inspection · ",l.id.slice(0,8)),e.createElement("p",null,"Saved snapshot from ",S[l.owner_id]||"a colleague",". This page does not run a new prediction.")),e.createElement("div",{className:"button-row"},P&&!l.archived_at&&e.createElement("button",{className:"secondary",onClick:()=>P(l)},"Open inspection & assistant"),e.createElement("button",{className:"text-button",onClick:()=>{v.current++,b(null)}},"Close"))),e.createElement("div",{className:"shared-images"},X.map((t,r)=>e.createElement("img",{key:t,src:t,alt:r?"Saved anomaly heatmap":"Saved inspected product"}))),e.createElement("div",{className:"observation"},e.createElement("strong",null,"SAVED MEASUREMENTS"),e.createElement("span",null,l.payload.verdict," · score ",Number(l.payload.score).toFixed(5)," · threshold ",Number(l.payload.threshold).toFixed(5))),e.createElement("h3",{className:"section-gap"},"Recorded evidence"),(K=l.conversation)!=null&&K.length?l.conversation.map((t,r)=>e.createElement("p",{className:"cloud-message",key:r},e.createElement("strong",null,t.role==="user"?"Inspector":"Evidence Assistant",": "),t.question||t.answer)):e.createElement("p",{className:"caption"},"No conversation was included when this inspection was shared."),!l.archived_at&&e.createElement(oe,{key:l.id+String(R.length),current:R.map(t=>Y(t,S)).filter(Boolean).at(-1),disabled:i,onSave:async t=>{const r=await d(),{error:a}=await r.from("staff_notes").insert({inspection_id:l.id,author_id:c.id,body:ie(t.status,t.decision,t.note)});if(a)throw a;await L(l),_()}}),e.createElement("h3",{className:"section-gap"},"Staff review notes"),R.filter(t=>!Y(t,S)).map(t=>e.createElement("div",{className:"cloud-message",key:t.id},e.createElement("strong",null,S[t.author_id]||"Staff member"),e.createElement("p",null,t.body),e.createElement("small",null,new Date(t.created_at).toLocaleString()))),!l.archived_at&&e.createElement("form",{className:"question-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.from("staff_notes").insert({inspection_id:l.id,author_id:c.id,body:A.trim()});if(a)throw a;H(""),await L(l),_()})}},e.createElement("input",{"aria-label":"Staff review note",maxLength:2e3,placeholder:"Add a review note for your colleagues…",value:A,onChange:t=>H(t.target.value)}),e.createElement("button",{className:"primary",disabled:i||!A.trim()},e.createElement(ye,{size:16})," Add note")))):e.createElement("section",{className:"card cloud-setup"},e.createElement("div",{className:"setup-icon"},e.createElement(q,{size:32})),e.createElement("span",{className:"eyebrow"},"TEAM WORKSPACE"),e.createElement("h2",null,"One shared view of inspection."),e.createElement("p",null,"The staff workspace is ready to connect to your own Supabase project. No cloud project or account has been created for you."),e.createElement("div",{className:"setup-grid"},[["01","Create a free project","Use your Supabase account and select an eligible Free plan."],["02","Set up staff access","Run the supplied schema, add your developer account and invite colleagues."],["03","Connect this dashboard","Add the project URL and publishable key to config.js, then reload."]].map(([t,r,a])=>e.createElement("div",{key:t},e.createElement("b",null,t),e.createElement("h3",null,r),e.createElement("p",null,a)))),e.createElement("a",{className:"primary",href:"https://supabase.com/dashboard",target:"_blank",rel:"noreferrer"},"Open Supabase ",e.createElement(ue,{size:16})),e.createElement("p",{className:"caption"},"Setup files: deployment/SUPABASE_SETUP.md and deployment/supabase.sql. Never place a service-role key in the browser. Local inspection works without cloud setup."))}export{we as default};
|
frontend/dist/assets/TeamWorkspace-DBuMBxqK.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import{c as E,r as n,a as ne,b as d,R as e,L as le,S as se,A as ce,d as oe,e as ie,w as _,p as Y,f as de}from"./index-CXC_txue.js";/**
|
| 2 |
+
* @license lucide-react v0.468.0 - ISC
|
| 3 |
+
*
|
| 4 |
+
* This source code is licensed under the ISC license.
|
| 5 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 6 |
+
*/const me=E("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/**
|
| 7 |
+
* @license lucide-react v0.468.0 - ISC
|
| 8 |
+
*
|
| 9 |
+
* This source code is licensed under the ISC license.
|
| 10 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 11 |
+
*/const q=E("Cloud",[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]);/**
|
| 12 |
+
* @license lucide-react v0.468.0 - ISC
|
| 13 |
+
*
|
| 14 |
+
* This source code is licensed under the ISC license.
|
| 15 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 16 |
+
*/const ue=E("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
|
| 17 |
+
* @license lucide-react v0.468.0 - ISC
|
| 18 |
+
*
|
| 19 |
+
* This source code is licensed under the ISC license.
|
| 20 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 21 |
+
*/const pe=E("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/**
|
| 22 |
+
* @license lucide-react v0.468.0 - ISC
|
| 23 |
+
*
|
| 24 |
+
* This source code is licensed under the ISC license.
|
| 25 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 26 |
+
*/const he=E("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/**
|
| 27 |
+
* @license lucide-react v0.468.0 - ISC
|
| 28 |
+
*
|
| 29 |
+
* This source code is licensed under the ISC license.
|
| 30 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 31 |
+
*/const Ee=E("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
| 32 |
+
* @license lucide-react v0.468.0 - ISC
|
| 33 |
+
*
|
| 34 |
+
* This source code is licensed under the ISC license.
|
| 35 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 36 |
+
*/const ye=E("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
|
| 37 |
+
* @license lucide-react v0.468.0 - ISC
|
| 38 |
+
*
|
| 39 |
+
* This source code is licensed under the ISC license.
|
| 40 |
+
* See the LICENSE file in the root directory of this source tree.
|
| 41 |
+
*/const fe=E("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function we({onOpenInspection:P}){var K;const v=n.useRef(0),z=n.useRef(null),[c,U]=n.useState(null),[s,O]=n.useState(null),[g,I]=n.useState([]),[S,Z]=n.useState({}),[C,J]=n.useState(""),[j,D]=n.useState(""),[i,T]=n.useState(!1),[F,w]=n.useState(""),[y,Q]=n.useState(!1),[l,b]=n.useState(null),[X,$]=n.useState([]),[R,ee]=n.useState([]),[A,H]=n.useState(""),[te,B]=n.useState(!1),[W,V]=n.useState(""),[ae,x]=n.useState(!1),M=ne();async function m(t){T(!0),w("");try{await t()}catch(r){w(r.message||"Team request failed.")}finally{T(!1)}}async function k(){const{client:t,staff:r}=await de();O(r);let a=t.from("shared_inspections").select("*").order("created_at",{ascending:!1}).limit(200);a=y?a.not("archived_at","is",null):a.is("archived_at",null);const[{data:u,error:p},{data:o,error:f}]=await Promise.all([a,t.from("staff_members").select("*")]);if(p)throw p;if(f)throw f;I(u||[]),Z(Object.fromEntries((o||[]).map(h=>[h.user_id,h.display_name])))}n.useEffect(()=>{if(!M)return;let t=!1,r;return d().then(async a=>{r=a.auth.onAuthStateChange((p,o)=>{var f;if(!t){const h=((f=o==null?void 0:o.user)==null?void 0:f.id)||null;z.current!==h&&(v.current++,b(null),z.current=h),U((o==null?void 0:o.user)||null),p==="PASSWORD_RECOVERY"&&B(!0)}}).data.subscription;const{data:u}=await a.auth.getUser();t||U(u.user)}).catch(a=>{t||w(a.message)}),()=>{t=!0,v.current++,r==null||r.unsubscribe()}},[M]),n.useEffect(()=>{if(!c)return;let t=!1;k().catch(a=>{t||w(a.message)});const r=setInterval(()=>k().catch(a=>{t||w(a.message)}),15e3);return()=>{t=!0,clearInterval(r)}},[c==null?void 0:c.id,y]);async function L(t){const r=++v.current;await m(async()=>{const a=await d(),u=a.storage.from("team-inspections"),[{data:p,error:o},{data:f,error:h}]=await Promise.all([a.from("shared_inspections").select("*").eq("id",t.id).single(),a.from("staff_notes").select("*").eq("inspection_id",t.id).order("created_at")]);if(o)throw o;if(h)throw h;const G=await Promise.all([p.image_path,p.heatmap_path].map(N=>u.createSignedUrl(N,900)));if(G.some(N=>N.error))throw new Error("Private images could not be loaded. Check staff/storage policies.");r===v.current&&(b(p),$(G.map(N=>N.data.signedUrl)),ee(f||[]))})}async function re(){await m(async()=>{const t=await d(),r=g.filter(a=>a.owner_id===c.id).map(a=>a.id);if(r.length){const{error:a}=await t.rpc("archive_team_inspections",{p_ids:r});if(a)throw a}v.current++,b(null),x(!1),await k(),_()})}return M?e.createElement(e.Fragment,null,e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,e.createElement(fe,{size:21})," Staff workspace"),e.createElement("p",null,"Signed-in staff share saved inspections and review notes. Live AI runs on the connected inspection backend.")),e.createElement("span",{className:"subtle-tag"},e.createElement(q,{size:13})," SUPABASE")),F&&e.createElement("div",{className:"error",role:"alert"},F),c?e.createElement(e.Fragment,null,e.createElement("div",{className:"team-toolbar"},e.createElement("div",null,e.createElement(se,{size:18}),e.createElement("strong",null,(s==null?void 0:s.display_name)||c.email),e.createElement("span",{className:"subtle-tag"},(s==null?void 0:s.role)||"CHECKING MEMBERSHIP")),e.createElement("button",{className:"secondary",disabled:i,onClick:()=>m(k)},e.createElement(Ee,{size:16})," Refresh"),e.createElement("button",{className:"secondary",onClick:()=>m(async()=>{await(await d()).auth.signOut(),I([]),b(null),O(null)})},e.createElement(he,{size:16})," Sign out")),te&&e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.auth.updateUser({password:W});if(a)throw a;V(""),B(!1)})}},e.createElement("label",{className:"field"},"Set a new password",e.createElement("input",{type:"password",minLength:12,autoComplete:"new-password",value:W,onChange:t=>V(t.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:i},"Save password")),e.createElement("div",{className:"team-toolbar"},e.createElement("span",null,"Latest ",g.length," shared records · refreshes every 15 seconds"),(s==null?void 0:s.role)==="developer"&&e.createElement("button",{className:"secondary",onClick:()=>{Q(!y),b(null)}},e.createElement(me,{size:16}),y?"Active history":"Developer recovery"),!y&&e.createElement("button",{className:"secondary danger",disabled:i||!g.some(t=>t.owner_id===c.id),onClick:()=>x(!0)},e.createElement(ce,{size:16})," Archive my visible history")),ae&&e.createElement("div",{className:"note"},e.createElement("div",null,e.createElement("strong",null,"Archive your visible records?"),e.createElement("p",null,"They will leave the shared active history. Original files and conversations remain recoverable by a developer. Other staff members’ records will stay active."),e.createElement("div",{className:"button-row"},e.createElement("button",{className:"primary",disabled:i,onClick:re},"Archive my records"),e.createElement("button",{className:"secondary",onClick:()=>x(!1)},"Cancel")))),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Inspection"),e.createElement("th",null,"Product"),e.createElement("th",null,"Result"),e.createElement("th",null,"Shared by"),e.createElement("th",null,"Saved"),e.createElement("th",null))),e.createElement("tbody",null,g.map(t=>{var r;return e.createElement("tr",{key:t.id},e.createElement("td",null,e.createElement("strong",null,t.id.slice(0,8))),e.createElement("td",null,t.payload.category),e.createElement("td",null,e.createElement("span",{className:"badge "+((r=t.payload.verdict)==null?void 0:r.toLowerCase())},t.payload.verdict)),e.createElement("td",null,S[t.owner_id]||"Staff member"),e.createElement("td",null,new Date(t.created_at).toLocaleString()),e.createElement("td",null,e.createElement("button",{className:"text-button",onClick:()=>L(t)},"Review"),y&&(s==null?void 0:s.role)==="developer"&&e.createElement("button",{className:"text-button",disabled:i,onClick:()=>m(async()=>{const a=await d(),{error:u}=await a.rpc("restore_team_inspections",{p_ids:[t.id]});if(u)throw u;await k(),_()})},"Restore")))}))),!g.length&&e.createElement("div",{className:"empty"},e.createElement(q,{size:30}),e.createElement("p",null,y?"No archived records to recover.":"No shared inspections yet. Open an inspection result and select Share with staff.")))):e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.auth.signInWithPassword({email:C,password:j});if(a)throw a;D("")})}},e.createElement("label",{className:"field"},"Work email",e.createElement("input",{type:"email",autoComplete:"username",value:C,onChange:t=>J(t.target.value),required:!0})),e.createElement("label",{className:"field"},"Password",e.createElement("input",{type:"password",autoComplete:"current-password",value:j,onChange:t=>D(t.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:i},i?e.createElement(le,{className:"spin",size:17}):e.createElement(pe,{size:17})," Sign in"),e.createElement("button",{type:"button",className:"text-button",disabled:!C||i,onClick:()=>m(async()=>{const t=await d(),{error:r}=await t.auth.resetPasswordForEmail(C,{redirectTo:location.origin+location.pathname});if(r)throw r;w("Password reset requested. Check your email.")})},"Reset password"),e.createElement("p",{className:"caption"},"Accounts must be invited and approved by your workspace developer. Signing up alone does not grant staff access."))),c&&l&&e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,"Shared inspection · ",l.id.slice(0,8)),e.createElement("p",null,"Saved snapshot from ",S[l.owner_id]||"a colleague",". This page does not run a new prediction.")),e.createElement("div",{className:"button-row"},P&&!l.archived_at&&e.createElement("button",{className:"secondary",onClick:()=>P(l)},"Open inspection & assistant"),e.createElement("button",{className:"text-button",onClick:()=>{v.current++,b(null)}},"Close"))),e.createElement("div",{className:"shared-images"},X.map((t,r)=>e.createElement("img",{key:t,src:t,alt:r?"Saved anomaly heatmap":"Saved inspected product"}))),e.createElement("div",{className:"observation"},e.createElement("strong",null,"SAVED MEASUREMENTS"),e.createElement("span",null,l.payload.verdict," · score ",Number(l.payload.score).toFixed(5)," · threshold ",Number(l.payload.threshold).toFixed(5))),e.createElement("h3",{className:"section-gap"},"Recorded evidence"),(K=l.conversation)!=null&&K.length?l.conversation.map((t,r)=>e.createElement("p",{className:"cloud-message",key:r},e.createElement("strong",null,t.role==="user"?"Inspector":"Evidence Assistant",": "),t.question||t.answer)):e.createElement("p",{className:"caption"},"No conversation was included when this inspection was shared."),!l.archived_at&&e.createElement(oe,{key:l.id+String(R.length),current:R.map(t=>Y(t,S)).filter(Boolean).at(-1),disabled:i,onSave:async t=>{const r=await d(),{error:a}=await r.from("staff_notes").insert({inspection_id:l.id,author_id:c.id,body:ie(t.status,t.decision,t.note)});if(a)throw a;await L(l),_()}}),e.createElement("h3",{className:"section-gap"},"Staff review notes"),R.filter(t=>!Y(t,S)).map(t=>e.createElement("div",{className:"cloud-message",key:t.id},e.createElement("strong",null,S[t.author_id]||"Staff member"),e.createElement("p",null,t.body),e.createElement("small",null,new Date(t.created_at).toLocaleString()))),!l.archived_at&&e.createElement("form",{className:"question-form",onSubmit:t=>{t.preventDefault(),m(async()=>{const r=await d(),{error:a}=await r.from("staff_notes").insert({inspection_id:l.id,author_id:c.id,body:A.trim()});if(a)throw a;H(""),await L(l),_()})}},e.createElement("input",{"aria-label":"Staff review note",maxLength:2e3,placeholder:"Add a review note for your colleagues…",value:A,onChange:t=>H(t.target.value)}),e.createElement("button",{className:"primary",disabled:i||!A.trim()},e.createElement(ye,{size:16})," Add note")))):e.createElement("section",{className:"card cloud-setup"},e.createElement("div",{className:"setup-icon"},e.createElement(q,{size:32})),e.createElement("span",{className:"eyebrow"},"TEAM WORKSPACE"),e.createElement("h2",null,"One shared view of inspection."),e.createElement("p",null,"The staff workspace is ready to connect to your own Supabase project. No cloud project or account has been created for you."),e.createElement("div",{className:"setup-grid"},[["01","Create a free project","Use your Supabase account and select an eligible Free plan."],["02","Set up staff access","Run the supplied schema, add your developer account and invite colleagues."],["03","Connect this dashboard","Add the project URL and publishable key to config.js, then reload."]].map(([t,r,a])=>e.createElement("div",{key:t},e.createElement("b",null,t),e.createElement("h3",null,r),e.createElement("p",null,a)))),e.createElement("a",{className:"primary",href:"https://supabase.com/dashboard",target:"_blank",rel:"noreferrer"},"Open Supabase ",e.createElement(ue,{size:16})),e.createElement("p",{className:"caption"},"Setup files: deployment/SUPABASE_SETUP.md and deployment/supabase.sql. Never place a service-role key in the browser. Local inspection works without cloud setup."))}export{we as default};
|
frontend/dist/assets/index-BhrFTP_4.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/dist/assets/index-CXC_txue.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/dist/assets/index-DyHDnvjh.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/dist/index.html
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><meta name="theme-color" content="#132e32"/><meta name="description" content="Local visual anomaly inspection with traceable evidence."/><title>DefectRAG · Inspection intelligence</title><link rel="icon" type="image/svg+xml" href="./logo.svg"><script src="./config.js"></script> <script type="module" crossorigin src="./assets/index-
|
| 2 |
<link rel="stylesheet" crossorigin href="./assets/index-Bn4HF2vD.css">
|
| 3 |
</head><body><div id="root"></div></body></html>
|
|
|
|
| 1 |
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><meta name="theme-color" content="#132e32"/><meta name="description" content="Local visual anomaly inspection with traceable evidence."/><title>DefectRAG · Inspection intelligence</title><link rel="icon" type="image/svg+xml" href="./logo.svg"><script src="./config.js"></script> <script type="module" crossorigin src="./assets/index-DyHDnvjh.js"></script>
|
| 2 |
<link rel="stylesheet" crossorigin href="./assets/index-Bn4HF2vD.css">
|
| 3 |
</head><body><div id="root"></div></body></html>
|