promptfoo 0.72.1 → 0.73.0

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 (470) hide show
  1. package/README.md +5 -5
  2. package/dist/package.json +14 -8
  3. package/dist/src/accounts.d.ts.map +1 -1
  4. package/dist/src/accounts.js +2 -1
  5. package/dist/src/accounts.js.map +1 -1
  6. package/dist/src/assertions/validateAssertions.d.ts +1 -1
  7. package/dist/src/assertions/validateAssertions.d.ts.map +1 -1
  8. package/dist/src/assertions/validateAssertions.js +7 -7
  9. package/dist/src/assertions/validateAssertions.js.map +1 -1
  10. package/dist/src/assertions.d.ts.map +1 -1
  11. package/dist/src/assertions.js +2 -1
  12. package/dist/src/assertions.js.map +1 -1
  13. package/dist/src/cache.js +2 -2
  14. package/dist/src/cache.js.map +1 -1
  15. package/dist/src/commands/eval.d.ts.map +1 -1
  16. package/dist/src/commands/eval.js +10 -0
  17. package/dist/src/commands/eval.js.map +1 -1
  18. package/dist/src/commands/export.d.ts.map +1 -1
  19. package/dist/src/commands/export.js +15 -14
  20. package/dist/src/commands/export.js.map +1 -1
  21. package/dist/src/commands/generate/redteam.d.ts +1 -46
  22. package/dist/src/commands/generate/redteam.d.ts.map +1 -1
  23. package/dist/src/commands/generate/redteam.js +70 -26
  24. package/dist/src/commands/generate/redteam.js.map +1 -1
  25. package/dist/src/commands/import.d.ts.map +1 -1
  26. package/dist/src/commands/import.js +2 -1
  27. package/dist/src/commands/import.js.map +1 -1
  28. package/dist/src/commands/init.d.ts.map +1 -1
  29. package/dist/src/commands/init.js +12 -0
  30. package/dist/src/commands/init.js.map +1 -1
  31. package/dist/src/commands/redteam.d.ts.map +1 -1
  32. package/dist/src/commands/redteam.js +72 -18
  33. package/dist/src/commands/redteam.js.map +1 -1
  34. package/dist/src/commands/view.d.ts.map +1 -1
  35. package/dist/src/commands/view.js +2 -1
  36. package/dist/src/commands/view.js.map +1 -1
  37. package/dist/src/config.d.ts.map +1 -1
  38. package/dist/src/config.js +2 -20
  39. package/dist/src/config.js.map +1 -1
  40. package/dist/src/configTypes.d.ts +7 -0
  41. package/dist/src/configTypes.d.ts.map +1 -0
  42. package/dist/src/configTypes.js +3 -0
  43. package/dist/src/configTypes.js.map +1 -0
  44. package/dist/src/database/index.d.ts +4 -0
  45. package/dist/src/database/index.d.ts.map +1 -0
  46. package/dist/src/database/index.js +50 -0
  47. package/dist/src/database/index.js.map +1 -0
  48. package/dist/src/{database.d.ts → database/operations.d.ts} +173 -115
  49. package/dist/src/{database.d.ts.map → database/operations.d.ts.map} +1 -1
  50. package/dist/src/{database.js → database/operations.js} +1 -25
  51. package/dist/src/database/operations.js.map +1 -0
  52. package/dist/src/evaluator.js +2 -2
  53. package/dist/src/evaluator.js.map +1 -1
  54. package/dist/src/globalConfig.d.ts +1 -7
  55. package/dist/src/globalConfig.d.ts.map +1 -1
  56. package/dist/src/globalConfig.js +3 -3
  57. package/dist/src/globalConfig.js.map +1 -1
  58. package/dist/src/matchers.d.ts.map +1 -1
  59. package/dist/src/matchers.js +6 -2
  60. package/dist/src/matchers.js.map +1 -1
  61. package/dist/src/prompts/grading.js +2 -2
  62. package/dist/src/prompts/processors/python.js +4 -4
  63. package/dist/src/prompts/processors/python.js.map +1 -1
  64. package/dist/src/providers/anthropic.d.ts +1 -1
  65. package/dist/src/providers/anthropic.d.ts.map +1 -1
  66. package/dist/src/providers/bam.d.ts +1 -1
  67. package/dist/src/providers/bam.d.ts.map +1 -1
  68. package/dist/src/providers/bedrock.d.ts +1 -1
  69. package/dist/src/providers/bedrock.d.ts.map +1 -1
  70. package/dist/src/providers/cohere.d.ts.map +1 -1
  71. package/dist/src/providers/cohere.js +4 -1
  72. package/dist/src/providers/cohere.js.map +1 -1
  73. package/dist/src/providers/http.d.ts +1 -1
  74. package/dist/src/providers/http.d.ts.map +1 -1
  75. package/dist/src/providers/http.js +3 -3
  76. package/dist/src/providers/http.js.map +1 -1
  77. package/dist/src/providers/llama.d.ts +1 -1
  78. package/dist/src/providers/llama.d.ts.map +1 -1
  79. package/dist/src/providers/localai.d.ts +1 -1
  80. package/dist/src/providers/localai.d.ts.map +1 -1
  81. package/dist/src/providers/ollama.d.ts +1 -1
  82. package/dist/src/providers/ollama.d.ts.map +1 -1
  83. package/dist/src/providers/openai.d.ts +1 -1
  84. package/dist/src/providers/openai.d.ts.map +1 -1
  85. package/dist/src/providers/openai.js +48 -50
  86. package/dist/src/providers/openai.js.map +1 -1
  87. package/dist/src/providers/palm.d.ts +1 -1
  88. package/dist/src/providers/palm.d.ts.map +1 -1
  89. package/dist/src/providers/pythonCompletion.d.ts.map +1 -1
  90. package/dist/src/providers/pythonCompletion.js +6 -5
  91. package/dist/src/providers/pythonCompletion.js.map +1 -1
  92. package/dist/src/providers/replicate.js +2 -2
  93. package/dist/src/providers/replicate.js.map +1 -1
  94. package/dist/src/providers/scriptCompletion.js +3 -3
  95. package/dist/src/providers/scriptCompletion.js.map +1 -1
  96. package/dist/src/providers/vertex.d.ts +1 -1
  97. package/dist/src/providers/vertex.d.ts.map +1 -1
  98. package/dist/src/providers/vertex.js +23 -10
  99. package/dist/src/providers/vertex.js.map +1 -1
  100. package/dist/src/providers/vertexUtil.d.ts +2 -1
  101. package/dist/src/providers/vertexUtil.d.ts.map +1 -1
  102. package/dist/src/providers/vertexUtil.js.map +1 -1
  103. package/dist/src/providers/webhook.d.ts +1 -1
  104. package/dist/src/providers/webhook.d.ts.map +1 -1
  105. package/dist/src/providers.d.ts.map +1 -1
  106. package/dist/src/providers.js +5 -2
  107. package/dist/src/providers.js.map +1 -1
  108. package/dist/src/python/pythonUtils.d.ts +4 -0
  109. package/dist/src/python/pythonUtils.d.ts.map +1 -0
  110. package/dist/src/python/pythonUtils.js +51 -0
  111. package/dist/src/python/pythonUtils.js.map +1 -0
  112. package/dist/src/python/wrapper.d.ts +0 -10
  113. package/dist/src/python/wrapper.d.ts.map +1 -1
  114. package/dist/src/python/wrapper.js +2 -49
  115. package/dist/src/python/wrapper.js.map +1 -1
  116. package/dist/src/redteam/constants.d.ts +60 -3
  117. package/dist/src/redteam/constants.d.ts.map +1 -1
  118. package/dist/src/redteam/constants.js +71 -10
  119. package/dist/src/redteam/constants.js.map +1 -1
  120. package/dist/src/redteam/index.d.ts +15 -4
  121. package/dist/src/redteam/index.d.ts.map +1 -1
  122. package/dist/src/redteam/index.js +110 -33
  123. package/dist/src/redteam/index.js.map +1 -1
  124. package/dist/src/redteam/plugins/base.d.ts +10 -13
  125. package/dist/src/redteam/plugins/base.d.ts.map +1 -1
  126. package/dist/src/redteam/plugins/base.js +36 -20
  127. package/dist/src/redteam/plugins/base.js.map +1 -1
  128. package/dist/src/redteam/plugins/debugInterface.d.ts +7 -0
  129. package/dist/src/redteam/plugins/debugInterface.d.ts.map +1 -0
  130. package/dist/src/redteam/plugins/debugInterface.js +49 -0
  131. package/dist/src/redteam/plugins/debugInterface.js.map +1 -0
  132. package/dist/src/redteam/plugins/harmful.d.ts +1 -54
  133. package/dist/src/redteam/plugins/harmful.d.ts.map +1 -1
  134. package/dist/src/redteam/plugins/harmful.js +8 -51
  135. package/dist/src/redteam/plugins/harmful.js.map +1 -1
  136. package/dist/src/redteam/plugins/pii.d.ts +9 -10
  137. package/dist/src/redteam/plugins/pii.d.ts.map +1 -1
  138. package/dist/src/redteam/plugins/pii.js +33 -53
  139. package/dist/src/redteam/plugins/pii.js.map +1 -1
  140. package/dist/src/redteam/plugins/rbac.d.ts +7 -0
  141. package/dist/src/redteam/plugins/rbac.d.ts.map +1 -0
  142. package/dist/src/redteam/plugins/rbac.js +49 -0
  143. package/dist/src/redteam/plugins/rbac.js.map +1 -0
  144. package/dist/src/redteam/plugins/shellInjection.d.ts +7 -0
  145. package/dist/src/redteam/plugins/shellInjection.d.ts.map +1 -0
  146. package/dist/src/redteam/plugins/shellInjection.js +54 -0
  147. package/dist/src/redteam/plugins/shellInjection.js.map +1 -0
  148. package/dist/src/redteam/plugins/sqlInjection.d.ts +7 -0
  149. package/dist/src/redteam/plugins/sqlInjection.d.ts.map +1 -0
  150. package/dist/src/redteam/plugins/sqlInjection.js +44 -0
  151. package/dist/src/redteam/plugins/sqlInjection.js.map +1 -0
  152. package/dist/src/redteam/providers/iterative.d.ts.map +1 -1
  153. package/dist/src/redteam/providers/iterative.js +2 -1
  154. package/dist/src/redteam/providers/iterative.js.map +1 -1
  155. package/dist/src/redteam/strategies/injections.d.ts.map +1 -0
  156. package/dist/src/redteam/{methods → strategies}/injections.js +0 -12
  157. package/dist/src/redteam/strategies/injections.js.map +1 -0
  158. package/dist/src/redteam/strategies/iterative.d.ts.map +1 -0
  159. package/dist/src/redteam/strategies/iterative.js.map +1 -0
  160. package/dist/src/redteam/types.d.ts +196 -0
  161. package/dist/src/redteam/types.d.ts.map +1 -0
  162. package/dist/src/redteam/types.js +124 -0
  163. package/dist/src/redteam/types.js.map +1 -0
  164. package/dist/src/redteam/util.d.ts +22 -0
  165. package/dist/src/redteam/util.d.ts.map +1 -0
  166. package/dist/src/redteam/util.js +56 -0
  167. package/dist/src/redteam/util.js.map +1 -0
  168. package/dist/src/testCases.d.ts +1 -2
  169. package/dist/src/testCases.d.ts.map +1 -1
  170. package/dist/src/testCases.js.map +1 -1
  171. package/dist/src/types/databaseTypes.d.ts +17 -0
  172. package/dist/src/types/databaseTypes.d.ts.map +1 -0
  173. package/dist/src/types/databaseTypes.js +3 -0
  174. package/dist/src/types/databaseTypes.js.map +1 -0
  175. package/dist/src/{types.d.ts → types/index.d.ts} +4296 -1425
  176. package/dist/src/{types.d.ts.map → types/index.d.ts.map} +1 -1
  177. package/dist/src/{types.js → types/index.js} +38 -9
  178. package/dist/src/types/index.js.map +1 -0
  179. package/dist/src/util/config.d.ts +3 -0
  180. package/dist/src/util/config.d.ts.map +1 -0
  181. package/dist/src/util/config.js +42 -0
  182. package/dist/src/util/config.js.map +1 -0
  183. package/dist/src/util/index.d.ts +41 -25
  184. package/dist/src/util/index.d.ts.map +1 -1
  185. package/dist/src/util/index.js +81 -119
  186. package/dist/src/util/index.js.map +1 -1
  187. package/dist/src/util/json.d.ts +3 -0
  188. package/dist/src/util/json.d.ts.map +1 -0
  189. package/dist/src/util/json.js +27 -0
  190. package/dist/src/util/json.js.map +1 -0
  191. package/dist/src/web/nextui/404/index.html +1 -1
  192. package/dist/src/web/nextui/404.html +1 -1
  193. package/dist/src/web/nextui/_next/static/chunks/155-4e319e68476266ee.js +1 -0
  194. package/dist/src/web/nextui/_next/static/chunks/163-93bab94bc04ae71b.js +6 -0
  195. package/dist/src/web/nextui/_next/static/chunks/{258-4acb452fe85cff6f.js → 258-b6257e5de9d0e2c7.js} +1 -1
  196. package/dist/src/web/nextui/_next/static/chunks/281-64d9f1415a301ee5.js +1 -0
  197. package/dist/src/web/nextui/_next/static/chunks/304-cf667fe8f06238b4.js +1 -0
  198. package/dist/src/web/nextui/_next/static/chunks/322-b47b6cc3f5b5fdb8.js +1 -0
  199. package/dist/src/web/nextui/_next/static/chunks/325-0d36870ade5e5263.js +1 -0
  200. package/dist/src/web/nextui/_next/static/chunks/339-79124d204fa988a3.js +1 -0
  201. package/dist/src/web/nextui/_next/static/chunks/378-c135e497df1864cb.js +1 -0
  202. package/dist/src/web/nextui/_next/static/chunks/476-0afb5eb266c57b7f.js +17 -0
  203. package/dist/src/web/nextui/_next/static/chunks/493-ebd12f00541c4969.js +2 -0
  204. package/dist/src/web/nextui/_next/static/chunks/497-e280a5610a3d7d42.js +32 -0
  205. package/dist/src/web/nextui/_next/static/chunks/515-e06d044f12d8a1bd.js +1 -0
  206. package/dist/src/web/nextui/_next/static/chunks/69-5e4d5e60859a86d2.js +1 -0
  207. package/dist/src/web/nextui/_next/static/chunks/737-32d5472455807d7a.js +1 -0
  208. package/dist/src/web/nextui/_next/static/chunks/903-7cc440d9f9e9f95d.js +97 -0
  209. package/dist/src/web/nextui/_next/static/chunks/905-78cd666f27891ee6.js +28 -0
  210. package/dist/src/web/nextui/_next/static/chunks/916-b92fea2ab6136411.js +1 -0
  211. package/dist/src/web/nextui/_next/static/chunks/969-6ab6c8f4158da970.js +1 -0
  212. package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-7247b17e8f179a46.js +1 -0
  213. package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-8560afaf494f9882.js +1 -0
  214. package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-6e6ec3c778ccd110.js +1 -0
  215. package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-fe10d5df88bc44ef.js +1 -0
  216. package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/{page-0a39d3450aa09dda.js → page-057e5eb83e0f614b.js} +1 -1
  217. package/dist/src/web/nextui/_next/static/chunks/app/eval/page-88fa70fc5bf755bc.js +1 -0
  218. package/dist/src/web/nextui/_next/static/chunks/app/layout-15abf0d1049cb47c.js +1 -0
  219. package/dist/src/web/nextui/_next/static/chunks/app/{page-5650318e57510b6c.js → page-122e9cfa52eb218a.js} +1 -1
  220. package/dist/src/web/nextui/_next/static/chunks/app/progress/page-a62ca531a4bb4149.js +1 -0
  221. package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-10bb2e571670139c.js +1 -0
  222. package/dist/src/web/nextui/_next/static/chunks/app/report/page-a8b83960f08e2bb2.js +1 -0
  223. package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6ea3e180c3116fb2.js +1 -0
  224. package/dist/src/web/nextui/_next/static/chunks/{main-app-929a26b3c8cd3f7a.js → main-app-7a1376166cb8b72e.js} +1 -1
  225. package/dist/src/web/nextui/_next/static/chunks/{webpack-c9f728822666f852.js → webpack-ee33d95b3e219985.js} +1 -1
  226. package/dist/src/web/nextui/_next/static/css/13f881e4290b6d59.css +1 -0
  227. package/dist/src/web/nextui/_next/static/css/87b5e6e04efd27e5.css +1 -0
  228. package/dist/src/web/nextui/_next/static/css/e17fdafd8599f69b.css +1 -0
  229. package/dist/src/web/nextui/_next/static/css/eb523daddb89dfc1.css +1 -0
  230. package/dist/src/web/nextui/auth/login/index.html +1 -1
  231. package/dist/src/web/nextui/auth/login/index.txt +6 -6
  232. package/dist/src/web/nextui/auth/signup/index.html +1 -1
  233. package/dist/src/web/nextui/auth/signup/index.txt +6 -6
  234. package/dist/src/web/nextui/datasets/index.html +1 -1
  235. package/dist/src/web/nextui/datasets/index.txt +6 -6
  236. package/dist/src/web/nextui/eval/index.html +1 -1
  237. package/dist/src/web/nextui/eval/index.txt +8 -8
  238. package/dist/src/web/nextui/index.html +1 -1
  239. package/dist/src/web/nextui/index.txt +5 -5
  240. package/dist/src/web/nextui/logo-panda.svg +91 -0
  241. package/dist/src/web/nextui/progress/index.html +1 -1
  242. package/dist/src/web/nextui/progress/index.txt +6 -6
  243. package/dist/src/web/nextui/prompts/index.html +1 -1
  244. package/dist/src/web/nextui/prompts/index.txt +6 -6
  245. package/dist/src/web/nextui/report/index.html +1 -1
  246. package/dist/src/web/nextui/report/index.txt +8 -8
  247. package/dist/src/web/nextui/setup/index.html +1 -1
  248. package/dist/src/web/nextui/setup/index.txt +7 -7
  249. package/dist/test/__mocks__/tempCustomModule.d.ts +13 -0
  250. package/dist/test/__mocks__/tempCustomModule.d.ts.map +1 -0
  251. package/dist/test/__mocks__/tempCustomModule.js +15 -0
  252. package/dist/test/__mocks__/tempCustomModule.js.map +1 -0
  253. package/dist/test/account.test.d.ts +2 -0
  254. package/dist/test/account.test.d.ts.map +1 -0
  255. package/dist/test/account.test.js +46 -0
  256. package/dist/test/account.test.js.map +1 -0
  257. package/dist/test/assertions/AssertionResult.test.d.ts +2 -0
  258. package/dist/test/assertions/AssertionResult.test.d.ts.map +1 -0
  259. package/dist/test/assertions/AssertionResult.test.js +184 -0
  260. package/dist/test/assertions/AssertionResult.test.js.map +1 -0
  261. package/dist/test/assertions/validateAssertions.test.d.ts +2 -0
  262. package/dist/test/assertions/validateAssertions.test.d.ts.map +1 -0
  263. package/dist/test/assertions/validateAssertions.test.js +40 -0
  264. package/dist/test/assertions/validateAssertions.test.js.map +1 -0
  265. package/dist/test/assertions.test.d.ts +2 -0
  266. package/dist/test/assertions.test.d.ts.map +1 -0
  267. package/dist/test/assertions.test.js +3162 -0
  268. package/dist/test/assertions.test.js.map +1 -0
  269. package/dist/test/cache.test.d.ts +2 -0
  270. package/dist/test/cache.test.d.ts.map +1 -0
  271. package/dist/test/cache.test.js +90 -0
  272. package/dist/test/cache.test.js.map +1 -0
  273. package/dist/test/checkNodeVersion.test.d.ts +2 -0
  274. package/dist/test/checkNodeVersion.test.d.ts.map +1 -0
  275. package/dist/test/checkNodeVersion.test.js +85 -0
  276. package/dist/test/checkNodeVersion.test.js.map +1 -0
  277. package/dist/test/commands/eval/filterFailingTests.test.d.ts +2 -0
  278. package/dist/test/commands/eval/filterFailingTests.test.d.ts.map +1 -0
  279. package/dist/test/commands/eval/filterFailingTests.test.js +84 -0
  280. package/dist/test/commands/eval/filterFailingTests.test.js.map +1 -0
  281. package/dist/test/commands/eval/filterProviders.test.d.ts +2 -0
  282. package/dist/test/commands/eval/filterProviders.test.d.ts.map +1 -0
  283. package/dist/test/commands/eval/filterProviders.test.js +50 -0
  284. package/dist/test/commands/eval/filterProviders.test.js.map +1 -0
  285. package/dist/test/commands/eval/filterTests.test.d.ts +2 -0
  286. package/dist/test/commands/eval/filterTests.test.d.ts.map +1 -0
  287. package/dist/test/commands/eval/filterTests.test.js +51 -0
  288. package/dist/test/commands/eval/filterTests.test.js.map +1 -0
  289. package/dist/test/config.test.d.ts +2 -0
  290. package/dist/test/config.test.d.ts.map +1 -0
  291. package/dist/test/config.test.js +404 -0
  292. package/dist/test/config.test.js.map +1 -0
  293. package/dist/test/csv.test.d.ts +2 -0
  294. package/dist/test/csv.test.d.ts.map +1 -0
  295. package/dist/test/csv.test.js +239 -0
  296. package/dist/test/csv.test.js.map +1 -0
  297. package/dist/test/evaluator.test.d.ts +2 -0
  298. package/dist/test/evaluator.test.d.ts.map +1 -0
  299. package/dist/test/evaluator.test.js +922 -0
  300. package/dist/test/evaluator.test.js.map +1 -0
  301. package/dist/test/globalConfig.test.d.ts +2 -0
  302. package/dist/test/globalConfig.test.d.ts.map +1 -0
  303. package/dist/test/globalConfig.test.js +91 -0
  304. package/dist/test/globalConfig.test.js.map +1 -0
  305. package/dist/test/is-sql-tests/node-sql-parser.test.d.ts +2 -0
  306. package/dist/test/is-sql-tests/node-sql-parser.test.d.ts.map +1 -0
  307. package/dist/test/is-sql-tests/node-sql-parser.test.js +179 -0
  308. package/dist/test/is-sql-tests/node-sql-parser.test.js.map +1 -0
  309. package/dist/test/matchers.test.d.ts +2 -0
  310. package/dist/test/matchers.test.d.ts.map +1 -0
  311. package/dist/test/matchers.test.js +807 -0
  312. package/dist/test/matchers.test.js.map +1 -0
  313. package/dist/test/prompts.processors.javascript.test.d.ts +2 -0
  314. package/dist/test/prompts.processors.javascript.test.d.ts.map +1 -0
  315. package/dist/test/prompts.processors.javascript.test.js +93 -0
  316. package/dist/test/prompts.processors.javascript.test.js.map +1 -0
  317. package/dist/test/prompts.processors.json.test.d.ts +2 -0
  318. package/dist/test/prompts.processors.json.test.d.ts.map +1 -0
  319. package/dist/test/prompts.processors.json.test.js +67 -0
  320. package/dist/test/prompts.processors.json.test.js.map +1 -0
  321. package/dist/test/prompts.processors.jsonl.test.d.ts +2 -0
  322. package/dist/test/prompts.processors.jsonl.test.d.ts.map +1 -0
  323. package/dist/test/prompts.processors.jsonl.test.js +99 -0
  324. package/dist/test/prompts.processors.jsonl.test.js.map +1 -0
  325. package/dist/test/prompts.processors.python.test.d.ts +2 -0
  326. package/dist/test/prompts.processors.python.test.d.ts.map +1 -0
  327. package/dist/test/prompts.processors.python.test.js +100 -0
  328. package/dist/test/prompts.processors.python.test.js.map +1 -0
  329. package/dist/test/prompts.processors.python.utils.test.d.ts +2 -0
  330. package/dist/test/prompts.processors.python.utils.test.d.ts.map +1 -0
  331. package/dist/test/prompts.processors.python.utils.test.js +68 -0
  332. package/dist/test/prompts.processors.python.utils.test.js.map +1 -0
  333. package/dist/test/prompts.processors.string.test.d.ts +2 -0
  334. package/dist/test/prompts.processors.string.test.d.ts.map +1 -0
  335. package/dist/test/prompts.processors.string.test.js +24 -0
  336. package/dist/test/prompts.processors.string.test.js.map +1 -0
  337. package/dist/test/prompts.processors.text.test.d.ts +2 -0
  338. package/dist/test/prompts.processors.text.test.d.ts.map +1 -0
  339. package/dist/test/prompts.processors.text.test.js +109 -0
  340. package/dist/test/prompts.processors.text.test.js.map +1 -0
  341. package/dist/test/prompts.processors.yaml.test.d.ts +2 -0
  342. package/dist/test/prompts.processors.yaml.test.d.ts.map +1 -0
  343. package/dist/test/prompts.processors.yaml.test.js +76 -0
  344. package/dist/test/prompts.processors.yaml.test.js.map +1 -0
  345. package/dist/test/prompts.test.d.ts +2 -0
  346. package/dist/test/prompts.test.d.ts.map +1 -0
  347. package/dist/test/prompts.test.js +562 -0
  348. package/dist/test/prompts.test.js.map +1 -0
  349. package/dist/test/prompts.utils.test.d.ts +2 -0
  350. package/dist/test/prompts.utils.test.d.ts.map +1 -0
  351. package/dist/test/prompts.utils.test.js +123 -0
  352. package/dist/test/prompts.utils.test.js.map +1 -0
  353. package/dist/test/providers.anthropic.test.d.ts +2 -0
  354. package/dist/test/providers.anthropic.test.d.ts.map +1 -0
  355. package/dist/test/providers.anthropic.test.js +520 -0
  356. package/dist/test/providers.anthropic.test.js.map +1 -0
  357. package/dist/test/providers.azure.test.d.ts +2 -0
  358. package/dist/test/providers.azure.test.d.ts.map +1 -0
  359. package/dist/test/providers.azure.test.js +96 -0
  360. package/dist/test/providers.azure.test.js.map +1 -0
  361. package/dist/test/providers.bedrock.test.d.ts +2 -0
  362. package/dist/test/providers.bedrock.test.d.ts.map +1 -0
  363. package/dist/test/providers.bedrock.test.js +349 -0
  364. package/dist/test/providers.bedrock.test.js.map +1 -0
  365. package/dist/test/providers.http.test.d.ts +2 -0
  366. package/dist/test/providers.http.test.d.ts.map +1 -0
  367. package/dist/test/providers.http.test.js +130 -0
  368. package/dist/test/providers.http.test.js.map +1 -0
  369. package/dist/test/providers.llama.test.d.ts +2 -0
  370. package/dist/test/providers.llama.test.d.ts.map +1 -0
  371. package/dist/test/providers.llama.test.js +101 -0
  372. package/dist/test/providers.llama.test.js.map +1 -0
  373. package/dist/test/providers.pythonCompletion.test.d.ts +2 -0
  374. package/dist/test/providers.pythonCompletion.test.d.ts.map +1 -0
  375. package/dist/test/providers.pythonCompletion.test.js +149 -0
  376. package/dist/test/providers.pythonCompletion.test.js.map +1 -0
  377. package/dist/test/providers.test.d.ts +2 -0
  378. package/dist/test/providers.test.d.ts.map +1 -0
  379. package/dist/test/providers.test.js +883 -0
  380. package/dist/test/providers.test.js.map +1 -0
  381. package/dist/test/providers.vertex.test.d.ts +2 -0
  382. package/dist/test/providers.vertex.test.d.ts.map +1 -0
  383. package/dist/test/providers.vertex.test.js +153 -0
  384. package/dist/test/providers.vertex.test.js.map +1 -0
  385. package/dist/test/pythonWrapper.test.d.ts +2 -0
  386. package/dist/test/pythonWrapper.test.d.ts.map +1 -0
  387. package/dist/test/pythonWrapper.test.js +65 -0
  388. package/dist/test/pythonWrapper.test.js.map +1 -0
  389. package/dist/test/redteam/plugins/base.test.d.ts +2 -0
  390. package/dist/test/redteam/plugins/base.test.d.ts.map +1 -0
  391. package/dist/test/redteam/plugins/base.test.js +149 -0
  392. package/dist/test/redteam/plugins/base.test.js.map +1 -0
  393. package/dist/test/redteam/purpose.test.d.ts +2 -0
  394. package/dist/test/redteam/purpose.test.d.ts.map +1 -0
  395. package/dist/test/redteam/purpose.test.js +37 -0
  396. package/dist/test/redteam/purpose.test.js.map +1 -0
  397. package/dist/test/redteam/types.test.d.ts +2 -0
  398. package/dist/test/redteam/types.test.d.ts.map +1 -0
  399. package/dist/test/redteam/types.test.js +325 -0
  400. package/dist/test/redteam/types.test.js.map +1 -0
  401. package/dist/test/redteam/util.test.d.ts +2 -0
  402. package/dist/test/redteam/util.test.d.ts.map +1 -0
  403. package/dist/test/redteam/util.test.js +99 -0
  404. package/dist/test/redteam/util.test.js.map +1 -0
  405. package/dist/test/telemetry.test.d.ts +2 -0
  406. package/dist/test/telemetry.test.d.ts.map +1 -0
  407. package/dist/test/telemetry.test.js +68 -0
  408. package/dist/test/telemetry.test.js.map +1 -0
  409. package/dist/test/testCases.test.d.ts +2 -0
  410. package/dist/test/testCases.test.d.ts.map +1 -0
  411. package/dist/test/testCases.test.js +362 -0
  412. package/dist/test/testCases.test.js.map +1 -0
  413. package/dist/test/updates.test.d.ts +2 -0
  414. package/dist/test/updates.test.d.ts.map +1 -0
  415. package/dist/test/updates.test.js +63 -0
  416. package/dist/test/updates.test.js.map +1 -0
  417. package/dist/test/util.templates.test.d.ts +2 -0
  418. package/dist/test/util.templates.test.d.ts.map +1 -0
  419. package/dist/test/util.templates.test.js +75 -0
  420. package/dist/test/util.templates.test.js.map +1 -0
  421. package/dist/test/util.test.d.ts +2 -0
  422. package/dist/test/util.test.d.ts.map +1 -0
  423. package/dist/test/util.test.js +661 -0
  424. package/dist/test/util.test.js.map +1 -0
  425. package/dist/test/utils.d.ts +6 -0
  426. package/dist/test/utils.d.ts.map +1 -0
  427. package/dist/test/utils.js +16 -0
  428. package/dist/test/utils.js.map +1 -0
  429. package/package.json +14 -8
  430. package/dist/src/database.js.map +0 -1
  431. package/dist/src/redteam/methods/injections.d.ts.map +0 -1
  432. package/dist/src/redteam/methods/injections.js.map +0 -1
  433. package/dist/src/redteam/methods/iterative.d.ts.map +0 -1
  434. package/dist/src/redteam/methods/iterative.js.map +0 -1
  435. package/dist/src/types.js.map +0 -1
  436. package/dist/src/web/nextui/_next/static/chunks/163-e65e0f7f442a0c72.js +0 -6
  437. package/dist/src/web/nextui/_next/static/chunks/180-46db19289d856800.js +0 -1
  438. package/dist/src/web/nextui/_next/static/chunks/304-9d57a2251034b801.js +0 -1
  439. package/dist/src/web/nextui/_next/static/chunks/322-4a0fc9b0508f47e8.js +0 -1
  440. package/dist/src/web/nextui/_next/static/chunks/339-db5bd05e24dde905.js +0 -1
  441. package/dist/src/web/nextui/_next/static/chunks/374-d40afe599198abd3.js +0 -1
  442. package/dist/src/web/nextui/_next/static/chunks/378-e22c8aeb8e031fad.js +0 -1
  443. package/dist/src/web/nextui/_next/static/chunks/448-4da3bf74eae4996a.js +0 -97
  444. package/dist/src/web/nextui/_next/static/chunks/53-fae6e50ace6c83a1.js +0 -1
  445. package/dist/src/web/nextui/_next/static/chunks/578-8efe57f906f7573c.js +0 -44
  446. package/dist/src/web/nextui/_next/static/chunks/620-7a5a7bf6e1fe49e5.js +0 -1
  447. package/dist/src/web/nextui/_next/static/chunks/737-538f50dc31cc8c49.js +0 -1
  448. package/dist/src/web/nextui/_next/static/chunks/905-0da344cee75690e7.js +0 -32
  449. package/dist/src/web/nextui/_next/static/chunks/932-75585b3be8ce494d.js +0 -1
  450. package/dist/src/web/nextui/_next/static/chunks/973-ffe3726c956d08ef.js +0 -2
  451. package/dist/src/web/nextui/_next/static/chunks/995-803c74b81e7bf6cd.js +0 -1
  452. package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-2e2c0c725127ea2d.js +0 -1
  453. package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-ccdb1f6890601666.js +0 -1
  454. package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-642db4f4a8e8ba40.js +0 -1
  455. package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-ce320e6d1e6d1d23.js +0 -1
  456. package/dist/src/web/nextui/_next/static/chunks/app/eval/page-32eaa14d2384c5b0.js +0 -1
  457. package/dist/src/web/nextui/_next/static/chunks/app/layout-4282b1d33566e258.js +0 -1
  458. package/dist/src/web/nextui/_next/static/chunks/app/progress/page-462526776efd6fd6.js +0 -1
  459. package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-0ae78bc0bf7c56bc.js +0 -1
  460. package/dist/src/web/nextui/_next/static/chunks/app/report/page-e4f7851d41eb0f92.js +0 -1
  461. package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6cde750ec428cd75.js +0 -1
  462. package/dist/src/web/nextui/_next/static/css/35ab7ce8025438b0.css +0 -1
  463. package/dist/src/web/nextui/_next/static/css/5bd2f45de1f3ba83.css +0 -1
  464. package/dist/src/web/nextui/_next/static/css/94b771e23fc5d5f5.css +0 -1
  465. package/dist/src/web/nextui/_next/static/css/dab5d695b3657d59.css +0 -1
  466. /package/dist/src/redteam/{methods → strategies}/injections.d.ts +0 -0
  467. /package/dist/src/redteam/{methods → strategies}/iterative.d.ts +0 -0
  468. /package/dist/src/redteam/{methods → strategies}/iterative.js +0 -0
  469. /package/dist/src/web/nextui/_next/static/{8E4q0Tmu22G1wENZyXEq0 → L-tpppAe26U-euPv62afH}/_buildManifest.js +0 -0
  470. /package/dist/src/web/nextui/_next/static/{8E4q0Tmu22G1wENZyXEq0 → L-tpppAe26U-euPv62afH}/_ssgManifest.js +0 -0
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../src/prompts/utils");
4
+ jest.mock('fs', () => ({
5
+ statSync: jest.fn(jest.requireActual('fs').statSync),
6
+ }));
7
+ jest.mock('glob', () => ({
8
+ globSync: jest.fn(jest.requireActual('glob').globSync),
9
+ }));
10
+ describe('maybeFilePath', () => {
11
+ it('should return true for valid file paths', () => {
12
+ expect((0, utils_1.maybeFilePath)('C:\\path\\to\\file.txt')).toBe(true);
13
+ expect((0, utils_1.maybeFilePath)('file.*')).toBe(true);
14
+ expect((0, utils_1.maybeFilePath)('filename.ext')).toBe(true);
15
+ expect((0, utils_1.maybeFilePath)('path/to/file.txt')).toBe(true);
16
+ });
17
+ it('should return false for strings with new lines', () => {
18
+ expect((0, utils_1.maybeFilePath)('path/to\nfile.txt')).toBe(false);
19
+ expect((0, utils_1.maybeFilePath)('file\nname.ext')).toBe(false);
20
+ });
21
+ it('should return false for strings with "portkey://"', () => {
22
+ expect((0, utils_1.maybeFilePath)('portkey://path/to/file')).toBe(false);
23
+ });
24
+ it('should return false for strings with "langfuse://"', () => {
25
+ expect((0, utils_1.maybeFilePath)('langfuse://path/to/file')).toBe(false);
26
+ });
27
+ it('should return false for strings without file path indicators', () => {
28
+ expect((0, utils_1.maybeFilePath)('anotherstring')).toBe(false);
29
+ expect((0, utils_1.maybeFilePath)('justastring')).toBe(false);
30
+ expect((0, utils_1.maybeFilePath)('stringwith.dotbutnotfile')).toBe(false);
31
+ });
32
+ it('should return true for strings with file:// prefix', () => {
33
+ expect((0, utils_1.maybeFilePath)('file://path/to/file.txt')).toBe(true);
34
+ });
35
+ it('should return true for strings with wildcard character', () => {
36
+ expect((0, utils_1.maybeFilePath)('*.txt')).toBe(true);
37
+ expect((0, utils_1.maybeFilePath)('path/to/*.txt')).toBe(true);
38
+ });
39
+ it('should return true for strings with file extension at the third or fourth last position', () => {
40
+ expect((0, utils_1.maybeFilePath)('file.ext')).toBe(true);
41
+ expect((0, utils_1.maybeFilePath)('file.name.ext')).toBe(true);
42
+ expect((0, utils_1.maybeFilePath)('filename.e')).toBe(false);
43
+ expect((0, utils_1.maybeFilePath)('filename.ex')).toBe(true);
44
+ });
45
+ it('should work for files that end with specific allowed extensions', () => {
46
+ expect((0, utils_1.maybeFilePath)('filename.cjs')).toBe(true);
47
+ expect((0, utils_1.maybeFilePath)('filename.js')).toBe(true);
48
+ expect((0, utils_1.maybeFilePath)('filename.js:functionName')).toBe(true);
49
+ expect((0, utils_1.maybeFilePath)('filename.json')).toBe(true);
50
+ expect((0, utils_1.maybeFilePath)('filename.jsonl')).toBe(true);
51
+ expect((0, utils_1.maybeFilePath)('filename.mjs')).toBe(true);
52
+ expect((0, utils_1.maybeFilePath)('filename.py')).toBe(true);
53
+ expect((0, utils_1.maybeFilePath)('filename.py:functionName')).toBe(true);
54
+ expect((0, utils_1.maybeFilePath)('filename.txt')).toBe(true);
55
+ });
56
+ // Additional tests
57
+ it('should return false for empty strings', () => {
58
+ expect((0, utils_1.maybeFilePath)('')).toBe(false);
59
+ });
60
+ it('should return false for whitespace strings', () => {
61
+ expect((0, utils_1.maybeFilePath)(' ')).toBe(false);
62
+ expect((0, utils_1.maybeFilePath)('\t')).toBe(false);
63
+ });
64
+ it('should return false for non-string inputs', () => {
65
+ expect(() => (0, utils_1.maybeFilePath)(123)).toThrow('Invalid input: 123');
66
+ expect(() => (0, utils_1.maybeFilePath)({})).toThrow('Invalid input: {}');
67
+ expect(() => (0, utils_1.maybeFilePath)([])).toThrow('Invalid input: []');
68
+ });
69
+ it('should return false for strings with invalid and valid indicators mixed', () => {
70
+ expect((0, utils_1.maybeFilePath)('file://path/to\nfile.txt')).toBe(false);
71
+ expect((0, utils_1.maybeFilePath)('path/to/file.txtportkey://')).toBe(false);
72
+ });
73
+ it('should return true for very long valid file paths', () => {
74
+ const longPath = 'a/'.repeat(100) + 'file.txt';
75
+ expect((0, utils_1.maybeFilePath)(longPath)).toBe(true);
76
+ });
77
+ it('should return false for very long invalid file paths', () => {
78
+ const longInvalidPath = 'a/'.repeat(100) + 'file\n.txt';
79
+ expect((0, utils_1.maybeFilePath)(longInvalidPath)).toBe(false);
80
+ });
81
+ it('should return false for strings ending with a dot', () => {
82
+ expect((0, utils_1.maybeFilePath)('Write a tweet about {{topic}}.')).toBe(false);
83
+ });
84
+ });
85
+ describe('normalizeInput', () => {
86
+ it('rejects invalid input types', () => {
87
+ expect(() => (0, utils_1.normalizeInput)(null)).toThrow('Invalid input prompt: null');
88
+ expect(() => (0, utils_1.normalizeInput)(undefined)).toThrow('Invalid input prompt: undefined');
89
+ expect(() => (0, utils_1.normalizeInput)(1)).toThrow('Invalid input prompt: 1');
90
+ expect(() => (0, utils_1.normalizeInput)(true)).toThrow('Invalid input prompt: true');
91
+ expect(() => (0, utils_1.normalizeInput)(false)).toThrow('Invalid input prompt: false');
92
+ });
93
+ it('rejects empty inputs', () => {
94
+ expect(() => (0, utils_1.normalizeInput)([])).toThrow('Invalid input prompt: []');
95
+ expect(() => (0, utils_1.normalizeInput)({})).toThrow('Invalid input prompt: {}');
96
+ expect(() => (0, utils_1.normalizeInput)('')).toThrow('Invalid input prompt: ""');
97
+ });
98
+ it('returns array with single string when input is a non-empty string', () => {
99
+ expect((0, utils_1.normalizeInput)('valid string')).toEqual([{ raw: 'valid string' }]);
100
+ });
101
+ it('returns input array when input is a non-empty array', () => {
102
+ const inputArray = ['prompt1', { raw: 'prompt2' }];
103
+ expect((0, utils_1.normalizeInput)(inputArray)).toEqual([{ raw: 'prompt1' }, { raw: 'prompt2' }]);
104
+ });
105
+ // NOTE: Legacy mode. This is deprecated and will be removed in a future version.
106
+ it('returns array of prompts when input is an object', () => {
107
+ const inputObject = {
108
+ 'prompts1.txt': 'label A',
109
+ 'prompts2.txt': 'label B',
110
+ };
111
+ expect((0, utils_1.normalizeInput)(inputObject)).toEqual([
112
+ {
113
+ label: 'label A',
114
+ raw: 'prompts1.txt',
115
+ },
116
+ {
117
+ label: 'label B',
118
+ raw: 'prompts2.txt',
119
+ },
120
+ ]);
121
+ });
122
+ });
123
+ //# sourceMappingURL=prompts.utils.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.utils.test.js","sourceRoot":"","sources":["../../test/prompts.utils.test.ts"],"names":[],"mappings":";;AAAA,gDAAqE;AAErE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACrB,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;CACrD,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACvB,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC;CACvD,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,IAAA,qBAAa,EAAC,wBAAwB,CAAC,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AAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;QACnD,MAAM,CAAC,IAAA,sBAAc,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC,CAAC,CAAC;IAEH,iFAAiF;IACjF,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,WAAW,GAAG;YAClB,cAAc,EAAE,SAAS;YACzB,cAAc,EAAE,SAAS;SAC1B,CAAC;QACF,MAAM,CAAC,IAAA,sBAAc,EAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;YAC1C;gBACE,KAAK,EAAE,SAAS;gBAChB,GAAG,EAAE,cAAc;aACpB;YACD;gBACE,KAAK,EAAE,SAAS;gBAChB,GAAG,EAAE,cAAc;aACpB;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=providers.anthropic.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.anthropic.test.d.ts","sourceRoot":"","sources":["../../test/providers.anthropic.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,520 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const dedent_1 = __importDefault(require("dedent"));
7
+ const cache_1 = require("../src/cache");
8
+ const anthropic_1 = require("../src/providers/anthropic");
9
+ jest.mock('proxy-agent', () => ({
10
+ ProxyAgent: jest.fn().mockImplementation(() => ({})),
11
+ }));
12
+ describe('Anthropic', () => {
13
+ afterEach(async () => {
14
+ jest.clearAllMocks();
15
+ await (0, cache_1.clearCache)();
16
+ });
17
+ describe('AnthropicMessagesProvider callApi', () => {
18
+ const tools = [
19
+ {
20
+ name: 'get_weather',
21
+ description: 'Get the current weather in a given location',
22
+ input_schema: {
23
+ type: 'object',
24
+ properties: {
25
+ location: {
26
+ type: 'string',
27
+ description: 'The city and state, e.g. San Francisco, CA',
28
+ },
29
+ unit: {
30
+ type: 'string',
31
+ enum: ['celsius', 'fahrenheit'],
32
+ },
33
+ },
34
+ required: ['location'],
35
+ },
36
+ },
37
+ ];
38
+ const provider = new anthropic_1.AnthropicMessagesProvider('claude-3-opus-20240229', {
39
+ config: { tools },
40
+ });
41
+ it('should use cache by default for ToolUse requests', async () => {
42
+ jest
43
+ .spyOn(provider.anthropic.messages, 'create')
44
+ .mockImplementation()
45
+ .mockResolvedValue({
46
+ content: [
47
+ {
48
+ type: 'text',
49
+ text: '<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>',
50
+ },
51
+ {
52
+ type: 'tool_use',
53
+ id: 'toolu_01A09q90qw90lq917835lq9',
54
+ name: 'get_weather',
55
+ input: { location: 'San Francisco, CA', unit: 'celsius' },
56
+ },
57
+ ],
58
+ });
59
+ const result = await provider.callApi('What is the forecast in San Francisco?');
60
+ expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
61
+ expect(provider.anthropic.messages.create).toHaveBeenNthCalledWith(1, {
62
+ model: 'claude-3-opus-20240229',
63
+ max_tokens: 1024,
64
+ messages: [
65
+ {
66
+ role: 'user',
67
+ content: [
68
+ {
69
+ text: 'What is the forecast in San Francisco?',
70
+ type: 'text',
71
+ },
72
+ ],
73
+ },
74
+ ],
75
+ tools,
76
+ temperature: 0,
77
+ stream: false,
78
+ });
79
+ expect(result).toMatchObject({
80
+ cost: undefined,
81
+ output: (0, dedent_1.default) `<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>
82
+
83
+ {"type":"tool_use","id":"toolu_01A09q90qw90lq917835lq9","name":"get_weather","input":{"location":"San Francisco, CA","unit":"celsius"}}`,
84
+ tokenUsage: {},
85
+ });
86
+ const resultFromCache = await provider.callApi('What is the forecast in San Francisco?');
87
+ expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
88
+ expect(result).toMatchObject(resultFromCache);
89
+ });
90
+ it('should pass the tool choice if specified', async () => {
91
+ const toolChoice = {
92
+ name: 'get_weather',
93
+ type: 'tool',
94
+ };
95
+ provider.config.tool_choice = toolChoice;
96
+ jest
97
+ .spyOn(provider.anthropic.messages, 'create')
98
+ .mockImplementation()
99
+ .mockResolvedValue({
100
+ content: [
101
+ {
102
+ type: 'text',
103
+ text: '<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>',
104
+ },
105
+ {
106
+ type: 'tool_use',
107
+ id: 'toolu_01A09q90qw90lq917835lq9',
108
+ name: 'get_weather',
109
+ input: { location: 'San Francisco, CA', unit: 'celsius' },
110
+ },
111
+ ],
112
+ });
113
+ const result = await provider.callApi('What is the forecast in San Francisco?');
114
+ expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
115
+ expect(provider.anthropic.messages.create).toHaveBeenNthCalledWith(1, {
116
+ model: 'claude-3-opus-20240229',
117
+ max_tokens: 1024,
118
+ messages: [
119
+ {
120
+ role: 'user',
121
+ content: [
122
+ {
123
+ text: 'What is the forecast in San Francisco?',
124
+ type: 'text',
125
+ },
126
+ ],
127
+ },
128
+ ],
129
+ tools,
130
+ tool_choice: toolChoice,
131
+ temperature: 0,
132
+ stream: false,
133
+ });
134
+ provider.config.tool_choice = undefined;
135
+ });
136
+ it('should not use cache if caching is disabled for ToolUse requests', async () => {
137
+ jest
138
+ .spyOn(provider.anthropic.messages, 'create')
139
+ .mockImplementation()
140
+ .mockResolvedValue({
141
+ content: [
142
+ {
143
+ type: 'text',
144
+ text: '<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>',
145
+ },
146
+ {
147
+ type: 'tool_use',
148
+ id: 'toolu_01A09q90qw90lq917835lq9',
149
+ name: 'get_weather',
150
+ input: { location: 'San Francisco, CA', unit: 'celsius' },
151
+ },
152
+ ],
153
+ });
154
+ (0, cache_1.disableCache)();
155
+ const result = await provider.callApi('What is the forecast in San Francisco?');
156
+ expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(1);
157
+ expect(result).toMatchObject({
158
+ output: (0, dedent_1.default) `<thinking>I need to use the get_weather, and the user wants SF, which is likely San Francisco, CA.</thinking>
159
+
160
+ {"type":"tool_use","id":"toolu_01A09q90qw90lq917835lq9","name":"get_weather","input":{"location":"San Francisco, CA","unit":"celsius"}}`,
161
+ tokenUsage: {},
162
+ });
163
+ await provider.callApi('What is the forecast in San Francisco?');
164
+ expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(2);
165
+ (0, cache_1.enableCache)();
166
+ });
167
+ it('should return cached response for legacy caching behavior', async () => {
168
+ jest
169
+ .spyOn(provider.anthropic.messages, 'create')
170
+ .mockImplementation()
171
+ .mockResolvedValue({
172
+ content: [],
173
+ });
174
+ (0, cache_1.getCache)().set('anthropic:{"model":"claude-3-opus-20240229","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"text","text":"What is the forecast in San Francisco?"}]}],"stream":false,"temperature":0,"tools":[{"name":"get_weather","description":"Get the current weather in a given location","input_schema":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}]}', 'Test output');
175
+ const result = await provider.callApi('What is the forecast in San Francisco?');
176
+ expect(result).toMatchObject({
177
+ output: 'Test output',
178
+ tokenUsage: {},
179
+ });
180
+ expect(provider.anthropic.messages.create).toHaveBeenCalledTimes(0);
181
+ });
182
+ it('should handle API call error', async () => {
183
+ const provider = new anthropic_1.AnthropicMessagesProvider('claude-3-opus-20240229');
184
+ jest
185
+ .spyOn(provider.anthropic.messages, 'create')
186
+ .mockImplementation()
187
+ .mockRejectedValue(new Error('API call failed'));
188
+ const result = await provider.callApi('What is the forecast in San Francisco?');
189
+ expect(result).toMatchObject({
190
+ error: 'API call error: Error: API call failed',
191
+ });
192
+ });
193
+ it('should return token usage and cost', async () => {
194
+ const provider = new anthropic_1.AnthropicMessagesProvider('claude-3-opus-20240229', {
195
+ config: { max_tokens: 100, temperature: 0.5, cost: 0.015 },
196
+ });
197
+ jest
198
+ .spyOn(provider.anthropic.messages, 'create')
199
+ .mockImplementation()
200
+ .mockResolvedValue({
201
+ content: [{ type: 'text', text: 'Test output' }],
202
+ usage: { input_tokens: 50, output_tokens: 50 },
203
+ });
204
+ const result = await provider.callApi('What is the forecast in San Francisco?');
205
+ expect(result).toMatchObject({
206
+ output: 'Test output',
207
+ tokenUsage: { total: 100, prompt: 50, completion: 50 },
208
+ cost: 1.5,
209
+ });
210
+ });
211
+ });
212
+ describe('AnthropicLlmRubricProvider', () => {
213
+ let provider;
214
+ beforeEach(() => {
215
+ provider = new anthropic_1.AnthropicLlmRubricProvider('claude-3-5-sonnet-20240620');
216
+ });
217
+ it('should initialize with forced tool configuration', () => {
218
+ expect(provider.modelName).toBe('claude-3-5-sonnet-20240620');
219
+ expect(provider.config.tool_choice).toEqual({ type: 'tool', name: 'grade_output' });
220
+ });
221
+ it('should call API and parse the result correctly', async () => {
222
+ const mockApiResponse = {
223
+ output: JSON.stringify({
224
+ type: 'tool_use',
225
+ id: 'test-id',
226
+ name: 'grade_output',
227
+ input: {
228
+ pass: true,
229
+ score: 0.85,
230
+ reason: 'The output meets the criteria.',
231
+ },
232
+ }),
233
+ };
234
+ jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockResolvedValue(mockApiResponse);
235
+ const result = await provider.callApi('Test prompt');
236
+ expect(result).toEqual({
237
+ output: {
238
+ pass: true,
239
+ score: 0.85,
240
+ reason: 'The output meets the criteria.',
241
+ },
242
+ });
243
+ });
244
+ it('should handle non-string API response', async () => {
245
+ const mockApiResponse = {
246
+ output: { confession: 'I am not a string' },
247
+ };
248
+ jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockResolvedValue(mockApiResponse);
249
+ const result = await provider.callApi('Test prompt');
250
+ expect(result.error).toContain('Anthropic LLM rubric grader - malformed non-string output');
251
+ });
252
+ it('should handle malformed API response', async () => {
253
+ const mockApiResponse = {
254
+ output: 'Invalid JSON',
255
+ };
256
+ jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockResolvedValue(mockApiResponse);
257
+ const result = await provider.callApi('Test prompt');
258
+ expect(result.error).toContain('Anthropic LLM rubric grader - invalid JSON');
259
+ });
260
+ it('should handle API errors', async () => {
261
+ const mockError = new Error('API Error');
262
+ jest.spyOn(anthropic_1.AnthropicMessagesProvider.prototype, 'callApi').mockRejectedValue(mockError);
263
+ await expect(provider.callApi('Test prompt')).rejects.toThrow('API Error');
264
+ });
265
+ });
266
+ describe('AnthropicCompletionProvider callApi', () => {
267
+ it('should return output for default behavior', async () => {
268
+ const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
269
+ jest.spyOn(provider.anthropic.completions, 'create').mockImplementation().mockResolvedValue({
270
+ id: 'test-id',
271
+ model: 'claude-1',
272
+ stop_reason: 'stop_sequence',
273
+ type: 'completion',
274
+ completion: 'Test output',
275
+ });
276
+ const result = await provider.callApi('Test prompt');
277
+ expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
278
+ expect(result).toMatchObject({
279
+ output: 'Test output',
280
+ tokenUsage: {},
281
+ });
282
+ });
283
+ it('should return cached output with caching enabled', async () => {
284
+ const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
285
+ jest.spyOn(provider.anthropic.completions, 'create').mockImplementation().mockResolvedValue({
286
+ id: 'test-id',
287
+ model: 'claude-1',
288
+ stop_reason: 'stop_sequence',
289
+ type: 'completion',
290
+ completion: 'Test output',
291
+ });
292
+ const result = await provider.callApi('Test prompt');
293
+ expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
294
+ expect(result).toMatchObject({
295
+ output: 'Test output',
296
+ tokenUsage: {},
297
+ });
298
+ jest.mocked(provider.anthropic.completions.create).mockClear();
299
+ const cachedResult = await provider.callApi('Test prompt');
300
+ expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(0);
301
+ expect(cachedResult).toMatchObject({
302
+ output: 'Test output',
303
+ tokenUsage: {},
304
+ });
305
+ });
306
+ it('should return fresh output with caching disabled', async () => {
307
+ const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
308
+ jest.spyOn(provider.anthropic.completions, 'create').mockImplementation().mockResolvedValue({
309
+ id: 'test-id',
310
+ model: 'claude-1',
311
+ stop_reason: 'stop_sequence',
312
+ type: 'completion',
313
+ completion: 'Test output',
314
+ });
315
+ const result = await provider.callApi('Test prompt');
316
+ expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
317
+ expect(result).toMatchObject({
318
+ output: 'Test output',
319
+ tokenUsage: {},
320
+ });
321
+ jest.mocked(provider.anthropic.completions.create).mockClear();
322
+ (0, cache_1.disableCache)();
323
+ const freshResult = await provider.callApi('Test prompt');
324
+ expect(provider.anthropic.completions.create).toHaveBeenCalledTimes(1);
325
+ expect(freshResult).toMatchObject({
326
+ output: 'Test output',
327
+ tokenUsage: {},
328
+ });
329
+ });
330
+ it('should handle API call error', async () => {
331
+ const provider = new anthropic_1.AnthropicCompletionProvider('claude-1');
332
+ jest
333
+ .spyOn(provider.anthropic.completions, 'create')
334
+ .mockImplementation()
335
+ .mockRejectedValue(new Error('API call failed'));
336
+ const result = await provider.callApi('Test prompt');
337
+ expect(result).toMatchObject({
338
+ error: 'API call error: Error: API call failed',
339
+ });
340
+ });
341
+ });
342
+ describe('calculateCost', () => {
343
+ it('should calculate cost for valid input and output tokens', () => {
344
+ const cost = (0, anthropic_1.calculateCost)('claude-3-opus-20240229', { cost: 0.015 }, 100, 200);
345
+ expect(cost).toBe(4.5); // (0.015 * 100) + (0.075 * 200)
346
+ });
347
+ it('should return undefined for missing model', () => {
348
+ const cost = (0, anthropic_1.calculateCost)('non-existent-model', { cost: 0.015 });
349
+ expect(cost).toBeUndefined();
350
+ });
351
+ it('should return undefined for missing tokens', () => {
352
+ const cost = (0, anthropic_1.calculateCost)('claude-3-opus-20240229', { cost: 0.015 });
353
+ expect(cost).toBeUndefined();
354
+ });
355
+ });
356
+ describe('outputFromMessage', () => {
357
+ it('should return an empty string for empty content array', () => {
358
+ const message = {
359
+ content: [],
360
+ id: '',
361
+ model: '',
362
+ role: 'assistant',
363
+ stop_reason: null,
364
+ stop_sequence: null,
365
+ type: 'message',
366
+ usage: {
367
+ input_tokens: 0,
368
+ output_tokens: 0,
369
+ },
370
+ };
371
+ const result = (0, anthropic_1.outputFromMessage)(message);
372
+ expect(result).toBe('');
373
+ });
374
+ it('should return text from a single text block', () => {
375
+ const message = {
376
+ content: [{ type: 'text', text: 'Hello' }],
377
+ id: '',
378
+ model: '',
379
+ role: 'assistant',
380
+ stop_reason: null,
381
+ stop_sequence: null,
382
+ type: 'message',
383
+ usage: {
384
+ input_tokens: 0,
385
+ output_tokens: 0,
386
+ },
387
+ };
388
+ const result = (0, anthropic_1.outputFromMessage)(message);
389
+ expect(result).toBe('Hello');
390
+ });
391
+ it('should concatenate text blocks without tool_use blocks', () => {
392
+ const message = {
393
+ content: [
394
+ { type: 'text', text: 'Hello' },
395
+ { type: 'text', text: 'World' },
396
+ ],
397
+ id: '',
398
+ model: '',
399
+ role: 'assistant',
400
+ stop_reason: null,
401
+ stop_sequence: null,
402
+ type: 'message',
403
+ usage: {
404
+ input_tokens: 0,
405
+ output_tokens: 0,
406
+ },
407
+ };
408
+ const result = (0, anthropic_1.outputFromMessage)(message);
409
+ expect(result).toBe('Hello\n\nWorld');
410
+ });
411
+ it('should handle content with tool_use blocks', () => {
412
+ const message = {
413
+ content: [
414
+ {
415
+ type: 'tool_use',
416
+ id: 'tool1',
417
+ name: 'get_weather',
418
+ input: { location: 'San Francisco, CA' },
419
+ },
420
+ {
421
+ type: 'tool_use',
422
+ id: 'tool2',
423
+ name: 'get_time',
424
+ input: { location: 'New York, NY' },
425
+ },
426
+ ],
427
+ id: '',
428
+ model: '',
429
+ role: 'assistant',
430
+ stop_reason: null,
431
+ stop_sequence: null,
432
+ type: 'message',
433
+ usage: {
434
+ input_tokens: 0,
435
+ output_tokens: 0,
436
+ },
437
+ };
438
+ const result = (0, anthropic_1.outputFromMessage)(message);
439
+ expect(result).toBe('{"type":"tool_use","id":"tool1","name":"get_weather","input":{"location":"San Francisco, CA"}}\n\n{"type":"tool_use","id":"tool2","name":"get_time","input":{"location":"New York, NY"}}');
440
+ });
441
+ it('should concatenate text and tool_use blocks as JSON strings', () => {
442
+ const message = {
443
+ content: [
444
+ { type: 'text', text: 'Hello' },
445
+ {
446
+ type: 'tool_use',
447
+ id: 'tool1',
448
+ name: 'get_weather',
449
+ input: { location: 'San Francisco, CA' },
450
+ },
451
+ { type: 'text', text: 'World' },
452
+ ],
453
+ id: '',
454
+ model: '',
455
+ role: 'assistant',
456
+ stop_reason: null,
457
+ stop_sequence: null,
458
+ type: 'message',
459
+ usage: {
460
+ input_tokens: 0,
461
+ output_tokens: 0,
462
+ },
463
+ };
464
+ const result = (0, anthropic_1.outputFromMessage)(message);
465
+ expect(result).toBe('Hello\n\n{"type":"tool_use","id":"tool1","name":"get_weather","input":{"location":"San Francisco, CA"}}\n\nWorld');
466
+ });
467
+ });
468
+ describe('parseMessages', () => {
469
+ it('should parse messages with user and assistant roles', () => {
470
+ const inputMessages = (0, dedent_1.default) `user: What is the weather?
471
+ assistant: The weather is sunny.`;
472
+ const { system, extractedMessages } = (0, anthropic_1.parseMessages)(inputMessages);
473
+ expect(system).toBeUndefined();
474
+ expect(extractedMessages).toMatchObject([
475
+ {
476
+ role: 'user',
477
+ content: [
478
+ {
479
+ type: 'text',
480
+ text: (0, dedent_1.default) `user: What is the weather?
481
+ assistant: The weather is sunny.`,
482
+ },
483
+ ],
484
+ },
485
+ ]);
486
+ });
487
+ it('should handle system messages', () => {
488
+ const inputMessages = (0, dedent_1.default) `system: This is a system message.
489
+ user: What is the weather?
490
+ assistant: The weather is sunny.`;
491
+ const { system, extractedMessages } = (0, anthropic_1.parseMessages)(inputMessages);
492
+ expect(system).toBeUndefined();
493
+ expect(extractedMessages).toMatchObject([
494
+ {
495
+ role: 'user',
496
+ content: [
497
+ {
498
+ type: 'text',
499
+ text: (0, dedent_1.default) `system: This is a system message.
500
+ user: What is the weather?
501
+ assistant: The weather is sunny.`,
502
+ },
503
+ ],
504
+ },
505
+ ]);
506
+ });
507
+ it('should handle empty input', () => {
508
+ const inputMessages = '';
509
+ const { system, extractedMessages } = (0, anthropic_1.parseMessages)(inputMessages);
510
+ expect(system).toBeUndefined();
511
+ expect(extractedMessages).toMatchObject([
512
+ {
513
+ role: 'user',
514
+ content: [{ type: 'text', text: '' }],
515
+ },
516
+ ]);
517
+ });
518
+ });
519
+ });
520
+ //# sourceMappingURL=providers.anthropic.test.js.map