browser-assistant 2.9.1 → 2.9.3
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 +8 -5
- package/extension/automation-policy.js +8 -4
- package/extension/background.js +1 -1
- package/extension/content.js +36 -23
- package/extension/journal-automation.js +2 -8
- package/extension/manifest.json +1 -1
- package/extension/popup.html +21 -52
- package/extension/question-visuals.js +6 -2
- package/extension/styles.css +473 -554
- package/package.json +1 -1
- package/server/journal.py +6 -3
- package/server/main.py +22 -22
- package/server/practice_quiz.html +79 -6
package/package.json
CHANGED
package/server/journal.py
CHANGED
|
@@ -7,6 +7,7 @@ from fastapi import HTTPException
|
|
|
7
7
|
from pydantic import BaseModel, Field
|
|
8
8
|
|
|
9
9
|
SYLLABUS_PATH = Path(__file__).with_name('journal_syllabus.json')
|
|
10
|
+
PROMPT_PATH = Path(__file__).with_name('journal_prompt.md')
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def load_syllabus():
|
|
@@ -19,9 +20,7 @@ def load_syllabus():
|
|
|
19
20
|
return value
|
|
20
21
|
|
|
21
22
|
|
|
22
|
-
SYLLABUS = load_syllabus() # Compatibility snapshot; requests use a fresh catalog.
|
|
23
23
|
SECTIONS = ('experience', 'feelings', 'learning', 'application', 'conclusion')
|
|
24
|
-
MASTER_PROMPT = Path(__file__).with_name('journal_prompt.md').read_text(encoding='utf-8-sig')
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
class JournalRequest(BaseModel):
|
|
@@ -74,8 +73,12 @@ def register_journal(app, cloud, local):
|
|
|
74
73
|
module = syllabus.get('modules', {}).get(str(request.number))
|
|
75
74
|
if not isinstance(module, str) or not module.strip():
|
|
76
75
|
raise HTTPException(422, 'The selected module is missing from the supplied syllabus. Nothing was generated.')
|
|
76
|
+
try:
|
|
77
|
+
master_prompt = PROMPT_PATH.read_text(encoding='utf-8-sig')
|
|
78
|
+
except (OSError, UnicodeError) as exc:
|
|
79
|
+
raise HTTPException(503, 'The journal prompt could not be loaded. Nothing was generated.') from exc
|
|
77
80
|
messages = [
|
|
78
|
-
{'role': 'system', 'content':
|
|
81
|
+
{'role': 'system', 'content': master_prompt + '\n\nPORTAL OUTPUT ADAPTER:\n'
|
|
79
82
|
'Apply the master prompt above to the complete supplied syllabus. This request '
|
|
80
83
|
'is for one portal journal: output ONLY the requested module_number, not every '
|
|
81
84
|
'module in one response. Return one JSON object with exactly these string keys '
|
package/server/main.py
CHANGED
|
@@ -55,22 +55,10 @@ _groq_key_index = 0 # current active key index
|
|
|
55
55
|
|
|
56
56
|
def get_groq_client():
|
|
57
57
|
"""Get the current Groq client. Returns None if no keys configured."""
|
|
58
|
-
global _groq_key_index
|
|
59
58
|
if not _groq_clients:
|
|
60
59
|
return None
|
|
61
60
|
return _groq_clients[_groq_key_index % len(_groq_clients)]
|
|
62
61
|
|
|
63
|
-
def rotate_groq_key(reason="rate limit"):
|
|
64
|
-
"""Rotate to the next API key."""
|
|
65
|
-
global _groq_key_index
|
|
66
|
-
if len(_groq_clients) <= 1:
|
|
67
|
-
return False
|
|
68
|
-
old_idx = _groq_key_index % len(_groq_clients)
|
|
69
|
-
_groq_key_index += 1
|
|
70
|
-
new_idx = _groq_key_index % len(_groq_clients)
|
|
71
|
-
logger.warning(f"Rotating API key ({reason}): key #{old_idx+1} → key #{new_idx+1} (of {len(_groq_clients)})")
|
|
72
|
-
return True
|
|
73
|
-
|
|
74
62
|
logger.info(f"Loaded {len(_groq_clients)} Groq API key(s)")
|
|
75
63
|
|
|
76
64
|
# Ollama model is now configurable via .env
|
|
@@ -191,7 +179,7 @@ async def lifespan(_app: FastAPI):
|
|
|
191
179
|
client.close()
|
|
192
180
|
|
|
193
181
|
|
|
194
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
182
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.3", lifespan=lifespan)
|
|
195
183
|
install_local_guards(app)
|
|
196
184
|
|
|
197
185
|
@app.exception_handler(HTTPException)
|
|
@@ -284,10 +272,16 @@ class HistoryEntry(BaseModel):
|
|
|
284
272
|
|
|
285
273
|
@app.get("/health")
|
|
286
274
|
async def health():
|
|
275
|
+
try:
|
|
276
|
+
journal_subjects = list(load_syllabus())
|
|
277
|
+
except HTTPException:
|
|
278
|
+
# The journal route reports its own configuration error. Other
|
|
279
|
+
# backend capabilities remain available while the file is repaired.
|
|
280
|
+
journal_subjects = []
|
|
287
281
|
return {
|
|
288
282
|
"status": "ok",
|
|
289
283
|
"version": app.version,
|
|
290
|
-
"journal_syllabus_subjects":
|
|
284
|
+
"journal_syllabus_subjects": journal_subjects,
|
|
291
285
|
"journal_syllabus_live_reload": True,
|
|
292
286
|
"code_review_before_submit": True,
|
|
293
287
|
"compact_code_review": True,
|
|
@@ -370,12 +364,12 @@ def clear_history():
|
|
|
370
364
|
|
|
371
365
|
async def try_groq(messages: list, model: str = None, temperature: float = 0.0, _token_limit: int = GROQ_COMPLETION_TOKEN_LIMIT, _review: bool = False) -> str:
|
|
372
366
|
"""Call Groq with automatic API key rotation on rate limit (429)."""
|
|
373
|
-
global _groq_disabled_until
|
|
367
|
+
global _groq_disabled_until, _groq_key_index
|
|
374
368
|
if time.monotonic() < _groq_disabled_until:
|
|
375
369
|
remaining = max(1, round(_groq_disabled_until - time.monotonic()))
|
|
376
370
|
raise RuntimeError(f"Groq temporarily disabled after an access failure ({remaining}s remaining)")
|
|
377
|
-
|
|
378
|
-
if not
|
|
371
|
+
clients = tuple(_groq_clients)
|
|
372
|
+
if not clients:
|
|
379
373
|
raise Exception("Groq client not configured — set GROQ_API_KEY in .env")
|
|
380
374
|
use_model = model or GROQ_TEXT_MODEL
|
|
381
375
|
loop = asyncio.get_running_loop()
|
|
@@ -387,9 +381,13 @@ async def try_groq(messages: list, model: str = None, temperature: float = 0.0,
|
|
|
387
381
|
if use_model in {'openai/gpt-oss-20b', 'openai/gpt-oss-120b'}:
|
|
388
382
|
review_options['reasoning_effort'] = 'low'
|
|
389
383
|
|
|
390
|
-
#
|
|
391
|
-
|
|
384
|
+
# Use a request-local order so another request cannot skip a backup key
|
|
385
|
+
# by advancing the preferred index while this call is in flight.
|
|
386
|
+
first_key = _groq_key_index % len(clients)
|
|
387
|
+
attempts = len(clients)
|
|
392
388
|
for attempt in range(attempts):
|
|
389
|
+
key_index = (first_key + attempt) % attempts
|
|
390
|
+
client = clients[key_index]
|
|
393
391
|
try:
|
|
394
392
|
response = await asyncio.wait_for(
|
|
395
393
|
loop.run_in_executor(
|
|
@@ -424,9 +422,11 @@ async def try_groq(messages: list, model: str = None, temperature: float = 0.0,
|
|
|
424
422
|
raise
|
|
425
423
|
# Check for rate limit (429) error
|
|
426
424
|
if "429" in err_str or "rate_limit" in err_str.lower() or "401" in err_str or "invalid_api_key" in err_str.lower():
|
|
427
|
-
if attempt + 1 < attempts
|
|
428
|
-
|
|
429
|
-
|
|
425
|
+
if attempt + 1 < attempts:
|
|
426
|
+
if _groq_key_index % attempts == key_index:
|
|
427
|
+
_groq_key_index += 1
|
|
428
|
+
next_key = (key_index + 1) % attempts
|
|
429
|
+
logger.info("Retrying %s with API key #%s (attempt %s/%s)", use_model, next_key + 1, attempt + 2, attempts)
|
|
430
430
|
continue
|
|
431
431
|
# Not a rate limit error or no more keys — re-raise
|
|
432
432
|
raise
|
|
@@ -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>
|