promptfoo 0.121.3 → 0.121.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (394) hide show
  1. package/README.md +1 -1
  2. package/dist/src/{ListApp-Du7YVwj5.js → ListApp-BRUsT43Y.js} +1 -1
  3. package/dist/src/{accounts-BPyfpSeU.cjs → accounts-BIFntVWB.cjs} +5 -5
  4. package/dist/src/{accounts-CFLK3mnD.js → accounts-CLJHCDDb.js} +6 -6
  5. package/dist/src/{accounts-B2XmGjty.js → accounts-CaLNYnf7.js} +5 -5
  6. package/dist/src/{accounts-Xatc0RYb.js → accounts-bnyHT7Ju.js} +5 -5
  7. package/dist/src/{agentic-utils-36epdqwB.js → agentic-utils-B5krlibj.js} +3 -3
  8. package/dist/src/{agentic-utils-DIYAAYE7.js → agentic-utils-Ba67xmgs.js} +3 -3
  9. package/dist/src/{agentic-utils-D8yXo5Lm.js → agentic-utils-BclbiXiq.js} +4 -4
  10. package/dist/src/{agentic-utils-DAVsChuB.cjs → agentic-utils-D2x0wGhB.cjs} +3 -3
  11. package/dist/src/{agents-CLQ-P15P.js → agents-BGqaTDnr.js} +5 -7
  12. package/dist/src/{agents-wg3ohknq.js → agents-BV9yFpXX.js} +6 -7
  13. package/dist/src/{agents-CgBniSlI.js → agents-BYdMl1UE.js} +5 -9
  14. package/dist/src/{agents-Bqgfdokm.js → agents-DhxWMCtH.js} +35 -14
  15. package/dist/src/{agents-BBWxKSM0.cjs → agents-DiWmQYH9.cjs} +5 -7
  16. package/dist/src/{agents-CAYbM7qD.cjs → agents-WULPVjbH.cjs} +34 -12
  17. package/dist/src/{agents-DSSTV4bv.js → agents-emVcx3yh.js} +35 -13
  18. package/dist/src/{agents-BBVJCIYr.js → agents-n6vPqV3i.js} +35 -13
  19. package/dist/src/{aimlapi-BwGC1TtS.js → aimlapi-BxqK9HF_.js} +8 -14
  20. package/dist/src/{aimlapi-Bv8Fmc-b.cjs → aimlapi-BzLjZI_m.cjs} +8 -15
  21. package/dist/src/{aimlapi-MgSLdvy7.js → aimlapi-DR4pgeiC.js} +7 -14
  22. package/dist/src/{aimlapi-DaC3qZ-o.js → aimlapi-uPGp0Zdo.js} +7 -16
  23. package/dist/src/app/app/tsconfig.app.tsbuildinfo +1 -0
  24. package/dist/src/app/assets/Report-vjzrbgce.js +1 -0
  25. package/dist/src/app/assets/index-B3NQ8HTd.js +385 -0
  26. package/dist/src/app/assets/index-Cli2yAXv.css +1 -0
  27. package/dist/src/app/assets/rolldown-runtime-COnpUsM8.js +1 -0
  28. package/dist/src/app/assets/scroll-timeline-D9IT_e8Z.js +1 -0
  29. package/dist/src/app/assets/sync-IjzpWrOE.js +4 -0
  30. package/dist/src/app/assets/vendor-charts-BNdH8TCw.js +36 -0
  31. package/dist/src/app/assets/vendor-markdown-Ch00wnNI.js +29 -0
  32. package/dist/src/app/assets/vendor-react-CVvmk1UB.js +9 -0
  33. package/dist/src/app/assets/vendor-utils-BnEYbx2Q.js +37 -0
  34. package/dist/src/app/index.html +32 -7
  35. package/dist/src/{audio-Bn44pQxv.js → audio-BvpTOArF.js} +4 -4
  36. package/dist/src/{audio-DVFjQ67_.cjs → audio-C0vDeS0j.cjs} +4 -4
  37. package/dist/src/{audio-DjU9GswO.js → audio-CScmnmEB.js} +4 -5
  38. package/dist/src/{audio-DDA5WHdx.js → audio-Da8U9IS5.js} +4 -4
  39. package/dist/src/{base-CKjwebIH.js → base-BOMaNEes.js} +3 -3
  40. package/dist/src/{base-CqzQ4K8j.js → base-BTux96b1.js} +3 -3
  41. package/dist/src/{base-BboXIF_0.cjs → base-Tw6uhH8K.cjs} +3 -3
  42. package/dist/src/{base-Cz2ZC_iA.js → base-dYsl2hmL.js} +3 -3
  43. package/dist/src/{blobs-C6j0bvFz.cjs → blobs-B95F_7vE.cjs} +3 -3
  44. package/dist/src/{blobs-DXTl6J3H.js → blobs-BW4U31ue.js} +3 -3
  45. package/dist/src/{blobs-BUWmKWzo.js → blobs-D_gg8nbm.js} +4 -4
  46. package/dist/src/{blobs-B1JriOyi.js → blobs-DjLby-uP.js} +4 -4
  47. package/dist/src/cache-BI5BY7ey.js +280 -0
  48. package/dist/src/cache-BRkhlH3k.cjs +3 -0
  49. package/dist/src/cache-BlC6aeJ0.js +3 -0
  50. package/dist/src/cache-Bzttsk0X.js +310 -0
  51. package/dist/src/cache-Cr-qWIbP.js +310 -0
  52. package/dist/src/cache-DGg-yTZG.cjs +376 -0
  53. package/dist/src/{chat-BEwdgGEg.js → chat-BLOdH60v.js} +63 -37
  54. package/dist/src/{chat-B0iaWhoh.js → chat-Cx_LkwvZ.js} +63 -37
  55. package/dist/src/{chat-DK1U-eZ-.js → chat-D9nudO9b.js} +5 -14
  56. package/dist/src/{chat-pxmiVpWe.js → chat-DChSH_Es.js} +63 -37
  57. package/dist/src/{chat-B-52XYI1.js → chat-DG2LkwLq.js} +3 -13
  58. package/dist/src/{chat-BtIKkLKx.cjs → chat-DH97tVV9.cjs} +3 -13
  59. package/dist/src/{chat-BE0qTA8e.js → chat-aMQZw6R7.js} +4 -16
  60. package/dist/src/{chat-CM8qWR3_.cjs → chat-vYqqv1gP.cjs} +64 -38
  61. package/dist/src/{chatkit-_8eJqKcD.js → chatkit-B8X34dQc.js} +4 -4
  62. package/dist/src/{chatkit-BYGQlHlV.js → chatkit-BXu42Qwt.js} +4 -4
  63. package/dist/src/{chatkit-a2D6mY6s.js → chatkit-CbMRoeYw.js} +4 -4
  64. package/dist/src/{chatkit-Cx174XI3.cjs → chatkit-D44VyUyB.cjs} +4 -4
  65. package/dist/src/{claude-agent-sdk-8ddRp1L2.cjs → claude-agent-sdk-BRq0bbIK.cjs} +23 -18
  66. package/dist/src/{claude-agent-sdk-CMjh4LFH.js → claude-agent-sdk-BjriSVRZ.js} +20 -15
  67. package/dist/src/{claude-agent-sdk-HgbFioFw.js → claude-agent-sdk-BzNZeZ0N.js} +20 -15
  68. package/dist/src/{claude-agent-sdk-Bq5EArsX.js → claude-agent-sdk-DYv_AJ8u.js} +21 -17
  69. package/dist/src/cloud-CoD5OacT.js +3 -0
  70. package/dist/src/{cloud-z8KZpUoa.js → cloud-Da0bofJd.js} +25 -13
  71. package/dist/src/{cloudflare-ai-Bbp26N0L.js → cloudflare-ai-CXC4b1EU.js} +5 -14
  72. package/dist/src/{cloudflare-ai-BGyXlpXJ.js → cloudflare-ai-CyBoIs1Q.js} +7 -15
  73. package/dist/src/{cloudflare-ai-DdKP9TKT.js → cloudflare-ai-DGOwgexC.js} +6 -17
  74. package/dist/src/{cloudflare-ai-C62x6MQG.cjs → cloudflare-ai-DJv5qnyb.cjs} +6 -15
  75. package/dist/src/{cloudflare-gateway-DXhtXDRb.js → cloudflare-gateway-1sAoOyft.js} +6 -16
  76. package/dist/src/{cloudflare-gateway-D-e9i1Sn.js → cloudflare-gateway-D-dnkzCF.js} +5 -18
  77. package/dist/src/{cloudflare-gateway-Dx36ftqF.cjs → cloudflare-gateway-DKVjkDav.cjs} +4 -15
  78. package/dist/src/{cloudflare-gateway-BwAaUgeW.js → cloudflare-gateway-TJkVrZlB.js} +4 -15
  79. package/dist/src/codex-app-server-CCLjqCh9.js +1915 -0
  80. package/dist/src/codex-app-server-CCe0TiDc.js +1915 -0
  81. package/dist/src/codex-app-server-CPW1LFwh.js +1916 -0
  82. package/dist/src/codex-app-server-VMRnjZ68.cjs +1920 -0
  83. package/dist/src/codex-sdk-1jm_qPHf.js +3 -0
  84. package/dist/src/codex-sdk-Bd8UbO9q.cjs +1172 -0
  85. package/dist/src/codex-sdk-BgEFQ70r.js +1164 -0
  86. package/dist/src/codex-sdk-Bzb_TqX9.js +1165 -0
  87. package/dist/src/codex-sdk-Danroptg.cjs +2 -0
  88. package/dist/src/codex-sdk-DfvDTN33.js +1165 -0
  89. package/dist/src/{cometapi-BDyV-NNm.js → cometapi-B5ImDlSm.js} +9 -15
  90. package/dist/src/{cometapi-C3hOlM7-.cjs → cometapi-BgAkuYCw.cjs} +9 -16
  91. package/dist/src/{cometapi-hhL4TAh3.js → cometapi-CC7hWxmX.js} +8 -15
  92. package/dist/src/{cometapi-sp7sJpBD.js → cometapi-CCbpHkuF.js} +8 -17
  93. package/dist/src/{completion-DoYy49ti.js → completion-2iuYVxwi.js} +8 -57
  94. package/dist/src/{completion-BCimtq-h.js → completion-CrD6MQ93.js} +8 -57
  95. package/dist/src/{completion-DlXUhj5c.cjs → completion-DtQ72Bm3.cjs} +7 -62
  96. package/dist/src/{completion-DCjv7RZ3.js → completion-Vq_ad618.js} +8 -57
  97. package/dist/src/{createHash-CTQmL3G2.js → createHash-4gFQpDDv.js} +3 -3
  98. package/dist/src/{createHash-Da8fMwqB.js → createHash-DPpsZgFF.js} +3 -3
  99. package/dist/src/{createHash-DmPQkvBh.js → createHash-Un4Q_huE.js} +3 -3
  100. package/dist/src/{createHash-BYwImsYv.cjs → createHash-VvBIc-AW.cjs} +4 -4
  101. package/dist/src/{docker-CxCkwMzc.js → docker--3qzPa-6.js} +6 -14
  102. package/dist/src/{docker-Cqj2-QVi.cjs → docker-D3AY-5F5.cjs} +7 -15
  103. package/dist/src/{docker-FeBni2dw.js → docker-DCsCDvwM.js} +7 -14
  104. package/dist/src/{docker-DpguQj-w.js → docker-Dorv4_Dg.js} +6 -16
  105. package/dist/src/embedding-BXhN5lCH.cjs +63 -0
  106. package/dist/src/embedding-ChS1ivFS.js +58 -0
  107. package/dist/src/embedding-DNRvZwRN.js +59 -0
  108. package/dist/src/embedding-D_bI4NDq.js +58 -0
  109. package/dist/src/entrypoint.js +69 -6
  110. package/dist/src/{errors-P6ll7XSJ.js → errors-DFHe4L-n.js} +1 -1
  111. package/dist/src/{esm-SUNIX1x3.js → esm-B6whoAcf.js} +15 -6
  112. package/dist/src/{esm-CKWP3u_P.js → esm-BRkfNsYs.js} +16 -7
  113. package/dist/src/{esm-7UIl0pPM.js → esm-BX8fwlAO.js} +27 -18
  114. package/dist/src/{esm-CipptfDu.cjs → esm-B_rGuPTo.cjs} +15 -6
  115. package/dist/src/eval-BQPLBJbw.js +3 -0
  116. package/dist/src/{eval-BTqTn7lb.js → eval-DJ_4A-tr.js} +50 -21
  117. package/dist/src/evalResult-BBJAHAtw.cjs +2 -0
  118. package/dist/src/evalResult-BBK58h2B.js +3 -0
  119. package/dist/src/{evalResult-DpARzUCb.cjs → evalResult-Cx-8OWkb.cjs} +29 -11
  120. package/dist/src/{evalResult-DUDShQrm.js → evalResult-D6P5I5il.js} +29 -11
  121. package/dist/src/{evalResult-BkIhRdTe.js → evalResult-pSvGWFMo.js} +29 -11
  122. package/dist/src/evalResult-spPqh1G_.js +2 -0
  123. package/dist/src/{evaluator-BcvOGaam.js → evaluator-D-UIbbYq.js} +3975 -2152
  124. package/dist/src/evaluator-DgLKaZk8.js +3 -0
  125. package/dist/src/{extractor-D_wd8jxt.js → extractor-BM3jRERL.js} +6 -6
  126. package/dist/src/{extractor-DG3sSfXE.cjs → extractor-Dxr2J_wK.cjs} +6 -6
  127. package/dist/src/{extractor-CAZ2G3Kh.js → extractor-DxyiFhPk.js} +6 -6
  128. package/dist/src/{extractor-C8XwivI9.js → extractor-YlZbUMsL.js} +6 -6
  129. package/dist/src/fetch-8viavNv8.js +3 -0
  130. package/dist/src/{fetch-DoVRJZhJ.js → fetch-B6ch2nU2.js} +199 -60
  131. package/dist/src/{fetch-CVAtKnI3.js → fetch-D9xxyC1p.js} +404 -252
  132. package/dist/src/{fetch-BnR9wSnm.cjs → fetch-NuqXW1Xb.cjs} +415 -263
  133. package/dist/src/{fetch-BiYv2BZc.js → fetch-Y5qX_kST.js} +222 -70
  134. package/dist/src/{fileExtensions-LcDYkU4v.js → fileExtensions-8CjoL7vB.js} +1 -1
  135. package/dist/src/{fileExtensions-DnqA1y9x.js → fileExtensions-BGh-W-HT.js} +1 -1
  136. package/dist/src/{fileExtensions-bYh77CN8.cjs → fileExtensions-D9h-8Wxg.cjs} +1 -1
  137. package/dist/src/{fileExtensions-Ds-foDzt.js → fileExtensions-DysCsxNG.js} +1 -1
  138. package/dist/src/{formatDuration-DgBVMN65.js → formatDuration-Ch4A7G3o.js} +1 -1
  139. package/dist/src/{genaiTracer-BfxrvSUb.cjs → genaiTracer-BokHC-MW.cjs} +7 -3
  140. package/dist/src/{genaiTracer-C1rxGO8Q.js → genaiTracer-C3ZPQU60.js} +6 -2
  141. package/dist/src/{genaiTracer-70Z8BIuV.js → genaiTracer-CFny3gOy.js} +6 -2
  142. package/dist/src/{genaiTracer-D3fD9dNV.js → genaiTracer-DxODqT9e.js} +6 -2
  143. package/dist/src/golang/wrapper.go +1 -1
  144. package/dist/src/{graders-DG7mhg-b.js → graders-BoUqsCEm.js} +7402 -5699
  145. package/dist/src/{graders-BElhu9ZY.cjs → graders-Bw1wk_21.cjs} +5220 -3437
  146. package/dist/src/graders-C84JI-m5.js +2 -0
  147. package/dist/src/graders-CBbd0K0Q.cjs +2 -0
  148. package/dist/src/graders-CbQqpHSN.js +3 -0
  149. package/dist/src/{graders-RjHF8VfG.js → graders-CgPn32yp.js} +7400 -5697
  150. package/dist/src/{graders-BXAJ0sbS.js → graders-CwrbifOo.js} +6136 -4433
  151. package/dist/src/graders-DS42d3ZG.js +2 -0
  152. package/dist/src/{image-6WQXK8m8.js → image-BeWaInPF.js} +4 -4
  153. package/dist/src/{image-PoF6DN3x.js → image-BmilRNqO.js} +8 -8
  154. package/dist/src/{image--F58eEIn.cjs → image-CxJoa3aW.cjs} +8 -8
  155. package/dist/src/{image-fza3zuKs.cjs → image-D10dNAav.cjs} +4 -4
  156. package/dist/src/{image-DO0RYnjH.js → image-Dr_3I3nK.js} +4 -5
  157. package/dist/src/{image-B8b6f36E.js → image-DsGRlkh7.js} +8 -8
  158. package/dist/src/{image-CoxZp9PZ.js → image-a_SGUobh.js} +8 -8
  159. package/dist/src/{image-xNbw5ph2.js → image-qjO6FWPs.js} +4 -4
  160. package/dist/src/index.cjs +4835 -2582
  161. package/dist/src/index.d.cts +2782 -31
  162. package/dist/src/index.d.ts +2783 -32
  163. package/dist/src/index.js +4817 -2564
  164. package/dist/src/{interactiveCheck-BnMYOjMu.js → interactiveCheck-CCICw2cy.js} +2 -2
  165. package/dist/src/{invariant-BtWWVVhl.js → invariant-B2Rf6avk.js} +1 -1
  166. package/dist/src/{invariant-vgHWClmd.js → invariant-DIYf9sP1.js} +1 -1
  167. package/dist/src/{knowledgeBase-Bi7CmDbx.js → knowledgeBase-BBETc5-S.js} +6 -8
  168. package/dist/src/{knowledgeBase-DqrLX8fy.cjs → knowledgeBase-C8qOo26M.cjs} +6 -8
  169. package/dist/src/{knowledgeBase-DFRXPZl_.js → knowledgeBase-CzAi2rUI.js} +7 -8
  170. package/dist/src/{knowledgeBase-Ce3ofVan.js → knowledgeBase-Dr3Kib7F.js} +6 -10
  171. package/dist/src/{litellm-CKiAxnoM.js → litellm-BLSiANhk.js} +6 -14
  172. package/dist/src/{litellm-CnHI69aj.cjs → litellm-CaUmV7Mk.cjs} +6 -15
  173. package/dist/src/{litellm-Tc294Jhj.js → litellm-DQGo_juI.js} +5 -14
  174. package/dist/src/{litellm-Bo2gQXpo.js → litellm-DRc4qWfc.js} +5 -16
  175. package/dist/src/{logger-BcJBzSSA.js → logger-BbY6ypFL.js} +41 -12
  176. package/dist/src/{logger-D5iKBpu_.cjs → logger-COuQb2xB.cjs} +51 -10
  177. package/dist/src/{logger-DO8_zM18.js → logger-Ct2S6Yx-.js} +40 -11
  178. package/dist/src/{logger-BnkjG2jt.js → logger-KD8JjCRJ.js} +41 -12
  179. package/dist/src/{luma-ray-C9q8rdQe.js → luma-ray-B-tNZzqW.js} +6 -10
  180. package/dist/src/{luma-ray-DP0QA9qn.js → luma-ray-CtS3OlGq.js} +6 -10
  181. package/dist/src/{luma-ray-0ehMPt5N.js → luma-ray-PJJgUjOc.js} +6 -11
  182. package/dist/src/{luma-ray-m9Ku2meV.cjs → luma-ray-if-Ml4R9.cjs} +6 -10
  183. package/dist/src/main.d.ts +1 -26
  184. package/dist/src/main.js +1188 -679
  185. package/dist/src/messages-B9dSjrNf.js +544 -0
  186. package/dist/src/messages-BnsVHUnm.cjs +558 -0
  187. package/dist/src/messages-CI69Lasb.js +543 -0
  188. package/dist/src/messages-CewuNcNS.js +543 -0
  189. package/dist/src/{meteor-DLZZ3osF.cjs → meteor-BBGcGeCa.cjs} +1 -1
  190. package/dist/src/{meteor-DUiCJRC-.js → meteor-BKTM-7KS.js} +1 -1
  191. package/dist/src/{meteor-44VjEACX.js → meteor-CeGo0Lu2.js} +2 -2
  192. package/dist/src/{meteor-D-SotUw9.js → meteor-Wc_aUVvu.js} +2 -2
  193. package/dist/src/{modelslab-B5J-ZM5c.js → modelslab-BCLOtfek.js} +8 -10
  194. package/dist/src/{modelslab-IQbNg-r7.cjs → modelslab-BkapYJhh.cjs} +7 -10
  195. package/dist/src/{modelslab-BTOT8FUO.js → modelslab-D73OnKSx.js} +7 -10
  196. package/dist/src/{modelslab-BI458moT.js → modelslab-zpz9JcK0.js} +7 -12
  197. package/dist/src/{nova-reel-BZ9y-Y5s.js → nova-reel-B8F_TK5w.js} +7 -10
  198. package/dist/src/{nova-reel-Xw1SXLpg.js → nova-reel-Bx0NFV2f.js} +6 -10
  199. package/dist/src/{nova-reel-DEeQlnOJ.js → nova-reel-CNGJTLtG.js} +6 -12
  200. package/dist/src/{nova-reel-CE5etkv9.cjs → nova-reel-DkT7tnoB.cjs} +6 -10
  201. package/dist/src/{nova-sonic-Ogqf-csn.js → nova-sonic-BaXRN1cr.js} +5 -7
  202. package/dist/src/{nova-sonic-DXTLpi-r.js → nova-sonic-BeTRaFOh.js} +4 -7
  203. package/dist/src/{nova-sonic-DWswpN1E.js → nova-sonic-CL7Zqv0G.js} +4 -9
  204. package/dist/src/{nova-sonic-N0yCm0vb.cjs → nova-sonic-YT426juD.cjs} +4 -7
  205. package/dist/src/{openai-BcB5KlTk.js → openai-BMHD2Huo.js} +6 -3
  206. package/dist/src/{openai-BMcwgD5C.js → openai-BT-JvDse.js} +6 -3
  207. package/dist/src/{openai-CoxGAQwn.cjs → openai-Cy1XLs0c.cjs} +6 -3
  208. package/dist/src/{openai-D6wITiVn.js → openai-D4fxGvRx.js} +6 -3
  209. package/dist/src/openclaw-Bq7RVR3k.js +1200 -0
  210. package/dist/src/openclaw-DA8U4DsD.js +1201 -0
  211. package/dist/src/openclaw-DObVgpjC.js +1200 -0
  212. package/dist/src/openclaw-DUBZP3GL.cjs +1206 -0
  213. package/dist/src/{opencode-sdk-CHCs7dEb.js → opencode-sdk-BB40Wir1.js} +6 -8
  214. package/dist/src/{opencode-sdk-DDxj4QqH.js → opencode-sdk-BM1UAIv1.js} +6 -8
  215. package/dist/src/{opencode-sdk-WWJhnbKr.cjs → opencode-sdk-CeqiOcOU.cjs} +7 -9
  216. package/dist/src/{opencode-sdk-C71Z0ehR.js → opencode-sdk-ChdK7F7z.js} +6 -9
  217. package/dist/src/{otlpReceiver-CZL48YfC.js → otlpReceiver-C6thJRXi.js} +154 -98
  218. package/dist/src/{otlpReceiver-C9KlUtxh.js → otlpReceiver-CcdIikOu.js} +154 -98
  219. package/dist/src/{otlpReceiver-DHKqJlsz.cjs → otlpReceiver-DNSQj6bf.cjs} +154 -98
  220. package/dist/src/{otlpReceiver-CavGAA6k.js → otlpReceiver-UYMQx3sy.js} +154 -98
  221. package/dist/src/{providerRegistry-BkzVH5Ba.js → providerRegistry-1gB5vtzQ.js} +2 -2
  222. package/dist/src/{providerRegistry-BTDgfV5h.cjs → providerRegistry-BESeALrr.cjs} +2 -2
  223. package/dist/src/{providerRegistry-CUWki5mQ.js → providerRegistry-DoACwqhD.js} +2 -2
  224. package/dist/src/{providerRegistry-B9lh-_tx.js → providerRegistry-PMsleEzs.js} +2 -2
  225. package/dist/src/providers-BuyzKt7C.js +2 -0
  226. package/dist/src/providers-C7lNVBjX.cjs +3 -0
  227. package/dist/src/providers-CCE2COJi2.js +2 -0
  228. package/dist/src/{providers-Cn73d5sr.js → providers-CJh7iriU.js} +17180 -16823
  229. package/dist/src/providers-Ctcc592x.js +3 -0
  230. package/dist/src/{providers-DvddrgxL.js → providers-DRrerKra.js} +1052 -695
  231. package/dist/src/{providers-Ch6Mr0gn.js → providers-DT-GtF2t.js} +16716 -16359
  232. package/dist/src/{providers-CScd1wN6.cjs → providers-eDShy16E.cjs} +19893 -19506
  233. package/dist/src/python/persistent_wrapper.py +0 -5
  234. package/dist/src/{pythonUtils-Cpo0Ez1p.js → pythonUtils-C4tltmIn.js} +4 -4
  235. package/dist/src/{pythonUtils-dAVigVK-.cjs → pythonUtils-CoLaCwNY.cjs} +4 -4
  236. package/dist/src/{pythonUtils-Bzwbgpbg.js → pythonUtils-DMO68Jg7.js} +3 -3
  237. package/dist/src/{pythonUtils-wIqk7zAf.js → pythonUtils-DNqbnRdx.js} +3 -3
  238. package/dist/src/{quiverai-BeofbLVc.js → quiverai-BSS9a7wV.js} +4 -4
  239. package/dist/src/{quiverai-DVSEqJiq.js → quiverai-Bk1KrvL6.js} +4 -4
  240. package/dist/src/{quiverai-CcUhPIBg.cjs → quiverai-Bpx6MZ7T.cjs} +4 -4
  241. package/dist/src/{quiverai-CCQn73lq.js → quiverai-CPKhWgaT.js} +4 -5
  242. package/dist/src/render-7uNJ2V14.js +135 -0
  243. package/dist/src/render-DlscvAUJ.js +135 -0
  244. package/dist/src/render-eui5p5mL.js +136 -0
  245. package/dist/src/{render-BHl6QVq9.js → render-nj-UaPdn.js} +2 -3
  246. package/dist/src/render-tG6ir9_g.cjs +165 -0
  247. package/dist/src/{responses-CgNyTPsY.js → responses-1ztiVYsx.js} +56 -17
  248. package/dist/src/{responses-BKP_WYis.js → responses-B8haB-mD.js} +56 -17
  249. package/dist/src/{responses-CQb1Tj69.js → responses-BiaBguAu.js} +56 -17
  250. package/dist/src/{responses-mo0KQDbu.cjs → responses-CF-ayauu.cjs} +56 -17
  251. package/dist/src/rubyUtils-4hjGxvju.js +3 -0
  252. package/dist/src/{rubyUtils-DECSbsfY.js → rubyUtils-BI0p46eZ.js} +3 -3
  253. package/dist/src/{rubyUtils-CiVfln3g.js → rubyUtils-CIQFnVz4.js} +3 -3
  254. package/dist/src/rubyUtils-CO-tuszQ.cjs +2 -0
  255. package/dist/src/{rubyUtils-PgU-gHmx.js → rubyUtils-DGnoCYL2.js} +4 -4
  256. package/dist/src/{rubyUtils-CGeUtCfW.cjs → rubyUtils-DoifqkiA.cjs} +5 -4
  257. package/dist/src/{sagemaker-CqeASYE5.js → sagemaker-BDLeW29y.js} +14 -18
  258. package/dist/src/{sagemaker-MUbD5V3v.js → sagemaker-C5T60MKf.js} +14 -19
  259. package/dist/src/{sagemaker-CVv8W7so.js → sagemaker-ClS_NB07.js} +14 -18
  260. package/dist/src/{sagemaker-jiw1wQa-.cjs → sagemaker-ljtY12VM.cjs} +14 -18
  261. package/dist/src/{scanner-DVDeUz1r.js → scanner-nOCWNIXa.js} +130 -35
  262. package/dist/src/server/golang/wrapper.go +1 -1
  263. package/dist/src/server/index.js +4829 -2529
  264. package/dist/src/server/python/persistent_wrapper.py +0 -5
  265. package/dist/src/{server-BtoCXeXI.cjs → server-BEECpeGG.cjs} +140 -6
  266. package/dist/src/{server-DZ9MtCn0.js → server-ByiF3qlg.js} +129 -9
  267. package/dist/src/{server-Cns05F1j.js → server-ByxbqAcQ.js} +128 -8
  268. package/dist/src/server-C0XKRNB_.cjs +2 -0
  269. package/dist/src/server-C_15p79-.js +3 -0
  270. package/dist/src/{server-CP9qKM40.js → server-gyd6d4Hc.js} +126 -7
  271. package/dist/src/{signal-C3ZTsUgi.js → signal-DTtUuU3l.js} +3 -3
  272. package/dist/src/{slack-DCEV-vWP.js → slack-4zZX1OKP.js} +2 -2
  273. package/dist/src/{slack-94iG3T0s.cjs → slack-BLlsDpfG.cjs} +2 -2
  274. package/dist/src/{slack-BR0HtO3K.js → slack-BPYLQLgb.js} +2 -2
  275. package/dist/src/{slack-2sdpGzbt.js → slack-Bamy_7te.js} +2 -2
  276. package/dist/src/{store-CLyU7AtI.cjs → store-2K0kDi80.cjs} +3 -3
  277. package/dist/src/{store-VB0GP46K.js → store-2OXm_eBY.js} +3 -3
  278. package/dist/src/store-BELqNwvz.js +3 -0
  279. package/dist/src/{store-Cj258DgL.js → store-BPkzEyFM.js} +3 -3
  280. package/dist/src/{store-P8OKm19S.js → store-CPh25336.js} +3 -3
  281. package/dist/src/store-uQZ4AjPe.cjs +2 -0
  282. package/dist/src/{tables-BEIFz2tM.js → tables-BMSOS2Gg.js} +3 -3
  283. package/dist/src/{tables-BdZQEpRz.cjs → tables-CXbaZ9y1.cjs} +3 -3
  284. package/dist/src/{tables-DmzvLbeZ.js → tables-NlvH23ky.js} +3 -3
  285. package/dist/src/{tables-kC7R5kiK.js → tables-WgdUZ8Ck.js} +3 -3
  286. package/dist/src/{telemetry-DPXLd7UE.js → telemetry--iqaGyaS.js} +5 -4
  287. package/dist/src/{telemetry-re627Lre.cjs → telemetry-CEQxGnMZ.cjs} +8 -7
  288. package/dist/src/{telemetry-BugWqKiu.js → telemetry-CgdVGV8N.js} +5 -4
  289. package/dist/src/{telemetry-BnH5VJAU.js → telemetry-DWdGHvEf.js} +5 -4
  290. package/dist/src/telemetry-DjNoC_n3.cjs +2 -0
  291. package/dist/src/telemetry-ZdPZc0fm.js +3 -0
  292. package/dist/src/{text-CW1cyrwj.cjs → text-BiNME7QG.cjs} +1 -1
  293. package/dist/src/{text-Db-Wt2u2.js → text-D4lz-Jg_.js} +1 -1
  294. package/dist/src/{text-TIv0QYnd.js → text-DDQP0tuQ.js} +1 -1
  295. package/dist/src/{text-B_UCRPp2.js → text-NWvfMfkF.js} +1 -1
  296. package/dist/src/{tokenUsageUtils-DflFMjS0.js → tokenUsageUtils-2wIvAhB3.js} +7 -3
  297. package/dist/src/{tokenUsageUtils-BDGe-iyI.js → tokenUsageUtils-4c780gFd.js} +7 -3
  298. package/dist/src/{tokenUsageUtils-NYT-WKS6.js → tokenUsageUtils-BjVkdk18.js} +7 -3
  299. package/dist/src/{tokenUsageUtils-bVa1ga6f.cjs → tokenUsageUtils-C9odhsbW.cjs} +7 -3
  300. package/dist/src/{transcription-CaMivnjG.js → transcription-84t4ALo2.js} +7 -11
  301. package/dist/src/{transcription-Hb3VnC4M.js → transcription-Bm2emLmJ.js} +8 -11
  302. package/dist/src/{transcription-BvtsrzRG.cjs → transcription-CZ4LG5hQ.cjs} +9 -13
  303. package/dist/src/{transcription-DOMMTu01.js → transcription-D7Q0vJsh.js} +7 -13
  304. package/dist/src/{transform-DrleutM3.js → transform-B-b6Cq-q.js} +8 -6
  305. package/dist/src/transform-BQt0BeAW.js +3 -0
  306. package/dist/src/transform-Bq5oqC0s.cjs +2 -0
  307. package/dist/src/{transform-ZrG2dvlo.cjs → transform-C9izGX54.cjs} +5 -5
  308. package/dist/src/{transform-BzK09Q_9.js → transform-CwbAZ84V.js} +5 -5
  309. package/dist/src/{transform-0BwoBsvO.cjs → transform-Dg4LcO1Y.cjs} +18 -10
  310. package/dist/src/{transform-B2-jIv68.js → transform-DtooZqYY.js} +8 -6
  311. package/dist/src/{transform-ljLYHEPh.js → transform-DzCF-wqV.js} +5 -5
  312. package/dist/src/{transform-DyDAwEpE.js → transform-_DpNB4qp.js} +9 -7
  313. package/dist/src/{transform-BqPkNPYm.js → transform-eGiUAv86.js} +5 -5
  314. package/dist/src/{transformersAvailability-DKoRtQLy.cjs → transformersAvailability-B22swDxr.cjs} +1 -1
  315. package/dist/src/{transformersAvailability-BGkzavwb.js → transformersAvailability-lvCCvuPT.js} +1 -1
  316. package/dist/src/{transformersAvailability-D6c6ROpT.js → transformersAvailability-rJGPccjr.js} +1 -1
  317. package/dist/src/{types-Cd3ygw8W.js → types-BDjGOq4E.js} +354 -24
  318. package/dist/src/{types-CIhFeUC4.js → types-BVH9hjgW.js} +364 -23
  319. package/dist/src/{types-D8cGDZbL.cjs → types-CgG2rKiW.cjs} +534 -167
  320. package/dist/src/{types-q8GXGF65.js → types-DNRZVOue.js} +498 -167
  321. package/dist/src/{util-BLvy9qfE.js → util-3pBZZb_H.js} +151 -149
  322. package/dist/src/{util-CFj4YKIn.cjs → util-A5_ZsQUn.cjs} +66 -44
  323. package/dist/src/{util-BtoGs5Cb.js → util-B9CNhyac.js} +66 -44
  324. package/dist/src/{util-Bm3E9jpK.js → util-BQOCAHQC.js} +692 -690
  325. package/dist/src/{util-vNmDL5DT.js → util-BVXcTwXu.js} +138 -36
  326. package/dist/src/{util-CgDCK4KI.js → util-BlFVL0UF.js} +66 -44
  327. package/dist/src/{util-DM2rTn_6.js → util-C-kmRosx.js} +66 -44
  328. package/dist/src/{util-DbVG-yZU.js → util-DFPeFkiV.js} +138 -36
  329. package/dist/src/{util-DMFeUvLz.js → util-DN0-b81k.js} +138 -36
  330. package/dist/src/{util--9u9UVCt.cjs → util-Dpmm_dAI.cjs} +143 -35
  331. package/dist/src/{util-CMMkIxfU.js → util-Dub0f_ej.js} +693 -691
  332. package/dist/src/{util-CuLo2pMR.cjs → util-DvpHnLt0.cjs} +714 -719
  333. package/dist/src/{utils-DOjD4dTC.js → utils-BUMN8orw.js} +6 -4
  334. package/dist/src/{utils-DKw8mrgr.cjs → utils-DkVeShIB.cjs} +6 -4
  335. package/dist/src/{utils-DEuL4VNB.js → utils-kt7lv30R.js} +6 -4
  336. package/dist/src/{utils-CFxO9KGo.js → utils-o8S5huU2.js} +6 -4
  337. package/dist/src/version-0frU0UTr.js +16 -0
  338. package/dist/src/version-CbpiUINz.js +17 -0
  339. package/dist/src/version-CbuBKu2U.js +16 -0
  340. package/dist/src/version-D9zu9FWB.cjs +27 -0
  341. package/dist/tsconfig.tsbuildinfo +1 -1
  342. package/package.json +57 -46
  343. package/dist/src/app/assets/index-B6l9CVVb.js +0 -439
  344. package/dist/src/app/assets/index-DyZ0Ep37.css +0 -1
  345. package/dist/src/app/assets/scroll-timeline-BdJZVXlz.js +0 -1
  346. package/dist/src/app/assets/sync-CStkzc6u.js +0 -4
  347. package/dist/src/app/assets/vendor-charts-BnDWwBlI.js +0 -36
  348. package/dist/src/app/assets/vendor-markdown-Bz7N-ca6.js +0 -29
  349. package/dist/src/app/assets/vendor-react-AtKqiNEf.js +0 -4
  350. package/dist/src/app/assets/vendor-syntax-D06x6TQF.js +0 -2
  351. package/dist/src/app/assets/vendor-utils-BvMHZmO7.js +0 -37
  352. package/dist/src/cache-C5yFZ4gC.cjs +0 -816
  353. package/dist/src/cache-CaT5tPgo.js +0 -756
  354. package/dist/src/cache-CyCanoMu.js +0 -6
  355. package/dist/src/cache-DSqR6ezl.js +0 -726
  356. package/dist/src/cache-Df_QFDNu.cjs +0 -5
  357. package/dist/src/cache-HP0NP4k3.js +0 -756
  358. package/dist/src/cloud-DE3t1-ZI.js +0 -4
  359. package/dist/src/codex-sdk-BQEw16R_.js +0 -834
  360. package/dist/src/codex-sdk-C_07GuVS.js +0 -834
  361. package/dist/src/codex-sdk-DE5G18dx.js +0 -835
  362. package/dist/src/codex-sdk-ZLKfDjqP.cjs +0 -838
  363. package/dist/src/eval-7aEqoMs3.js +0 -15
  364. package/dist/src/evalResult-CYNHkk5A.js +0 -12
  365. package/dist/src/evalResult-CuvJeNiM.js +0 -10
  366. package/dist/src/evalResult-tGdilrWt.cjs +0 -10
  367. package/dist/src/evaluator-BBUqRhz1.js +0 -36
  368. package/dist/src/fetch-UWU706qb.js +0 -5
  369. package/dist/src/graders-BxfEguVY.js +0 -32
  370. package/dist/src/graders-CzVMbEnv.js +0 -34
  371. package/dist/src/graders-DjCXfj0l.cjs +0 -32
  372. package/dist/src/graders-kHzIWOKu.js +0 -32
  373. package/dist/src/messages-DJNo37Ko.js +0 -246
  374. package/dist/src/messages-Dy9QecMs.js +0 -245
  375. package/dist/src/messages-HJsyEh4o.cjs +0 -257
  376. package/dist/src/messages-biC_ex-p.js +0 -245
  377. package/dist/src/openclaw-0Sv7AK3O.js +0 -580
  378. package/dist/src/openclaw-CXxbKgDH.cjs +0 -586
  379. package/dist/src/openclaw-D1FSCps-.js +0 -580
  380. package/dist/src/openclaw-D2ENvu7a.js +0 -582
  381. package/dist/src/providers-BSLEaIQG.js +0 -32
  382. package/dist/src/providers-D-FnDg8k.cjs +0 -31
  383. package/dist/src/providers-DEYiFVAo.js +0 -30
  384. package/dist/src/providers-sS2WI8YD.js +0 -30
  385. package/dist/src/rubyUtils-B1HXG4ej.cjs +0 -4
  386. package/dist/src/rubyUtils-Rt6pKA96.js +0 -5
  387. package/dist/src/server-B0Xh1Gx-.js +0 -7
  388. package/dist/src/server-DJTKu9IR.cjs +0 -5
  389. package/dist/src/store-C5u6MgC8.js +0 -6
  390. package/dist/src/store-CNHk-De4.cjs +0 -5
  391. package/dist/src/telemetry-Yig0Tino.js +0 -7
  392. package/dist/src/telemetry-p8Pwqm1i.cjs +0 -5
  393. package/dist/src/transform-ChNIpHz7.js +0 -6
  394. package/dist/src/transform-PtQ6rAE3.cjs +0 -5
