Ship DeepSeek roadmap P0-5/P2 integrations.
Smoke simple_project offline, reviewer shortest_path, library promotion gate, PDF drop logs, and per-stage cache hit-rate helper — without touching Layout placement packing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -104,3 +104,27 @@ class ApiLogger:
|
||||
|
||||
key = f"{project_prefix(user_id, project_id)}/api_logs.jsonl"
|
||||
storage.write_text(key, text)
|
||||
|
||||
|
||||
def cache_stats_by_stage(entries: list[dict]) -> dict[str, dict]:
|
||||
"""Roll up prompt-cache hit rate per pipeline stage.
|
||||
|
||||
Returns ``{stage: {calls, input_tokens, cache_read_tokens, hit_ratio}}``.
|
||||
``hit_ratio`` is cache_read / input when input > 0, else 0.
|
||||
"""
|
||||
out: dict[str, dict] = {}
|
||||
for e in entries:
|
||||
stage = str(e.get("stage") or "unknown")
|
||||
bucket = out.setdefault(
|
||||
stage,
|
||||
{"calls": 0, "input_tokens": 0, "cache_read_tokens": 0, "hit_ratio": 0.0},
|
||||
)
|
||||
bucket["calls"] += 1
|
||||
bucket["input_tokens"] += int(e.get("input_tokens") or 0)
|
||||
bucket["cache_read_tokens"] += int(e.get("cache_read_input_tokens") or 0)
|
||||
for bucket in out.values():
|
||||
inp = bucket["input_tokens"]
|
||||
bucket["hit_ratio"] = (
|
||||
round(bucket["cache_read_tokens"] / inp, 4) if inp else 0.0
|
||||
)
|
||||
return out
|
||||
|
||||
@@ -133,6 +133,16 @@ def render_pdf_page_jpegs(
|
||||
return []
|
||||
|
||||
try:
|
||||
total = len(doc)
|
||||
omitted = [i + 1 for i in range(total) if i not in set(page_indices)]
|
||||
if omitted:
|
||||
log.info(
|
||||
"PDF page images: %s rendering %d/%d pages; omitted e.g. %s",
|
||||
pdf_path.name,
|
||||
min(len(page_indices), max_pages),
|
||||
total,
|
||||
omitted[:12],
|
||||
)
|
||||
matrix = fitz.Matrix(zoom, zoom)
|
||||
for i in page_indices:
|
||||
if i < 0 or i >= len(doc):
|
||||
|
||||
@@ -839,10 +839,30 @@ async def _stage_ic_extraction(ctx: PipelineContext) -> None:
|
||||
api_logger=private,
|
||||
)
|
||||
|
||||
# Upload to storage, then copy to library
|
||||
# Upload to storage, then copy to library only if pintable is usable
|
||||
extracted_key = f"{ctx.ws.prefix}/extracted/{safe}.json"
|
||||
ctx.storage.upload_from_local(json_path, extracted_key)
|
||||
proj_svc.save_to_library(ctx.storage, extracted_key, "extracted", f"{safe}.json")
|
||||
try:
|
||||
from backend.pinscopex.library_gate import should_promote_extraction
|
||||
|
||||
payload = json.loads(json_path.read_text(encoding="utf-8"))
|
||||
ok, reason = should_promote_extraction(payload)
|
||||
if ok:
|
||||
proj_svc.save_to_library(
|
||||
ctx.storage, extracted_key, "extracted", f"{safe}.json",
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Skipping library promote for %s: %s (kept project-local)",
|
||||
mpn, reason,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Library gate failed for %s — promoting anyway", mpn,
|
||||
)
|
||||
proj_svc.save_to_library(
|
||||
ctx.storage, extracted_key, "extracted", f"{safe}.json",
|
||||
)
|
||||
|
||||
# Upload source datasheet PDF to library (content-addressed)
|
||||
store_datasheet(ctx.storage, pdf_path, mpn)
|
||||
|
||||
Reference in New Issue
Block a user