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
@@ -0,0 +1,1915 @@
1
+ import { T as getEnvString, a as logger, c as REDACTED, d as normalizeFieldName, f as sanitizeObject, k as state } from "./logger-KD8JjCRJ.js";
2
+ import { n as VERSION } from "./version-0frU0UTr.js";
3
+ import { n as withGenAISpan, t as getTraceparent } from "./genaiTracer-DxODqT9e.js";
4
+ import { n as renderVarsInObject } from "./render-7uNJ2V14.js";
5
+ import { t as providerRegistry } from "./providerRegistry-1gB5vtzQ.js";
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import { z } from "zod";
9
+ import crypto from "crypto";
10
+ import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
11
+ import dedent from "dedent";
12
+ import readline from "readline";
13
+ import { spawn } from "child_process";
14
+ //#region src/providers/openai/codex-app-server.ts
15
+ const MAX_BUFFERED_JSON_RPC_CHARS = 5e6;
16
+ const DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
17
+ const DEFAULT_STARTUP_TIMEOUT_MS = 3e4;
18
+ const MINIMAL_CLI_ENV_KEYS = [
19
+ "PATH",
20
+ "Path",
21
+ "HOME",
22
+ "USER",
23
+ "USERNAME",
24
+ "USERPROFILE",
25
+ "TMPDIR",
26
+ "TMP",
27
+ "TEMP",
28
+ "SHELL",
29
+ "COMSPEC",
30
+ "SystemRoot",
31
+ "PATHEXT",
32
+ "LANG",
33
+ "LC_ALL",
34
+ "TERM"
35
+ ];
36
+ const COMMON_OPTIONAL_PROCESS_ENV_KEYS = [
37
+ "CODEX_HOME",
38
+ "HTTP_PROXY",
39
+ "HTTPS_PROXY",
40
+ "ALL_PROXY",
41
+ "NO_PROXY",
42
+ "SSL_CERT_FILE",
43
+ "SSL_CERT_DIR",
44
+ "REQUESTS_CA_BUNDLE",
45
+ "NODE_EXTRA_CA_CERTS",
46
+ "SSH_AUTH_SOCK",
47
+ "GIT_SSH_COMMAND"
48
+ ];
49
+ const CODEX_MODEL_PRICING = {
50
+ "gpt-5.4": {
51
+ input: 2.5,
52
+ output: 15,
53
+ cache_read: .25
54
+ },
55
+ "gpt-5.4-pro": {
56
+ input: 30,
57
+ output: 180,
58
+ cache_read: 30
59
+ },
60
+ "gpt-5.3-codex": {
61
+ input: 1.75,
62
+ output: 14,
63
+ cache_read: .175
64
+ },
65
+ "gpt-5.3-codex-spark": {
66
+ input: .5,
67
+ output: 4,
68
+ cache_read: .05
69
+ },
70
+ "gpt-5.2": {
71
+ input: 1.75,
72
+ output: 14,
73
+ cache_read: .175
74
+ },
75
+ "gpt-5.2-codex": {
76
+ input: 1.75,
77
+ output: 14,
78
+ cache_read: .175
79
+ },
80
+ "gpt-5.1-codex": {
81
+ input: 2,
82
+ output: 8,
83
+ cache_read: .2
84
+ },
85
+ "gpt-5.1-codex-max": {
86
+ input: 3,
87
+ output: 12,
88
+ cache_read: .3
89
+ },
90
+ "gpt-5.1-codex-mini": {
91
+ input: .5,
92
+ output: 2,
93
+ cache_read: .05
94
+ },
95
+ "gpt-5-codex": {
96
+ input: 2,
97
+ output: 8,
98
+ cache_read: .2
99
+ },
100
+ "gpt-5-codex-mini": {
101
+ input: .5,
102
+ output: 2,
103
+ cache_read: .05
104
+ },
105
+ "gpt-5": {
106
+ input: 2,
107
+ output: 8,
108
+ cache_read: .2
109
+ }
110
+ };
111
+ const CodexCliEnvValueSchema = z.union([
112
+ z.string(),
113
+ z.number(),
114
+ z.boolean()
115
+ ]).transform(String);
116
+ const CodexAppServerReasoningEffortSchema = z.enum([
117
+ "none",
118
+ "minimal",
119
+ "low",
120
+ "medium",
121
+ "high",
122
+ "xhigh"
123
+ ]);
124
+ const CodexAppServerGranularApprovalPolicySchema = z.object({ granular: z.object({
125
+ sandbox_approval: z.boolean(),
126
+ rules: z.boolean(),
127
+ skill_approval: z.boolean(),
128
+ request_permissions: z.boolean(),
129
+ mcp_elicitations: z.boolean()
130
+ }).strict() }).strict();
131
+ const CodexAppServerApprovalPolicySchema = z.union([z.enum([
132
+ "never",
133
+ "on-request",
134
+ "on-failure",
135
+ "untrusted"
136
+ ]), CodexAppServerGranularApprovalPolicySchema]);
137
+ const CommandExecutionApprovalDecisionSchema = z.union([
138
+ z.enum([
139
+ "accept",
140
+ "acceptForSession",
141
+ "decline",
142
+ "cancel"
143
+ ]),
144
+ z.object({ acceptWithExecpolicyAmendment: z.object({ execpolicy_amendment: z.array(z.string()) }).strict() }).strict(),
145
+ z.object({ applyNetworkPolicyAmendment: z.object({ network_policy_amendment: z.object({
146
+ host: z.string().min(1),
147
+ action: z.enum(["allow", "deny"])
148
+ }).strict() }).strict() }).strict()
149
+ ]);
150
+ const McpElicitationPolicySchema = z.union([z.enum([
151
+ "accept",
152
+ "decline",
153
+ "cancel"
154
+ ]), z.object({
155
+ action: z.enum([
156
+ "accept",
157
+ "decline",
158
+ "cancel"
159
+ ]),
160
+ content: z.unknown().optional(),
161
+ _meta: z.unknown().optional()
162
+ }).strict()]);
163
+ const CollaborationModeSchema = z.object({
164
+ mode: z.enum(["plan", "default"]),
165
+ settings: z.object({
166
+ model: z.string().min(1),
167
+ reasoning_effort: CodexAppServerReasoningEffortSchema.nullable(),
168
+ developer_instructions: z.string().nullable()
169
+ }).strict()
170
+ }).strict();
171
+ const ServerRequestPolicySchema = z.object({
172
+ command_execution: CommandExecutionApprovalDecisionSchema.optional(),
173
+ file_change: z.enum([
174
+ "accept",
175
+ "acceptForSession",
176
+ "decline",
177
+ "cancel"
178
+ ]).optional(),
179
+ permissions: z.object({
180
+ permissions: z.record(z.string(), z.unknown()).optional(),
181
+ scope: z.enum(["turn", "session"]).optional()
182
+ }).optional(),
183
+ user_input: z.union([z.enum(["empty", "first-option"]), z.record(z.string(), z.union([z.string(), z.array(z.string())]))]).optional(),
184
+ mcp_elicitation: McpElicitationPolicySchema.optional(),
185
+ dynamic_tools: z.record(z.string(), z.object({
186
+ success: z.boolean().optional(),
187
+ text: z.string().optional(),
188
+ contentItems: z.array(z.union([z.object({
189
+ type: z.literal("inputText"),
190
+ text: z.string()
191
+ }), z.object({
192
+ type: z.literal("inputImage"),
193
+ imageUrl: z.string()
194
+ })])).optional()
195
+ })).optional()
196
+ }).strict();
197
+ const CodexAppServerConfigShape = {
198
+ basePath: z.string().optional(),
199
+ prefix: z.string().optional(),
200
+ suffix: z.string().optional(),
201
+ provider: z.unknown().optional(),
202
+ linkedTargetId: z.string().optional(),
203
+ apiKey: z.string().min(1).optional(),
204
+ base_url: z.string().min(1).optional(),
205
+ working_dir: z.string().min(1).optional(),
206
+ additional_directories: z.array(z.string().min(1)).optional(),
207
+ skip_git_repo_check: z.boolean().optional(),
208
+ codex_path_override: z.string().min(1).optional(),
209
+ model: z.string().min(1).optional(),
210
+ model_provider: z.string().min(1).optional(),
211
+ service_tier: z.enum(["fast", "flex"]).optional(),
212
+ sandbox_mode: z.enum([
213
+ "read-only",
214
+ "workspace-write",
215
+ "danger-full-access"
216
+ ]).optional(),
217
+ sandbox_policy: z.record(z.string(), z.unknown()).optional(),
218
+ network_access_enabled: z.boolean().optional(),
219
+ approval_policy: CodexAppServerApprovalPolicySchema.optional(),
220
+ approvals_reviewer: z.enum(["user", "guardian_subagent"]).optional(),
221
+ model_reasoning_effort: CodexAppServerReasoningEffortSchema.optional(),
222
+ reasoning_summary: z.enum([
223
+ "auto",
224
+ "concise",
225
+ "detailed",
226
+ "none"
227
+ ]).optional(),
228
+ personality: z.enum([
229
+ "none",
230
+ "friendly",
231
+ "pragmatic"
232
+ ]).optional(),
233
+ base_instructions: z.string().min(1).optional(),
234
+ developer_instructions: z.string().min(1).optional(),
235
+ collaboration_mode: CollaborationModeSchema.optional(),
236
+ output_schema: z.record(z.string(), z.unknown()).optional(),
237
+ thread_id: z.string().min(1).optional(),
238
+ persist_threads: z.boolean().optional(),
239
+ thread_pool_size: z.number().int().positive().optional(),
240
+ thread_cleanup: z.enum([
241
+ "unsubscribe",
242
+ "archive",
243
+ "none"
244
+ ]).optional(),
245
+ ephemeral: z.boolean().optional(),
246
+ persist_extended_history: z.boolean().optional(),
247
+ experimental_raw_events: z.boolean().optional(),
248
+ experimental_api: z.boolean().optional(),
249
+ include_raw_events: z.boolean().optional(),
250
+ cli_config: z.record(z.string(), z.unknown()).optional(),
251
+ cli_env: z.record(z.string(), CodexCliEnvValueSchema).optional(),
252
+ inherit_process_env: z.boolean().optional(),
253
+ reuse_server: z.boolean().optional(),
254
+ deep_tracing: z.boolean().optional(),
255
+ request_timeout_ms: z.number().int().positive().optional(),
256
+ startup_timeout_ms: z.number().int().positive().optional(),
257
+ turn_timeout_ms: z.number().int().positive().optional(),
258
+ server_request_policy: ServerRequestPolicySchema.optional()
259
+ };
260
+ const CodexAppServerConfigSchema = z.object(CodexAppServerConfigShape).strict();
261
+ const CodexAppServerMergedPromptConfigSchema = z.object(CodexAppServerConfigShape).strip();
262
+ function createDeferred() {
263
+ let resolve;
264
+ let reject;
265
+ return {
266
+ promise: new Promise((promiseResolve, promiseReject) => {
267
+ resolve = promiseResolve;
268
+ reject = promiseReject;
269
+ }),
270
+ resolve,
271
+ reject
272
+ };
273
+ }
274
+ function parseCodexAppServerConfig(config, options = {}) {
275
+ const schema = options.stripUnknownKeys ? CodexAppServerMergedPromptConfigSchema : CodexAppServerConfigSchema;
276
+ try {
277
+ return schema.parse(config ?? {});
278
+ } catch (error) {
279
+ if (error instanceof z.ZodError) {
280
+ const issues = error.issues.map((issue) => {
281
+ return `${issue.path.length > 0 ? issue.path.join(".") : "(root)"}: ${issue.message}`;
282
+ }).join("; ");
283
+ throw new Error(`Invalid OpenAI Codex app-server config: ${issues}`);
284
+ }
285
+ throw error;
286
+ }
287
+ }
288
+ function mergeOptionalRecord(base, override) {
289
+ if (!base && !override) return;
290
+ return {
291
+ ...base ?? {},
292
+ ...override ?? {}
293
+ };
294
+ }
295
+ function mergeServerRequestPolicy(base, override) {
296
+ if (!base && !override) return;
297
+ const merged = {
298
+ ...base ?? {},
299
+ ...override ?? {}
300
+ };
301
+ const permissions = mergeOptionalRecord(base?.permissions, override?.permissions);
302
+ const dynamicTools = mergeOptionalRecord(base?.dynamic_tools, override?.dynamic_tools);
303
+ if (permissions) merged.permissions = permissions;
304
+ else delete merged.permissions;
305
+ if (dynamicTools) merged.dynamic_tools = dynamicTools;
306
+ else delete merged.dynamic_tools;
307
+ return merged;
308
+ }
309
+ function mergeCodexAppServerConfig(base, override) {
310
+ if (!override) return { ...base };
311
+ return {
312
+ ...base,
313
+ ...override,
314
+ cli_config: mergeOptionalRecord(base.cli_config, override.cli_config),
315
+ cli_env: mergeOptionalRecord(base.cli_env, override.cli_env),
316
+ server_request_policy: mergeServerRequestPolicy(base.server_request_policy, override.server_request_policy)
317
+ };
318
+ }
319
+ function getMinimalProcessEnv() {
320
+ const env = {};
321
+ for (const key of MINIMAL_CLI_ENV_KEYS) {
322
+ const value = process.env[key];
323
+ if (typeof value === "string" && value.length > 0) env[key] = value;
324
+ }
325
+ return env;
326
+ }
327
+ function isPlainObject(value) {
328
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
329
+ }
330
+ function flattenConfig(value, prefix = "") {
331
+ const entries = [];
332
+ for (const [key, entryValue] of Object.entries(value)) {
333
+ const nextKey = prefix ? `${prefix}.${key}` : key;
334
+ if (isPlainObject(entryValue)) entries.push(...flattenConfig(entryValue, nextKey));
335
+ else if (entryValue !== void 0) entries.push({
336
+ key: nextKey,
337
+ value: entryValue
338
+ });
339
+ }
340
+ return entries;
341
+ }
342
+ function toTomlLiteral(value) {
343
+ if (typeof value === "string") return JSON.stringify(value);
344
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
345
+ if (Array.isArray(value)) return `[${value.map((item) => toTomlLiteral(item)).join(", ")}]`;
346
+ if (value === null) return "\"\"";
347
+ return JSON.stringify(value);
348
+ }
349
+ function getJsonRpcErrorMessage(message) {
350
+ if (typeof message.error?.message === "string" && message.error.message) return message.error.message;
351
+ return "Unknown app-server error";
352
+ }
353
+ function createAbortError(message) {
354
+ const error = new Error(message);
355
+ error.name = "AbortError";
356
+ return error;
357
+ }
358
+ var CodexAppServerConnection = class {
359
+ instanceId;
360
+ process;
361
+ lineInterface;
362
+ nextRequestId = 1;
363
+ pending = /* @__PURE__ */ new Map();
364
+ closed = false;
365
+ stderrChunks = [];
366
+ stderrTotalLength = 0;
367
+ bufferedJsonRpcLines = [];
368
+ closePromise = null;
369
+ constructor(options) {
370
+ this.options = options;
371
+ this.instanceId = options.connectionInstanceId;
372
+ this.process = spawn(options.command, options.args, {
373
+ env: options.env,
374
+ stdio: [
375
+ "pipe",
376
+ "pipe",
377
+ "pipe"
378
+ ]
379
+ });
380
+ this.lineInterface = readline.createInterface({ input: this.process.stdout });
381
+ this.lineInterface.on("line", (line) => this.handleLine(line));
382
+ this.process.stderr.on("data", (chunk) => this.recordStderr(chunk));
383
+ this.process.stdin.on("error", (error) => {
384
+ logger.debug("[CodexAppServer] stdin error", { error: error.message });
385
+ });
386
+ this.process.on("error", (error) => this.handleProcessFailure(error));
387
+ this.process.on("exit", (code, signal) => {
388
+ if (this.closed) this.rejectPending(/* @__PURE__ */ new Error("codex app-server process closed"));
389
+ else this.handleProcessFailure(/* @__PURE__ */ new Error(`codex app-server exited with code ${code ?? "null"} signal ${signal ?? "null"}`));
390
+ });
391
+ }
392
+ async initialize(config) {
393
+ await this.request("initialize", {
394
+ clientInfo: {
395
+ name: "promptfoo_codex_app_server",
396
+ title: "Promptfoo Codex App Server Provider",
397
+ version: VERSION
398
+ },
399
+ capabilities: { experimentalApi: config.experimental_api ?? true }
400
+ }, { timeoutMs: this.options.startupTimeoutMs });
401
+ this.notify("initialized", {});
402
+ }
403
+ request(method, params, options = {}) {
404
+ if (this.closed) return Promise.reject(/* @__PURE__ */ new Error("codex app-server connection is closed"));
405
+ if (options.abortSignal?.aborted) return Promise.reject(createAbortError(`codex app-server request aborted: ${method}`));
406
+ const id = this.nextRequestId++;
407
+ const message = {
408
+ method,
409
+ id
410
+ };
411
+ if (params !== void 0) message.params = params;
412
+ const timeoutMs = options.timeoutMs ?? this.options.requestTimeoutMs;
413
+ return new Promise((resolve, reject) => {
414
+ const pendingRequest = {
415
+ method,
416
+ resolve,
417
+ reject,
418
+ abortSignal: options.abortSignal,
419
+ onResponse: options.onResponse
420
+ };
421
+ pendingRequest.timeout = setTimeout(() => {
422
+ const error = /* @__PURE__ */ new Error(`codex app-server request timed out: ${method}`);
423
+ this.pending.delete(id);
424
+ if (options.abortSignal && pendingRequest.abortListener) options.abortSignal.removeEventListener("abort", pendingRequest.abortListener);
425
+ reject(error);
426
+ this.closeAfterRequestTimeout(method, error);
427
+ }, timeoutMs);
428
+ if (options.abortSignal) {
429
+ pendingRequest.abortListener = () => {
430
+ const error = createAbortError(`codex app-server request aborted: ${method}`);
431
+ this.pending.delete(id);
432
+ if (pendingRequest.timeout) clearTimeout(pendingRequest.timeout);
433
+ reject(error);
434
+ logger.debug("[CodexAppServer] JSON-RPC request aborted", {
435
+ error: error.message,
436
+ method
437
+ });
438
+ };
439
+ options.abortSignal.addEventListener("abort", pendingRequest.abortListener, { once: true });
440
+ }
441
+ this.pending.set(id, pendingRequest);
442
+ this.send(message);
443
+ });
444
+ }
445
+ notify(method, params) {
446
+ const message = { method };
447
+ if (params !== void 0) message.params = params;
448
+ this.send(message);
449
+ }
450
+ getStderr() {
451
+ return this.stderrChunks.join("").slice(-1e4);
452
+ }
453
+ async close() {
454
+ if (this.closePromise !== null) return this.closePromise;
455
+ this.closePromise = new Promise((resolve) => {
456
+ this.closed = true;
457
+ this.rejectPending(/* @__PURE__ */ new Error("codex app-server connection closed"));
458
+ this.lineInterface.close();
459
+ const finish = () => resolve();
460
+ const killTimer = setTimeout(() => {
461
+ try {
462
+ if (!this.process.killed) this.process.kill("SIGKILL");
463
+ } catch {}
464
+ finish();
465
+ }, 1e3);
466
+ this.process.once("exit", () => {
467
+ clearTimeout(killTimer);
468
+ finish();
469
+ });
470
+ if (this.process.killed || this.process.exitCode !== null) {
471
+ clearTimeout(killTimer);
472
+ finish();
473
+ return;
474
+ }
475
+ try {
476
+ this.process.stdin.end();
477
+ this.process.kill("SIGTERM");
478
+ } catch {
479
+ clearTimeout(killTimer);
480
+ finish();
481
+ }
482
+ });
483
+ return this.closePromise;
484
+ }
485
+ handleLine(line) {
486
+ const trimmed = line.trim();
487
+ if (!trimmed && this.bufferedJsonRpcLines.length === 0) return;
488
+ const candidateLines = this.bufferedJsonRpcLines.length > 0 ? [...this.bufferedJsonRpcLines, line] : [trimmed];
489
+ const candidate = candidateLines.join("\\n");
490
+ let message;
491
+ try {
492
+ message = JSON.parse(candidate);
493
+ } catch (error) {
494
+ if (this.shouldBufferJsonRpcLine(error, trimmed)) {
495
+ this.bufferedJsonRpcLines = candidateLines;
496
+ if (candidate.length > MAX_BUFFERED_JSON_RPC_CHARS) {
497
+ logger.warn("[CodexAppServer] Dropping oversized partial JSON-RPC message", {
498
+ error,
499
+ bufferedChars: candidate.length
500
+ });
501
+ this.bufferedJsonRpcLines = [];
502
+ }
503
+ return;
504
+ }
505
+ logger.warn("[CodexAppServer] Failed to parse JSON-RPC line", {
506
+ error,
507
+ line: candidate
508
+ });
509
+ this.bufferedJsonRpcLines = [];
510
+ return;
511
+ }
512
+ this.bufferedJsonRpcLines = [];
513
+ this.handleMessage(message);
514
+ }
515
+ shouldBufferJsonRpcLine(error, trimmedLine) {
516
+ if (this.bufferedJsonRpcLines.length > 0) return true;
517
+ if (!trimmedLine.startsWith("{")) return false;
518
+ const message = error instanceof Error ? error.message : String(error);
519
+ return /Unterminated string|Unexpected end of JSON input|Bad control character/i.test(message);
520
+ }
521
+ handleMessage(message) {
522
+ if (message.id !== void 0 && (message.result !== void 0 || message.error !== void 0)) {
523
+ this.handleResponse(message);
524
+ return;
525
+ }
526
+ if (message.id !== void 0 && message.method) {
527
+ this.handleServerRequest(message);
528
+ return;
529
+ }
530
+ if (message.method) {
531
+ this.options.onNotification(message);
532
+ return;
533
+ }
534
+ logger.debug("[CodexAppServer] Ignoring unknown JSON-RPC message shape", { message });
535
+ }
536
+ handleResponse(message) {
537
+ const pendingRequest = this.pending.get(message.id);
538
+ if (!pendingRequest) {
539
+ logger.debug("[CodexAppServer] Received response for unknown request", { id: message.id });
540
+ return;
541
+ }
542
+ this.pending.delete(message.id);
543
+ if (pendingRequest.timeout) clearTimeout(pendingRequest.timeout);
544
+ if (pendingRequest.abortSignal && pendingRequest.abortListener) pendingRequest.abortSignal.removeEventListener("abort", pendingRequest.abortListener);
545
+ if (message.error) {
546
+ pendingRequest.reject(new Error(getJsonRpcErrorMessage(message)));
547
+ return;
548
+ }
549
+ try {
550
+ pendingRequest.onResponse?.(message.result);
551
+ } catch (error) {
552
+ pendingRequest.reject(error instanceof Error ? error : new Error(String(error)));
553
+ return;
554
+ }
555
+ pendingRequest.resolve(message.result);
556
+ }
557
+ async handleServerRequest(message) {
558
+ try {
559
+ const result = await this.options.onServerRequest(message);
560
+ this.send({
561
+ id: message.id,
562
+ result
563
+ });
564
+ } catch (error) {
565
+ const errorMessage = error instanceof Error ? error.message : String(error);
566
+ try {
567
+ this.send({
568
+ id: message.id,
569
+ error: {
570
+ code: -32e3,
571
+ message: errorMessage
572
+ }
573
+ });
574
+ } catch (sendError) {
575
+ logger.debug("[CodexAppServer] Failed to send error response for server request", {
576
+ error: sendError,
577
+ originalError: errorMessage,
578
+ method: message.method
579
+ });
580
+ }
581
+ }
582
+ }
583
+ recordStderr(chunk) {
584
+ const text = chunk.toString("utf8");
585
+ this.stderrChunks.push(text);
586
+ this.stderrTotalLength += text.length;
587
+ if (this.stderrTotalLength > 2e4) {
588
+ const truncated = this.getStderr();
589
+ this.stderrChunks = [truncated];
590
+ this.stderrTotalLength = truncated.length;
591
+ }
592
+ logger.debug("[CodexAppServer] stderr", { text });
593
+ }
594
+ handleProcessFailure(error) {
595
+ if (this.closed) return;
596
+ this.closed = true;
597
+ this.rejectPending(error);
598
+ logger.error("[CodexAppServer] Process failure", {
599
+ error: error.message,
600
+ stderr: this.getStderr()
601
+ });
602
+ this.options.onClose(error);
603
+ }
604
+ closeAfterRequestTimeout(method, error) {
605
+ if (this.closed) return;
606
+ logger.warn("[CodexAppServer] Closing app-server after JSON-RPC request timeout", {
607
+ error: error.message,
608
+ method
609
+ });
610
+ this.options.onClose(error);
611
+ this.close().catch((closeError) => {
612
+ logger.debug("[CodexAppServer] Error closing app-server after request timeout", { error: closeError });
613
+ });
614
+ }
615
+ rejectPending(error) {
616
+ for (const [id, pendingRequest] of this.pending) {
617
+ if (pendingRequest.timeout) clearTimeout(pendingRequest.timeout);
618
+ if (pendingRequest.abortSignal && pendingRequest.abortListener) pendingRequest.abortSignal.removeEventListener("abort", pendingRequest.abortListener);
619
+ pendingRequest.reject(error);
620
+ this.pending.delete(id);
621
+ }
622
+ }
623
+ send(message) {
624
+ if (this.closed) throw new Error("codex app-server connection is closed");
625
+ this.process.stdin.write(`${JSON.stringify(message)}\n`);
626
+ }
627
+ };
628
+ var OpenAICodexAppServerProvider = class {
629
+ config;
630
+ env;
631
+ apiKey;
632
+ providerId = "openai:codex-app-server";
633
+ connections = /* @__PURE__ */ new Map();
634
+ connectionPromises = /* @__PURE__ */ new Map();
635
+ initializingConnections = /* @__PURE__ */ new Set();
636
+ threads = /* @__PURE__ */ new Map();
637
+ threadPromises = /* @__PURE__ */ new Map();
638
+ threadPromiseConnectionInstances = /* @__PURE__ */ new Map();
639
+ protectedThreadCounts = /* @__PURE__ */ new Map();
640
+ threadRunQueues = /* @__PURE__ */ new Map();
641
+ activeTurnsByThread = /* @__PURE__ */ new Map();
642
+ activeTurnsByTurn = /* @__PURE__ */ new Map();
643
+ validatedWorkingDirs = /* @__PURE__ */ new Set();
644
+ ignoredProviderEnvWarningShown = false;
645
+ omittedProcessEnvWarningShown = false;
646
+ deepTracingWarningShown = false;
647
+ constructor(options = {}) {
648
+ this.config = parseCodexAppServerConfig(options.config);
649
+ this.env = options.env;
650
+ this.apiKey = this.getApiKey();
651
+ this.providerId = options.id ?? this.providerId;
652
+ providerRegistry.register(this);
653
+ }
654
+ id() {
655
+ return this.providerId;
656
+ }
657
+ getApiKey(config = this.config) {
658
+ return config.apiKey || this.env?.OPENAI_API_KEY || this.env?.CODEX_API_KEY || getEnvString("OPENAI_API_KEY") || getEnvString("CODEX_API_KEY");
659
+ }
660
+ requiresApiKey() {
661
+ return false;
662
+ }
663
+ toString() {
664
+ return "[OpenAI Codex App Server Provider]";
665
+ }
666
+ async cleanup() {
667
+ this.resolveActiveTurns(/* @__PURE__ */ new Error("codex app-server provider cleanup interrupted active turn"));
668
+ this.threads.clear();
669
+ this.threadPromises.clear();
670
+ this.threadPromiseConnectionInstances.clear();
671
+ this.threadRunQueues.clear();
672
+ this.activeTurnsByThread.clear();
673
+ this.activeTurnsByTurn.clear();
674
+ this.protectedThreadCounts.clear();
675
+ this.validatedWorkingDirs.clear();
676
+ const connections = Array.from(new Set([...this.connections.values(), ...this.initializingConnections]));
677
+ this.connections.clear();
678
+ this.connectionPromises.clear();
679
+ this.initializingConnections.clear();
680
+ await Promise.all(connections.map((connection) => connection.close().catch((error) => {
681
+ logger.warn("[CodexAppServer] Error during cleanup", { error });
682
+ })));
683
+ }
684
+ async shutdown() {
685
+ try {
686
+ await this.cleanup();
687
+ } finally {
688
+ providerRegistry.unregister(this);
689
+ }
690
+ }
691
+ async callApi(prompt, context, callOptions) {
692
+ const config = renderVarsInObject(mergeCodexAppServerConfig(this.config, context?.prompt?.config), context?.vars);
693
+ const requestedModel = typeof config.model === "string" && config.model ? config.model : void 0;
694
+ return withGenAISpan(this.buildSpanContext(prompt, context, requestedModel), () => this.callApiInternal(prompt, context, callOptions, config), (response) => this.extractSpanResult(response, requestedModel));
695
+ }
696
+ buildSpanContext(prompt, context, requestedModel) {
697
+ return {
698
+ system: "openai",
699
+ operationName: "chat",
700
+ model: requestedModel ?? "codex-app-server",
701
+ providerId: this.id(),
702
+ evalId: context?.evaluationId || context?.test?.metadata?.evaluationId,
703
+ testIndex: typeof context?.test?.vars?.__testIdx === "number" ? context.test.vars.__testIdx : void 0,
704
+ promptLabel: context?.prompt?.label,
705
+ traceparent: context?.traceparent,
706
+ requestBody: prompt
707
+ };
708
+ }
709
+ extractSpanResult(response, requestedModel) {
710
+ const result = {};
711
+ if (response.tokenUsage) result.tokenUsage = response.tokenUsage;
712
+ if (response.sessionId) result.responseId = response.sessionId;
713
+ if (requestedModel) result.responseModel = requestedModel;
714
+ if (response.cached !== void 0) result.cacheHit = response.cached;
715
+ if (response.output !== void 0) result.responseBody = typeof response.output === "string" ? response.output : JSON.stringify(response.output);
716
+ if (response.metadata?.codexAppServer?.itemCounts) result.additionalAttributes = {
717
+ ...result.additionalAttributes,
718
+ "codex.app_server.items.breakdown": JSON.stringify(response.metadata.codexAppServer.itemCounts)
719
+ };
720
+ return result;
721
+ }
722
+ async callApiInternal(prompt, context, callOptions, rawConfig) {
723
+ let config;
724
+ try {
725
+ config = parseCodexAppServerConfig(rawConfig, { stripUnknownKeys: true });
726
+ } catch (error) {
727
+ const errorMessage = error instanceof Error ? error.message : String(error);
728
+ logger.error("Error calling OpenAI Codex app-server", { error: errorMessage });
729
+ return { error: `Error calling OpenAI Codex app-server: ${errorMessage}` };
730
+ }
731
+ if (callOptions?.abortSignal?.aborted) return { error: "OpenAI Codex app-server call aborted before it started" };
732
+ const workingDirectory = this.resolveWorkingDirectory(config);
733
+ const resolvedConfig = {
734
+ approval_policy: "never",
735
+ sandbox_mode: "read-only",
736
+ network_access_enabled: false,
737
+ ephemeral: true,
738
+ thread_cleanup: "unsubscribe",
739
+ reuse_server: true,
740
+ ...config,
741
+ working_dir: workingDirectory,
742
+ additional_directories: this.resolveAdditionalDirectories(config)
743
+ };
744
+ const currentTraceparent = getTraceparent();
745
+ const apiKey = this.getApiKey(resolvedConfig);
746
+ const env = this.prepareEnvironment(resolvedConfig, currentTraceparent, apiKey);
747
+ const promptInput = this.parsePromptInput(prompt);
748
+ const connectionKey = this.generateConnectionKey(env, resolvedConfig);
749
+ const useReusableConnection = resolvedConfig.reuse_server !== false && !resolvedConfig.deep_tracing;
750
+ let localConnection;
751
+ try {
752
+ this.validateWorkingDirectory(resolvedConfig.working_dir, resolvedConfig.skip_git_repo_check);
753
+ this.warnOnceForDeepTracingThreadOptions(resolvedConfig);
754
+ const connection = useReusableConnection ? await this.getOrCreateConnection(connectionKey, env, resolvedConfig) : await this.createConnection(connectionKey, env, resolvedConfig);
755
+ if (!useReusableConnection) localConnection = connection;
756
+ const promptCacheBasis = context?.prompt?.raw ?? prompt;
757
+ const threadHandle = await this.getOrCreateThread(connection, connectionKey, promptCacheBasis, resolvedConfig, useReusableConnection, callOptions);
758
+ this.protectThread(threadHandle.threadId);
759
+ let turnStarted = false;
760
+ try {
761
+ const queueKey = this.getThreadRunQueueKey(resolvedConfig, threadHandle);
762
+ return await this.runSerializedThreadTurn(queueKey, callOptions?.abortSignal, async () => {
763
+ turnStarted = true;
764
+ const state = this.createTurnState(connectionKey, connection.instanceId, threadHandle.threadId, promptInput, resolvedConfig, env);
765
+ this.registerTurnState(state);
766
+ try {
767
+ const turnResponse = await connection.request("turn/start", this.buildTurnStartParams(threadHandle.threadId, promptInput, resolvedConfig), {
768
+ abortSignal: callOptions?.abortSignal,
769
+ timeoutMs: this.getRequestTimeoutMs(resolvedConfig),
770
+ onResponse: (response) => {
771
+ const turnId = response?.turn?.id;
772
+ if (typeof turnId === "string") this.updateTurnStateId(state, turnId);
773
+ }
774
+ });
775
+ if (typeof turnResponse?.turn?.id === "string") this.updateTurnStateId(state, turnResponse.turn.id);
776
+ await this.waitForTurnCompletion(connection, state, resolvedConfig, callOptions);
777
+ return this.buildProviderResponse(state, threadHandle, resolvedConfig);
778
+ } finally {
779
+ this.unregisterTurnState(state);
780
+ await this.cleanupThreadAfterTurn(connection, threadHandle, resolvedConfig);
781
+ }
782
+ });
783
+ } finally {
784
+ this.unprotectThread(threadHandle.threadId);
785
+ if (!turnStarted) await this.cleanupThreadAfterTurn(connection, threadHandle, resolvedConfig, { skipIfActiveTurn: true });
786
+ this.scheduleThreadPoolEnforcement(connection, connectionKey, resolvedConfig);
787
+ }
788
+ } catch (error) {
789
+ if (error instanceof Error && error.name === "AbortError" || callOptions?.abortSignal?.aborted) {
790
+ logger.warn("OpenAI Codex app-server call aborted");
791
+ return { error: "OpenAI Codex app-server call aborted" };
792
+ }
793
+ const errorMessage = error instanceof Error ? error.message : String(error);
794
+ logger.error("Error calling OpenAI Codex app-server", { error: errorMessage });
795
+ return { error: `Error calling OpenAI Codex app-server: ${errorMessage}` };
796
+ } finally {
797
+ if (localConnection) await localConnection.close().catch((error) => {
798
+ logger.debug("[CodexAppServer] Error closing local connection", { error });
799
+ });
800
+ }
801
+ }
802
+ resolveWorkingDirectory(config) {
803
+ const basePath = config.basePath || state.basePath || process.cwd();
804
+ if (!config.working_dir) return process.cwd();
805
+ return path.resolve(basePath, config.working_dir);
806
+ }
807
+ resolveAdditionalDirectories(config) {
808
+ if (!config.additional_directories?.length) return;
809
+ const basePath = config.basePath || state.basePath || process.cwd();
810
+ return config.additional_directories.map((directory) => path.resolve(basePath, directory));
811
+ }
812
+ prepareEnvironment(config, traceparent, apiKey = this.getApiKey(config)) {
813
+ const inheritProcessEnv = config.inherit_process_env === true;
814
+ const cliEnv = Object.fromEntries(Object.entries(config.cli_env ?? {}).map(([key, value]) => [key, String(value)]));
815
+ const env = {
816
+ ...inheritProcessEnv ? process.env : getMinimalProcessEnv(),
817
+ ...cliEnv
818
+ };
819
+ const ignoredProviderEnvKeys = Object.keys(this.env ?? {}).filter((key) => key !== "OPENAI_API_KEY" && key !== "CODEX_API_KEY" && !(key in (config.cli_env ?? {}))).sort();
820
+ if (ignoredProviderEnvKeys.length > 0 && !this.ignoredProviderEnvWarningShown) {
821
+ logger.warn("[CodexAppServer] Ignoring promptfoo-level env overrides for the Codex app-server process. Move these keys into config.cli_env if Codex shell commands need them.", { envKeys: ignoredProviderEnvKeys });
822
+ this.ignoredProviderEnvWarningShown = true;
823
+ }
824
+ if (!inheritProcessEnv && !this.omittedProcessEnvWarningShown) {
825
+ const omittedProcessEnvKeys = this.getOmittedOptionalProcessEnvKeys(config, env);
826
+ if (omittedProcessEnvKeys.length > 0) {
827
+ logger.warn("[CodexAppServer] Optional Codex app-server process env vars are not inherited by default. Move these keys into config.cli_env or set inherit_process_env: true if Codex commands need them.", { envKeys: omittedProcessEnvKeys });
828
+ this.omittedProcessEnvWarningShown = true;
829
+ }
830
+ }
831
+ const sortedEnv = {};
832
+ for (const key of Object.keys(env).sort()) if (env[key] !== void 0) sortedEnv[key] = env[key];
833
+ if (apiKey) {
834
+ sortedEnv.OPENAI_API_KEY = apiKey;
835
+ sortedEnv.CODEX_API_KEY = apiKey;
836
+ }
837
+ if (config.base_url) {
838
+ sortedEnv.OPENAI_BASE_URL = config.base_url;
839
+ sortedEnv.OPENAI_API_BASE_URL = config.base_url;
840
+ }
841
+ if (config.deep_tracing) {
842
+ if (!sortedEnv.OTEL_EXPORTER_OTLP_ENDPOINT) sortedEnv.OTEL_EXPORTER_OTLP_ENDPOINT = "http://127.0.0.1:4318";
843
+ if (!sortedEnv.OTEL_EXPORTER_OTLP_PROTOCOL) sortedEnv.OTEL_EXPORTER_OTLP_PROTOCOL = "http/json";
844
+ if (!sortedEnv.OTEL_SERVICE_NAME) sortedEnv.OTEL_SERVICE_NAME = "codex-app-server";
845
+ if (!sortedEnv.OTEL_TRACES_EXPORTER) sortedEnv.OTEL_TRACES_EXPORTER = "otlp";
846
+ if (traceparent) sortedEnv.TRACEPARENT = traceparent;
847
+ } else delete sortedEnv.TRACEPARENT;
848
+ return sortedEnv;
849
+ }
850
+ getOmittedOptionalProcessEnvKeys(config, env) {
851
+ const shouldWarnForSshEnv = config.network_access_enabled === true;
852
+ return COMMON_OPTIONAL_PROCESS_ENV_KEYS.filter((key) => typeof process.env[key] === "string" && !(key in env) && (shouldWarnForSshEnv || key !== "SSH_AUTH_SOCK" && key !== "GIT_SSH_COMMAND"));
853
+ }
854
+ buildAppServerArgs(config) {
855
+ const args = [
856
+ "app-server",
857
+ "--listen",
858
+ "stdio://"
859
+ ];
860
+ const cliConfig = this.getResolvedCliConfig(config);
861
+ for (const { key, value } of flattenConfig(cliConfig)) args.push("-c", `${key}=${toTomlLiteral(value)}`);
862
+ return args;
863
+ }
864
+ getResolvedCliConfig(config) {
865
+ return { ...config.cli_config ?? {} };
866
+ }
867
+ getRequestTimeoutMs(config) {
868
+ return config.request_timeout_ms ?? DEFAULT_REQUEST_TIMEOUT_MS;
869
+ }
870
+ async getOrCreateConnection(connectionKey, env, config) {
871
+ const existing = this.connections.get(connectionKey);
872
+ if (existing) return existing;
873
+ const pending = this.connectionPromises.get(connectionKey);
874
+ if (pending) return pending;
875
+ let connectionPromise;
876
+ connectionPromise = this.createConnection(connectionKey, env, config).then((connection) => {
877
+ if (this.connectionPromises.get(connectionKey) !== connectionPromise) {
878
+ connection.close().catch((error) => {
879
+ logger.debug("[CodexAppServer] Error closing stale initialized connection", { error });
880
+ });
881
+ throw new Error("codex app-server connection was closed during cleanup");
882
+ }
883
+ this.connections.set(connectionKey, connection);
884
+ return connection;
885
+ }).finally(() => {
886
+ this.connectionPromises.delete(connectionKey);
887
+ });
888
+ this.connectionPromises.set(connectionKey, connectionPromise);
889
+ return connectionPromise;
890
+ }
891
+ async createConnection(connectionKey, env, config) {
892
+ const connectionInstanceId = `${connectionKey}:${crypto.randomUUID()}`;
893
+ const connection = new CodexAppServerConnection({
894
+ connectionInstanceId,
895
+ command: config.codex_path_override ?? "codex",
896
+ args: this.buildAppServerArgs(config),
897
+ env,
898
+ requestTimeoutMs: this.getRequestTimeoutMs(config),
899
+ startupTimeoutMs: config.startup_timeout_ms ?? DEFAULT_STARTUP_TIMEOUT_MS,
900
+ onNotification: (message) => this.handleNotification(message),
901
+ onServerRequest: (message) => this.handleServerRequest(message, config),
902
+ onClose: (error) => this.handleConnectionClose(connectionKey, connectionInstanceId, error)
903
+ });
904
+ this.initializingConnections.add(connection);
905
+ try {
906
+ await connection.initialize(config);
907
+ return connection;
908
+ } catch (error) {
909
+ await connection.close().catch((closeError) => {
910
+ logger.debug("[CodexAppServer] Error closing app-server after failed initialization", { error: closeError });
911
+ });
912
+ throw error;
913
+ } finally {
914
+ this.initializingConnections.delete(connection);
915
+ }
916
+ }
917
+ handleConnectionClose(connectionKey, connectionInstanceId, error) {
918
+ logger.warn("[CodexAppServer] Connection closed", {
919
+ connectionKey,
920
+ error: error.message
921
+ });
922
+ if (this.connections.get(connectionKey)?.instanceId === connectionInstanceId) {
923
+ this.connections.delete(connectionKey);
924
+ this.connectionPromises.delete(connectionKey);
925
+ for (const [threadCacheKey, handle] of this.threads) if (handle.connectionKey === connectionKey) this.threads.delete(threadCacheKey);
926
+ for (const [threadCacheKey] of this.threadPromises) if (this.threadPromiseConnectionInstances.get(threadCacheKey) === connectionInstanceId) {
927
+ this.threadPromises.delete(threadCacheKey);
928
+ this.threadPromiseConnectionInstances.delete(threadCacheKey);
929
+ }
930
+ }
931
+ this.resolveActiveTurns(error, (state) => state.connectionInstanceId === connectionInstanceId);
932
+ }
933
+ resolveActiveTurns(error, predicate = () => true) {
934
+ for (const state of new Set(this.activeTurnsByThread.values())) {
935
+ if (!predicate(state)) continue;
936
+ state.error = error.message;
937
+ state.completed.resolve();
938
+ }
939
+ }
940
+ generateConnectionKey(env, config) {
941
+ const stableEnv = { ...env };
942
+ delete stableEnv.TRACEPARENT;
943
+ const keyData = {
944
+ env: stableEnv,
945
+ codex_path_override: config.codex_path_override,
946
+ cli_config: this.getResolvedCliConfig(config),
947
+ experimental_api: config.experimental_api
948
+ };
949
+ return `openai:codex-app-server:connection:${crypto.createHash("sha256").update(JSON.stringify(keyData)).digest("hex")}`;
950
+ }
951
+ generateThreadCacheKey(connectionKey, promptCacheBasis, config) {
952
+ const keyData = {
953
+ connectionKey,
954
+ prompt: promptCacheBasis,
955
+ working_dir: config.working_dir,
956
+ additional_directories: config.additional_directories,
957
+ model: config.model,
958
+ model_provider: config.model_provider,
959
+ service_tier: config.service_tier,
960
+ sandbox_mode: config.sandbox_mode,
961
+ sandbox_policy: config.sandbox_policy,
962
+ network_access_enabled: config.network_access_enabled,
963
+ approval_policy: config.approval_policy,
964
+ approvals_reviewer: config.approvals_reviewer,
965
+ model_reasoning_effort: config.model_reasoning_effort,
966
+ reasoning_summary: config.reasoning_summary,
967
+ personality: config.personality,
968
+ base_instructions: config.base_instructions,
969
+ developer_instructions: config.developer_instructions,
970
+ collaboration_mode: config.collaboration_mode,
971
+ output_schema: config.output_schema,
972
+ base_url: config.base_url,
973
+ ephemeral: config.ephemeral,
974
+ experimental_raw_events: config.experimental_raw_events,
975
+ persist_extended_history: config.persist_extended_history
976
+ };
977
+ return `openai:codex-app-server:thread:${crypto.createHash("sha256").update(JSON.stringify(keyData)).digest("hex")}`;
978
+ }
979
+ async getOrCreateThread(connection, connectionKey, promptCacheBasis, config, allowThreadPersistence, callOptions) {
980
+ const canPersistThread = allowThreadPersistence && config.persist_threads === true;
981
+ if (config.thread_id) {
982
+ const cacheKey = canPersistThread ? `${connectionKey}:thread_id:${config.thread_id}` : void 0;
983
+ const cachedOrPending = this.getCachedOrPendingThread(cacheKey);
984
+ if (cachedOrPending !== void 0) return this.waitForThreadHandle(cachedOrPending, callOptions?.abortSignal);
985
+ this.throwIfThreadWaitAborted(callOptions?.abortSignal);
986
+ const threadPromise = this.cacheThreadPromise(cacheKey, connection.instanceId, async () => {
987
+ const response = await connection.request("thread/resume", this.buildThreadResumeParams(config.thread_id, config), { timeoutMs: this.getRequestTimeoutMs(config) });
988
+ const handle = {
989
+ connectionKey,
990
+ threadId: response?.thread?.id ?? config.thread_id,
991
+ response,
992
+ cacheKey,
993
+ persistent: canPersistThread
994
+ };
995
+ if (cacheKey) this.threads.set(cacheKey, handle);
996
+ return handle;
997
+ });
998
+ return cacheKey ? this.waitForThreadHandle(threadPromise, callOptions?.abortSignal) : this.waitForThreadHandle(threadPromise, callOptions?.abortSignal, { onAbortResolvedThread: (threadHandle) => this.cleanupThreadAfterTurn(connection, threadHandle, config, { skipIfProtected: true }) });
999
+ }
1000
+ const cacheKey = canPersistThread ? this.generateThreadCacheKey(connectionKey, promptCacheBasis, config) : void 0;
1001
+ const cachedOrPending = this.getCachedOrPendingThread(cacheKey);
1002
+ if (cachedOrPending !== void 0) return this.waitForThreadHandle(cachedOrPending, callOptions?.abortSignal);
1003
+ this.throwIfThreadWaitAborted(callOptions?.abortSignal);
1004
+ const threadPromise = this.cacheThreadPromise(cacheKey, connection.instanceId, async () => {
1005
+ const poolSize = config.thread_pool_size ?? 1;
1006
+ if (cacheKey && this.threads.size >= poolSize) await this.evictOldestInactiveCachedThread(connection, connectionKey, this.getRequestTimeoutMs(config));
1007
+ const response = await connection.request("thread/start", this.buildThreadStartParams(config), { timeoutMs: this.getRequestTimeoutMs(config) });
1008
+ const threadId = response?.thread?.id;
1009
+ if (typeof threadId !== "string" || !threadId) throw new Error("codex app-server did not return a thread id");
1010
+ const handle = {
1011
+ connectionKey,
1012
+ threadId,
1013
+ response,
1014
+ cacheKey,
1015
+ persistent: canPersistThread
1016
+ };
1017
+ if (cacheKey) this.threads.set(cacheKey, handle);
1018
+ return handle;
1019
+ });
1020
+ return cacheKey ? this.waitForThreadHandle(threadPromise, callOptions?.abortSignal) : this.waitForThreadHandle(threadPromise, callOptions?.abortSignal, { onAbortResolvedThread: (threadHandle) => this.cleanupThreadAfterTurn(connection, threadHandle, config, { skipIfProtected: true }) });
1021
+ }
1022
+ getCachedOrPendingThread(cacheKey) {
1023
+ if (!cacheKey) return;
1024
+ return this.threads.get(cacheKey) ?? this.threadPromises.get(cacheKey);
1025
+ }
1026
+ cacheThreadPromise(cacheKey, connectionInstanceId, createThread) {
1027
+ if (!cacheKey) return createThread();
1028
+ let threadPromise;
1029
+ threadPromise = createThread().finally(() => {
1030
+ if (this.threadPromises.get(cacheKey) === threadPromise) {
1031
+ this.threadPromises.delete(cacheKey);
1032
+ this.threadPromiseConnectionInstances.delete(cacheKey);
1033
+ }
1034
+ });
1035
+ this.threadPromises.set(cacheKey, threadPromise);
1036
+ this.threadPromiseConnectionInstances.set(cacheKey, connectionInstanceId);
1037
+ return threadPromise;
1038
+ }
1039
+ throwIfThreadWaitAborted(abortSignal) {
1040
+ if (abortSignal?.aborted) throw createAbortError("Codex app-server thread wait aborted");
1041
+ }
1042
+ async waitForThreadHandle(thread, abortSignal, options = {}) {
1043
+ const threadPromise = Promise.resolve(thread);
1044
+ if (!abortSignal) return threadPromise;
1045
+ let abortCleanupScheduled = false;
1046
+ const scheduleAbortCleanup = () => {
1047
+ if (abortCleanupScheduled) return;
1048
+ abortCleanupScheduled = true;
1049
+ threadPromise.then(async (threadHandle) => {
1050
+ if (options.onAbortResolvedThread) await options.onAbortResolvedThread(threadHandle);
1051
+ }).catch((error) => {
1052
+ logger.debug("[CodexAppServer] Thread request finished with error after abort", { error });
1053
+ });
1054
+ };
1055
+ const createThreadAbortError = () => createAbortError(options.abortMessage ?? "Codex app-server thread wait aborted");
1056
+ if (abortSignal.aborted) {
1057
+ scheduleAbortCleanup();
1058
+ throw createThreadAbortError();
1059
+ }
1060
+ let abortListener;
1061
+ const abortPromise = new Promise((_, reject) => {
1062
+ abortListener = () => {
1063
+ scheduleAbortCleanup();
1064
+ reject(createThreadAbortError());
1065
+ };
1066
+ abortSignal.addEventListener("abort", abortListener, { once: true });
1067
+ });
1068
+ try {
1069
+ return await Promise.race([threadPromise, abortPromise]);
1070
+ } finally {
1071
+ if (abortListener) abortSignal.removeEventListener("abort", abortListener);
1072
+ }
1073
+ }
1074
+ scheduleThreadPoolEnforcement(fallbackConnection, fallbackConnectionKey, config) {
1075
+ if (!config.persist_threads || config.thread_id) return;
1076
+ this.enforceThreadPoolLimit(fallbackConnection, fallbackConnectionKey, config).catch((error) => {
1077
+ logger.debug("[CodexAppServer] Error enforcing thread pool limit", { error });
1078
+ });
1079
+ }
1080
+ async enforceThreadPoolLimit(fallbackConnection, fallbackConnectionKey, config) {
1081
+ const poolSize = config.thread_pool_size ?? 1;
1082
+ while (this.threads.size > poolSize) if (!await this.evictOldestInactiveCachedThread(fallbackConnection, fallbackConnectionKey, this.getRequestTimeoutMs(config))) return;
1083
+ }
1084
+ async evictOldestInactiveCachedThread(fallbackConnection, fallbackConnectionKey, timeoutMs) {
1085
+ for (const [cacheKey, handle] of this.threads) {
1086
+ if (this.isThreadProtected(handle.threadId)) continue;
1087
+ await this.evictCachedThread(fallbackConnection, fallbackConnectionKey, cacheKey, timeoutMs);
1088
+ return true;
1089
+ }
1090
+ logger.debug("[CodexAppServer] Thread pool is full, but all cached threads are active");
1091
+ return false;
1092
+ }
1093
+ async evictCachedThread(fallbackConnection, fallbackConnectionKey, cacheKey, timeoutMs) {
1094
+ const evicted = this.threads.get(cacheKey);
1095
+ this.threads.delete(cacheKey);
1096
+ if (!evicted) return;
1097
+ const connection = this.connections.get(evicted.connectionKey) ?? (evicted.connectionKey === fallbackConnectionKey ? fallbackConnection : void 0);
1098
+ if (!connection) {
1099
+ logger.debug("[CodexAppServer] Evicted cached thread without an active connection", { threadId: evicted.threadId });
1100
+ return;
1101
+ }
1102
+ try {
1103
+ await connection.request("thread/unsubscribe", { threadId: evicted.threadId }, { timeoutMs });
1104
+ } catch (error) {
1105
+ logger.warn("[CodexAppServer] Failed to unsubscribe evicted cached thread", {
1106
+ error,
1107
+ threadId: evicted.threadId
1108
+ });
1109
+ }
1110
+ }
1111
+ buildThreadStartParams(config) {
1112
+ return {
1113
+ ...config.model ? { model: config.model } : {},
1114
+ ...config.model_provider ? { modelProvider: config.model_provider } : {},
1115
+ ...config.service_tier ? { serviceTier: config.service_tier } : {},
1116
+ ...config.working_dir ? { cwd: config.working_dir } : {},
1117
+ approvalPolicy: config.approval_policy ?? "never",
1118
+ ...config.approvals_reviewer ? { approvalsReviewer: config.approvals_reviewer } : {},
1119
+ sandbox: config.sandbox_mode ?? "read-only",
1120
+ ...Object.keys(config.cli_config ?? {}).length > 0 ? { config: config.cli_config } : {},
1121
+ serviceName: "promptfoo",
1122
+ ...config.base_instructions ? { baseInstructions: config.base_instructions } : {},
1123
+ ...config.developer_instructions ? { developerInstructions: config.developer_instructions } : {},
1124
+ ...config.personality ? { personality: config.personality } : {},
1125
+ ...config.base_url ? { config: {
1126
+ ...config.cli_config ?? {},
1127
+ base_url: config.base_url
1128
+ } } : {},
1129
+ ephemeral: config.ephemeral ?? true,
1130
+ experimentalRawEvents: config.experimental_raw_events ?? false,
1131
+ persistExtendedHistory: config.persist_extended_history ?? false
1132
+ };
1133
+ }
1134
+ buildThreadResumeParams(threadId, config) {
1135
+ return {
1136
+ threadId,
1137
+ ...config.model ? { model: config.model } : {},
1138
+ ...config.model_provider ? { modelProvider: config.model_provider } : {},
1139
+ ...config.service_tier ? { serviceTier: config.service_tier } : {},
1140
+ ...config.working_dir ? { cwd: config.working_dir } : {},
1141
+ approvalPolicy: config.approval_policy ?? "never",
1142
+ ...config.approvals_reviewer ? { approvalsReviewer: config.approvals_reviewer } : {},
1143
+ sandbox: config.sandbox_mode ?? "read-only",
1144
+ ...Object.keys(config.cli_config ?? {}).length > 0 ? { config: config.cli_config } : {},
1145
+ ...config.base_instructions ? { baseInstructions: config.base_instructions } : {},
1146
+ ...config.developer_instructions ? { developerInstructions: config.developer_instructions } : {},
1147
+ ...config.personality ? { personality: config.personality } : {},
1148
+ persistExtendedHistory: config.persist_extended_history ?? false
1149
+ };
1150
+ }
1151
+ buildTurnStartParams(threadId, input, config) {
1152
+ return {
1153
+ threadId,
1154
+ input,
1155
+ ...config.working_dir ? { cwd: config.working_dir } : {},
1156
+ approvalPolicy: config.approval_policy ?? "never",
1157
+ ...config.approvals_reviewer ? { approvalsReviewer: config.approvals_reviewer } : {},
1158
+ ...config.sandbox_policy || config.network_access_enabled !== void 0 ? { sandboxPolicy: this.buildSandboxPolicy(config) } : {},
1159
+ ...config.model ? { model: config.model } : {},
1160
+ ...config.service_tier ? { serviceTier: config.service_tier } : {},
1161
+ ...config.model_reasoning_effort ? { effort: config.model_reasoning_effort } : {},
1162
+ ...config.reasoning_summary ? { summary: config.reasoning_summary } : {},
1163
+ ...config.personality ? { personality: config.personality } : {},
1164
+ ...config.collaboration_mode ? { collaborationMode: config.collaboration_mode } : {},
1165
+ ...config.output_schema ? { outputSchema: config.output_schema } : {}
1166
+ };
1167
+ }
1168
+ buildSandboxPolicy(config) {
1169
+ if (config.sandbox_policy) return config.sandbox_policy;
1170
+ const networkAccess = config.network_access_enabled === true;
1171
+ switch (config.sandbox_mode ?? "read-only") {
1172
+ case "danger-full-access": return { type: "dangerFullAccess" };
1173
+ case "workspace-write": return {
1174
+ type: "workspaceWrite",
1175
+ writableRoots: [config.working_dir, ...config.additional_directories ?? []].filter(Boolean),
1176
+ readOnlyAccess: { type: "fullAccess" },
1177
+ networkAccess,
1178
+ excludeTmpdirEnvVar: false,
1179
+ excludeSlashTmp: false
1180
+ };
1181
+ default: return {
1182
+ type: "readOnly",
1183
+ access: { type: "fullAccess" },
1184
+ networkAccess
1185
+ };
1186
+ }
1187
+ }
1188
+ parsePromptInput(prompt) {
1189
+ let parsedPrompt;
1190
+ try {
1191
+ parsedPrompt = JSON.parse(prompt);
1192
+ } catch {
1193
+ return [{
1194
+ type: "text",
1195
+ text: prompt,
1196
+ text_elements: []
1197
+ }];
1198
+ }
1199
+ if (!Array.isArray(parsedPrompt) || parsedPrompt.length === 0) return [{
1200
+ type: "text",
1201
+ text: prompt,
1202
+ text_elements: []
1203
+ }];
1204
+ const input = [];
1205
+ for (const item of parsedPrompt) {
1206
+ if (!this.isPromptInputItem(item)) return [{
1207
+ type: "text",
1208
+ text: prompt,
1209
+ text_elements: []
1210
+ }];
1211
+ input.push(this.normalizePromptInputItem(item));
1212
+ }
1213
+ return input;
1214
+ }
1215
+ isPromptInputItem(item) {
1216
+ if (!item || typeof item !== "object" || Array.isArray(item)) return false;
1217
+ if ("type" in item && item.type === "text") return "text" in item && typeof item.text === "string";
1218
+ if ("type" in item && item.type === "image") return "url" in item && typeof item.url === "string";
1219
+ if ("type" in item && (item.type === "local_image" || item.type === "localImage")) return "path" in item && typeof item.path === "string";
1220
+ if ("type" in item && (item.type === "skill" || item.type === "mention")) return "name" in item && typeof item.name === "string" && "path" in item && typeof item.path === "string";
1221
+ return false;
1222
+ }
1223
+ normalizePromptInputItem(item) {
1224
+ switch (item.type) {
1225
+ case "text": return {
1226
+ type: "text",
1227
+ text: item.text,
1228
+ text_elements: []
1229
+ };
1230
+ case "image": return {
1231
+ type: "image",
1232
+ url: item.url
1233
+ };
1234
+ case "local_image":
1235
+ case "localImage": return {
1236
+ type: "localImage",
1237
+ path: item.path
1238
+ };
1239
+ case "skill": return {
1240
+ type: "skill",
1241
+ name: item.name,
1242
+ path: item.path
1243
+ };
1244
+ case "mention": return {
1245
+ type: "mention",
1246
+ name: item.name,
1247
+ path: item.path
1248
+ };
1249
+ }
1250
+ }
1251
+ formatPromptInputForTrace(input) {
1252
+ return input.map((item) => {
1253
+ switch (item.type) {
1254
+ case "text": return item.text;
1255
+ case "image": return `[image: ${item.url}]`;
1256
+ case "localImage": return `[local_image: ${item.path}]`;
1257
+ case "skill": return `[skill: ${item.name} ${item.path}]`;
1258
+ case "mention": return `[mention: ${item.name} ${item.path}]`;
1259
+ }
1260
+ }).join("\n");
1261
+ }
1262
+ createTurnState(connectionKey, connectionInstanceId, threadId, promptInput, config, appServerEnv) {
1263
+ return {
1264
+ connectionKey,
1265
+ connectionInstanceId,
1266
+ threadId,
1267
+ config,
1268
+ appServerEnv,
1269
+ promptInput,
1270
+ items: [],
1271
+ itemStarts: [],
1272
+ notifications: [],
1273
+ notificationCount: 0,
1274
+ serverRequests: [],
1275
+ agentMessageDeltas: [],
1276
+ agentMessageDeltasByItemId: /* @__PURE__ */ new Map(),
1277
+ completed: createDeferred(),
1278
+ activeSpans: /* @__PURE__ */ new Map(),
1279
+ itemStartTimes: /* @__PURE__ */ new Map(),
1280
+ lastEventTime: Date.now()
1281
+ };
1282
+ }
1283
+ registerTurnState(state) {
1284
+ this.activeTurnsByThread.set(state.threadId, state);
1285
+ if (state.turnId) this.activeTurnsByTurn.set(state.turnId, state);
1286
+ }
1287
+ updateTurnStateId(state, turnId) {
1288
+ if (state.turnId && state.turnId !== turnId) this.activeTurnsByTurn.delete(state.turnId);
1289
+ state.turnId = turnId;
1290
+ this.activeTurnsByTurn.set(turnId, state);
1291
+ }
1292
+ unregisterTurnState(state) {
1293
+ this.activeTurnsByThread.delete(state.threadId);
1294
+ if (state.turnId) this.activeTurnsByTurn.delete(state.turnId);
1295
+ this.endUnclosedItemSpans(state);
1296
+ }
1297
+ protectThread(threadId) {
1298
+ this.protectedThreadCounts.set(threadId, (this.protectedThreadCounts.get(threadId) ?? 0) + 1);
1299
+ }
1300
+ unprotectThread(threadId) {
1301
+ const count = this.protectedThreadCounts.get(threadId);
1302
+ if (!count || count <= 1) {
1303
+ this.protectedThreadCounts.delete(threadId);
1304
+ return;
1305
+ }
1306
+ this.protectedThreadCounts.set(threadId, count - 1);
1307
+ }
1308
+ isThreadProtected(threadId) {
1309
+ return this.activeTurnsByThread.has(threadId) || (this.protectedThreadCounts.get(threadId) ?? 0) > 0;
1310
+ }
1311
+ getTurnState(threadId, turnId) {
1312
+ if (turnId) return this.activeTurnsByTurn.get(turnId);
1313
+ if (threadId) return this.activeTurnsByThread.get(threadId);
1314
+ }
1315
+ handleNotification(message) {
1316
+ const params = message.params ?? {};
1317
+ const state = this.getTurnState(params.threadId, params.turnId);
1318
+ if (!state) {
1319
+ logger.debug("[CodexAppServer] Notification without active turn", { method: message.method });
1320
+ return;
1321
+ }
1322
+ state.notificationCount += 1;
1323
+ if (state.config.include_raw_events) state.notifications.push(message);
1324
+ const eventTime = Date.now();
1325
+ switch (message.method) {
1326
+ case "turn/started":
1327
+ if (typeof params.turn?.id === "string") this.updateTurnStateId(state, params.turn.id);
1328
+ break;
1329
+ case "item/started":
1330
+ this.handleItemStarted(state, params.item, eventTime);
1331
+ break;
1332
+ case "item/completed":
1333
+ this.handleItemCompleted(state, params.item, eventTime);
1334
+ break;
1335
+ case "item/agentMessage/delta":
1336
+ this.handleAgentMessageDelta(state, params);
1337
+ break;
1338
+ case "thread/tokenUsage/updated":
1339
+ state.rawTokenUsage = params.tokenUsage;
1340
+ state.tokenUsage = this.buildTokenUsage(params.tokenUsage);
1341
+ break;
1342
+ case "turn/completed":
1343
+ state.turn = params.turn;
1344
+ if (params.turn?.status === "failed") state.error = params.turn?.error?.message ?? "Codex app-server turn failed";
1345
+ state.completed.resolve();
1346
+ break;
1347
+ case "error":
1348
+ if (params.willRetry === true) {
1349
+ logger.debug("[CodexAppServer] Retryable error received", {
1350
+ error: params.error?.message,
1351
+ threadId: params.threadId,
1352
+ turnId: params.turnId
1353
+ });
1354
+ break;
1355
+ }
1356
+ state.error = params.error?.message ?? "Codex app-server error";
1357
+ state.completed.resolve();
1358
+ break;
1359
+ }
1360
+ state.lastEventTime = eventTime;
1361
+ }
1362
+ handleItemStarted(state, item, eventTime) {
1363
+ if (!item) return;
1364
+ state.itemStarts.push(item);
1365
+ if (!item.id) return;
1366
+ const itemId = String(item.id);
1367
+ const span = this.startItemSpan(item, itemId);
1368
+ state.activeSpans.set(itemId, span);
1369
+ state.itemStartTimes.set(itemId, eventTime);
1370
+ }
1371
+ handleItemCompleted(state, item, eventTime) {
1372
+ if (!item) return;
1373
+ state.items.push(item);
1374
+ const itemId = item.id ? String(item.id) : crypto.randomUUID();
1375
+ const span = state.activeSpans.get(itemId) ?? this.startItemSpan(item, itemId, state.lastEventTime);
1376
+ const startTime = state.itemStartTimes.get(itemId) ?? state.lastEventTime;
1377
+ this.applyItemCompletionAttributes(span, item, eventTime, startTime);
1378
+ span.end();
1379
+ state.activeSpans.delete(itemId);
1380
+ state.itemStartTimes.delete(itemId);
1381
+ }
1382
+ handleAgentMessageDelta(state, params) {
1383
+ if (typeof params.delta !== "string") return;
1384
+ state.agentMessageDeltas.push(params.delta);
1385
+ if (typeof params.itemId === "string") {
1386
+ const existing = state.agentMessageDeltasByItemId.get(params.itemId) ?? "";
1387
+ state.agentMessageDeltasByItemId.set(params.itemId, existing + params.delta);
1388
+ }
1389
+ }
1390
+ async handleServerRequest(message, config) {
1391
+ const params = message.params ?? {};
1392
+ const state = this.getTurnState(params.threadId ?? params.conversationId, params.turnId);
1393
+ const record = {
1394
+ id: message.id,
1395
+ method: message.method ?? "unknown",
1396
+ params: this.sanitizeForMetadata(params)
1397
+ };
1398
+ try {
1399
+ const response = this.buildServerRequestResponse(message, state?.config ?? config);
1400
+ record.response = this.sanitizeForMetadata(response);
1401
+ state?.serverRequests.push(record);
1402
+ return response;
1403
+ } catch (error) {
1404
+ record.error = error instanceof Error ? error.message : String(error);
1405
+ state?.serverRequests.push(record);
1406
+ throw error;
1407
+ }
1408
+ }
1409
+ buildServerRequestResponse(message, config) {
1410
+ const policy = config.server_request_policy ?? {};
1411
+ switch (message.method) {
1412
+ case "item/commandExecution/requestApproval": return { decision: policy.command_execution ?? "decline" };
1413
+ case "execCommandApproval": return this.buildLegacyApprovalResponse(policy.command_execution);
1414
+ case "item/fileChange/requestApproval": return { decision: policy.file_change ?? "decline" };
1415
+ case "applyPatchApproval": return this.buildLegacyApprovalResponse(policy.file_change);
1416
+ case "item/permissions/requestApproval": return {
1417
+ permissions: policy.permissions?.permissions ?? {},
1418
+ scope: policy.permissions?.scope ?? "turn"
1419
+ };
1420
+ case "item/tool/requestUserInput": return this.buildUserInputResponse(message.params, policy.user_input ?? "empty");
1421
+ case "mcpServer/elicitation/request": return this.buildMcpElicitationResponse(policy.mcp_elicitation);
1422
+ case "item/tool/call": return this.buildDynamicToolResponse(message.params, policy.dynamic_tools);
1423
+ case "account/chatgptAuthTokens/refresh": throw new Error("ChatGPT auth token refresh requests are not supported by promptfoo");
1424
+ default: throw new Error(`Unsupported codex app-server request: ${message.method ?? "unknown"}`);
1425
+ }
1426
+ }
1427
+ buildLegacyApprovalResponse(decision = "decline") {
1428
+ if (typeof decision !== "string") return { decision: "denied" };
1429
+ switch (decision) {
1430
+ case "accept": return { decision: "approved" };
1431
+ case "acceptForSession": return { decision: "approved_for_session" };
1432
+ case "cancel": return { decision: "abort" };
1433
+ case "decline": return { decision: "denied" };
1434
+ }
1435
+ }
1436
+ buildMcpElicitationResponse(policy = "decline") {
1437
+ if (typeof policy === "string") return {
1438
+ action: policy,
1439
+ content: null,
1440
+ _meta: null
1441
+ };
1442
+ return {
1443
+ action: policy.action,
1444
+ content: policy.content ?? null,
1445
+ _meta: policy._meta ?? null
1446
+ };
1447
+ }
1448
+ buildUserInputResponse(params, policy) {
1449
+ const answers = {};
1450
+ const questions = Array.isArray(params?.questions) ? params.questions : [];
1451
+ for (const question of questions) {
1452
+ if (!question?.id || typeof question.id !== "string") continue;
1453
+ if (policy === "empty") {
1454
+ answers[question.id] = { answers: [] };
1455
+ continue;
1456
+ }
1457
+ if (policy === "first-option") {
1458
+ const firstLabel = Array.isArray(question.options) && typeof question.options[0]?.label === "string" ? question.options[0].label : "";
1459
+ answers[question.id] = { answers: firstLabel ? [firstLabel] : [] };
1460
+ continue;
1461
+ }
1462
+ const configuredAnswer = policy[question.id];
1463
+ answers[question.id] = { answers: Array.isArray(configuredAnswer) ? configuredAnswer : configuredAnswer ? [configuredAnswer] : [] };
1464
+ }
1465
+ return { answers };
1466
+ }
1467
+ buildDynamicToolResponse(params, tools) {
1468
+ const configured = typeof params?.tool === "string" ? tools?.[params.tool] : void 0;
1469
+ if (!configured) return {
1470
+ contentItems: [{
1471
+ type: "inputText",
1472
+ text: "No dynamic tool response configured."
1473
+ }],
1474
+ success: false
1475
+ };
1476
+ return {
1477
+ contentItems: configured.contentItems ?? [{
1478
+ type: "inputText",
1479
+ text: configured.text ?? ""
1480
+ }],
1481
+ success: configured.success ?? true
1482
+ };
1483
+ }
1484
+ async waitForTurnCompletion(connection, state, config, callOptions) {
1485
+ const interruptTurn = () => {
1486
+ if (!state.turnId) return;
1487
+ connection.request("turn/interrupt", {
1488
+ threadId: state.threadId,
1489
+ turnId: state.turnId
1490
+ }, { timeoutMs: 5e3 }).catch((error) => {
1491
+ logger.debug("[CodexAppServer] Error interrupting turn", { error });
1492
+ });
1493
+ };
1494
+ let timeout;
1495
+ let abortListener;
1496
+ const timeoutPromise = config.turn_timeout_ms ? new Promise((_, reject) => {
1497
+ timeout = setTimeout(() => {
1498
+ interruptTurn();
1499
+ reject(/* @__PURE__ */ new Error(`codex app-server turn timed out after ${config.turn_timeout_ms}ms`));
1500
+ }, config.turn_timeout_ms);
1501
+ }) : void 0;
1502
+ const abortPromise = callOptions?.abortSignal ? new Promise((_, reject) => {
1503
+ abortListener = () => {
1504
+ interruptTurn();
1505
+ reject(createAbortError("OpenAI Codex app-server call aborted"));
1506
+ };
1507
+ callOptions.abortSignal?.addEventListener("abort", abortListener, { once: true });
1508
+ }) : void 0;
1509
+ try {
1510
+ await Promise.race([
1511
+ state.completed.promise,
1512
+ timeoutPromise,
1513
+ abortPromise
1514
+ ].filter((promise) => Boolean(promise)));
1515
+ } finally {
1516
+ if (timeout) clearTimeout(timeout);
1517
+ if (abortListener && callOptions?.abortSignal) callOptions.abortSignal.removeEventListener("abort", abortListener);
1518
+ }
1519
+ if (state.error) throw new Error(state.error);
1520
+ }
1521
+ async cleanupThreadAfterTurn(connection, threadHandle, config, options = {}) {
1522
+ if (threadHandle.persistent || config.thread_cleanup === "none") return;
1523
+ if (options.skipIfProtected && this.isThreadProtected(threadHandle.threadId)) return;
1524
+ if (options.skipIfActiveTurn && this.activeTurnsByThread.has(threadHandle.threadId)) return;
1525
+ if (config.thread_id && (this.protectedThreadCounts.get(threadHandle.threadId) ?? 0) > 1) return;
1526
+ if (config.thread_id && config.thread_cleanup === "archive") return;
1527
+ try {
1528
+ if (config.thread_cleanup === "archive") await connection.request("thread/archive", { threadId: threadHandle.threadId }, { timeoutMs: this.getRequestTimeoutMs(config) });
1529
+ else await connection.request("thread/unsubscribe", { threadId: threadHandle.threadId }, { timeoutMs: this.getRequestTimeoutMs(config) });
1530
+ } catch (error) {
1531
+ logger.warn("[CodexAppServer] Error cleaning up thread after turn", {
1532
+ threadId: threadHandle.threadId,
1533
+ error
1534
+ });
1535
+ }
1536
+ }
1537
+ getThreadRunQueueKey(config, threadHandle) {
1538
+ if (config.thread_id) return `thread_id:${threadHandle.threadId}`;
1539
+ if (config.deep_tracing) return;
1540
+ if (threadHandle.persistent && threadHandle.cacheKey) return threadHandle.cacheKey;
1541
+ }
1542
+ async runSerializedThreadTurn(queueKey, abortSignal, executeTurn) {
1543
+ if (!queueKey) return executeTurn();
1544
+ const previousRun = this.threadRunQueues.get(queueKey) ?? Promise.resolve();
1545
+ let releaseCurrentRun = () => {};
1546
+ const currentRun = new Promise((resolve) => {
1547
+ releaseCurrentRun = resolve;
1548
+ });
1549
+ const queuedRun = previousRun.catch(() => void 0).then(() => currentRun);
1550
+ this.threadRunQueues.set(queueKey, queuedRun);
1551
+ queuedRun.finally(() => {
1552
+ if (this.threadRunQueues.get(queueKey) === queuedRun) this.threadRunQueues.delete(queueKey);
1553
+ });
1554
+ try {
1555
+ await this.waitForPreviousThreadRun(previousRun, abortSignal);
1556
+ return await executeTurn();
1557
+ } finally {
1558
+ releaseCurrentRun();
1559
+ }
1560
+ }
1561
+ async waitForPreviousThreadRun(previousRun, abortSignal) {
1562
+ const previousRunDone = previousRun.catch(() => void 0);
1563
+ if (!abortSignal) {
1564
+ await previousRunDone;
1565
+ return;
1566
+ }
1567
+ if (abortSignal.aborted) throw createAbortError("Codex app-server thread turn wait aborted");
1568
+ let onAbort;
1569
+ const abortPromise = new Promise((_, reject) => {
1570
+ onAbort = () => reject(createAbortError("Codex app-server thread turn wait aborted"));
1571
+ abortSignal.addEventListener("abort", onAbort, { once: true });
1572
+ });
1573
+ try {
1574
+ await Promise.race([previousRunDone, abortPromise]);
1575
+ } finally {
1576
+ if (onAbort) abortSignal.removeEventListener("abort", onAbort);
1577
+ }
1578
+ }
1579
+ buildProviderResponse(state, threadHandle, config) {
1580
+ const output = this.getFinalOutput(state);
1581
+ const normalizedItems = state.items.map((item) => this.normalizeItemForMetadata(item));
1582
+ const raw = {
1583
+ output,
1584
+ thread: this.sanitizeForMetadata(threadHandle.response?.thread),
1585
+ turn: this.sanitizeForMetadata(state.turn),
1586
+ items: normalizedItems,
1587
+ tokenUsage: this.sanitizeForMetadata(state.rawTokenUsage),
1588
+ serverRequests: state.serverRequests,
1589
+ ...config.include_raw_events ? { notifications: this.sanitizeForMetadata(state.notifications) } : {}
1590
+ };
1591
+ const metadata = this.buildResponseMetadata(state, threadHandle, config, normalizedItems);
1592
+ return {
1593
+ output,
1594
+ tokenUsage: state.tokenUsage,
1595
+ cost: this.calculateResponseCost(state.tokenUsage, config.model),
1596
+ metadata,
1597
+ raw: JSON.stringify(raw),
1598
+ sessionId: threadHandle.threadId
1599
+ };
1600
+ }
1601
+ getFinalOutput(state) {
1602
+ const completedAgentMessages = state.items.filter((item) => item?.type === "agentMessage" && typeof item.text === "string").map((item) => item.text);
1603
+ if (completedAgentMessages.length > 0) return completedAgentMessages[completedAgentMessages.length - 1];
1604
+ const deltaMessages = Array.from(state.agentMessageDeltasByItemId.values()).filter(Boolean);
1605
+ if (deltaMessages.length > 0) return deltaMessages[deltaMessages.length - 1];
1606
+ return state.agentMessageDeltas.join("");
1607
+ }
1608
+ buildResponseMetadata(state, threadHandle, config, normalizedItems) {
1609
+ const skillMetadata = this.buildSkillMetadata(state.items, this.getSkillRootPrefixes(config, state.appServerEnv));
1610
+ return {
1611
+ codexAppServer: {
1612
+ threadId: threadHandle.threadId,
1613
+ turnId: state.turnId,
1614
+ model: config.model,
1615
+ modelProvider: config.model_provider,
1616
+ cwd: config.working_dir,
1617
+ sandboxMode: config.sandbox_mode ?? "read-only",
1618
+ approvalPolicy: config.approval_policy ?? "never",
1619
+ itemCounts: this.getItemCounts(state.items),
1620
+ items: normalizedItems,
1621
+ serverRequests: state.serverRequests,
1622
+ notificationCount: state.notificationCount
1623
+ },
1624
+ ...skillMetadata?.skillCalls.length ? { skillCalls: skillMetadata.skillCalls } : {},
1625
+ ...skillMetadata && skillMetadata.attemptedSkillCalls.length > skillMetadata.skillCalls.length ? { attemptedSkillCalls: skillMetadata.attemptedSkillCalls } : {}
1626
+ };
1627
+ }
1628
+ normalizeItemForMetadata(item) {
1629
+ const base = {
1630
+ id: item?.id,
1631
+ type: item?.type,
1632
+ status: item?.status
1633
+ };
1634
+ switch (item?.type) {
1635
+ case "commandExecution": return this.sanitizeForMetadata({
1636
+ ...base,
1637
+ command: item.command,
1638
+ cwd: item.cwd,
1639
+ exitCode: item.exitCode,
1640
+ durationMs: item.durationMs,
1641
+ aggregatedOutput: item.aggregatedOutput
1642
+ });
1643
+ case "fileChange": return this.sanitizeForMetadata({
1644
+ ...base,
1645
+ changes: item.changes
1646
+ });
1647
+ case "mcpToolCall": return this.sanitizeForMetadata({
1648
+ ...base,
1649
+ server: item.server,
1650
+ tool: item.tool,
1651
+ arguments: item.arguments,
1652
+ result: item.result,
1653
+ error: item.error,
1654
+ durationMs: item.durationMs
1655
+ });
1656
+ case "dynamicToolCall": return this.sanitizeForMetadata({
1657
+ ...base,
1658
+ tool: item.tool,
1659
+ arguments: item.arguments,
1660
+ success: item.success,
1661
+ contentItems: item.contentItems,
1662
+ durationMs: item.durationMs
1663
+ });
1664
+ case "webSearch": return this.sanitizeForMetadata({
1665
+ ...base,
1666
+ query: item.query,
1667
+ action: item.action
1668
+ });
1669
+ case "agentMessage": return this.sanitizeForMetadata({
1670
+ ...base,
1671
+ text: item.text
1672
+ });
1673
+ case "reasoning": return this.sanitizeForMetadata({
1674
+ ...base,
1675
+ summary: item.summary,
1676
+ content: item.content
1677
+ });
1678
+ default: return this.sanitizeForMetadata(base);
1679
+ }
1680
+ }
1681
+ buildTokenUsage(rawTokenUsage) {
1682
+ const usage = rawTokenUsage?.last ?? rawTokenUsage?.total ?? rawTokenUsage;
1683
+ if (!usage) return;
1684
+ const prompt = usage.inputTokens ?? usage.input_tokens;
1685
+ const completion = usage.outputTokens ?? usage.output_tokens;
1686
+ const cached = usage.cachedInputTokens ?? usage.cached_input_tokens ?? 0;
1687
+ if (typeof prompt !== "number" || typeof completion !== "number") return;
1688
+ return {
1689
+ prompt,
1690
+ completion,
1691
+ total: prompt + completion,
1692
+ cached
1693
+ };
1694
+ }
1695
+ calculateResponseCost(tokenUsage, model) {
1696
+ if (!tokenUsage || !model) return 0;
1697
+ const pricing = CODEX_MODEL_PRICING[model];
1698
+ if (!pricing) return 0;
1699
+ const cachedTokens = tokenUsage.cached || 0;
1700
+ return ((tokenUsage.prompt || 0) - cachedTokens) * (pricing.input / 1e6) + cachedTokens * (pricing.cache_read / 1e6) + (tokenUsage.completion || 0) * (pricing.output / 1e6);
1701
+ }
1702
+ getItemCounts(items) {
1703
+ const counts = {};
1704
+ for (const item of items) {
1705
+ const type = typeof item?.type === "string" ? item.type : "unknown";
1706
+ counts[type] = (counts[type] ?? 0) + 1;
1707
+ }
1708
+ return counts;
1709
+ }
1710
+ validateWorkingDirectory(workingDir, skipGitCheck = false) {
1711
+ const cacheKey = `${workingDir}:${skipGitCheck}`;
1712
+ if (this.validatedWorkingDirs.has(cacheKey)) return;
1713
+ let stats;
1714
+ try {
1715
+ stats = fs.statSync(workingDir);
1716
+ } catch (err) {
1717
+ throw new Error(`Working directory ${workingDir} does not exist or isn't accessible: ${err.message}`);
1718
+ }
1719
+ if (!stats.isDirectory()) throw new Error(`Working directory ${workingDir} is not a directory`);
1720
+ if (!skipGitCheck && !this.isInsideGitRepository(workingDir)) throw new Error(dedent`Working directory ${workingDir} is not inside a Git repository.
1721
+
1722
+ Codex app-server requires a Git repository by default to prevent unrecoverable errors.
1723
+
1724
+ To bypass this check, set skip_git_repo_check: true in your provider config.`);
1725
+ this.validatedWorkingDirs.add(cacheKey);
1726
+ }
1727
+ isInsideGitRepository(workingDir) {
1728
+ return this.findGitRepositoryRoot(workingDir) !== void 0;
1729
+ }
1730
+ findGitRepositoryRoot(workingDir) {
1731
+ let currentDir = path.resolve(workingDir);
1732
+ while (true) {
1733
+ if (fs.existsSync(path.join(currentDir, ".git"))) return currentDir;
1734
+ const parentDir = path.dirname(currentDir);
1735
+ if (parentDir === currentDir) return;
1736
+ currentDir = parentDir;
1737
+ }
1738
+ }
1739
+ warnOnceForDeepTracingThreadOptions(config) {
1740
+ if (!config.deep_tracing || this.deepTracingWarningShown || !config.persist_threads && (config.thread_pool_size ?? 0) <= 1) return;
1741
+ logger.warn("[CodexAppServer] deep_tracing requires a fresh app-server process per call. Persistent thread pooling options (persist_threads, thread_pool_size) are ignored when deep_tracing is enabled. Explicit thread_id values are still resumed and serialized.");
1742
+ this.deepTracingWarningShown = true;
1743
+ }
1744
+ startItemSpan(item, itemId, startTime) {
1745
+ return trace.getTracer("promptfoo.codex-app-server").startSpan(this.getSpanNameForItem(item), {
1746
+ kind: SpanKind.INTERNAL,
1747
+ ...startTime === void 0 ? {} : { startTime },
1748
+ attributes: {
1749
+ "codex.app_server.item.id": itemId,
1750
+ "codex.app_server.item.type": item?.type ?? "unknown",
1751
+ ...this.getAttributesForItem(item)
1752
+ }
1753
+ });
1754
+ }
1755
+ applyItemCompletionAttributes(span, item, eventTime, startTime) {
1756
+ for (const [key, value] of Object.entries(this.getCompletionAttributesForItem(item))) span.setAttribute(key, value);
1757
+ span.setAttribute("codex.app_server.duration_ms", eventTime - startTime);
1758
+ if (this.isItemError(item)) span.setStatus({
1759
+ code: SpanStatusCode.ERROR,
1760
+ message: this.getItemErrorMessage(item)
1761
+ });
1762
+ else span.setStatus({ code: SpanStatusCode.OK });
1763
+ }
1764
+ endUnclosedItemSpans(state) {
1765
+ for (const [itemId, span] of state.activeSpans) {
1766
+ logger.warn("[CodexAppServer] Item span not properly closed", { itemId });
1767
+ span.setStatus({
1768
+ code: SpanStatusCode.ERROR,
1769
+ message: "Span not properly closed"
1770
+ });
1771
+ span.end();
1772
+ }
1773
+ state.activeSpans.clear();
1774
+ state.itemStartTimes.clear();
1775
+ }
1776
+ getSpanNameForItem(item) {
1777
+ switch (item?.type) {
1778
+ case "commandExecution": return `exec ${typeof item.command === "string" ? item.command.split(" ")[0] || "command" : "command"}`;
1779
+ case "fileChange": return "file change";
1780
+ case "mcpToolCall": return `mcp ${item.server ?? "unknown"}/${item.tool ?? "unknown"}`;
1781
+ case "dynamicToolCall": return `tool ${item.tool ?? "unknown"}`;
1782
+ case "agentMessage": return "agent response";
1783
+ case "reasoning": return "reasoning";
1784
+ case "webSearch": return "web search";
1785
+ default: return `codex.app_server.${item?.type ?? "unknown"}`;
1786
+ }
1787
+ }
1788
+ getAttributesForItem(item) {
1789
+ const attrs = {};
1790
+ if (item?.type === "commandExecution" && typeof item.command === "string") attrs["codex.command"] = this.sanitizeTraceText(item.command, "Codex app-server command trace attribute") ?? "";
1791
+ if (item?.type === "mcpToolCall") {
1792
+ if (typeof item.server === "string") attrs["codex.mcp.server"] = item.server;
1793
+ if (typeof item.tool === "string") attrs["codex.mcp.tool"] = item.tool;
1794
+ }
1795
+ if (item?.type === "dynamicToolCall" && typeof item.tool === "string") attrs["codex.tool.name"] = item.tool;
1796
+ if (item?.type === "webSearch" && typeof item.query === "string") attrs["codex.search.query"] = this.sanitizeTraceText(item.query, "Codex app-server web search trace attribute") ?? "";
1797
+ return attrs;
1798
+ }
1799
+ getCompletionAttributesForItem(item) {
1800
+ const attrs = {};
1801
+ if (typeof item?.status === "string") attrs["codex.status"] = item.status;
1802
+ if (item?.type === "commandExecution") {
1803
+ if (typeof item.exitCode === "number") attrs["codex.exit_code"] = item.exitCode;
1804
+ if (typeof item.aggregatedOutput === "string") attrs["codex.output"] = this.sanitizeTraceText(item.aggregatedOutput, "Codex app-server command output trace attribute") ?? "";
1805
+ }
1806
+ if (item?.type === "agentMessage" && typeof item.text === "string") attrs["codex.message"] = this.sanitizeTraceText(item.text, "Codex app-server message trace attribute") ?? "";
1807
+ return attrs;
1808
+ }
1809
+ isItemError(item) {
1810
+ return item?.status === "failed" || item?.status === "declined" || item?.error !== void 0 || item?.type === "commandExecution" && typeof item.exitCode === "number" && item.exitCode !== 0;
1811
+ }
1812
+ getItemErrorMessage(item) {
1813
+ return (typeof item?.error?.message === "string" ? item.error.message : null) || (item?.type === "commandExecution" && item.exitCode !== 0 ? `Command exited with code ${item.exitCode}` : null) || "Item failed";
1814
+ }
1815
+ getSkillRootPrefixes(config, appServerEnv) {
1816
+ const prefixes = /* @__PURE__ */ new Set();
1817
+ const addPrefix = (candidate) => {
1818
+ if (!candidate) return;
1819
+ const normalized = candidate.replace(/\\/g, "/").replace(/\/+$/g, "");
1820
+ if (normalized) prefixes.add(normalized);
1821
+ };
1822
+ addPrefix(appServerEnv.CODEX_HOME);
1823
+ addPrefix("/etc/codex");
1824
+ if (config.working_dir) {
1825
+ const resolvedWorkingDir = path.resolve(config.working_dir).replace(/\\/g, "/");
1826
+ addPrefix(path.posix.join(resolvedWorkingDir, ".agents"));
1827
+ const gitRoot = this.findGitRepositoryRoot(resolvedWorkingDir);
1828
+ if (gitRoot) addPrefix(path.posix.join(gitRoot.replace(/\\/g, "/"), ".agents"));
1829
+ }
1830
+ const homeDir = appServerEnv.HOME || appServerEnv.USERPROFILE;
1831
+ if (homeDir) addPrefix(path.posix.join(homeDir.replace(/\\/g, "/"), ".codex"));
1832
+ return Array.from(prefixes);
1833
+ }
1834
+ buildSkillMetadata(items, skillRootPrefixes) {
1835
+ if (!Array.isArray(items) || items.length === 0) return;
1836
+ const attemptedSkillCalls = this.extractSkillCallsFromItems(items, skillRootPrefixes);
1837
+ const skillCalls = this.extractSkillCallsFromItems(items, skillRootPrefixes, { requireSuccessfulCommand: true });
1838
+ if (skillCalls.length === 0 && attemptedSkillCalls.length <= skillCalls.length) return;
1839
+ return {
1840
+ attemptedSkillCalls,
1841
+ skillCalls
1842
+ };
1843
+ }
1844
+ extractSkillCallsFromItems(items, skillRootPrefixes, options = {}) {
1845
+ const skillCalls = /* @__PURE__ */ new Map();
1846
+ for (const item of items) {
1847
+ if (item?.type !== "commandExecution") continue;
1848
+ if (options.requireSuccessfulCommand && !this.isSuccessfulCommandExecution(item)) continue;
1849
+ if (typeof item.command !== "string" || !item.command.trim()) continue;
1850
+ for (const skillPath of this.extractSkillPathCandidates(item.command, skillRootPrefixes)) skillCalls.set(skillPath.path, skillPath);
1851
+ }
1852
+ return Array.from(skillCalls.values()).map((skillCall) => ({
1853
+ name: skillCall.name,
1854
+ path: skillCall.path,
1855
+ source: "heuristic"
1856
+ }));
1857
+ }
1858
+ isSuccessfulCommandExecution(item) {
1859
+ if (item?.type !== "commandExecution") return false;
1860
+ if (typeof item.status === "string" && item.status !== "completed") return false;
1861
+ if (typeof item.exitCode === "number" && item.exitCode !== 0) return false;
1862
+ return true;
1863
+ }
1864
+ extractSkillPathCandidates(text, skillRootPrefixes = []) {
1865
+ const matches = /* @__PURE__ */ new Map();
1866
+ for (const rawToken of text.split(/\s+/)) {
1867
+ const token = rawToken.replace(/^[`"'([{<]+|[`"',;:)\]}>]+$/g, "").trim();
1868
+ if (!token) continue;
1869
+ const normalizedPath = token.replace(/\\/g, "/");
1870
+ const repoMatch = normalizedPath.match(/^\.agents\/skills\/([^/\s]+)\/SKILL\.md$/);
1871
+ if (repoMatch && this.isValidSkillName(repoMatch[1])) {
1872
+ matches.set(normalizedPath, {
1873
+ name: repoMatch[1],
1874
+ path: normalizedPath
1875
+ });
1876
+ continue;
1877
+ }
1878
+ const matchingRoot = skillRootPrefixes.find((prefix) => normalizedPath.startsWith(`${prefix}/skills/`));
1879
+ if (!matchingRoot) continue;
1880
+ const customRootMatch = normalizedPath.slice(matchingRoot.length + 1).match(/^skills\/([^/\s]+)\/SKILL\.md$/);
1881
+ if (customRootMatch && this.isValidSkillName(customRootMatch[1])) matches.set(normalizedPath, {
1882
+ name: customRootMatch[1],
1883
+ path: normalizedPath
1884
+ });
1885
+ }
1886
+ return Array.from(matches.values());
1887
+ }
1888
+ isValidSkillName(name) {
1889
+ return /^[A-Za-z0-9._:-]+$/.test(name);
1890
+ }
1891
+ sanitizeTraceText(value, context) {
1892
+ const sanitized = this.redactTracePii(sanitizeObject(value, { context }));
1893
+ if (typeof sanitized === "string") return sanitized;
1894
+ if (sanitized === void 0 || sanitized === null) return;
1895
+ try {
1896
+ return JSON.stringify(sanitized);
1897
+ } catch (error) {
1898
+ logger.debug("[CodexAppServer] Failed to stringify sanitized trace text", { error });
1899
+ return;
1900
+ }
1901
+ }
1902
+ sanitizeForMetadata(value) {
1903
+ return this.redactTracePii(sanitizeObject(value, { context: "Codex app-server metadata" }));
1904
+ }
1905
+ redactTracePii(value) {
1906
+ if (typeof value === "string") return value.replace(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, REDACTED).replace(/\b(?:sk-(?:proj-)?[A-Za-z0-9_-]{20,}|sk-ant-[A-Za-z0-9_-]{20,}|AKIA[A-Z0-9]{16}|AIza[A-Za-z0-9_-]{35}|Bearer\s+[A-Za-z0-9._~+/-]{20,}|Basic\s+[A-Za-z0-9+/=]{20,})\b/g, REDACTED).replace(/\b(api[_-]?key|token|password|secret|authorization|auth)\s*([=:])(\s*)(["']?)[^\s"'`]+(\4)/gi, (_match, key, separator, spacing, quote) => `${key}${separator}${spacing}${quote}${REDACTED}${quote}`);
1907
+ if (Array.isArray(value)) return value.map((item) => this.redactTracePii(item));
1908
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [key, normalizeFieldName(key).includes("email") ? REDACTED : this.redactTracePii(entryValue)]));
1909
+ return value;
1910
+ }
1911
+ };
1912
+ //#endregion
1913
+ export { OpenAICodexAppServerProvider };
1914
+
1915
+ //# sourceMappingURL=codex-app-server-CCLjqCh9.js.map