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