@@ -0,0 +1,1920 @@
1
+ const require_logger = require("./logger-COuQb2xB.cjs");
2
+ const require_version = require("./version-D9zu9FWB.cjs");
3
+ const require_genaiTracer = require("./genaiTracer-BokHC-MW.cjs");
4
+ const require_render = require("./render-tG6ir9_g.cjs");
5
+ const require_providerRegistry = require("./providerRegistry-BESeALrr.cjs");
6
+ let fs = require("fs");
7
+ fs = require_logger.__toESM(fs);
8
+ let path = require("path");
9
+ path = require_logger.__toESM(path);
10
+ let dedent = require("dedent");
11
+ dedent = require_logger.__toESM(dedent);
12
+ let zod = require("zod");
13
+ let crypto = require("crypto");
14
+ crypto = require_logger.__toESM(crypto);
15
+ let _opentelemetry_api = require("@opentelemetry/api");
16
+ let readline = require("readline");
17
+ readline = require_logger.__toESM(readline);
18
+ let child_process = require("child_process");
19
+ //#region src/providers/openai/codex-app-server.ts
20
+ const MAX_BUFFERED_JSON_RPC_CHARS = 5e6;
21
+ const DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
22
+ const DEFAULT_STARTUP_TIMEOUT_MS = 3e4;
23
+ const MINIMAL_CLI_ENV_KEYS = [
24
+ "PATH",
25
+ "Path",
26
+ "HOME",
27
+ "USER",
28
+ "USERNAME",
29
+ "USERPROFILE",
30
+ "TMPDIR",
31
+ "TMP",
32
+ "TEMP",
33
+ "SHELL",
34
+ "COMSPEC",
35
+ "SystemRoot",
36
+ "PATHEXT",
37
+ "LANG",
38
+ "LC_ALL",
39
+ "TERM"
40
+ ];
41
+ const COMMON_OPTIONAL_PROCESS_ENV_KEYS = [
42
+ "CODEX_HOME",
43
+ "HTTP_PROXY",
44
+ "HTTPS_PROXY",
45
+ "ALL_PROXY",
46
+ "NO_PROXY",
47
+ "SSL_CERT_FILE",
48
+ "SSL_CERT_DIR",
49
+ "REQUESTS_CA_BUNDLE",
50
+ "NODE_EXTRA_CA_CERTS",
51
+ "SSH_AUTH_SOCK",
52
+ "GIT_SSH_COMMAND"
53
+ ];
54
+ const CODEX_MODEL_PRICING = {
55
+ "gpt-5.4": {
56
+ input: 2.5,
57
+ output: 15,
58
+ cache_read: .25
59
+ },
60
+ "gpt-5.4-pro": {
61
+ input: 30,
62
+ output: 180,
63
+ cache_read: 30
64
+ },
65
+ "gpt-5.3-codex": {
66
+ input: 1.75,
67
+ output: 14,
68
+ cache_read: .175
69
+ },
70
+ "gpt-5.3-codex-spark": {
71
+ input: .5,
72
+ output: 4,
73
+ cache_read: .05
74
+ },
75
+ "gpt-5.2": {
76
+ input: 1.75,
77
+ output: 14,
78
+ cache_read: .175
79
+ },
80
+ "gpt-5.2-codex": {
81
+ input: 1.75,
82
+ output: 14,
83
+ cache_read: .175
84
+ },
85
+ "gpt-5.1-codex": {
86
+ input: 2,
87
+ output: 8,
88
+ cache_read: .2
89
+ },
90
+ "gpt-5.1-codex-max": {
91
+ input: 3,
92
+ output: 12,
93
+ cache_read: .3
94
+ },
95
+ "gpt-5.1-codex-mini": {
96
+ input: .5,
97
+ output: 2,
98
+ cache_read: .05
99
+ },
100
+ "gpt-5-codex": {
101
+ input: 2,
102
+ output: 8,
103
+ cache_read: .2
104
+ },
105
+ "gpt-5-codex-mini": {
106
+ input: .5,
107
+ output: 2,
108
+ cache_read: .05
109
+ },
110
+ "gpt-5": {
111
+ input: 2,
112
+ output: 8,
113
+ cache_read: .2
114
+ }
115
+ };
116
+ const CodexCliEnvValueSchema = zod.z.union([
117
+ zod.z.string(),
118
+ zod.z.number(),
119
+ zod.z.boolean()
120
+ ]).transform(String);
121
+ const CodexAppServerReasoningEffortSchema = zod.z.enum([
122
+ "none",
123
+ "minimal",
124
+ "low",
125
+ "medium",
126
+ "high",
127
+ "xhigh"
128
+ ]);
129
+ const CodexAppServerGranularApprovalPolicySchema = zod.z.object({ granular: zod.z.object({
130
+ sandbox_approval: zod.z.boolean(),
131
+ rules: zod.z.boolean(),
132
+ skill_approval: zod.z.boolean(),
133
+ request_permissions: zod.z.boolean(),
134
+ mcp_elicitations: zod.z.boolean()
135
+ }).strict() }).strict();
136
+ const CodexAppServerApprovalPolicySchema = zod.z.union([zod.z.enum([
137
+ "never",
138
+ "on-request",
139
+ "on-failure",
140
+ "untrusted"
141
+ ]), CodexAppServerGranularApprovalPolicySchema]);
142
+ const CommandExecutionApprovalDecisionSchema = zod.z.union([
143
+ zod.z.enum([
144
+ "accept",
145
+ "acceptForSession",
146
+ "decline",
147
+ "cancel"
148
+ ]),
149
+ zod.z.object({ acceptWithExecpolicyAmendment: zod.z.object({ execpolicy_amendment: zod.z.array(zod.z.string()) }).strict() }).strict(),
150
+ zod.z.object({ applyNetworkPolicyAmendment: zod.z.object({ network_policy_amendment: zod.z.object({
151
+ host: zod.z.string().min(1),
152
+ action: zod.z.enum(["allow", "deny"])
153
+ }).strict() }).strict() }).strict()
154
+ ]);
155
+ const McpElicitationPolicySchema = zod.z.union([zod.z.enum([
156
+ "accept",
157
+ "decline",
158
+ "cancel"
159
+ ]), zod.z.object({
160
+ action: zod.z.enum([
161
+ "accept",
162
+ "decline",
163
+ "cancel"
164
+ ]),
165
+ content: zod.z.unknown().optional(),
166
+ _meta: zod.z.unknown().optional()
167
+ }).strict()]);
168
+ const CollaborationModeSchema = zod.z.object({
169
+ mode: zod.z.enum(["plan", "default"]),
170
+ settings: zod.z.object({
171
+ model: zod.z.string().min(1),
172
+ reasoning_effort: CodexAppServerReasoningEffortSchema.nullable(),
173
+ developer_instructions: zod.z.string().nullable()
174
+ }).strict()
175
+ }).strict();
176
+ const ServerRequestPolicySchema = zod.z.object({
177
+ command_execution: CommandExecutionApprovalDecisionSchema.optional(),
178
+ file_change: zod.z.enum([
179
+ "accept",
180
+ "acceptForSession",
181
+ "decline",
182
+ "cancel"
183
+ ]).optional(),
184
+ permissions: zod.z.object({
185
+ permissions: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
186
+ scope: zod.z.enum(["turn", "session"]).optional()
187
+ }).optional(),
188
+ user_input: zod.z.union([zod.z.enum(["empty", "first-option"]), zod.z.record(zod.z.string(), zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]))]).optional(),
189
+ mcp_elicitation: McpElicitationPolicySchema.optional(),
190
+ dynamic_tools: zod.z.record(zod.z.string(), zod.z.object({
191
+ success: zod.z.boolean().optional(),
192
+ text: zod.z.string().optional(),
193
+ contentItems: zod.z.array(zod.z.union([zod.z.object({
194
+ type: zod.z.literal("inputText"),
195
+ text: zod.z.string()
196
+ }), zod.z.object({
197
+ type: zod.z.literal("inputImage"),
198
+ imageUrl: zod.z.string()
199
+ })])).optional()
200
+ })).optional()
201
+ }).strict();
202
+ const CodexAppServerConfigShape = {
203
+ basePath: zod.z.string().optional(),
204
+ prefix: zod.z.string().optional(),
205
+ suffix: zod.z.string().optional(),
206
+ provider: zod.z.unknown().optional(),
207
+ linkedTargetId: zod.z.string().optional(),
208
+ apiKey: zod.z.string().min(1).optional(),
209
+ base_url: zod.z.string().min(1).optional(),
210
+ working_dir: zod.z.string().min(1).optional(),
211
+ additional_directories: zod.z.array(zod.z.string().min(1)).optional(),
212
+ skip_git_repo_check: zod.z.boolean().optional(),
213
+ codex_path_override: zod.z.string().min(1).optional(),
214
+ model: zod.z.string().min(1).optional(),
215
+ model_provider: zod.z.string().min(1).optional(),
216
+ service_tier: zod.z.enum(["fast", "flex"]).optional(),
217
+ sandbox_mode: zod.z.enum([
218
+ "read-only",
219
+ "workspace-write",
220
+ "danger-full-access"
221
+ ]).optional(),
222
+ sandbox_policy: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
223
+ network_access_enabled: zod.z.boolean().optional(),
224
+ approval_policy: CodexAppServerApprovalPolicySchema.optional(),
225
+ approvals_reviewer: zod.z.enum(["user", "guardian_subagent"]).optional(),
226
+ model_reasoning_effort: CodexAppServerReasoningEffortSchema.optional(),
227
+ reasoning_summary: zod.z.enum([
228
+ "auto",
229
+ "concise",
230
+ "detailed",
231
+ "none"
232
+ ]).optional(),
233
+ personality: zod.z.enum([
234
+ "none",
235
+ "friendly",
236
+ "pragmatic"
237
+ ]).optional(),
238
+ base_instructions: zod.z.string().min(1).optional(),
239
+ developer_instructions: zod.z.string().min(1).optional(),
240
+ collaboration_mode: CollaborationModeSchema.optional(),
241
+ output_schema: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
242
+ thread_id: zod.z.string().min(1).optional(),
243
+ persist_threads: zod.z.boolean().optional(),
244
+ thread_pool_size: zod.z.number().int().positive().optional(),
245
+ thread_cleanup: zod.z.enum([
246
+ "unsubscribe",
247
+ "archive",
248
+ "none"
249
+ ]).optional(),
250
+ ephemeral: zod.z.boolean().optional(),
251
+ persist_extended_history: zod.z.boolean().optional(),
252
+ experimental_raw_events: zod.z.boolean().optional(),
253
+ experimental_api: zod.z.boolean().optional(),
254
+ include_raw_events: zod.z.boolean().optional(),
255
+ cli_config: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
256
+ cli_env: zod.z.record(zod.z.string(), CodexCliEnvValueSchema).optional(),
257
+ inherit_process_env: zod.z.boolean().optional(),
258
+ reuse_server: zod.z.boolean().optional(),
259
+ deep_tracing: zod.z.boolean().optional(),
260
+ request_timeout_ms: zod.z.number().int().positive().optional(),
261
+ startup_timeout_ms: zod.z.number().int().positive().optional(),
262
+ turn_timeout_ms: zod.z.number().int().positive().optional(),
263
+ server_request_policy: ServerRequestPolicySchema.optional()
264
+ };
265
+ const CodexAppServerConfigSchema = zod.z.object(CodexAppServerConfigShape).strict();
266
+ const CodexAppServerMergedPromptConfigSchema = zod.z.object(CodexAppServerConfigShape).strip();
267
+ function createDeferred() {
268
+ let resolve;
269
+ let reject;
270
+ return {
271
+ promise: new Promise((promiseResolve, promiseReject) => {
272
+ resolve = promiseResolve;
273
+ reject = promiseReject;
274
+ }),
275
+ resolve,
276
+ reject
277
+ };
278
+ }
279
+ function parseCodexAppServerConfig(config, options = {}) {
280
+ const schema = options.stripUnknownKeys ? CodexAppServerMergedPromptConfigSchema : CodexAppServerConfigSchema;
281
+ try {
282
+ return schema.parse(config ?? {});
283
+ } catch (error) {
284
+ if (error instanceof zod.z.ZodError) {
285
+ const issues = error.issues.map((issue) => {
286
+ return `${issue.path.length > 0 ? issue.path.join(".") : "(root)"}: ${issue.message}`;
287
+ }).join("; ");
288
+ throw new Error(`Invalid OpenAI Codex app-server config: ${issues}`);
289
+ }
290
+ throw error;
291
+ }
292
+ }
293
+ function mergeOptionalRecord(base, override) {
294
+ if (!base && !override) return;
295
+ return {
296
+ ...base ?? {},
297
+ ...override ?? {}
298
+ };
299
+ }
300
+ function mergeServerRequestPolicy(base, override) {
301
+ if (!base && !override) return;
302
+ const merged = {
303
+ ...base ?? {},
304
+ ...override ?? {}
305
+ };
306
+ const permissions = mergeOptionalRecord(base?.permissions, override?.permissions);
307
+ const dynamicTools = mergeOptionalRecord(base?.dynamic_tools, override?.dynamic_tools);
308
+ if (permissions) merged.permissions = permissions;
309
+ else delete merged.permissions;
310
+ if (dynamicTools) merged.dynamic_tools = dynamicTools;
311
+ else delete merged.dynamic_tools;
312
+ return merged;
313
+ }
314
+ function mergeCodexAppServerConfig(base, override) {
315
+ if (!override) return { ...base };
316
+ return {
317
+ ...base,
318
+ ...override,
319
+ cli_config: mergeOptionalRecord(base.cli_config, override.cli_config),
320
+ cli_env: mergeOptionalRecord(base.cli_env, override.cli_env),
321
+ server_request_policy: mergeServerRequestPolicy(base.server_request_policy, override.server_request_policy)
322
+ };
323
+ }
324
+ function getMinimalProcessEnv() {
325
+ const env = {};
326
+ for (const key of MINIMAL_CLI_ENV_KEYS) {
327
+ const value = process.env[key];
328
+ if (typeof value === "string" && value.length > 0) env[key] = value;
329
+ }
330
+ return env;
331
+ }
332
+ function isPlainObject(value) {
333
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
334
+ }
335
+ function flattenConfig(value, prefix = "") {
336
+ const entries = [];
337
+ for (const [key, entryValue] of Object.entries(value)) {
338
+ const nextKey = prefix ? `${prefix}.${key}` : key;
339
+ if (isPlainObject(entryValue)) entries.push(...flattenConfig(entryValue, nextKey));
340
+ else if (entryValue !== void 0) entries.push({
341
+ key: nextKey,
342
+ value: entryValue
343
+ });
344
+ }
345
+ return entries;
346
+ }
347
+ function toTomlLiteral(value) {
348
+ if (typeof value === "string") return JSON.stringify(value);
349
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
350
+ if (Array.isArray(value)) return `[${value.map((item) => toTomlLiteral(item)).join(", ")}]`;
351
+ if (value === null) return "\"\"";
352
+ return JSON.stringify(value);
353
+ }
354
+ function getJsonRpcErrorMessage(message) {
355
+ if (typeof message.error?.message === "string" && message.error.message) return message.error.message;
356
+ return "Unknown app-server error";
357
+ }
358
+ function createAbortError(message) {
359
+ const error = new Error(message);
360
+ error.name = "AbortError";
361
+ return error;
362
+ }
363
+ var CodexAppServerConnection = class {
364
+ instanceId;
365
+ process;
366
+ lineInterface;
367
+ nextRequestId = 1;
368
+ pending = /* @__PURE__ */ new Map();
369
+ closed = false;
370
+ stderrChunks = [];
371
+ stderrTotalLength = 0;
372
+ bufferedJsonRpcLines = [];
373
+ closePromise = null;
374
+ constructor(options) {
375
+ this.options = options;
376
+ this.instanceId = options.connectionInstanceId;
377
+ this.process = (0, child_process.spawn)(options.command, options.args, {
378
+ env: options.env,
379
+ stdio: [
380
+ "pipe",
381
+ "pipe",
382
+ "pipe"
383
+ ]
384
+ });
385
+ this.lineInterface = readline.default.createInterface({ input: this.process.stdout });
386
+ this.lineInterface.on("line", (line) => this.handleLine(line));
387
+ this.process.stderr.on("data", (chunk) => this.recordStderr(chunk));
388
+ this.process.stdin.on("error", (error) => {
389
+ require_logger.logger.debug("[CodexAppServer] stdin error", { error: error.message });
390
+ });
391
+ this.process.on("error", (error) => this.handleProcessFailure(error));
392
+ this.process.on("exit", (code, signal) => {
393
+ if (this.closed) this.rejectPending(/* @__PURE__ */ new Error("codex app-server process closed"));
394
+ else this.handleProcessFailure(/* @__PURE__ */ new Error(`codex app-server exited with code ${code ?? "null"} signal ${signal ?? "null"}`));
395
+ });
396
+ }
397
+ async initialize(config) {
398
+ await this.request("initialize", {
399
+ clientInfo: {
400
+ name: "promptfoo_codex_app_server",
401
+ title: "Promptfoo Codex App Server Provider",
402
+ version: require_version.VERSION
403
+ },
404
+ capabilities: { experimentalApi: config.experimental_api ?? true }
405
+ }, { timeoutMs: this.options.startupTimeoutMs });
406
+ this.notify("initialized", {});
407
+ }
408
+ request(method, params, options = {}) {
409
+ if (this.closed) return Promise.reject(/* @__PURE__ */ new Error("codex app-server connection is closed"));
410
+ if (options.abortSignal?.aborted) return Promise.reject(createAbortError(`codex app-server request aborted: ${method}`));
411
+ const id = this.nextRequestId++;
412
+ const message = {
413
+ method,
414
+ id
415
+ };
416
+ if (params !== void 0) message.params = params;
417
+ const timeoutMs = options.timeoutMs ?? this.options.requestTimeoutMs;
418
+ return new Promise((resolve, reject) => {
419
+ const pendingRequest = {
420
+ method,
421
+ resolve,
422
+ reject,
423
+ abortSignal: options.abortSignal,
424
+ onResponse: options.onResponse
425
+ };
426
+ pendingRequest.timeout = setTimeout(() => {
427
+ const error = /* @__PURE__ */ new Error(`codex app-server request timed out: ${method}`);
428
+ this.pending.delete(id);
429
+ if (options.abortSignal && pendingRequest.abortListener) options.abortSignal.removeEventListener("abort", pendingRequest.abortListener);
430
+ reject(error);
431
+ this.closeAfterRequestTimeout(method, error);
432
+ }, timeoutMs);
433
+ if (options.abortSignal) {
434
+ pendingRequest.abortListener = () => {
435
+ const error = createAbortError(`codex app-server request aborted: ${method}`);
436
+ this.pending.delete(id);
437
+ if (pendingRequest.timeout) clearTimeout(pendingRequest.timeout);
438
+ reject(error);
439
+ require_logger.logger.debug("[CodexAppServer] JSON-RPC request aborted", {
440
+ error: error.message,
441
+ method
442
+ });
443
+ };
444
+ options.abortSignal.addEventListener("abort", pendingRequest.abortListener, { once: true });
445
+ }
446
+ this.pending.set(id, pendingRequest);
447
+ this.send(message);
448
+ });
449
+ }
450
+ notify(method, params) {
451
+ const message = { method };
452
+ if (params !== void 0) message.params = params;
453
+ this.send(message);
454
+ }
455
+ getStderr() {
456
+ return this.stderrChunks.join("").slice(-1e4);
457
+ }
458
+ async close() {
459
+ if (this.closePromise !== null) return this.closePromise;
460
+ this.closePromise = new Promise((resolve) => {
461
+ this.closed = true;
462
+ this.rejectPending(/* @__PURE__ */ new Error("codex app-server connection closed"));
463
+ this.lineInterface.close();
464
+ const finish = () => resolve();
465
+ const killTimer = setTimeout(() => {
466
+ try {
467
+ if (!this.process.killed) this.process.kill("SIGKILL");
468
+ } catch {}
469
+ finish();
470
+ }, 1e3);
471
+ this.process.once("exit", () => {
472
+ clearTimeout(killTimer);
473
+ finish();
474
+ });
475
+ if (this.process.killed || this.process.exitCode !== null) {
476
+ clearTimeout(killTimer);
477
+ finish();
478
+ return;
479
+ }
480
+ try {
481
+ this.process.stdin.end();
482
+ this.process.kill("SIGTERM");
483
+ } catch {
484
+ clearTimeout(killTimer);
485
+ finish();
486
+ }
487
+ });
488
+ return this.closePromise;
489
+ }
490
+ handleLine(line) {
491
+ const trimmed = line.trim();
492
+ if (!trimmed && this.bufferedJsonRpcLines.length === 0) return;
493
+ const candidateLines = this.bufferedJsonRpcLines.length > 0 ? [...this.bufferedJsonRpcLines, line] : [trimmed];
494
+ const candidate = candidateLines.join("\\n");
495
+ let message;
496
+ try {
497
+ message = JSON.parse(candidate);
498
+ } catch (error) {
499
+ if (this.shouldBufferJsonRpcLine(error, trimmed)) {
500
+ this.bufferedJsonRpcLines = candidateLines;
501
+ if (candidate.length > MAX_BUFFERED_JSON_RPC_CHARS) {
502
+ require_logger.logger.warn("[CodexAppServer] Dropping oversized partial JSON-RPC message", {
503
+ error,
504
+ bufferedChars: candidate.length
505
+ });
506
+ this.bufferedJsonRpcLines = [];
507
+ }
508
+ return;
509
+ }
510
+ require_logger.logger.warn("[CodexAppServer] Failed to parse JSON-RPC line", {
511
+ error,
512
+ line: candidate
513
+ });
514
+ this.bufferedJsonRpcLines = [];
515
+ return;
516
+ }
517
+ this.bufferedJsonRpcLines = [];
518
+ this.handleMessage(message);
519
+ }
520
+ shouldBufferJsonRpcLine(error, trimmedLine) {
521
+ if (this.bufferedJsonRpcLines.length > 0) return true;
522
+ if (!trimmedLine.startsWith("{")) return false;
523
+ const message = error instanceof Error ? error.message : String(error);
524
+ return /Unterminated string|Unexpected end of JSON input|Bad control character/i.test(message);
525
+ }
526
+ handleMessage(message) {
527
+ if (message.id !== void 0 && (message.result !== void 0 || message.error !== void 0)) {
528
+ this.handleResponse(message);
529
+ return;
530
+ }
531
+ if (message.id !== void 0 && message.method) {
532
+ this.handleServerRequest(message);
533
+ return;
534
+ }
535
+ if (message.method) {
536
+ this.options.onNotification(message);
537
+ return;
538
+ }
539
+ require_logger.logger.debug("[CodexAppServer] Ignoring unknown JSON-RPC message shape", { message });
540
+ }
541
+ handleResponse(message) {
542
+ const pendingRequest = this.pending.get(message.id);
543
+ if (!pendingRequest) {
544
+ require_logger.logger.debug("[CodexAppServer] Received response for unknown request", { id: message.id });
545
+ return;
546
+ }
547
+ this.pending.delete(message.id);
548
+ if (pendingRequest.timeout) clearTimeout(pendingRequest.timeout);
549
+ if (pendingRequest.abortSignal && pendingRequest.abortListener) pendingRequest.abortSignal.removeEventListener("abort", pendingRequest.abortListener);
550
+ if (message.error) {
551
+ pendingRequest.reject(new Error(getJsonRpcErrorMessage(message)));
552
+ return;
553
+ }
554
+ try {
555
+ pendingRequest.onResponse?.(message.result);
556
+ } catch (error) {
557
+ pendingRequest.reject(error instanceof Error ? error : new Error(String(error)));
558
+ return;
559
+ }
560
+ pendingRequest.resolve(message.result);
561
+ }
562
+ async handleServerRequest(message) {
563
+ try {
564
+ const result = await this.options.onServerRequest(message);
565
+ this.send({
566
+ id: message.id,
567
+ result
568
+ });
569
+ } catch (error) {
570
+ const errorMessage = error instanceof Error ? error.message : String(error);
571
+ try {
572
+ this.send({
573
+ id: message.id,
574
+ error: {
575
+ code: -32e3,
576
+ message: errorMessage
577
+ }
578
+ });
579
+ } catch (sendError) {
580
+ require_logger.logger.debug("[CodexAppServer] Failed to send error response for server request", {
581
+ error: sendError,
582
+ originalError: errorMessage,
583
+ method: message.method
584
+ });
585
+ }
586
+ }
587
+ }
588
+ recordStderr(chunk) {
589
+ const text = chunk.toString("utf8");
590
+ this.stderrChunks.push(text);
591
+ this.stderrTotalLength += text.length;
592
+ if (this.stderrTotalLength > 2e4) {
593
+ const truncated = this.getStderr();
594
+ this.stderrChunks = [truncated];
595
+ this.stderrTotalLength = truncated.length;
596
+ }
597
+ require_logger.logger.debug("[CodexAppServer] stderr", { text });
598
+ }
599
+ handleProcessFailure(error) {
600
+ if (this.closed) return;
601
+ this.closed = true;
602
+ this.rejectPending(error);
603
+ require_logger.logger.error("[CodexAppServer] Process failure", {
604
+ error: error.message,
605
+ stderr: this.getStderr()
606
+ });
607
+ this.options.onClose(error);
608
+ }
609
+ closeAfterRequestTimeout(method, error) {
610
+ if (this.closed) return;
611
+ require_logger.logger.warn("[CodexAppServer] Closing app-server after JSON-RPC request timeout", {
612
+ error: error.message,
613
+ method
614
+ });
615
+ this.options.onClose(error);
616
+ this.close().catch((closeError) => {
617
+ require_logger.logger.debug("[CodexAppServer] Error closing app-server after request timeout", { error: closeError });
618
+ });
619
+ }
620
+ rejectPending(error) {
621
+ for (const [id, pendingRequest] of this.pending) {
622
+ if (pendingRequest.timeout) clearTimeout(pendingRequest.timeout);
623
+ if (pendingRequest.abortSignal && pendingRequest.abortListener) pendingRequest.abortSignal.removeEventListener("abort", pendingRequest.abortListener);
624
+ pendingRequest.reject(error);
625
+ this.pending.delete(id);
626
+ }
627
+ }
628
+ send(message) {
629
+ if (this.closed) throw new Error("codex app-server connection is closed");
630
+ this.process.stdin.write(`${JSON.stringify(message)}\n`);
631
+ }
632
+ };
633
+ var OpenAICodexAppServerProvider = class {
634
+ config;
635
+ env;
636
+ apiKey;
637
+ providerId = "openai:codex-app-server";
638
+ connections = /* @__PURE__ */ new Map();
639
+ connectionPromises = /* @__PURE__ */ new Map();
640
+ initializingConnections = /* @__PURE__ */ new Set();
641
+ threads = /* @__PURE__ */ new Map();
642
+ threadPromises = /* @__PURE__ */ new Map();
643
+ threadPromiseConnectionInstances = /* @__PURE__ */ new Map();
644
+ protectedThreadCounts = /* @__PURE__ */ new Map();
645
+ threadRunQueues = /* @__PURE__ */ new Map();
646
+ activeTurnsByThread = /* @__PURE__ */ new Map();
647
+ activeTurnsByTurn = /* @__PURE__ */ new Map();
648
+ validatedWorkingDirs = /* @__PURE__ */ new Set();
649
+ ignoredProviderEnvWarningShown = false;
650
+ omittedProcessEnvWarningShown = false;
651
+ deepTracingWarningShown = false;
652
+ constructor(options = {}) {
653
+ this.config = parseCodexAppServerConfig(options.config);
654
+ this.env = options.env;
655
+ this.apiKey = this.getApiKey();
656
+ this.providerId = options.id ?? this.providerId;
657
+ require_providerRegistry.providerRegistry.register(this);
658
+ }
659
+ id() {
660
+ return this.providerId;
661
+ }
662
+ getApiKey(config = this.config) {
663
+ return config.apiKey || this.env?.OPENAI_API_KEY || this.env?.CODEX_API_KEY || require_logger.getEnvString("OPENAI_API_KEY") || require_logger.getEnvString("CODEX_API_KEY");
664
+ }
665
+ requiresApiKey() {
666
+ return false;
667
+ }
668
+ toString() {
669
+ return "[OpenAI Codex App Server Provider]";
670
+ }
671
+ async cleanup() {
672
+ this.resolveActiveTurns(/* @__PURE__ */ new Error("codex app-server provider cleanup interrupted active turn"));
673
+ this.threads.clear();
674
+ this.threadPromises.clear();
675
+ this.threadPromiseConnectionInstances.clear();
676
+ this.threadRunQueues.clear();
677
+ this.activeTurnsByThread.clear();
678
+ this.activeTurnsByTurn.clear();
679
+ this.protectedThreadCounts.clear();
680
+ this.validatedWorkingDirs.clear();
681
+ const connections = Array.from(new Set([...this.connections.values(), ...this.initializingConnections]));
682
+ this.connections.clear();
683
+ this.connectionPromises.clear();
684
+ this.initializingConnections.clear();
685
+ await Promise.all(connections.map((connection) => connection.close().catch((error) => {
686
+ require_logger.logger.warn("[CodexAppServer] Error during cleanup", { error });
687
+ })));
688
+ }
689
+ async shutdown() {
690
+ try {
691
+ await this.cleanup();
692
+ } finally {
693
+ require_providerRegistry.providerRegistry.unregister(this);
694
+ }
695
+ }
696
+ async callApi(prompt, context, callOptions) {
697
+ const config = require_render.renderVarsInObject(mergeCodexAppServerConfig(this.config, context?.prompt?.config), context?.vars);
698
+ const requestedModel = typeof config.model === "string" && config.model ? config.model : void 0;
699
+ return require_genaiTracer.withGenAISpan(this.buildSpanContext(prompt, context, requestedModel), () => this.callApiInternal(prompt, context, callOptions, config), (response) => this.extractSpanResult(response, requestedModel));
700
+ }
701
+ buildSpanContext(prompt, context, requestedModel) {
702
+ return {
703
+ system: "openai",
704
+ operationName: "chat",
705
+ model: requestedModel ?? "codex-app-server",
706
+ providerId: this.id(),
707
+ evalId: context?.evaluationId || context?.test?.metadata?.evaluationId,
708
+ testIndex: typeof context?.test?.vars?.__testIdx === "number" ? context.test.vars.__testIdx : void 0,
709
+ promptLabel: context?.prompt?.label,
710
+ traceparent: context?.traceparent,
711
+ requestBody: prompt
712
+ };
713
+ }
714
+ extractSpanResult(response, requestedModel) {
715
+ const result = {};
716
+ if (response.tokenUsage) result.tokenUsage = response.tokenUsage;
717
+ if (response.sessionId) result.responseId = response.sessionId;
718
+ if (requestedModel) result.responseModel = requestedModel;
719
+ if (response.cached !== void 0) result.cacheHit = response.cached;
720
+ if (response.output !== void 0) result.responseBody = typeof response.output === "string" ? response.output : JSON.stringify(response.output);
721
+ if (response.metadata?.codexAppServer?.itemCounts) result.additionalAttributes = {
722
+ ...result.additionalAttributes,
723
+ "codex.app_server.items.breakdown": JSON.stringify(response.metadata.codexAppServer.itemCounts)
724
+ };
725
+ return result;
726
+ }
727
+ async callApiInternal(prompt, context, callOptions, rawConfig) {
728
+ let config;
729
+ try {
730
+ config = parseCodexAppServerConfig(rawConfig, { stripUnknownKeys: true });
731
+ } catch (error) {
732
+ const errorMessage = error instanceof Error ? error.message : String(error);
733
+ require_logger.logger.error("Error calling OpenAI Codex app-server", { error: errorMessage });
734
+ return { error: `Error calling OpenAI Codex app-server: ${errorMessage}` };
735
+ }
736
+ if (callOptions?.abortSignal?.aborted) return { error: "OpenAI Codex app-server call aborted before it started" };
737
+ const workingDirectory = this.resolveWorkingDirectory(config);
738
+ const resolvedConfig = {
739
+ approval_policy: "never",
740
+ sandbox_mode: "read-only",
741
+ network_access_enabled: false,
742
+ ephemeral: true,
743
+ thread_cleanup: "unsubscribe",
744
+ reuse_server: true,
745
+ ...config,
746
+ working_dir: workingDirectory,
747
+ additional_directories: this.resolveAdditionalDirectories(config)
748
+ };
749
+ const currentTraceparent = require_genaiTracer.getTraceparent();
750
+ const apiKey = this.getApiKey(resolvedConfig);
751
+ const env = this.prepareEnvironment(resolvedConfig, currentTraceparent, apiKey);
752
+ const promptInput = this.parsePromptInput(prompt);
753
+ const connectionKey = this.generateConnectionKey(env, resolvedConfig);
754
+ const useReusableConnection = resolvedConfig.reuse_server !== false && !resolvedConfig.deep_tracing;
755
+ let localConnection;
756
+ try {
757
+ this.validateWorkingDirectory(resolvedConfig.working_dir, resolvedConfig.skip_git_repo_check);
758
+ this.warnOnceForDeepTracingThreadOptions(resolvedConfig);
759
+ const connection = useReusableConnection ? await this.getOrCreateConnection(connectionKey, env, resolvedConfig) : await this.createConnection(connectionKey, env, resolvedConfig);
760
+ if (!useReusableConnection) localConnection = connection;
761
+ const promptCacheBasis = context?.prompt?.raw ?? prompt;
762
+ const threadHandle = await this.getOrCreateThread(connection, connectionKey, promptCacheBasis, resolvedConfig, useReusableConnection, callOptions);
763
+ this.protectThread(threadHandle.threadId);
764
+ let turnStarted = false;
765
+ try {
766
+ const queueKey = this.getThreadRunQueueKey(resolvedConfig, threadHandle);
767
+ return await this.runSerializedThreadTurn(queueKey, callOptions?.abortSignal, async () => {
768
+ turnStarted = true;
769
+ const state = this.createTurnState(connectionKey, connection.instanceId, threadHandle.threadId, promptInput, resolvedConfig, env);
770
+ this.registerTurnState(state);
771
+ try {
772
+ const turnResponse = await connection.request("turn/start", this.buildTurnStartParams(threadHandle.threadId, promptInput, resolvedConfig), {
773
+ abortSignal: callOptions?.abortSignal,
774
+ timeoutMs: this.getRequestTimeoutMs(resolvedConfig),
775
+ onResponse: (response) => {
776
+ const turnId = response?.turn?.id;
777
+ if (typeof turnId === "string") this.updateTurnStateId(state, turnId);
778
+ }
779
+ });
780
+ if (typeof turnResponse?.turn?.id === "string") this.updateTurnStateId(state, turnResponse.turn.id);
781
+ await this.waitForTurnCompletion(connection, state, resolvedConfig, callOptions);
782
+ return this.buildProviderResponse(state, threadHandle, resolvedConfig);
783
+ } finally {
784
+ this.unregisterTurnState(state);
785
+ await this.cleanupThreadAfterTurn(connection, threadHandle, resolvedConfig);
786
+ }
787
+ });
788
+ } finally {
789
+ this.unprotectThread(threadHandle.threadId);
790
+ if (!turnStarted) await this.cleanupThreadAfterTurn(connection, threadHandle, resolvedConfig, { skipIfActiveTurn: true });
791
+ this.scheduleThreadPoolEnforcement(connection, connectionKey, resolvedConfig);
792
+ }
793
+ } catch (error) {
794
+ if (error instanceof Error && error.name === "AbortError" || callOptions?.abortSignal?.aborted) {
795
+ require_logger.logger.warn("OpenAI Codex app-server call aborted");
796
+ return { error: "OpenAI Codex app-server call aborted" };
797
+ }
798
+ const errorMessage = error instanceof Error ? error.message : String(error);
799
+ require_logger.logger.error("Error calling OpenAI Codex app-server", { error: errorMessage });
800
+ return { error: `Error calling OpenAI Codex app-server: ${errorMessage}` };
801
+ } finally {
802
+ if (localConnection) await localConnection.close().catch((error) => {
803
+ require_logger.logger.debug("[CodexAppServer] Error closing local connection", { error });
804
+ });
805
+ }
806
+ }
807
+ resolveWorkingDirectory(config) {
808
+ const basePath = config.basePath || require_logger.state.basePath || process.cwd();
809
+ if (!config.working_dir) return process.cwd();
810
+ return path.default.resolve(basePath, config.working_dir);
811
+ }
812
+ resolveAdditionalDirectories(config) {
813
+ if (!config.additional_directories?.length) return;
814
+ const basePath = config.basePath || require_logger.state.basePath || process.cwd();
815
+ return config.additional_directories.map((directory) => path.default.resolve(basePath, directory));
816
+ }
817
+ prepareEnvironment(config, traceparent, apiKey = this.getApiKey(config)) {
818
+ const inheritProcessEnv = config.inherit_process_env === true;
819
+ const cliEnv = Object.fromEntries(Object.entries(config.cli_env ?? {}).map(([key, value]) => [key, String(value)]));
820
+ const env = {
821
+ ...inheritProcessEnv ? process.env : getMinimalProcessEnv(),
822
+ ...cliEnv
823
+ };
824
+ const ignoredProviderEnvKeys = Object.keys(this.env ?? {}).filter((key) => key !== "OPENAI_API_KEY" && key !== "CODEX_API_KEY" && !(key in (config.cli_env ?? {}))).sort();
825
+ if (ignoredProviderEnvKeys.length > 0 && !this.ignoredProviderEnvWarningShown) {
826
+ require_logger.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 });
827
+ this.ignoredProviderEnvWarningShown = true;
828
+ }
829
+ if (!inheritProcessEnv && !this.omittedProcessEnvWarningShown) {
830
+ const omittedProcessEnvKeys = this.getOmittedOptionalProcessEnvKeys(config, env);
831
+ if (omittedProcessEnvKeys.length > 0) {
832
+ require_logger.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 });
833
+ this.omittedProcessEnvWarningShown = true;
834
+ }
835
+ }
836
+ const sortedEnv = {};
837
+ for (const key of Object.keys(env).sort()) if (env[key] !== void 0) sortedEnv[key] = env[key];
838
+ if (apiKey) {
839
+ sortedEnv.OPENAI_API_KEY = apiKey;
840
+ sortedEnv.CODEX_API_KEY = apiKey;
841
+ }
842
+ if (config.base_url) {
843
+ sortedEnv.OPENAI_BASE_URL = config.base_url;
844
+ sortedEnv.OPENAI_API_BASE_URL = config.base_url;
845
+ }
846
+ if (config.deep_tracing) {
847
+ if (!sortedEnv.OTEL_EXPORTER_OTLP_ENDPOINT) sortedEnv.OTEL_EXPORTER_OTLP_ENDPOINT = "http://127.0.0.1:4318";
848
+ if (!sortedEnv.OTEL_EXPORTER_OTLP_PROTOCOL) sortedEnv.OTEL_EXPORTER_OTLP_PROTOCOL = "http/json";
849
+ if (!sortedEnv.OTEL_SERVICE_NAME) sortedEnv.OTEL_SERVICE_NAME = "codex-app-server";
850
+ if (!sortedEnv.OTEL_TRACES_EXPORTER) sortedEnv.OTEL_TRACES_EXPORTER = "otlp";
851
+ if (traceparent) sortedEnv.TRACEPARENT = traceparent;
852
+ } else delete sortedEnv.TRACEPARENT;
853
+ return sortedEnv;
854
+ }
855
+ getOmittedOptionalProcessEnvKeys(config, env) {
856
+ const shouldWarnForSshEnv = config.network_access_enabled === true;
857
+ 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"));
858
+ }
859
+ buildAppServerArgs(config) {
860
+ const args = [
861
+ "app-server",
862
+ "--listen",
863
+ "stdio://"
864
+ ];
865
+ const cliConfig = this.getResolvedCliConfig(config);
866
+ for (const { key, value } of flattenConfig(cliConfig)) args.push("-c", `${key}=${toTomlLiteral(value)}`);
867
+ return args;
868
+ }
869
+ getResolvedCliConfig(config) {
870
+ return { ...config.cli_config ?? {} };
871
+ }
872
+ getRequestTimeoutMs(config) {
873
+ return config.request_timeout_ms ?? DEFAULT_REQUEST_TIMEOUT_MS;
874
+ }
875
+ async getOrCreateConnection(connectionKey, env, config) {
876
+ const existing = this.connections.get(connectionKey);
877
+ if (existing) return existing;
878
+ const pending = this.connectionPromises.get(connectionKey);
879
+ if (pending) return pending;
880
+ let connectionPromise;
881
+ connectionPromise = this.createConnection(connectionKey, env, config).then((connection) => {
882
+ if (this.connectionPromises.get(connectionKey) !== connectionPromise) {
883
+ connection.close().catch((error) => {
884
+ require_logger.logger.debug("[CodexAppServer] Error closing stale initialized connection", { error });
885
+ });
886
+ throw new Error("codex app-server connection was closed during cleanup");
887
+ }
888
+ this.connections.set(connectionKey, connection);
889
+ return connection;
890
+ }).finally(() => {
891
+ this.connectionPromises.delete(connectionKey);
892
+ });
893
+ this.connectionPromises.set(connectionKey, connectionPromise);
894
+ return connectionPromise;
895
+ }
896
+ async createConnection(connectionKey, env, config) {
897
+ const connectionInstanceId = `${connectionKey}:${crypto.default.randomUUID()}`;
898
+ const connection = new CodexAppServerConnection({
899
+ connectionInstanceId,
900
+ command: config.codex_path_override ?? "codex",
901
+ args: this.buildAppServerArgs(config),
902
+ env,
903
+ requestTimeoutMs: this.getRequestTimeoutMs(config),
904
+ startupTimeoutMs: config.startup_timeout_ms ?? DEFAULT_STARTUP_TIMEOUT_MS,
905
+ onNotification: (message) => this.handleNotification(message),
906
+ onServerRequest: (message) => this.handleServerRequest(message, config),
907
+ onClose: (error) => this.handleConnectionClose(connectionKey, connectionInstanceId, error)
908
+ });
909
+ this.initializingConnections.add(connection);
910
+ try {
911
+ await connection.initialize(config);
912
+ return connection;
913
+ } catch (error) {
914
+ await connection.close().catch((closeError) => {
915
+ require_logger.logger.debug("[CodexAppServer] Error closing app-server after failed initialization", { error: closeError });
916
+ });
917
+ throw error;
918
+ } finally {
919
+ this.initializingConnections.delete(connection);
920
+ }
921
+ }
922
+ handleConnectionClose(connectionKey, connectionInstanceId, error) {
923
+ require_logger.logger.warn("[CodexAppServer] Connection closed", {
924
+ connectionKey,
925
+ error: error.message
926
+ });
927
+ if (this.connections.get(connectionKey)?.instanceId === connectionInstanceId) {
928
+ this.connections.delete(connectionKey);
929
+ this.connectionPromises.delete(connectionKey);
930
+ for (const [threadCacheKey, handle] of this.threads) if (handle.connectionKey === connectionKey) this.threads.delete(threadCacheKey);
931
+ for (const [threadCacheKey] of this.threadPromises) if (this.threadPromiseConnectionInstances.get(threadCacheKey) === connectionInstanceId) {
932
+ this.threadPromises.delete(threadCacheKey);
933
+ this.threadPromiseConnectionInstances.delete(threadCacheKey);
934
+ }
935
+ }
936
+ this.resolveActiveTurns(error, (state) => state.connectionInstanceId === connectionInstanceId);
937
+ }
938
+ resolveActiveTurns(error, predicate = () => true) {
939
+ for (const state of new Set(this.activeTurnsByThread.values())) {
940
+ if (!predicate(state)) continue;
941
+ state.error = error.message;
942
+ state.completed.resolve();
943
+ }
944
+ }
945
+ generateConnectionKey(env, config) {
946
+ const stableEnv = { ...env };
947
+ delete stableEnv.TRACEPARENT;
948
+ const keyData = {
949
+ env: stableEnv,
950
+ codex_path_override: config.codex_path_override,
951
+ cli_config: this.getResolvedCliConfig(config),
952
+ experimental_api: config.experimental_api
953
+ };
954
+ return `openai:codex-app-server:connection:${crypto.default.createHash("sha256").update(JSON.stringify(keyData)).digest("hex")}`;
955
+ }
956
+ generateThreadCacheKey(connectionKey, promptCacheBasis, config) {
957
+ const keyData = {
958
+ connectionKey,
959
+ prompt: promptCacheBasis,
960
+ working_dir: config.working_dir,
961
+ additional_directories: config.additional_directories,
962
+ model: config.model,
963
+ model_provider: config.model_provider,
964
+ service_tier: config.service_tier,
965
+ sandbox_mode: config.sandbox_mode,
966
+ sandbox_policy: config.sandbox_policy,
967
+ network_access_enabled: config.network_access_enabled,
968
+ approval_policy: config.approval_policy,
969
+ approvals_reviewer: config.approvals_reviewer,
970
+ model_reasoning_effort: config.model_reasoning_effort,
971
+ reasoning_summary: config.reasoning_summary,
972
+ personality: config.personality,
973
+ base_instructions: config.base_instructions,
974
+ developer_instructions: config.developer_instructions,
975
+ collaboration_mode: config.collaboration_mode,
976
+ output_schema: config.output_schema,
977
+ base_url: config.base_url,
978
+ ephemeral: config.ephemeral,
979
+ experimental_raw_events: config.experimental_raw_events,
980
+ persist_extended_history: config.persist_extended_history
981
+ };
982
+ return `openai:codex-app-server:thread:${crypto.default.createHash("sha256").update(JSON.stringify(keyData)).digest("hex")}`;
983
+ }
984
+ async getOrCreateThread(connection, connectionKey, promptCacheBasis, config, allowThreadPersistence, callOptions) {
985
+ const canPersistThread = allowThreadPersistence && config.persist_threads === true;
986
+ if (config.thread_id) {
987
+ const cacheKey = canPersistThread ? `${connectionKey}:thread_id:${config.thread_id}` : void 0;
988
+ const cachedOrPending = this.getCachedOrPendingThread(cacheKey);
989
+ if (cachedOrPending !== void 0) return this.waitForThreadHandle(cachedOrPending, callOptions?.abortSignal);
990
+ this.throwIfThreadWaitAborted(callOptions?.abortSignal);
991
+ const threadPromise = this.cacheThreadPromise(cacheKey, connection.instanceId, async () => {
992
+ const response = await connection.request("thread/resume", this.buildThreadResumeParams(config.thread_id, config), { timeoutMs: this.getRequestTimeoutMs(config) });
993
+ const handle = {
994
+ connectionKey,
995
+ threadId: response?.thread?.id ?? config.thread_id,
996
+ response,
997
+ cacheKey,
998
+ persistent: canPersistThread
999
+ };
1000
+ if (cacheKey) this.threads.set(cacheKey, handle);
1001
+ return handle;
1002
+ });
1003
+ return cacheKey ? this.waitForThreadHandle(threadPromise, callOptions?.abortSignal) : this.waitForThreadHandle(threadPromise, callOptions?.abortSignal, { onAbortResolvedThread: (threadHandle) => this.cleanupThreadAfterTurn(connection, threadHandle, config, { skipIfProtected: true }) });
1004
+ }
1005
+ const cacheKey = canPersistThread ? this.generateThreadCacheKey(connectionKey, promptCacheBasis, config) : void 0;
1006
+ const cachedOrPending = this.getCachedOrPendingThread(cacheKey);
1007
+ if (cachedOrPending !== void 0) return this.waitForThreadHandle(cachedOrPending, callOptions?.abortSignal);
1008
+ this.throwIfThreadWaitAborted(callOptions?.abortSignal);
1009
+ const threadPromise = this.cacheThreadPromise(cacheKey, connection.instanceId, async () => {
1010
+ const poolSize = config.thread_pool_size ?? 1;
1011
+ if (cacheKey && this.threads.size >= poolSize) await this.evictOldestInactiveCachedThread(connection, connectionKey, this.getRequestTimeoutMs(config));
1012
+ const response = await connection.request("thread/start", this.buildThreadStartParams(config), { timeoutMs: this.getRequestTimeoutMs(config) });
1013
+ const threadId = response?.thread?.id;
1014
+ if (typeof threadId !== "string" || !threadId) throw new Error("codex app-server did not return a thread id");
1015
+ const handle = {
1016
+ connectionKey,
1017
+ threadId,
1018
+ response,
1019
+ cacheKey,
1020
+ persistent: canPersistThread
1021
+ };
1022
+ if (cacheKey) this.threads.set(cacheKey, handle);
1023
+ return handle;
1024
+ });
1025
+ return cacheKey ? this.waitForThreadHandle(threadPromise, callOptions?.abortSignal) : this.waitForThreadHandle(threadPromise, callOptions?.abortSignal, { onAbortResolvedThread: (threadHandle) => this.cleanupThreadAfterTurn(connection, threadHandle, config, { skipIfProtected: true }) });
1026
+ }
1027
+ getCachedOrPendingThread(cacheKey) {
1028
+ if (!cacheKey) return;
1029
+ return this.threads.get(cacheKey) ?? this.threadPromises.get(cacheKey);
1030
+ }
1031
+ cacheThreadPromise(cacheKey, connectionInstanceId, createThread) {
1032
+ if (!cacheKey) return createThread();
1033
+ let threadPromise;
1034
+ threadPromise = createThread().finally(() => {
1035
+ if (this.threadPromises.get(cacheKey) === threadPromise) {
1036
+ this.threadPromises.delete(cacheKey);
1037
+ this.threadPromiseConnectionInstances.delete(cacheKey);
1038
+ }
1039
+ });
1040
+ this.threadPromises.set(cacheKey, threadPromise);
1041
+ this.threadPromiseConnectionInstances.set(cacheKey, connectionInstanceId);
1042
+ return threadPromise;
1043
+ }
1044
+ throwIfThreadWaitAborted(abortSignal) {
1045
+ if (abortSignal?.aborted) throw createAbortError("Codex app-server thread wait aborted");
1046
+ }
1047
+ async waitForThreadHandle(thread, abortSignal, options = {}) {
1048
+ const threadPromise = Promise.resolve(thread);
1049
+ if (!abortSignal) return threadPromise;
1050
+ let abortCleanupScheduled = false;
1051
+ const scheduleAbortCleanup = () => {
1052
+ if (abortCleanupScheduled) return;
1053
+ abortCleanupScheduled = true;
1054
+ threadPromise.then(async (threadHandle) => {
1055
+ if (options.onAbortResolvedThread) await options.onAbortResolvedThread(threadHandle);
1056
+ }).catch((error) => {
1057
+ require_logger.logger.debug("[CodexAppServer] Thread request finished with error after abort", { error });
1058
+ });
1059
+ };
1060
+ const createThreadAbortError = () => createAbortError(options.abortMessage ?? "Codex app-server thread wait aborted");
1061
+ if (abortSignal.aborted) {
1062
+ scheduleAbortCleanup();
1063
+ throw createThreadAbortError();
1064
+ }
1065
+ let abortListener;
1066
+ const abortPromise = new Promise((_, reject) => {
1067
+ abortListener = () => {
1068
+ scheduleAbortCleanup();
1069
+ reject(createThreadAbortError());
1070
+ };
1071
+ abortSignal.addEventListener("abort", abortListener, { once: true });
1072
+ });
1073
+ try {
1074
+ return await Promise.race([threadPromise, abortPromise]);
1075
+ } finally {
1076
+ if (abortListener) abortSignal.removeEventListener("abort", abortListener);
1077
+ }
1078
+ }
1079
+ scheduleThreadPoolEnforcement(fallbackConnection, fallbackConnectionKey, config) {
1080
+ if (!config.persist_threads || config.thread_id) return;
1081
+ this.enforceThreadPoolLimit(fallbackConnection, fallbackConnectionKey, config).catch((error) => {
1082
+ require_logger.logger.debug("[CodexAppServer] Error enforcing thread pool limit", { error });
1083
+ });
1084
+ }
1085
+ async enforceThreadPoolLimit(fallbackConnection, fallbackConnectionKey, config) {
1086
+ const poolSize = config.thread_pool_size ?? 1;
1087
+ while (this.threads.size > poolSize) if (!await this.evictOldestInactiveCachedThread(fallbackConnection, fallbackConnectionKey, this.getRequestTimeoutMs(config))) return;
1088
+ }
1089
+ async evictOldestInactiveCachedThread(fallbackConnection, fallbackConnectionKey, timeoutMs) {
1090
+ for (const [cacheKey, handle] of this.threads) {
1091
+ if (this.isThreadProtected(handle.threadId)) continue;
1092
+ await this.evictCachedThread(fallbackConnection, fallbackConnectionKey, cacheKey, timeoutMs);
1093
+ return true;
1094
+ }
1095
+ require_logger.logger.debug("[CodexAppServer] Thread pool is full, but all cached threads are active");
1096
+ return false;
1097
+ }
1098
+ async evictCachedThread(fallbackConnection, fallbackConnectionKey, cacheKey, timeoutMs) {
1099
+ const evicted = this.threads.get(cacheKey);
1100
+ this.threads.delete(cacheKey);
1101
+ if (!evicted) return;
1102
+ const connection = this.connections.get(evicted.connectionKey) ?? (evicted.connectionKey === fallbackConnectionKey ? fallbackConnection : void 0);
1103
+ if (!connection) {
1104
+ require_logger.logger.debug("[CodexAppServer] Evicted cached thread without an active connection", { threadId: evicted.threadId });
1105
+ return;
1106
+ }
1107
+ try {
1108
+ await connection.request("thread/unsubscribe", { threadId: evicted.threadId }, { timeoutMs });
1109
+ } catch (error) {
1110
+ require_logger.logger.warn("[CodexAppServer] Failed to unsubscribe evicted cached thread", {
1111
+ error,
1112
+ threadId: evicted.threadId
1113
+ });
1114
+ }
1115
+ }
1116
+ buildThreadStartParams(config) {
1117
+ return {
1118
+ ...config.model ? { model: config.model } : {},
1119
+ ...config.model_provider ? { modelProvider: config.model_provider } : {},
1120
+ ...config.service_tier ? { serviceTier: config.service_tier } : {},
1121
+ ...config.working_dir ? { cwd: config.working_dir } : {},
1122
+ approvalPolicy: config.approval_policy ?? "never",
1123
+ ...config.approvals_reviewer ? { approvalsReviewer: config.approvals_reviewer } : {},
1124
+ sandbox: config.sandbox_mode ?? "read-only",
1125
+ ...Object.keys(config.cli_config ?? {}).length > 0 ? { config: config.cli_config } : {},
1126
+ serviceName: "promptfoo",
1127
+ ...config.base_instructions ? { baseInstructions: config.base_instructions } : {},
1128
+ ...config.developer_instructions ? { developerInstructions: config.developer_instructions } : {},
1129
+ ...config.personality ? { personality: config.personality } : {},
1130
+ ...config.base_url ? { config: {
1131
+ ...config.cli_config ?? {},
1132
+ base_url: config.base_url
1133
+ } } : {},
1134
+ ephemeral: config.ephemeral ?? true,
1135
+ experimentalRawEvents: config.experimental_raw_events ?? false,
1136
+ persistExtendedHistory: config.persist_extended_history ?? false
1137
+ };
1138
+ }
1139
+ buildThreadResumeParams(threadId, config) {
1140
+ return {
1141
+ threadId,
1142
+ ...config.model ? { model: config.model } : {},
1143
+ ...config.model_provider ? { modelProvider: config.model_provider } : {},
1144
+ ...config.service_tier ? { serviceTier: config.service_tier } : {},
1145
+ ...config.working_dir ? { cwd: config.working_dir } : {},
1146
+ approvalPolicy: config.approval_policy ?? "never",
1147
+ ...config.approvals_reviewer ? { approvalsReviewer: config.approvals_reviewer } : {},
1148
+ sandbox: config.sandbox_mode ?? "read-only",
1149
+ ...Object.keys(config.cli_config ?? {}).length > 0 ? { config: config.cli_config } : {},
1150
+ ...config.base_instructions ? { baseInstructions: config.base_instructions } : {},
1151
+ ...config.developer_instructions ? { developerInstructions: config.developer_instructions } : {},
1152
+ ...config.personality ? { personality: config.personality } : {},
1153
+ persistExtendedHistory: config.persist_extended_history ?? false
1154
+ };
1155
+ }
1156
+ buildTurnStartParams(threadId, input, config) {
1157
+ return {
1158
+ threadId,
1159
+ input,
1160
+ ...config.working_dir ? { cwd: config.working_dir } : {},
1161
+ approvalPolicy: config.approval_policy ?? "never",
1162
+ ...config.approvals_reviewer ? { approvalsReviewer: config.approvals_reviewer } : {},
1163
+ ...config.sandbox_policy || config.network_access_enabled !== void 0 ? { sandboxPolicy: this.buildSandboxPolicy(config) } : {},
1164
+ ...config.model ? { model: config.model } : {},
1165
+ ...config.service_tier ? { serviceTier: config.service_tier } : {},
1166
+ ...config.model_reasoning_effort ? { effort: config.model_reasoning_effort } : {},
1167
+ ...config.reasoning_summary ? { summary: config.reasoning_summary } : {},
1168
+ ...config.personality ? { personality: config.personality } : {},
1169
+ ...config.collaboration_mode ? { collaborationMode: config.collaboration_mode } : {},
1170
+ ...config.output_schema ? { outputSchema: config.output_schema } : {}
1171
+ };
1172
+ }
1173
+ buildSandboxPolicy(config) {
1174
+ if (config.sandbox_policy) return config.sandbox_policy;
1175
+ const networkAccess = config.network_access_enabled === true;
1176
+ switch (config.sandbox_mode ?? "read-only") {
1177
+ case "danger-full-access": return { type: "dangerFullAccess" };
1178
+ case "workspace-write": return {
1179
+ type: "workspaceWrite",
1180
+ writableRoots: [config.working_dir, ...config.additional_directories ?? []].filter(Boolean),
1181
+ readOnlyAccess: { type: "fullAccess" },
1182
+ networkAccess,
1183
+ excludeTmpdirEnvVar: false,
1184
+ excludeSlashTmp: false
1185
+ };
1186
+ default: return {
1187
+ type: "readOnly",
1188
+ access: { type: "fullAccess" },
1189
+ networkAccess
1190
+ };
1191
+ }
1192
+ }
1193
+ parsePromptInput(prompt) {
1194
+ let parsedPrompt;
1195
+ try {
1196
+ parsedPrompt = JSON.parse(prompt);
1197
+ } catch {
1198
+ return [{
1199
+ type: "text",
1200
+ text: prompt,
1201
+ text_elements: []
1202
+ }];
1203
+ }
1204
+ if (!Array.isArray(parsedPrompt) || parsedPrompt.length === 0) return [{
1205
+ type: "text",
1206
+ text: prompt,
1207
+ text_elements: []
1208
+ }];
1209
+ const input = [];
1210
+ for (const item of parsedPrompt) {
1211
+ if (!this.isPromptInputItem(item)) return [{
1212
+ type: "text",
1213
+ text: prompt,
1214
+ text_elements: []
1215
+ }];
1216
+ input.push(this.normalizePromptInputItem(item));
1217
+ }
1218
+ return input;
1219
+ }
1220
+ isPromptInputItem(item) {
1221
+ if (!item || typeof item !== "object" || Array.isArray(item)) return false;
1222
+ if ("type" in item && item.type === "text") return "text" in item && typeof item.text === "string";
1223
+ if ("type" in item && item.type === "image") return "url" in item && typeof item.url === "string";
1224
+ if ("type" in item && (item.type === "local_image" || item.type === "localImage")) return "path" in item && typeof item.path === "string";
1225
+ 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";
1226
+ return false;
1227
+ }
1228
+ normalizePromptInputItem(item) {
1229
+ switch (item.type) {
1230
+ case "text": return {
1231
+ type: "text",
1232
+ text: item.text,
1233
+ text_elements: []
1234
+ };
1235
+ case "image": return {
1236
+ type: "image",
1237
+ url: item.url
1238
+ };
1239
+ case "local_image":
1240
+ case "localImage": return {
1241
+ type: "localImage",
1242
+ path: item.path
1243
+ };
1244
+ case "skill": return {
1245
+ type: "skill",
1246
+ name: item.name,
1247
+ path: item.path
1248
+ };
1249
+ case "mention": return {
1250
+ type: "mention",
1251
+ name: item.name,
1252
+ path: item.path
1253
+ };
1254
+ }
1255
+ }
1256
+ formatPromptInputForTrace(input) {
1257
+ return input.map((item) => {
1258
+ switch (item.type) {
1259
+ case "text": return item.text;
1260
+ case "image": return `[image: ${item.url}]`;
1261
+ case "localImage": return `[local_image: ${item.path}]`;
1262
+ case "skill": return `[skill: ${item.name} ${item.path}]`;
1263
+ case "mention": return `[mention: ${item.name} ${item.path}]`;
1264
+ }
1265
+ }).join("\n");
1266
+ }
1267
+ createTurnState(connectionKey, connectionInstanceId, threadId, promptInput, config, appServerEnv) {
1268
+ return {
1269
+ connectionKey,
1270
+ connectionInstanceId,
1271
+ threadId,
1272
+ config,
1273
+ appServerEnv,
1274
+ promptInput,
1275
+ items: [],
1276
+ itemStarts: [],
1277
+ notifications: [],
1278
+ notificationCount: 0,
1279
+ serverRequests: [],
1280
+ agentMessageDeltas: [],
1281
+ agentMessageDeltasByItemId: /* @__PURE__ */ new Map(),
1282
+ completed: createDeferred(),
1283
+ activeSpans: /* @__PURE__ */ new Map(),
1284
+ itemStartTimes: /* @__PURE__ */ new Map(),
1285
+ lastEventTime: Date.now()
1286
+ };
1287
+ }
1288
+ registerTurnState(state) {
1289
+ this.activeTurnsByThread.set(state.threadId, state);
1290
+ if (state.turnId) this.activeTurnsByTurn.set(state.turnId, state);
1291
+ }
1292
+ updateTurnStateId(state, turnId) {
1293
+ if (state.turnId && state.turnId !== turnId) this.activeTurnsByTurn.delete(state.turnId);
1294
+ state.turnId = turnId;
1295
+ this.activeTurnsByTurn.set(turnId, state);
1296
+ }
1297
+ unregisterTurnState(state) {
1298
+ this.activeTurnsByThread.delete(state.threadId);
1299
+ if (state.turnId) this.activeTurnsByTurn.delete(state.turnId);
1300
+ this.endUnclosedItemSpans(state);
1301
+ }
1302
+ protectThread(threadId) {
1303
+ this.protectedThreadCounts.set(threadId, (this.protectedThreadCounts.get(threadId) ?? 0) + 1);
1304
+ }
1305
+ unprotectThread(threadId) {
1306
+ const count = this.protectedThreadCounts.get(threadId);
1307
+ if (!count || count <= 1) {
1308
+ this.protectedThreadCounts.delete(threadId);
1309
+ return;
1310
+ }
1311
+ this.protectedThreadCounts.set(threadId, count - 1);
1312
+ }
1313
+ isThreadProtected(threadId) {
1314
+ return this.activeTurnsByThread.has(threadId) || (this.protectedThreadCounts.get(threadId) ?? 0) > 0;
1315
+ }
1316
+ getTurnState(threadId, turnId) {
1317
+ if (turnId) return this.activeTurnsByTurn.get(turnId);
1318
+ if (threadId) return this.activeTurnsByThread.get(threadId);
1319
+ }
1320
+ handleNotification(message) {
1321
+ const params = message.params ?? {};
1322
+ const state = this.getTurnState(params.threadId, params.turnId);
1323
+ if (!state) {
1324
+ require_logger.logger.debug("[CodexAppServer] Notification without active turn", { method: message.method });
1325
+ return;
1326
+ }
1327
+ state.notificationCount += 1;
1328
+ if (state.config.include_raw_events) state.notifications.push(message);
1329
+ const eventTime = Date.now();
1330
+ switch (message.method) {
1331
+ case "turn/started":
1332
+ if (typeof params.turn?.id === "string") this.updateTurnStateId(state, params.turn.id);
1333
+ break;
1334
+ case "item/started":
1335
+ this.handleItemStarted(state, params.item, eventTime);
1336
+ break;
1337
+ case "item/completed":
1338
+ this.handleItemCompleted(state, params.item, eventTime);
1339
+ break;
1340
+ case "item/agentMessage/delta":
1341
+ this.handleAgentMessageDelta(state, params);
1342
+ break;
1343
+ case "thread/tokenUsage/updated":
1344
+ state.rawTokenUsage = params.tokenUsage;
1345
+ state.tokenUsage = this.buildTokenUsage(params.tokenUsage);
1346
+ break;
1347
+ case "turn/completed":
1348
+ state.turn = params.turn;
1349
+ if (params.turn?.status === "failed") state.error = params.turn?.error?.message ?? "Codex app-server turn failed";
1350
+ state.completed.resolve();
1351
+ break;
1352
+ case "error":
1353
+ if (params.willRetry === true) {
1354
+ require_logger.logger.debug("[CodexAppServer] Retryable error received", {
1355
+ error: params.error?.message,
1356
+ threadId: params.threadId,
1357
+ turnId: params.turnId
1358
+ });
1359
+ break;
1360
+ }
1361
+ state.error = params.error?.message ?? "Codex app-server error";
1362
+ state.completed.resolve();
1363
+ break;
1364
+ }
1365
+ state.lastEventTime = eventTime;
1366
+ }
1367
+ handleItemStarted(state, item, eventTime) {
1368
+ if (!item) return;
1369
+ state.itemStarts.push(item);
1370
+ if (!item.id) return;
1371
+ const itemId = String(item.id);
1372
+ const span = this.startItemSpan(item, itemId);
1373
+ state.activeSpans.set(itemId, span);
1374
+ state.itemStartTimes.set(itemId, eventTime);
1375
+ }
1376
+ handleItemCompleted(state, item, eventTime) {
1377
+ if (!item) return;
1378
+ state.items.push(item);
1379
+ const itemId = item.id ? String(item.id) : crypto.default.randomUUID();
1380
+ const span = state.activeSpans.get(itemId) ?? this.startItemSpan(item, itemId, state.lastEventTime);
1381
+ const startTime = state.itemStartTimes.get(itemId) ?? state.lastEventTime;
1382
+ this.applyItemCompletionAttributes(span, item, eventTime, startTime);
1383
+ span.end();
1384
+ state.activeSpans.delete(itemId);
1385
+ state.itemStartTimes.delete(itemId);
1386
+ }
1387
+ handleAgentMessageDelta(state, params) {
1388
+ if (typeof params.delta !== "string") return;
1389
+ state.agentMessageDeltas.push(params.delta);
1390
+ if (typeof params.itemId === "string") {
1391
+ const existing = state.agentMessageDeltasByItemId.get(params.itemId) ?? "";
1392
+ state.agentMessageDeltasByItemId.set(params.itemId, existing + params.delta);
1393
+ }
1394
+ }
1395
+ async handleServerRequest(message, config) {
1396
+ const params = message.params ?? {};
1397
+ const state = this.getTurnState(params.threadId ?? params.conversationId, params.turnId);
1398
+ const record = {
1399
+ id: message.id,
1400
+ method: message.method ?? "unknown",
1401
+ params: this.sanitizeForMetadata(params)
1402
+ };
1403
+ try {
1404
+ const response = this.buildServerRequestResponse(message, state?.config ?? config);
1405
+ record.response = this.sanitizeForMetadata(response);
1406
+ state?.serverRequests.push(record);
1407
+ return response;
1408
+ } catch (error) {
1409
+ record.error = error instanceof Error ? error.message : String(error);
1410
+ state?.serverRequests.push(record);
1411
+ throw error;
1412
+ }
1413
+ }
1414
+ buildServerRequestResponse(message, config) {
1415
+ const policy = config.server_request_policy ?? {};
1416
+ switch (message.method) {
1417
+ case "item/commandExecution/requestApproval": return { decision: policy.command_execution ?? "decline" };
1418
+ case "execCommandApproval": return this.buildLegacyApprovalResponse(policy.command_execution);
1419
+ case "item/fileChange/requestApproval": return { decision: policy.file_change ?? "decline" };
1420
+ case "applyPatchApproval": return this.buildLegacyApprovalResponse(policy.file_change);
1421
+ case "item/permissions/requestApproval": return {
1422
+ permissions: policy.permissions?.permissions ?? {},
1423
+ scope: policy.permissions?.scope ?? "turn"
1424
+ };
1425
+ case "item/tool/requestUserInput": return this.buildUserInputResponse(message.params, policy.user_input ?? "empty");
1426
+ case "mcpServer/elicitation/request": return this.buildMcpElicitationResponse(policy.mcp_elicitation);
1427
+ case "item/tool/call": return this.buildDynamicToolResponse(message.params, policy.dynamic_tools);
1428
+ case "account/chatgptAuthTokens/refresh": throw new Error("ChatGPT auth token refresh requests are not supported by promptfoo");
1429
+ default: throw new Error(`Unsupported codex app-server request: ${message.method ?? "unknown"}`);
1430
+ }
1431
+ }
1432
+ buildLegacyApprovalResponse(decision = "decline") {
1433
+ if (typeof decision !== "string") return { decision: "denied" };
1434
+ switch (decision) {
1435
+ case "accept": return { decision: "approved" };
1436
+ case "acceptForSession": return { decision: "approved_for_session" };
1437
+ case "cancel": return { decision: "abort" };
1438
+ case "decline": return { decision: "denied" };
1439
+ }
1440
+ }
1441
+ buildMcpElicitationResponse(policy = "decline") {
1442
+ if (typeof policy === "string") return {
1443
+ action: policy,
1444
+ content: null,
1445
+ _meta: null
1446
+ };
1447
+ return {
1448
+ action: policy.action,
1449
+ content: policy.content ?? null,
1450
+ _meta: policy._meta ?? null
1451
+ };
1452
+ }
1453
+ buildUserInputResponse(params, policy) {
1454
+ const answers = {};
1455
+ const questions = Array.isArray(params?.questions) ? params.questions : [];
1456
+ for (const question of questions) {
1457
+ if (!question?.id || typeof question.id !== "string") continue;
1458
+ if (policy === "empty") {
1459
+ answers[question.id] = { answers: [] };
1460
+ continue;
1461
+ }
1462
+ if (policy === "first-option") {
1463
+ const firstLabel = Array.isArray(question.options) && typeof question.options[0]?.label === "string" ? question.options[0].label : "";
1464
+ answers[question.id] = { answers: firstLabel ? [firstLabel] : [] };
1465
+ continue;
1466
+ }
1467
+ const configuredAnswer = policy[question.id];
1468
+ answers[question.id] = { answers: Array.isArray(configuredAnswer) ? configuredAnswer : configuredAnswer ? [configuredAnswer] : [] };
1469
+ }
1470
+ return { answers };
1471
+ }
1472
+ buildDynamicToolResponse(params, tools) {
1473
+ const configured = typeof params?.tool === "string" ? tools?.[params.tool] : void 0;
1474
+ if (!configured) return {
1475
+ contentItems: [{
1476
+ type: "inputText",
1477
+ text: "No dynamic tool response configured."
1478
+ }],
1479
+ success: false
1480
+ };
1481
+ return {
1482
+ contentItems: configured.contentItems ?? [{
1483
+ type: "inputText",
1484
+ text: configured.text ?? ""
1485
+ }],
1486
+ success: configured.success ?? true
1487
+ };
1488
+ }
1489
+ async waitForTurnCompletion(connection, state, config, callOptions) {
1490
+ const interruptTurn = () => {
1491
+ if (!state.turnId) return;
1492
+ connection.request("turn/interrupt", {
1493
+ threadId: state.threadId,
1494
+ turnId: state.turnId
1495
+ }, { timeoutMs: 5e3 }).catch((error) => {
1496
+ require_logger.logger.debug("[CodexAppServer] Error interrupting turn", { error });
1497
+ });
1498
+ };
1499
+ let timeout;
1500
+ let abortListener;
1501
+ const timeoutPromise = config.turn_timeout_ms ? new Promise((_, reject) => {
1502
+ timeout = setTimeout(() => {
1503
+ interruptTurn();
1504
+ reject(/* @__PURE__ */ new Error(`codex app-server turn timed out after ${config.turn_timeout_ms}ms`));
1505
+ }, config.turn_timeout_ms);
1506
+ }) : void 0;
1507
+ const abortPromise = callOptions?.abortSignal ? new Promise((_, reject) => {
1508
+ abortListener = () => {
1509
+ interruptTurn();
1510
+ reject(createAbortError("OpenAI Codex app-server call aborted"));
1511
+ };
1512
+ callOptions.abortSignal?.addEventListener("abort", abortListener, { once: true });
1513
+ }) : void 0;
1514
+ try {
1515
+ await Promise.race([
1516
+ state.completed.promise,
1517
+ timeoutPromise,
1518
+ abortPromise
1519
+ ].filter((promise) => Boolean(promise)));
1520
+ } finally {
1521
+ if (timeout) clearTimeout(timeout);
1522
+ if (abortListener && callOptions?.abortSignal) callOptions.abortSignal.removeEventListener("abort", abortListener);
1523
+ }
1524
+ if (state.error) throw new Error(state.error);
1525
+ }
1526
+ async cleanupThreadAfterTurn(connection, threadHandle, config, options = {}) {
1527
+ if (threadHandle.persistent || config.thread_cleanup === "none") return;
1528
+ if (options.skipIfProtected && this.isThreadProtected(threadHandle.threadId)) return;
1529
+ if (options.skipIfActiveTurn && this.activeTurnsByThread.has(threadHandle.threadId)) return;
1530
+ if (config.thread_id && (this.protectedThreadCounts.get(threadHandle.threadId) ?? 0) > 1) return;
1531
+ if (config.thread_id && config.thread_cleanup === "archive") return;
1532
+ try {
1533
+ if (config.thread_cleanup === "archive") await connection.request("thread/archive", { threadId: threadHandle.threadId }, { timeoutMs: this.getRequestTimeoutMs(config) });
1534
+ else await connection.request("thread/unsubscribe", { threadId: threadHandle.threadId }, { timeoutMs: this.getRequestTimeoutMs(config) });
1535
+ } catch (error) {
1536
+ require_logger.logger.warn("[CodexAppServer] Error cleaning up thread after turn", {
1537
+ threadId: threadHandle.threadId,
1538
+ error
1539
+ });
1540
+ }
1541
+ }
1542
+ getThreadRunQueueKey(config, threadHandle) {
1543
+ if (config.thread_id) return `thread_id:${threadHandle.threadId}`;
1544
+ if (config.deep_tracing) return;
1545
+ if (threadHandle.persistent && threadHandle.cacheKey) return threadHandle.cacheKey;
1546
+ }
1547
+ async runSerializedThreadTurn(queueKey, abortSignal, executeTurn) {
1548
+ if (!queueKey) return executeTurn();
1549
+ const previousRun = this.threadRunQueues.get(queueKey) ?? Promise.resolve();
1550
+ let releaseCurrentRun = () => {};
1551
+ const currentRun = new Promise((resolve) => {
1552
+ releaseCurrentRun = resolve;
1553
+ });
1554
+ const queuedRun = previousRun.catch(() => void 0).then(() => currentRun);
1555
+ this.threadRunQueues.set(queueKey, queuedRun);
1556
+ queuedRun.finally(() => {
1557
+ if (this.threadRunQueues.get(queueKey) === queuedRun) this.threadRunQueues.delete(queueKey);
1558
+ });
1559
+ try {
1560
+ await this.waitForPreviousThreadRun(previousRun, abortSignal);
1561
+ return await executeTurn();
1562
+ } finally {
1563
+ releaseCurrentRun();
1564
+ }
1565
+ }
1566
+ async waitForPreviousThreadRun(previousRun, abortSignal) {
1567
+ const previousRunDone = previousRun.catch(() => void 0);
1568
+ if (!abortSignal) {
1569
+ await previousRunDone;
1570
+ return;
1571
+ }
1572
+ if (abortSignal.aborted) throw createAbortError("Codex app-server thread turn wait aborted");
1573
+ let onAbort;
1574
+ const abortPromise = new Promise((_, reject) => {
1575
+ onAbort = () => reject(createAbortError("Codex app-server thread turn wait aborted"));
1576
+ abortSignal.addEventListener("abort", onAbort, { once: true });
1577
+ });
1578
+ try {
1579
+ await Promise.race([previousRunDone, abortPromise]);
1580
+ } finally {
1581
+ if (onAbort) abortSignal.removeEventListener("abort", onAbort);
1582
+ }
1583
+ }
1584
+ buildProviderResponse(state, threadHandle, config) {
1585
+ const output = this.getFinalOutput(state);
1586
+ const normalizedItems = state.items.map((item) => this.normalizeItemForMetadata(item));
1587
+ const raw = {
1588
+ output,
1589
+ thread: this.sanitizeForMetadata(threadHandle.response?.thread),
1590
+ turn: this.sanitizeForMetadata(state.turn),
1591
+ items: normalizedItems,
1592
+ tokenUsage: this.sanitizeForMetadata(state.rawTokenUsage),
1593
+ serverRequests: state.serverRequests,
1594
+ ...config.include_raw_events ? { notifications: this.sanitizeForMetadata(state.notifications) } : {}
1595
+ };
1596
+ const metadata = this.buildResponseMetadata(state, threadHandle, config, normalizedItems);
1597
+ return {
1598
+ output,
1599
+ tokenUsage: state.tokenUsage,
1600
+ cost: this.calculateResponseCost(state.tokenUsage, config.model),
1601
+ metadata,
1602
+ raw: JSON.stringify(raw),
1603
+ sessionId: threadHandle.threadId
1604
+ };
1605
+ }
1606
+ getFinalOutput(state) {
1607
+ const completedAgentMessages = state.items.filter((item) => item?.type === "agentMessage" && typeof item.text === "string").map((item) => item.text);
1608
+ if (completedAgentMessages.length > 0) return completedAgentMessages[completedAgentMessages.length - 1];
1609
+ const deltaMessages = Array.from(state.agentMessageDeltasByItemId.values()).filter(Boolean);
1610
+ if (deltaMessages.length > 0) return deltaMessages[deltaMessages.length - 1];
1611
+ return state.agentMessageDeltas.join("");
1612
+ }
1613
+ buildResponseMetadata(state, threadHandle, config, normalizedItems) {
1614
+ const skillMetadata = this.buildSkillMetadata(state.items, this.getSkillRootPrefixes(config, state.appServerEnv));
1615
+ return {
1616
+ codexAppServer: {
1617
+ threadId: threadHandle.threadId,
1618
+ turnId: state.turnId,
1619
+ model: config.model,
1620
+ modelProvider: config.model_provider,
1621
+ cwd: config.working_dir,
1622
+ sandboxMode: config.sandbox_mode ?? "read-only",
1623
+ approvalPolicy: config.approval_policy ?? "never",
1624
+ itemCounts: this.getItemCounts(state.items),
1625
+ items: normalizedItems,
1626
+ serverRequests: state.serverRequests,
1627
+ notificationCount: state.notificationCount
1628
+ },
1629
+ ...skillMetadata?.skillCalls.length ? { skillCalls: skillMetadata.skillCalls } : {},
1630
+ ...skillMetadata && skillMetadata.attemptedSkillCalls.length > skillMetadata.skillCalls.length ? { attemptedSkillCalls: skillMetadata.attemptedSkillCalls } : {}
1631
+ };
1632
+ }
1633
+ normalizeItemForMetadata(item) {
1634
+ const base = {
1635
+ id: item?.id,
1636
+ type: item?.type,
1637
+ status: item?.status
1638
+ };
1639
+ switch (item?.type) {
1640
+ case "commandExecution": return this.sanitizeForMetadata({
1641
+ ...base,
1642
+ command: item.command,
1643
+ cwd: item.cwd,
1644
+ exitCode: item.exitCode,
1645
+ durationMs: item.durationMs,
1646
+ aggregatedOutput: item.aggregatedOutput
1647
+ });
1648
+ case "fileChange": return this.sanitizeForMetadata({
1649
+ ...base,
1650
+ changes: item.changes
1651
+ });
1652
+ case "mcpToolCall": return this.sanitizeForMetadata({
1653
+ ...base,
1654
+ server: item.server,
1655
+ tool: item.tool,
1656
+ arguments: item.arguments,
1657
+ result: item.result,
1658
+ error: item.error,
1659
+ durationMs: item.durationMs
1660
+ });
1661
+ case "dynamicToolCall": return this.sanitizeForMetadata({
1662
+ ...base,
1663
+ tool: item.tool,
1664
+ arguments: item.arguments,
1665
+ success: item.success,
1666
+ contentItems: item.contentItems,
1667
+ durationMs: item.durationMs
1668
+ });
1669
+ case "webSearch": return this.sanitizeForMetadata({
1670
+ ...base,
1671
+ query: item.query,
1672
+ action: item.action
1673
+ });
1674
+ case "agentMessage": return this.sanitizeForMetadata({
1675
+ ...base,
1676
+ text: item.text
1677
+ });
1678
+ case "reasoning": return this.sanitizeForMetadata({
1679
+ ...base,
1680
+ summary: item.summary,
1681
+ content: item.content
1682
+ });
1683
+ default: return this.sanitizeForMetadata(base);
1684
+ }
1685
+ }
1686
+ buildTokenUsage(rawTokenUsage) {
1687
+ const usage = rawTokenUsage?.last ?? rawTokenUsage?.total ?? rawTokenUsage;
1688
+ if (!usage) return;
1689
+ const prompt = usage.inputTokens ?? usage.input_tokens;
1690
+ const completion = usage.outputTokens ?? usage.output_tokens;
1691
+ const cached = usage.cachedInputTokens ?? usage.cached_input_tokens ?? 0;
1692
+ if (typeof prompt !== "number" || typeof completion !== "number") return;
1693
+ return {
1694
+ prompt,
1695
+ completion,
1696
+ total: prompt + completion,
1697
+ cached
1698
+ };
1699
+ }
1700
+ calculateResponseCost(tokenUsage, model) {
1701
+ if (!tokenUsage || !model) return 0;
1702
+ const pricing = CODEX_MODEL_PRICING[model];
1703
+ if (!pricing) return 0;
1704
+ const cachedTokens = tokenUsage.cached || 0;
1705
+ return ((tokenUsage.prompt || 0) - cachedTokens) * (pricing.input / 1e6) + cachedTokens * (pricing.cache_read / 1e6) + (tokenUsage.completion || 0) * (pricing.output / 1e6);
1706
+ }
1707
+ getItemCounts(items) {
1708
+ const counts = {};
1709
+ for (const item of items) {
1710
+ const type = typeof item?.type === "string" ? item.type : "unknown";
1711
+ counts[type] = (counts[type] ?? 0) + 1;
1712
+ }
1713
+ return counts;
1714
+ }
1715
+ validateWorkingDirectory(workingDir, skipGitCheck = false) {
1716
+ const cacheKey = `${workingDir}:${skipGitCheck}`;
1717
+ if (this.validatedWorkingDirs.has(cacheKey)) return;
1718
+ let stats;
1719
+ try {
1720
+ stats = fs.default.statSync(workingDir);
1721
+ } catch (err) {
1722
+ throw new Error(`Working directory ${workingDir} does not exist or isn't accessible: ${err.message}`);
1723
+ }
1724
+ if (!stats.isDirectory()) throw new Error(`Working directory ${workingDir} is not a directory`);
1725
+ if (!skipGitCheck && !this.isInsideGitRepository(workingDir)) throw new Error(dedent.default`Working directory ${workingDir} is not inside a Git repository.
1726
+
1727
+ Codex app-server requires a Git repository by default to prevent unrecoverable errors.
1728
+
1729
+ To bypass this check, set skip_git_repo_check: true in your provider config.`);
1730
+ this.validatedWorkingDirs.add(cacheKey);
1731
+ }
1732
+ isInsideGitRepository(workingDir) {
1733
+ return this.findGitRepositoryRoot(workingDir) !== void 0;
1734
+ }
1735
+ findGitRepositoryRoot(workingDir) {
1736
+ let currentDir = path.default.resolve(workingDir);
1737
+ while (true) {
1738
+ if (fs.default.existsSync(path.default.join(currentDir, ".git"))) return currentDir;
1739
+ const parentDir = path.default.dirname(currentDir);
1740
+ if (parentDir === currentDir) return;
1741
+ currentDir = parentDir;
1742
+ }
1743
+ }
1744
+ warnOnceForDeepTracingThreadOptions(config) {
1745
+ if (!config.deep_tracing || this.deepTracingWarningShown || !config.persist_threads && (config.thread_pool_size ?? 0) <= 1) return;
1746
+ require_logger.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.");
1747
+ this.deepTracingWarningShown = true;
1748
+ }
1749
+ startItemSpan(item, itemId, startTime) {
1750
+ return _opentelemetry_api.trace.getTracer("promptfoo.codex-app-server").startSpan(this.getSpanNameForItem(item), {
1751
+ kind: _opentelemetry_api.SpanKind.INTERNAL,
1752
+ ...startTime === void 0 ? {} : { startTime },
1753
+ attributes: {
1754
+ "codex.app_server.item.id": itemId,
1755
+ "codex.app_server.item.type": item?.type ?? "unknown",
1756
+ ...this.getAttributesForItem(item)
1757
+ }
1758
+ });
1759
+ }
1760
+ applyItemCompletionAttributes(span, item, eventTime, startTime) {
1761
+ for (const [key, value] of Object.entries(this.getCompletionAttributesForItem(item))) span.setAttribute(key, value);
1762
+ span.setAttribute("codex.app_server.duration_ms", eventTime - startTime);
1763
+ if (this.isItemError(item)) span.setStatus({
1764
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
1765
+ message: this.getItemErrorMessage(item)
1766
+ });
1767
+ else span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
1768
+ }
1769
+ endUnclosedItemSpans(state) {
1770
+ for (const [itemId, span] of state.activeSpans) {
1771
+ require_logger.logger.warn("[CodexAppServer] Item span not properly closed", { itemId });
1772
+ span.setStatus({
1773
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
1774
+ message: "Span not properly closed"
1775
+ });
1776
+ span.end();
1777
+ }
1778
+ state.activeSpans.clear();
1779
+ state.itemStartTimes.clear();
1780
+ }
1781
+ getSpanNameForItem(item) {
1782
+ switch (item?.type) {
1783
+ case "commandExecution": return `exec ${typeof item.command === "string" ? item.command.split(" ")[0] || "command" : "command"}`;
1784
+ case "fileChange": return "file change";
1785
+ case "mcpToolCall": return `mcp ${item.server ?? "unknown"}/${item.tool ?? "unknown"}`;
1786
+ case "dynamicToolCall": return `tool ${item.tool ?? "unknown"}`;
1787
+ case "agentMessage": return "agent response";
1788
+ case "reasoning": return "reasoning";
1789
+ case "webSearch": return "web search";
1790
+ default: return `codex.app_server.${item?.type ?? "unknown"}`;
1791
+ }
1792
+ }
1793
+ getAttributesForItem(item) {
1794
+ const attrs = {};
1795
+ if (item?.type === "commandExecution" && typeof item.command === "string") attrs["codex.command"] = this.sanitizeTraceText(item.command, "Codex app-server command trace attribute") ?? "";
1796
+ if (item?.type === "mcpToolCall") {
1797
+ if (typeof item.server === "string") attrs["codex.mcp.server"] = item.server;
1798
+ if (typeof item.tool === "string") attrs["codex.mcp.tool"] = item.tool;
1799
+ }
1800
+ if (item?.type === "dynamicToolCall" && typeof item.tool === "string") attrs["codex.tool.name"] = item.tool;
1801
+ if (item?.type === "webSearch" && typeof item.query === "string") attrs["codex.search.query"] = this.sanitizeTraceText(item.query, "Codex app-server web search trace attribute") ?? "";
1802
+ return attrs;
1803
+ }
1804
+ getCompletionAttributesForItem(item) {
1805
+ const attrs = {};
1806
+ if (typeof item?.status === "string") attrs["codex.status"] = item.status;
1807
+ if (item?.type === "commandExecution") {
1808
+ if (typeof item.exitCode === "number") attrs["codex.exit_code"] = item.exitCode;
1809
+ if (typeof item.aggregatedOutput === "string") attrs["codex.output"] = this.sanitizeTraceText(item.aggregatedOutput, "Codex app-server command output trace attribute") ?? "";
1810
+ }
1811
+ if (item?.type === "agentMessage" && typeof item.text === "string") attrs["codex.message"] = this.sanitizeTraceText(item.text, "Codex app-server message trace attribute") ?? "";
1812
+ return attrs;
1813
+ }
1814
+ isItemError(item) {
1815
+ return item?.status === "failed" || item?.status === "declined" || item?.error !== void 0 || item?.type === "commandExecution" && typeof item.exitCode === "number" && item.exitCode !== 0;
1816
+ }
1817
+ getItemErrorMessage(item) {
1818
+ 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";
1819
+ }
1820
+ getSkillRootPrefixes(config, appServerEnv) {
1821
+ const prefixes = /* @__PURE__ */ new Set();
1822
+ const addPrefix = (candidate) => {
1823
+ if (!candidate) return;
1824
+ const normalized = candidate.replace(/\\/g, "/").replace(/\/+$/g, "");
1825
+ if (normalized) prefixes.add(normalized);
1826
+ };
1827
+ addPrefix(appServerEnv.CODEX_HOME);
1828
+ addPrefix("/etc/codex");
1829
+ if (config.working_dir) {
1830
+ const resolvedWorkingDir = path.default.resolve(config.working_dir).replace(/\\/g, "/");
1831
+ addPrefix(path.default.posix.join(resolvedWorkingDir, ".agents"));
1832
+ const gitRoot = this.findGitRepositoryRoot(resolvedWorkingDir);
1833
+ if (gitRoot) addPrefix(path.default.posix.join(gitRoot.replace(/\\/g, "/"), ".agents"));
1834
+ }
1835
+ const homeDir = appServerEnv.HOME || appServerEnv.USERPROFILE;
1836
+ if (homeDir) addPrefix(path.default.posix.join(homeDir.replace(/\\/g, "/"), ".codex"));
1837
+ return Array.from(prefixes);
1838
+ }
1839
+ buildSkillMetadata(items, skillRootPrefixes) {
1840
+ if (!Array.isArray(items) || items.length === 0) return;
1841
+ const attemptedSkillCalls = this.extractSkillCallsFromItems(items, skillRootPrefixes);
1842
+ const skillCalls = this.extractSkillCallsFromItems(items, skillRootPrefixes, { requireSuccessfulCommand: true });
1843
+ if (skillCalls.length === 0 && attemptedSkillCalls.length <= skillCalls.length) return;
1844
+ return {
1845
+ attemptedSkillCalls,
1846
+ skillCalls
1847
+ };
1848
+ }
1849
+ extractSkillCallsFromItems(items, skillRootPrefixes, options = {}) {
1850
+ const skillCalls = /* @__PURE__ */ new Map();
1851
+ for (const item of items) {
1852
+ if (item?.type !== "commandExecution") continue;
1853
+ if (options.requireSuccessfulCommand && !this.isSuccessfulCommandExecution(item)) continue;
1854
+ if (typeof item.command !== "string" || !item.command.trim()) continue;
1855
+ for (const skillPath of this.extractSkillPathCandidates(item.command, skillRootPrefixes)) skillCalls.set(skillPath.path, skillPath);
1856
+ }
1857
+ return Array.from(skillCalls.values()).map((skillCall) => ({
1858
+ name: skillCall.name,
1859
+ path: skillCall.path,
1860
+ source: "heuristic"
1861
+ }));
1862
+ }
1863
+ isSuccessfulCommandExecution(item) {
1864
+ if (item?.type !== "commandExecution") return false;
1865
+ if (typeof item.status === "string" && item.status !== "completed") return false;
1866
+ if (typeof item.exitCode === "number" && item.exitCode !== 0) return false;
1867
+ return true;
1868
+ }
1869
+ extractSkillPathCandidates(text, skillRootPrefixes = []) {
1870
+ const matches = /* @__PURE__ */ new Map();
1871
+ for (const rawToken of text.split(/\s+/)) {
1872
+ const token = rawToken.replace(/^[`"'([{<]+|[`"',;:)\]}>]+$/g, "").trim();
1873
+ if (!token) continue;
1874
+ const normalizedPath = token.replace(/\\/g, "/");
1875
+ const repoMatch = normalizedPath.match(/^\.agents\/skills\/([^/\s]+)\/SKILL\.md$/);
1876
+ if (repoMatch && this.isValidSkillName(repoMatch[1])) {
1877
+ matches.set(normalizedPath, {
1878
+ name: repoMatch[1],
1879
+ path: normalizedPath
1880
+ });
1881
+ continue;
1882
+ }
1883
+ const matchingRoot = skillRootPrefixes.find((prefix) => normalizedPath.startsWith(`${prefix}/skills/`));
1884
+ if (!matchingRoot) continue;
1885
+ const customRootMatch = normalizedPath.slice(matchingRoot.length + 1).match(/^skills\/([^/\s]+)\/SKILL\.md$/);
1886
+ if (customRootMatch && this.isValidSkillName(customRootMatch[1])) matches.set(normalizedPath, {
1887
+ name: customRootMatch[1],
1888
+ path: normalizedPath
1889
+ });
1890
+ }
1891
+ return Array.from(matches.values());
1892
+ }
1893
+ isValidSkillName(name) {
1894
+ return /^[A-Za-z0-9._:-]+$/.test(name);
1895
+ }
1896
+ sanitizeTraceText(value, context) {
1897
+ const sanitized = this.redactTracePii(require_logger.sanitizeObject(value, { context }));
1898
+ if (typeof sanitized === "string") return sanitized;
1899
+ if (sanitized === void 0 || sanitized === null) return;
1900
+ try {
1901
+ return JSON.stringify(sanitized);
1902
+ } catch (error) {
1903
+ require_logger.logger.debug("[CodexAppServer] Failed to stringify sanitized trace text", { error });
1904
+ return;
1905
+ }
1906
+ }
1907
+ sanitizeForMetadata(value) {
1908
+ return this.redactTracePii(require_logger.sanitizeObject(value, { context: "Codex app-server metadata" }));
1909
+ }
1910
+ redactTracePii(value) {
1911
+ if (typeof value === "string") return value.replace(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, require_logger.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, require_logger.REDACTED).replace(/\b(api[_-]?key|token|password|secret|authorization|auth)\s*([=:])(\s*)(["']?)[^\s"'`]+(\4)/gi, (_match, key, separator, spacing, quote) => `${key}${separator}${spacing}${quote}${require_logger.REDACTED}${quote}`);
1912
+ if (Array.isArray(value)) return value.map((item) => this.redactTracePii(item));
1913
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [key, require_logger.normalizeFieldName(key).includes("email") ? require_logger.REDACTED : this.redactTracePii(entryValue)]));
1914
+ return value;
1915
+ }
1916
+ };
1917
+ //#endregion
1918
+ exports.OpenAICodexAppServerProvider = OpenAICodexAppServerProvider;
1919
+
1920
+ //# sourceMappingURL=codex-app-server-VMRnjZ68.cjs.map