@allansantos-dev/smart-tool 0.9.79 → 0.9.81
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/CHANGELOG.md +132 -0
- package/README.md +82 -18
- package/browser_control.py +10 -3
- package/browser_service_client.py +3 -32
- package/chromium_flags.py +30 -0
- package/client_hooks.py +10 -8
- package/code_health.py +182 -0
- package/code_impact.py +14 -2
- package/config.py +76 -8
- package/credential_check.py +38 -0
- package/dependency_notice.py +262 -14
- package/document_converter.py +221 -0
- package/document_read.py +100 -25
- package/document_text.py +194 -6
- package/dossier.py +71 -9
- package/embedding_cache.py +32 -8
- package/freshness.py +3 -2
- package/hook_decision.py +289 -18
- package/hooks/pretool_router.py +5 -4
- package/indexer.py +92 -3
- package/install.py +66 -27
- package/install_runtime.py +24 -10
- package/layer_check.py +57 -0
- package/link_check.py +69 -0
- package/local_embedder.py +115 -58
- package/locales/pt-BR.json +122 -18
- package/low_priority.py +41 -0
- package/model_client.py +1 -1
- package/model_health.py +24 -6
- package/notice_action.py +9 -0
- package/package.json +1 -1
- package/pr_comment.py +94 -0
- package/pr_impact.py +292 -8
- package/process_limits.py +108 -0
- package/project_admission.py +17 -15
- package/project_monitor.py +33 -7
- package/project_scheduler.py +12 -4
- package/removed_callers.py +146 -0
- package/scout.py +6 -2
- package/setup_audit.py +34 -1
- package/setup_ui.py +241 -41
- package/smart_tool_daemon.py +403 -91
- package/tray.py +29 -9
- package/update_check.py +18 -0
- package/update_splash.py +2 -2
- package/usage_meter.py +78 -0
- package/version.py +1 -1
- package/web_adapters/browser/crawl4ai_search.py +7 -3
- package/web_document_graph.py +12 -1
- package/web_fetch.py +24 -0
- package/web_search_health.py +31 -0
package/local_embedder.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Client of the embeddings home (casa-de-embeddings): the per-machine daemon that serves the embedder and forwards
|
|
2
|
+
rerank to the host the user configured in it.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
The home is found through its announce file. Its embedder is identified by the `model_sha256` and `dimension` of
|
|
5
|
+
`/info`, never by a model name. Measured in 2026-10-05 on the rerank gold set (42 code targets, no rerank,
|
|
6
|
+
docs/spikes/local_embedder_spike.py): granite-embedding-107m-multilingual on this client 42/35/41 (in pool / 1st /
|
|
7
|
+
top 5), MRR@5 0.892; the gateway's text-embedding-3-small 42/35/40, 0.885; lexical only 38/29/36, 0.767.
|
|
6
8
|
"""
|
|
7
9
|
import http.client
|
|
8
10
|
import json
|
|
@@ -18,37 +20,49 @@ import model_breaker
|
|
|
18
20
|
import model_health
|
|
19
21
|
|
|
20
22
|
PREFIX = "local:"
|
|
21
|
-
|
|
23
|
+
ANNOUNCE = os.path.join(os.path.expanduser("~"), ".casa-de-embeddings", "run", "daemon.json")
|
|
24
|
+
MIN_API_VERSION = 1
|
|
22
25
|
BATCH = 16
|
|
23
26
|
INFO_TTL_S = 60
|
|
24
27
|
MAX_ATTEMPTS = 3
|
|
25
28
|
REQUEST_TIMEOUT_S = 60
|
|
29
|
+
RERANK_TIMEOUT_S = 15
|
|
26
30
|
_lock = threading.Lock()
|
|
27
|
-
_info = {"at": 0.0, "value": None}
|
|
31
|
+
_info = {"at": 0.0, "value": None, "error": None}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class IdentityError(ValueError):
|
|
35
|
+
"""The home is announced or answers, but cannot be used as it is: a malformed announce file, an API version older
|
|
36
|
+
than this client needs, or an `/info` without `model_sha256` or `dimension`."""
|
|
28
37
|
|
|
29
38
|
|
|
30
39
|
def url():
|
|
31
|
-
"""
|
|
32
|
-
|
|
40
|
+
"""Base URL of the home from its announce file; None when the file does not exist (the home is not installed or
|
|
41
|
+
not running). A file that exists but cannot be read as an announce raises IdentityError. localhost becomes
|
|
42
|
+
127.0.0.1: on Windows ::1 is tried first and a daemon bound to IPv4 only costs about 2 s per connection."""
|
|
33
43
|
try:
|
|
34
|
-
with open(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
value = value.strip()
|
|
38
|
-
if key.strip() == "tei.url":
|
|
39
|
-
if not value or value.lower() == "off":
|
|
40
|
-
return None
|
|
41
|
-
parsed = urllib.parse.urlsplit(value.rstrip("/"))
|
|
42
|
-
if parsed.hostname == "localhost":
|
|
43
|
-
parsed = parsed._replace(netloc=parsed.netloc.replace("localhost", "127.0.0.1", 1))
|
|
44
|
-
return urllib.parse.urlunsplit(parsed)
|
|
45
|
-
except OSError:
|
|
44
|
+
with open(ANNOUNCE, encoding="utf-8") as stream:
|
|
45
|
+
data = json.load(stream)
|
|
46
|
+
except FileNotFoundError:
|
|
46
47
|
return None
|
|
47
|
-
|
|
48
|
+
except (OSError, ValueError) as exc:
|
|
49
|
+
raise IdentityError(f"The embeddings home announce file {ANNOUNCE} cannot be read ({exc}).") from None
|
|
50
|
+
base = str(data.get("url") or "").strip().rstrip("/") if isinstance(data, dict) else ""
|
|
51
|
+
parsed = urllib.parse.urlsplit(base)
|
|
52
|
+
if parsed.scheme not in ("http", "https") or not parsed.hostname:
|
|
53
|
+
raise IdentityError(f"The embeddings home announce file {ANNOUNCE} has no http(s) url.")
|
|
54
|
+
version = data.get("apiVersion")
|
|
55
|
+
if type(version) is not int or version < MIN_API_VERSION:
|
|
56
|
+
raise IdentityError(f"The embeddings home announces API version {version!r}; Smart Tool needs "
|
|
57
|
+
f"{MIN_API_VERSION} or later. Update the embeddings home.")
|
|
58
|
+
if parsed.hostname == "localhost":
|
|
59
|
+
parsed = parsed._replace(netloc=parsed.netloc.replace("localhost", "127.0.0.1", 1))
|
|
60
|
+
return urllib.parse.urlunsplit(parsed)
|
|
48
61
|
|
|
49
62
|
|
|
50
63
|
def configured():
|
|
51
|
-
|
|
64
|
+
"""Whether an announce file of the home exists (malformed counts: it raises at use, loudly)."""
|
|
65
|
+
return os.path.isfile(ANNOUNCE)
|
|
52
66
|
|
|
53
67
|
|
|
54
68
|
def _connection(base, timeout):
|
|
@@ -63,7 +77,9 @@ def _request(conn, method, path, body=None):
|
|
|
63
77
|
response = conn.getresponse()
|
|
64
78
|
data = response.read()
|
|
65
79
|
if response.status >= 400:
|
|
66
|
-
|
|
80
|
+
detail = data[:300].decode("utf-8", "replace").strip()
|
|
81
|
+
raise urllib.error.HTTPError(f"{conn.host}:{conn.port}{path}", response.status,
|
|
82
|
+
f"{response.reason}{': ' + detail if detail else ''}", response.headers, None)
|
|
67
83
|
return json.loads(data)
|
|
68
84
|
|
|
69
85
|
|
|
@@ -73,48 +89,87 @@ def _probe(base, timeout):
|
|
|
73
89
|
data = _request(conn, "GET", "/info")
|
|
74
90
|
finally:
|
|
75
91
|
conn.close()
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
digest = str(data.get("model_sha256") or "").strip().lower()
|
|
93
|
+
try:
|
|
94
|
+
dimensions = int(data.get("dimension") or 0)
|
|
95
|
+
except (TypeError, ValueError):
|
|
96
|
+
dimensions = 0
|
|
97
|
+
if not digest or dimensions <= 0:
|
|
98
|
+
raise IdentityError(f"The embeddings home at {base} answered /info without model_sha256 or dimension, so its "
|
|
99
|
+
"model cannot be identified; Smart Tool will not fall back to lexical search silently. "
|
|
100
|
+
"Update the embeddings home so /info reports model_sha256 and dimension.")
|
|
101
|
+
cpu = bool(data.get("demoted_to_cpu")) or str(data.get("provider") or "").startswith("CPU")
|
|
102
|
+
rerank_host = data.get("rerank_host") if isinstance(data.get("rerank_host"), dict) else {}
|
|
103
|
+
return {"model": f"{PREFIX}{digest[:16]}-{dimensions}", "name": data.get("model_id") or "", "dimensions": dimensions,
|
|
104
|
+
"url": base, "sha256": digest, "cpu": cpu, "rerank": rerank_host.get("configured") is True}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def runs_on_cpu(model):
|
|
108
|
+
"""Whether `model` is the home's embedder and the home computes on the CPU (no GPU, or demoted to the CPU)."""
|
|
109
|
+
return is_local(model) and bool((info() or {}).get("cpu"))
|
|
80
110
|
|
|
81
111
|
|
|
82
112
|
def info(timeout=1.5):
|
|
83
|
-
"""
|
|
84
|
-
|
|
113
|
+
"""Home /info cached for INFO_TTL_S; None when it is not announced or not answering. A home that is announced or
|
|
114
|
+
answers but cannot be used raises IdentityError. The probe runs under the lock so a slow failing probe never
|
|
115
|
+
overwrites a newer good answer."""
|
|
85
116
|
with _lock:
|
|
86
|
-
if time.monotonic() - _info["at"]
|
|
87
|
-
|
|
88
|
-
base, value = url(), None
|
|
89
|
-
if base:
|
|
117
|
+
if time.monotonic() - _info["at"] >= INFO_TTL_S:
|
|
118
|
+
value, error = None, None
|
|
90
119
|
try:
|
|
91
|
-
|
|
120
|
+
base = url()
|
|
121
|
+
if base:
|
|
122
|
+
value = _probe(base, timeout)
|
|
123
|
+
except IdentityError as exc:
|
|
124
|
+
error = exc
|
|
92
125
|
except (OSError, ValueError, http.client.HTTPException):
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
126
|
+
pass
|
|
127
|
+
_info.update(at=time.monotonic(), value=value, error=error)
|
|
128
|
+
if _info["error"]:
|
|
129
|
+
raise _info["error"]
|
|
130
|
+
return _info["value"]
|
|
96
131
|
|
|
97
132
|
|
|
98
133
|
def is_local(model):
|
|
99
134
|
return bool(model) and model.startswith(PREFIX)
|
|
100
135
|
|
|
101
136
|
|
|
102
|
-
def resolve(
|
|
103
|
-
"""Embedding model
|
|
137
|
+
def resolve(cfg=None, current=None):
|
|
138
|
+
"""Embedding model the index of a folder must be built with, following config `embedder`.
|
|
104
139
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if
|
|
111
|
-
|
|
140
|
+
`gateway` is the user's explicit choice: the gateway's `embedding_model`, or lexical without one. `home` (the
|
|
141
|
+
default) is the home's embedder. While the home is not running, an index the home can keep (its own, or lexical)
|
|
142
|
+
is kept as it is, so a restart of the home never triggers a rebuild to lexical and back; an index of another model
|
|
143
|
+
gives None: it keeps answering and is not updated, and re-embedding waits for the home. A folder without an index
|
|
144
|
+
is indexed lexically meanwhile. The gateway is never used in place of the home."""
|
|
145
|
+
cfg = cfg if cfg is not None else config.load_config()
|
|
146
|
+
if config.embedder(cfg) == "gateway":
|
|
147
|
+
return cfg.get("embedding_model") or indexer.LEXICAL_MODEL
|
|
112
148
|
available = info()
|
|
113
149
|
if available:
|
|
114
150
|
return available["model"]
|
|
115
|
-
if is_local(current):
|
|
116
|
-
return current
|
|
117
|
-
return
|
|
151
|
+
if not current or is_local(current) or current == indexer.LEXICAL_MODEL:
|
|
152
|
+
return current or indexer.LEXICAL_MODEL
|
|
153
|
+
return None
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def rerank_configured():
|
|
157
|
+
"""Whether the home reports a rerank host configured in it."""
|
|
158
|
+
return bool((info() or {}).get("rerank"))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def rerank(query, documents, top_n, deadline=None):
|
|
162
|
+
"""The home's `POST /rerank` answer in the canonical form `{results: [{index, relevance_score}]}`. The home forwards
|
|
163
|
+
to the host the user configured; an error answer raises, it is never replaced by another reranker."""
|
|
164
|
+
base = url()
|
|
165
|
+
if not base:
|
|
166
|
+
raise RuntimeError(f"The embeddings home is not running (no announce file at {ANNOUNCE}).")
|
|
167
|
+
timeout = RERANK_TIMEOUT_S if deadline is None else min(RERANK_TIMEOUT_S, _left(deadline))
|
|
168
|
+
conn = _connection(base, timeout)
|
|
169
|
+
try:
|
|
170
|
+
return _request(conn, "POST", "/rerank", {"query": query, "documents": documents, "top_n": top_n})
|
|
171
|
+
finally:
|
|
172
|
+
conn.close()
|
|
118
173
|
|
|
119
174
|
|
|
120
175
|
def _left(deadline):
|
|
@@ -128,7 +183,7 @@ def _left(deadline):
|
|
|
128
183
|
|
|
129
184
|
def _retry_delay(failure, attempt):
|
|
130
185
|
"""Seconds to wait after a failed attempt: the `Retry-After` of the answer (whole seconds, at most the pause of the
|
|
131
|
-
circuit) when the
|
|
186
|
+
circuit) when the home sent one, else the attempt number."""
|
|
132
187
|
value = str(getattr(failure, "headers", None) and failure.headers.get("Retry-After") or "")
|
|
133
188
|
return min(int(value), model_breaker.PAUSE_S) if value.isdigit() else attempt
|
|
134
189
|
|
|
@@ -136,16 +191,18 @@ def _retry_delay(failure, attempt):
|
|
|
136
191
|
def embed(model, texts, deadline=None, cancel_check=None, on_retry=None):
|
|
137
192
|
base = url()
|
|
138
193
|
if not base:
|
|
139
|
-
raise RuntimeError(f"
|
|
194
|
+
raise RuntimeError(f"The embeddings home is not running (no announce file at {ANNOUNCE}).")
|
|
140
195
|
# Fresh /info before and after: /embed does not echo the model, and a cached answer could let vectors of a
|
|
141
196
|
# different model reach the persistent vector cache under this model's contract.
|
|
142
197
|
try:
|
|
143
198
|
before = _probe(base, _left(deadline))
|
|
199
|
+
except IdentityError:
|
|
200
|
+
raise
|
|
144
201
|
except (OSError, ValueError, http.client.HTTPException) as exc:
|
|
145
|
-
raise RuntimeError(f"
|
|
202
|
+
raise RuntimeError(f"The embeddings home is not responding ({base}): {exc}") from None
|
|
146
203
|
if before["model"] != model:
|
|
147
204
|
raise indexer.IndexCompatibilityError(
|
|
148
|
-
f"The
|
|
205
|
+
f"The embeddings home now serves {before['model']}; the index was built with {model} and must be rebuilt.")
|
|
149
206
|
vectors = []
|
|
150
207
|
conn = _connection(base, _left(deadline))
|
|
151
208
|
try:
|
|
@@ -154,7 +211,7 @@ def embed(model, texts, deadline=None, cancel_check=None, on_retry=None):
|
|
|
154
211
|
for attempt in range(1, MAX_ATTEMPTS + 1):
|
|
155
212
|
if cancel_check:
|
|
156
213
|
cancel_check()
|
|
157
|
-
|
|
214
|
+
model_health.guard("/v1/embeddings", model)
|
|
158
215
|
conn.timeout = _left(deadline)
|
|
159
216
|
try:
|
|
160
217
|
with model_breaker.slot(model):
|
|
@@ -165,19 +222,19 @@ def embed(model, texts, deadline=None, cancel_check=None, on_retry=None):
|
|
|
165
222
|
conn.close()
|
|
166
223
|
conn = _connection(base, _left(deadline))
|
|
167
224
|
if attempt == MAX_ATTEMPTS:
|
|
168
|
-
raise RuntimeError(f"
|
|
225
|
+
raise RuntimeError(f"Embeddings home failed after {MAX_ATTEMPTS} attempts: {exc}") from None
|
|
169
226
|
if on_retry:
|
|
170
227
|
on_retry(attempt + 1, len(part))
|
|
171
228
|
delay = _retry_delay(exc, attempt)
|
|
172
229
|
if deadline is not None and time.monotonic() + delay >= deadline:
|
|
173
|
-
raise TimeoutError("Not enough time left to retry the
|
|
230
|
+
raise TimeoutError("Not enough time left to retry the embeddings home.") from None
|
|
174
231
|
time.sleep(delay)
|
|
175
232
|
else:
|
|
176
233
|
model_breaker.note(model)
|
|
177
234
|
model_health.record("/v1/embeddings", {"model": model})
|
|
178
235
|
break
|
|
179
236
|
if not isinstance(got, list) or len(got) != len(part):
|
|
180
|
-
raise indexer.IndexVectorError("
|
|
237
|
+
raise indexer.IndexVectorError("The embeddings home returned a vector count different from the input.")
|
|
181
238
|
for vector in got:
|
|
182
239
|
indexer.validate_vector(vector, before["dimensions"])
|
|
183
240
|
vectors += got
|
|
@@ -185,5 +242,5 @@ def embed(model, texts, deadline=None, cancel_check=None, on_retry=None):
|
|
|
185
242
|
conn.close()
|
|
186
243
|
after = _probe(base, _left(deadline))
|
|
187
244
|
if (after["model"], after.get("sha256")) != (before["model"], before.get("sha256")):
|
|
188
|
-
raise indexer.IndexCompatibilityError("The
|
|
245
|
+
raise indexer.IndexCompatibilityError("The embeddings home changed models during the call; try again.")
|
|
189
246
|
return vectors
|
package/locales/pt-BR.json
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"Keep mine, don't ask again": "Manter os meus, não perguntar de novo",
|
|
38
38
|
"Switch back to my previous models": "Voltar aos meus modelos anteriores",
|
|
39
39
|
"Model failures (last 24 h)": "Falhas de modelos (últimas 24 h)",
|
|
40
|
-
"Failed calls to a gateway model, grouped by type (429, 503, timeout, ...) and role, with the latest lines of each group. A model that fails half of its calls (5 or more) also raises a Windows notification.": "Chamadas com falha a um modelo do gateway, agrupadas por tipo (429, 503, tempo esgotado, ...) e função, com as linhas mais recentes de cada grupo. Um modelo que falha em metade das chamadas (5 ou mais) também gera uma notificação do Windows.",
|
|
40
|
+
"Failed calls to a gateway model, grouped by type (429, 503, timeout, ...) and role, with the latest lines of each group. A model that fails half of its calls (5 or more) also raises a Windows notification. Calls refused while a model is paused show as Circuit open and do not count toward that limit.": "Chamadas com falha a um modelo do gateway, agrupadas por tipo (429, 503, tempo esgotado, ...) e função, com as linhas mais recentes de cada grupo. Um modelo que falha em metade das chamadas (5 ou mais) também gera uma notificação do Windows. Chamadas recusadas enquanto um modelo está pausado aparecem como Circuito aberto e não contam para esse limite.",
|
|
41
41
|
"Any model id your gateway accepts. The gateway's catalog shows up as suggestions while you type.": "Qualquer id de modelo que o seu gateway aceite. O catálogo do gateway aparece como sugestões enquanto você digita.",
|
|
42
42
|
"<strong>Connect the gateway first.</strong> The catalog and the model choice open once the gateway answers.": "<strong>Conecte o gateway primeiro.</strong> O catálogo e a escolha do modelo abrem quando o gateway responde.",
|
|
43
43
|
"Connect the gateway first.": "Conecte o gateway primeiro.",
|
|
@@ -61,11 +61,7 @@
|
|
|
61
61
|
"Quick search time limit (s)": "Tempo limite da busca rápida (s)",
|
|
62
62
|
"How long a quick web search waits for its sources.": "Quanto tempo uma busca rápida na web espera pelas suas fontes.",
|
|
63
63
|
"Per-site memory similarity": "Similaridade da memória por site",
|
|
64
|
-
"How close a new question must be to a remembered page of the same site to reuse it.": "Quão parecida uma nova pergunta precisa ser de uma página lembrada do mesmo site para reaproveitá-la.",
|
|
65
64
|
"Save models": "Salvar modelos",
|
|
66
|
-
"3. Local models": "3. Modelos locais",
|
|
67
|
-
"Embedding from the mcp-memory sidecar on this machine. Switching between gateway and local rebuilds the project indexes; going back to a model used before reuses its vector cache.": "Embedding do sidecar mcp-memory neste computador. Alternar entre gateway e local reconstrói os índices dos projetos; voltar a um modelo usado antes reaproveita o cache de vetores.",
|
|
68
|
-
"When to use the local model": "Quando usar o modelo local",
|
|
69
65
|
"web_search asks several providers at once. All of them work without a key on their public free tier; add your own key only if you need more volume.": "web_search consulta vários provedores ao mesmo tempo. Todos funcionam sem chave no plano gratuito público; adicione a sua própria chave só se precisar de mais volume.",
|
|
70
66
|
"Providers": "Provedores",
|
|
71
67
|
"A key is tested with a real search before it is saved, and is protected by DPAPI in this Windows profile.": "Uma chave é testada com uma busca real antes de ser salva e fica protegida por DPAPI neste perfil do Windows.",
|
|
@@ -191,6 +187,7 @@
|
|
|
191
187
|
"Other 5xx": "Outro 5xx",
|
|
192
188
|
"Timeout": "Tempo esgotado",
|
|
193
189
|
"Connection": "Conexão",
|
|
190
|
+
"Circuit open": "Circuito aberto",
|
|
194
191
|
"Other": "Outro",
|
|
195
192
|
"Indexing": "Indexação",
|
|
196
193
|
"Query": "Consulta",
|
|
@@ -215,16 +212,6 @@
|
|
|
215
212
|
"Saving…": "Salvando…",
|
|
216
213
|
"Models saved.": "Modelos salvos.",
|
|
217
214
|
"Recommended": "Recomendado",
|
|
218
|
-
"Only as a fallback": "Só como alternativa",
|
|
219
|
-
"Use the local model only when the gateway does not have the embedding model.": "Use o modelo local apenas quando o gateway não tiver o modelo de embedding.",
|
|
220
|
-
"Prefer local": "Preferir local",
|
|
221
|
-
"Use the local model even when the gateway has it; your code vectors stay on this machine.": "Use o modelo local mesmo quando o gateway o tiver; os vetores do seu código ficam neste computador.",
|
|
222
|
-
"Never": "Nunca",
|
|
223
|
-
"Always use the gateway.": "Usar sempre o gateway.",
|
|
224
|
-
"Saved. The indexes adjust on the next search or check.": "Salvo. Os índices se ajustam na próxima busca ou verificação.",
|
|
225
|
-
"No sidecar on this machine": "Nenhum sidecar neste computador",
|
|
226
|
-
"Sidecar answering:": "Sidecar respondendo:",
|
|
227
|
-
"Sidecar not answering (": "Sidecar não responde (",
|
|
228
215
|
"Status unavailable": "Status indisponível",
|
|
229
216
|
"Redirect behavior": "Comportamento do redirecionamento",
|
|
230
217
|
"Applies on the next tool call.": "Vale na próxima chamada de ferramenta.",
|
|
@@ -674,7 +661,6 @@
|
|
|
674
661
|
"per-site memory similarity threshold": "limiar de similaridade da memória por site",
|
|
675
662
|
"Send the adapter and the field values in a JSON object.": "Envie o adaptador e os valores dos campos em um objeto JSON.",
|
|
676
663
|
"Setup page session token missing or invalid; open {0}/setup again.": "O token de sessão da página de configuração está ausente ou é inválido; abra {0}/setup de novo.",
|
|
677
|
-
"Invalid mode: use fallback, off or prefer.": "Modo inválido: use fallback, off ou prefer.",
|
|
678
664
|
"Invalid client: use claude or codex.": "Cliente inválido: use claude ou codex.",
|
|
679
665
|
"Invalid request.": "Requisição inválida.",
|
|
680
666
|
"Send the contact as text.": "Envie o contato como texto.",
|
|
@@ -812,7 +798,6 @@
|
|
|
812
798
|
", {0} with your key.": ", {0} com a sua chave.",
|
|
813
799
|
"{0}{1} your attention.": "{0}{1} da sua atenção.",
|
|
814
800
|
"{0}{1} Protected by DPAPI.": "{0}{1} Protegido pelo DPAPI.",
|
|
815
|
-
"Sidecar not answering ({0})": "Sidecar sem resposta ({0})",
|
|
816
801
|
"Not available on this machine ({0}). Pages are still read by web_fetch.": "Indisponível neste computador ({0}). As páginas continuam sendo lidas pelo web_fetch.",
|
|
817
802
|
"Registered at {0}. Gives the agent smart_search, web_search and web_fetch.": "Registrado em {0}. Dá ao agente smart_search, web_search e web_fetch.",
|
|
818
803
|
"Registering the MCP server in {0}…": "Registrando o servidor MCP no {0}…",
|
|
@@ -903,6 +888,10 @@
|
|
|
903
888
|
"{0} {1} (~{2} tokens)": "{0} {1} (~{2} tokens)",
|
|
904
889
|
"Checking the browsers…": "Verificando os navegadores…",
|
|
905
890
|
"View log": "Ver o log",
|
|
891
|
+
"Update now": "Atualizar agora",
|
|
892
|
+
"Open tray log": "Abrir o log da bandeja",
|
|
893
|
+
"There is no tray log yet.": "Ainda não há log da bandeja.",
|
|
894
|
+
"Could not open the log: {error}": "Não foi possível abrir o log: {error}",
|
|
906
895
|
"What changed": "O que mudou",
|
|
907
896
|
"Tip only, does not block": "Só dica, não bloqueia",
|
|
908
897
|
"Blocks": "Bloqueia",
|
|
@@ -910,7 +899,122 @@
|
|
|
910
899
|
"Tip only": "Só dica",
|
|
911
900
|
"Patterns you accepted (": "Padrões que você aceitou (",
|
|
912
901
|
"Patterns you accepted ({0})": "Padrões que você aceitou ({0})",
|
|
913
|
-
"{0} holds a setup audit of {1} from an older Smart Tool, whose findings have no fix: run project_manage action=setup_audit mode=run to replace it.": "{0} guarda uma auditoria da configuração de {1} feita por um Smart Tool mais antigo, cujos achados não trazem a correção: rode project_manage action=setup_audit mode=run para substituí-la."
|
|
902
|
+
"{0} holds a setup audit of {1} from an older Smart Tool, whose findings have no fix: run project_manage action=setup_audit mode=run to replace it.": "{0} guarda uma auditoria da configuração de {1} feita por um Smart Tool mais antigo, cujos achados não trazem a correção: rode project_manage action=setup_audit mode=run para substituí-la.",
|
|
903
|
+
"The embeddings home (casa-de-embeddings) is the embedding service of this machine, shared with other tools; its rerank connector forwards to the rerank host configured in it. Switching the embedder re-embeds each project in the background: the old index keeps answering until the new one is complete, then the old vectors are deleted.": "A casa de embeddings (casa-de-embeddings) é o serviço de embeddings desta máquina, compartilhado com outras ferramentas; o conector de rerank dela repassa ao host de rerank configurado nela. Trocar o embedder reembute cada projeto em segundo plano: o índice antigo continua respondendo até o novo ficar completo, e depois os vetores antigos são apagados.",
|
|
904
|
+
"Embedder for the project indexes": "Embedder dos índices dos projetos",
|
|
905
|
+
"Embeddings home": "Casa de embeddings",
|
|
906
|
+
"The embedding service of this machine; your code goes to the address it announces, not to the gateway.": "O serviço de embeddings desta máquina; seu código vai para o endereço que ela anuncia, não para o gateway.",
|
|
907
|
+
"The gateway's embedding_model and rerank_model; your code goes to the gateway.": "O embedding_model e o rerank_model do gateway; seu código vai para o gateway.",
|
|
908
|
+
"Saved. Each project is re-embedded in the background; its old index answers meanwhile.": "Salvo. Cada projeto é reembutido em segundo plano; o índice antigo responde enquanto isso.",
|
|
909
|
+
"Embeddings home not running": "Casa de embeddings não está rodando",
|
|
910
|
+
"Embeddings home not answering (": "Casa de embeddings não responde (",
|
|
911
|
+
"Gateway": "Gateway",
|
|
912
|
+
"Embeddings home answering:": "Casa de embeddings respondendo:",
|
|
913
|
+
"· rerank host configured": "· host de rerank configurado",
|
|
914
|
+
"Embeddings home not answering ({0})": "Casa de embeddings sem resposta ({0})",
|
|
915
|
+
"Invalid embedder: use home or gateway.": "Embedder inválido: use home ou gateway.",
|
|
916
|
+
"How close a new question must be to a remembered page of the same site to reuse it, with the gateway embedder; the embeddings home uses 0.62, measured on its model.": "Quão próxima uma pergunta nova precisa estar de uma página lembrada do mesmo site para reaproveitá-la, com o embedder do gateway; a casa de embeddings usa 0,62, medido no modelo dela.",
|
|
917
|
+
"Model use (last 30 days)": "Uso de modelos (últimos 30 dias)",
|
|
918
|
+
"Calls, failures and, when the gateway reports them, tokens and cost, per purpose and over every project. A purpose whose calls in one hour pass twice its own busiest hour of the previous week (and at least 100) is flagged here; it never raises a notification.": "Chamadas, falhas e, quando o gateway informa, tokens e custo, por finalidade e em todos os projetos. Uma finalidade cujas chamadas em uma hora passam do dobro da sua própria hora mais cheia da semana anterior (e de pelo menos 100) é sinalizada aqui; nunca gera notificação.",
|
|
919
|
+
"Volume alert": "Alerta de volume",
|
|
920
|
+
"Prompt tokens": "Tokens de entrada",
|
|
921
|
+
"Output tokens": "Tokens de saída",
|
|
922
|
+
"Reported cost": "Custo informado",
|
|
923
|
+
"No model call in the last 30 days.": "Nenhuma chamada de modelo nos últimos 30 dias.",
|
|
924
|
+
"volume alert": "alerta de volume",
|
|
925
|
+
"Could not read the usage meter:": "Não foi possível ler o medidor de uso:",
|
|
926
|
+
"Volume alert muted for 7 days.": "Alerta de volume silenciado por 7 dias.",
|
|
927
|
+
"Automatic updates": "Atualizações automáticas",
|
|
928
|
+
"Smart Tool checks npm at start and every 24 hours and, when this is on, installs a newer version by itself. The switch is the same as in the tray menu.": "O Smart Tool consulta o npm ao iniciar e a cada 24 horas e, com isto ligado, instala sozinho uma versão mais nova. A chave é a mesma do menu da bandeja.",
|
|
929
|
+
"Installed: {0}.": "Instalada: {0}.",
|
|
930
|
+
"Last check: {0}.": "Última verificação: {0}.",
|
|
931
|
+
"Not checked yet.": "Ainda não verificado.",
|
|
932
|
+
"Smart Tool is up to date.": "O Smart Tool está atualizado.",
|
|
933
|
+
"Updated from {0} to {1} on {2}.": "Atualizado da {0} para a {1} em {2}.",
|
|
934
|
+
"Automatic updates turned on.": "Atualizações automáticas ligadas.",
|
|
935
|
+
"Automatic updates turned off.": "Atualizações automáticas desligadas.",
|
|
936
|
+
"Send {\"enabled\": true or false}.": "Envie {\"enabled\": true ou false}.",
|
|
937
|
+
"{0}=off is set: automatic updates stay off until it is removed.": "{0}=off está definida: as atualizações automáticas ficam desligadas até removê-la.",
|
|
938
|
+
"Who asked the searches": "Quem pediu as buscas",
|
|
939
|
+
"The recent web search calls grouped by the client and project folder that made them. The text of a search is never recorded.": "As chamadas recentes de busca na web agrupadas pelo cliente e pela pasta do projeto que as fez. O texto de uma busca nunca é gravado.",
|
|
940
|
+
"Sessions": "Sessões",
|
|
941
|
+
"Attributed by": "Atribuído por",
|
|
942
|
+
"No web search recorded yet.": "Nenhuma busca na web registrada ainda.",
|
|
943
|
+
"Could not read the search log:": "Não foi possível ler o registro de buscas:",
|
|
944
|
+
"Calls that go up the layers on edit": "Chamadas que sobem as camadas na edição",
|
|
945
|
+
"When the project has confirmed layers (.smart-tool/layers.json), warns about a call an edit adds from a lower layer to a function of a higher one. A project without layers is never checked. It never blocks.": "Quando o projeto tem camadas confirmadas (.smart-tool/layers.json), avisa sobre uma chamada que a edição adiciona de uma camada inferior para uma função de uma superior. Projeto sem camadas nunca é verificado. Nunca bloqueia.",
|
|
946
|
+
"The edit runs; the agent is told which new calls go up the layers.": "A edição roda; o agente é avisado de quais chamadas novas sobem as camadas.",
|
|
947
|
+
"No layer checks.": "Sem verificação de camadas.",
|
|
948
|
+
"Broken local links on edit": "Links locais quebrados na edição",
|
|
949
|
+
"Checks the relative links (href, src, Markdown link targets) an edit of an HTML or Markdown file adds or changes against the files on disk, and says which ones it could not check. Links that were already broken are left alone. It never blocks.": "Confere os links relativos (href, src, destinos de link do Markdown) que a edição de um arquivo HTML ou Markdown adiciona ou altera com os arquivos do disco, e diz quais não conseguiu conferir. Links que já estavam quebrados são deixados em paz. Nunca bloqueia.",
|
|
950
|
+
"The edit runs; the agent is told which new links point to a file that does not exist.": "A edição roda; o agente é avisado de quais links novos apontam para um arquivo que não existe.",
|
|
951
|
+
"No link checks.": "Sem verificação de links.",
|
|
952
|
+
"Recorded decisions on edit": "Decisões registradas na edição",
|
|
953
|
+
"Looks up the notes of the project (docs/research, the backlog, CLAUDE.md and AGENTS.md) and its commit messages for the functions an edit touches, and names the ones that record a decision about them. A single-word function name counts only when a note qualifies it with its module or class. It never blocks.": "Procura nas notas do projeto (docs/research, o backlog, CLAUDE.md e AGENTS.md) e nas mensagens de commit as funções que a edição toca, e cita as que registram uma decisão sobre elas. Um nome de função de uma palavra só conta quando uma nota o qualifica com o módulo ou a classe. Nunca bloqueia.",
|
|
954
|
+
"The edit runs; the agent is told which notes and commits record a decision about a touched function.": "A edição roda; o agente é avisado de quais notas e commits registram uma decisão sobre uma função tocada.",
|
|
955
|
+
"No decision lookup.": "Sem busca de decisões.",
|
|
956
|
+
"{0} volume alert": "{0} alerta de volume",
|
|
957
|
+
"{0} volume alerts": "{0} alertas de volume",
|
|
958
|
+
"In {0}, move each listed package to a version past its advisories; project_manage action=deps lists every advisory ID.": "Em {0}, mova cada pacote listado para uma versão além dos seus avisos; project_manage action=deps lista cada ID de aviso.",
|
|
959
|
+
"dependency advisories": "avisos de dependências",
|
|
960
|
+
"Fix the cause named in the detail (OSV unreachable, or the advisory cache file), then run the audit again.": "Corrija a causa indicada no detalhe (OSV inacessível ou o arquivo de cache de avisos) e rode a auditoria de novo.",
|
|
961
|
+
"; {0} more": "; mais {0}",
|
|
962
|
+
"Impact report as a pull request comment": "Relatório de impacto como comentário de pull request",
|
|
963
|
+
"Applies on the next request of an agent.": "Vale no próximo pedido de um agente.",
|
|
964
|
+
"Lets Smart Tool post the impact report as a comment on a pull request through the gh CLI, with your own gh login. This writes to GitHub: nothing is ever posted while this is off, and each post is one agent request (project_manage action=pr_impact_comment). A rerun replaces the previous Smart Tool comment instead of adding another.": "Permite que o Smart Tool poste o relatório de impacto como comentário de um pull request pela CLI gh, com o seu próprio login do gh. Isto escreve no GitHub: nada é postado enquanto estiver desligado, e cada postagem é um pedido de um agente (project_manage action=pr_impact_comment). Repetir o pedido substitui o comentário anterior do Smart Tool em vez de acrescentar outro.",
|
|
965
|
+
"Nothing is posted to GitHub.": "Nada é postado no GitHub.",
|
|
966
|
+
"Agents may post the impact report as a comment on a pull request through the gh CLI.": "Os agentes podem postar o relatório de impacto como comentário de um pull request pela CLI gh.",
|
|
967
|
+
"Could not close the running Smart Tool ({count} process(es) still active).": "Não foi possível encerrar o Smart Tool em execução ({count} processo(s) ainda ativo(s)).",
|
|
968
|
+
"Another Smart Tool daemon is still active on the registered port; close it before updating.": "Outro daemon do Smart Tool ainda está ativo na porta registrada; encerre-o antes de atualizar.",
|
|
969
|
+
"Older Smart Tool installation found at {folder}; removing it.": "Instalação mais antiga do Smart Tool encontrada em {folder}; removendo.",
|
|
970
|
+
"Hooks in {path} now point to {target}.": "Os hooks em {path} agora apontam para {target}.",
|
|
971
|
+
"Old Camoufox builds not pruned: prune_camoufox.py exited {code}.": "Versões antigas do Camoufox não foram removidas: prune_camoufox.py terminou com o código {code}.",
|
|
972
|
+
"no output": "sem saída",
|
|
973
|
+
"Daemon did not respond: {detail}": "O daemon não respondeu: {detail}",
|
|
974
|
+
"Missing MCP tools: {tools}": "Ferramentas MCP ausentes: {tools}",
|
|
975
|
+
"The daemon runs version {running}, not the {expected} being installed": "O daemon executa a versão {running}, e não a {expected} que está sendo instalada",
|
|
976
|
+
"The active daemon (pid {pid}) does not belong to this installation: {command}": "O daemon ativo (pid {pid}) não pertence a esta instalação: {command}",
|
|
977
|
+
"Browser control not set up: {detail}": "Controle do navegador não configurado: {detail}",
|
|
978
|
+
"Browser control in {client}: {state}": "Controle do navegador em {client}: {state}",
|
|
979
|
+
"Could not read the Smart Tool settings, so the Windows language is used instead: {problem}": "Não foi possível ler as configurações do Smart Tool; o idioma do Windows será usado: {problem}",
|
|
980
|
+
"This package is Smart Tool {version}, not the {requested} requested; nothing was changed.": "Este pacote é o Smart Tool {version}, e não o {requested} pedido; nada foi alterado.",
|
|
981
|
+
"The target cannot be the source folder itself.": "A pasta de destino não pode ser a própria pasta de origem.",
|
|
982
|
+
"Tests skipped by --skip-tests.": "Testes ignorados por --skip-tests.",
|
|
983
|
+
"No test suite in {source}; a packaged install runs with --skip-tests (npx @allansantos-dev/smart-tool@{version} install).": "Não há suíte de testes em {source}; uma instalação a partir do pacote roda com --skip-tests (npx @allansantos-dev/smart-tool@{version} install).",
|
|
984
|
+
"Tests failed; installation aborted without touching the installed version.": "Os testes falharam; a instalação foi interrompida sem alterar a versão instalada.",
|
|
985
|
+
"Updating Smart Tool at {target} ({count} files from {source})": "Atualizando o Smart Tool em {target} ({count} arquivos de {source})",
|
|
986
|
+
"Installing Smart Tool at {target} ({count} files from {source})": "Instalando o Smart Tool em {target} ({count} arquivos de {source})",
|
|
987
|
+
"Removed the old copy {folder}.": "Cópia antiga {folder} removida.",
|
|
988
|
+
"Smart Tool ready.": "Smart Tool pronto.",
|
|
989
|
+
"Files installed; daemon not restarted (--no-start).": "Arquivos instalados; daemon não reiniciado (--no-start).",
|
|
990
|
+
"Could not remove the old copy {folder}: {error}": "Não foi possível remover a cópia antiga {folder}: {error}",
|
|
991
|
+
"Files changed: {changed}; removed as obsolete: {removed}": "Arquivos alterados: {changed}; removidos por obsolescência: {removed}",
|
|
992
|
+
"Dependencies unchanged since the last update; pip and install_runtime.py skipped.": "Dependências iguais às da última atualização; pip e install_runtime.py ignorados.",
|
|
993
|
+
"Failed: {error}. Restoring the previous version.": "Falhou: {error}. Restaurando a versão anterior.",
|
|
994
|
+
"Incomplete rollback; backup kept at {backup}: {problems}": "Restauração incompleta; cópia de segurança mantida em {backup}: {problems}",
|
|
995
|
+
"Downloading Node LTS for the Smart Tool web runtime...": "Baixando o Node LTS para o runtime web do Smart Tool...",
|
|
996
|
+
"Node {version} installed inside Smart Tool.": "Node {version} instalado dentro do Smart Tool.",
|
|
997
|
+
"Downloading Moli {version} (structured-first headless browser, 43 MB)...": "Baixando o Moli {version} (navegador headless que prioriza dados estruturados, 43 MB)...",
|
|
998
|
+
"Moli {version} installed inside Smart Tool.": "Moli {version} instalado dentro do Smart Tool.",
|
|
999
|
+
"{label}: starting (attempt {attempt} of {attempts})...": "{label}: iniciando (tentativa {attempt} de {attempts})...",
|
|
1000
|
+
"{label}: starting...": "{label}: iniciando...",
|
|
1001
|
+
"{label}: done.": "{label}: concluído.",
|
|
1002
|
+
"{error}; trying again.": "{error}; tentando de novo.",
|
|
1003
|
+
"{label}: waiting for {seconds}s...": "{label}: aguardando há {seconds}s...",
|
|
1004
|
+
"Smart Tool runtime installed: Node, open-websearch, TypeScript, Java, Angular, Playwright MCP, Camoufox, Crawl4AI and Moli.": "Runtime do Smart Tool instalado: Node, open-websearch, TypeScript, Java, Angular, Playwright MCP, Camoufox, Crawl4AI e Moli.",
|
|
1005
|
+
"Web runtime installation failed: {error}": "A instalação do runtime web falhou: {error}",
|
|
1006
|
+
"Not indexing {root}: it is {reason}. A project is the folder where the session started; pass that folder as project_root.": "Não estou indexando {root}: a pasta é {reason}. Um projeto é a pasta onde a sessão começou; passe essa pasta como project_root.",
|
|
1007
|
+
"Not indexing {root}: the session started in {home}, which is {home_reason}, not a project. Start the session inside the project folder.": "Não estou indexando {root}: a sessão começou em {home}, que não serve como projeto, pois é {home_reason}. Inicie a sessão dentro da pasta do projeto.",
|
|
1008
|
+
"Not indexing {root}: the session started in the project {home}, and a new project is indexed only from the session that started in it.": "Não estou indexando {root}: a sessão começou no projeto {home}, e um projeto novo só é indexado pela sessão que começou nele.",
|
|
1009
|
+
"a drive or filesystem root": "uma raiz de unidade ou do sistema de arquivos",
|
|
1010
|
+
"a personal folder, not a project": "uma pasta pessoal, não um projeto",
|
|
1011
|
+
"the temporary folder": "a pasta temporária",
|
|
1012
|
+
"inside a tool's hidden folder in the home folder": "uma pasta dentro da pasta oculta de uma ferramenta, na pasta do usuário",
|
|
1013
|
+
"a system or application folder": "uma pasta do sistema ou de aplicativos",
|
|
1014
|
+
"application data": "uma pasta de dados de aplicativo",
|
|
1015
|
+
"a build or dependency folder ({folder})": "uma pasta de build ou de dependências ({folder})",
|
|
1016
|
+
"a Java home": "uma pasta de instalação do Java",
|
|
1017
|
+
"inside the system temporary folder": "uma pasta dentro da pasta temporária do sistema"
|
|
914
1018
|
},
|
|
915
1019
|
"ignore": [
|
|
916
1020
|
"and {0} more",
|
package/low_priority.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Lowers the scheduling priority of the calling thread for a block, so a long index build on a machine without a GPU
|
|
2
|
+
leaves the processor to the user's own programs. Only Windows has a per-thread priority that can be put back; on any
|
|
3
|
+
other system the block runs unchanged (`current()` returns None)."""
|
|
4
|
+
import contextlib
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
BELOW_NORMAL = -1
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _kernel():
|
|
11
|
+
import ctypes
|
|
12
|
+
kernel = ctypes.windll.kernel32
|
|
13
|
+
kernel.GetCurrentThread.restype = ctypes.c_void_p
|
|
14
|
+
kernel.GetThreadPriority.argtypes = [ctypes.c_void_p]
|
|
15
|
+
kernel.SetThreadPriority.argtypes = [ctypes.c_void_p, ctypes.c_int]
|
|
16
|
+
return kernel
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def current():
|
|
20
|
+
"""Priority of the calling thread (0 is normal, -1 below normal); None where it cannot be read."""
|
|
21
|
+
if sys.platform != "win32":
|
|
22
|
+
return None
|
|
23
|
+
kernel = _kernel()
|
|
24
|
+
return kernel.GetThreadPriority(kernel.GetCurrentThread())
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@contextlib.contextmanager
|
|
28
|
+
def background():
|
|
29
|
+
"""Runs the block with the calling thread below normal priority and restores the previous one afterwards."""
|
|
30
|
+
if sys.platform != "win32":
|
|
31
|
+
yield
|
|
32
|
+
return
|
|
33
|
+
kernel = _kernel()
|
|
34
|
+
thread = kernel.GetCurrentThread()
|
|
35
|
+
previous = kernel.GetThreadPriority(thread)
|
|
36
|
+
if not kernel.SetThreadPriority(thread, BELOW_NORMAL):
|
|
37
|
+
raise OSError("SetThreadPriority failed; the index build cannot run at low priority.")
|
|
38
|
+
try:
|
|
39
|
+
yield
|
|
40
|
+
finally:
|
|
41
|
+
kernel.SetThreadPriority(thread, previous)
|
package/model_client.py
CHANGED
|
@@ -32,7 +32,7 @@ def fetch(path, token, method="GET", body=None, timeout=15):
|
|
|
32
32
|
if OFFLINE.get():
|
|
33
33
|
raise RuntimeError(OFFLINE.get())
|
|
34
34
|
model=body.get("model") if isinstance(body,dict) else None
|
|
35
|
-
|
|
35
|
+
model_health.guard(path,model)
|
|
36
36
|
with model_breaker.slot(model):
|
|
37
37
|
started=time.monotonic();result=None;headers=None;failure=None
|
|
38
38
|
try:
|
package/model_health.py
CHANGED
|
@@ -14,6 +14,7 @@ import sqlite3
|
|
|
14
14
|
import time
|
|
15
15
|
|
|
16
16
|
import config
|
|
17
|
+
import model_breaker
|
|
17
18
|
import project_store
|
|
18
19
|
import usage_meter
|
|
19
20
|
|
|
@@ -34,6 +35,7 @@ _PURPOSE_ROLE = {"scope": "scope_model", "scout": "scout_model", "docs": "docs_m
|
|
|
34
35
|
_TOOL = contextvars.ContextVar("model_health_tool", default=None)
|
|
35
36
|
_COLLECTED = contextvars.ContextVar("model_health_collected", default=None)
|
|
36
37
|
_SCHEMA = set()
|
|
38
|
+
_CIRCUIT_OPEN = model_breaker.CircuitOpen.__name__ + ":"
|
|
37
39
|
_STATUS = re.compile(r"HTTP(?: Error)? (\d{3})")
|
|
38
40
|
_TIMEOUT = re.compile(r"timed out|timeout|WinError 10060|Errno 110\b", re.I)
|
|
39
41
|
_CONNECTION = re.compile(r"URLError|ConnectionError|ConnectionRefused|ConnectionReset|refused|reset|getaddrinfo|"
|
|
@@ -68,8 +70,11 @@ def _tables(db):
|
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
def classify(error):
|
|
71
|
-
"""Failure type of a stored error text: '
|
|
72
|
-
'connection' or 'other'. An HTTP status in the text wins over words in the
|
|
73
|
+
"""Failure type of a stored error text: 'circuit_open' (refused while the model is paused), '429', '503', '5xx' (any
|
|
74
|
+
other 5xx), 'auth' (401/403), 'timeout', 'connection' or 'other'. An HTTP status in the text wins over words in the
|
|
75
|
+
response body, except that the pause text names the 429/503 that opened it."""
|
|
76
|
+
if (error or "").startswith(_CIRCUIT_OPEN):
|
|
77
|
+
return "circuit_open"
|
|
73
78
|
status = _STATUS.search(error or "")
|
|
74
79
|
if status:
|
|
75
80
|
code = int(status.group(1))
|
|
@@ -107,8 +112,19 @@ def error_text(exc):
|
|
|
107
112
|
return " ".join(text.split())[:ERROR_CHARS]
|
|
108
113
|
|
|
109
114
|
|
|
115
|
+
def guard(path, model):
|
|
116
|
+
"""`model_breaker.guard` that also logs the refusal, then re-raises it."""
|
|
117
|
+
try:
|
|
118
|
+
model_breaker.guard(model)
|
|
119
|
+
except model_breaker.CircuitOpen as refusal:
|
|
120
|
+
record(path, {"model": model}, refusal)
|
|
121
|
+
raise
|
|
122
|
+
|
|
123
|
+
|
|
110
124
|
def record(path, body, failure=None):
|
|
111
|
-
"""Counts one model call and, when it failed, logs it.
|
|
125
|
+
"""Counts one model call and, when it failed, logs it. A `CircuitOpen` refusal sent nothing: it is logged in the
|
|
126
|
+
failure table only, so it is neither a call nor an error of the rate and never reaches the tool answer's warning
|
|
127
|
+
(the search already says the model is paused). Never raises: the log must not change the call's result."""
|
|
112
128
|
if path not in _PATHS:
|
|
113
129
|
return
|
|
114
130
|
try:
|
|
@@ -116,17 +132,19 @@ def record(path, body, failure=None):
|
|
|
116
132
|
role = role_of(model, purpose=usage_meter.purpose())
|
|
117
133
|
now = time.time()
|
|
118
134
|
text = error_text(failure) if failure is not None else None
|
|
135
|
+
refused = isinstance(failure, model_breaker.CircuitOpen)
|
|
119
136
|
with project_store._LOCK, _db() as db:
|
|
120
137
|
_tables(db)
|
|
121
|
-
|
|
122
|
-
|
|
138
|
+
if not refused:
|
|
139
|
+
db.execute("INSERT INTO model_calls VALUES(?,?,?,1,?) ON CONFLICT(hour,model,role) DO UPDATE SET "
|
|
140
|
+
"calls=calls+1,errors=errors+excluded.errors", (int(now // 3600), model, role, int(text is not None)))
|
|
123
141
|
if text is not None:
|
|
124
142
|
db.execute("INSERT INTO model_failures VALUES(?,?,?,?,?,?)", (now, model, role, _TOOL.get() or "", path, text))
|
|
125
143
|
db.execute("DELETE FROM model_failures WHERE at<? OR rowid NOT IN "
|
|
126
144
|
"(SELECT rowid FROM model_failures ORDER BY at DESC LIMIT ?)", (now - KEEP_S, KEEP_FAILURES))
|
|
127
145
|
db.execute("DELETE FROM model_calls WHERE hour<?", (int((now - KEEP_S) // 3600),))
|
|
128
146
|
collected = _COLLECTED.get()
|
|
129
|
-
if text is not None and collected is not None:
|
|
147
|
+
if text is not None and collected is not None and not refused:
|
|
130
148
|
collected.append({"model": model, "role": role, "error": text})
|
|
131
149
|
except Exception:
|
|
132
150
|
pass
|