amfs-http-server 0.3.63__tar.gz → 0.3.64__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: amfs-http-server
3
- Version: 0.3.63
3
+ Version: 0.3.64
4
4
  Summary: AMFS HTTP/REST API server with SSE support
5
5
  License-Expression: Apache-2.0
6
6
  Requires-Python: >=3.11
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "amfs-http-server"
3
- version = "0.3.63"
3
+ version = "0.3.64"
4
4
  description = "AMFS HTTP/REST API server with SSE support"
5
5
  requires-python = ">=3.11"
6
6
  license = "Apache-2.0"
@@ -2088,6 +2088,87 @@ def entry_quality(
2088
2088
  }
2089
2089
 
2090
2090
 
2091
+ class QualityBatchItem(BaseModel):
2092
+ entity_path: str
2093
+ key: str
2094
+
2095
+
2096
+ class QualityBatchRequest(BaseModel):
2097
+ items: list[QualityBatchItem] = Field(..., max_length=2000)
2098
+ branch: str | None = None
2099
+
2100
+
2101
+ @app.post("/api/v1/quality/batch")
2102
+ def entry_quality_batch(
2103
+ request: Request,
2104
+ body: QualityBatchRequest,
2105
+ _auth: str | None = Depends(verify_api_key),
2106
+ ) -> dict[str, Any]:
2107
+ """Quality scores for many entries in one request.
2108
+
2109
+ The topic and agent pages used to ask ``/quality/{path}/{key}`` once per
2110
+ entry, and each of those listed the whole topic again to find the
2111
+ sibling keys — on a 365-entry topic that was 365 round trips of about a
2112
+ second each, serialised three at a time, before the page rendered. Here
2113
+ each topic is listed once and every requested key in it is scored from
2114
+ that one list. An entry that does not exist, or that the caller may not
2115
+ see, comes back with a null score rather than an error, so one bad key
2116
+ does not fail the page.
2117
+ """
2118
+ branch = _effective_branch(request, body.branch)
2119
+ mem = _get_memory()
2120
+ vis = _active_visibility_filter(request)
2121
+ evaluator = HeuristicQualityEvaluator()
2122
+
2123
+ wanted: dict[str, list[str]] = {}
2124
+ for item in body.items:
2125
+ wanted.setdefault(item.entity_path, []).append(item.key)
2126
+
2127
+ scores: dict[tuple[str, str], float | None] = {}
2128
+ for entity_path, keys in wanted.items():
2129
+ # Straight from the adapter, as the single route reads: ``mem.list``
2130
+ # on the server's own handle keeps only shared entries and the
2131
+ # server's, so another agent's private keys — which the topic page
2132
+ # already lists — would come back null. The caller's visibility
2133
+ # rule, applied below, is the only filter that belongs here.
2134
+ try:
2135
+ entries = mem._adapter.list(entity_path, branch=branch)
2136
+ except Exception:
2137
+ logger.debug("quality batch: list failed for %s", entity_path, exc_info=True)
2138
+ entries = []
2139
+ if vis is not None:
2140
+ entries = vis.filter_entries(entries)
2141
+ by_key = {e.key: e for e in entries}
2142
+ all_keys = list(by_key)
2143
+ for key in keys:
2144
+ entry = by_key.get(key)
2145
+ if entry is None:
2146
+ scores[(entity_path, key)] = None
2147
+ continue
2148
+ mt = (
2149
+ entry.memory_type.value
2150
+ if hasattr(entry.memory_type, "value")
2151
+ else str(entry.memory_type)
2152
+ )
2153
+ report = evaluator.evaluate(
2154
+ entry.value,
2155
+ entity_path=entity_path,
2156
+ key=key,
2157
+ confidence=entry.confidence,
2158
+ memory_type=mt,
2159
+ pattern_refs=list(entry.provenance.pattern_refs),
2160
+ existing_keys=[k for k in all_keys if k != key],
2161
+ )
2162
+ scores[(entity_path, key)] = report.score
2163
+
2164
+ return {
2165
+ "results": [
2166
+ {"entity_path": i.entity_path, "key": i.key, "score": scores[(i.entity_path, i.key)]}
2167
+ for i in body.items
2168
+ ]
2169
+ }
2170
+
2171
+
2091
2172
  async def _scope_block(
2092
2173
  entity_path: str,
2093
2174
  key: str,