browser-assistant 2.9.2 → 2.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/extension/automation-policy.js +21 -2
- package/extension/background.js +13 -5
- package/extension/content.js +403 -55
- package/extension/detached-panel-background.js +101 -0
- package/extension/detached-panel.html +18 -0
- package/extension/detached-panel.js +201 -0
- package/extension/journal-automation.js +13 -14
- package/extension/manifest.json +1 -1
- package/extension/popup.html +23 -52
- package/extension/popup.js +24 -0
- package/extension/styles.css +555 -547
- package/package.json +7 -2
- package/server/main.py +62 -2
- package/server/practice_quiz.html +79 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-assistant",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.4",
|
|
4
4
|
"description": "Chrome extension and local Python backend for exploring webpage questions and coding exercises",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"LICENSE",
|
|
16
16
|
"extension/manifest.json",
|
|
17
17
|
"extension/background.js",
|
|
18
|
+
"extension/detached-panel-background.js",
|
|
19
|
+
"extension/detached-panel.html",
|
|
20
|
+
"extension/detached-panel.js",
|
|
18
21
|
"extension/editor-bridge.js",
|
|
19
22
|
"extension/automation-policy.js",
|
|
20
23
|
"extension/question-visuals.js",
|
|
@@ -42,11 +45,13 @@
|
|
|
42
45
|
"build": "tsc --project tsconfig.json",
|
|
43
46
|
"prepack": "npm run build",
|
|
44
47
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
45
|
-
"test": "npm run build && node --test extension/*.test.cts"
|
|
48
|
+
"test": "npm run build && node --test extension/*.test.cts",
|
|
49
|
+
"test:browser": "npm run build && node --test scripts/test_separate_panel.cjs"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
52
|
"@types/chrome": "0.3.7",
|
|
49
53
|
"linkedom": "^0.18.12",
|
|
54
|
+
"playwright": "1.65.0",
|
|
50
55
|
"typescript": "5.9.3"
|
|
51
56
|
}
|
|
52
57
|
}
|
package/server/main.py
CHANGED
|
@@ -7,7 +7,10 @@ import math
|
|
|
7
7
|
import re
|
|
8
8
|
import time
|
|
9
9
|
from fastapi import FastAPI, HTTPException
|
|
10
|
-
from pydantic import BaseModel, field_validator
|
|
10
|
+
from pydantic import BaseModel, Field, field_validator
|
|
11
|
+
from typing import Literal
|
|
12
|
+
from uuid import UUID
|
|
13
|
+
from urllib.parse import urlsplit
|
|
11
14
|
from dotenv import load_dotenv
|
|
12
15
|
from groq import Groq
|
|
13
16
|
import ollama
|
|
@@ -167,6 +170,15 @@ def initialize_history_database() -> None:
|
|
|
167
170
|
connection.execute(
|
|
168
171
|
"CREATE INDEX IF NOT EXISTS idx_scan_history_created_at ON scan_history(created_at DESC)"
|
|
169
172
|
)
|
|
173
|
+
connection.execute(
|
|
174
|
+
"""CREATE TABLE IF NOT EXISTS automation_history (
|
|
175
|
+
id TEXT PRIMARY KEY,
|
|
176
|
+
started_at TEXT NOT NULL,
|
|
177
|
+
revision INTEGER NOT NULL,
|
|
178
|
+
status TEXT NOT NULL,
|
|
179
|
+
record TEXT NOT NULL
|
|
180
|
+
)"""
|
|
181
|
+
)
|
|
170
182
|
|
|
171
183
|
|
|
172
184
|
@asynccontextmanager
|
|
@@ -179,7 +191,7 @@ async def lifespan(_app: FastAPI):
|
|
|
179
191
|
client.close()
|
|
180
192
|
|
|
181
193
|
|
|
182
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
194
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.4", lifespan=lifespan)
|
|
183
195
|
install_local_guards(app)
|
|
184
196
|
|
|
185
197
|
@app.exception_handler(HTTPException)
|
|
@@ -268,6 +280,27 @@ class HistoryEntry(BaseModel):
|
|
|
268
280
|
return value
|
|
269
281
|
|
|
270
282
|
|
|
283
|
+
class AutomationHistoryEntry(BaseModel):
|
|
284
|
+
id: UUID
|
|
285
|
+
type: Literal["MCQ", "Quiz", "Coding", "Batch Coding", "Journal"]
|
|
286
|
+
url: str = Field(max_length=2048)
|
|
287
|
+
started_at: datetime
|
|
288
|
+
ended_at: datetime | None = None
|
|
289
|
+
total: int | None = Field(default=None, ge=0)
|
|
290
|
+
completed: int = Field(ge=0)
|
|
291
|
+
failed: int = Field(ge=0)
|
|
292
|
+
status: Literal["Running", "Completed", "Failed", "Stopped"]
|
|
293
|
+
revision: int = Field(ge=1)
|
|
294
|
+
|
|
295
|
+
@field_validator("url")
|
|
296
|
+
@classmethod
|
|
297
|
+
def validate_page_url(cls, value):
|
|
298
|
+
parsed = urlsplit(value)
|
|
299
|
+
if parsed.scheme not in ("http", "https") or not parsed.hostname or parsed.username or parsed.password or parsed.query or parsed.fragment:
|
|
300
|
+
raise ValueError("Provide a webpage URL without credentials, a query or a fragment")
|
|
301
|
+
return value
|
|
302
|
+
|
|
303
|
+
|
|
271
304
|
# ── Health check ──────────────────────────────────────────────────────────────
|
|
272
305
|
|
|
273
306
|
@app.get("/health")
|
|
@@ -360,6 +393,33 @@ def clear_history():
|
|
|
360
393
|
connection.execute("DELETE FROM scan_history")
|
|
361
394
|
|
|
362
395
|
|
|
396
|
+
@app.get("/automation-history")
|
|
397
|
+
def list_automation_history(limit: int = Query(default=20, ge=1, le=HISTORY_MAX_ITEMS)):
|
|
398
|
+
with get_history_connection() as connection:
|
|
399
|
+
rows = connection.execute(
|
|
400
|
+
"SELECT record FROM automation_history ORDER BY started_at DESC LIMIT ?", (limit,)
|
|
401
|
+
).fetchall()
|
|
402
|
+
return {"items": [json.loads(row["record"]) for row in rows]}
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
@app.put("/automation-history")
|
|
406
|
+
def save_automation_history(entry: AutomationHistoryEntry):
|
|
407
|
+
if (entry.status == "Running") != (entry.ended_at is None):
|
|
408
|
+
raise HTTPException(422, "Only a finished run has an end time.")
|
|
409
|
+
with get_history_connection() as connection:
|
|
410
|
+
connection.execute(
|
|
411
|
+
"""INSERT INTO automation_history (id, started_at, revision, status, record)
|
|
412
|
+
VALUES (?, ?, ?, ?, ?)
|
|
413
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
414
|
+
revision=excluded.revision, status=excluded.status, record=excluded.record
|
|
415
|
+
WHERE automation_history.status='Running'
|
|
416
|
+
AND excluded.revision > automation_history.revision
|
|
417
|
+
AND excluded.started_at=automation_history.started_at""",
|
|
418
|
+
(str(entry.id), entry.started_at.isoformat(), entry.revision, entry.status, entry.model_dump_json()),
|
|
419
|
+
)
|
|
420
|
+
return {"id": str(entry.id)}
|
|
421
|
+
|
|
422
|
+
|
|
363
423
|
# ── AI providers ──────────────────────────────────────────────────────────────
|
|
364
424
|
|
|
365
425
|
async def try_groq(messages: list, model: str = None, temperature: float = 0.0, _token_limit: int = GROQ_COMPLETION_TOKEN_LIMIT, _review: bool = False) -> str:
|
|
@@ -5,12 +5,85 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<title>Browser Assistant Local Practice Quiz</title>
|
|
7
7
|
<style>
|
|
8
|
-
body {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
body {
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
min-height: 100vh;
|
|
11
|
+
margin: 0;
|
|
12
|
+
padding: clamp(52px, 9vh, 100px) 16px 32px;
|
|
13
|
+
color-scheme: dark;
|
|
14
|
+
font: 16px/1.5 Inter, system-ui, sans-serif;
|
|
15
|
+
color: #f7fbff;
|
|
16
|
+
background: radial-gradient(ellipse at 0% 0%, #283f85, transparent 63%),
|
|
17
|
+
radial-gradient(ellipse at 95% 100%, #146263, transparent 62%),
|
|
18
|
+
linear-gradient(145deg, #101831, #080f20 62%);
|
|
19
|
+
}
|
|
20
|
+
body > main {
|
|
21
|
+
box-sizing: border-box;
|
|
22
|
+
max-width: 640px;
|
|
23
|
+
margin: auto;
|
|
24
|
+
padding: clamp(18px, 5vw, 36px);
|
|
25
|
+
border: 1px solid rgb(191 215 255 / 34%);
|
|
26
|
+
border-radius: 25px;
|
|
27
|
+
background: rgb(8 15 33 / 65%);
|
|
28
|
+
backdrop-filter: blur(24px) saturate(135%);
|
|
29
|
+
box-shadow: 0 22px 60px rgb(4 10 26 / 40%), inset 0 1px rgb(224 238 255 / 16%);
|
|
30
|
+
}
|
|
31
|
+
.tag { color: #acd6ff; font-size: .81rem; font-weight: 720; letter-spacing: .07em; text-transform: uppercase; }
|
|
32
|
+
h1 { margin: 4px 0 12px; font-size: clamp(2rem, 6vw, 3.15rem); line-height: 1.07; letter-spacing: -.045em; }
|
|
33
|
+
#progress { margin: 0 0 16px; color: #c7d4eb; font-size: .875rem; font-weight: 650; }
|
|
34
|
+
#question-card {
|
|
35
|
+
padding: clamp(13px, 3vw, 22px);
|
|
36
|
+
border: 1px solid rgb(191 215 255 / 30%);
|
|
37
|
+
border-radius: 16px;
|
|
38
|
+
background: rgb(26 40 66 / 60%);
|
|
39
|
+
backdrop-filter: blur(16px);
|
|
40
|
+
box-shadow: 0 8px 24px rgb(4 10 26 / 24%);
|
|
41
|
+
}
|
|
42
|
+
#question-card h2 { margin: 0 0 14px; font-size: clamp(1.1rem, 3vw, 1.45rem); line-height: 1.3; }
|
|
43
|
+
.option {
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
gap: 10px;
|
|
47
|
+
margin: 8px 0;
|
|
48
|
+
padding: 10px 12px;
|
|
49
|
+
border: 1px solid rgb(191 215 255 / 60%);
|
|
50
|
+
border-radius: 10px;
|
|
51
|
+
background: rgb(4 11 27 / 64%);
|
|
52
|
+
backdrop-filter: blur(12px);
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
}
|
|
55
|
+
.option input { margin: 0; accent-color: #a5f6da; }
|
|
56
|
+
.option:hover { border-color: #acd6ff; }
|
|
57
|
+
.option:has(input:checked) { border-color: #a5f6da; background: rgb(20 67 66 / 82%); }
|
|
58
|
+
[data-practice-submit] {
|
|
59
|
+
margin-top: 10px;
|
|
60
|
+
padding: 10px 16px;
|
|
61
|
+
border: 1px solid transparent;
|
|
62
|
+
border-radius: 9px;
|
|
63
|
+
background: linear-gradient(125deg, #a5e8ff, #c2bbff);
|
|
64
|
+
color: #111b33;
|
|
65
|
+
font: inherit;
|
|
66
|
+
font-weight: 750;
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
}
|
|
69
|
+
[data-practice-submit]:hover:not(:disabled) { background: linear-gradient(125deg, #c0f1ff, #d3ccff); }
|
|
70
|
+
[data-practice-submit]:disabled {
|
|
71
|
+
background: rgb(4 11 27 / 64%);
|
|
72
|
+
border: 1px dashed rgb(191 215 255 / 60%);
|
|
73
|
+
color: #c7d4eb;
|
|
74
|
+
cursor: not-allowed;
|
|
75
|
+
}
|
|
76
|
+
.option:has(input:focus-visible), [data-practice-submit]:focus-visible { outline: 2px solid #acd6ff; outline-offset: 2px; }
|
|
77
|
+
#feedback { margin: 12px 0 0; min-height: 1.5em; color: #f7fbff; font-weight: 650; }
|
|
78
|
+
.done { color: #a5f6da; font-weight: 700; }
|
|
79
|
+
@supports not (backdrop-filter: blur(12px)) {
|
|
80
|
+
body > main { background: #13213a; }
|
|
81
|
+
#question-card { background: #202e47; }
|
|
82
|
+
}
|
|
83
|
+
@media (forced-colors: active) {
|
|
84
|
+
.option:has(input:checked) { border-color: Highlight; }
|
|
85
|
+
.option:has(input:focus-visible), [data-practice-submit]:focus-visible { outline-color: Highlight; }
|
|
86
|
+
}
|
|
14
87
|
</style>
|
|
15
88
|
</head>
|
|
16
89
|
<body>
|