Spaces:
Sleeping
Sleeping
Download eddison-app.html from EddisonIntelligence/intelligence: direct link, hf CLI and curl.
- Browser
- Download file 82.9 kB
-
https://huggingface.co/spaces/EddisonIntelligence/intelligence/resolve/main/eddison-app.html
- Command line
-
hf download hf://spaces/EddisonIntelligence/intelligence/eddison-app.html
-
curl -L -o eddison-app.html https://huggingface.co/spaces/EddisonIntelligence/intelligence/resolve/main/eddison-app.html
82.9 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Eddison Intelligence β Patent Assistant</title>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Mono:wght@300;400;500&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,300&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mammoth/1.6.0/mammoth.browser.min.js"></script>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #07090F;
--surface: #0E1118;
--surface2: #141821;
--border: rgba(255,255,255,0.07);
--border-active: rgba(200,241,53,0.4);
--accent: #C8F135;
--accent-dim: rgba(200,241,53,0.15);
--red: #FF4757;
--blue: #3B82F6;
--text: #EDF0FF;
--muted: rgba(237,240,255,0.45);
--mono: 'DM Mono', monospace;
--sans: 'DM Sans', sans-serif;
--display: 'Bebas Neue', sans-serif;
}
html, body {
height: 100%;
background: var(--bg);
color: var(--text);
font-family: var(--sans);
overflow-x: hidden;
}
/* βββ NOISE OVERLAY βββ */
body::after {
content: '';
position: fixed; inset: 0;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
pointer-events: none; z-index: 9999; opacity: 0.4;
}
/* βββ LAYOUT βββ */
.app {
display: grid;
grid-template-rows: auto 1fr;
min-height: 100vh;
}
/* βββ HEADER βββ */
header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 40px;
border-bottom: 1px solid var(--border);
background: rgba(7,9,15,0.9);
backdrop-filter: blur(12px);
position: sticky; top: 0; z-index: 100;
}
.logo {
font-family: var(--display);
font-size: 22px;
letter-spacing: 0.15em;
color: var(--text);
}
.logo span { color: var(--accent); }
.steps-nav {
display: flex;
align-items: center;
gap: 4px;
}
.step-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 7px 16px;
border-radius: 8px;
border: none;
background: transparent;
cursor: pointer;
font-family: var(--sans);
font-size: 12px;
font-weight: 500;
letter-spacing: 0.04em;
color: var(--muted);
transition: all 0.2s;
position: relative;
}
.step-btn .num {
width: 20px; height: 20px;
border-radius: 50%;
background: var(--surface2);
border: 1px solid var(--border);
display: flex; align-items: center; justify-content: center;
font-family: var(--mono);
font-size: 10px;
transition: all 0.2s;
}
.step-btn.active { color: var(--accent); }
.step-btn.active .num {
background: var(--accent-dim);
border-color: var(--accent);
color: var(--accent);
}
.step-btn.done { color: var(--muted); }
.step-btn.done .num {
background: rgba(200,241,53,0.08);
border-color: rgba(200,241,53,0.3);
color: rgba(200,241,53,0.6);
}
.step-divider {
width: 28px; height: 1px;
background: var(--border);
}
/* βββ MAIN CONTENT βββ */
main {
display: grid;
place-items: start center;
padding: 48px 24px 80px;
}
.panel {
width: 100%;
max-width: 820px;
animation: fadeUp 0.4s ease both;
}
@keyframes fadeUp {
from { opacity: 0; transform: translateY(16px); }
to { opacity: 1; transform: translateY(0); }
}
.panel-header {
margin-bottom: 32px;
}
.panel-tag {
font-size: 10px;
letter-spacing: 0.2em;
text-transform: uppercase;
color: var(--accent);
font-weight: 500;
margin-bottom: 10px;
}
.panel-title {
font-family: var(--display);
font-size: 48px;
letter-spacing: 0.02em;
line-height: 0.95;
color: var(--text);
}
.panel-sub {
font-size: 14px;
color: var(--muted);
margin-top: 10px;
font-weight: 300;
}
/* βββ CARDS / BOXES βββ */
.card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 28px;
margin-bottom: 16px;
transition: border-color 0.2s;
}
.card:focus-within { border-color: var(--border-active); }
.card-label {
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
color: var(--muted);
margin-bottom: 14px;
font-weight: 500;
}
textarea {
width: 100%;
background: transparent;
border: none;
outline: none;
font-family: var(--sans);
font-size: 14px;
color: var(--text);
resize: none;
line-height: 1.6;
font-weight: 300;
}
textarea::placeholder { color: rgba(237,240,255,0.2); }
/* βββ FILE UPLOAD βββ */
.upload-zone {
border: 1px dashed rgba(255,255,255,0.12);
border-radius: 10px;
padding: 24px;
text-align: center;
cursor: pointer;
transition: all 0.2s;
background: rgba(255,255,255,0.02);
}
.upload-zone:hover, .upload-zone.dragover {
border-color: rgba(200,241,53,0.4);
background: var(--accent-dim);
}
.upload-icon { font-size: 28px; margin-bottom: 8px; }
.upload-text { font-size: 13px; color: var(--muted); font-weight: 300; }
.upload-text strong { color: var(--accent); font-weight: 500; }
#fileInput { display: none; }
.file-attached {
display: flex; align-items: center; gap: 10px;
font-size: 13px; color: var(--accent);
background: var(--accent-dim);
border-radius: 8px; padding: 10px 14px;
margin-top: 12px;
}
/* βββ OR DIVIDER βββ */
.or-row {
display: flex; align-items: center; gap: 16px;
margin: 16px 0; color: var(--muted); font-size: 12px;
}
.or-row::before, .or-row::after {
content: ''; flex: 1; height: 1px; background: var(--border);
}
/* βββ TAGS (keywords / kind codes) βββ */
.tags-area {
display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.tag {
display: flex; align-items: center; gap: 6px;
background: var(--surface2);
border: 1px solid var(--border);
border-radius: 6px;
padding: 5px 10px;
font-size: 12px;
font-family: var(--mono);
color: var(--text);
cursor: pointer;
transition: all 0.15s;
user-select: none;
}
.tag:hover { border-color: rgba(200,241,53,0.3); }
.tag.selected {
background: var(--accent-dim);
border-color: var(--accent);
color: var(--accent);
}
.tag.kind-code {
background: rgba(59,130,246,0.1);
border-color: rgba(59,130,246,0.3);
color: #93C5FD;
}
.tag.kind-code.selected {
background: rgba(59,130,246,0.2);
border-color: #3B82F6;
color: #60A5FA;
}
.tag.cpc-code {
background: rgba(168,85,247,0.1);
border-color: rgba(168,85,247,0.3);
color: #C084FC;
}
.tag.cpc-code.selected {
background: rgba(168,85,247,0.2);
border-color: #A855F7;
color: #D8B4FE;
}
.tag-remove {
width: 14px; height: 14px;
display: flex; align-items: center; justify-content: center;
opacity: 0.5; transition: opacity 0.15s;
font-size: 14px; line-height: 1;
}
.tag-remove:hover { opacity: 1; }
.tag-input-row {
display: flex; gap: 8px; margin-top: 12px;
}
.tag-input {
flex: 1;
background: var(--surface2);
border: 1px solid var(--border);
border-radius: 8px;
padding: 8px 14px;
font-family: var(--mono);
font-size: 12px;
color: var(--text);
outline: none;
transition: border-color 0.2s;
}
.tag-input:focus { border-color: var(--border-active); }
.tag-input::placeholder { color: rgba(237,240,255,0.2); }
/* βββ BUTTONS βββ */
.btn {
display: inline-flex; align-items: center; gap: 8px;
padding: 11px 24px;
border-radius: 9px;
border: none;
font-family: var(--sans);
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
letter-spacing: 0.02em;
}
.btn-primary {
background: var(--accent);
color: #07090F;
}
.btn-primary:hover { background: #d4f54a; transform: translateY(-1px); box-shadow: 0 4px 20px rgba(200,241,53,0.3); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary {
background: var(--surface2);
border: 1px solid var(--border);
color: var(--text);
}
.btn-secondary:hover { border-color: rgba(255,255,255,0.2); }
.btn-ghost {
background: transparent;
border: 1px solid var(--border);
color: var(--muted);
padding: 8px 14px;
font-size: 12px;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }
.btn-row {
display: flex; align-items: center; gap: 12px;
margin-top: 24px;
}
/* βββ LOADING SPINNER βββ */
.spinner {
width: 16px; height: 16px;
border: 2px solid rgba(7,9,15,0.3);
border-top-color: #07090F;
border-radius: 50%;
animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-accent {
border-color: rgba(200,241,53,0.2);
border-top-color: var(--accent);
}
/* βββ PRIOR ART RESULTS βββ */
.prior-art-list { display: flex; flex-direction: column; gap: 12px; }
.prior-art-item {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
padding: 20px 22px;
cursor: pointer;
transition: all 0.2s;
position: relative;
}
.prior-art-item:hover { border-color: rgba(255,255,255,0.15); }
.prior-art-item.approved {
border-color: var(--accent);
background: rgba(200,241,53,0.04);
}
.prior-art-item.rejected {
border-color: rgba(255,71,87,0.3);
background: rgba(255,71,87,0.03);
opacity: 0.5;
}
.pa-header {
display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
margin-bottom: 8px;
}
.pa-title { font-size: 14px; font-weight: 500; color: var(--text); line-height: 1.3; }
.pa-num {
font-family: var(--mono);
font-size: 11px;
color: var(--accent);
background: var(--accent-dim);
padding: 3px 8px;
border-radius: 4px;
white-space: nowrap;
flex-shrink: 0;
text-decoration: none;
transition: filter 0.15s, text-decoration 0.15s;
}
a.pa-num:hover {
text-decoration: underline;
filter: brightness(1.2);
}
.pa-relevance {
display: inline-block;
font-family: var(--mono);
font-size: 11px;
font-weight: 600;
padding: 2px 8px;
border-radius: 4px;
margin-bottom: 6px;
}
.pa-relevance.high { color: #4ade80; background: rgba(74,222,128,0.12); }
.pa-relevance.medium { color: #facc15; background: rgba(250,204,21,0.12); }
.pa-relevance.low { color: var(--muted); background: rgba(237,240,255,0.06); }
.pa-meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; font-weight: 300; }
.pa-abstract { font-size: 13px; color: rgba(237,240,255,0.6); line-height: 1.55; font-weight: 300; }
.pa-actions {
display: flex; gap: 8px; margin-top: 14px;
}
.approve-btn {
padding: 6px 14px; font-size: 12px; border-radius: 6px; border: none; cursor: pointer;
background: var(--accent-dim); border: 1px solid rgba(200,241,53,0.3);
color: var(--accent); font-family: var(--sans); font-weight: 500;
transition: all 0.15s;
}
.approve-btn:hover { background: rgba(200,241,53,0.25); }
.approve-btn.active { background: var(--accent); color: #07090F; }
.reject-btn {
padding: 6px 14px; font-size: 12px; border-radius: 6px; border: 1px solid rgba(255,71,87,0.2);
color: rgba(255,71,87,0.6); background: transparent; cursor: pointer; font-family: var(--sans);
transition: all 0.15s;
}
.reject-btn:hover { border-color: var(--red); color: var(--red); }
.reject-btn.active { background: rgba(255,71,87,0.1); border-color: var(--red); color: var(--red); }
.approved-count {
font-size: 12px; color: var(--muted); margin-top: 6px;
}
.approved-count strong { color: var(--accent); }
/* βββ CLAIM DRAFT βββ */
.claim-output {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
overflow: hidden;
}
.claim-toolbar {
display: flex; align-items: center; justify-content: space-between;
padding: 14px 20px;
border-bottom: 1px solid var(--border);
background: var(--surface2);
}
.claim-toolbar-left {
font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
color: var(--muted); font-weight: 500;
}
.claim-content {
padding: 28px;
font-size: 14px; line-height: 1.8;
color: rgba(237,240,255,0.85);
font-weight: 300;
white-space: pre-wrap;
font-family: var(--sans);
min-height: 300px;
}
.claim-content[contenteditable="true"] { outline: none; }
.claim-content[contenteditable="true"]:focus {
background: rgba(255,255,255,0.01);
}
.claim-num {
font-family: var(--mono);
font-size: 12px;
color: var(--accent);
font-weight: 400;
}
/* βββ STATUS BADGE βββ */
.status-badge {
display: inline-flex; align-items: center; gap: 6px;
font-size: 11px; font-weight: 500;
padding: 4px 10px; border-radius: 20px;
}
.status-badge.generating {
background: rgba(59,130,246,0.15);
color: #93C5FD;
border: 1px solid rgba(59,130,246,0.3);
}
.status-badge.done {
background: var(--accent-dim);
color: var(--accent);
border: 1px solid rgba(200,241,53,0.3);
}
/* βββ SECTION DIVIDERS βββ */
.section-gap { margin-top: 24px; }
/* βββ EMPTY STATE βββ */
.empty-state {
text-align: center; padding: 60px 40px;
color: var(--muted); font-size: 14px; font-weight: 300;
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
/* βββ ERROR CARD βββ */
.error-card {
background: rgba(255,71,87,0.06);
border: 1px solid rgba(255,71,87,0.3);
border-radius: 12px;
padding: 24px 28px;
margin-top: 16px;
}
.error-card-header {
display: flex; align-items: center; gap: 10px;
font-size: 14px; font-weight: 500; color: var(--red);
margin-bottom: 10px;
}
.error-card-detail {
font-size: 13px; color: rgba(255,71,87,0.7);
font-weight: 300; line-height: 1.5;
margin-bottom: 16px;
font-family: var(--mono);
word-break: break-word;
}
.error-card .btn-ghost {
border-color: rgba(255,71,87,0.3);
color: var(--red);
}
.error-card .btn-ghost:hover {
border-color: var(--red);
}
/* βββ KEYWORD HIGHLIGHT βββ */
.pa-highlight {
background: var(--accent-dim);
border-radius: 2px;
padding: 0 2px;
}
/* βββ COPY BUTTON FEEDBACK βββ */
.copied { color: var(--accent) !important; }
/* βββ CLAIM ANALYSIS βββ */
.analysis-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
margin-top: 16px;
}
@media (max-width: 768px) {
.analysis-grid { grid-template-columns: 1fr; }
}
.analysis-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 24px;
transition: border-color 0.2s;
}
.analysis-card:hover { border-color: rgba(255,255,255,0.15); }
.analysis-card-icon { font-size: 24px; margin-bottom: 12px; }
.analysis-card-title {
font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
color: var(--muted); font-weight: 500; margin-bottom: 10px;
}
.analysis-rating {
display: inline-flex; align-items: center;
font-size: 12px; font-weight: 600; font-family: var(--mono);
padding: 4px 12px; border-radius: 20px; margin-bottom: 12px;
}
.analysis-rating.green {
background: rgba(74,222,128,0.12); color: #4ade80; border: 1px solid rgba(74,222,128,0.3);
}
.analysis-rating.yellow {
background: rgba(250,204,21,0.12); color: #facc15; border: 1px solid rgba(250,204,21,0.3);
}
.analysis-rating.red {
background: rgba(255,71,87,0.12); color: var(--red); border: 1px solid rgba(255,71,87,0.3);
}
.analysis-summary {
font-size: 13px; color: rgba(237,240,255,0.85); line-height: 1.5;
font-weight: 400; margin-bottom: 14px;
}
.analysis-bullets { list-style: none; padding: 0; margin: 0; }
.analysis-bullets li {
font-size: 12px; color: rgba(237,240,255,0.6); line-height: 1.55;
font-weight: 300; padding: 4px 0 4px 16px; position: relative;
}
.analysis-bullets li::before {
content: '\2014'; position: absolute; left: 0; color: var(--muted);
}
.analysis-improve-btn {
margin-top: 16px; padding: 6px 14px; font-size: 11px; font-weight: 500;
font-family: var(--sans); border-radius: 6px; cursor: pointer;
background: transparent; color: var(--accent);
border: 1px solid rgba(200,241,53,0.3);
transition: all 0.15s;
}
.analysis-improve-btn:hover {
background: var(--accent-dim); border-color: var(--accent);
}
/* βββ COLLAPSIBLE SECTIONS βββ */
.collapsible-header {
display: flex; align-items: center; justify-content: space-between;
cursor: pointer; user-select: none;
}
.collapsible-header:hover { color: var(--text); }
.collapse-icon { font-size: 10px; color: var(--muted); transition: transform 0.2s; }
/* βββ DECOMPOSITION GRID βββ */
.decomp-grid {
display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px;
}
@media (max-width: 600px) { .decomp-grid { grid-template-columns: 1fr; } }
.decomp-label {
font-size: 11px; font-weight: 500; color: var(--accent);
letter-spacing: 0.05em; margin-bottom: 8px;
}
.decomp-list { list-style: none; padding: 0; margin: 0; }
.decomp-list li {
font-size: 13px; color: rgba(237,240,255,0.75); line-height: 1.55;
padding: 3px 0 3px 14px; position: relative; font-weight: 300;
}
.decomp-list li::before { content: '\203A'; position: absolute; left: 0; color: var(--accent); }
/* βββ SYNONYM EXPANSION βββ */
.synonym-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.synonym-row:last-child { border-bottom: none; }
.synonym-feature { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 8px; }
.synonym-tags { display: flex; flex-wrap: wrap; gap: 6px; }
/* βββ BOOLEAN QUERIES βββ */
.boolean-query-item {
background: var(--surface2); border: 1px solid var(--border);
border-radius: 10px; padding: 16px; margin-bottom: 10px;
}
.boolean-query-label {
font-size: 11px; font-weight: 500; color: var(--accent);
letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 8px;
}
.boolean-query-text {
font-family: var(--mono); font-size: 12px; color: rgba(237,240,255,0.7);
line-height: 1.6; background: rgba(0,0,0,0.2); border-radius: 6px;
padding: 10px 12px; margin-bottom: 10px; word-break: break-word;
}
.boolean-query-actions { display: flex; gap: 8px; }
/* βββ SEED PATENT βββ */
.seed-patent-summary {
background: var(--surface2); border: 1px solid var(--border);
border-radius: 10px; padding: 16px;
}
/* βββ SATURATION BAR βββ */
.saturation-bar {
background: var(--surface); border: 1px solid var(--border);
border-radius: 10px; padding: 16px; margin-bottom: 16px;
}
.saturation-header {
display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.saturation-pct { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--accent); }
.saturation-track {
width: 100%; height: 6px; background: var(--surface2);
border-radius: 3px; overflow: hidden; margin-bottom: 8px;
}
.saturation-fill {
height: 100%; background: var(--accent); border-radius: 3px;
transition: width 0.4s ease; width: 0%;
}
.saturation-hint { font-size: 12px; color: var(--muted); font-weight: 300; }
/* βββ EVALUATION TABLE βββ */
.pa-evaluation table { font-family: var(--sans); }
.pa-evaluation th {
font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 500;
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="logo"><span>EDDISON</span> INTELLIGENCE</div>
<nav class="steps-nav">
<button class="step-btn active" id="nav1" onclick="goToStep(1)">
<span class="num">1</span> Idea & Codes
</button>
<div class="step-divider"></div>
<button class="step-btn" id="nav2" onclick="goToStep(2)">
<span class="num">2</span> Prior Art Search
</button>
<div class="step-divider"></div>
<button class="step-btn" id="nav3" onclick="goToStep(3)">
<span class="num">3</span> Draft Claim
</button>
</nav>
<button class="btn btn-ghost" onclick="if(confirm('Clear all progress and start over?')) clearState()" style="font-size:11px;opacity:0.6">βΊ Start Over</button>
</header>
<main>
<!-- ββββββββββββββ STEP 1 ββββββββββββββ -->
<div class="panel" id="step1">
<div class="panel-header">
<div class="panel-tag">Step 01 / 03</div>
<div class="panel-title">Describe Your<br>Invention</div>
<div class="panel-sub">Type a description or upload notes β we'll extract keywords and suggest USPTO Kind Codes.</div>
</div>
<div class="card">
<div class="card-label">Describe your invention</div>
<textarea id="ideaText" rows="5" placeholder="e.g. A machine learning system that automatically classifies patent applications and routes them to the correct examiner based on technical field..."></textarea>
</div>
<div class="or-row">or</div>
<div class="card" style="padding:20px">
<div class="card-label">Upload notes or documents</div>
<div class="upload-zone" id="uploadZone" onclick="document.getElementById('fileInput').click()">
<div class="upload-icon">π</div>
<div class="upload-text"><strong>Click to upload</strong> or drag & drop a .txt, .pdf, or .docx file</div>
</div>
<input type="file" id="fileInput" accept=".txt,.pdf,.docx" onchange="handleFile(event)">
<div id="fileAttached" style="display:none"></div>
</div>
<div class="btn-row">
<button class="btn btn-primary" id="analyzeBtn" onclick="analyzeIdea()">
β¦ Analyze & Extract Keywords
</button>
</div>
<div id="extractedSection" style="display:none" class="section-gap">
<div class="card">
<div class="card-label">Extracted Keywords β click to toggle selection</div>
<div class="tags-area" id="keywordTags"></div>
<div class="tag-input-row">
<input class="tag-input" id="kwInput" placeholder="+ Add keyword..." onkeydown="addTagOnEnter(event,'keyword')">
<button class="btn btn-ghost" onclick="addTag('keyword')">Add</button>
</div>
</div>
<div class="card section-gap">
<div class="card-label">Suggested CPC Codes
<span style="font-size:10px;color:var(--muted);margin-left:8px;text-transform:none;letter-spacing:0">
(Cooperative Patent Classification β e.g. G06F40/30)
</span>
</div>
<div class="tags-area" id="cpcCodeTags"></div>
<div class="tag-input-row">
<input class="tag-input" id="cpcInput" placeholder="+ Add CPC code..." onkeydown="addTagOnEnter(event,'cpc')">
<button class="btn btn-ghost" onclick="addTag('cpc')">Add</button>
</div>
</div>
<div class="card section-gap">
<div class="card-label">Suggested USPTO Kind Codes
<span style="font-size:10px;color:var(--muted);margin-left:8px;text-transform:none;letter-spacing:0">
(e.g. A1=Published App, B1=Granted Patent, B2=Reissue...)
</span>
</div>
<div class="tags-area" id="kindCodeTags"></div>
<div class="tag-input-row">
<input class="tag-input" id="kcInput" placeholder="+ Add kind code..." onkeydown="addTagOnEnter(event,'kindcode')">
<button class="btn btn-ghost" onclick="addTag('kindcode')">Add</button>
</div>
</div>
<!-- Invention Decomposition (collapsible) -->
<div class="card section-gap" id="decompositionCard" style="display:none">
<div class="card-label collapsible-header" onclick="toggleSection('decomposition')">
<span>Invention Decomposition</span>
<span class="collapse-icon" id="decomposition-icon">▼</span>
</div>
<div class="collapsible-body" id="decomposition-body">
<div class="decomp-grid">
<div class="decomp-col">
<div class="decomp-label">Core Technical Features</div>
<ul class="decomp-list" id="coreFeatures"></ul>
</div>
<div class="decomp-col">
<div class="decomp-label">Supporting Features</div>
<ul class="decomp-list" id="supportingFeatures"></ul>
</div>
<div class="decomp-col">
<div class="decomp-label">Claimed Improvements</div>
<ul class="decomp-list" id="claimedImprovements"></ul>
</div>
<div class="decomp-col">
<div class="decomp-label">HW/SW Components</div>
<ul class="decomp-list" id="hwswComponents"></ul>
</div>
</div>
</div>
</div>
<!-- Synonym Expansion (collapsible) -->
<div class="card section-gap" id="synonymCard" style="display:none">
<div class="card-label collapsible-header" onclick="toggleSection('synonym')">
<span>Synonym Expansion</span>
<span class="collapse-icon" id="synonym-icon">▼</span>
</div>
<div class="collapsible-body" id="synonym-body">
<div id="synonymGrid"></div>
</div>
</div>
<div class="btn-row">
<button class="btn btn-primary" onclick="goToStep(2)">Continue to Prior Art Search β</button>
</div>
</div>
</div>
<!-- ββββββββββββββ STEP 2 ββββββββββββββ -->
<div class="panel" id="step2" style="display:none">
<div class="panel-header">
<div class="panel-tag">Step 02 / 03</div>
<div class="panel-title">Prior Art<br>Search</div>
<div class="panel-sub">Review your search parameters, then approve or reject results to inform your claim.</div>
</div>
<div class="card">
<div class="card-label">Search Keywords</div>
<div class="tags-area" id="searchKeywords"></div>
<div class="tag-input-row">
<input class="tag-input" id="skInput" placeholder="+ Add keyword..." onkeydown="addSearchTagOnEnter(event,'kw')">
<button class="btn btn-ghost" onclick="addSearchTag('kw')">Add</button>
</div>
</div>
<div class="card">
<div class="card-label">CPC Codes to Include</div>
<div class="tags-area" id="searchCpcCodes"></div>
</div>
<div class="card">
<div class="card-label">Kind Codes to Include</div>
<div class="tags-area" id="searchKindCodes"></div>
</div>
<div class="card">
<div class="card-label">Sort by</div>
<select id="sortSelect" style="background:var(--surface2);border:1px solid var(--border);border-radius:8px;padding:8px 14px;font-family:var(--sans);font-size:13px;color:var(--text);">
<option value="relevance">Most relevant</option>
<option value="date">Newest first</option>
<option value="citations">Most cited first</option>
</select>
</div>
<!-- Boolean Search Strings (collapsible) -->
<div class="card section-gap" id="booleanQueriesCard" style="display:none">
<div class="card-label collapsible-header" onclick="toggleSection('boolean')">
<span>Boolean Search Strings</span>
<span class="collapse-icon" id="boolean-icon">▼</span>
</div>
<div class="collapsible-body" id="boolean-body">
<div class="panel-sub" style="margin-bottom:16px;font-size:12px">
Reference queries for USPTO Full-Text search. Click "Run in App" to search with extracted keywords.
</div>
<div id="booleanQueryList"></div>
</div>
</div>
<!-- Seed Patent Strategy (collapsible) -->
<div class="card section-gap" id="seedPatentCard" style="display:none">
<div class="card-label collapsible-header" onclick="toggleSection('seed')">
<span>Seed Patent Strategy</span>
<span class="collapse-icon" id="seed-icon">▼</span>
</div>
<div class="collapsible-body" id="seed-body">
<div class="panel-sub" style="margin-bottom:12px;font-size:12px">
Mark a result as your "seed patent" to mine its citations and CPC codes for expanded search.
</div>
<div id="seedPatentInfo" style="display:none"></div>
<div id="seedPatentEmpty" style="font-size:12px;color:var(--muted)">
No seed patent selected. After searching, click "Use as Seed" on a result to begin citation mining.
</div>
</div>
</div>
<div class="btn-row">
<button class="btn btn-primary" id="searchBtn" onclick="runPriorArtSearch()">
β Search Prior Art
</button>
<button class="btn btn-secondary" onclick="goToStep(1)">β Back</button>
</div>
<div id="priorArtResults" class="section-gap" style="display:none">
<!-- Saturation Tracker -->
<div class="saturation-bar" id="saturationBar" style="display:none">
<div class="saturation-header">
<span class="card-label" style="margin:0">Search Saturation</span>
<span class="saturation-pct" id="saturationPct">0%</span>
</div>
<div class="saturation-track">
<div class="saturation-fill" id="saturationFill"></div>
</div>
<div class="saturation-hint" id="saturationHint"></div>
</div>
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:16px">
<div style="font-family:var(--display);font-size:22px;letter-spacing:0.05em">Results</div>
<div class="approved-count" id="approvedCount"></div>
</div>
<div class="prior-art-list" id="paList"></div>
<div id="loadMoreWrap" style="margin-top:16px;display:none">
<button class="btn btn-secondary" id="loadMoreBtn" onclick="loadMorePriorArt()">Load more</button>
</div>
<div class="btn-row" style="margin-top:24px">
<button class="btn btn-primary" id="proceedBtn" onclick="goToStep(3)">
Draft Claim from Approved Art β
</button>
<button class="btn btn-secondary" onclick="runPriorArtSearch()">Re-search</button>
</div>
</div>
</div>
<!-- ββββββββββββββ STEP 3 ββββββββββββββ -->
<div class="panel" id="step3" style="display:none">
<div class="panel-header">
<div class="panel-tag">Step 03 / 03</div>
<div class="panel-title">First Claim<br>Draft</div>
<div class="panel-sub">AI-drafted independent and dependent claims based on your invention and approved prior art. Edit inline.</div>
</div>
<div id="claimLoading" class="card" style="text-align:center;padding:60px">
<div style="display:flex;justify-content:center;margin-bottom:16px">
<div class="spinner spinner-accent" style="width:28px;height:28px;border-width:3px"></div>
</div>
<div style="color:var(--muted);font-size:13px">Drafting patent claims...</div>
</div>
<div id="claimOutputWrap" style="display:none">
<div class="claim-output">
<div class="claim-toolbar">
<div class="claim-toolbar-left">Patent Claims Draft</div>
<div style="display:flex;gap:8px;align-items:center">
<span class="status-badge done" id="claimStatus">β Draft Ready</span>
<button class="btn btn-ghost" onclick="copyClaim(event)">Copy</button>
</div>
</div>
<div class="claim-content" id="claimContent" contenteditable="true"></div>
</div>
<!-- Claim Analysis -->
<div id="claimAnalysisWrap" style="display:none">
<div style="margin-top:28px;margin-bottom:8px;display:flex;align-items:center;justify-content:space-between">
<div style="font-family:var(--display);font-size:22px;letter-spacing:0.05em">Claim Analysis</div>
<span class="status-badge done" id="analysisStatus" style="display:none">✓ Analysis Complete</span>
</div>
<div id="analysisGrid" class="analysis-grid"></div>
</div>
<div id="claimAnalysisLoading" style="display:none;text-align:center;padding:40px;margin-top:20px" class="card">
<div style="display:flex;justify-content:center;margin-bottom:16px">
<div class="spinner spinner-accent" style="width:28px;height:28px;border-width:3px"></div>
</div>
<div style="color:var(--muted);font-size:13px">Analyzing claim specificity, protection scope, and infringement potential...</div>
</div>
<div id="claimAnalysisError" style="display:none"></div>
<div style="margin-top:20px">
<button class="btn btn-secondary" id="analyzeClaimBtn" onclick="analyzeClaimDraft()">⚖ Analyze Claims</button>
</div>
<div class="btn-row" style="margin-top:12px">
<button class="btn btn-primary" onclick="copyClaim(event)">Copy to Clipboard</button>
<button class="btn btn-secondary" onclick="regenerateClaim()">Regenerate</button>
<button class="btn btn-ghost" onclick="goToStep(2)">← Back to Prior Art</button>
</div>
</div>
</div>
</main>
</div>
<script>
// βββ CONFIG ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const API_BASE = window.location.origin;
function renderError(container, message, detail, retryFn) {
container.innerHTML = `
<div class="error-card">
<div class="error-card-header">β ${message}</div>
${detail ? `<div class="error-card-detail">${detail}</div>` : ''}
${retryFn ? `<button class="btn btn-ghost" id="_retryBtn">Try Again</button>` : ''}
</div>`;
if (retryFn) {
container.querySelector('#_retryBtn').onclick = retryFn;
}
container.style.display = 'block';
}
// βββ STATE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const STORAGE_KEY = 'eddison_state';
const state = {
ideaText: '',
keywords: [],
selectedKeywords: [],
kindCodes: [],
selectedKindCodes: [],
cpcCodes: [],
selectedCpcCodes: [],
priorArt: [],
approvedArt: [],
claimDraft: '',
claimAnalysis: null,
currentStep: 1,
searchAfter: null,
searchTotal: 0,
searchKeywords: [],
// USPTO 7-Step Methodology fields
decomposition: null,
synonyms: null,
booleanQueries: null,
seedPatent: null,
evaluations: {},
saturation: { searchesRun: 0, queriesExhausted: [] }
};
function saveState() {
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(state)); } catch(e) {}
}
function loadState() {
try {
const saved = localStorage.getItem(STORAGE_KEY);
if (saved) Object.assign(state, JSON.parse(saved));
} catch(e) {}
}
function clearState() {
localStorage.removeItem(STORAGE_KEY);
location.reload();
}
// βββ NAVIGATION ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function goToStep(n, opts = {}) {
[1,2,3].forEach(i => {
document.getElementById(`step${i}`).style.display = 'none';
document.getElementById(`nav${i}`).className = 'step-btn';
});
document.getElementById(`step${n}`).style.display = 'block';
document.getElementById(`nav${n}`).className = 'step-btn active';
for(let i = 1; i < n; i++) document.getElementById(`nav${i}`).className = 'step-btn done';
window.scrollTo({ top: 0, behavior: 'smooth' });
state.currentStep = n;
saveState();
if (n === 2) populateSearchPanel();
if (n === 3 && !opts.skipGenerate) generateClaim();
}
// βββ STEP 1: FILE HANDLING βββββββββββββββββββββββββββββββββββββββββββββββββββ
const uploadZone = document.getElementById('uploadZone');
uploadZone.addEventListener('dragover', e => { e.preventDefault(); uploadZone.classList.add('dragover'); });
uploadZone.addEventListener('dragleave', () => uploadZone.classList.remove('dragover'));
uploadZone.addEventListener('drop', e => {
e.preventDefault(); uploadZone.classList.remove('dragover');
const file = e.dataTransfer.files[0];
if (file) processFile(file);
});
function handleFile(e) { processFile(e.target.files[0]); }
function processFile(file) {
const div = document.getElementById('fileAttached');
div.style.display = 'flex';
div.innerHTML = `<span>π</span><span>${file.name} β extracting text...</span>`;
const ext = file.name.split('.').pop().toLowerCase();
if (file.type === 'text/plain' || ext === 'txt') {
const reader = new FileReader();
reader.onload = e => {
setExtractedText(file.name, e.target.result);
};
reader.readAsText(file);
} else if (ext === 'pdf') {
const reader = new FileReader();
reader.onload = async e => {
try {
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
const pdf = await pdfjsLib.getDocument({ data: new Uint8Array(e.target.result) }).promise;
let text = '';
for (let i = 1; i <= pdf.numPages; i++) {
const page = await pdf.getPage(i);
const content = await page.getTextContent();
text += content.items.map(item => item.str).join(' ') + '\n';
}
setExtractedText(file.name, text);
} catch (err) {
div.innerHTML = `<span>β οΈ</span><span>${file.name} β PDF extraction failed</span>`;
document.getElementById('ideaText').value = '';
}
};
reader.readAsArrayBuffer(file);
} else if (ext === 'docx') {
const reader = new FileReader();
reader.onload = async e => {
try {
const result = await mammoth.extractRawText({ arrayBuffer: e.target.result });
setExtractedText(file.name, result.value);
} catch (err) {
div.innerHTML = `<span>β οΈ</span><span>${file.name} β DOCX extraction failed</span>`;
document.getElementById('ideaText').value = '';
}
};
reader.readAsArrayBuffer(file);
} else {
div.innerHTML = `<span>β οΈ</span><span>${file.name} β unsupported format (use .txt, .pdf, or .docx)</span>`;
}
}
function setExtractedText(filename, text) {
const cleaned = text.trim();
document.getElementById('ideaText').value = cleaned;
const div = document.getElementById('fileAttached');
const charCount = cleaned.length;
div.innerHTML = `<span>π</span><span>${filename} β ${charCount.toLocaleString()} characters extracted</span>`;
}
// βββ STEP 1: ANALYZE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
async function analyzeIdea() {
const text = document.getElementById('ideaText').value.trim();
if (!text) { document.getElementById('ideaText').focus(); return; }
state.ideaText = text;
const btn = document.getElementById('analyzeBtn');
btn.disabled = true;
btn.innerHTML = '<div class="spinner"></div> Analyzing (decomposing invention)...';
try {
const response = await fetch(`${API_BASE}/api/analyze-deep`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text })
});
if (!response.ok) {
const err = await response.json().catch(() => ({}));
throw new Error(err.detail || `Server error (HTTP ${response.status})`);
}
const parsed = await response.json();
// Existing fields
state.keywords = parsed.keywords || [];
state.kindCodes = parsed.kindCodes || [];
state.cpcCodes = (parsed.cpcCodes || []).map(c => ({
code: c.code, reason: c.reason || '', type: c.type || 'primary'
}));
state.selectedKeywords = [...state.keywords];
state.selectedKindCodes = state.kindCodes.map(k => k.code);
state.selectedCpcCodes = state.cpcCodes.map(c => c.code);
// New 7-step methodology fields
state.decomposition = parsed.decomposition || null;
state.synonyms = parsed.synonyms || null;
state.booleanQueries = parsed.booleanQueries || null;
// Clear evaluations and saturation when re-analyzing
state.evaluations = {};
state.saturation = { searchesRun: 0, queriesExhausted: [] };
// Render existing sections
renderKeywords();
renderCpcCodes();
renderKindCodes();
// Render new methodology sections
if (state.decomposition) renderDecomposition();
if (state.synonyms) renderSynonyms();
document.getElementById('extractedSection').style.display = 'block';
document.getElementById('extractedSection').scrollIntoView({ behavior: 'smooth', block: 'start' });
} catch (err) {
const section = document.getElementById('extractedSection');
renderError(section, 'Analysis failed', err.message, analyzeIdea);
section.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
saveState();
btn.disabled = false;
btn.innerHTML = 'β¦ Re-analyze';
}
function renderKeywords() {
const container = document.getElementById('keywordTags');
container.innerHTML = '';
state.keywords.forEach((kw, i) => {
const tag = document.createElement('div');
tag.className = 'tag' + (state.selectedKeywords.includes(kw) ? ' selected' : '');
tag.innerHTML = `${kw}<span class="tag-remove" onclick="removeTag(event,'keyword',${i})">Γ</span>`;
tag.onclick = (e) => { if (!e.target.classList.contains('tag-remove')) toggleKeyword(kw, tag); };
container.appendChild(tag);
});
}
function renderCpcCodes() {
const container = document.getElementById('cpcCodeTags');
if (!container) return;
container.innerHTML = '';
state.cpcCodes.forEach((cc, i) => {
const tag = document.createElement('div');
const selected = state.selectedCpcCodes.includes(cc.code);
tag.className = 'tag cpc-code' + (selected ? ' selected' : '');
tag.title = cc.reason || '';
tag.innerHTML = `${cc.code}<span class="tag-remove" onclick="removeCpcCode(event,${i})">Γ</span>`;
tag.onclick = (e) => { if (!e.target.classList.contains('tag-remove')) toggleCpcCode(cc.code, tag); };
container.appendChild(tag);
});
}
function renderKindCodes() {
const container = document.getElementById('kindCodeTags');
container.innerHTML = '';
state.kindCodes.forEach((kc, i) => {
const tag = document.createElement('div');
const selected = state.selectedKindCodes.includes(kc.code);
tag.className = 'tag kind-code' + (selected ? ' selected' : '');
tag.title = kc.reason || '';
tag.innerHTML = `<strong>${kc.code}</strong> β ${kc.label}<span class="tag-remove" onclick="removeKindCode(event,${i})">Γ</span>`;
tag.onclick = (e) => { if (!e.target.classList.contains('tag-remove')) toggleKindCode(kc.code, tag); };
container.appendChild(tag);
});
}
function toggleKeyword(kw, el) {
const idx = state.selectedKeywords.indexOf(kw);
if (idx > -1) { state.selectedKeywords.splice(idx, 1); el.classList.remove('selected'); }
else { state.selectedKeywords.push(kw); el.classList.add('selected'); }
saveState();
}
function toggleKindCode(code, el) {
const idx = state.selectedKindCodes.indexOf(code);
if (idx > -1) { state.selectedKindCodes.splice(idx, 1); el.classList.remove('selected'); }
else { state.selectedKindCodes.push(code); el.classList.add('selected'); }
saveState();
}
function toggleCpcCode(code, el) {
const idx = state.selectedCpcCodes.indexOf(code);
if (idx > -1) { state.selectedCpcCodes.splice(idx, 1); el.classList.remove('selected'); }
else { state.selectedCpcCodes.push(code); el.classList.add('selected'); }
saveState();
}
function removeCpcCode(e, i) {
e.stopPropagation();
const code = state.cpcCodes[i].code;
state.cpcCodes.splice(i, 1);
state.selectedCpcCodes = state.selectedCpcCodes.filter(c => c !== code);
renderCpcCodes();
saveState();
}
function removeTag(e, type, i) {
e.stopPropagation();
state.keywords.splice(i, 1);
state.selectedKeywords = state.selectedKeywords.filter(k => state.keywords.includes(k));
renderKeywords();
saveState();
}
function removeKindCode(e, i) {
e.stopPropagation();
const code = state.kindCodes[i].code;
state.kindCodes.splice(i, 1);
state.selectedKindCodes = state.selectedKindCodes.filter(c => c !== code);
renderKindCodes();
saveState();
}
function addTagOnEnter(e, type) { if (e.key === 'Enter') { e.preventDefault(); addTag(type); } }
function addTag(type) {
if (type === 'keyword') {
const val = document.getElementById('kwInput').value.trim();
if (val && !state.keywords.includes(val)) { state.keywords.push(val); state.selectedKeywords.push(val); renderKeywords(); }
document.getElementById('kwInput').value = '';
} else if (type === 'cpc') {
const val = document.getElementById('cpcInput').value.trim();
if (val && !state.cpcCodes.find(c => c.code === val)) {
state.cpcCodes.push({ code: val, reason: '' });
state.selectedCpcCodes.push(val);
renderCpcCodes();
}
document.getElementById('cpcInput').value = '';
} else {
const val = document.getElementById('kcInput').value.trim().toUpperCase();
if (val && !state.kindCodes.find(k => k.code === val)) {
state.kindCodes.push({ code: val, label: val, reason: '' });
state.selectedKindCodes.push(val);
renderKindCodes();
}
document.getElementById('kcInput').value = '';
}
saveState();
}
// βββ STEP 2: POPULATE SEARCH PANEL βββββββββββββββββββββββββββββββββββββββββββ
function populateSearchPanel() {
const kwContainer = document.getElementById('searchKeywords');
kwContainer.innerHTML = '';
state.selectedKeywords.forEach((kw, i) => {
const tag = document.createElement('div');
tag.className = 'tag selected';
tag.dataset.kw = kw;
tag.innerHTML = `${escapeHtml(kw)}<span class="tag-remove" onclick="removeSearchKw(event, this)">Γ</span>`;
kwContainer.appendChild(tag);
});
const cpcContainer = document.getElementById('searchCpcCodes');
if (cpcContainer) {
cpcContainer.innerHTML = '';
state.selectedCpcCodes.forEach(code => {
const tag = document.createElement('div');
tag.className = 'tag cpc-code selected';
tag.innerHTML = code;
cpcContainer.appendChild(tag);
});
}
const kcContainer = document.getElementById('searchKindCodes');
kcContainer.innerHTML = '';
state.selectedKindCodes.forEach(code => {
const tag = document.createElement('div');
const kc = state.kindCodes.find(k => k.code === code);
tag.className = 'tag kind-code selected';
tag.innerHTML = `<strong>${code}</strong>${kc ? ' β ' + kc.label : ''}`;
kcContainer.appendChild(tag);
});
// Render 7-step methodology panels
renderBooleanQueries();
if (state.seedPatent !== null) {
document.getElementById('seedPatentCard').style.display = 'block';
document.getElementById('seedPatentEmpty').style.display = 'none';
} else {
document.getElementById('seedPatentCard').style.display = 'block';
}
updateSaturation();
}
function removeSearchKw(e, btn) {
e.stopPropagation();
(btn || e.target).closest('.tag').remove();
}
function addSearchTagOnEnter(e, type) { if (e.key === 'Enter') addSearchTag(type); }
function addSearchTag(type) {
const val = document.getElementById('skInput').value.trim();
if (!val) return;
const kwContainer = document.getElementById('searchKeywords');
const tag = document.createElement('div');
tag.className = 'tag selected';
tag.dataset.kw = val;
tag.innerHTML = `${escapeHtml(val)}<span class="tag-remove" onclick="this.closest('.tag').remove()">Γ</span>`;
kwContainer.appendChild(tag);
document.getElementById('skInput').value = '';
}
function getSearchKeywords() {
return [...document.querySelectorAll('#searchKeywords .tag')].map(t => t.dataset.kw || t.textContent.replace('Γ','').trim());
}
// βββ STEP 2: SEARCH βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
async function runPriorArtSearch(append) {
const btn = document.getElementById('searchBtn');
btn.disabled = true;
btn.innerHTML = '<div class="spinner"></div> Searching...';
if (!append) document.getElementById('priorArtResults').style.display = 'none';
const keywords = getSearchKeywords();
const codes = state.selectedKindCodes;
const cpcCodes = state.selectedCpcCodes || [];
const sortBy = document.getElementById('sortSelect')?.value || 'relevance';
const apiSortBy = sortBy === 'relevance' ? 'date' : sortBy;
const after = append ? state.searchAfter : null;
try {
const response = await fetch(`${API_BASE}/api/search`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
keywords,
kind_codes: codes,
cpc_codes: cpcCodes,
sort_by: apiSortBy,
after
})
});
if (!response.ok) {
const err = await response.json().catch(() => ({}));
throw new Error(err.detail || `Server error (HTTP ${response.status})`);
}
const data = await response.json();
const results = data.results || [];
if (append) {
state.priorArt = state.priorArt.concat(results);
} else {
state.priorArt = results;
state.approvedArt = [];
}
state.searchAfter = data.after || null;
state.searchTotal = data.total || 0;
state.searchKeywords = [...keywords];
} catch(err) {
state.priorArt = [];
const resultsDiv = document.getElementById('priorArtResults');
const listDiv = document.getElementById('paList');
renderError(listDiv, 'Prior art search failed', err.message, runPriorArtSearch);
resultsDiv.style.display = 'block';
resultsDiv.scrollIntoView({ behavior: 'smooth' });
btn.disabled = false;
btn.innerHTML = 'β Re-Search';
return;
}
if (!append) state.approvedArt = [];
if (sortBy === 'relevance') {
const kw = state.searchKeywords || keywords;
state.priorArt.sort((a, b) =>
computeRelevanceScore(b, kw, cpcCodes) - computeRelevanceScore(a, kw, cpcCodes)
);
}
renderPriorArt();
document.getElementById('priorArtResults').style.display = 'block';
if (!append) document.getElementById('priorArtResults').scrollIntoView({ behavior: 'smooth' });
const loadMoreWrap = document.getElementById('loadMoreWrap');
const hasMore = state.searchAfter && state.priorArt.length < state.searchTotal;
if (loadMoreWrap) loadMoreWrap.style.display = hasMore ? 'block' : 'none';
// Track saturation
if (!append) state.saturation.searchesRun++;
saveState();
updateSaturation();
btn.disabled = false;
btn.innerHTML = 'β Re-Search';
}
function loadMorePriorArt() {
runPriorArtSearch(true);
}
function escapeHtml(s) {
if (!s) return '';
const div = document.createElement('div');
div.textContent = s;
return div.innerHTML;
}
function computeRelevanceScore(patent, keywords, cpcCodes) {
if (!keywords || keywords.length === 0) return 0;
let score = 0;
const title = (patent.title || '').toLowerCase();
const abstract = (patent.abstract || '').toLowerCase();
const seen = new Set();
keywords.forEach(kw => {
if (!kw) return;
const lower = kw.toLowerCase();
if (seen.has(lower)) return;
seen.add(lower);
if (title.includes(lower)) score += 15;
if (abstract.includes(lower)) score += 5;
});
if (cpcCodes && cpcCodes.length > 0 && patent.cpc) {
const patentCpc = patent.cpc.toLowerCase();
if (cpcCodes.some(c => patentCpc.startsWith(c.toLowerCase()))) score += 15;
}
return Math.min(100, score);
}
function highlightKeywords(text, keywords) {
if (!text || !keywords || keywords.length === 0) return escapeHtml(text);
let out = escapeHtml(text);
const seen = new Set();
keywords.forEach(kw => {
if (!kw || seen.has(kw.toLowerCase())) return;
seen.add(kw.toLowerCase());
const re = new RegExp(`(${kw.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi');
out = out.replace(re, '<mark class="pa-highlight">$1</mark>');
});
return out;
}
function renderPriorArt() {
const list = document.getElementById('paList');
list.innerHTML = '';
const keywords = state.searchKeywords || [];
state.priorArt.forEach((pa, i) => {
const div = document.createElement('div');
div.className = 'prior-art-item';
div.id = `pa-${i}`;
const titleHtml = highlightKeywords(pa.title, keywords);
const abstractHtml = highlightKeywords(pa.abstract, keywords);
const patentId = (pa.patentNumber || '').replace(/[,\s\/]/g, '');
const score = computeRelevanceScore(pa, keywords, state.selectedCpcCodes || []);
const scoreTier = score >= 70 ? 'high' : score >= 40 ? 'medium' : 'low';
div.innerHTML = `
<div class="pa-header">
<div class="pa-title">${titleHtml}</div>
<a class="pa-num" href="https://patents.google.com/patent/${patentId}" target="_blank" rel="noopener" onclick="event.stopPropagation()">${escapeHtml(pa.patentNumber || '')}</a>
</div>
<div class="pa-relevance ${scoreTier}">Relevance: ${score}%</div>
<div class="pa-meta">${escapeHtml(pa.assignee || '')} Β· ${escapeHtml(String(pa.year || ''))} Β· Kind Code: <strong>${escapeHtml(pa.kindCode || '')}</strong></div>
<div class="pa-abstract">${abstractHtml}</div>
<div class="pa-actions">
<button class="approve-btn" id="approve-${i}" onclick="approvePA(${i})">β Approve</button>
<button class="reject-btn" id="reject-${i}" onclick="rejectPA(${i})">β Reject</button>
<button class="btn btn-ghost" style="font-size:11px;padding:4px 10px" onclick="event.stopPropagation();toggleCitations(${i})">Related patents</button>
<button class="btn btn-ghost" style="font-size:11px;padding:4px 10px" onclick="event.stopPropagation();evaluatePatent(${i})">⚖ Evaluate</button>
<button class="btn btn-ghost" style="font-size:11px;padding:4px 10px" onclick="event.stopPropagation();setSeedPatent(${i})">★ Use as Seed</button>
</div>
<div id="citations-${i}" class="pa-citations" style="display:none;margin-top:12px;padding-top:12px;border-top:1px solid var(--border);font-size:12px;color:var(--muted)"></div>
<div id="eval-${i}" style="display:none"></div>
`;
list.appendChild(div);
});
updateApprovedCount();
// Re-render any cached evaluations
Object.keys(state.evaluations).forEach(idx => {
const i = parseInt(idx);
if (state.evaluations[i]) renderEvaluation(i, state.evaluations[i]);
});
}
async function toggleCitations(i) {
const el = document.getElementById(`citations-${i}`);
if (!el) return;
if (el.style.display === 'block') {
el.style.display = 'none';
return;
}
const pa = state.priorArt[i];
if (!pa) return;
const pid = (pa.patentNumber || '').replace(/[,\s\/]/g, '').replace(/^US/i, '');
if (!pid) return;
el.innerHTML = '<span>Loading...</span>';
el.style.display = 'block';
try {
const resp = await fetch(`${API_BASE}/api/patent/${pid}/citations`);
if (!resp.ok) throw new Error('Failed to load');
const data = await resp.json();
const citing = (data.citing || []).map(p => `US${p.patent_id}`).filter(Boolean);
const cited = (data.cited || []).map(p => `US${p.patent_id}`).filter(Boolean);
let html = '';
if (citing.length) {
html += '<div style="margin-bottom:8px"><strong>Citing this patent:</strong> ';
html += citing.map(id => `<a href="https://patents.google.com/patent/${id.replace(/[,\s]/g,'')}" target="_blank" rel="noopener" style="color:var(--accent);margin-right:8px">${id}</a>`).join('');
html += '</div>';
}
if (cited.length) {
html += '<div><strong>Cited by this patent:</strong> ';
html += cited.map(id => `<a href="https://patents.google.com/patent/${id.replace(/[,\s]/g,'')}" target="_blank" rel="noopener" style="color:var(--accent);margin-right:8px">${id}</a>`).join('');
html += '</div>';
}
if (!html) html = 'No citation data found.';
el.innerHTML = html;
} catch (e) {
el.innerHTML = 'Could not load citations.';
}
}
function approvePA(i) {
const item = document.getElementById(`pa-${i}`);
const approveBtn = document.getElementById(`approve-${i}`);
const rejectBtn = document.getElementById(`reject-${i}`);
item.classList.remove('rejected');
item.classList.toggle('approved');
approveBtn.classList.toggle('active');
rejectBtn.classList.remove('active');
if (state.approvedArt.includes(i)) {
state.approvedArt = state.approvedArt.filter(x => x !== i);
} else {
state.approvedArt.push(i);
}
updateApprovedCount();
saveState();
}
function rejectPA(i) {
const item = document.getElementById(`pa-${i}`);
const approveBtn = document.getElementById(`approve-${i}`);
const rejectBtn = document.getElementById(`reject-${i}`);
item.classList.remove('approved');
item.classList.toggle('rejected');
rejectBtn.classList.toggle('active');
approveBtn.classList.remove('active');
state.approvedArt = state.approvedArt.filter(x => x !== i);
updateApprovedCount();
saveState();
}
function updateApprovedCount() {
const n = state.approvedArt.length;
document.getElementById('approvedCount').innerHTML = n > 0
? `<strong>${n}</strong> approved for claim drafting`
: 'Approve at least 1 result to proceed';
document.getElementById('proceedBtn').disabled = n === 0;
document.getElementById('proceedBtn').style.opacity = n === 0 ? '0.4' : '1';
}
// βββ STEP 3: CLAIM GENERATION βββββββββββββββββββββββββββββββββββββββββββββββββ
async function generateClaim() {
document.getElementById('claimLoading').style.display = 'block';
document.getElementById('claimOutputWrap').style.display = 'none';
const approvedPatents = state.approvedArt.map(i => state.priorArt[i]);
const priorArtSummary = approvedPatents.map(p =>
`- ${p.patentNumber}: "${p.title}" (${p.assignee}, ${p.year}): ${p.abstract}`
).join('\n');
try {
const response = await fetch(`${API_BASE}/api/generate-claim`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
invention_text: state.ideaText,
prior_art: approvedPatents
})
});
if (!response.ok) {
const err = await response.json().catch(() => ({}));
throw new Error(err.detail || `Server error (HTTP ${response.status})`);
}
const data = await response.json();
state.claimDraft = data.claims || '';
} catch(err) {
document.getElementById('claimLoading').style.display = 'none';
const wrap = document.getElementById('claimOutputWrap');
renderError(wrap, 'Claim generation failed', err.message, regenerateClaim);
return;
}
document.getElementById('claimContent').innerText = state.claimDraft;
document.getElementById('claimLoading').style.display = 'none';
document.getElementById('claimOutputWrap').style.display = 'block';
saveState();
}
async function regenerateClaim() {
document.getElementById('claimOutputWrap').style.display = 'none';
await generateClaim();
}
function copyClaim(e) {
const text = document.getElementById('claimContent').innerText;
navigator.clipboard.writeText(text).then(() => {
const btn = e ? e.target : document.activeElement;
const orig = btn.textContent;
btn.textContent = 'β Copied!';
btn.classList.add('copied');
setTimeout(() => { btn.textContent = orig; btn.classList.remove('copied'); }, 2000);
});
}
// βββ STEP 3: CLAIM ANALYSIS βββββββββββββββββββββββββββββββββββββββββββββββββ
async function analyzeClaimDraft() {
const claims = document.getElementById('claimContent').innerText.trim();
if (!claims) return;
const btn = document.getElementById('analyzeClaimBtn');
btn.disabled = true;
btn.innerHTML = '<div class="spinner"></div> Analyzing...';
document.getElementById('claimAnalysisWrap').style.display = 'none';
document.getElementById('claimAnalysisError').style.display = 'none';
document.getElementById('claimAnalysisLoading').style.display = 'block';
const approvedPatents = state.approvedArt.map(i => state.priorArt[i]);
try {
const response = await fetch(`${API_BASE}/api/analyze-claim`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
claims: claims,
invention_text: state.ideaText,
prior_art: approvedPatents
})
});
if (!response.ok) {
const err = await response.json().catch(() => ({}));
throw new Error(err.detail || `Server error (HTTP ${response.status})`);
}
const data = await response.json();
state.claimAnalysis = data;
} catch(err) {
document.getElementById('claimAnalysisLoading').style.display = 'none';
const errorWrap = document.getElementById('claimAnalysisError');
renderError(errorWrap, 'Claim analysis failed', err.message, analyzeClaimDraft);
btn.disabled = false;
btn.innerHTML = '⚖ Analyze Claims';
return;
}
document.getElementById('claimAnalysisLoading').style.display = 'none';
renderClaimAnalysis();
saveState();
btn.disabled = false;
btn.innerHTML = '⚖ Re-Analyze Claims';
}
function ratingColor(section, rating) {
const r = (rating || '').toLowerCase();
if (section === 'specificity') return r === 'high' ? 'green' : r === 'medium' ? 'yellow' : 'red';
if (section === 'protection') return r === 'broad' ? 'green' : r === 'moderate' ? 'yellow' : 'red';
if (section === 'infringements') return r === 'high' ? 'green' : r === 'medium' ? 'yellow' : 'red';
return 'yellow';
}
function renderClaimAnalysis() {
if (!state.claimAnalysis) return;
const grid = document.getElementById('analysisGrid');
const data = state.claimAnalysis;
const sections = [
{ key: 'specificity', icon: '\uD83D\uDD0D', title: 'Specificity' },
{ key: 'protection', icon: '\uD83D\uDEE1\uFE0F', title: 'Protection Scope' },
{ key: 'infringements', icon: '\u26A0\uFE0F', title: 'Potential Infringements' }
];
const bestRating = { specificity: 'high', protection: 'broad', infringements: 'high' };
grid.innerHTML = sections.map(s => {
const section = data[s.key];
if (!section) return '';
const color = ratingColor(s.key, section.rating);
const bullets = (section.bullets || []).map(b => `<li>${escapeHtml(b)}</li>`).join('');
const isBest = (section.rating || '').toLowerCase() === bestRating[s.key];
const improveBtn = isBest ? '' :
`<button class="analysis-improve-btn" onclick="improveClaimDimension('${s.key}')">↻ Improve ${escapeHtml(s.title)}</button>`;
return `
<div class="analysis-card">
<div class="analysis-card-icon">${s.icon}</div>
<div class="analysis-card-title">${s.title}</div>
<div class="analysis-rating ${color}">${escapeHtml(section.rating)}</div>
<div class="analysis-summary">${escapeHtml(section.summary)}</div>
<ul class="analysis-bullets">${bullets}</ul>
${improveBtn}
</div>`;
}).join('');
document.getElementById('claimAnalysisWrap').style.display = 'block';
document.getElementById('analysisStatus').style.display = 'inline-flex';
}
async function improveClaimDimension(dimension) {
const claims = document.getElementById('claimContent').innerText.trim();
if (!claims || !state.claimAnalysis || !state.claimAnalysis[dimension]) return;
const feedback = state.claimAnalysis[dimension];
// Show loading state β reuse claim loading spinner
document.getElementById('claimAnalysisWrap').style.display = 'none';
document.getElementById('claimAnalysisLoading').style.display = 'none';
document.getElementById('claimLoading').style.display = 'block';
document.getElementById('claimOutputWrap').style.display = 'none';
const approvedPatents = state.approvedArt.map(i => state.priorArt[i]);
try {
const response = await fetch(`${API_BASE}/api/generate-claim`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
invention_text: state.ideaText,
prior_art: approvedPatents,
improvement_focus: dimension,
previous_claims: claims,
analysis_feedback: feedback
})
});
if (!response.ok) {
const err = await response.json().catch(() => ({}));
throw new Error(err.detail || `Server error (HTTP ${response.status})`);
}
const data = await response.json();
state.claimDraft = data.claims || '';
} catch(err) {
document.getElementById('claimLoading').style.display = 'none';
const wrap = document.getElementById('claimOutputWrap');
renderError(wrap, 'Claim improvement failed', err.message, () => improveClaimDimension(dimension));
return;
}
// Clear old analysis so user re-analyzes the improved version
state.claimAnalysis = null;
document.getElementById('claimContent').innerText = state.claimDraft;
document.getElementById('claimLoading').style.display = 'none';
document.getElementById('claimOutputWrap').style.display = 'block';
document.getElementById('claimAnalysisWrap').style.display = 'none';
document.getElementById('analysisStatus').style.display = 'none';
document.getElementById('analyzeClaimBtn').innerHTML = '⚖ Analyze Claims';
saveState();
document.getElementById('claimContent').scrollIntoView({ behavior: 'smooth' });
}
// βββ USPTO 7-STEP: COLLAPSIBLE SECTIONS ββββββββββββββββββββββββββββββββββββββ
function toggleSection(name) {
const body = document.getElementById(`${name}-body`);
const icon = document.getElementById(`${name}-icon`);
if (!body) return;
if (body.style.display === 'none') {
body.style.display = 'block';
if (icon) icon.innerHTML = '▲';
} else {
body.style.display = 'none';
if (icon) icon.innerHTML = '▼';
}
}
// βββ USPTO STEP 1: RENDER DECOMPOSITION ββββββββββββββββββββββββββββββββββββββ
function renderDecomposition() {
const d = state.decomposition;
if (!d) return;
document.getElementById('decompositionCard').style.display = 'block';
const render = (id, items) => {
const ul = document.getElementById(id);
if (ul) ul.innerHTML = (items || []).map(f => `<li>${escapeHtml(f)}</li>`).join('');
};
render('coreFeatures', d.core_features);
render('supportingFeatures', d.supporting_features);
render('claimedImprovements', d.claimed_improvements);
render('hwswComponents', d.components);
}
// βββ USPTO STEP 2: RENDER SYNONYMS ββββββββββββββββββββββββββββββββββββββββββ
function renderSynonyms() {
const s = state.synonyms;
if (!s || typeof s !== 'object') return;
document.getElementById('synonymCard').style.display = 'block';
const grid = document.getElementById('synonymGrid');
grid.innerHTML = Object.entries(s).map(([feature, data]) => `
<div class="synonym-row">
<div class="synonym-feature">${escapeHtml(feature)}</div>
<div class="synonym-tags">
${(data.technical_synonyms || []).map(t => `<span class="tag">${escapeHtml(t)}</span>`).join('')}
${(data.industry_terms || []).map(t => `<span class="tag kind-code">${escapeHtml(t)}</span>`).join('')}
${data.broader ? `<span class="tag cpc-code" title="Broader term">${escapeHtml(data.broader)}</span>` : ''}
${data.narrower ? `<span class="tag" style="background:rgba(74,222,128,0.1);border-color:rgba(74,222,128,0.3);color:#4ade80" title="Narrower term">${escapeHtml(data.narrower)}</span>` : ''}
</div>
</div>
`).join('');
}
// βββ USPTO STEP 4: BOOLEAN QUERIES ββββββββββββββββββββββββββββββββββββββββββ
function renderBooleanQueries() {
const queries = state.booleanQueries;
if (!queries || queries.length === 0) {
document.getElementById('booleanQueriesCard').style.display = 'none';
return;
}
document.getElementById('booleanQueriesCard').style.display = 'block';
const list = document.getElementById('booleanQueryList');
list.innerHTML = queries.map((q, i) => `
<div class="boolean-query-item">
<div class="boolean-query-label">${escapeHtml(q.label || q.level)}</div>
<div class="boolean-query-text">${escapeHtml(q.query)}</div>
<div class="boolean-query-actions">
<button class="btn btn-ghost" style="font-size:11px" onclick="copyBooleanQuery(${i})">Copy for USPTO</button>
<button class="btn btn-ghost" style="font-size:11px;color:var(--accent);border-color:rgba(200,241,53,0.3)" onclick="runBooleanQuery(${i})">Run in App</button>
</div>
</div>
`).join('');
}
function copyBooleanQuery(index) {
const q = state.booleanQueries[index];
if (!q) return;
navigator.clipboard.writeText(q.query).then(() => {
const items = document.querySelectorAll('.boolean-query-item');
if (items[index]) {
const btn = items[index].querySelector('.btn-ghost');
if (btn) { const orig = btn.textContent; btn.textContent = 'β Copied!'; setTimeout(() => btn.textContent = orig, 1500); }
}
});
}
function runBooleanQuery(index) {
const q = state.booleanQueries[index];
if (!q || !q.keyword_sets || q.keyword_sets.length === 0) return;
const kwContainer = document.getElementById('searchKeywords');
kwContainer.innerHTML = '';
q.keyword_sets.forEach(kw => {
const tag = document.createElement('div');
tag.className = 'tag selected';
tag.dataset.kw = kw;
tag.innerHTML = `${escapeHtml(kw)}<span class="tag-remove" onclick="this.closest('.tag').remove()">Γ</span>`;
kwContainer.appendChild(tag);
});
if (!state.saturation.queriesExhausted.includes(q.level)) {
state.saturation.queriesExhausted.push(q.level);
}
state.saturation.searchesRun++;
saveState();
runPriorArtSearch();
}
// βββ USPTO STEP 5: SEED PATENT STRATEGY βββββββββββββββββββββββββββββββββββββ
function setSeedPatent(index) {
state.seedPatent = index;
saveState();
document.getElementById('seedPatentCard').style.display = 'block';
document.getElementById('seedPatentEmpty').style.display = 'none';
loadSeedCitations(index);
}
async function loadSeedCitations(index) {
const pa = state.priorArt[index];
if (!pa) return;
const pid = (pa.patentNumber || '').replace(/[,\s\/]/g, '').replace(/^US/i, '');
const infoDiv = document.getElementById('seedPatentInfo');
infoDiv.style.display = 'block';
infoDiv.innerHTML = '<div style="font-size:13px;color:var(--muted)"><div class="spinner spinner-accent" style="display:inline-block;vertical-align:middle;margin-right:8px;width:14px;height:14px;border-width:2px"></div>Loading citations...</div>';
try {
const resp = await fetch(`${API_BASE}/api/patent/${pid}/citations`);
if (!resp.ok) throw new Error('Failed');
const data = await resp.json();
const citing = (data.citing || []).map(p => `US${p.patent_id}`);
const cited = (data.cited || []).map(p => `US${p.patent_id}`);
const seedCpc = pa.cpc ? [pa.cpc] : [];
infoDiv.innerHTML = `
<div class="seed-patent-summary">
<div style="font-size:14px;font-weight:500;margin-bottom:8px">${escapeHtml(pa.patentNumber)}: ${escapeHtml(pa.title)}</div>
<div style="font-size:12px;color:var(--muted);margin-bottom:12px">
CPC: ${escapeHtml(pa.cpc || 'N/A')} | ${citing.length} patents cite this | Cites ${cited.length} patents
</div>
<div style="font-size:12px;margin-bottom:8px;color:rgba(237,240,255,0.8)">
<strong>Strategy:</strong> Search within this patent's CPC subclass and citation network for comprehensive coverage.
</div>
<div style="display:flex;gap:8px;flex-wrap:wrap">
${seedCpc.length ? `<button class="btn btn-ghost" style="font-size:11px" onclick="searchSeedCpc('${escapeHtml(seedCpc[0])}')">Search CPC ${escapeHtml(seedCpc[0])}</button>` : ''}
${citing.length ? `<span style="font-size:11px;color:var(--muted)">Citing: ${citing.slice(0,5).map(id => `<a href="https://patents.google.com/patent/${id.replace(/[,\s]/g,'')}" target="_blank" rel="noopener" style="color:var(--accent);margin-right:4px">${id}</a>`).join('')}${citing.length > 5 ? ` +${citing.length-5} more` : ''}</span>` : ''}
</div>
${cited.length ? `<div style="margin-top:8px;font-size:11px;color:var(--muted)">Cited: ${cited.slice(0,5).map(id => `<a href="https://patents.google.com/patent/${id.replace(/[,\s]/g,'')}" target="_blank" rel="noopener" style="color:var(--accent);margin-right:4px">${id}</a>`).join('')}${cited.length > 5 ? ` +${cited.length-5} more` : ''}</div>` : ''}
</div>
`;
} catch(e) {
infoDiv.innerHTML = '<div style="color:var(--red);font-size:12px">Could not load seed patent data.</div>';
}
}
function searchSeedCpc(cpcCode) {
// Add the seed CPC code to search CPC codes and re-search
if (!state.selectedCpcCodes.includes(cpcCode)) {
state.selectedCpcCodes.push(cpcCode);
}
state.saturation.searchesRun++;
saveState();
populateSearchPanel();
runPriorArtSearch();
}
// βββ USPTO STEP 6: EXAMINER COMPARISON FRAMEWORK ββββββββββββββββββββββββββββ
async function evaluatePatent(index) {
if (state.evaluations[index]) {
toggleEvaluation(index);
return;
}
const evalDiv = document.getElementById(`eval-${index}`);
if (!evalDiv) return;
const pa = state.priorArt[index];
if (!pa || !state.decomposition) {
evalDiv.innerHTML = '<div style="color:var(--muted);font-size:12px;padding:12px 0">Run analysis in Step 1 first to enable evaluation.</div>';
evalDiv.style.display = 'block';
return;
}
evalDiv.innerHTML = '<div style="padding:12px 0;font-size:12px;color:var(--muted)"><div class="spinner spinner-accent" style="display:inline-block;vertical-align:middle;margin-right:8px;width:14px;height:14px;border-width:2px"></div>Evaluating against invention features...</div>';
evalDiv.style.display = 'block';
try {
const response = await fetch(`${API_BASE}/api/evaluate-patent`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
invention_text: state.ideaText,
patent: pa,
decomposition: state.decomposition
})
});
if (!response.ok) {
const err = await response.json().catch(() => ({}));
throw new Error(err.detail || 'Evaluation failed');
}
const data = await response.json();
state.evaluations[index] = data;
saveState();
renderEvaluation(index, data);
} catch(err) {
evalDiv.innerHTML = `<div style="color:var(--red);font-size:12px;padding:12px 0">${escapeHtml(err.message)}</div>`;
}
}
function statusIcon(val) {
if (val === 'yes') return '<span style="color:#4ade80">✓</span>';
if (val === 'partial') return '<span style="color:#facc15">~</span>';
return '<span style="color:var(--muted)">✗</span>';
}
function renderEvaluation(index, data) {
const evalDiv = document.getElementById(`eval-${index}`);
if (!evalDiv) return;
const threatColors = { high: 'red', medium: 'yellow', low: 'green' };
const threatColor = threatColors[data.threat_level] || 'yellow';
const comparisonRows = (data.feature_comparison || []).map(fc => `
<tr>
<td style="padding:6px 8px;font-size:12px;border-bottom:1px solid var(--border)">${escapeHtml(fc.feature)}</td>
<td style="padding:6px 8px;text-align:center;border-bottom:1px solid var(--border)">${statusIcon(fc.disclosed)}</td>
<td style="padding:6px 8px;text-align:center;border-bottom:1px solid var(--border)">${statusIcon(fc.equivalent)}</td>
<td style="padding:6px 8px;text-align:center;border-bottom:1px solid var(--border)">${statusIcon(fc.same_solution)}</td>
<td style="padding:6px 8px;text-align:center;border-bottom:1px solid var(--border)">${statusIcon(fc.problem_only)}</td>
</tr>
`).join('');
evalDiv.innerHTML = `
<div class="pa-evaluation" style="padding:16px 0;border-top:1px solid var(--border);margin-top:12px">
<div style="display:flex;align-items:center;gap:12px;margin-bottom:12px">
<span style="font-size:11px;letter-spacing:0.12em;text-transform:uppercase;color:var(--muted);font-weight:500">Examiner Comparison</span>
<span class="analysis-rating ${threatColor}">${escapeHtml(data.threat_level || 'unknown')} threat</span>
</div>
<div style="font-size:13px;color:rgba(237,240,255,0.8);margin-bottom:12px">${escapeHtml(data.overlap_summary || '')}</div>
<table style="width:100%;border-collapse:collapse;font-size:12px;color:var(--text)">
<thead>
<tr style="color:var(--muted)">
<th style="text-align:left;padding:6px 8px;border-bottom:1px solid var(--border)">Feature</th>
<th style="padding:6px 8px;border-bottom:1px solid var(--border)">Disclosed</th>
<th style="padding:6px 8px;border-bottom:1px solid var(--border)">Equivalent</th>
<th style="padding:6px 8px;border-bottom:1px solid var(--border)">Same Sol.</th>
<th style="padding:6px 8px;border-bottom:1px solid var(--border)">Prob. Only</th>
</tr>
</thead>
<tbody>${comparisonRows}</tbody>
</table>
${data.distinguishing_features && data.distinguishing_features.length ? `
<div style="margin-top:12px;font-size:12px">
<strong style="color:var(--accent)">Distinguishing features:</strong>
${data.distinguishing_features.map(f => `<span class="tag" style="margin:4px 4px 0 0">${escapeHtml(f)}</span>`).join('')}
</div>
` : ''}
</div>
`;
evalDiv.style.display = 'block';
}
function toggleEvaluation(index) {
const el = document.getElementById(`eval-${index}`);
if (!el) return;
el.style.display = el.style.display === 'none' ? 'block' : 'none';
}
// βββ USPTO STEP 7: SATURATION TRACKING ββββββββββββββββββββββββββββββββββββββ
function updateSaturation() {
const s = state.saturation;
if (s.searchesRun === 0) {
document.getElementById('saturationBar').style.display = 'none';
return;
}
document.getElementById('saturationBar').style.display = 'block';
let score = 0;
// Factor 1: Number of distinct searches run (max 30 points for 3+ searches)
score += Math.min(30, s.searchesRun * 10);
// Factor 2: How many boolean query levels exhausted (max 30 points)
const uniqueExhausted = [...new Set(s.queriesExhausted)];
score += Math.min(30, uniqueExhausted.length * 10);
// Factor 3: Review coverage (max 20 points)
const totalReviewed = Object.keys(state.evaluations).length + state.approvedArt.length;
const totalResults = state.priorArt.length;
if (totalResults > 0) score += Math.min(20, Math.round((totalReviewed / totalResults) * 20));
// Factor 4: Having a seed patent (max 20 points)
if (state.seedPatent !== null) score += 20;
score = Math.min(100, score);
document.getElementById('saturationPct').textContent = `${score}%`;
document.getElementById('saturationFill').style.width = `${score}%`;
let hint = '';
if (score < 30) hint = 'Early stage \u2014 run broad and intermediate queries to establish baseline.';
else if (score < 60) hint = 'Developing \u2014 try examiner-level queries and evaluate key results.';
else if (score < 85) hint = 'Good coverage \u2014 use seed patent strategy and check diminishing returns.';
else hint = 'Near saturation \u2014 search is likely comprehensive for this invention scope.';
document.getElementById('saturationHint').textContent = hint;
}
// βββ RESTORE SESSION ON LOAD βββββββββββββββββββββββββββββββββββββββββββββββββ
function restoreSession() {
loadState();
if (!state.ideaText && state.keywords.length === 0) return;
document.getElementById('ideaText').value = state.ideaText;
if (state.keywords.length > 0) {
renderKeywords();
if (state.cpcCodes && state.cpcCodes.length) renderCpcCodes();
renderKindCodes();
// Restore 7-step methodology sections
if (state.decomposition) renderDecomposition();
if (state.synonyms) renderSynonyms();
document.getElementById('extractedSection').style.display = 'block';
document.getElementById('analyzeBtn').innerHTML = 'β¦ Re-analyze';
}
if (state.priorArt.length > 0) {
renderPriorArt();
const loadMoreWrap = document.getElementById('loadMoreWrap');
if (loadMoreWrap) loadMoreWrap.style.display = (state.searchAfter && state.priorArt.length < state.searchTotal) ? 'block' : 'none';
state.approvedArt.forEach(i => {
const item = document.getElementById(`pa-${i}`);
const btn = document.getElementById(`approve-${i}`);
if (item) { item.classList.add('approved'); }
if (btn) { btn.classList.add('active'); }
});
document.getElementById('priorArtResults').style.display = 'block';
document.getElementById('searchBtn').innerHTML = 'β Re-Search';
}
if (state.claimDraft) {
document.getElementById('claimContent').innerText = state.claimDraft;
document.getElementById('claimLoading').style.display = 'none';
document.getElementById('claimOutputWrap').style.display = 'block';
}
if (state.claimAnalysis) {
renderClaimAnalysis();
document.getElementById('analyzeClaimBtn').innerHTML = '⚖ Re-Analyze Claims';
}
if (state.currentStep > 1) {
goToStep(state.currentStep, { skipGenerate: true });
}
}
restoreSession();
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Eddison Intelligence β Patent Assistant</title>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Mono:wght@300;400;500&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,300&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mammoth/1.6.0/mammoth.browser.min.js"></script>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #07090F;
--surface: #0E1118;
--surface2: #141821;
--border: rgba(255,255,255,0.07);
--border-active: rgba(200,241,53,0.4);
--accent: #C8F135;
--accent-dim: rgba(200,241,53,0.15);
--red: #FF4757;
--blue: #3B82F6;
--text: #EDF0FF;
--muted: rgba(237,240,255,0.45);
--mono: 'DM Mono', monospace;
--sans: 'DM Sans', sans-serif;
--display: 'Bebas Neue', sans-serif;
}
html, body {
height: 100%;
background: var(--bg);
color: var(--text);
font-family: var(--sans);
overflow-x: hidden;
}
/* βββ NOISE OVERLAY βββ */
body::after {
content: '';
position: fixed; inset: 0;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
pointer-events: none; z-index: 9999; opacity: 0.4;
}
/* βββ LAYOUT βββ */
.app {
display: grid;
grid-template-rows: auto 1fr;
min-height: 100vh;
}
/* βββ HEADER βββ */
header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 40px;
border-bottom: 1px solid var(--border);
background: rgba(7,9,15,0.9);
backdrop-filter: blur(12px);
position: sticky; top: 0; z-index: 100;
}
.logo {
font-family: var(--display);
font-size: 22px;
letter-spacing: 0.15em;
color: var(--text);
}
.logo span { color: var(--accent); }
.steps-nav {
display: flex;
align-items: center;
gap: 4px;
}
.step-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 7px 16px;
border-radius: 8px;
border: none;
background: transparent;
cursor: pointer;
font-family: var(--sans);
font-size: 12px;
font-weight: 500;
letter-spacing: 0.04em;
color: var(--muted);
transition: all 0.2s;
position: relative;
}
.step-btn .num {
width: 20px; height: 20px;
border-radius: 50%;
background: var(--surface2);
border: 1px solid var(--border);
display: flex; align-items: center; justify-content: center;
font-family: var(--mono);