ó
    5ûojQ  ã                  óî   • S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
  SSKJr  SSKJrJr  SSKJr  SSKJrJr  SSKJr  SS	KJrJr   " S
 S\5      rSr\
 " S S\5      5       r " S S5      r " S S5      rg)uM  FootnoteLookup â€” finds footnote definitions the deterministic tiers missed.

A table can carry a reference marker whose footnote text sits beyond the
correction agent's crop and defeats the reading-order text scan (a text
layer that dropped the line, a definition set in a layout the leading-token
parse cannot see). This agent is the last tier: it gets the unresolved
markers and the rendered page images following the table, and returns the
definitions it can actually see printed â€” each as the marker plus its text.

Demand-driven by design: callers invoke it only for markers the pure
resolution (`quber.core.fusion.footnotes`) left unresolved, so a table whose
footnotes sit under it costs no model call. A failed call returns None and
the markers stay unresolved in the exception record; the lookup must never
take a run down with it.
é    )Úannotations)ÚAnyÚDictÚListÚOptionalÚProtocolÚSequenceÚruntime_checkable)Úlogger)Ú	BaseModelÚField)Úsupports_sampling_temperature)ÚLangSmithTracerÚusage_metadata_from)ÚFootnoteDef)ÚDEFAULT_LLM_MODELÚget_settingsc                  ó2   • \ rS rSr% Sr\" \SS9rS\S'   Sr	g)	ÚFootnoteLookupReporté   z;The definitions the agent found printed on the given pages.uÓ   One entry per requested marker whose printed definition is visible on the pages: the marker as requested, and the definition text as printed. Omit any marker whose definition you cannot see â€” never invent one.)Údefault_factoryÚdescriptionzList[FootnoteDef]Úfound© N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Úlistr   Ú__annotations__Ú__static_attributes__r   ó    Ú:/home/mande/repo/quber/src/quber/agents/footnote_lookup.pyr   r      s    ‡ ÙEá$ØðOñ €EÐö r#   r   u†  You find the printed FOOTNOTE DEFINITIONS for specific reference markers.

A table carries the footnote reference markers listed below, but their
definitions were not printed directly under the table. You are given the
rendered images of the pages that follow it. Somewhere on them there may be
footnote lines â€” each opening with its own marker (a superscript or
parenthesized number, letter, or symbol) followed by its text.

For EVERY requested marker, look for a printed footnote line whose own
marker matches it. Report each one you find: the marker exactly as
requested, and the definition text exactly as printed (without the leading
marker). Omit markers whose definition you cannot see on these pages â€”
return them missing rather than guessed. Never compose, summarize, or
invent text; only transcribe what is printed.

What is NOT a footnote definition:
- A row of a table. If the marker's number appears inside a table row â€”
  'Commitments and contingencies (Note 16)' â€” that row is table content,
  not a footnote line. Do not transcribe it.
- A cross-reference to a named section of the document ('Note 16',
  '(Note 8)', 'Schedule II', 'Addendum 3'). A section is a separate part
  of the document, not a footnote printed for this table; a marker whose
  only appearance is such a reference is reported missing.
- A section heading, a caption, or body prose that merely contains the
  number.
c                  ó2   • \ rS rSrSr        SS jrSrg)ÚFootnoteLookupéH   z:Finds printed footnote definitions for unresolved markers.c              ƒ  ó   #   • g 7f©Nr   ©ÚselfÚmarkersÚ	page_pngsÚpages       r$   ÚlookupÚFootnoteLookup.lookupL   s   é € à),ùs   ‚r   N©r,   zSequence[str]r-   zSequence[bytes]r.   ÚintÚreturnzOptional[FootnoteLookupReport])r   r   r   r   r   r/   r"   r   r#   r$   r&   r&   H   s*   † áDð-Ø$ð-Ø1@ð-ØHKð-à	'÷-r#   r&   c                  ób   • \ rS rSrSrSr   S	       S
S jjrSS jr        SS jrSr	g)ÚPydanticAIFootnoteLookupéQ   a  FootnoteLookup backed by pydantic-ai with an Anthropic vision model.

