promptfoo 0.121.4 → 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/dist/src/{ListApp-DQkFNqE9.js → ListApp-BRUsT43Y.js} +1 -1
- package/dist/src/{accounts-Dy17bs4D.cjs → accounts-BIFntVWB.cjs} +4 -4
- package/dist/src/{accounts-F9d_5sMC.js → accounts-CLJHCDDb.js} +6 -6
- package/dist/src/{accounts-DhMYUUbu.js → accounts-CaLNYnf7.js} +4 -4
- package/dist/src/{accounts-DdJ2pHMI.js → accounts-bnyHT7Ju.js} +5 -5
- package/dist/src/{agentic-utils-w68v6_Dz.js → agentic-utils-B5krlibj.js} +3 -3
- package/dist/src/{agentic-utils-P172hM8B.js → agentic-utils-Ba67xmgs.js} +2 -2
- package/dist/src/{agentic-utils-qFlm6zes.js → agentic-utils-BclbiXiq.js} +3 -3
- package/dist/src/{agentic-utils-BpX5b23w.cjs → agentic-utils-D2x0wGhB.cjs} +2 -2
- package/dist/src/{agents-CgaMXvLM.js → agents-BGqaTDnr.js} +5 -5
- package/dist/src/{agents-8FDnTriG.js → agents-BV9yFpXX.js} +5 -5
- package/dist/src/{agents-aYPQLf8W.js → agents-BYdMl1UE.js} +4 -4
- package/dist/src/{agents-pQeBEXMm.js → agents-DhxWMCtH.js} +5 -5
- package/dist/src/{agents-D7-HGxUj.cjs → agents-DiWmQYH9.cjs} +4 -4
- package/dist/src/{agents-BahDpe5G.cjs → agents-WULPVjbH.cjs} +4 -4
- package/dist/src/{agents-DJ35I3Nt.js → agents-emVcx3yh.js} +5 -5
- package/dist/src/{agents-C-R_jfzI.js → agents-n6vPqV3i.js} +4 -4
- package/dist/src/{aimlapi-BCq3MHeL.js → aimlapi-BxqK9HF_.js} +7 -7
- package/dist/src/{aimlapi-qcK4OT55.cjs → aimlapi-BzLjZI_m.cjs} +6 -6
- package/dist/src/{aimlapi-BD6J9oKt.js → aimlapi-DR4pgeiC.js} +6 -6
- package/dist/src/{aimlapi-sgYnkE54.js → aimlapi-uPGp0Zdo.js} +7 -7
- package/dist/src/app/app/tsconfig.app.tsbuildinfo +1 -1
- 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-BXGkeMwh.css → index-Cli2yAXv.css} +1 -1
- package/dist/src/app/index.html +27 -2
- package/dist/src/{audio-DcVKoInv.js → audio-BvpTOArF.js} +4 -4
- package/dist/src/{audio-BQtNuYBj.cjs → audio-C0vDeS0j.cjs} +3 -3
- package/dist/src/{audio-B7izf48x.js → audio-CScmnmEB.js} +4 -4
- package/dist/src/{audio-COrn8rM6.js → audio-Da8U9IS5.js} +3 -3
- package/dist/src/{base-fZ9wgg50.js → base-BOMaNEes.js} +3 -3
- package/dist/src/{base-PYJvBE1i.js → base-BTux96b1.js} +2 -2
- package/dist/src/{base-D-670DX8.cjs → base-Tw6uhH8K.cjs} +2 -2
- package/dist/src/{base-yrI1Yal4.js → base-dYsl2hmL.js} +3 -3
- package/dist/src/{blobs-D2FAd1Q5.cjs → blobs-B95F_7vE.cjs} +2 -2
- package/dist/src/{blobs-C-F78Kfn.js → blobs-BW4U31ue.js} +2 -2
- package/dist/src/{blobs-BCZavS8s.js → blobs-D_gg8nbm.js} +3 -3
- package/dist/src/{blobs-BQWqnnvL.js → blobs-DjLby-uP.js} +3 -3
- package/dist/src/{cache-mb7c8hbp.js → cache-BI5BY7ey.js} +4 -4
- package/dist/src/{cache-DbLsVWB2.cjs → cache-BRkhlH3k.cjs} +1 -1
- package/dist/src/cache-BlC6aeJ0.js +3 -0
- package/dist/src/{cache-D5NZmMiT.js → cache-Bzttsk0X.js} +2 -2
- package/dist/src/{cache-C4Xb-hNb.js → cache-Cr-qWIbP.js} +3 -3
- package/dist/src/{cache-BIyPcp5v.cjs → cache-DGg-yTZG.cjs} +2 -2
- package/dist/src/{chat-Dr3DUQ0D.js → chat-BLOdH60v.js} +12 -12
- package/dist/src/{chat-BfPaS15_.js → chat-Cx_LkwvZ.js} +12 -12
- package/dist/src/{chat-mW0ORo8G.js → chat-D9nudO9b.js} +4 -4
- package/dist/src/{chat-I9izLm49.js → chat-DChSH_Es.js} +12 -12
- package/dist/src/{chat-MKxMnZJZ.js → chat-DG2LkwLq.js} +2 -2
- package/dist/src/{chat-BPXSW8Bv.cjs → chat-DH97tVV9.cjs} +2 -2
- package/dist/src/{chat-0bwXjVP0.js → chat-aMQZw6R7.js} +4 -4
- package/dist/src/{chat-CclRbxGf.cjs → chat-vYqqv1gP.cjs} +11 -11
- package/dist/src/{chatkit-zUIVoDos.js → chatkit-B8X34dQc.js} +4 -4
- package/dist/src/{chatkit-Cv6AhukM.js → chatkit-BXu42Qwt.js} +3 -3
- package/dist/src/{chatkit-CJnHRRMM.js → chatkit-CbMRoeYw.js} +4 -4
- package/dist/src/{chatkit-BoWoSgXl.cjs → chatkit-D44VyUyB.cjs} +3 -3
- package/dist/src/{claude-agent-sdk-CPJo3dBQ.cjs → claude-agent-sdk-BRq0bbIK.cjs} +8 -8
- package/dist/src/{claude-agent-sdk-BQNuLaAK.js → claude-agent-sdk-BjriSVRZ.js} +7 -7
- package/dist/src/{claude-agent-sdk-Dtq_L-Sc.js → claude-agent-sdk-BzNZeZ0N.js} +7 -7
- package/dist/src/{claude-agent-sdk-nfAIcxNf.js → claude-agent-sdk-DYv_AJ8u.js} +7 -7
- package/dist/src/cloud-CoD5OacT.js +3 -0
- package/dist/src/{cloud-DQZ5sVjW.js → cloud-Da0bofJd.js} +3 -3
- package/dist/src/{cloudflare-ai-BIB567w6.js → cloudflare-ai-CXC4b1EU.js} +4 -4
- package/dist/src/{cloudflare-ai-DlKr0rY7.js → cloudflare-ai-CyBoIs1Q.js} +6 -6
- package/dist/src/{cloudflare-ai-DGLte7Py.js → cloudflare-ai-DGOwgexC.js} +6 -6
- package/dist/src/{cloudflare-ai-Dl3N9OVD.cjs → cloudflare-ai-DJv5qnyb.cjs} +4 -4
- package/dist/src/{cloudflare-gateway-BDZrYydE.js → cloudflare-gateway-1sAoOyft.js} +5 -5
- package/dist/src/{cloudflare-gateway-CiIZHU0Q.js → cloudflare-gateway-D-dnkzCF.js} +5 -5
- package/dist/src/{cloudflare-gateway-BYDp495F.cjs → cloudflare-gateway-DKVjkDav.cjs} +3 -3
- package/dist/src/{cloudflare-gateway-DI1HNP5F.js → cloudflare-gateway-TJkVrZlB.js} +3 -3
- 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-C2_M2pl_.cjs → codex-sdk-Bd8UbO9q.cjs} +5 -5
- package/dist/src/{codex-sdk-CpqiOqDO.js → codex-sdk-BgEFQ70r.js} +6 -6
- package/dist/src/{codex-sdk-Rtky3M4I.js → codex-sdk-Bzb_TqX9.js} +6 -6
- package/dist/src/{codex-sdk-CWEnH70W.cjs → codex-sdk-Danroptg.cjs} +1 -1
- package/dist/src/{codex-sdk-CErXn7qh.js → codex-sdk-DfvDTN33.js} +5 -5
- package/dist/src/{cometapi-CtJ-mS8R.js → cometapi-B5ImDlSm.js} +8 -8
- package/dist/src/{cometapi-UVOryo4W.cjs → cometapi-BgAkuYCw.cjs} +7 -7
- package/dist/src/{cometapi-BUlt_ELa.js → cometapi-CC7hWxmX.js} +8 -8
- package/dist/src/{cometapi-DT-jlVCB.js → cometapi-CCbpHkuF.js} +7 -7
- package/dist/src/{completion-x0a_c2y1.js → completion-2iuYVxwi.js} +6 -6
- package/dist/src/{completion-Dnxn7E-j.js → completion-CrD6MQ93.js} +5 -5
- package/dist/src/{completion-BozdoXba.cjs → completion-DtQ72Bm3.cjs} +5 -5
- package/dist/src/{completion-HUe8wDhZ.js → completion-Vq_ad618.js} +6 -6
- package/dist/src/{createHash-ChI45QR1.js → createHash-DPpsZgFF.js} +1 -1
- package/dist/src/{createHash-CwDVU5xr.js → createHash-Un4Q_huE.js} +1 -1
- package/dist/src/{createHash-B7KvgoOD.cjs → createHash-VvBIc-AW.cjs} +1 -1
- package/dist/src/{docker-DCgsveLD.js → docker--3qzPa-6.js} +6 -6
- package/dist/src/{docker-DS4_Osau.cjs → docker-D3AY-5F5.cjs} +5 -5
- package/dist/src/{docker-CQmlA2NU.js → docker-DCsCDvwM.js} +6 -6
- package/dist/src/{docker-ClnmCf1Z.js → docker-Dorv4_Dg.js} +5 -5
- package/dist/src/{embedding-I45KG3o7.cjs → embedding-BXhN5lCH.cjs} +5 -5
- package/dist/src/{embedding-nFbumxcv.js → embedding-ChS1ivFS.js} +5 -5
- package/dist/src/{embedding-D3xTseo7.js → embedding-DNRvZwRN.js} +6 -6
- package/dist/src/{embedding-DD9wa3ae.js → embedding-D_bI4NDq.js} +6 -6
- package/dist/src/{errors-Cw810C93.js → errors-DFHe4L-n.js} +1 -1
- package/dist/src/{esm-Dh4dOLlt.js → esm-B6whoAcf.js} +2 -2
- package/dist/src/{esm-C7PnfdF8.js → esm-BRkfNsYs.js} +1 -1
- package/dist/src/{esm-tVgYPY-f.js → esm-BX8fwlAO.js} +2 -2
- package/dist/src/{esm-CtEPLdAj.cjs → esm-B_rGuPTo.cjs} +1 -1
- package/dist/src/{eval-CzJFfFO9.js → eval-BQPLBJbw.js} +1 -1
- package/dist/src/{eval-u4UVafl6.js → eval-DJ_4A-tr.js} +14 -14
- package/dist/src/evalResult-BBJAHAtw.cjs +2 -0
- package/dist/src/evalResult-BBK58h2B.js +3 -0
- package/dist/src/{evalResult-KZqXl4XP.cjs → evalResult-Cx-8OWkb.cjs} +28 -10
- package/dist/src/{evalResult-D3hVYFis.js → evalResult-D6P5I5il.js} +29 -11
- package/dist/src/{evalResult-Bgm9ZH31.js → evalResult-pSvGWFMo.js} +29 -11
- package/dist/src/{evaluator-IvuDYSvQ.js → evaluator-D-UIbbYq.js} +845 -98
- package/dist/src/evaluator-DgLKaZk8.js +3 -0
- package/dist/src/{extractor-Dk6bRWkv.js → extractor-BM3jRERL.js} +5 -5
- package/dist/src/{extractor-WVPOrH43.cjs → extractor-Dxr2J_wK.cjs} +5 -5
- package/dist/src/{extractor-DNSeBVOJ.js → extractor-DxyiFhPk.js} +6 -6
- package/dist/src/{extractor-CAfTSraf.js → extractor-YlZbUMsL.js} +6 -6
- package/dist/src/fetch-8viavNv8.js +3 -0
- package/dist/src/{fetch-BEWnXrrG.js → fetch-B6ch2nU2.js} +9 -20
- package/dist/src/{fetch-Di00EQrc.js → fetch-D9xxyC1p.js} +221 -232
- package/dist/src/{fetch-CJU5ELPa.cjs → fetch-NuqXW1Xb.cjs} +221 -244
- package/dist/src/{fetch-B0Z3Oe4k.js → fetch-Y5qX_kST.js} +8 -19
- package/dist/src/{fileExtensions-BArZuxsI.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-AWa2ZML4.js → fileExtensions-DysCsxNG.js} +1 -1
- package/dist/src/{formatDuration-DZzPsexs.js → formatDuration-Ch4A7G3o.js} +1 -1
- package/dist/src/{genaiTracer-yRuxj9-L.cjs → genaiTracer-BokHC-MW.cjs} +1 -1
- package/dist/src/{genaiTracer-DWdZ28hY.js → genaiTracer-C3ZPQU60.js} +1 -1
- package/dist/src/{genaiTracer-XnrcgDCe.js → genaiTracer-CFny3gOy.js} +1 -1
- package/dist/src/{genaiTracer-COYDi-tC.js → genaiTracer-DxODqT9e.js} +1 -1
- package/dist/src/{graders-Zy3x0zqX.js → graders-BoUqsCEm.js} +1303 -2044
- package/dist/src/{graders--zknU_uk.cjs → graders-Bw1wk_21.cjs} +1553 -2240
- 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-eIHhRqoC.js → graders-CgPn32yp.js} +1300 -2041
- package/dist/src/{graders-pvbReLLn.js → graders-CwrbifOo.js} +747 -1488
- package/dist/src/graders-DS42d3ZG.js +2 -0
- package/dist/src/{image-9302QVqR.js → image-BeWaInPF.js} +3 -3
- package/dist/src/{image-DVz2RiMF.js → image-BmilRNqO.js} +7 -7
- package/dist/src/{image-x6KqLQl4.cjs → image-CxJoa3aW.cjs} +6 -6
- package/dist/src/{image-De2FBmYV.cjs → image-D10dNAav.cjs} +3 -3
- package/dist/src/{image-dnoUgPrC.js → image-Dr_3I3nK.js} +4 -4
- package/dist/src/{image-B5Mv-Z3h.js → image-DsGRlkh7.js} +7 -7
- package/dist/src/{image-qUpPvmNZ.js → image-a_SGUobh.js} +6 -6
- package/dist/src/{image-u7-rKnYU.js → image-qjO6FWPs.js} +4 -4
- package/dist/src/index.cjs +1052 -296
- package/dist/src/index.d.cts +124 -13
- package/dist/src/index.d.ts +125 -14
- package/dist/src/index.js +1018 -262
- package/dist/src/{interactiveCheck-CLERUB0c.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-RhFPGWDc.js → knowledgeBase-BBETc5-S.js} +6 -6
- package/dist/src/{knowledgeBase-Bpoe_nLu.cjs → knowledgeBase-C8qOo26M.cjs} +5 -5
- package/dist/src/{knowledgeBase-lm9RXSAm.js → knowledgeBase-CzAi2rUI.js} +6 -6
- package/dist/src/{knowledgeBase-Dgc7CBWF.js → knowledgeBase-Dr3Kib7F.js} +5 -5
- package/dist/src/{litellm-C2kqjxqp.js → litellm-BLSiANhk.js} +5 -5
- package/dist/src/{litellm-CoyI4IAl.cjs → litellm-CaUmV7Mk.cjs} +4 -4
- package/dist/src/{litellm-p37R1dzQ.js → litellm-DQGo_juI.js} +4 -4
- package/dist/src/{litellm-DRjpcSa7.js → litellm-DRc4qWfc.js} +5 -5
- package/dist/src/{logger-DksKw1Qc.js → logger-BbY6ypFL.js} +2 -2
- package/dist/src/{logger-B88EkIn6.js → logger-KD8JjCRJ.js} +2 -2
- package/dist/src/{luma-ray-KgTCXrZC.js → luma-ray-B-tNZzqW.js} +6 -6
- package/dist/src/{luma-ray-B863CmuZ.js → luma-ray-CtS3OlGq.js} +5 -5
- package/dist/src/{luma-ray-BTTLtqQ8.js → luma-ray-PJJgUjOc.js} +6 -6
- package/dist/src/{luma-ray-BxVKaW2a.cjs → luma-ray-if-Ml4R9.cjs} +5 -5
- package/dist/src/main.js +242 -198
- package/dist/src/{messages-zWbkLLHz.js → messages-B9dSjrNf.js} +264 -16
- package/dist/src/{messages-811uVVW5.cjs → messages-BnsVHUnm.cjs} +266 -15
- package/dist/src/{messages-MYTQ2TWp.js → messages-CI69Lasb.js} +264 -16
- package/dist/src/{messages-BTQz42fn.js → messages-CewuNcNS.js} +264 -16
- package/dist/src/{meteor-Co1VQ1u5.cjs → meteor-BBGcGeCa.cjs} +1 -1
- package/dist/src/{meteor-DuAFv6gF.js → meteor-BKTM-7KS.js} +1 -1
- package/dist/src/{meteor-DHdzY1Ss.js → meteor-CeGo0Lu2.js} +2 -2
- package/dist/src/{meteor-CU5UAE-H.js → meteor-Wc_aUVvu.js} +2 -2
- package/dist/src/{modelslab-wu9yi5GE.js → modelslab-BCLOtfek.js} +7 -7
- package/dist/src/{modelslab-Dk1JAtVo.cjs → modelslab-BkapYJhh.cjs} +6 -6
- package/dist/src/{modelslab-DIq-6y7x.js → modelslab-D73OnKSx.js} +6 -6
- package/dist/src/{modelslab-D0erNWKe.js → modelslab-zpz9JcK0.js} +7 -7
- package/dist/src/{nova-reel-CCFRfeRb.js → nova-reel-B8F_TK5w.js} +6 -6
- package/dist/src/{nova-reel-DQrm74ng.js → nova-reel-Bx0NFV2f.js} +5 -5
- package/dist/src/{nova-reel-gr11WG7f.js → nova-reel-CNGJTLtG.js} +6 -6
- package/dist/src/{nova-reel-CrLXVKQf.cjs → nova-reel-DkT7tnoB.cjs} +5 -5
- package/dist/src/{nova-sonic-BYdp-QLs.js → nova-sonic-BaXRN1cr.js} +4 -4
- package/dist/src/{nova-sonic-TDgrlTk7.js → nova-sonic-BeTRaFOh.js} +4 -4
- package/dist/src/{nova-sonic-B_ZXcUJB.js → nova-sonic-CL7Zqv0G.js} +3 -3
- package/dist/src/{nova-sonic-i5tUvXKn.cjs → nova-sonic-YT426juD.cjs} +3 -3
- package/dist/src/{openai-DhVEmgeZ.js → openai-BMHD2Huo.js} +2 -2
- package/dist/src/{openai-Qsvz25mV.js → openai-BT-JvDse.js} +2 -2
- package/dist/src/{openai-URNyItar.cjs → openai-Cy1XLs0c.cjs} +1 -1
- package/dist/src/{openai-iYtrXzOX.js → openai-D4fxGvRx.js} +1 -1
- package/dist/src/{openclaw-CwzlQSQX.js → openclaw-Bq7RVR3k.js} +7 -6
- package/dist/src/{openclaw-CLWrW03k.js → openclaw-DA8U4DsD.js} +8 -7
- package/dist/src/{openclaw-CnQ363Wi.js → openclaw-DObVgpjC.js} +8 -7
- package/dist/src/{openclaw-wX9rtfke.cjs → openclaw-DUBZP3GL.cjs} +8 -7
- package/dist/src/{opencode-sdk-BUu5Nevv.js → opencode-sdk-BB40Wir1.js} +4 -4
- package/dist/src/{opencode-sdk-GI2KaAXq.js → opencode-sdk-BM1UAIv1.js} +3 -3
- package/dist/src/{opencode-sdk-BZ2idgYA.cjs → opencode-sdk-CeqiOcOU.cjs} +4 -4
- package/dist/src/{opencode-sdk-BxD8vXp_.js → opencode-sdk-ChdK7F7z.js} +4 -4
- package/dist/src/{otlpReceiver-DmVulbhC.js → otlpReceiver-C6thJRXi.js} +4 -4
- package/dist/src/{otlpReceiver-B2z58l4e.js → otlpReceiver-CcdIikOu.js} +3 -3
- package/dist/src/{otlpReceiver-BfcVq2Nq.cjs → otlpReceiver-DNSQj6bf.cjs} +3 -3
- package/dist/src/{otlpReceiver-BntK801g.js → otlpReceiver-UYMQx3sy.js} +4 -4
- package/dist/src/{providerRegistry-CPQ_CmVO.js → providerRegistry-1gB5vtzQ.js} +2 -2
- package/dist/src/{providerRegistry-CQMdTmHP.cjs → providerRegistry-BESeALrr.cjs} +1 -1
- package/dist/src/{providerRegistry-Bvh8mv85.js → providerRegistry-DoACwqhD.js} +1 -1
- package/dist/src/{providerRegistry-CWoPjKFZ.js → providerRegistry-PMsleEzs.js} +2 -2
- package/dist/src/{providers-Bp4S-FvO.js → providers-BuyzKt7C.js} +1 -1
- package/dist/src/{providers-DV3ax9e_.cjs → providers-C7lNVBjX.cjs} +1 -1
- package/dist/src/{providers-u9Enmfok.js → providers-CCE2COJi2.js} +1 -1
- package/dist/src/{providers-DruaQfwu.js → providers-CJh7iriU.js} +18103 -17952
- package/dist/src/{providers-iUt5fbAN.js → providers-Ctcc592x.js} +1 -1
- package/dist/src/{providers-Domz_llv.js → providers-DRrerKra.js} +432 -281
- package/dist/src/{providers-BV_KMZje.js → providers-DT-GtF2t.js} +19094 -18943
- package/dist/src/{providers-1eKkXBKp.cjs → providers-eDShy16E.cjs} +17946 -17795
- package/dist/src/{pythonUtils-Cldx7huE.js → pythonUtils-C4tltmIn.js} +3 -3
- package/dist/src/{pythonUtils-tAJvvpS-.cjs → pythonUtils-CoLaCwNY.cjs} +3 -3
- package/dist/src/{pythonUtils-C2UQ30Rz.js → pythonUtils-DMO68Jg7.js} +3 -3
- package/dist/src/{pythonUtils-CnndUbW-.js → pythonUtils-DNqbnRdx.js} +3 -3
- package/dist/src/{quiverai-DR0SnIQV.js → quiverai-BSS9a7wV.js} +3 -3
- package/dist/src/{quiverai-CtWi6x_g.js → quiverai-Bk1KrvL6.js} +4 -4
- package/dist/src/{quiverai-DFotyafY.cjs → quiverai-Bpx6MZ7T.cjs} +3 -3
- package/dist/src/{quiverai-aPPvXOgn.js → quiverai-CPKhWgaT.js} +4 -4
- package/dist/src/{render-DHIZ6_k8.js → render-7uNJ2V14.js} +2 -2
- package/dist/src/{render-CH-62LbA.js → render-DlscvAUJ.js} +1 -1
- package/dist/src/{render-CMEpfLaO.js → render-eui5p5mL.js} +2 -2
- package/dist/src/{render-CgVDrJmM.js → render-nj-UaPdn.js} +2 -2
- package/dist/src/{render-DfQSFxGE.cjs → render-tG6ir9_g.cjs} +1 -1
- package/dist/src/{responses--OsX2aYW.js → responses-1ztiVYsx.js} +49 -15
- package/dist/src/{responses-DL9m8CyY.js → responses-B8haB-mD.js} +49 -15
- package/dist/src/{responses-C-flexAY.js → responses-BiaBguAu.js} +49 -15
- package/dist/src/{responses-Bi9vBuW_.cjs → responses-CF-ayauu.cjs} +48 -14
- package/dist/src/rubyUtils-4hjGxvju.js +3 -0
- package/dist/src/{rubyUtils-DVLeA2jg.js → rubyUtils-BI0p46eZ.js} +3 -3
- package/dist/src/{rubyUtils-DsGrTx8R.js → rubyUtils-CIQFnVz4.js} +3 -3
- package/dist/src/rubyUtils-CO-tuszQ.cjs +2 -0
- package/dist/src/{rubyUtils-CYSQEG4a.js → rubyUtils-DGnoCYL2.js} +3 -3
- package/dist/src/{rubyUtils-B6eljPuh.cjs → rubyUtils-DoifqkiA.cjs} +4 -3
- package/dist/src/{sagemaker-BveBvuxm.js → sagemaker-BDLeW29y.js} +12 -12
- package/dist/src/{sagemaker-D67yzMzs.js → sagemaker-C5T60MKf.js} +13 -13
- package/dist/src/{sagemaker-BVkaG2-l.js → sagemaker-ClS_NB07.js} +13 -13
- package/dist/src/{sagemaker-XnfhheQv.cjs → sagemaker-ljtY12VM.cjs} +12 -12
- package/dist/src/{scanner-1DqWi1Ej.js → scanner-nOCWNIXa.js} +7 -7
- package/dist/src/server/index.js +1067 -265
- package/dist/src/{server-Dx2TyCH2.cjs → server-BEECpeGG.cjs} +5 -5
- package/dist/src/{server-BNYztJkh.js → server-ByiF3qlg.js} +9 -8
- package/dist/src/{server-BSB45Nt9.js → server-ByxbqAcQ.js} +8 -7
- package/dist/src/{server-DaA2eR26.cjs → server-C0XKRNB_.cjs} +1 -1
- package/dist/src/server-C_15p79-.js +3 -0
- package/dist/src/{server-D6Il2Sob.js → server-gyd6d4Hc.js} +5 -5
- package/dist/src/{signal-CE5G3a7x.js → signal-DTtUuU3l.js} +3 -3
- package/dist/src/{slack-acRb0IqQ.js → slack-4zZX1OKP.js} +1 -1
- package/dist/src/{slack-1Rhq0EoV.cjs → slack-BLlsDpfG.cjs} +1 -1
- package/dist/src/{slack-D5Wpy8LM.js → slack-BPYLQLgb.js} +2 -2
- package/dist/src/{slack-DDUe-5MC.js → slack-Bamy_7te.js} +2 -2
- package/dist/src/{store-DAAyxcy6.cjs → store-2K0kDi80.cjs} +2 -2
- package/dist/src/{store-Dn9HUkdW.js → store-2OXm_eBY.js} +3 -3
- package/dist/src/store-BELqNwvz.js +3 -0
- package/dist/src/{store-M0b1WfYb.js → store-BPkzEyFM.js} +2 -2
- package/dist/src/{store-CYEy5J2D.js → store-CPh25336.js} +3 -3
- package/dist/src/store-uQZ4AjPe.cjs +2 -0
- package/dist/src/{tables-CsWou1Bx.js → tables-BMSOS2Gg.js} +3 -3
- package/dist/src/{tables-DUfh1F7Z.cjs → tables-CXbaZ9y1.cjs} +2 -2
- package/dist/src/{tables-C4CH3zRr.js → tables-NlvH23ky.js} +3 -3
- package/dist/src/{tables-DQ4WU5tX.js → tables-WgdUZ8Ck.js} +2 -2
- package/dist/src/{telemetry-dbaJ0E98.js → telemetry--iqaGyaS.js} +5 -4
- package/dist/src/{telemetry-Dsw_faFj.cjs → telemetry-CEQxGnMZ.cjs} +7 -6
- package/dist/src/{telemetry-Dvqxv3YC.js → telemetry-CgdVGV8N.js} +4 -3
- package/dist/src/{telemetry-CQPez_Jp.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-BVi-cLPJ.cjs → text-BiNME7QG.cjs} +1 -1
- package/dist/src/{text-KvuD2Iko.js → text-D4lz-Jg_.js} +1 -1
- package/dist/src/{text-DHxdyQqT.js → text-DDQP0tuQ.js} +1 -1
- package/dist/src/{text-CZr46tp_.js → text-NWvfMfkF.js} +1 -1
- package/dist/src/{tokenUsageUtils-CXrvO-wA.js → tokenUsageUtils-2wIvAhB3.js} +1 -1
- package/dist/src/{tokenUsageUtils-C-bmyHoE.js → tokenUsageUtils-4c780gFd.js} +1 -1
- package/dist/src/tokenUsageUtils-BjVkdk18.js +142 -0
- package/dist/src/{tokenUsageUtils-Bb7DkZPz.cjs → tokenUsageUtils-C9odhsbW.cjs} +1 -1
- package/dist/src/{transcription-DuWDupG7.js → transcription-84t4ALo2.js} +5 -5
- package/dist/src/{transcription-CJspiD2c.js → transcription-Bm2emLmJ.js} +6 -6
- package/dist/src/{transcription-BvjmiYB1.cjs → transcription-CZ4LG5hQ.cjs} +5 -5
- package/dist/src/{transcription-V2HaAmy2.js → transcription-D7Q0vJsh.js} +6 -6
- package/dist/src/{transform-zDhMmzwX.js → transform-B-b6Cq-q.js} +5 -5
- package/dist/src/transform-BQt0BeAW.js +3 -0
- package/dist/src/{transform-DgKlRr73.cjs → transform-Bq5oqC0s.cjs} +1 -1
- package/dist/src/{transform-CUnzlsbn.cjs → transform-C9izGX54.cjs} +4 -4
- package/dist/src/{transform-DYX1_Xnh.js → transform-CwbAZ84V.js} +5 -5
- package/dist/src/{transform-CTeuTR3S.cjs → transform-Dg4LcO1Y.cjs} +6 -6
- package/dist/src/{transform-CG0ehZNG.js → transform-DtooZqYY.js} +6 -6
- package/dist/src/{transform-UN5UGu8U.js → transform-DzCF-wqV.js} +5 -5
- package/dist/src/{transform-lQrDE1BQ.js → transform-_DpNB4qp.js} +5 -5
- package/dist/src/{transform-Bbg6A8Jk.js → transform-eGiUAv86.js} +4 -4
- package/dist/src/{transformersAvailability-Cju9mHgR.cjs → transformersAvailability-B22swDxr.cjs} +1 -1
- package/dist/src/{transformersAvailability-CcHusyhw.js → transformersAvailability-lvCCvuPT.js} +1 -1
- package/dist/src/{transformersAvailability-DLlROWhg.js → transformersAvailability-rJGPccjr.js} +1 -1
- package/dist/src/{types-Bgh5SOn6.js → types-BDjGOq4E.js} +4 -2
- package/dist/src/{types-Dm9JM6Vb.js → types-BVH9hjgW.js} +4 -2
- package/dist/src/{types-CeaeaZdP.cjs → types-CgG2rKiW.cjs} +151 -149
- package/dist/src/{types-BGQDAP8i.js → types-DNRZVOue.js} +152 -150
- package/dist/src/{util-C8e5uydV.js → util-3pBZZb_H.js} +142 -17
- package/dist/src/{util-CN3SrLT4.cjs → util-A5_ZsQUn.cjs} +65 -43
- package/dist/src/{util-D3q0WQ-0.js → util-B9CNhyac.js} +66 -44
- package/dist/src/{util-DxWpWjhc.js → util-BQOCAHQC.js} +700 -575
- package/dist/src/{util-BYvQUPp7.js → util-BVXcTwXu.js} +3 -3
- package/dist/src/{util-D9TisOyk.js → util-BlFVL0UF.js} +65 -43
- package/dist/src/{util-C9J8ahRn.js → util-C-kmRosx.js} +66 -44
- package/dist/src/{util-DvU2Pw8c.js → util-DFPeFkiV.js} +3 -3
- package/dist/src/{util-DDs-7g6-.js → util-DN0-b81k.js} +3 -3
- package/dist/src/{util-olYL5C6N.cjs → util-Dpmm_dAI.cjs} +3 -3
- package/dist/src/{util-oGMLA7vc.js → util-Dub0f_ej.js} +700 -575
- package/dist/src/{util-Bxn8emtE.cjs → util-DvpHnLt0.cjs} +718 -570
- package/dist/src/{utils-DJfvjyMj.js → utils-BUMN8orw.js} +3 -3
- package/dist/src/{utils-B05gLxER.cjs → utils-DkVeShIB.cjs} +2 -2
- package/dist/src/{utils-BLJKfv0y.js → utils-kt7lv30R.js} +3 -3
- package/dist/src/{utils-hXtCYanr.js → utils-o8S5huU2.js} +2 -2
- 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 +22 -20
- package/dist/src/app/assets/Report-CQYFezYu.js +0 -1
- package/dist/src/app/assets/index-BzJt18Jz.js +0 -385
- package/dist/src/cache-Cr9oLMUa.js +0 -3
- package/dist/src/cloud-Hphvo8kr.js +0 -3
- package/dist/src/codex-sdk-BAmYE7qy.js +0 -3
- package/dist/src/evalResult-D8MT9p0s.js +0 -3
- package/dist/src/evalResult-Dvc-iucu.cjs +0 -2
- package/dist/src/evaluator-CVessDWe.js +0 -3
- package/dist/src/fetch-C7bGKDlQ.js +0 -3
- package/dist/src/graders-BOAzQEUe.cjs +0 -2
- package/dist/src/graders-D4BTsZdG2.js +0 -3
- package/dist/src/graders-DOJK1XpV.js +0 -2
- package/dist/src/graders-NAv9LcBn.js +0 -2
- package/dist/src/rubyUtils-D1L2d3jb.js +0 -3
- package/dist/src/rubyUtils-DUbq4tff.cjs +0 -2
- package/dist/src/server-DCtHUqlp.js +0 -3
- package/dist/src/store-CWOSz6D_.cjs +0 -2
- package/dist/src/store-DCDBhv7B.js +0 -3
- package/dist/src/telemetry-C1IqxcdW.js +0 -3
- package/dist/src/telemetry-C4ZEa_es.cjs +0 -2
- package/dist/src/transform-M6ITAESf.js +0 -3
- /package/dist/src/{evalResult-DElBuddX.js → evalResult-spPqh1G_.js} +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const require_logger = require("./logger-COuQb2xB.cjs");
|
|
2
2
|
const require_invariant = require("./invariant-kfQ8Bu82.cjs");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const require_render = require("./render-
|
|
8
|
-
const
|
|
3
|
+
const require_fetch = require("./fetch-NuqXW1Xb.cjs");
|
|
4
|
+
const require_version = require("./version-D9zu9FWB.cjs");
|
|
5
|
+
const require_types = require("./types-CgG2rKiW.cjs");
|
|
6
|
+
const require_esm = require("./esm-B_rGuPTo.cjs");
|
|
7
|
+
const require_render = require("./render-tG6ir9_g.cjs");
|
|
8
|
+
const require_pythonUtils = require("./pythonUtils-CoLaCwNY.cjs");
|
|
9
|
+
const require_fileExtensions = require("./fileExtensions-D9h-8Wxg.cjs");
|
|
9
10
|
let fs = require("fs");
|
|
10
11
|
fs = require_logger.__toESM(fs);
|
|
11
12
|
let path = require("path");
|
|
@@ -20,678 +21,801 @@ let dedent = require("dedent");
|
|
|
20
21
|
dedent = require_logger.__toESM(dedent);
|
|
21
22
|
let fs_promises = require("fs/promises");
|
|
22
23
|
fs_promises = require_logger.__toESM(fs_promises);
|
|
24
|
+
let nunjucks = require("nunjucks");
|
|
25
|
+
nunjucks = require_logger.__toESM(nunjucks);
|
|
26
|
+
let csv_parse_sync = require("csv-parse/sync");
|
|
23
27
|
let glob = require("glob");
|
|
24
28
|
let fast_deep_equal = require("fast-deep-equal");
|
|
25
29
|
fast_deep_equal = require_logger.__toESM(fast_deep_equal);
|
|
26
|
-
let csv_parse_sync = require("csv-parse/sync");
|
|
27
|
-
let nunjucks = require("nunjucks");
|
|
28
|
-
nunjucks = require_logger.__toESM(nunjucks);
|
|
29
30
|
let fast_xml_parser = require("fast-xml-parser");
|
|
30
31
|
let csv_stringify_sync = require("csv-stringify/sync");
|
|
31
|
-
//#region src/util/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
//#region src/util/functions/loadFunction.ts
|
|
33
|
+
const functionCache = {};
|
|
34
|
+
/**
|
|
35
|
+
* Loads a function from a JavaScript or Python file
|
|
36
|
+
* @param options Options for loading the function
|
|
37
|
+
* @returns The loaded function
|
|
38
|
+
*/
|
|
39
|
+
async function loadFunction({ filePath, functionName, defaultFunctionName = "func", basePath = require_logger.state.basePath, useCache = true }) {
|
|
40
|
+
const cacheKey = `${filePath}${functionName ? `:${functionName}` : ""}`;
|
|
41
|
+
if (useCache && functionCache[cacheKey]) return functionCache[cacheKey];
|
|
42
|
+
const resolvedPath = basePath ? path.default.resolve(basePath, filePath) : filePath;
|
|
43
|
+
if (!require_fileExtensions.isJavascriptFile(resolvedPath) && !resolvedPath.endsWith(".py")) throw new Error(`File must be a JavaScript (${require_fileExtensions.JAVASCRIPT_EXTENSIONS.join(", ")}) or Python (.py) file`);
|
|
44
|
+
try {
|
|
45
|
+
let func;
|
|
46
|
+
if (require_fileExtensions.isJavascriptFile(resolvedPath)) {
|
|
47
|
+
const module = await require_esm.importModule(resolvedPath, functionName);
|
|
48
|
+
let moduleFunc;
|
|
49
|
+
if (functionName) moduleFunc = module;
|
|
50
|
+
else moduleFunc = typeof module === "function" ? module : module?.default?.default || module?.default || module?.[defaultFunctionName] || module;
|
|
51
|
+
if (typeof moduleFunc !== "function") throw new Error(functionName ? `JavaScript file must export a "${functionName}" function` : `JavaScript file must export a function (as default export or named export "${defaultFunctionName}")`);
|
|
52
|
+
func = moduleFunc;
|
|
53
|
+
} else {
|
|
54
|
+
const result = (...args) => require_pythonUtils.runPython(resolvedPath, functionName || defaultFunctionName, args);
|
|
55
|
+
func = result;
|
|
56
|
+
}
|
|
57
|
+
if (useCache) functionCache[cacheKey] = func;
|
|
58
|
+
return func;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
require_logger.logger.error(`Failed to load function: ${err.message}`);
|
|
61
|
+
throw err;
|
|
45
62
|
}
|
|
46
|
-
if ((id.endsWith(".js") || id.endsWith(".ts") || id.endsWith(".mjs")) && (id.includes("/") || id.includes("\\"))) return `file://${path.resolve(id)}`;
|
|
47
|
-
return id;
|
|
48
|
-
}
|
|
49
|
-
function getProviderLabel(provider) {
|
|
50
|
-
return provider?.label && typeof provider.label === "string" ? provider.label : void 0;
|
|
51
63
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Extracts the file path and function name from a file:// URL
|
|
66
|
+
* @param fileUrl The file:// URL (e.g., "file://path/to/file.js:functionName")
|
|
67
|
+
* @returns The file path and optional function name
|
|
68
|
+
*/
|
|
69
|
+
function parseFileUrl(fileUrl) {
|
|
70
|
+
if (!fileUrl.startsWith("file://")) throw new Error("URL must start with file://");
|
|
71
|
+
const urlWithoutProtocol = fileUrl.slice(7);
|
|
72
|
+
const lastColonIndex = urlWithoutProtocol.lastIndexOf(":");
|
|
73
|
+
if (lastColonIndex > 1) return {
|
|
74
|
+
filePath: urlWithoutProtocol.slice(0, lastColonIndex),
|
|
75
|
+
functionName: urlWithoutProtocol.slice(lastColonIndex + 1)
|
|
76
|
+
};
|
|
77
|
+
return { filePath: urlWithoutProtocol };
|
|
63
78
|
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/util/file.ts
|
|
64
81
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
82
|
+
* Simple Nunjucks engine specifically for file paths
|
|
83
|
+
* This function is separate from the main getNunjucksEngine to avoid circular dependencies
|
|
67
84
|
*/
|
|
68
|
-
function
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
function getNunjucksEngineForFilePath() {
|
|
86
|
+
const env = nunjucks.default.configure({ autoescape: false });
|
|
87
|
+
env.addGlobal("env", {
|
|
88
|
+
...process.env,
|
|
89
|
+
...require_logger.state.config?.env
|
|
90
|
+
});
|
|
91
|
+
return env;
|
|
73
92
|
}
|
|
74
93
|
/**
|
|
75
|
-
*
|
|
76
|
-
* Supports
|
|
94
|
+
* Loads content from an external file if the input is a file path, otherwise
|
|
95
|
+
* returns the input as-is. Supports Nunjucks templating for file paths.
|
|
96
|
+
*
|
|
97
|
+
* @param filePath - The input to process. Can be a file path string starting with "file://",
|
|
98
|
+
* an array of file paths, or any other type of data.
|
|
99
|
+
* @param context - Optional context to control file loading behavior. 'assertion' context
|
|
100
|
+
* preserves Python/JS file references instead of loading their content.
|
|
101
|
+
* @returns The loaded content if the input was a file path, otherwise the original input.
|
|
102
|
+
* For JSON and YAML files, the content is parsed into an object.
|
|
103
|
+
* For other file types, the raw file content is returned as a string.
|
|
104
|
+
*
|
|
105
|
+
* @throws {Error} If the specified file does not exist.
|
|
77
106
|
*/
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
function maybeLoadFromExternalFile(filePath, context) {
|
|
108
|
+
if (Array.isArray(filePath)) return filePath.map((path$3) => {
|
|
109
|
+
return maybeLoadFromExternalFile(path$3, context);
|
|
110
|
+
});
|
|
111
|
+
if (typeof filePath !== "string") return filePath;
|
|
112
|
+
if (!filePath.startsWith("file://")) return filePath;
|
|
113
|
+
const renderedFilePath = getNunjucksEngineForFilePath().renderString(filePath, {});
|
|
114
|
+
const { filePath: cleanPath, functionName } = parseFileUrl(renderedFilePath);
|
|
115
|
+
if (context === "assertion" && (cleanPath.endsWith(".py") || require_fileExtensions.isJavascriptFile(cleanPath))) {
|
|
116
|
+
require_logger.logger.debug(`Preserving Python/JS file reference in assertion context: ${renderedFilePath}`);
|
|
117
|
+
return renderedFilePath;
|
|
88
118
|
}
|
|
89
|
-
if (
|
|
90
|
-
|
|
119
|
+
if (context === "vars") {
|
|
120
|
+
require_logger.logger.debug(`Preserving file reference in vars context: ${renderedFilePath}`);
|
|
121
|
+
return renderedFilePath;
|
|
122
|
+
}
|
|
123
|
+
if (functionName && (cleanPath.endsWith(".py") || require_fileExtensions.isJavascriptFile(cleanPath))) return renderedFilePath;
|
|
124
|
+
const pathToUse = functionName && !(cleanPath.endsWith(".py") || require_fileExtensions.isJavascriptFile(cleanPath)) ? renderedFilePath.slice(7) : cleanPath;
|
|
125
|
+
const resolvedPath = path.resolve(require_logger.state.basePath || "", pathToUse);
|
|
126
|
+
if ((0, glob.hasMagic)(pathToUse)) {
|
|
127
|
+
const matchedFiles = (0, glob.globSync)(resolvedPath, { windowsPathsNoEscape: true });
|
|
128
|
+
if (matchedFiles.length === 0) throw new Error(`No files found matching pattern: ${resolvedPath}`);
|
|
129
|
+
const allContents = [];
|
|
130
|
+
for (const matchedFile of matchedFiles) {
|
|
131
|
+
let contents;
|
|
132
|
+
try {
|
|
133
|
+
contents = fs.readFileSync(matchedFile, "utf8");
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error.code === "ENOENT") {
|
|
136
|
+
require_logger.logger.debug(`File disappeared during glob expansion: ${matchedFile}`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
if (matchedFile.endsWith(".json")) {
|
|
142
|
+
const parsed = JSON.parse(contents);
|
|
143
|
+
if (Array.isArray(parsed)) allContents.push(...parsed);
|
|
144
|
+
else allContents.push(parsed);
|
|
145
|
+
} else if (matchedFile.endsWith(".yaml") || matchedFile.endsWith(".yml")) {
|
|
146
|
+
const parsed = js_yaml.default.load(contents);
|
|
147
|
+
if (parsed === null || parsed === void 0) continue;
|
|
148
|
+
if (Array.isArray(parsed)) allContents.push(...parsed);
|
|
149
|
+
else allContents.push(parsed);
|
|
150
|
+
} else if (matchedFile.endsWith(".csv")) {
|
|
151
|
+
const records = (0, csv_parse_sync.parse)(contents, { columns: true });
|
|
152
|
+
if (records.length > 0 && Object.keys(records[0]).length === 1) allContents.push(...records.map((record) => Object.values(record)[0]));
|
|
153
|
+
else allContents.push(...records);
|
|
154
|
+
} else allContents.push(contents);
|
|
155
|
+
}
|
|
156
|
+
return allContents;
|
|
157
|
+
}
|
|
158
|
+
const finalPath = resolvedPath;
|
|
159
|
+
let contents;
|
|
160
|
+
try {
|
|
161
|
+
contents = fs.readFileSync(finalPath, "utf8");
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error.code === "ENOENT") throw new Error(`File does not exist: ${finalPath}`);
|
|
164
|
+
throw new Error(`Failed to read file ${finalPath}: ${error}`);
|
|
165
|
+
}
|
|
166
|
+
if (finalPath.endsWith(".json")) try {
|
|
167
|
+
return JSON.parse(contents);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
throw new Error(`Failed to parse JSON file ${finalPath}: ${error}`);
|
|
170
|
+
}
|
|
171
|
+
if (finalPath.endsWith(".yaml") || finalPath.endsWith(".yml")) try {
|
|
172
|
+
return js_yaml.default.load(contents);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
throw new Error(`Failed to parse YAML file ${finalPath}: ${error}`);
|
|
175
|
+
}
|
|
176
|
+
if (finalPath.endsWith(".csv")) {
|
|
177
|
+
const records = (0, csv_parse_sync.parse)(contents, { columns: true });
|
|
178
|
+
if (records.length > 0 && Object.keys(records[0]).length === 1) return records.map((record) => Object.values(record)[0]);
|
|
179
|
+
return records;
|
|
180
|
+
}
|
|
181
|
+
return contents;
|
|
91
182
|
}
|
|
92
183
|
/**
|
|
93
|
-
*
|
|
184
|
+
* Resolves a relative file path with respect to a base path, handling cloud configuration appropriately.
|
|
185
|
+
* When using a cloud configuration, the current working directory is always used instead of the context's base path.
|
|
186
|
+
*
|
|
187
|
+
* @param filePath - The relative or absolute file path to resolve.
|
|
188
|
+
* @param isCloudConfig - Whether this is a cloud configuration.
|
|
189
|
+
* @returns The resolved absolute file path.
|
|
94
190
|
*/
|
|
95
|
-
function
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
return allowedProviders.some((ref) => doesProviderRefMatch(ref, provider));
|
|
191
|
+
function getResolvedRelativePath(filePath, isCloudConfig) {
|
|
192
|
+
if (path.isAbsolute(filePath) || !isCloudConfig) return filePath;
|
|
193
|
+
return path.join(process.cwd(), filePath);
|
|
99
194
|
}
|
|
100
195
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
196
|
+
* Recursively loads external file references from a configuration object.
|
|
197
|
+
*
|
|
198
|
+
* @param config - The configuration object to process
|
|
199
|
+
* @param context - Optional context to control file loading behavior
|
|
200
|
+
* @returns The configuration with external file references resolved
|
|
103
201
|
*/
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
"curie",
|
|
114
|
-
"babbage",
|
|
115
|
-
"ada",
|
|
116
|
-
"text-embedding",
|
|
117
|
-
"whisper",
|
|
118
|
-
"dall-e",
|
|
119
|
-
"tts"
|
|
120
|
-
].some((indicator) => lowerProviderId.includes(indicator))) return true;
|
|
202
|
+
function maybeLoadConfigFromExternalFile(config, context) {
|
|
203
|
+
if (Array.isArray(config)) return config.map((item) => maybeLoadConfigFromExternalFile(item, context));
|
|
204
|
+
if (typeof config === "object" && config !== null) {
|
|
205
|
+
const result = {};
|
|
206
|
+
for (const key of Object.keys(config)) {
|
|
207
|
+
const childContext = key === "value" && "type" in config && typeof config.type === "string" && (config.type === "python" || config.type === "javascript") ? "assertion" : key === "vars" ? "vars" : context;
|
|
208
|
+
result[key] = maybeLoadConfigFromExternalFile(config[key], childContext);
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
121
211
|
}
|
|
122
|
-
return
|
|
212
|
+
return maybeLoadFromExternalFile(config, context);
|
|
123
213
|
}
|
|
124
214
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
215
|
+
* Parses a file path or glob pattern to extract function names and file extensions.
|
|
216
|
+
* Function names can be specified in the filename like this:
|
|
217
|
+
* prompt.py:myFunction or prompts.js:myFunction.
|
|
218
|
+
* @param basePath - The base path for file resolution.
|
|
219
|
+
* @param promptPath - The path or glob pattern.
|
|
220
|
+
* @returns Parsed details including function name, file extension, and directory status.
|
|
127
221
|
*/
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
222
|
+
function parsePathOrGlob(basePath, promptPath) {
|
|
223
|
+
if (promptPath.startsWith("file://")) promptPath = promptPath.slice(7);
|
|
224
|
+
const filePath = path.resolve(basePath, promptPath);
|
|
225
|
+
let filename = path.relative(basePath, filePath);
|
|
226
|
+
let functionName;
|
|
227
|
+
if (filename.includes(":")) {
|
|
228
|
+
const lastColonIndex = filename.lastIndexOf(":");
|
|
229
|
+
if (lastColonIndex > 1) {
|
|
230
|
+
const pathWithoutFunction = filename.slice(0, lastColonIndex);
|
|
231
|
+
if (require_fileExtensions.isJavascriptFile(pathWithoutFunction) || pathWithoutFunction.endsWith(".py") || pathWithoutFunction.endsWith(".go") || pathWithoutFunction.endsWith(".rb")) {
|
|
232
|
+
functionName = filename.slice(lastColonIndex + 1);
|
|
233
|
+
filename = pathWithoutFunction;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
136
236
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
hyperbolic: "HYPERBOLIC_API_KEY",
|
|
153
|
-
cerebras: "CEREBRAS_API_KEY",
|
|
154
|
-
togetherai: "TOGETHER_API_KEY",
|
|
155
|
-
fal: "FAL_KEY",
|
|
156
|
-
huggingface: "HF_TOKEN",
|
|
157
|
-
"cloudflare-ai": "CLOUDFLARE_API_KEY"
|
|
158
|
-
};
|
|
159
|
-
function getDefaultEnvVar(providerId) {
|
|
160
|
-
const prefix = providerId.split(":")[0];
|
|
161
|
-
return KNOWN_ENV_VARS[prefix] || `${prefix.toUpperCase()}_API_KEY`;
|
|
237
|
+
let stats;
|
|
238
|
+
try {
|
|
239
|
+
stats = fs.statSync(path.join(basePath, filename));
|
|
240
|
+
} catch (err) {
|
|
241
|
+
if (require_logger.getEnvBool("PROMPTFOO_STRICT_FILES")) throw err;
|
|
242
|
+
}
|
|
243
|
+
const normalizedFilePath = filePath.replace(/\\/g, "/");
|
|
244
|
+
const isPathPattern = stats?.isDirectory() || (0, glob.hasMagic)(promptPath) || (0, glob.hasMagic)(normalizedFilePath);
|
|
245
|
+
const safeFilename = path.relative(basePath, require_esm.safeResolve(basePath, filename));
|
|
246
|
+
return {
|
|
247
|
+
extension: isPathPattern ? void 0 : path.parse(safeFilename).ext,
|
|
248
|
+
filePath: path.join(basePath, safeFilename),
|
|
249
|
+
functionName,
|
|
250
|
+
isPathPattern
|
|
251
|
+
};
|
|
162
252
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const missingApiKeys = /* @__PURE__ */ new Map();
|
|
169
|
-
for (const provider of providers) {
|
|
170
|
-
const p = provider;
|
|
171
|
-
if (typeof p.getApiKey !== "function") continue;
|
|
172
|
-
if (provider.id().startsWith("azure:")) continue;
|
|
173
|
-
const requiresKey = typeof p.requiresApiKey === "function" ? p.requiresApiKey() : p.config?.apiKeyRequired !== false;
|
|
174
|
-
let apiKey;
|
|
175
|
-
try {
|
|
176
|
-
apiKey = p.getApiKey();
|
|
177
|
-
} catch {
|
|
178
|
-
apiKey = void 0;
|
|
179
|
-
}
|
|
180
|
-
if (requiresKey && !apiKey) {
|
|
181
|
-
const envVar = p.config?.apiKeyEnvar || getDefaultEnvVar(provider.id());
|
|
182
|
-
if (!missingApiKeys.has(envVar)) missingApiKeys.set(envVar, []);
|
|
183
|
-
missingApiKeys.get(envVar).push(provider.id());
|
|
184
|
-
}
|
|
253
|
+
function readOutput(outputPath) {
|
|
254
|
+
const ext = path.parse(outputPath).ext.slice(1);
|
|
255
|
+
switch (ext) {
|
|
256
|
+
case "json": return JSON.parse(fs.readFileSync(outputPath, "utf-8"));
|
|
257
|
+
default: throw new Error(`Unsupported output file format: ${ext} currently only supports json`);
|
|
185
258
|
}
|
|
186
|
-
return missingApiKeys;
|
|
187
259
|
}
|
|
188
260
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
261
|
+
* Load custom Nunjucks filters from external files.
|
|
262
|
+
* Note: If a glob pattern matches multiple files, only the last file's export is used.
|
|
263
|
+
* Each filter name should typically resolve to a single file.
|
|
192
264
|
*/
|
|
193
|
-
function
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
265
|
+
async function readFilters(filters, basePath = "") {
|
|
266
|
+
const ret = {};
|
|
267
|
+
for (const [name, filterPath] of Object.entries(filters)) {
|
|
268
|
+
const filePaths = (0, glob.globSync)(path.join(basePath, filterPath), { windowsPathsNoEscape: true });
|
|
269
|
+
for (const filePath of filePaths) ret[name] = await require_esm.importModule(path.resolve(filePath));
|
|
198
270
|
}
|
|
199
|
-
return
|
|
271
|
+
return ret;
|
|
200
272
|
}
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/util/comparison.ts
|
|
203
273
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
274
|
+
* Loads configuration from an external file with variable rendering.
|
|
275
|
+
* This is a convenience wrapper that combines renderVarsInObject and maybeLoadFromExternalFile.
|
|
206
276
|
*
|
|
207
|
-
*
|
|
277
|
+
* Use this for simple config fields that:
|
|
278
|
+
* - Need variable rendering ({{ vars.x }}, {{ env.X }})
|
|
279
|
+
* - May reference external files (file://path.json)
|
|
280
|
+
* - Don't have nested file references that need loading
|
|
208
281
|
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*/
|
|
212
|
-
const EXPLICIT_RUNTIME_VAR_KEYS = ["sessionId"];
|
|
213
|
-
/**
|
|
214
|
-
* Checks if a variable key is a runtime-only variable that should be filtered
|
|
215
|
-
* when comparing test cases.
|
|
282
|
+
* For fields with nested file references (like response_format.schema),
|
|
283
|
+
* use maybeLoadResponseFormatFromExternalFile instead.
|
|
216
284
|
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
285
|
+
* @param config - The configuration to process
|
|
286
|
+
* @param vars - Variables for template rendering
|
|
287
|
+
* @returns The processed configuration with variables rendered and files loaded
|
|
220
288
|
*/
|
|
221
|
-
function
|
|
222
|
-
return
|
|
289
|
+
function maybeLoadFromExternalFileWithVars(config, vars) {
|
|
290
|
+
return maybeLoadFromExternalFile(require_render.renderVarsInObject(config, vars));
|
|
223
291
|
}
|
|
224
292
|
/**
|
|
225
|
-
*
|
|
226
|
-
* but aren't part of the original test definition.
|
|
293
|
+
* Loads response_format configuration from an external file with variable rendering.
|
|
227
294
|
*
|
|
228
|
-
* This
|
|
229
|
-
*
|
|
295
|
+
* This function handles the special case where response_format may contain:
|
|
296
|
+
* 1. A top-level file reference (file://format.json)
|
|
297
|
+
* 2. A nested schema reference for json_schema type (schema: file://schema.json)
|
|
230
298
|
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
299
|
+
* Both levels need variable rendering and file loading.
|
|
300
|
+
*
|
|
301
|
+
* @param responseFormat - The response_format configuration
|
|
302
|
+
* @param vars - Variables for template rendering
|
|
303
|
+
* @returns The processed response_format with all files loaded
|
|
234
304
|
*/
|
|
235
|
-
function
|
|
236
|
-
if (
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
305
|
+
function maybeLoadResponseFormatFromExternalFile(responseFormat, vars) {
|
|
306
|
+
if (responseFormat === void 0 || responseFormat === null) return responseFormat;
|
|
307
|
+
const loaded = maybeLoadFromExternalFile(require_render.renderVarsInObject(responseFormat, vars));
|
|
308
|
+
if (!loaded || typeof loaded !== "object") return loaded;
|
|
309
|
+
if (loaded.type === "json_schema") {
|
|
310
|
+
const nestedSchema = loaded.schema || loaded.json_schema?.schema;
|
|
311
|
+
if (nestedSchema) {
|
|
312
|
+
const loadedSchema = maybeLoadFromExternalFile(require_render.renderVarsInObject(nestedSchema, vars));
|
|
313
|
+
if (loaded.schema !== void 0) return {
|
|
314
|
+
...loaded,
|
|
315
|
+
schema: loadedSchema
|
|
316
|
+
};
|
|
317
|
+
else if (loaded.json_schema?.schema !== void 0) return {
|
|
318
|
+
...loaded,
|
|
319
|
+
json_schema: {
|
|
320
|
+
...loaded.json_schema,
|
|
321
|
+
schema: loadedSchema
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return loaded;
|
|
240
327
|
}
|
|
241
328
|
/**
|
|
242
|
-
*
|
|
243
|
-
* This
|
|
329
|
+
* Renders variables in a tools object and loads from external file if applicable.
|
|
330
|
+
* This function combines renderVarsInObject and maybeLoadFromExternalFile into a single step
|
|
331
|
+
* specifically for handling tools configurations.
|
|
244
332
|
*
|
|
245
|
-
*
|
|
333
|
+
* Supports loading from JSON, YAML, Python, and JavaScript files.
|
|
334
|
+
*
|
|
335
|
+
* @param tools - The tools configuration object or array to process.
|
|
336
|
+
* @param vars - Variables to use for rendering.
|
|
337
|
+
* @returns The processed tools configuration with variables rendered and content loaded from files if needed.
|
|
338
|
+
* @throws {Error} If the loaded tools are in an invalid format
|
|
246
339
|
*/
|
|
247
|
-
function
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
340
|
+
async function maybeLoadToolsFromExternalFile(tools, vars) {
|
|
341
|
+
const rendered = require_render.renderVarsInObject(tools, vars);
|
|
342
|
+
if (typeof rendered === "string" && rendered.startsWith("file://")) {
|
|
343
|
+
const { filePath, functionName } = parseFileUrl(rendered);
|
|
344
|
+
if (functionName && (filePath.endsWith(".py") || require_fileExtensions.isJavascriptFile(filePath))) {
|
|
345
|
+
const fileType = filePath.endsWith(".py") ? "Python" : "JavaScript";
|
|
346
|
+
require_logger.logger.debug(`[maybeLoadToolsFromExternalFile] Loading tools from ${fileType} file: ${filePath}:${functionName}`);
|
|
347
|
+
try {
|
|
348
|
+
let toolDefinitions;
|
|
349
|
+
if (filePath.endsWith(".py")) {
|
|
350
|
+
const absPath = require_esm.safeResolve(require_logger.state.basePath || process.cwd(), filePath);
|
|
351
|
+
require_logger.logger.debug(`[maybeLoadToolsFromExternalFile] Resolved Python path: ${absPath}`);
|
|
352
|
+
toolDefinitions = await require_pythonUtils.runPython(absPath, functionName, []);
|
|
353
|
+
} else {
|
|
354
|
+
const absPath = require_esm.safeResolve(require_logger.state.basePath || process.cwd(), filePath);
|
|
355
|
+
require_logger.logger.debug(`[maybeLoadToolsFromExternalFile] Resolved JavaScript path: ${absPath}`);
|
|
356
|
+
const module = await require_esm.importModule(absPath);
|
|
357
|
+
const fn = module[functionName] || module.default?.[functionName];
|
|
358
|
+
if (typeof fn !== "function") {
|
|
359
|
+
const availableExports = Object.keys(module).filter((k) => k !== "default");
|
|
360
|
+
const basePath = require_logger.state.basePath || process.cwd();
|
|
361
|
+
throw new Error(`Function "${functionName}" not found in ${filePath}. Available exports: ${availableExports.length > 0 ? availableExports.join(", ") : "(none)"}\nResolved from: ${basePath}`);
|
|
362
|
+
}
|
|
363
|
+
toolDefinitions = await Promise.resolve(fn());
|
|
364
|
+
}
|
|
365
|
+
if (!toolDefinitions || typeof toolDefinitions === "string" || typeof toolDefinitions === "number" || typeof toolDefinitions === "boolean") throw new Error(`Function "${functionName}" must return an array or object of tool definitions, but returned: ${toolDefinitions === null ? "null" : typeof toolDefinitions}`);
|
|
366
|
+
require_logger.logger.debug(`[maybeLoadToolsFromExternalFile] Successfully loaded ${Array.isArray(toolDefinitions) ? toolDefinitions.length : "object"} tools`);
|
|
367
|
+
return toolDefinitions;
|
|
368
|
+
} catch (err) {
|
|
369
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
370
|
+
const basePath = require_logger.state.basePath || process.cwd();
|
|
371
|
+
throw new Error(`Failed to load tools from ${rendered}:\n${errorMessage}\n\nMake sure the function "${functionName}" exists and returns a valid tool definition array.\nResolved from: ${basePath}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (filePath.endsWith(".py") || require_fileExtensions.isJavascriptFile(filePath)) {
|
|
375
|
+
const ext = filePath.endsWith(".py") ? "Python" : "JavaScript";
|
|
376
|
+
const basePath = require_logger.state.basePath || process.cwd();
|
|
377
|
+
throw new Error(`Cannot load tools from ${rendered}\n${ext} files require a function name. Use this format:\n tools: file://${filePath}:get_tools\n\nYour ${ext} file should export a function that returns tool definitions:\n` + (filePath.endsWith(".py") ? ` def get_tools():\n return [{"type": "function", "function": {...}}]` : ` module.exports.get_tools = () => [{ type: "function", function: {...} }];`) + `\n\nResolved from: ${basePath}`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (Array.isArray(rendered)) {
|
|
381
|
+
const results = await Promise.all(rendered.map((item) => maybeLoadToolsFromExternalFile(item, vars)));
|
|
382
|
+
if (results.every((r) => Array.isArray(r))) return results.flat();
|
|
383
|
+
return results;
|
|
384
|
+
}
|
|
385
|
+
if (typeof rendered !== "string") return rendered;
|
|
386
|
+
const loaded = maybeLoadFromExternalFile(rendered);
|
|
387
|
+
if (loaded !== void 0 && loaded !== null && typeof loaded === "string") {
|
|
388
|
+
if (loaded.startsWith("file://")) throw new Error(`Failed to load tools from ${loaded}\nEnsure the file exists and contains valid JSON or YAML tool definitions.`);
|
|
389
|
+
if (loaded.includes("def ") || loaded.includes("import ")) throw new Error("Invalid tools configuration: file appears to contain Python code.\nPython files require a function name. Use this format:\n tools: file://tools.py:get_tools");
|
|
390
|
+
throw new Error("Invalid tools configuration: expected an array or object, but got a string.\nIf using file://, ensure the file contains valid JSON or YAML tool definitions.");
|
|
391
|
+
}
|
|
392
|
+
return loaded;
|
|
252
393
|
}
|
|
253
|
-
|
|
254
|
-
|
|
394
|
+
//#endregion
|
|
395
|
+
//#region src/util/providerRef.ts
|
|
396
|
+
const PROVIDER_OPTION_KEYS = new Set([
|
|
397
|
+
"id",
|
|
398
|
+
"label",
|
|
399
|
+
"config",
|
|
400
|
+
"prompts",
|
|
401
|
+
"transform",
|
|
402
|
+
"delay",
|
|
403
|
+
"env",
|
|
404
|
+
"inputs"
|
|
405
|
+
]);
|
|
406
|
+
/** Returns true if the value is a non-empty string suitable as a provider identifier. */
|
|
407
|
+
function isValidProviderId(id) {
|
|
408
|
+
return typeof id === "string" && id !== "";
|
|
409
|
+
}
|
|
410
|
+
function getProviderLabel(provider) {
|
|
411
|
+
if ((typeof provider === "object" || typeof provider === "function") && provider !== null && "label" in provider && typeof provider.label === "string") return provider.label;
|
|
255
412
|
}
|
|
256
413
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* with the same prompt but different strategies.
|
|
260
|
-
*
|
|
261
|
-
* @param testCase - The test case to generate a key for
|
|
262
|
-
* @returns A JSON string that uniquely identifies the test case
|
|
414
|
+
* Resolves relative file paths in provider IDs to absolute paths for consistent matching.
|
|
415
|
+
* Handles file://, exec:, python:, golang: prefixes and bare .js/.ts/.mjs paths.
|
|
263
416
|
*/
|
|
264
|
-
function
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
vars: filteredVars,
|
|
269
|
-
strategyId
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Deduplicates an array of test cases based on their vars and strategyId.
|
|
274
|
-
* Tests with the same vars but different strategies are considered different.
|
|
275
|
-
* Runtime variables (like _conversation, sessionId) are filtered out before comparison.
|
|
276
|
-
*
|
|
277
|
-
* @param tests - Array of test cases to deduplicate
|
|
278
|
-
* @returns Deduplicated array of test cases
|
|
279
|
-
*/
|
|
280
|
-
function deduplicateTestCases(tests) {
|
|
281
|
-
const seen = /* @__PURE__ */ new Set();
|
|
282
|
-
return tests.filter((test) => {
|
|
283
|
-
const key = getTestCaseDeduplicationKey(test);
|
|
284
|
-
if (seen.has(key)) return false;
|
|
285
|
-
seen.add(key);
|
|
286
|
-
return true;
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
function resultIsForTestCase(result, testCase) {
|
|
290
|
-
const testProviderId = testCase.provider ? providerToIdentifier(testCase.provider) : void 0;
|
|
291
|
-
const resultProviderId = providerToIdentifier(result.provider);
|
|
292
|
-
const providersMatch = !testProviderId || !resultProviderId || testProviderId === resultProviderId;
|
|
293
|
-
const resultVars = filterRuntimeVars(result.vars);
|
|
294
|
-
const testVars = filterRuntimeVars(testCase.vars);
|
|
295
|
-
const doVarsMatch = varsMatch(testVars, resultVars);
|
|
296
|
-
const isMatch = doVarsMatch && providersMatch;
|
|
297
|
-
if (!isMatch) {
|
|
298
|
-
const varKeys = testVars ? Object.keys(testVars).join(", ") : "none";
|
|
299
|
-
require_logger.logger.debug(`[resultIsForTestCase] No match: vars=${doVarsMatch}, providers=${providersMatch}`, {
|
|
300
|
-
testProvider: testProviderId || "none",
|
|
301
|
-
resultProvider: resultProviderId || "none",
|
|
302
|
-
testVarKeys: varKeys
|
|
303
|
-
});
|
|
417
|
+
function canonicalizeProviderId(id) {
|
|
418
|
+
if (id.startsWith("file://")) {
|
|
419
|
+
const filePath = id.slice(7);
|
|
420
|
+
return path.default.isAbsolute(filePath) ? id : `file://${path.default.resolve(filePath)}`;
|
|
304
421
|
}
|
|
305
|
-
|
|
422
|
+
for (const prefix of [
|
|
423
|
+
"exec:",
|
|
424
|
+
"python:",
|
|
425
|
+
"golang:"
|
|
426
|
+
]) if (id.startsWith(prefix)) {
|
|
427
|
+
const filePath = id.slice(prefix.length);
|
|
428
|
+
if (filePath.includes("/") || filePath.includes("\\")) return `${prefix}${path.default.resolve(filePath)}`;
|
|
429
|
+
return id;
|
|
430
|
+
}
|
|
431
|
+
if ((id.endsWith(".js") || id.endsWith(".ts") || id.endsWith(".mjs")) && (id.includes("/") || id.includes("\\"))) return `file://${path.default.resolve(id)}`;
|
|
432
|
+
return id;
|
|
306
433
|
}
|
|
307
|
-
//#endregion
|
|
308
|
-
//#region src/util/env.ts
|
|
309
434
|
/**
|
|
310
|
-
*
|
|
311
|
-
* @param envPath - Single path, array of paths, or undefined for default .env loading.
|
|
312
|
-
* When paths are explicitly specified, all files must exist or an error is thrown.
|
|
313
|
-
* When multiple files are provided, later files override values from earlier files.
|
|
435
|
+
* Returns true for provider refs that should be expanded from YAML/JSON config files.
|
|
314
436
|
*/
|
|
315
|
-
function
|
|
316
|
-
|
|
317
|
-
const paths = (Array.isArray(envPath) ? envPath : [envPath]).flatMap((p) => p.includes(",") ? p.split(",").map((s) => s.trim()) : p.trim()).filter((p) => p.length > 0);
|
|
318
|
-
if (paths.length === 0) {
|
|
319
|
-
dotenv.default.config({ quiet: true });
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
for (const p of paths) if (!fs.existsSync(p)) throw new Error(`Environment file not found: ${p}`);
|
|
323
|
-
if (paths.length === 1) require_logger.logger.info(`Loading environment variables from ${paths[0]}`);
|
|
324
|
-
else require_logger.logger.info(`Loading environment variables from: ${paths.join(", ")}`);
|
|
325
|
-
const pathArg = paths.length === 1 ? paths[0] : paths;
|
|
326
|
-
dotenv.default.config({
|
|
327
|
-
path: pathArg,
|
|
328
|
-
override: true,
|
|
329
|
-
quiet: true
|
|
330
|
-
});
|
|
331
|
-
} else dotenv.default.config({ quiet: true });
|
|
437
|
+
function isProviderConfigFileReference(providerPath) {
|
|
438
|
+
return providerPath.startsWith("file://") && (providerPath.endsWith(".yaml") || providerPath.endsWith(".yml") || providerPath.endsWith(".json"));
|
|
332
439
|
}
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region src/util/functions/loadFunction.ts
|
|
335
|
-
const functionCache = {};
|
|
336
440
|
/**
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
441
|
+
* Reads a provider config file and normalizes single-provider and multi-provider files.
|
|
442
|
+
* Returns a `wasArray` flag so callers can detect multi-provider files that require
|
|
443
|
+
* `loadApiProviders` instead of `loadApiProvider`.
|
|
340
444
|
*/
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (!require_fileExtensions.isJavascriptFile(resolvedPath) && !resolvedPath.endsWith(".py")) throw new Error(`File must be a JavaScript (${require_fileExtensions.JAVASCRIPT_EXTENSIONS.join(", ")}) or Python (.py) file`);
|
|
445
|
+
function readProviderConfigFile(providerPath, basePath) {
|
|
446
|
+
const relativePath = providerPath.slice(7);
|
|
447
|
+
const resolvedPath = path.default.isAbsolute(relativePath) ? relativePath : path.default.join(basePath || process.cwd(), relativePath);
|
|
448
|
+
let rawContent;
|
|
346
449
|
try {
|
|
347
|
-
|
|
348
|
-
if (require_fileExtensions.isJavascriptFile(resolvedPath)) {
|
|
349
|
-
const module = await require_esm.importModule(resolvedPath, functionName);
|
|
350
|
-
let moduleFunc;
|
|
351
|
-
if (functionName) moduleFunc = module;
|
|
352
|
-
else moduleFunc = typeof module === "function" ? module : module?.default?.default || module?.default || module?.[defaultFunctionName] || module;
|
|
353
|
-
if (typeof moduleFunc !== "function") throw new Error(functionName ? `JavaScript file must export a "${functionName}" function` : `JavaScript file must export a function (as default export or named export "${defaultFunctionName}")`);
|
|
354
|
-
func = moduleFunc;
|
|
355
|
-
} else {
|
|
356
|
-
const result = (...args) => require_pythonUtils.runPython(resolvedPath, functionName || defaultFunctionName, args);
|
|
357
|
-
func = result;
|
|
358
|
-
}
|
|
359
|
-
if (useCache) functionCache[cacheKey] = func;
|
|
360
|
-
return func;
|
|
450
|
+
rawContent = js_yaml.default.load(fs.default.readFileSync(resolvedPath, "utf8"));
|
|
361
451
|
} catch (err) {
|
|
362
|
-
|
|
363
|
-
throw err;
|
|
452
|
+
throw new Error(`Failed to load provider config ${relativePath}: ${err instanceof Error ? err.message : err}`);
|
|
364
453
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
function parseFileUrl(fileUrl) {
|
|
372
|
-
if (!fileUrl.startsWith("file://")) throw new Error("URL must start with file://");
|
|
373
|
-
const urlWithoutProtocol = fileUrl.slice(7);
|
|
374
|
-
const lastColonIndex = urlWithoutProtocol.lastIndexOf(":");
|
|
375
|
-
if (lastColonIndex > 1) return {
|
|
376
|
-
filePath: urlWithoutProtocol.slice(0, lastColonIndex),
|
|
377
|
-
functionName: urlWithoutProtocol.slice(lastColonIndex + 1)
|
|
454
|
+
const fileContent = maybeLoadConfigFromExternalFile(rawContent);
|
|
455
|
+
require_invariant.invariant(fileContent, `Provider config ${relativePath} is undefined`);
|
|
456
|
+
return {
|
|
457
|
+
configs: [fileContent].flat(),
|
|
458
|
+
relativePath,
|
|
459
|
+
wasArray: Array.isArray(fileContent)
|
|
378
460
|
};
|
|
379
|
-
return { filePath: urlWithoutProtocol };
|
|
380
461
|
}
|
|
381
|
-
//#endregion
|
|
382
|
-
//#region src/util/file.ts
|
|
383
462
|
/**
|
|
384
|
-
*
|
|
385
|
-
* This function is separate from the main getNunjucksEngine to avoid circular dependencies
|
|
463
|
+
* Loads provider config objects from a file-backed provider reference.
|
|
386
464
|
*/
|
|
387
|
-
function
|
|
388
|
-
|
|
389
|
-
env.addGlobal("env", {
|
|
390
|
-
...process.env,
|
|
391
|
-
...require_logger.state.config?.env
|
|
392
|
-
});
|
|
393
|
-
return env;
|
|
465
|
+
function loadProviderConfigsFromFile(providerPath, basePath) {
|
|
466
|
+
return readProviderConfigFile(providerPath, basePath).configs;
|
|
394
467
|
}
|
|
395
468
|
/**
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
* @param filePath - The input to process. Can be a file path string starting with "file://",
|
|
400
|
-
* an array of file paths, or any other type of data.
|
|
401
|
-
* @param context - Optional context to control file loading behavior. 'assertion' context
|
|
402
|
-
* preserves Python/JS file references instead of loading their content.
|
|
403
|
-
* @returns The loaded content if the input was a file path, otherwise the original input.
|
|
404
|
-
* For JSON and YAML files, the content is parsed into an object.
|
|
405
|
-
* For other file types, the raw file content is returned as a string.
|
|
406
|
-
*
|
|
407
|
-
* @throws {Error} If the specified file does not exist.
|
|
469
|
+
* Pure, synchronous classifier that converts every supported provider reference shape
|
|
470
|
+
* into a discriminated descriptor. Does not read files or instantiate providers.
|
|
408
471
|
*/
|
|
409
|
-
function
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
472
|
+
function normalizeProviderRef(provider, options = {}) {
|
|
473
|
+
const { index } = options;
|
|
474
|
+
if (typeof provider === "string") {
|
|
475
|
+
if (!isValidProviderId(provider)) return {
|
|
476
|
+
kind: "unknown",
|
|
477
|
+
id: index === void 0 ? "unknown" : `unknown-${index}`
|
|
478
|
+
};
|
|
479
|
+
if (isProviderConfigFileReference(provider)) return {
|
|
480
|
+
kind: "file",
|
|
481
|
+
id: provider,
|
|
482
|
+
loadProviderPath: provider
|
|
483
|
+
};
|
|
484
|
+
return {
|
|
485
|
+
kind: "named",
|
|
486
|
+
id: provider,
|
|
487
|
+
loadProviderPath: provider
|
|
488
|
+
};
|
|
420
489
|
}
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
return
|
|
490
|
+
if (typeof provider === "function") {
|
|
491
|
+
const label = getProviderLabel(provider);
|
|
492
|
+
return {
|
|
493
|
+
kind: "function",
|
|
494
|
+
id: label ?? (index === void 0 ? "custom-function" : `custom-function-${index}`),
|
|
495
|
+
label
|
|
496
|
+
};
|
|
424
497
|
}
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
498
|
+
if (typeof provider === "object" && provider !== null && !Array.isArray(provider)) {
|
|
499
|
+
const providerId = provider.id;
|
|
500
|
+
const label = getProviderLabel(provider);
|
|
501
|
+
if (isValidProviderId(providerId)) return {
|
|
502
|
+
kind: "options",
|
|
503
|
+
id: providerId,
|
|
504
|
+
label,
|
|
505
|
+
loadOptions: provider,
|
|
506
|
+
loadProviderPath: providerId
|
|
507
|
+
};
|
|
508
|
+
const keys = Object.keys(provider);
|
|
509
|
+
if (keys.length === 1 && !PROVIDER_OPTION_KEYS.has(keys[0])) {
|
|
510
|
+
const originalId = keys[0];
|
|
511
|
+
const providerObject = provider[originalId];
|
|
512
|
+
if (typeof providerObject === "object" && providerObject !== null && !Array.isArray(providerObject) && isValidProviderId(originalId)) {
|
|
513
|
+
const id = isValidProviderId(providerObject.id) ? providerObject.id : originalId;
|
|
514
|
+
return {
|
|
515
|
+
kind: "map",
|
|
516
|
+
id,
|
|
517
|
+
label: getProviderLabel(providerObject),
|
|
518
|
+
loadOptions: {
|
|
519
|
+
...providerObject,
|
|
520
|
+
id
|
|
521
|
+
},
|
|
522
|
+
loadProviderPath: originalId
|
|
523
|
+
};
|
|
442
524
|
}
|
|
443
|
-
if (matchedFile.endsWith(".json")) {
|
|
444
|
-
const parsed = JSON.parse(contents);
|
|
445
|
-
if (Array.isArray(parsed)) allContents.push(...parsed);
|
|
446
|
-
else allContents.push(parsed);
|
|
447
|
-
} else if (matchedFile.endsWith(".yaml") || matchedFile.endsWith(".yml")) {
|
|
448
|
-
const parsed = js_yaml.default.load(contents);
|
|
449
|
-
if (parsed === null || parsed === void 0) continue;
|
|
450
|
-
if (Array.isArray(parsed)) allContents.push(...parsed);
|
|
451
|
-
else allContents.push(parsed);
|
|
452
|
-
} else if (matchedFile.endsWith(".csv")) {
|
|
453
|
-
const records = (0, csv_parse_sync.parse)(contents, { columns: true });
|
|
454
|
-
if (records.length > 0 && Object.keys(records[0]).length === 1) allContents.push(...records.map((record) => Object.values(record)[0]));
|
|
455
|
-
else allContents.push(...records);
|
|
456
|
-
} else allContents.push(contents);
|
|
457
525
|
}
|
|
458
|
-
return
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
contents = fs.readFileSync(finalPath, "utf8");
|
|
464
|
-
} catch (error) {
|
|
465
|
-
if (error.code === "ENOENT") throw new Error(`File does not exist: ${finalPath}`);
|
|
466
|
-
throw new Error(`Failed to read file ${finalPath}: ${error}`);
|
|
467
|
-
}
|
|
468
|
-
if (finalPath.endsWith(".json")) try {
|
|
469
|
-
return JSON.parse(contents);
|
|
470
|
-
} catch (error) {
|
|
471
|
-
throw new Error(`Failed to parse JSON file ${finalPath}: ${error}`);
|
|
526
|
+
if (isValidProviderId(label)) return {
|
|
527
|
+
kind: "unknown",
|
|
528
|
+
id: label,
|
|
529
|
+
label
|
|
530
|
+
};
|
|
472
531
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
532
|
+
return {
|
|
533
|
+
kind: "unknown",
|
|
534
|
+
id: index === void 0 ? "unknown" : `unknown-${index}`
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
//#endregion
|
|
538
|
+
//#region src/util/provider.ts
|
|
539
|
+
function providerToIdentifier(provider) {
|
|
540
|
+
if (!provider) return;
|
|
541
|
+
if (typeof provider === "string") return canonicalizeProviderId(provider);
|
|
542
|
+
const { label } = normalizeProviderRef(provider);
|
|
543
|
+
if (label) return label;
|
|
544
|
+
if (require_types.isApiProvider(provider)) return canonicalizeProviderId(provider.id());
|
|
545
|
+
if (require_types.isProviderOptions(provider)) {
|
|
546
|
+
if (provider.id) return canonicalizeProviderId(provider.id);
|
|
547
|
+
return;
|
|
477
548
|
}
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
549
|
+
if (typeof provider === "object" && "id" in provider && typeof provider.id === "string") return canonicalizeProviderId(provider.id);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Gets a descriptive identifier string for a provider, showing both label and ID when both exist.
|
|
553
|
+
* Useful for error messages to help users debug provider reference issues.
|
|
554
|
+
*/
|
|
555
|
+
function getProviderDescription(provider) {
|
|
556
|
+
const label = provider.label;
|
|
557
|
+
const id = provider.id();
|
|
558
|
+
if (label && label !== id) return `${label} (${id})`;
|
|
559
|
+
return id;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Checks if a provider reference matches a given provider.
|
|
563
|
+
* Supports exact matching and wildcard patterns.
|
|
564
|
+
*/
|
|
565
|
+
function doesProviderRefMatch(ref, provider) {
|
|
566
|
+
const label = provider.label;
|
|
567
|
+
const id = provider.id();
|
|
568
|
+
const canonicalRef = canonicalizeProviderId(ref);
|
|
569
|
+
const canonicalId = canonicalizeProviderId(id);
|
|
570
|
+
if (label && label === ref) return true;
|
|
571
|
+
if (id === ref || canonicalId === canonicalRef) return true;
|
|
572
|
+
if (ref.endsWith("*")) {
|
|
573
|
+
const prefix = ref.slice(0, -1);
|
|
574
|
+
if (label?.startsWith(prefix) || id.startsWith(prefix) || canonicalId.startsWith(prefix)) return true;
|
|
482
575
|
}
|
|
483
|
-
return
|
|
576
|
+
if (label?.startsWith(`${ref}:`) || id.startsWith(`${ref}:`) || canonicalId.startsWith(`${ref}:`)) return true;
|
|
577
|
+
return false;
|
|
484
578
|
}
|
|
485
579
|
/**
|
|
486
|
-
*
|
|
487
|
-
* When using a cloud configuration, the current working directory is always used instead of the context's base path.
|
|
488
|
-
*
|
|
489
|
-
* @param filePath - The relative or absolute file path to resolve.
|
|
490
|
-
* @param isCloudConfig - Whether this is a cloud configuration.
|
|
491
|
-
* @returns The resolved absolute file path.
|
|
580
|
+
* Checks if a provider is allowed based on a list of allowed references.
|
|
492
581
|
*/
|
|
493
|
-
function
|
|
494
|
-
if (
|
|
495
|
-
|
|
582
|
+
function isProviderAllowed(provider, allowedProviders) {
|
|
583
|
+
if (!Array.isArray(allowedProviders)) return true;
|
|
584
|
+
if (allowedProviders.length === 0) return false;
|
|
585
|
+
return allowedProviders.some((ref) => doesProviderRefMatch(ref, provider));
|
|
496
586
|
}
|
|
497
587
|
/**
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
* @param config - The configuration object to process
|
|
501
|
-
* @param context - Optional context to control file loading behavior
|
|
502
|
-
* @returns The configuration with external file references resolved
|
|
588
|
+
* Detects if a provider uses OpenAI models.
|
|
589
|
+
* This includes direct OpenAI providers and Azure OpenAI.
|
|
503
590
|
*/
|
|
504
|
-
function
|
|
505
|
-
|
|
506
|
-
if (
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
591
|
+
function isOpenAiProvider(providerId) {
|
|
592
|
+
const lowerProviderId = providerId.toLowerCase();
|
|
593
|
+
if (lowerProviderId.startsWith("openai:")) return true;
|
|
594
|
+
if (lowerProviderId.startsWith("azureopenai:")) return true;
|
|
595
|
+
if (lowerProviderId.startsWith("azure:")) {
|
|
596
|
+
if ([
|
|
597
|
+
"gpt",
|
|
598
|
+
"openai",
|
|
599
|
+
"davinci",
|
|
600
|
+
"curie",
|
|
601
|
+
"babbage",
|
|
602
|
+
"ada",
|
|
603
|
+
"text-embedding",
|
|
604
|
+
"whisper",
|
|
605
|
+
"dall-e",
|
|
606
|
+
"tts"
|
|
607
|
+
].some((indicator) => lowerProviderId.includes(indicator))) return true;
|
|
513
608
|
}
|
|
514
|
-
return
|
|
609
|
+
return false;
|
|
515
610
|
}
|
|
516
611
|
/**
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
* prompt.py:myFunction or prompts.js:myFunction.
|
|
520
|
-
* @param basePath - The base path for file resolution.
|
|
521
|
-
* @param promptPath - The path or glob pattern.
|
|
522
|
-
* @returns Parsed details including function name, file extension, and directory status.
|
|
612
|
+
* Detects if a provider uses Anthropic/Claude models.
|
|
613
|
+
* This includes direct Anthropic providers, Bedrock with Claude, and Vertex with Claude.
|
|
523
614
|
*/
|
|
524
|
-
function
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
if (filename.includes(":")) {
|
|
530
|
-
const lastColonIndex = filename.lastIndexOf(":");
|
|
531
|
-
if (lastColonIndex > 1) {
|
|
532
|
-
const pathWithoutFunction = filename.slice(0, lastColonIndex);
|
|
533
|
-
if (require_fileExtensions.isJavascriptFile(pathWithoutFunction) || pathWithoutFunction.endsWith(".py") || pathWithoutFunction.endsWith(".go") || pathWithoutFunction.endsWith(".rb")) {
|
|
534
|
-
functionName = filename.slice(lastColonIndex + 1);
|
|
535
|
-
filename = pathWithoutFunction;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
615
|
+
function isAnthropicProvider(providerId) {
|
|
616
|
+
const lowerProviderId = providerId.toLowerCase();
|
|
617
|
+
if (lowerProviderId.startsWith("anthropic:")) return true;
|
|
618
|
+
if (lowerProviderId.startsWith("bedrock:")) {
|
|
619
|
+
if (lowerProviderId.includes("claude") || lowerProviderId.includes("anthropic")) return true;
|
|
538
620
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
stats = fs.statSync(path.join(basePath, filename));
|
|
542
|
-
} catch (err) {
|
|
543
|
-
if (require_logger.getEnvBool("PROMPTFOO_STRICT_FILES")) throw err;
|
|
621
|
+
if (lowerProviderId.startsWith("vertex:")) {
|
|
622
|
+
if (lowerProviderId.includes("claude")) return true;
|
|
544
623
|
}
|
|
545
|
-
|
|
546
|
-
const isPathPattern = stats?.isDirectory() || (0, glob.hasMagic)(promptPath) || (0, glob.hasMagic)(normalizedFilePath);
|
|
547
|
-
const safeFilename = path.relative(basePath, require_esm.safeResolve(basePath, filename));
|
|
548
|
-
return {
|
|
549
|
-
extension: isPathPattern ? void 0 : path.parse(safeFilename).ext,
|
|
550
|
-
filePath: path.join(basePath, safeFilename),
|
|
551
|
-
functionName,
|
|
552
|
-
isPathPattern
|
|
553
|
-
};
|
|
624
|
+
return false;
|
|
554
625
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
626
|
+
const KNOWN_ENV_VARS = {
|
|
627
|
+
openai: "OPENAI_API_KEY",
|
|
628
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
629
|
+
google: "GOOGLE_API_KEY",
|
|
630
|
+
mistral: "MISTRAL_API_KEY",
|
|
631
|
+
cohere: "COHERE_API_KEY",
|
|
632
|
+
replicate: "REPLICATE_API_TOKEN",
|
|
633
|
+
voyage: "VOYAGE_API_KEY",
|
|
634
|
+
ai21: "AI21_API_KEY",
|
|
635
|
+
xai: "XAI_API_KEY",
|
|
636
|
+
groq: "GROQ_API_KEY",
|
|
637
|
+
deepseek: "DEEPSEEK_API_KEY",
|
|
638
|
+
perplexity: "PERPLEXITY_API_KEY",
|
|
639
|
+
hyperbolic: "HYPERBOLIC_API_KEY",
|
|
640
|
+
cerebras: "CEREBRAS_API_KEY",
|
|
641
|
+
togetherai: "TOGETHER_API_KEY",
|
|
642
|
+
fal: "FAL_KEY",
|
|
643
|
+
huggingface: "HF_TOKEN",
|
|
644
|
+
"cloudflare-ai": "CLOUDFLARE_API_KEY"
|
|
645
|
+
};
|
|
646
|
+
function getDefaultEnvVar(providerId) {
|
|
647
|
+
const prefix = providerId.split(":")[0];
|
|
648
|
+
return KNOWN_ENV_VARS[prefix] || `${prefix.toUpperCase()}_API_KEY`;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Pre-checks providers for missing API keys before evaluation starts.
|
|
652
|
+
* Assumes getApiKey() is side-effect free (no network calls or token refresh).
|
|
653
|
+
*/
|
|
654
|
+
function checkProviderApiKeys(providers) {
|
|
655
|
+
const missingApiKeys = /* @__PURE__ */ new Map();
|
|
656
|
+
for (const provider of providers) {
|
|
657
|
+
const p = provider;
|
|
658
|
+
if (typeof p.getApiKey !== "function") continue;
|
|
659
|
+
if (provider.id().startsWith("azure:")) continue;
|
|
660
|
+
const requiresKey = typeof p.requiresApiKey === "function" ? p.requiresApiKey() : p.config?.apiKeyRequired !== false;
|
|
661
|
+
let apiKey;
|
|
662
|
+
try {
|
|
663
|
+
apiKey = p.getApiKey();
|
|
664
|
+
} catch {
|
|
665
|
+
apiKey = void 0;
|
|
666
|
+
}
|
|
667
|
+
if (requiresKey && !apiKey) {
|
|
668
|
+
const envVar = p.config?.apiKeyEnvar || getDefaultEnvVar(provider.id());
|
|
669
|
+
if (!missingApiKeys.has(envVar)) missingApiKeys.set(envVar, []);
|
|
670
|
+
missingApiKeys.get(envVar).push(provider.id());
|
|
671
|
+
}
|
|
560
672
|
}
|
|
673
|
+
return missingApiKeys;
|
|
561
674
|
}
|
|
562
675
|
/**
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
676
|
+
* Detects if a provider uses Google models.
|
|
677
|
+
* This includes direct Google/Vertex providers with Gemini and other Google models.
|
|
678
|
+
* Note: Vertex with Claude models is NOT counted as Google (it's Anthropic).
|
|
566
679
|
*/
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
680
|
+
function isGoogleProvider(providerId) {
|
|
681
|
+
const lowerProviderId = providerId.toLowerCase();
|
|
682
|
+
if (lowerProviderId.startsWith("google:")) return true;
|
|
683
|
+
if (lowerProviderId.startsWith("vertex:")) {
|
|
684
|
+
if (!lowerProviderId.includes("claude")) return true;
|
|
572
685
|
}
|
|
573
|
-
return
|
|
686
|
+
return false;
|
|
574
687
|
}
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/util/comparison.ts
|
|
575
690
|
/**
|
|
576
|
-
*
|
|
577
|
-
*
|
|
691
|
+
* Explicit runtime variable names that don't follow the underscore convention.
|
|
692
|
+
* These are added during evaluation but aren't part of the original test definition.
|
|
578
693
|
*
|
|
579
|
-
*
|
|
580
|
-
* - Need variable rendering ({{ vars.x }}, {{ env.X }})
|
|
581
|
-
* - May reference external files (file://path.json)
|
|
582
|
-
* - Don't have nested file references that need loading
|
|
694
|
+
* - sessionId: Added by multi-turn strategy providers (GOAT, Crescendo)
|
|
583
695
|
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
696
|
+
* Note: Variables starting with underscore (e.g., _conversation) are automatically
|
|
697
|
+
* treated as runtime variables and filtered out.
|
|
698
|
+
*/
|
|
699
|
+
const EXPLICIT_RUNTIME_VAR_KEYS = ["sessionId"];
|
|
700
|
+
/**
|
|
701
|
+
* Checks if a variable key is a runtime-only variable that should be filtered
|
|
702
|
+
* when comparing test cases.
|
|
586
703
|
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
704
|
+
* Runtime variables are identified by:
|
|
705
|
+
* 1. Starting with underscore (_) - convention for internal/runtime vars
|
|
706
|
+
* 2. Being in the explicit runtime var list (for legacy vars like sessionId)
|
|
590
707
|
*/
|
|
591
|
-
function
|
|
592
|
-
return
|
|
708
|
+
function isRuntimeVar(key) {
|
|
709
|
+
return key.startsWith("_") || EXPLICIT_RUNTIME_VAR_KEYS.includes(key);
|
|
593
710
|
}
|
|
594
711
|
/**
|
|
595
|
-
*
|
|
712
|
+
* Filters out runtime-only variables that are added during evaluation
|
|
713
|
+
* but aren't part of the original test definition.
|
|
596
714
|
*
|
|
597
|
-
* This
|
|
598
|
-
*
|
|
599
|
-
* 2. A nested schema reference for json_schema type (schema: file://schema.json)
|
|
715
|
+
* This is used when comparing test cases to determine if a result
|
|
716
|
+
* corresponds to a particular test, regardless of runtime state.
|
|
600
717
|
*
|
|
601
|
-
*
|
|
718
|
+
* Runtime variables are identified by:
|
|
719
|
+
* - Starting with underscore (e.g., _conversation, _metadata)
|
|
720
|
+
* - Being in the explicit list (e.g., sessionId for backward compatibility)
|
|
721
|
+
*/
|
|
722
|
+
function filterRuntimeVars(vars) {
|
|
723
|
+
if (!vars || typeof vars !== "object" || Array.isArray(vars)) return vars;
|
|
724
|
+
const filtered = {};
|
|
725
|
+
for (const [key, value] of Object.entries(vars)) if (!isRuntimeVar(key)) filtered[key] = value;
|
|
726
|
+
return filtered;
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Extracts only runtime variables from a vars object.
|
|
730
|
+
* This is the inverse of filterRuntimeVars.
|
|
602
731
|
*
|
|
603
|
-
*
|
|
604
|
-
* @param vars - Variables for template rendering
|
|
605
|
-
* @returns The processed response_format with all files loaded
|
|
732
|
+
* Used to restore runtime state when re-running filtered tests.
|
|
606
733
|
*/
|
|
607
|
-
function
|
|
608
|
-
if (
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if (loaded.schema !== void 0) return {
|
|
616
|
-
...loaded,
|
|
617
|
-
schema: loadedSchema
|
|
618
|
-
};
|
|
619
|
-
else if (loaded.json_schema?.schema !== void 0) return {
|
|
620
|
-
...loaded,
|
|
621
|
-
json_schema: {
|
|
622
|
-
...loaded.json_schema,
|
|
623
|
-
schema: loadedSchema
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
return loaded;
|
|
734
|
+
function extractRuntimeVars(vars) {
|
|
735
|
+
if (!vars || typeof vars !== "object" || Array.isArray(vars)) return;
|
|
736
|
+
const extracted = {};
|
|
737
|
+
for (const [key, value] of Object.entries(vars)) if (isRuntimeVar(key)) extracted[key] = value;
|
|
738
|
+
return Object.keys(extracted).length > 0 ? extracted : void 0;
|
|
739
|
+
}
|
|
740
|
+
function varsMatch(vars1, vars2) {
|
|
741
|
+
return (0, fast_deep_equal.default)(vars1, vars2);
|
|
629
742
|
}
|
|
630
743
|
/**
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
744
|
+
* Generate a unique key for a test case for deduplication purposes.
|
|
745
|
+
* Excludes runtime variables and includes strategyId to distinguish tests
|
|
746
|
+
* with the same prompt but different strategies.
|
|
634
747
|
*
|
|
635
|
-
*
|
|
748
|
+
* @param testCase - The test case to generate a key for
|
|
749
|
+
* @returns A JSON string that uniquely identifies the test case
|
|
750
|
+
*/
|
|
751
|
+
function getTestCaseDeduplicationKey(testCase) {
|
|
752
|
+
const filteredVars = filterRuntimeVars(testCase.vars);
|
|
753
|
+
const strategyId = testCase.metadata?.strategyId || "none";
|
|
754
|
+
return JSON.stringify({
|
|
755
|
+
vars: filteredVars,
|
|
756
|
+
strategyId
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Deduplicates an array of test cases based on their vars and strategyId.
|
|
761
|
+
* Tests with the same vars but different strategies are considered different.
|
|
762
|
+
* Runtime variables (like _conversation, sessionId) are filtered out before comparison.
|
|
636
763
|
*
|
|
637
|
-
* @param
|
|
638
|
-
* @
|
|
639
|
-
* @returns The processed tools configuration with variables rendered and content loaded from files if needed.
|
|
640
|
-
* @throws {Error} If the loaded tools are in an invalid format
|
|
764
|
+
* @param tests - Array of test cases to deduplicate
|
|
765
|
+
* @returns Deduplicated array of test cases
|
|
641
766
|
*/
|
|
642
|
-
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
const
|
|
646
|
-
if (
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
}
|
|
667
|
-
if (!toolDefinitions || typeof toolDefinitions === "string" || typeof toolDefinitions === "number" || typeof toolDefinitions === "boolean") throw new Error(`Function "${functionName}" must return an array or object of tool definitions, but returned: ${toolDefinitions === null ? "null" : typeof toolDefinitions}`);
|
|
668
|
-
require_logger.logger.debug(`[maybeLoadToolsFromExternalFile] Successfully loaded ${Array.isArray(toolDefinitions) ? toolDefinitions.length : "object"} tools`);
|
|
669
|
-
return toolDefinitions;
|
|
670
|
-
} catch (err) {
|
|
671
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
672
|
-
const basePath = require_logger.state.basePath || process.cwd();
|
|
673
|
-
throw new Error(`Failed to load tools from ${rendered}:\n${errorMessage}\n\nMake sure the function "${functionName}" exists and returns a valid tool definition array.\nResolved from: ${basePath}`);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
if (filePath.endsWith(".py") || require_fileExtensions.isJavascriptFile(filePath)) {
|
|
677
|
-
const ext = filePath.endsWith(".py") ? "Python" : "JavaScript";
|
|
678
|
-
const basePath = require_logger.state.basePath || process.cwd();
|
|
679
|
-
throw new Error(`Cannot load tools from ${rendered}\n${ext} files require a function name. Use this format:\n tools: file://${filePath}:get_tools\n\nYour ${ext} file should export a function that returns tool definitions:\n` + (filePath.endsWith(".py") ? ` def get_tools():\n return [{"type": "function", "function": {...}}]` : ` module.exports.get_tools = () => [{ type: "function", function: {...} }];`) + `\n\nResolved from: ${basePath}`);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
if (Array.isArray(rendered)) {
|
|
683
|
-
const results = await Promise.all(rendered.map((item) => maybeLoadToolsFromExternalFile(item, vars)));
|
|
684
|
-
if (results.every((r) => Array.isArray(r))) return results.flat();
|
|
685
|
-
return results;
|
|
686
|
-
}
|
|
687
|
-
if (typeof rendered !== "string") return rendered;
|
|
688
|
-
const loaded = maybeLoadFromExternalFile(rendered);
|
|
689
|
-
if (loaded !== void 0 && loaded !== null && typeof loaded === "string") {
|
|
690
|
-
if (loaded.startsWith("file://")) throw new Error(`Failed to load tools from ${loaded}\nEnsure the file exists and contains valid JSON or YAML tool definitions.`);
|
|
691
|
-
if (loaded.includes("def ") || loaded.includes("import ")) throw new Error("Invalid tools configuration: file appears to contain Python code.\nPython files require a function name. Use this format:\n tools: file://tools.py:get_tools");
|
|
692
|
-
throw new Error("Invalid tools configuration: expected an array or object, but got a string.\nIf using file://, ensure the file contains valid JSON or YAML tool definitions.");
|
|
767
|
+
function deduplicateTestCases(tests) {
|
|
768
|
+
const seen = /* @__PURE__ */ new Set();
|
|
769
|
+
return tests.filter((test) => {
|
|
770
|
+
const key = getTestCaseDeduplicationKey(test);
|
|
771
|
+
if (seen.has(key)) return false;
|
|
772
|
+
seen.add(key);
|
|
773
|
+
return true;
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
function resultIsForTestCase(result, testCase) {
|
|
777
|
+
const testProviderId = testCase.provider ? providerToIdentifier(testCase.provider) : void 0;
|
|
778
|
+
const resultProviderId = providerToIdentifier(result.provider);
|
|
779
|
+
const providersMatch = !testProviderId || !resultProviderId || testProviderId === resultProviderId;
|
|
780
|
+
const resultVars = filterRuntimeVars(result.vars);
|
|
781
|
+
const testVars = filterRuntimeVars(testCase.vars);
|
|
782
|
+
const doVarsMatch = varsMatch(testVars, resultVars);
|
|
783
|
+
const isMatch = doVarsMatch && providersMatch;
|
|
784
|
+
if (!isMatch) {
|
|
785
|
+
const varKeys = testVars ? Object.keys(testVars).join(", ") : "none";
|
|
786
|
+
require_logger.logger.debug(`[resultIsForTestCase] No match: vars=${doVarsMatch}, providers=${providersMatch}`, {
|
|
787
|
+
testProvider: testProviderId || "none",
|
|
788
|
+
resultProvider: resultProviderId || "none",
|
|
789
|
+
testVarKeys: varKeys
|
|
790
|
+
});
|
|
693
791
|
}
|
|
694
|
-
return
|
|
792
|
+
return isMatch;
|
|
793
|
+
}
|
|
794
|
+
//#endregion
|
|
795
|
+
//#region src/util/env.ts
|
|
796
|
+
/**
|
|
797
|
+
* Load environment variables from .env file(s).
|
|
798
|
+
* @param envPath - Single path, array of paths, or undefined for default .env loading.
|
|
799
|
+
* When paths are explicitly specified, all files must exist or an error is thrown.
|
|
800
|
+
* When multiple files are provided, later files override values from earlier files.
|
|
801
|
+
*/
|
|
802
|
+
function setupEnv(envPath) {
|
|
803
|
+
if (envPath) {
|
|
804
|
+
const paths = (Array.isArray(envPath) ? envPath : [envPath]).flatMap((p) => p.includes(",") ? p.split(",").map((s) => s.trim()) : p.trim()).filter((p) => p.length > 0);
|
|
805
|
+
if (paths.length === 0) {
|
|
806
|
+
dotenv.default.config({ quiet: true });
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
for (const p of paths) if (!fs.existsSync(p)) throw new Error(`Environment file not found: ${p}`);
|
|
810
|
+
if (paths.length === 1) require_logger.logger.info(`Loading environment variables from ${paths[0]}`);
|
|
811
|
+
else require_logger.logger.info(`Loading environment variables from: ${paths.join(", ")}`);
|
|
812
|
+
const pathArg = paths.length === 1 ? paths[0] : paths;
|
|
813
|
+
dotenv.default.config({
|
|
814
|
+
path: pathArg,
|
|
815
|
+
override: true,
|
|
816
|
+
quiet: true
|
|
817
|
+
});
|
|
818
|
+
} else dotenv.default.config({ quiet: true });
|
|
695
819
|
}
|
|
696
820
|
//#endregion
|
|
697
821
|
//#region src/googleSheets.ts
|
|
@@ -1040,7 +1164,7 @@ function createOutputMetadata(evalRecord) {
|
|
|
1040
1164
|
evaluationCreatedAt = void 0;
|
|
1041
1165
|
}
|
|
1042
1166
|
return {
|
|
1043
|
-
promptfooVersion:
|
|
1167
|
+
promptfooVersion: require_version.VERSION,
|
|
1044
1168
|
nodeVersion: process.version,
|
|
1045
1169
|
platform: os.platform(),
|
|
1046
1170
|
arch: os.arch(),
|
|
@@ -1265,12 +1389,24 @@ Object.defineProperty(exports, "isProviderAllowed", {
|
|
|
1265
1389
|
return isProviderAllowed;
|
|
1266
1390
|
}
|
|
1267
1391
|
});
|
|
1392
|
+
Object.defineProperty(exports, "isProviderConfigFileReference", {
|
|
1393
|
+
enumerable: true,
|
|
1394
|
+
get: function() {
|
|
1395
|
+
return isProviderConfigFileReference;
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1268
1398
|
Object.defineProperty(exports, "loadFunction", {
|
|
1269
1399
|
enumerable: true,
|
|
1270
1400
|
get: function() {
|
|
1271
1401
|
return loadFunction;
|
|
1272
1402
|
}
|
|
1273
1403
|
});
|
|
1404
|
+
Object.defineProperty(exports, "loadProviderConfigsFromFile", {
|
|
1405
|
+
enumerable: true,
|
|
1406
|
+
get: function() {
|
|
1407
|
+
return loadProviderConfigsFromFile;
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1274
1410
|
Object.defineProperty(exports, "maybeLoadConfigFromExternalFile", {
|
|
1275
1411
|
enumerable: true,
|
|
1276
1412
|
get: function() {
|
|
@@ -1301,6 +1437,12 @@ Object.defineProperty(exports, "maybeLoadToolsFromExternalFile", {
|
|
|
1301
1437
|
return maybeLoadToolsFromExternalFile;
|
|
1302
1438
|
}
|
|
1303
1439
|
});
|
|
1440
|
+
Object.defineProperty(exports, "normalizeProviderRef", {
|
|
1441
|
+
enumerable: true,
|
|
1442
|
+
get: function() {
|
|
1443
|
+
return normalizeProviderRef;
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1304
1446
|
Object.defineProperty(exports, "parseFileUrl", {
|
|
1305
1447
|
enumerable: true,
|
|
1306
1448
|
get: function() {
|
|
@@ -1331,6 +1473,12 @@ Object.defineProperty(exports, "readOutput", {
|
|
|
1331
1473
|
return readOutput;
|
|
1332
1474
|
}
|
|
1333
1475
|
});
|
|
1476
|
+
Object.defineProperty(exports, "readProviderConfigFile", {
|
|
1477
|
+
enumerable: true,
|
|
1478
|
+
get: function() {
|
|
1479
|
+
return readProviderConfigFile;
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1334
1482
|
Object.defineProperty(exports, "resultIsForTestCase", {
|
|
1335
1483
|
enumerable: true,
|
|
1336
1484
|
get: function() {
|
|
@@ -1356,4 +1504,4 @@ Object.defineProperty(exports, "writeOutput", {
|
|
|
1356
1504
|
}
|
|
1357
1505
|
});
|
|
1358
1506
|
|
|
1359
|
-
//# sourceMappingURL=util-
|
|
1507
|
+
//# sourceMappingURL=util-DvpHnLt0.cjs.map
|