promptfoo 0.121.3 → 0.121.5
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/README.md +1 -1
- package/dist/src/{ListApp-Du7YVwj5.js → ListApp-BRUsT43Y.js} +1 -1
- package/dist/src/{accounts-BPyfpSeU.cjs → accounts-BIFntVWB.cjs} +5 -5
- package/dist/src/{accounts-CFLK3mnD.js → accounts-CLJHCDDb.js} +6 -6
- package/dist/src/{accounts-B2XmGjty.js → accounts-CaLNYnf7.js} +5 -5
- package/dist/src/{accounts-Xatc0RYb.js → accounts-bnyHT7Ju.js} +5 -5
- package/dist/src/{agentic-utils-36epdqwB.js → agentic-utils-B5krlibj.js} +3 -3
- package/dist/src/{agentic-utils-DIYAAYE7.js → agentic-utils-Ba67xmgs.js} +3 -3
- package/dist/src/{agentic-utils-D8yXo5Lm.js → agentic-utils-BclbiXiq.js} +4 -4
- package/dist/src/{agentic-utils-DAVsChuB.cjs → agentic-utils-D2x0wGhB.cjs} +3 -3
- package/dist/src/{agents-CLQ-P15P.js → agents-BGqaTDnr.js} +5 -7
- package/dist/src/{agents-wg3ohknq.js → agents-BV9yFpXX.js} +6 -7
- package/dist/src/{agents-CgBniSlI.js → agents-BYdMl1UE.js} +5 -9
- package/dist/src/{agents-Bqgfdokm.js → agents-DhxWMCtH.js} +35 -14
- package/dist/src/{agents-BBWxKSM0.cjs → agents-DiWmQYH9.cjs} +5 -7
- package/dist/src/{agents-CAYbM7qD.cjs → agents-WULPVjbH.cjs} +34 -12
- package/dist/src/{agents-DSSTV4bv.js → agents-emVcx3yh.js} +35 -13
- package/dist/src/{agents-BBVJCIYr.js → agents-n6vPqV3i.js} +35 -13
- package/dist/src/{aimlapi-BwGC1TtS.js → aimlapi-BxqK9HF_.js} +8 -14
- package/dist/src/{aimlapi-Bv8Fmc-b.cjs → aimlapi-BzLjZI_m.cjs} +8 -15
- package/dist/src/{aimlapi-MgSLdvy7.js → aimlapi-DR4pgeiC.js} +7 -14
- package/dist/src/{aimlapi-DaC3qZ-o.js → aimlapi-uPGp0Zdo.js} +7 -16
- package/dist/src/app/app/tsconfig.app.tsbuildinfo +1 -0
- package/dist/src/app/assets/Report-vjzrbgce.js +1 -0
- package/dist/src/app/assets/index-B3NQ8HTd.js +385 -0
- package/dist/src/app/assets/index-Cli2yAXv.css +1 -0
- package/dist/src/app/assets/rolldown-runtime-COnpUsM8.js +1 -0
- package/dist/src/app/assets/scroll-timeline-D9IT_e8Z.js +1 -0
- package/dist/src/app/assets/sync-IjzpWrOE.js +4 -0
- package/dist/src/app/assets/vendor-charts-BNdH8TCw.js +36 -0
- package/dist/src/app/assets/vendor-markdown-Ch00wnNI.js +29 -0
- package/dist/src/app/assets/vendor-react-CVvmk1UB.js +9 -0
- package/dist/src/app/assets/vendor-utils-BnEYbx2Q.js +37 -0
- package/dist/src/app/index.html +32 -7
- package/dist/src/{audio-Bn44pQxv.js → audio-BvpTOArF.js} +4 -4
- package/dist/src/{audio-DVFjQ67_.cjs → audio-C0vDeS0j.cjs} +4 -4
- package/dist/src/{audio-DjU9GswO.js → audio-CScmnmEB.js} +4 -5
- package/dist/src/{audio-DDA5WHdx.js → audio-Da8U9IS5.js} +4 -4
- package/dist/src/{base-CKjwebIH.js → base-BOMaNEes.js} +3 -3
- package/dist/src/{base-CqzQ4K8j.js → base-BTux96b1.js} +3 -3
- package/dist/src/{base-BboXIF_0.cjs → base-Tw6uhH8K.cjs} +3 -3
- package/dist/src/{base-Cz2ZC_iA.js → base-dYsl2hmL.js} +3 -3
- package/dist/src/{blobs-C6j0bvFz.cjs → blobs-B95F_7vE.cjs} +3 -3
- package/dist/src/{blobs-DXTl6J3H.js → blobs-BW4U31ue.js} +3 -3
- package/dist/src/{blobs-BUWmKWzo.js → blobs-D_gg8nbm.js} +4 -4
- package/dist/src/{blobs-B1JriOyi.js → blobs-DjLby-uP.js} +4 -4
- package/dist/src/cache-BI5BY7ey.js +280 -0
- package/dist/src/cache-BRkhlH3k.cjs +3 -0
- package/dist/src/cache-BlC6aeJ0.js +3 -0
- package/dist/src/cache-Bzttsk0X.js +310 -0
- package/dist/src/cache-Cr-qWIbP.js +310 -0
- package/dist/src/cache-DGg-yTZG.cjs +376 -0
- package/dist/src/{chat-BEwdgGEg.js → chat-BLOdH60v.js} +63 -37
- package/dist/src/{chat-B0iaWhoh.js → chat-Cx_LkwvZ.js} +63 -37
- package/dist/src/{chat-DK1U-eZ-.js → chat-D9nudO9b.js} +5 -14
- package/dist/src/{chat-pxmiVpWe.js → chat-DChSH_Es.js} +63 -37
- package/dist/src/{chat-B-52XYI1.js → chat-DG2LkwLq.js} +3 -13
- package/dist/src/{chat-BtIKkLKx.cjs → chat-DH97tVV9.cjs} +3 -13
- package/dist/src/{chat-BE0qTA8e.js → chat-aMQZw6R7.js} +4 -16
- package/dist/src/{chat-CM8qWR3_.cjs → chat-vYqqv1gP.cjs} +64 -38
- package/dist/src/{chatkit-_8eJqKcD.js → chatkit-B8X34dQc.js} +4 -4
- package/dist/src/{chatkit-BYGQlHlV.js → chatkit-BXu42Qwt.js} +4 -4
- package/dist/src/{chatkit-a2D6mY6s.js → chatkit-CbMRoeYw.js} +4 -4
- package/dist/src/{chatkit-Cx174XI3.cjs → chatkit-D44VyUyB.cjs} +4 -4
- package/dist/src/{claude-agent-sdk-8ddRp1L2.cjs → claude-agent-sdk-BRq0bbIK.cjs} +23 -18
- package/dist/src/{claude-agent-sdk-CMjh4LFH.js → claude-agent-sdk-BjriSVRZ.js} +20 -15
- package/dist/src/{claude-agent-sdk-HgbFioFw.js → claude-agent-sdk-BzNZeZ0N.js} +20 -15
- package/dist/src/{claude-agent-sdk-Bq5EArsX.js → claude-agent-sdk-DYv_AJ8u.js} +21 -17
- package/dist/src/cloud-CoD5OacT.js +3 -0
- package/dist/src/{cloud-z8KZpUoa.js → cloud-Da0bofJd.js} +25 -13
- package/dist/src/{cloudflare-ai-Bbp26N0L.js → cloudflare-ai-CXC4b1EU.js} +5 -14
- package/dist/src/{cloudflare-ai-BGyXlpXJ.js → cloudflare-ai-CyBoIs1Q.js} +7 -15
- package/dist/src/{cloudflare-ai-DdKP9TKT.js → cloudflare-ai-DGOwgexC.js} +6 -17
- package/dist/src/{cloudflare-ai-C62x6MQG.cjs → cloudflare-ai-DJv5qnyb.cjs} +6 -15
- package/dist/src/{cloudflare-gateway-DXhtXDRb.js → cloudflare-gateway-1sAoOyft.js} +6 -16
- package/dist/src/{cloudflare-gateway-D-e9i1Sn.js → cloudflare-gateway-D-dnkzCF.js} +5 -18
- package/dist/src/{cloudflare-gateway-Dx36ftqF.cjs → cloudflare-gateway-DKVjkDav.cjs} +4 -15
- package/dist/src/{cloudflare-gateway-BwAaUgeW.js → cloudflare-gateway-TJkVrZlB.js} +4 -15
- package/dist/src/codex-app-server-CCLjqCh9.js +1915 -0
- package/dist/src/codex-app-server-CCe0TiDc.js +1915 -0
- package/dist/src/codex-app-server-CPW1LFwh.js +1916 -0
- package/dist/src/codex-app-server-VMRnjZ68.cjs +1920 -0
- package/dist/src/codex-sdk-1jm_qPHf.js +3 -0
- package/dist/src/codex-sdk-Bd8UbO9q.cjs +1172 -0
- package/dist/src/codex-sdk-BgEFQ70r.js +1164 -0
- package/dist/src/codex-sdk-Bzb_TqX9.js +1165 -0
- package/dist/src/codex-sdk-Danroptg.cjs +2 -0
- package/dist/src/codex-sdk-DfvDTN33.js +1165 -0
- package/dist/src/{cometapi-BDyV-NNm.js → cometapi-B5ImDlSm.js} +9 -15
- package/dist/src/{cometapi-C3hOlM7-.cjs → cometapi-BgAkuYCw.cjs} +9 -16
- package/dist/src/{cometapi-hhL4TAh3.js → cometapi-CC7hWxmX.js} +8 -15
- package/dist/src/{cometapi-sp7sJpBD.js → cometapi-CCbpHkuF.js} +8 -17
- package/dist/src/{completion-DoYy49ti.js → completion-2iuYVxwi.js} +8 -57
- package/dist/src/{completion-BCimtq-h.js → completion-CrD6MQ93.js} +8 -57
- package/dist/src/{completion-DlXUhj5c.cjs → completion-DtQ72Bm3.cjs} +7 -62
- package/dist/src/{completion-DCjv7RZ3.js → completion-Vq_ad618.js} +8 -57
- package/dist/src/{createHash-CTQmL3G2.js → createHash-4gFQpDDv.js} +3 -3
- package/dist/src/{createHash-Da8fMwqB.js → createHash-DPpsZgFF.js} +3 -3
- package/dist/src/{createHash-DmPQkvBh.js → createHash-Un4Q_huE.js} +3 -3
- package/dist/src/{createHash-BYwImsYv.cjs → createHash-VvBIc-AW.cjs} +4 -4
- package/dist/src/{docker-CxCkwMzc.js → docker--3qzPa-6.js} +6 -14
- package/dist/src/{docker-Cqj2-QVi.cjs → docker-D3AY-5F5.cjs} +7 -15
- package/dist/src/{docker-FeBni2dw.js → docker-DCsCDvwM.js} +7 -14
- package/dist/src/{docker-DpguQj-w.js → docker-Dorv4_Dg.js} +6 -16
- package/dist/src/embedding-BXhN5lCH.cjs +63 -0
- package/dist/src/embedding-ChS1ivFS.js +58 -0
- package/dist/src/embedding-DNRvZwRN.js +59 -0
- package/dist/src/embedding-D_bI4NDq.js +58 -0
- package/dist/src/entrypoint.js +69 -6
- package/dist/src/{errors-P6ll7XSJ.js → errors-DFHe4L-n.js} +1 -1
- package/dist/src/{esm-SUNIX1x3.js → esm-B6whoAcf.js} +15 -6
- package/dist/src/{esm-CKWP3u_P.js → esm-BRkfNsYs.js} +16 -7
- package/dist/src/{esm-7UIl0pPM.js → esm-BX8fwlAO.js} +27 -18
- package/dist/src/{esm-CipptfDu.cjs → esm-B_rGuPTo.cjs} +15 -6
- package/dist/src/eval-BQPLBJbw.js +3 -0
- package/dist/src/{eval-BTqTn7lb.js → eval-DJ_4A-tr.js} +50 -21
- package/dist/src/evalResult-BBJAHAtw.cjs +2 -0
- package/dist/src/evalResult-BBK58h2B.js +3 -0
- package/dist/src/{evalResult-DpARzUCb.cjs → evalResult-Cx-8OWkb.cjs} +29 -11
- package/dist/src/{evalResult-DUDShQrm.js → evalResult-D6P5I5il.js} +29 -11
- package/dist/src/{evalResult-BkIhRdTe.js → evalResult-pSvGWFMo.js} +29 -11
- package/dist/src/evalResult-spPqh1G_.js +2 -0
- package/dist/src/{evaluator-BcvOGaam.js → evaluator-D-UIbbYq.js} +3975 -2152
- package/dist/src/evaluator-DgLKaZk8.js +3 -0
- package/dist/src/{extractor-D_wd8jxt.js → extractor-BM3jRERL.js} +6 -6
- package/dist/src/{extractor-DG3sSfXE.cjs → extractor-Dxr2J_wK.cjs} +6 -6
- package/dist/src/{extractor-CAZ2G3Kh.js → extractor-DxyiFhPk.js} +6 -6
- package/dist/src/{extractor-C8XwivI9.js → extractor-YlZbUMsL.js} +6 -6
- package/dist/src/fetch-8viavNv8.js +3 -0
- package/dist/src/{fetch-DoVRJZhJ.js → fetch-B6ch2nU2.js} +199 -60
- package/dist/src/{fetch-CVAtKnI3.js → fetch-D9xxyC1p.js} +404 -252
- package/dist/src/{fetch-BnR9wSnm.cjs → fetch-NuqXW1Xb.cjs} +415 -263
- package/dist/src/{fetch-BiYv2BZc.js → fetch-Y5qX_kST.js} +222 -70
- package/dist/src/{fileExtensions-LcDYkU4v.js → fileExtensions-8CjoL7vB.js} +1 -1
- package/dist/src/{fileExtensions-DnqA1y9x.js → fileExtensions-BGh-W-HT.js} +1 -1
- package/dist/src/{fileExtensions-bYh77CN8.cjs → fileExtensions-D9h-8Wxg.cjs} +1 -1
- package/dist/src/{fileExtensions-Ds-foDzt.js → fileExtensions-DysCsxNG.js} +1 -1
- package/dist/src/{formatDuration-DgBVMN65.js → formatDuration-Ch4A7G3o.js} +1 -1
- package/dist/src/{genaiTracer-BfxrvSUb.cjs → genaiTracer-BokHC-MW.cjs} +7 -3
- package/dist/src/{genaiTracer-C1rxGO8Q.js → genaiTracer-C3ZPQU60.js} +6 -2
- package/dist/src/{genaiTracer-70Z8BIuV.js → genaiTracer-CFny3gOy.js} +6 -2
- package/dist/src/{genaiTracer-D3fD9dNV.js → genaiTracer-DxODqT9e.js} +6 -2
- package/dist/src/golang/wrapper.go +1 -1
- package/dist/src/{graders-DG7mhg-b.js → graders-BoUqsCEm.js} +7402 -5699
- package/dist/src/{graders-BElhu9ZY.cjs → graders-Bw1wk_21.cjs} +5220 -3437
- package/dist/src/graders-C84JI-m5.js +2 -0
- package/dist/src/graders-CBbd0K0Q.cjs +2 -0
- package/dist/src/graders-CbQqpHSN.js +3 -0
- package/dist/src/{graders-RjHF8VfG.js → graders-CgPn32yp.js} +7400 -5697
- package/dist/src/{graders-BXAJ0sbS.js → graders-CwrbifOo.js} +6136 -4433
- package/dist/src/graders-DS42d3ZG.js +2 -0
- package/dist/src/{image-6WQXK8m8.js → image-BeWaInPF.js} +4 -4
- package/dist/src/{image-PoF6DN3x.js → image-BmilRNqO.js} +8 -8
- package/dist/src/{image--F58eEIn.cjs → image-CxJoa3aW.cjs} +8 -8
- package/dist/src/{image-fza3zuKs.cjs → image-D10dNAav.cjs} +4 -4
- package/dist/src/{image-DO0RYnjH.js → image-Dr_3I3nK.js} +4 -5
- package/dist/src/{image-B8b6f36E.js → image-DsGRlkh7.js} +8 -8
- package/dist/src/{image-CoxZp9PZ.js → image-a_SGUobh.js} +8 -8
- package/dist/src/{image-xNbw5ph2.js → image-qjO6FWPs.js} +4 -4
- package/dist/src/index.cjs +4835 -2582
- package/dist/src/index.d.cts +2782 -31
- package/dist/src/index.d.ts +2783 -32
- package/dist/src/index.js +4817 -2564
- package/dist/src/{interactiveCheck-BnMYOjMu.js → interactiveCheck-CCICw2cy.js} +2 -2
- package/dist/src/{invariant-BtWWVVhl.js → invariant-B2Rf6avk.js} +1 -1
- package/dist/src/{invariant-vgHWClmd.js → invariant-DIYf9sP1.js} +1 -1
- package/dist/src/{knowledgeBase-Bi7CmDbx.js → knowledgeBase-BBETc5-S.js} +6 -8
- package/dist/src/{knowledgeBase-DqrLX8fy.cjs → knowledgeBase-C8qOo26M.cjs} +6 -8
- package/dist/src/{knowledgeBase-DFRXPZl_.js → knowledgeBase-CzAi2rUI.js} +7 -8
- package/dist/src/{knowledgeBase-Ce3ofVan.js → knowledgeBase-Dr3Kib7F.js} +6 -10
- package/dist/src/{litellm-CKiAxnoM.js → litellm-BLSiANhk.js} +6 -14
- package/dist/src/{litellm-CnHI69aj.cjs → litellm-CaUmV7Mk.cjs} +6 -15
- package/dist/src/{litellm-Tc294Jhj.js → litellm-DQGo_juI.js} +5 -14
- package/dist/src/{litellm-Bo2gQXpo.js → litellm-DRc4qWfc.js} +5 -16
- package/dist/src/{logger-BcJBzSSA.js → logger-BbY6ypFL.js} +41 -12
- package/dist/src/{logger-D5iKBpu_.cjs → logger-COuQb2xB.cjs} +51 -10
- package/dist/src/{logger-DO8_zM18.js → logger-Ct2S6Yx-.js} +40 -11
- package/dist/src/{logger-BnkjG2jt.js → logger-KD8JjCRJ.js} +41 -12
- package/dist/src/{luma-ray-C9q8rdQe.js → luma-ray-B-tNZzqW.js} +6 -10
- package/dist/src/{luma-ray-DP0QA9qn.js → luma-ray-CtS3OlGq.js} +6 -10
- package/dist/src/{luma-ray-0ehMPt5N.js → luma-ray-PJJgUjOc.js} +6 -11
- package/dist/src/{luma-ray-m9Ku2meV.cjs → luma-ray-if-Ml4R9.cjs} +6 -10
- package/dist/src/main.d.ts +1 -26
- package/dist/src/main.js +1188 -679
- package/dist/src/messages-B9dSjrNf.js +544 -0
- package/dist/src/messages-BnsVHUnm.cjs +558 -0
- package/dist/src/messages-CI69Lasb.js +543 -0
- package/dist/src/messages-CewuNcNS.js +543 -0
- package/dist/src/{meteor-DLZZ3osF.cjs → meteor-BBGcGeCa.cjs} +1 -1
- package/dist/src/{meteor-DUiCJRC-.js → meteor-BKTM-7KS.js} +1 -1
- package/dist/src/{meteor-44VjEACX.js → meteor-CeGo0Lu2.js} +2 -2
- package/dist/src/{meteor-D-SotUw9.js → meteor-Wc_aUVvu.js} +2 -2
- package/dist/src/{modelslab-B5J-ZM5c.js → modelslab-BCLOtfek.js} +8 -10
- package/dist/src/{modelslab-IQbNg-r7.cjs → modelslab-BkapYJhh.cjs} +7 -10
- package/dist/src/{modelslab-BTOT8FUO.js → modelslab-D73OnKSx.js} +7 -10
- package/dist/src/{modelslab-BI458moT.js → modelslab-zpz9JcK0.js} +7 -12
- package/dist/src/{nova-reel-BZ9y-Y5s.js → nova-reel-B8F_TK5w.js} +7 -10
- package/dist/src/{nova-reel-Xw1SXLpg.js → nova-reel-Bx0NFV2f.js} +6 -10
- package/dist/src/{nova-reel-DEeQlnOJ.js → nova-reel-CNGJTLtG.js} +6 -12
- package/dist/src/{nova-reel-CE5etkv9.cjs → nova-reel-DkT7tnoB.cjs} +6 -10
- package/dist/src/{nova-sonic-Ogqf-csn.js → nova-sonic-BaXRN1cr.js} +5 -7
- package/dist/src/{nova-sonic-DXTLpi-r.js → nova-sonic-BeTRaFOh.js} +4 -7
- package/dist/src/{nova-sonic-DWswpN1E.js → nova-sonic-CL7Zqv0G.js} +4 -9
- package/dist/src/{nova-sonic-N0yCm0vb.cjs → nova-sonic-YT426juD.cjs} +4 -7
- package/dist/src/{openai-BcB5KlTk.js → openai-BMHD2Huo.js} +6 -3
- package/dist/src/{openai-BMcwgD5C.js → openai-BT-JvDse.js} +6 -3
- package/dist/src/{openai-CoxGAQwn.cjs → openai-Cy1XLs0c.cjs} +6 -3
- package/dist/src/{openai-D6wITiVn.js → openai-D4fxGvRx.js} +6 -3
- package/dist/src/openclaw-Bq7RVR3k.js +1200 -0
- package/dist/src/openclaw-DA8U4DsD.js +1201 -0
- package/dist/src/openclaw-DObVgpjC.js +1200 -0
- package/dist/src/openclaw-DUBZP3GL.cjs +1206 -0
- package/dist/src/{opencode-sdk-CHCs7dEb.js → opencode-sdk-BB40Wir1.js} +6 -8
- package/dist/src/{opencode-sdk-DDxj4QqH.js → opencode-sdk-BM1UAIv1.js} +6 -8
- package/dist/src/{opencode-sdk-WWJhnbKr.cjs → opencode-sdk-CeqiOcOU.cjs} +7 -9
- package/dist/src/{opencode-sdk-C71Z0ehR.js → opencode-sdk-ChdK7F7z.js} +6 -9
- package/dist/src/{otlpReceiver-CZL48YfC.js → otlpReceiver-C6thJRXi.js} +154 -98
- package/dist/src/{otlpReceiver-C9KlUtxh.js → otlpReceiver-CcdIikOu.js} +154 -98
- package/dist/src/{otlpReceiver-DHKqJlsz.cjs → otlpReceiver-DNSQj6bf.cjs} +154 -98
- package/dist/src/{otlpReceiver-CavGAA6k.js → otlpReceiver-UYMQx3sy.js} +154 -98
- package/dist/src/{providerRegistry-BkzVH5Ba.js → providerRegistry-1gB5vtzQ.js} +2 -2
- package/dist/src/{providerRegistry-BTDgfV5h.cjs → providerRegistry-BESeALrr.cjs} +2 -2
- package/dist/src/{providerRegistry-CUWki5mQ.js → providerRegistry-DoACwqhD.js} +2 -2
- package/dist/src/{providerRegistry-B9lh-_tx.js → providerRegistry-PMsleEzs.js} +2 -2
- package/dist/src/providers-BuyzKt7C.js +2 -0
- package/dist/src/providers-C7lNVBjX.cjs +3 -0
- package/dist/src/providers-CCE2COJi2.js +2 -0
- package/dist/src/{providers-Cn73d5sr.js → providers-CJh7iriU.js} +17180 -16823
- package/dist/src/providers-Ctcc592x.js +3 -0
- package/dist/src/{providers-DvddrgxL.js → providers-DRrerKra.js} +1052 -695
- package/dist/src/{providers-Ch6Mr0gn.js → providers-DT-GtF2t.js} +16716 -16359
- package/dist/src/{providers-CScd1wN6.cjs → providers-eDShy16E.cjs} +19893 -19506
- package/dist/src/python/persistent_wrapper.py +0 -5
- package/dist/src/{pythonUtils-Cpo0Ez1p.js → pythonUtils-C4tltmIn.js} +4 -4
- package/dist/src/{pythonUtils-dAVigVK-.cjs → pythonUtils-CoLaCwNY.cjs} +4 -4
- package/dist/src/{pythonUtils-Bzwbgpbg.js → pythonUtils-DMO68Jg7.js} +3 -3
- package/dist/src/{pythonUtils-wIqk7zAf.js → pythonUtils-DNqbnRdx.js} +3 -3
- package/dist/src/{quiverai-BeofbLVc.js → quiverai-BSS9a7wV.js} +4 -4
- package/dist/src/{quiverai-DVSEqJiq.js → quiverai-Bk1KrvL6.js} +4 -4
- package/dist/src/{quiverai-CcUhPIBg.cjs → quiverai-Bpx6MZ7T.cjs} +4 -4
- package/dist/src/{quiverai-CCQn73lq.js → quiverai-CPKhWgaT.js} +4 -5
- package/dist/src/render-7uNJ2V14.js +135 -0
- package/dist/src/render-DlscvAUJ.js +135 -0
- package/dist/src/render-eui5p5mL.js +136 -0
- package/dist/src/{render-BHl6QVq9.js → render-nj-UaPdn.js} +2 -3
- package/dist/src/render-tG6ir9_g.cjs +165 -0
- package/dist/src/{responses-CgNyTPsY.js → responses-1ztiVYsx.js} +56 -17
- package/dist/src/{responses-BKP_WYis.js → responses-B8haB-mD.js} +56 -17
- package/dist/src/{responses-CQb1Tj69.js → responses-BiaBguAu.js} +56 -17
- package/dist/src/{responses-mo0KQDbu.cjs → responses-CF-ayauu.cjs} +56 -17
- package/dist/src/rubyUtils-4hjGxvju.js +3 -0
- package/dist/src/{rubyUtils-DECSbsfY.js → rubyUtils-BI0p46eZ.js} +3 -3
- package/dist/src/{rubyUtils-CiVfln3g.js → rubyUtils-CIQFnVz4.js} +3 -3
- package/dist/src/rubyUtils-CO-tuszQ.cjs +2 -0
- package/dist/src/{rubyUtils-PgU-gHmx.js → rubyUtils-DGnoCYL2.js} +4 -4
- package/dist/src/{rubyUtils-CGeUtCfW.cjs → rubyUtils-DoifqkiA.cjs} +5 -4
- package/dist/src/{sagemaker-CqeASYE5.js → sagemaker-BDLeW29y.js} +14 -18
- package/dist/src/{sagemaker-MUbD5V3v.js → sagemaker-C5T60MKf.js} +14 -19
- package/dist/src/{sagemaker-CVv8W7so.js → sagemaker-ClS_NB07.js} +14 -18
- package/dist/src/{sagemaker-jiw1wQa-.cjs → sagemaker-ljtY12VM.cjs} +14 -18
- package/dist/src/{scanner-DVDeUz1r.js → scanner-nOCWNIXa.js} +130 -35
- package/dist/src/server/golang/wrapper.go +1 -1
- package/dist/src/server/index.js +4829 -2529
- package/dist/src/server/python/persistent_wrapper.py +0 -5
- package/dist/src/{server-BtoCXeXI.cjs → server-BEECpeGG.cjs} +140 -6
- package/dist/src/{server-DZ9MtCn0.js → server-ByiF3qlg.js} +129 -9
- package/dist/src/{server-Cns05F1j.js → server-ByxbqAcQ.js} +128 -8
- package/dist/src/server-C0XKRNB_.cjs +2 -0
- package/dist/src/server-C_15p79-.js +3 -0
- package/dist/src/{server-CP9qKM40.js → server-gyd6d4Hc.js} +126 -7
- package/dist/src/{signal-C3ZTsUgi.js → signal-DTtUuU3l.js} +3 -3
- package/dist/src/{slack-DCEV-vWP.js → slack-4zZX1OKP.js} +2 -2
- package/dist/src/{slack-94iG3T0s.cjs → slack-BLlsDpfG.cjs} +2 -2
- package/dist/src/{slack-BR0HtO3K.js → slack-BPYLQLgb.js} +2 -2
- package/dist/src/{slack-2sdpGzbt.js → slack-Bamy_7te.js} +2 -2
- package/dist/src/{store-CLyU7AtI.cjs → store-2K0kDi80.cjs} +3 -3
- package/dist/src/{store-VB0GP46K.js → store-2OXm_eBY.js} +3 -3
- package/dist/src/store-BELqNwvz.js +3 -0
- package/dist/src/{store-Cj258DgL.js → store-BPkzEyFM.js} +3 -3
- package/dist/src/{store-P8OKm19S.js → store-CPh25336.js} +3 -3
- package/dist/src/store-uQZ4AjPe.cjs +2 -0
- package/dist/src/{tables-BEIFz2tM.js → tables-BMSOS2Gg.js} +3 -3
- package/dist/src/{tables-BdZQEpRz.cjs → tables-CXbaZ9y1.cjs} +3 -3
- package/dist/src/{tables-DmzvLbeZ.js → tables-NlvH23ky.js} +3 -3
- package/dist/src/{tables-kC7R5kiK.js → tables-WgdUZ8Ck.js} +3 -3
- package/dist/src/{telemetry-DPXLd7UE.js → telemetry--iqaGyaS.js} +5 -4
- package/dist/src/{telemetry-re627Lre.cjs → telemetry-CEQxGnMZ.cjs} +8 -7
- package/dist/src/{telemetry-BugWqKiu.js → telemetry-CgdVGV8N.js} +5 -4
- package/dist/src/{telemetry-BnH5VJAU.js → telemetry-DWdGHvEf.js} +5 -4
- package/dist/src/telemetry-DjNoC_n3.cjs +2 -0
- package/dist/src/telemetry-ZdPZc0fm.js +3 -0
- package/dist/src/{text-CW1cyrwj.cjs → text-BiNME7QG.cjs} +1 -1
- package/dist/src/{text-Db-Wt2u2.js → text-D4lz-Jg_.js} +1 -1
- package/dist/src/{text-TIv0QYnd.js → text-DDQP0tuQ.js} +1 -1
- package/dist/src/{text-B_UCRPp2.js → text-NWvfMfkF.js} +1 -1
- package/dist/src/{tokenUsageUtils-DflFMjS0.js → tokenUsageUtils-2wIvAhB3.js} +7 -3
- package/dist/src/{tokenUsageUtils-BDGe-iyI.js → tokenUsageUtils-4c780gFd.js} +7 -3
- package/dist/src/{tokenUsageUtils-NYT-WKS6.js → tokenUsageUtils-BjVkdk18.js} +7 -3
- package/dist/src/{tokenUsageUtils-bVa1ga6f.cjs → tokenUsageUtils-C9odhsbW.cjs} +7 -3
- package/dist/src/{transcription-CaMivnjG.js → transcription-84t4ALo2.js} +7 -11
- package/dist/src/{transcription-Hb3VnC4M.js → transcription-Bm2emLmJ.js} +8 -11
- package/dist/src/{transcription-BvtsrzRG.cjs → transcription-CZ4LG5hQ.cjs} +9 -13
- package/dist/src/{transcription-DOMMTu01.js → transcription-D7Q0vJsh.js} +7 -13
- package/dist/src/{transform-DrleutM3.js → transform-B-b6Cq-q.js} +8 -6
- package/dist/src/transform-BQt0BeAW.js +3 -0
- package/dist/src/transform-Bq5oqC0s.cjs +2 -0
- package/dist/src/{transform-ZrG2dvlo.cjs → transform-C9izGX54.cjs} +5 -5
- package/dist/src/{transform-BzK09Q_9.js → transform-CwbAZ84V.js} +5 -5
- package/dist/src/{transform-0BwoBsvO.cjs → transform-Dg4LcO1Y.cjs} +18 -10
- package/dist/src/{transform-B2-jIv68.js → transform-DtooZqYY.js} +8 -6
- package/dist/src/{transform-ljLYHEPh.js → transform-DzCF-wqV.js} +5 -5
- package/dist/src/{transform-DyDAwEpE.js → transform-_DpNB4qp.js} +9 -7
- package/dist/src/{transform-BqPkNPYm.js → transform-eGiUAv86.js} +5 -5
- package/dist/src/{transformersAvailability-DKoRtQLy.cjs → transformersAvailability-B22swDxr.cjs} +1 -1
- package/dist/src/{transformersAvailability-BGkzavwb.js → transformersAvailability-lvCCvuPT.js} +1 -1
- package/dist/src/{transformersAvailability-D6c6ROpT.js → transformersAvailability-rJGPccjr.js} +1 -1
- package/dist/src/{types-Cd3ygw8W.js → types-BDjGOq4E.js} +354 -24
- package/dist/src/{types-CIhFeUC4.js → types-BVH9hjgW.js} +364 -23
- package/dist/src/{types-D8cGDZbL.cjs → types-CgG2rKiW.cjs} +534 -167
- package/dist/src/{types-q8GXGF65.js → types-DNRZVOue.js} +498 -167
- package/dist/src/{util-BLvy9qfE.js → util-3pBZZb_H.js} +151 -149
- package/dist/src/{util-CFj4YKIn.cjs → util-A5_ZsQUn.cjs} +66 -44
- package/dist/src/{util-BtoGs5Cb.js → util-B9CNhyac.js} +66 -44
- package/dist/src/{util-Bm3E9jpK.js → util-BQOCAHQC.js} +692 -690
- package/dist/src/{util-vNmDL5DT.js → util-BVXcTwXu.js} +138 -36
- package/dist/src/{util-CgDCK4KI.js → util-BlFVL0UF.js} +66 -44
- package/dist/src/{util-DM2rTn_6.js → util-C-kmRosx.js} +66 -44
- package/dist/src/{util-DbVG-yZU.js → util-DFPeFkiV.js} +138 -36
- package/dist/src/{util-DMFeUvLz.js → util-DN0-b81k.js} +138 -36
- package/dist/src/{util--9u9UVCt.cjs → util-Dpmm_dAI.cjs} +143 -35
- package/dist/src/{util-CMMkIxfU.js → util-Dub0f_ej.js} +693 -691
- package/dist/src/{util-CuLo2pMR.cjs → util-DvpHnLt0.cjs} +714 -719
- package/dist/src/{utils-DOjD4dTC.js → utils-BUMN8orw.js} +6 -4
- package/dist/src/{utils-DKw8mrgr.cjs → utils-DkVeShIB.cjs} +6 -4
- package/dist/src/{utils-DEuL4VNB.js → utils-kt7lv30R.js} +6 -4
- package/dist/src/{utils-CFxO9KGo.js → utils-o8S5huU2.js} +6 -4
- package/dist/src/version-0frU0UTr.js +16 -0
- package/dist/src/version-CbpiUINz.js +17 -0
- package/dist/src/version-CbuBKu2U.js +16 -0
- package/dist/src/version-D9zu9FWB.cjs +27 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +57 -46
- package/dist/src/app/assets/index-B6l9CVVb.js +0 -439
- package/dist/src/app/assets/index-DyZ0Ep37.css +0 -1
- package/dist/src/app/assets/scroll-timeline-BdJZVXlz.js +0 -1
- package/dist/src/app/assets/sync-CStkzc6u.js +0 -4
- package/dist/src/app/assets/vendor-charts-BnDWwBlI.js +0 -36
- package/dist/src/app/assets/vendor-markdown-Bz7N-ca6.js +0 -29
- package/dist/src/app/assets/vendor-react-AtKqiNEf.js +0 -4
- package/dist/src/app/assets/vendor-syntax-D06x6TQF.js +0 -2
- package/dist/src/app/assets/vendor-utils-BvMHZmO7.js +0 -37
- package/dist/src/cache-C5yFZ4gC.cjs +0 -816
- package/dist/src/cache-CaT5tPgo.js +0 -756
- package/dist/src/cache-CyCanoMu.js +0 -6
- package/dist/src/cache-DSqR6ezl.js +0 -726
- package/dist/src/cache-Df_QFDNu.cjs +0 -5
- package/dist/src/cache-HP0NP4k3.js +0 -756
- package/dist/src/cloud-DE3t1-ZI.js +0 -4
- package/dist/src/codex-sdk-BQEw16R_.js +0 -834
- package/dist/src/codex-sdk-C_07GuVS.js +0 -834
- package/dist/src/codex-sdk-DE5G18dx.js +0 -835
- package/dist/src/codex-sdk-ZLKfDjqP.cjs +0 -838
- package/dist/src/eval-7aEqoMs3.js +0 -15
- package/dist/src/evalResult-CYNHkk5A.js +0 -12
- package/dist/src/evalResult-CuvJeNiM.js +0 -10
- package/dist/src/evalResult-tGdilrWt.cjs +0 -10
- package/dist/src/evaluator-BBUqRhz1.js +0 -36
- package/dist/src/fetch-UWU706qb.js +0 -5
- package/dist/src/graders-BxfEguVY.js +0 -32
- package/dist/src/graders-CzVMbEnv.js +0 -34
- package/dist/src/graders-DjCXfj0l.cjs +0 -32
- package/dist/src/graders-kHzIWOKu.js +0 -32
- package/dist/src/messages-DJNo37Ko.js +0 -246
- package/dist/src/messages-Dy9QecMs.js +0 -245
- package/dist/src/messages-HJsyEh4o.cjs +0 -257
- package/dist/src/messages-biC_ex-p.js +0 -245
- package/dist/src/openclaw-0Sv7AK3O.js +0 -580
- package/dist/src/openclaw-CXxbKgDH.cjs +0 -586
- package/dist/src/openclaw-D1FSCps-.js +0 -580
- package/dist/src/openclaw-D2ENvu7a.js +0 -582
- package/dist/src/providers-BSLEaIQG.js +0 -32
- package/dist/src/providers-D-FnDg8k.cjs +0 -31
- package/dist/src/providers-DEYiFVAo.js +0 -30
- package/dist/src/providers-sS2WI8YD.js +0 -30
- package/dist/src/rubyUtils-B1HXG4ej.cjs +0 -4
- package/dist/src/rubyUtils-Rt6pKA96.js +0 -5
- package/dist/src/server-B0Xh1Gx-.js +0 -7
- package/dist/src/server-DJTKu9IR.cjs +0 -5
- package/dist/src/store-C5u6MgC8.js +0 -6
- package/dist/src/store-CNHk-De4.cjs +0 -5
- package/dist/src/telemetry-Yig0Tino.js +0 -7
- package/dist/src/telemetry-p8Pwqm1i.cjs +0 -5
- package/dist/src/transform-ChNIpHz7.js +0 -6
- package/dist/src/transform-PtQ6rAE3.cjs +0 -5
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { D as getEnvInt, E as getEnvFloat, O as getEnvString, s as logger } from "./logger-BbY6ypFL.js";
|
|
3
|
+
import { C as transformToolChoice, w as transformTools } from "./fetch-B6ch2nU2.js";
|
|
4
|
+
import { n as withGenAISpan } from "./genaiTracer-C3ZPQU60.js";
|
|
5
|
+
import { o as getCache, s as isCacheEnabled } from "./cache-BI5BY7ey.js";
|
|
6
|
+
import { M as maybeLoadResponseFormatFromExternalFile, N as maybeLoadToolsFromExternalFile } from "./util-BQOCAHQC.js";
|
|
7
|
+
import { a as createEmptyTokenUsage } from "./tokenUsageUtils-2wIvAhB3.js";
|
|
8
|
+
import { i as normalizeFinishReason, n as MCPClient } from "./chat-BLOdH60v.js";
|
|
9
|
+
import { n as transformMCPToolsToAnthropic } from "./transform-B-b6Cq-q.js";
|
|
10
|
+
import { a as outputFromMessage, i as getTokenUsage, n as calculateAnthropicCost, o as parseMessages, r as getRefusalDetails, s as processAnthropicTools, t as ANTHROPIC_MODELS } from "./util-DN0-b81k.js";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import Anthropic, { APIError } from "@anthropic-ai/sdk";
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
//#region src/providers/anthropic/claudeCodeAuth.ts
|
|
17
|
+
/**
|
|
18
|
+
* Claude Code prepends this identity block as the first `system` message when
|
|
19
|
+
* calling the Anthropic Messages API with an OAuth token. As of 2025-Q4 the
|
|
20
|
+
* API returns HTTP 400 `invalid_request_error` when an OAuth-authenticated
|
|
21
|
+
* request's first system block is not this exact string, so any caller
|
|
22
|
+
* reusing a Claude Code OAuth token must inject this block before the
|
|
23
|
+
* user-provided system prompt. Re-verify if Anthropic ships an OAuth-native
|
|
24
|
+
* `/v1/messages` path that drops the requirement.
|
|
25
|
+
*/
|
|
26
|
+
const CLAUDE_CODE_IDENTITY_PROMPT = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
27
|
+
/**
|
|
28
|
+
* Anthropic beta headers required when authenticating the Messages API with a
|
|
29
|
+
* Claude Code OAuth token (e.g. a Claude Max subscription access token, or a
|
|
30
|
+
* long-lived token minted by `claude setup-token`).
|
|
31
|
+
*
|
|
32
|
+
* - `oauth-2025-04-20` enables OAuth bearer tokens on `/v1/messages`.
|
|
33
|
+
* - `claude-code-20250219` enables the Claude Code tool-use surface area the
|
|
34
|
+
* OAuth token is scoped to.
|
|
35
|
+
*
|
|
36
|
+
* Revisit if Anthropic ships an OAuth-native Messages path that no longer
|
|
37
|
+
* requires these betas.
|
|
38
|
+
*/
|
|
39
|
+
const CLAUDE_CODE_OAUTH_BETA_FEATURES = Object.freeze(["claude-code-20250219", "oauth-2025-04-20"]);
|
|
40
|
+
/**
|
|
41
|
+
* The `user-agent` value Claude Code CLI sends on OAuth-authenticated
|
|
42
|
+
* Messages requests. Anthropic's API gates OAuth tokens to the Claude Code
|
|
43
|
+
* app identity, so requests that use a different user-agent fail with 401.
|
|
44
|
+
*
|
|
45
|
+
* The `1.0.0` suffix is cosmetic — Anthropic gates on the `claude-cli`
|
|
46
|
+
* product identifier, not the semver. Revisit if OAuth requests start
|
|
47
|
+
* returning 401 after SDK or CLI updates.
|
|
48
|
+
*/
|
|
49
|
+
const CLAUDE_CODE_USER_AGENT = "claude-cli/1.0.0 (external, promptfoo)";
|
|
50
|
+
const CLAUDE_CODE_KEYCHAIN_SERVICE = "Claude Code-credentials";
|
|
51
|
+
const CLAUDE_CODE_CREDENTIALS_FILE = path.join(".claude", ".credentials.json");
|
|
52
|
+
function resolveCredentialsPath() {
|
|
53
|
+
return path.join(os.homedir(), CLAUDE_CODE_CREDENTIALS_FILE);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* `security` exits with status 44 when the requested generic-password entry
|
|
57
|
+
* does not exist. Any other non-zero exit (or throw) indicates a real failure
|
|
58
|
+
* — ACL denial, corrupted entry, missing binary, timeout — and is worth a
|
|
59
|
+
* `warn` log rather than silently falling through.
|
|
60
|
+
*/
|
|
61
|
+
const SECURITY_ENTRY_NOT_FOUND = 44;
|
|
62
|
+
function parseCredential(raw) {
|
|
63
|
+
if (!raw || typeof raw !== "object") return {
|
|
64
|
+
ok: false,
|
|
65
|
+
reason: "credential JSON is not an object"
|
|
66
|
+
};
|
|
67
|
+
const claudeAiOauth = raw.claudeAiOauth;
|
|
68
|
+
if (!claudeAiOauth || typeof claudeAiOauth !== "object") return {
|
|
69
|
+
ok: false,
|
|
70
|
+
reason: "missing `claudeAiOauth` object"
|
|
71
|
+
};
|
|
72
|
+
const inner = claudeAiOauth;
|
|
73
|
+
const accessToken = inner.accessToken;
|
|
74
|
+
if (typeof accessToken !== "string" || !accessToken) return {
|
|
75
|
+
ok: false,
|
|
76
|
+
reason: "missing `claudeAiOauth.accessToken` string"
|
|
77
|
+
};
|
|
78
|
+
const credential = { accessToken };
|
|
79
|
+
if (typeof inner.refreshToken === "string" && inner.refreshToken) credential.refreshToken = inner.refreshToken;
|
|
80
|
+
if (typeof inner.expiresAt === "number" && Number.isFinite(inner.expiresAt)) credential.expiresAt = inner.expiresAt;
|
|
81
|
+
if (typeof inner.subscriptionType === "string") credential.subscriptionType = inner.subscriptionType;
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
credential
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function parseJsonBlob(blob) {
|
|
88
|
+
let parsed;
|
|
89
|
+
try {
|
|
90
|
+
parsed = JSON.parse(blob);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
reason: `invalid JSON: ${err instanceof Error ? err.message : String(err)}`
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return parseCredential(parsed);
|
|
98
|
+
}
|
|
99
|
+
function readFromMacosKeychain() {
|
|
100
|
+
if (process.platform !== "darwin") return null;
|
|
101
|
+
let out;
|
|
102
|
+
try {
|
|
103
|
+
out = execFileSync("security", [
|
|
104
|
+
"find-generic-password",
|
|
105
|
+
"-s",
|
|
106
|
+
CLAUDE_CODE_KEYCHAIN_SERVICE,
|
|
107
|
+
"-w"
|
|
108
|
+
], {
|
|
109
|
+
encoding: "utf-8",
|
|
110
|
+
stdio: [
|
|
111
|
+
"ignore",
|
|
112
|
+
"pipe",
|
|
113
|
+
"ignore"
|
|
114
|
+
],
|
|
115
|
+
timeout: 5e3
|
|
116
|
+
});
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if (err?.status === SECURITY_ENTRY_NOT_FOUND) {
|
|
119
|
+
logger.debug("[anthropic] No Claude Code credential entry in the macOS keychain; trying file fallback.");
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
logger.warn("[anthropic] Failed to read Claude Code credential from macOS keychain; falling back to file lookup.", { error: err instanceof Error ? err.message : String(err) });
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const trimmed = out.trim();
|
|
126
|
+
if (!trimmed) {
|
|
127
|
+
logger.warn("[anthropic] Claude Code macOS keychain entry is empty. Run `claude /login` to refresh it.");
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const result = parseJsonBlob(trimmed);
|
|
131
|
+
if (!result.ok) {
|
|
132
|
+
logger.warn(`[anthropic] Claude Code macOS keychain entry is malformed (${result.reason}). Run \`claude /login\` to refresh it.`);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return result.credential;
|
|
136
|
+
}
|
|
137
|
+
function readFromFile() {
|
|
138
|
+
const filePath = resolveCredentialsPath();
|
|
139
|
+
if (!fs.existsSync(filePath)) return null;
|
|
140
|
+
let raw;
|
|
141
|
+
try {
|
|
142
|
+
raw = fs.readFileSync(filePath, "utf-8");
|
|
143
|
+
} catch (err) {
|
|
144
|
+
logger.warn(`[anthropic] Claude Code credentials file at ${filePath} exists but could not be read. Run \`claude /login\` to refresh it.`, { error: err instanceof Error ? err.message : String(err) });
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const result = parseJsonBlob(raw);
|
|
148
|
+
if (!result.ok) {
|
|
149
|
+
logger.warn(`[anthropic] Claude Code credentials file at ${filePath} is malformed (${result.reason}). Run \`claude /login\` to refresh it.`);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return result.credential;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Loads a Claude Code OAuth credential from the local environment.
|
|
156
|
+
*
|
|
157
|
+
* Resolution order:
|
|
158
|
+
* 1. macOS keychain (`security find-generic-password -s "Claude Code-credentials"`)
|
|
159
|
+
* — only attempted on darwin.
|
|
160
|
+
* 2. `$HOME/.claude/.credentials.json` — the Linux/Windows default used by
|
|
161
|
+
* Claude Code, and a fallback on macOS when the keychain entry is missing.
|
|
162
|
+
* On Windows this resolves to `%USERPROFILE%\.claude\.credentials.json`.
|
|
163
|
+
*
|
|
164
|
+
* Returns `null` when no credential is available. Callers should check
|
|
165
|
+
* {@link isCredentialExpired} on a non-null return before using it — this
|
|
166
|
+
* function does not filter out expired credentials so callers can decide
|
|
167
|
+
* whether to warn, refuse, or surface a 401 to the user.
|
|
168
|
+
*
|
|
169
|
+
* Never throws. Missing credentials fall through silently; corrupted or
|
|
170
|
+
* unreadable credentials are logged at `warn` level with a reason so broken
|
|
171
|
+
* setups are diagnosable without enabling debug logging.
|
|
172
|
+
*/
|
|
173
|
+
function loadClaudeCodeCredential() {
|
|
174
|
+
return readFromMacosKeychain() ?? readFromFile();
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns `true` when the credential's `expiresAt` (ms since epoch) is in the
|
|
178
|
+
* past. Credentials without an `expiresAt` are treated as non-expired — the
|
|
179
|
+
* Anthropic API will reject them with a 401 if the token is actually invalid.
|
|
180
|
+
*/
|
|
181
|
+
function isCredentialExpired(credential) {
|
|
182
|
+
if (credential.expiresAt == null) return false;
|
|
183
|
+
return Date.now() >= credential.expiresAt;
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/providers/anthropic/generic.ts
|
|
187
|
+
/**
|
|
188
|
+
* Generic provider class for Anthropic APIs.
|
|
189
|
+
*
|
|
190
|
+
* Serves as a base class with shared functionality for all Anthropic
|
|
191
|
+
* subclass providers. Handles API key resolution and, for subclasses that
|
|
192
|
+
* opt in via {@link AnthropicGenericProvider.SUPPORTS_CLAUDE_CODE_OAUTH},
|
|
193
|
+
* falls back to an OAuth token loaded from a local Claude Code session so
|
|
194
|
+
* Claude.ai subscribers can run evals without a separate console API key.
|
|
195
|
+
*
|
|
196
|
+
* The OAuth fallback is opt-in so it only affects
|
|
197
|
+
* `AnthropicMessagesProvider`. Claude Code OAuth tokens are gated to the
|
|
198
|
+
* Messages API (`/v1/messages`) — forwarding them to the legacy
|
|
199
|
+
* text-completion endpoint would fail at request time, which would cause
|
|
200
|
+
* `anthropic:completion:*` configs to bypass promptfoo's upfront preflight
|
|
201
|
+
* check and then produce a less useful error for every test case.
|
|
202
|
+
*/
|
|
203
|
+
var AnthropicGenericProvider = class {
|
|
204
|
+
/**
|
|
205
|
+
* Subclasses that can authenticate via a Claude Code OAuth session
|
|
206
|
+
* should override this to `true`. The base class's constructor reads the
|
|
207
|
+
* flag from `this.constructor` so only OAuth-capable subclasses attempt
|
|
208
|
+
* the credential lookup (and only they honor `apiKeyRequired: false`).
|
|
209
|
+
*/
|
|
210
|
+
static SUPPORTS_CLAUDE_CODE_OAUTH = false;
|
|
211
|
+
modelName;
|
|
212
|
+
config;
|
|
213
|
+
env;
|
|
214
|
+
apiKey;
|
|
215
|
+
/**
|
|
216
|
+
* `true` when this provider is authenticating via a Claude Code OAuth token
|
|
217
|
+
* rather than a standard `ANTHROPIC_API_KEY`. Subclasses use this to inject
|
|
218
|
+
* the Claude Code identity system block that Anthropic's API requires for
|
|
219
|
+
* OAuth-authenticated Messages requests.
|
|
220
|
+
*/
|
|
221
|
+
usingClaudeCodeOAuth;
|
|
222
|
+
/**
|
|
223
|
+
* The Claude Code credential used to authenticate, when
|
|
224
|
+
* `usingClaudeCodeOAuth` is `true`. Kept so subclasses can re-check expiry
|
|
225
|
+
* at request time and surface a "run `claude /login`" error instead of a
|
|
226
|
+
* raw 401 from the SDK.
|
|
227
|
+
*/
|
|
228
|
+
claudeCodeCredential;
|
|
229
|
+
anthropic;
|
|
230
|
+
constructor(modelName, options = {}) {
|
|
231
|
+
const { config, id, env } = options;
|
|
232
|
+
this.env = env;
|
|
233
|
+
this.modelName = modelName;
|
|
234
|
+
this.config = config || {};
|
|
235
|
+
this.apiKey = this.getApiKey();
|
|
236
|
+
this.usingClaudeCodeOAuth = false;
|
|
237
|
+
let authToken;
|
|
238
|
+
const defaultHeaders = {};
|
|
239
|
+
const subclass = this.constructor;
|
|
240
|
+
if (!this.apiKey && this.config.apiKeyRequired === false && subclass.SUPPORTS_CLAUDE_CODE_OAUTH) {
|
|
241
|
+
const credential = loadClaudeCodeCredential();
|
|
242
|
+
if (credential) {
|
|
243
|
+
if (isCredentialExpired(credential)) logger.warn("[anthropic] Claude Code OAuth credential is expired. Run `claude /login` to refresh it.");
|
|
244
|
+
else logger.debug("[anthropic] Authenticating with Claude Code OAuth credential from local session.");
|
|
245
|
+
authToken = credential.accessToken;
|
|
246
|
+
this.usingClaudeCodeOAuth = true;
|
|
247
|
+
this.claudeCodeCredential = credential;
|
|
248
|
+
defaultHeaders["anthropic-beta"] = CLAUDE_CODE_OAUTH_BETA_FEATURES.join(",");
|
|
249
|
+
defaultHeaders["user-agent"] = CLAUDE_CODE_USER_AGENT;
|
|
250
|
+
defaultHeaders["x-app"] = "cli";
|
|
251
|
+
} else logger.warn("[anthropic] apiKeyRequired is false but no Claude Code credential was found. Run `claude /login` to create one, or set ANTHROPIC_API_KEY.");
|
|
252
|
+
}
|
|
253
|
+
this.anthropic = new Anthropic({
|
|
254
|
+
apiKey: this.apiKey ?? null,
|
|
255
|
+
authToken: authToken ?? null,
|
|
256
|
+
baseURL: this.getApiBaseUrl(),
|
|
257
|
+
...Object.keys(defaultHeaders).length > 0 ? { defaultHeaders } : {}
|
|
258
|
+
});
|
|
259
|
+
this.id = id ? () => id : this.id;
|
|
260
|
+
}
|
|
261
|
+
id() {
|
|
262
|
+
return `anthropic:${this.modelName}`;
|
|
263
|
+
}
|
|
264
|
+
toString() {
|
|
265
|
+
return `[Anthropic Provider ${this.modelName}]`;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Whether promptfoo's preflight check should require an API key before
|
|
269
|
+
* dispatching requests to this provider. Returns `false` only for
|
|
270
|
+
* OAuth-capable subclasses (see {@link SUPPORTS_CLAUDE_CODE_OAUTH}) when
|
|
271
|
+
* the user has opted in via `apiKeyRequired: false`. All other subclasses
|
|
272
|
+
* keep the preflight check so missing-credential errors surface upfront
|
|
273
|
+
* rather than at per-request call time.
|
|
274
|
+
*/
|
|
275
|
+
requiresApiKey() {
|
|
276
|
+
if (this.constructor.SUPPORTS_CLAUDE_CODE_OAUTH && this.config.apiKeyRequired === false) return false;
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
getApiKey() {
|
|
280
|
+
return this.config?.apiKey || this.env?.ANTHROPIC_API_KEY || getEnvString("ANTHROPIC_API_KEY");
|
|
281
|
+
}
|
|
282
|
+
getApiBaseUrl() {
|
|
283
|
+
return this.config?.apiBaseUrl || this.env?.ANTHROPIC_BASE_URL || getEnvString("ANTHROPIC_BASE_URL");
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Base implementation - should be overridden by specific provider implementations
|
|
287
|
+
*/
|
|
288
|
+
async callApi(_prompt, _context) {
|
|
289
|
+
throw new Error("Not implemented: callApi must be implemented by subclasses");
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/providers/anthropic/messages.ts
|
|
294
|
+
function parseEnvFloat(value) {
|
|
295
|
+
if (value === void 0) return;
|
|
296
|
+
const parsed = Number.parseFloat(value);
|
|
297
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
298
|
+
}
|
|
299
|
+
function resolveThinkingConfig(configThinking, promptThinking) {
|
|
300
|
+
return configThinking ?? promptThinking;
|
|
301
|
+
}
|
|
302
|
+
function isThinkingEnabled(thinking) {
|
|
303
|
+
return thinking?.type === "enabled" || thinking?.type === "adaptive";
|
|
304
|
+
}
|
|
305
|
+
var AnthropicMessagesProvider = class AnthropicMessagesProvider extends AnthropicGenericProvider {
|
|
306
|
+
mcpClient = null;
|
|
307
|
+
initializationPromise = null;
|
|
308
|
+
static SUPPORTS_CLAUDE_CODE_OAUTH = true;
|
|
309
|
+
static ANTHROPIC_MODELS = ANTHROPIC_MODELS;
|
|
310
|
+
static ANTHROPIC_MODELS_NAMES = ANTHROPIC_MODELS.map((model) => model.id);
|
|
311
|
+
constructor(modelName, options = {}) {
|
|
312
|
+
if (!AnthropicMessagesProvider.ANTHROPIC_MODELS_NAMES.includes(modelName)) logger.warn(`Using unknown Anthropic model: ${modelName}`);
|
|
313
|
+
super(modelName, options);
|
|
314
|
+
const { id } = options;
|
|
315
|
+
this.id = id ? () => id : this.id;
|
|
316
|
+
if (this.config.mcp?.enabled) this.initializationPromise = this.initializeMCP();
|
|
317
|
+
}
|
|
318
|
+
async initializeMCP() {
|
|
319
|
+
this.mcpClient = new MCPClient(this.config.mcp);
|
|
320
|
+
await this.mcpClient.initialize();
|
|
321
|
+
}
|
|
322
|
+
async cleanup() {
|
|
323
|
+
if (this.mcpClient) {
|
|
324
|
+
await this.initializationPromise;
|
|
325
|
+
await this.mcpClient.cleanup();
|
|
326
|
+
this.mcpClient = null;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
toString() {
|
|
330
|
+
if (!this.modelName) throw new Error("Anthropic model name is not set. Please provide a valid model name.");
|
|
331
|
+
return `[Anthropic Messages Provider ${this.modelName}]`;
|
|
332
|
+
}
|
|
333
|
+
async callApi(prompt, context) {
|
|
334
|
+
if (this.initializationPromise != null) await this.initializationPromise;
|
|
335
|
+
if (!this.apiKey && !this.usingClaudeCodeOAuth) throw new Error("Anthropic API key is not set. Set the ANTHROPIC_API_KEY environment variable or add `apiKey` to the provider config. Alternatively, if you have an active Claude Code session, set `apiKeyRequired: false` in the provider config to authenticate via Claude Code.");
|
|
336
|
+
if (this.usingClaudeCodeOAuth && this.claudeCodeCredential && isCredentialExpired(this.claudeCodeCredential)) throw new Error("Claude Code OAuth credential is expired. Run `claude /login` to refresh it, then re-run the eval.");
|
|
337
|
+
if (!this.modelName) throw new Error("Anthropic model name is not set. Please provide a valid model name.");
|
|
338
|
+
const spanContext = {
|
|
339
|
+
system: "anthropic",
|
|
340
|
+
operationName: "chat",
|
|
341
|
+
model: this.modelName,
|
|
342
|
+
providerId: this.id(),
|
|
343
|
+
maxTokens: this.config.max_tokens,
|
|
344
|
+
temperature: this.config.temperature,
|
|
345
|
+
testIndex: context?.test?.vars?.__testIdx,
|
|
346
|
+
promptLabel: context?.prompt?.label,
|
|
347
|
+
traceparent: context?.traceparent,
|
|
348
|
+
requestBody: prompt
|
|
349
|
+
};
|
|
350
|
+
const resultExtractor = (response) => {
|
|
351
|
+
const result = {};
|
|
352
|
+
if (response.tokenUsage) result.tokenUsage = {
|
|
353
|
+
prompt: response.tokenUsage.prompt,
|
|
354
|
+
completion: response.tokenUsage.completion,
|
|
355
|
+
total: response.tokenUsage.total,
|
|
356
|
+
cached: response.tokenUsage.cached,
|
|
357
|
+
completionDetails: response.tokenUsage.completionDetails
|
|
358
|
+
};
|
|
359
|
+
if (response.finishReason) result.finishReasons = [response.finishReason];
|
|
360
|
+
if (response.cached !== void 0) result.cacheHit = response.cached;
|
|
361
|
+
if (response.output !== void 0) result.responseBody = typeof response.output === "string" ? response.output : JSON.stringify(response.output);
|
|
362
|
+
return result;
|
|
363
|
+
};
|
|
364
|
+
return withGenAISpan(spanContext, () => this.callApiInternal(prompt, context), resultExtractor);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Internal implementation of callApi without tracing wrapper.
|
|
368
|
+
*/
|
|
369
|
+
async callApiInternal(prompt, context) {
|
|
370
|
+
const config = {
|
|
371
|
+
...this.config,
|
|
372
|
+
...context?.prompt?.config
|
|
373
|
+
};
|
|
374
|
+
const { system, extractedMessages, thinking } = parseMessages(prompt);
|
|
375
|
+
let mcpTools = [];
|
|
376
|
+
if (this.mcpClient) mcpTools = transformMCPToolsToAnthropic(this.mcpClient.getAllTools());
|
|
377
|
+
const { processedTools: processedConfigTools, requiredBetaFeatures } = processAnthropicTools(transformTools(await maybeLoadToolsFromExternalFile(config.tools, context?.vars) || [], "anthropic"));
|
|
378
|
+
const allTools = [...mcpTools, ...processedConfigTools];
|
|
379
|
+
const processedOutputFormat = maybeLoadResponseFormatFromExternalFile(config.output_format, context?.vars);
|
|
380
|
+
const resolvedThinking = resolveThinkingConfig(config.thinking, thinking);
|
|
381
|
+
const thinkingEnabled = isThinkingEnabled(resolvedThinking);
|
|
382
|
+
if (thinkingEnabled) {
|
|
383
|
+
if (config.top_k != null) logger.warn("top_k is incompatible with extended thinking and will be omitted. Remove top_k from your config or disable thinking.");
|
|
384
|
+
if (config.temperature != null) logger.warn("temperature is incompatible with extended thinking and will be omitted. Remove temperature from your config or disable thinking.");
|
|
385
|
+
if (config.top_p != null && (config.top_p < .95 || config.top_p > 1)) logger.warn(`top_p must be between 0.95 and 1.0 with extended thinking (got ${config.top_p}). Clamping to valid range.`);
|
|
386
|
+
}
|
|
387
|
+
let resolvedToolChoice;
|
|
388
|
+
if (config.tool_choice) {
|
|
389
|
+
const transformed = transformToolChoice(config.tool_choice, "anthropic");
|
|
390
|
+
if (thinkingEnabled && (transformed.type === "any" || transformed.type === "tool")) logger.warn(`tool_choice type '${transformed.type}' (forced tool use) is incompatible with extended thinking and will be omitted. Use 'auto' or remove tool_choice.`);
|
|
391
|
+
else resolvedToolChoice = transformed;
|
|
392
|
+
}
|
|
393
|
+
let resolvedTopP;
|
|
394
|
+
if (config.top_p != null) resolvedTopP = thinkingEnabled ? Math.max(.95, Math.min(1, config.top_p)) : config.top_p;
|
|
395
|
+
if (config.temperature != null && resolvedTopP != null && !thinkingEnabled) logger.warn("temperature is incompatible with top_p on Anthropic and will be omitted. Remove one of these parameters.");
|
|
396
|
+
if (this.modelName.startsWith("claude-opus-4-6") && extractedMessages.length > 0) {
|
|
397
|
+
if (extractedMessages[extractedMessages.length - 1].role === "assistant") logger.warn("Assistant message prefilling is not supported on Claude Opus 4.6 and will cause a 400 error. Remove the trailing assistant message from your prompt.");
|
|
398
|
+
}
|
|
399
|
+
const resolvedSystem = this.usingClaudeCodeOAuth ? [{
|
|
400
|
+
type: "text",
|
|
401
|
+
text: CLAUDE_CODE_IDENTITY_PROMPT
|
|
402
|
+
}, ...system ?? []] : system;
|
|
403
|
+
const shouldStream = config.stream ?? false;
|
|
404
|
+
const params = {
|
|
405
|
+
model: this.modelName,
|
|
406
|
+
...resolvedSystem && resolvedSystem.length > 0 ? { system: resolvedSystem } : {},
|
|
407
|
+
max_tokens: config.max_tokens ?? getEnvInt("ANTHROPIC_MAX_TOKENS", thinkingEnabled ? 2048 : 1024),
|
|
408
|
+
messages: extractedMessages,
|
|
409
|
+
stream: shouldStream,
|
|
410
|
+
...resolvedTopP != null || thinkingEnabled ? {} : { temperature: config.temperature ?? parseEnvFloat(this.env?.ANTHROPIC_TEMPERATURE) ?? getEnvFloat("ANTHROPIC_TEMPERATURE", 0) },
|
|
411
|
+
...resolvedTopP == null ? {} : { top_p: resolvedTopP },
|
|
412
|
+
...config.top_k == null || thinkingEnabled ? {} : { top_k: config.top_k },
|
|
413
|
+
...config.cache_control ? { cache_control: config.cache_control } : {},
|
|
414
|
+
...config.service_tier ? { service_tier: config.service_tier } : {},
|
|
415
|
+
...config.stop_sequences?.length ? { stop_sequences: config.stop_sequences } : {},
|
|
416
|
+
...config.metadata ? { metadata: config.metadata } : {},
|
|
417
|
+
...allTools.length > 0 ? { tools: allTools } : {},
|
|
418
|
+
...resolvedToolChoice ? { tool_choice: resolvedToolChoice } : {},
|
|
419
|
+
...resolvedThinking ? { thinking: resolvedThinking } : {},
|
|
420
|
+
...processedOutputFormat || config.effort ? { output_config: {
|
|
421
|
+
...processedOutputFormat ? { format: processedOutputFormat } : {},
|
|
422
|
+
...config.effort ? { effort: config.effort } : {}
|
|
423
|
+
} } : {},
|
|
424
|
+
...typeof config?.extra_body === "object" && config.extra_body ? config.extra_body : {}
|
|
425
|
+
};
|
|
426
|
+
logger.debug("Calling Anthropic Messages API", { params });
|
|
427
|
+
const headers = { ...config.headers || {} };
|
|
428
|
+
let allBetaFeatures = [...config.beta || [], ...requiredBetaFeatures];
|
|
429
|
+
const userBetaHeader = config.headers?.["anthropic-beta"];
|
|
430
|
+
if (typeof userBetaHeader === "string" && userBetaHeader.length > 0) allBetaFeatures.push(...userBetaHeader.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0));
|
|
431
|
+
if (processedOutputFormat && !allBetaFeatures.includes("structured-outputs-2025-11-13")) allBetaFeatures.push("structured-outputs-2025-11-13");
|
|
432
|
+
if (this.usingClaudeCodeOAuth) allBetaFeatures.push(...CLAUDE_CODE_OAUTH_BETA_FEATURES);
|
|
433
|
+
allBetaFeatures = [...new Set(allBetaFeatures)];
|
|
434
|
+
if (allBetaFeatures.length > 0) headers["anthropic-beta"] = allBetaFeatures.join(",");
|
|
435
|
+
if (this.usingClaudeCodeOAuth) {
|
|
436
|
+
headers["user-agent"] = CLAUDE_CODE_USER_AGENT;
|
|
437
|
+
headers["x-app"] = "cli";
|
|
438
|
+
}
|
|
439
|
+
const cache = await getCache();
|
|
440
|
+
const { metadata: _metadata, ...cacheKeyParams } = params;
|
|
441
|
+
const cacheKey = `anthropic:${JSON.stringify(cacheKeyParams)}`;
|
|
442
|
+
if (isCacheEnabled()) {
|
|
443
|
+
const cachedResponse = await cache.get(cacheKey);
|
|
444
|
+
if (cachedResponse) {
|
|
445
|
+
logger.debug(`Returning cached response for ${prompt}: ${cachedResponse}`);
|
|
446
|
+
try {
|
|
447
|
+
const parsedCachedResponse = JSON.parse(cachedResponse);
|
|
448
|
+
const finishReason = normalizeFinishReason(parsedCachedResponse.stop_reason);
|
|
449
|
+
let output = outputFromMessage(parsedCachedResponse, config.showThinking ?? true);
|
|
450
|
+
if (processedOutputFormat?.type === "json_schema" && typeof output === "string") try {
|
|
451
|
+
output = JSON.parse(output);
|
|
452
|
+
} catch (error) {
|
|
453
|
+
logger.error(`Failed to parse JSON output from structured outputs: ${error}`);
|
|
454
|
+
}
|
|
455
|
+
const cachedRefusalDetails = getRefusalDetails(parsedCachedResponse);
|
|
456
|
+
return {
|
|
457
|
+
output,
|
|
458
|
+
tokenUsage: getTokenUsage(parsedCachedResponse, true),
|
|
459
|
+
...finishReason && { finishReason },
|
|
460
|
+
...cachedRefusalDetails && { guardrails: {
|
|
461
|
+
flagged: true,
|
|
462
|
+
reason: cachedRefusalDetails
|
|
463
|
+
} },
|
|
464
|
+
cost: calculateAnthropicCost(this.modelName, config, parsedCachedResponse.usage?.input_tokens, parsedCachedResponse.usage?.output_tokens, parsedCachedResponse.usage?.cache_read_input_tokens ?? void 0, parsedCachedResponse.usage?.cache_creation_input_tokens ?? void 0),
|
|
465
|
+
cached: true
|
|
466
|
+
};
|
|
467
|
+
} catch {
|
|
468
|
+
return {
|
|
469
|
+
output: cachedResponse,
|
|
470
|
+
tokenUsage: createEmptyTokenUsage()
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
try {
|
|
476
|
+
if (shouldStream) {
|
|
477
|
+
const finalMessage = await (await this.anthropic.messages.stream(params, { ...typeof headers === "object" && Object.keys(headers).length > 0 ? { headers } : {} })).finalMessage();
|
|
478
|
+
logger.debug(`Anthropic Messages API streaming complete`, { finalMessage });
|
|
479
|
+
if (isCacheEnabled()) try {
|
|
480
|
+
await cache.set(cacheKey, JSON.stringify(finalMessage));
|
|
481
|
+
} catch (err) {
|
|
482
|
+
logger.error(`Failed to cache response: ${String(err)}`);
|
|
483
|
+
}
|
|
484
|
+
const finishReason = normalizeFinishReason(finalMessage.stop_reason);
|
|
485
|
+
let output = outputFromMessage(finalMessage, config.showThinking ?? true);
|
|
486
|
+
if (processedOutputFormat?.type === "json_schema" && typeof output === "string") try {
|
|
487
|
+
output = JSON.parse(output);
|
|
488
|
+
} catch (error) {
|
|
489
|
+
logger.error(`Failed to parse JSON output from structured outputs: ${error}`);
|
|
490
|
+
}
|
|
491
|
+
const refusalDetails = getRefusalDetails(finalMessage);
|
|
492
|
+
if (refusalDetails) logger.warn(refusalDetails);
|
|
493
|
+
return {
|
|
494
|
+
output,
|
|
495
|
+
tokenUsage: getTokenUsage(finalMessage, false),
|
|
496
|
+
...finishReason && { finishReason },
|
|
497
|
+
...refusalDetails && { guardrails: {
|
|
498
|
+
flagged: true,
|
|
499
|
+
reason: refusalDetails
|
|
500
|
+
} },
|
|
501
|
+
cost: calculateAnthropicCost(this.modelName, config, finalMessage.usage?.input_tokens, finalMessage.usage?.output_tokens, finalMessage.usage?.cache_read_input_tokens ?? void 0, finalMessage.usage?.cache_creation_input_tokens ?? void 0)
|
|
502
|
+
};
|
|
503
|
+
} else {
|
|
504
|
+
const response = await this.anthropic.messages.create(params, { ...typeof headers === "object" && Object.keys(headers).length > 0 ? { headers } : {} });
|
|
505
|
+
logger.debug(`Anthropic Messages API response`, { response });
|
|
506
|
+
if (isCacheEnabled()) try {
|
|
507
|
+
await cache.set(cacheKey, JSON.stringify(response));
|
|
508
|
+
} catch (err) {
|
|
509
|
+
logger.error(`Failed to cache response: ${String(err)}`);
|
|
510
|
+
}
|
|
511
|
+
const finishReason = normalizeFinishReason(response.stop_reason);
|
|
512
|
+
let output = outputFromMessage(response, config.showThinking ?? true);
|
|
513
|
+
if (processedOutputFormat?.type === "json_schema" && typeof output === "string") try {
|
|
514
|
+
output = JSON.parse(output);
|
|
515
|
+
} catch (error) {
|
|
516
|
+
logger.error(`Failed to parse JSON output from structured outputs: ${error}`);
|
|
517
|
+
}
|
|
518
|
+
const refusalDetails = getRefusalDetails(response);
|
|
519
|
+
if (refusalDetails) logger.warn(refusalDetails);
|
|
520
|
+
return {
|
|
521
|
+
output,
|
|
522
|
+
tokenUsage: getTokenUsage(response, false),
|
|
523
|
+
...finishReason && { finishReason },
|
|
524
|
+
...refusalDetails && { guardrails: {
|
|
525
|
+
flagged: true,
|
|
526
|
+
reason: refusalDetails
|
|
527
|
+
} },
|
|
528
|
+
cost: calculateAnthropicCost(this.modelName, config, response.usage?.input_tokens, response.usage?.output_tokens, response.usage?.cache_read_input_tokens ?? void 0, response.usage?.cache_creation_input_tokens ?? void 0)
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
} catch (err) {
|
|
532
|
+
logger.error(`Anthropic Messages API call error: ${err instanceof Error ? err.message : String(err)}`);
|
|
533
|
+
if (err instanceof APIError && err.error) {
|
|
534
|
+
const errorDetails = err.error;
|
|
535
|
+
return { error: `API call error: ${errorDetails.error.message}, status ${err.status}, type ${errorDetails.error.type}` };
|
|
536
|
+
}
|
|
537
|
+
return { error: `API call error: ${err instanceof Error ? err.message : String(err)}` };
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
//#endregion
|
|
542
|
+
export { AnthropicGenericProvider as n, AnthropicMessagesProvider as t };
|
|
543
|
+
|
|
544
|
+
//# sourceMappingURL=messages-B9dSjrNf.js.map
|