Mirrors `PydanticAIStatusInspector`: same auth resolution
(`ANTHROPIC_AUTH_TOKEN` preferred over `ANTHROPIC_API_KEY`), greedy
decoding so the same pages yield the same findings run to run.
g        Nc           	     óò  • SSK Jn  SSKJn  SSKJn  SSKJn  [        5       R                  nU=(       d    UR                  =(       d    [        nU=(       d    UR                  n	U=(       d    UR                  n
U	(       a  SSKJn  U" X5      nOU
(       a  U" U
S9nU" XS9nO[!        S	5      eXl
        U" U["        [$        ['        U5      (       a  U" U R(                  S
9OS S9U l        [-        SS9U l        g )Nr   )ÚAgent)ÚAnthropicModel)ÚAnthropicProvider)ÚModelSettings)Úmake_oauth_anthropic_model)Úapi_key)ÚproviderzxPydanticAIFootnoteLookup: neither ANTHROPIC_AUTH_TOKEN nor ANTHROPIC_API_KEY is set. Provide one via env or constructor.)Útemperature)Úoutput_typeÚsystem_promptÚmodel_settingszquber-footnote-lookup)Úrun_name)Úpydantic_air8   Úpydantic_ai.models.anthropicr9   Úpydantic_ai.providers.anthropicr:   Úpydantic_ai.settingsr;   r   ÚllmÚmodelr   Úanthropic_auth_tokenÚanthropic_api_keyÚquber.agents._oauth_gater<   ÚRuntimeErrorr   ÚLOOKUP_PROMPTr   ÚDEFAULT_TEMPERATUREÚagentr   Útracer)r+   rI   Ú
auth_tokenr=   r8   r9   r:   r;   Úllm_settingsÚresolved_authÚresolved_keyr<   Ú
anth_modelr>   s                 r$   Ú__init__Ú!PydanticAIFootnoteLookup.__init__[   sÖ   € õ 	&Ý?ÝEÝ6ä#“~×)Ñ)ˆØ×@˜×+Ñ+×@Ô/@ˆØ"×G l×&GÑ&GˆØ×@ ,×"@Ñ"@ˆæÝKá3°EÓI‰JÞÙ(°Ñ>ˆHÙ'¨ÑA‰JäðPóð ð
 Œ
ÙØÜ,Ü'ä,¨U×3Ñ3ñ )°T×5MÑ5MÒNàñ
ˆŒ
ô &Ð/FÑGˆ�r#   c                ó*   • SS[         S.SSUS./S./0$ )NÚmessagesÚsystem©ÚroleÚcontentÚuserÚtext)Útyper`   )rN   )r+   Ú	user_texts     r$   Útrace_inputsÚ%PydanticAIFootnoteLookup.trace_inputsƒ   s,   € àØ!¬mÑ<Ø°fÀiÑ-PÐ,QÑRðð
ð 	
r#   c              ƒ  óˆ  ^#   • SSK Jm  SSR                  S U 5       5      -   nU R                  U5      n U R                  R                  SXPR                  S9 IS h  v•N nU/nUR                  U4S jU 5       5        U R                  R                  U5      I S h  v•N nUR                  n	S	U	R                  5       S
./[        UR                  5      S.Ul        S S S 5      IS h  v•N   U	$  N’ NS N
! , IS h  v•N  (       d  f       W	$ = f! [         a"  n
[         R"                  " SUU
5         S n
A
g S n
A
ff = f7f)Nr   )ÚBinaryContentz9Find the printed footnote definitions for these markers: z, c              3  ó8   #   • U  H  n[        U5      v •  M     g 7fr)   )Úrepr)Ú.0Úms     r$   Ú	<genexpr>Ú2PydanticAIFootnoteLookup.lookup.<locals>.<genexpr>�   s   é € ð \
Ú$˜ŒD��GˆGšWùs   ‚Úfootnote_lookup)rI   c              3  ó2   >#   • U  H  nT" US S9v •  M     g7f)z	image/png)ÚdataÚ
media_typeNr   )ri   Úpngrf   s     €r$   rk   rl   —   s   øé € ÐdÒZcÐSV™}°#À+ÖNÒZcùs   ƒÚ	assistantr\   )rZ   Úusage_metadatazapage {}: the footnote lookup call failed; the markers stay unresolved in the exception record: {})rD   rf   Újoinrc   rQ   Úllm_runrI   ÚextendrP   ÚrunÚoutputÚmodel_dump_jsonr   ÚusageÚoutputsÚ	Exceptionr   Úwarning)r+   r,   r-   r.   rb   Úinputsrw   r^   ÚresultÚreportÚexcrf   s              @r$   r/   ÚPydanticAIFootnoteLookup.lookup‹   s&  øé € õ 	.àOÐRV×R[ÑR[ñ \
Ù$ó\
ó S
ñ 
ˆ	ð ×"Ñ" 9Ó-ˆð	Ø—{‘{×*Ñ*Ð+<¸fÏJÉJÐ*×WÑWÐ[^Ø&/ [�Ø—‘ÔdÑZcÓdÔdØ#Ÿz™zŸ~™~¨gÓ6×6�Ø/5¯}©}�à*5À&×BXÑBXÓBZÑ![Ð \Ü&9¸&¿,¹,Ó&Gñ�”÷ X×Wð ˆMñ Xñ 7÷ X×W×Wð ˆMûÜó 	Ü�NŠNð.àØô	ô ûð	üs”   ƒ3E·(D ÁC2Á D Á#=C8Â C4Â!?C8Ã D Ã+C6Ã,D Ã1EÃ2D Ã4C8Ã6D Ã8DÃ>DÃ?DÄD ÄEÄD Ä
D?ÄD:Ä5EÄ:D?Ä?E)rP   rI   rQ   )NNN)rI   úOptional[str]rR   rƒ   r=   rƒ   r3   ÚNone)rb   Ústrr3   zDict[str, Any]r1   )
r   r   r   r   r   rO   rW   rc   r/   r"   r   r#   r$   r5   r5   Q   su   † ñð Ðð  $Ø$(Ø!%ð	&Hàð&Hð "ð&Hð ð	&Hð
 
