ó
    À‘´j  ã                  óì   • S r SSKJr  SSKrSSKrSSKJr  SSKJrJ	r	J
r
  SSKJr  SSKJr  SSKJrJrJrJr  SS	KJr  SS
KJr  SrSrSrSr\\4         SS jjr  S             SS jjrg)uw  Scan one page: submit it whole, read the figures and the page text back.

A nominated page is submitted on its own, as a one-page PDF. Billing is per
submitted page, so scanning six pages one at a time costs exactly what
submitting the six together would, and submitting per page is what makes the
response per page: one submission covering several pages returns a single
payload for all of them, and the fields that identify a scan â€” the job, the
model version, the credits â€” are document-level and would not divide.

The whole page goes in, not a crop of the chart. A chart's title is printed
above it and its note at the foot of the page, and both are only related to the
chart by where they sit, so cropping to the chart discards them and tiling
several charts onto one composite page destroys the arrangement that relates
them.

`page_scan` turns one dpt-2 response, a flat `chunks` list, into the record for
that page. Every figure becomes a chart record, every table becomes a grid with
a box on each of its cells, and every text and marginalia chunk is kept
alongside them â€” that is where the titles and the notes are. A response from a
dpt-3 model, the default, has a different shape and is read by
`quber.core.figures.dpt3` instead.

Nothing filters on what a chunk contains, so a figure that is not a chart still
becomes a record. A page's logo comes back as a figure of its own, and on a
branded deck that means a record per page on top of the charts. Reading the text
to decide which figures are charts would mean writing a rule against
descriptions that have no fixed shape, and the cost of a wrong rule is a
silently discarded chart.
é    )ÚannotationsN)ÚPath)ÚAnyÚListÚOptional)Úlogger)Úscanned_tables)ÚChartContextÚFigureRecordÚPageScanÚ
PageStatus)Ú
slice_page)Úparse_documentzdpt-3-pro-20260710g       @aC  This page comes from a financial document. If the figure is a chart, read its plotted values, its axis labels and units, and its legend. A number or symbol in superscript refers to a note that is often printed on another page and so is not visible here; report the superscript as printed and do not guess what it refers to.)ÚtextÚ
marginaliac           
   ƒ  ót  #   • [         R                  " SS9 n[        R                  " [        X[        U5      SU S3-  5      I Sh  v•N n[        R                  " SU R                  U5        [        R                  " [        UUS[        0U5      I Sh  v•N sSSS5        $  N[ N! , (       d  f       g= f7f)zMSubmit page `page` of `source` as a one-page PDF and return the raw response.zquber-chart-)ÚprefixÚpz.pdfNz"Figure scan: submitting {} page {}Úfigure)ÚtempfileÚTemporaryDirectoryÚasyncioÚ	to_threadr   r   r   ÚinfoÚnamer   ÚCHART_FIGURE_PROMPT)ÚsourceÚpageÚmodelÚpoll_secondsÚtmpÚ	submitteds         Ú5/home/mande/repo/quber/src/quber/core/figures/scan.pyÚ	scan_pager$   N   s™   é € ô 
×	$Ò	$¨NÒ	;¸sÜ!×+Ò+¬J¸ÄdÈ3ÃiÐTUÐVZÐU[Ð[_ÐR`ÑF`Óa×aˆ	Ü�ŠÐ8¸&¿+¹+ÀtÔLÜ×&Ò&ÜØØØÔ*Ð+Øó
÷ 
÷ 
<Ñ	;Ùañ
÷ 
<Õ	;üsA   ‚B8—0B'ÁB#ÁAB'ÂB%ÂB'Â
B8Â#B'Â%B'Â'
B5Â1B8c                óJ  • U R                  S5      =(       d    0 nUR                  S5      n/ n/ n	U R                  S5      =(       d    /  H¿  n
U
R                  S5      nU
R                  S5      =(       d    0 nUR                  S5      nU
R                  S5      =(       d    SnUS	:X  a+  UR                  [        XXÚR                  S
5      US95        MŠ  U[        ;   d  M–  U	R                  [	        XXíU
R                  S
5      S95        MÁ     [        XU5      nUR                  S5      nUc)  UR                  S5      =(       d    0 R                  S5      nU(       a  SO
U(       a  SOSn[        UUUUUUR                  S5      =(       d    UR                  S5      UUUUUU	S9$ )zïBuild the record for one scanned page from its raw response.

`page` is the source page number the submission came from. The response
numbers its own single page from zero, so the source page is carried in
rather than read back out of it.
ÚmetadataÚjob_idÚchunksÚtypeÚ	groundingÚboxÚmarkdownÚ r   Úid)r   r   r+   Úchunk_idr'   )r   Úkindr   r+   r/   Úcredit_usageÚbillingÚtotal_creditsÚfiguresÚtablesÚemptyÚversionÚmodel_version)r   ÚstatusÚpicture_classesr'   r   r7   ÚcreditsÚreusedÚresponse_artifactr4   r5   Úcontext)ÚgetÚappendr   ÚCONTEXT_TYPESr
   r	   r   )Úresponser   r   r:   r=   r<   Úmetar'   r4   r>   Úchunkr0   r*   r+   r   r5   r;   r9   s                     r#   Ú	page_scanrE   a   su  € ð �<‰<˜
Ó#×) r€DØ�X‰X�hÓ€FØ"$€GØ"$€GØ—‘˜hÓ'×-¨2Ò-ˆØ�y‰y˜Ó ˆØ—I‘I˜kÓ*×0¨bˆ	Ø�m‰m˜EÓ"ˆØ�y‰y˜Ó$×*¨ˆØ�8ÓØ�N‰NÜ $°sÇYÁYÈtÃ_Ð]cÑdöð ”]Õ"Ø�N‰Nœ<¨TÀ4Ð[`×[dÑ[dÐeiÓ[jÑkÖlñ .ô ˜H¨FÓ3€Fà�h‰h�~Ó&€GØ�Ø—8‘8˜IÓ&×,¨"×1Ñ1°/ÓBˆÞ&-™¾v±8È7€FÜØØØ'ØØØ—‘˜Ó#×@ t§x¡x°Ó'@ØØØ+ØØØñð ó    )
r   r   r   Úintr   Ústrr    ÚfloatÚreturnúdict[str, Any])NF)rB   rK   r   rG   r   rH   r:   z	List[str]r=   zOptional[str]r<   ÚboolrJ   r   )Ú__doc__Ú
__future__r   r   r   Úpathlibr   Útypingr   r   r   Úlogurur   Úquber.core.figures.gridr	   Úquber.core.figures.modelsr
   r   r   r   Úquber.files.pdfr   Úquber.providers.landing.clientr   ÚSCAN_DEFAULT_MODELÚPAGE_POLL_SECONDSr   rA   r$   rE   © rF   r#   Ú<module>rY      sÜ   ðñõ< #ã Û Ý ß &Ñ &å å 2ß VÓ VÝ &Ý 9ð *Ð ð Ð ðZð ð '€ð $Ø+ð	
Øð
à
ð
ð ð
ð ð	
ð
 õ
ð0 (,Øð1Øð1à
ð1ð ð1ð ð	1ð
 %ð1ð ð1ð ö1rF   