õ&HôP
ðØ$ðØ1@ðØHKðà	'÷r#   r5   c                  ó@   • \ rS rSrSrSSS jjr        S	S jrSrg)
ÚMockFootnoteLookupé©   zAReturns canned findings and records what it was asked. For tests.Nc                ó2   • U=(       d    / U l         / U l        g r)   )r   Úcalls)r+   r   s     r$   rW   ÚMockFootnoteLookup.__init__¬   s   € Ø—[˜bˆŒ
Ø+-ˆ�
r#   c              ƒ  ó’   #   • U R                   R                  [        U5      [        U5      US.5        [	        U R
                  S9$ 7f)N)r,   Úpagesr.   )r   )rŠ   Úappendr    Úlenr   r   r*   s       r$   r/   ÚMockFootnoteLookup.lookup°   s8   é € ð 	�
‰
×Ñ¤d¨7£m¼cÀ)»nÐVZÑ[Ô\Ü#¨$¯*©*Ñ5Ð5ùs   ‚AA)rŠ   r   r)   )r   zOptional[List[FootnoteDef]]r3   r„   r1   )r   r   r   r   r   rW   r/   r"   r   r#   r$   r‡   r‡   ©   s/   † ÙKö.ð6Ø$ð6Ø1@ð6ØHKð6à	'÷6r#   r‡   N)r   Ú
__future__r   Útypingr   r   r   r   r   r	   r
   Úlogurur   Úpydanticr   r   Úquber.agents.factoryr   Úquber.agents.langsmith_tracerr   r   Úquber.agents.llm_clientr   Úquber.settingsr   r   r   rN   r&   r5   r‡   r   r#   r$   Ú<module>r™      so   ðñõ  #ç S× SÑ Så ß %å >ß NÝ /ß :ô
˜9ô 
ð€ð: ô-�Xó -ó ð-÷Uñ U÷p6ò 6r#   