promptfoo 0.62.1 → 0.63.1

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 (92) hide show
  1. package/README.md +8 -5
  2. package/dist/package.json +57 -48
  3. package/dist/src/assertions.d.ts.map +1 -1
  4. package/dist/src/assertions.js +31 -8
  5. package/dist/src/assertions.js.map +1 -1
  6. package/dist/src/cache.js +1 -1
  7. package/dist/src/cache.js.map +1 -1
  8. package/dist/src/csv.d.ts.map +1 -1
  9. package/dist/src/csv.js +13 -1
  10. package/dist/src/csv.js.map +1 -1
  11. package/dist/src/evaluator.js +2 -2
  12. package/dist/src/evaluator.js.map +1 -1
  13. package/dist/src/fetch.d.ts +3 -2
  14. package/dist/src/fetch.d.ts.map +1 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js.map +1 -1
  17. package/dist/src/logger.js +1 -1
  18. package/dist/src/logger.js.map +1 -1
  19. package/dist/src/main.js +5 -31
  20. package/dist/src/main.js.map +1 -1
  21. package/dist/src/matchers.js +17 -17
  22. package/dist/src/matchers.js.map +1 -1
  23. package/dist/src/onboarding.d.ts +12 -2
  24. package/dist/src/onboarding.d.ts.map +1 -1
  25. package/dist/src/onboarding.js +398 -28
  26. package/dist/src/onboarding.js.map +1 -1
  27. package/dist/src/providers/bedrock.d.ts.map +1 -1
  28. package/dist/src/providers/bedrock.js +144 -36
  29. package/dist/src/providers/bedrock.js.map +1 -1
  30. package/dist/src/providers/huggingface.d.ts.map +1 -1
  31. package/dist/src/providers/huggingface.js.map +1 -1
  32. package/dist/src/providers/ollama.d.ts.map +1 -1
  33. package/dist/src/providers/ollama.js +9 -0
  34. package/dist/src/providers/ollama.js.map +1 -1
  35. package/dist/src/providers/openai.d.ts +1 -1
  36. package/dist/src/providers/openai.d.ts.map +1 -1
  37. package/dist/src/providers/pythonCompletion.d.ts.map +1 -1
  38. package/dist/src/providers/pythonCompletion.js.map +1 -1
  39. package/dist/src/providers/scriptCompletion.d.ts.map +1 -1
  40. package/dist/src/providers/scriptCompletion.js.map +1 -1
  41. package/dist/src/providers/vertex.d.ts +3 -3
  42. package/dist/src/providers/vertex.d.ts.map +1 -1
  43. package/dist/src/providers/vertex.js +24 -54
  44. package/dist/src/providers/vertex.js.map +1 -1
  45. package/dist/src/providers/vertexUtil.d.ts +4 -0
  46. package/dist/src/providers/vertexUtil.d.ts.map +1 -1
  47. package/dist/src/providers/vertexUtil.js +44 -1
  48. package/dist/src/providers/vertexUtil.js.map +1 -1
  49. package/dist/src/redteam/getCompetitorTests.d.ts +3 -0
  50. package/dist/src/redteam/getCompetitorTests.d.ts.map +1 -0
  51. package/dist/src/redteam/getCompetitorTests.js +68 -0
  52. package/dist/src/redteam/getCompetitorTests.js.map +1 -0
  53. package/dist/src/redteam/index.d.ts.map +1 -1
  54. package/dist/src/redteam/index.js +14 -1
  55. package/dist/src/redteam/index.js.map +1 -1
  56. package/dist/src/tableOutput.html +8 -2
  57. package/dist/src/types.d.ts +1 -1
  58. package/dist/src/types.d.ts.map +1 -1
  59. package/dist/src/util.js +3 -3
  60. package/dist/src/util.js.map +1 -1
  61. package/dist/src/web/nextui/404/index.html +1 -1
  62. package/dist/src/web/nextui/404.html +1 -1
  63. package/dist/src/web/nextui/_next/static/chunks/226-8eeb88a656092f72.js +1 -0
  64. package/dist/src/web/nextui/_next/static/chunks/7-6b1daff67cc5affb.js +32 -0
  65. package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/{page-b654fa5327065d04.js → page-4f99a1a3db60e001.js} +1 -1
  66. package/dist/src/web/nextui/_next/static/chunks/app/eval/{page-dc583966b824a0ac.js → page-ff3a23e0e056a0cc.js} +1 -1
  67. package/dist/src/web/nextui/_next/static/chunks/app/setup/page-f75709dda664e392.js +1 -0
  68. package/dist/src/web/nextui/_next/static/chunks/framework-e023a0f436413246.js +25 -0
  69. package/dist/src/web/nextui/auth/login/index.html +1 -1
  70. package/dist/src/web/nextui/auth/login/index.txt +1 -1
  71. package/dist/src/web/nextui/auth/signup/index.html +1 -1
  72. package/dist/src/web/nextui/auth/signup/index.txt +1 -1
  73. package/dist/src/web/nextui/datasets/index.html +1 -1
  74. package/dist/src/web/nextui/datasets/index.txt +1 -1
  75. package/dist/src/web/nextui/eval/index.html +1 -1
  76. package/dist/src/web/nextui/eval/index.txt +2 -2
  77. package/dist/src/web/nextui/index.html +1 -1
  78. package/dist/src/web/nextui/index.txt +1 -1
  79. package/dist/src/web/nextui/progress/index.html +1 -1
  80. package/dist/src/web/nextui/progress/index.txt +1 -1
  81. package/dist/src/web/nextui/prompts/index.html +1 -1
  82. package/dist/src/web/nextui/prompts/index.txt +1 -1
  83. package/dist/src/web/nextui/setup/index.html +1 -1
  84. package/dist/src/web/nextui/setup/index.txt +2 -2
  85. package/package.json +57 -48
  86. package/dist/src/web/nextui/_next/static/chunks/226-023620d1bff22d99.js +0 -1
  87. package/dist/src/web/nextui/_next/static/chunks/525-014890ddea6714cf.js +0 -32
  88. package/dist/src/web/nextui/_next/static/chunks/app/setup/page-bab30b8e8c1e30f8.js +0 -1
  89. package/dist/src/web/nextui/_next/static/chunks/framework-b292a8c542627b4d.js +0 -25
  90. /package/dist/src/web/nextui/_next/static/{sgzwM0-e5LLzjj48n4_x5 → bXPEnP7-ceSkOgVkRNu6x}/_buildManifest.js +0 -0
  91. /package/dist/src/web/nextui/_next/static/{sgzwM0-e5LLzjj48n4_x5 → bXPEnP7-ceSkOgVkRNu6x}/_ssgManifest.js +0 -0
  92. /package/dist/src/web/nextui/_next/static/chunks/{main-850014bd889b28b2.js → main-a0f072bd67a01e59.js} +0 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "promptfoo",
3
3
  "description": "LLM eval & testing toolkit",
4
4
  "author": "Ian Webster",
5
- "version": "0.62.1",
5
+ "version": "0.63.1",
6
6
  "license": "MIT",
7
7
  "type": "commonjs",
8
8
  "repository": "promptfoo/promptfoo",
@@ -31,20 +31,21 @@
31
31
  "scripts": {
32
32
  "bin": "dist/src/main.js",
33
33
  "tsc": "tsc",
34
+ "lint": "eslint . --max-warnings=0",
34
35
  "local": "ts-node --cwdMode --transpileOnly src/main.ts",
35
- "local:web": "cd src/web/nextui && npm run dev",
36
- "install:nextui": "cd src/web/nextui && npm install",
37
- "build:clean": "rm -rf dist",
38
- "build:nextui": "cd src/web/nextui && npm run build && { [ -z \"$NEXT_PUBLIC_PROMPTFOO_BUILD_STANDALONE_SERVER\" ] && cp -r out/ ../../../dist/src/web/nextui; } || true",
36
+ "local:web": "npm run dev --prefix src/web/nextui",
37
+ "install:nextui": "npm install --prefix src/web/nextui",
38
+ "build:clean": "shx rm -rf dist",
39
+ "build:nextui": "sh src/web/nextui/build.sh",
39
40
  "build:watch": "tsc --watch",
40
- "build": "tsc && cp src/*.html dist/src && cp src/python/wrapper.py dist/src/python && rm -rf dist/drizzle && cp -r drizzle/ dist/drizzle && npm run build:nextui && chmod +x dist/src/main.js",
41
+ "build": "tsc && shx cp src/*.html dist/src && shx cp src/python/wrapper.py dist/src/python && shx rm -rf dist/drizzle && shx cp -r drizzle dist/drizzle && npm run build:nextui && shx chmod +x dist/src/main.js",
41
42
  "test": "jest",
42
43
  "test:watch": "jest --watch",
43
44
  "format": "prettier -w .",
44
45
  "format:check": "prettier --check .",
45
46
  "db:migrate": "npx tsx src/migrate.ts",
46
47
  "db:generate": "npx drizzle-kit generate:sqlite",
47
- "audit:fix": "npm audit fix && cd src/web/nextui && npm audit fix && cd ../../site && npm audit fix",
48
+ "audit:fix": "npm audit fix && npm audit fix --prefix src/web/nextui && npm audit fix --prefix site",
48
49
  "prepublishOnly": "npm run build:clean && npm run build"
49
50
  },
50
51
  "peerDependencies": {
@@ -57,77 +58,85 @@
57
58
  "langfuse": "^3.7.0"
58
59
  },
59
60
  "devDependencies": {
60
- "@aws-sdk/client-bedrock-runtime": "^3.458.0",
61
- "@azure/identity": "^4.0.0",
62
- "@types/async": "^3.2.20",
61
+ "@aws-sdk/client-bedrock-runtime": "^3.592.0",
62
+ "@azure/identity": "^4.2.0",
63
+ "@eslint/js": "^9.4.0",
64
+ "@swc/cli": "^0.3.12",
65
+ "@swc/core": "^1.5.27",
66
+ "@swc/jest": "^0.2.36",
67
+ "@types/async": "^3.2.24",
63
68
  "@types/better-sqlite3": "^7.6.10",
64
- "@types/cache-manager": "^4.0.2",
65
- "@types/cache-manager-fs-hash": "^0.0.1",
66
- "@types/cli-progress": "^3.11.0",
67
- "@types/compression": "^1.7.2",
68
- "@types/cors": "^2.8.13",
69
- "@types/debounce": "^1.2.1",
70
- "@types/express": "^4.17.17",
69
+ "@types/cache-manager": "^4.0.6",
70
+ "@types/cache-manager-fs-hash": "^0.0.4",
71
+ "@types/cli-progress": "^3.11.5",
72
+ "@types/compression": "^1.7.5",
73
+ "@types/cors": "^2.8.17",
74
+ "@types/debounce": "^1.2.4",
75
+ "@types/eslint__js": "^8.42.3",
76
+ "@types/express": "^4.17.21",
71
77
  "@types/glob": "^8.1.0",
72
- "@types/jest": "^29.5.1",
73
- "@types/js-yaml": "^4.0.5",
74
- "@types/node-fetch": "^2.6.4",
75
- "@types/nunjucks": "^3.2.2",
76
- "@types/opener": "^1.4.0",
77
- "@types/semver": "^7.5.0",
78
- "@types/uuid": "^9.0.2",
79
- "babel-jest": "^29.5.0",
80
- "cloudflare": "^3.2.0",
78
+ "@types/inquirer": "^9.0.7",
79
+ "@types/jest": "^29.5.12",
80
+ "@types/js-yaml": "^4.0.9",
81
+ "@types/node-fetch": "^2.6.11",
82
+ "@types/nunjucks": "^3.2.6",
83
+ "@types/opener": "^1.4.3",
84
+ "@types/semver": "^7.5.8",
85
+ "@types/uuid": "^9.0.8",
81
86
  "check-dependency-version-consistency": "^4.1.0",
87
+ "cloudflare": "^3.2.0",
82
88
  "drizzle-kit": "^0.20.13",
83
- "jest": "^29.5.0",
89
+ "eslint": "^8.57.0",
90
+ "jest": "^29.7.0",
84
91
  "jest-watch-typeahead": "^2.2.2",
85
92
  "next": "13.4.13",
86
- "prettier": "^2.8.8",
87
- "ts-jest": "^29.1.0",
88
- "ts-node": "^10.9.1",
89
- "typescript": "^5.1.6"
93
+ "prettier": "^3.3.1",
94
+ "shx": "^0.3.4",
95
+ "ts-node": "^10.9.2",
96
+ "typescript": "^5.4.5",
97
+ "typescript-eslint": "^7.12.0"
90
98
  },
91
99
  "dependencies": {
92
100
  "@anthropic-ai/sdk": "^0.20.1",
93
- "@apidevtools/json-schema-ref-parser": "^10.1.0",
94
- "ajv": "^8.14.0",
101
+ "@apidevtools/json-schema-ref-parser": "^11.6.4",
102
+ "ajv": "^8.16.0",
95
103
  "ajv-formats": "^2.1.1",
96
- "async": "^3.2.4",
104
+ "async": "^3.2.5",
97
105
  "better-sqlite3": "^10.1.0",
98
106
  "cache-manager": "^4.1.0",
99
107
  "cache-manager-fs-hash": "^1.0.0",
100
108
  "chalk": "^4.1.2",
101
- "chokidar": "^3.5.3",
109
+ "chokidar": "^3.6.0",
102
110
  "cli-progress": "^3.12.0",
103
- "cli-table3": "^0.6.3",
111
+ "cli-table3": "^0.6.5",
104
112
  "commander": "^10.0.1",
105
113
  "compression": "^1.7.4",
106
114
  "cors": "^2.8.5",
107
- "csv-parse": "^5.5.3",
108
- "csv-stringify": "^6.3.2",
115
+ "csv-parse": "^5.5.6",
116
+ "csv-stringify": "^6.5.0",
109
117
  "debounce": "^1.2.1",
110
118
  "dedent": "^1.5.3",
111
119
  "dotenv": "^16.4.5",
112
120
  "drizzle-orm": "^0.29.3",
113
- "express": "^4.18.2",
121
+ "express": "^4.19.2",
114
122
  "fast-deep-equal": "^3.1.3",
115
123
  "fastest-levenshtein": "^1.0.16",
116
- "glob": "^10.2.6",
124
+ "glob": "^10.4.1",
125
+ "inquirer": "^8.2.6",
117
126
  "js-yaml": "^4.1.0",
118
127
  "mathjs": "^12.4.1",
119
128
  "node-fetch": "^2.6.7",
120
129
  "nunjucks": "^3.2.4",
121
- "openai": "^4.38.5",
130
+ "openai": "^4.49.1",
122
131
  "opener": "^1.5.2",
123
- "proxy-agent": "^6.3.1",
132
+ "proxy-agent": "^6.4.0",
124
133
  "python-shell": "^5.0.0",
125
- "replicate": "^0.27.1",
134
+ "replicate": "^0.30.1",
126
135
  "rouge": "git+https://github.com/kenlimmj/rouge.git#f35111b599aca55f1d4dc1d4a3d15e28e7f7c55f",
127
- "semver": "^7.5.3",
128
- "socket.io": "^4.7.2",
129
- "tiny-invariant": "^1.3.1",
130
- "uuid": "^9.0.0",
131
- "winston": "^3.8.2"
136
+ "semver": "^7.6.2",
137
+ "socket.io": "^4.7.5",
138
+ "tiny-invariant": "^1.3.3",
139
+ "uuid": "^9.0.1",
140
+ "winston": "^3.13.0"
132
141
  }
133
142
  }
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[226],{9532:function(e,t,n){"use strict";let s,l;async function a(){if(s||(l||(l=fetch("/api/config").then(e=>e.json()).then(e=>s=e.apiBaseUrl)),await l),void 0===s)throw Error("API base URL is undefined");return s}n.d(t,{b:function(){return a}})},4226:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return eq}});var s=n(4004),l=n(4978),a=n(3179),i=n(1615),r=n(4997),o=n(8891),c=n(2594),d=n(3205),u=n(8873),p=n(1358),h=n(982),m=n(4362),x=n(5101),g=n(4931),j=n(9813),v=n(3147),f=n(1852),b=n(4941),y=n(7027),Z=n(2324),C=n(6976),w=n(8508),k=n(4304),S=n(5307),N=n(7178),R=n(2414),E=n(7339),I=n(5969),P=n(2610),O=n(4059),T=n(3223),F=n(4235),M=n(8931),D=n(9794),L=n(1956),U=n(9685),A=n(4595);let W=(0,U.Ue)()((0,A.tJ)((e,t)=>({evalId:null,setEvalId:t=>e(()=>({evalId:t})),table:null,setTable:t=>e(()=>({table:t})),config:null,setConfig:t=>e(()=>({config:t})),maxTextLength:250,setMaxTextLength:t=>e(()=>({maxTextLength:t})),wordBreak:"break-word",setWordBreak:t=>e(()=>({wordBreak:t})),showInferenceDetails:!0,setShowInferenceDetails:t=>e(()=>({showInferenceDetails:t})),renderMarkdown:!1,setRenderMarkdown:t=>e(()=>({renderMarkdown:t})),prettifyJson:!1,setPrettifyJson:t=>e(()=>({prettifyJson:t})),showPrompts:!1,setShowPrompts:t=>e(()=>({showPrompts:t}))}),{name:"ResultsViewStorage",storage:(0,A.FL)(()=>localStorage)}));var _=function(){let{table:e,config:t,evalId:n}=W(),[a,i]=l.useState(!1),r=(e,t)=>{let n=URL.createObjectURL(e),s=document.createElement("a");s.href=n,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(n)},o=()=>{i(!1)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(C.Z,{onClick:()=>{i(!0)},children:[(0,s.jsx)(y.Z,{children:(0,s.jsx)(M.Z,{fontSize:"small"})}),(0,s.jsx)(b.Z,{children:"Download"})]}),(0,s.jsx)(D.Z,{onClose:o,open:a,children:(0,s.jsx)(L.Z,{children:(0,s.jsxs)(R.Z,{direction:"column",spacing:2,sx:{width:"100%"},children:[(0,s.jsx)(h.Z,{onClick:()=>{let e=F.default.dump(t),n=new Blob([e],{type:"text/yaml;charset=utf-8"});r(n,"promptfooconfig.yaml"),o()},startIcon:(0,s.jsx)(M.Z,{}),fullWidth:!0,sx:{justifyContent:"flex-start"},children:"Download YAML Config"}),(0,s.jsx)(h.Z,{onClick:()=>{if(!e){alert("No table data");return}let t=new Blob([JSON.stringify(e,null,2)],{type:"application/json"});r(t,"".concat(n,"-table.json")),o()},startIcon:(0,s.jsx)(M.Z,{}),fullWidth:!0,sx:{justifyContent:"flex-start"},children:"Download Table JSON"}),(0,s.jsx)(h.Z,{onClick:()=>{if(!e){alert("No table data");return}let t=e.body.map((t,n)=>({chosen:t.outputs.filter(e=>e.pass).map(e=>e.text),rejected:t.outputs.filter(e=>!e.pass).map(e=>e.text),vars:t.test.vars,providers:e.head.prompts.map(e=>e.provider),prompts:e.head.prompts.map(e=>e.label||e.display||e.raw)})),s=new Blob([JSON.stringify(t,null,2)],{type:"application/json"});r(s,"".concat(n,"-dpo.json")),o()},startIcon:(0,s.jsx)(M.Z,{}),fullWidth:!0,sx:{justifyContent:"flex-start"},children:"Download DPO JSON"})]})})})]})},z=n(6001),V=n(2669),B=n(2863),J=n(7803),H=n(7656),G=n(2715),X=n(9179);let Y=["#fd7f6f","#7eb0d5","#b2e061","#bd7ebe","#ffb55a","#ffee65","#beb9db","#fdcce5","#8bd3c7"];function q(e){let{table:t}=e,n=(0,l.useRef)(null),a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{if(!n.current)return;a.current&&a.current.destroy();let e=t.body.flatMap(e=>e.outputs.map(e=>e.score)),s=Math.min(...e),l=(Math.ceil(Math.max(...e))-Math.floor(s))/10,i=Array.from({length:11},(e,t)=>parseFloat((Math.floor(s)+t*l).toFixed(2))),r=t.head.prompts.map((e,n)=>{let s=t.body.flatMap(e=>e.outputs[n].score),a=i.map(e=>s.filter(t=>t>=e&&t<e+l).length);return{label:"Column ".concat(n+1),data:a,backgroundColor:Y[n%Y.length]}});a.current=new z.kL(n.current,{type:"bar",data:{labels:i,datasets:r},options:{animation:!1,plugins:{title:{display:!0,text:"Score Distribution"},legend:{display:!1},tooltip:{callbacks:{title:function(e){let t=e[0].datasetIndex;return"Column ".concat(t+1)},label:function(e){let t=e.dataIndex,n=i[t],s=i[t+1];return s?"".concat(n," <= score < ").concat(s):"".concat(n," <= score")}}}}}})},[t]),(0,s.jsx)("canvas",{ref:n,style:{maxHeight:"300px"}})}function $(e){let{table:t}=e,n=(0,l.useRef)(null),a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{if(!n.current)return;a.current&&a.current.destroy();let e=t.head.prompts.map((e,n)=>{let s=t.body.flatMap(e=>e.outputs[n]),l=s.filter(e=>e.pass).length,a=l/s.length*100;return{label:"Column ".concat(n+1),data:[a],backgroundColor:Y[n%Y.length]}});a.current=new z.kL(n.current,{type:"bar",data:{labels:["Pass Rate (%)"],datasets:e},options:{animation:!1,plugins:{title:{display:!0,text:"Pass rate"},legend:{display:!0}}}})},[t]),(0,s.jsx)("canvas",{ref:n,style:{maxHeight:"300px"}})}function K(e){let{table:t}=e,n=(0,l.useRef)(null),a=(0,l.useRef)(null),[i,r]=(0,l.useState)(0),[o,c]=(0,l.useState)(1),[d,u]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{if(!n.current)return;a.current&&a.current.destroy();let e=t.body.flatMap(e=>e.outputs.map(e=>e.score)),s=Math.min(...e),l=Math.max(...e),r=t.body.map(e=>{let t=e.outputs[i].score,n=e.outputs[o].score;return{x:t,y:n,backgroundColor:n>t?"green":n<t?"red":"gray"}});a.current=new z.kL(n.current,{type:"scatter",data:{datasets:[{data:r,backgroundColor:r.map(e=>e.backgroundColor)},{type:"line",data:[{x:s,y:s},{x:l,y:l}],borderColor:"gray",borderWidth:1,borderDash:[5,5],pointRadius:0}]},options:{animation:!1,plugins:{legend:{display:!1},tooltip:{callbacks:{label:function(e){let n=t.body[e.dataIndex],s=n.outputs[0].text,l=n.outputs[1].text;return s.length>30&&(s=s.substring(0,30)+"..."),l.length>30&&(l=l.substring(0,30)+"..."),"Output 1: ".concat(s,"\nOutput 2: ").concat(l)}}}},scales:{x:{title:{display:!0,text:"Prompt ".concat(i+1," Score")},ticks:{callback:function(e,t,n){let s=String(Math.round(100*Number(e)));return t===n.length-1&&(s+="%"),s}}},y:{title:{display:!0,text:"Prompt ".concat(o+1," Score")},ticks:{callback:function(e,t,n){let s=String(Math.round(100*Number(e)));return t===n.length-1&&(s+="%"),s}}}}}})},[t,i,o]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(D.Z,{open:d,onClose:()=>u(!1),children:[(0,s.jsx)(V.Z,{children:"Compare prompt outputs"}),(0,s.jsxs)(L.Z,{children:[(0,s.jsx)(j.Z,{sx:{m:1,minWidth:120},children:(0,s.jsx)(k.Z,{value:i,onChange:e=>r(Number(e.target.value)),children:t.head.prompts.map((e,t)=>(0,s.jsxs)(C.Z,{value:t,children:["Prompt ",t+1]},t))})}),(0,s.jsx)(j.Z,{sx:{m:1,minWidth:120},children:(0,s.jsx)(k.Z,{value:o,onChange:e=>c(Number(e.target.value)),children:t.head.prompts.map((e,t)=>(0,s.jsxs)(C.Z,{value:t,children:["Prompt ",t+1]},t))})})]})]}),(0,s.jsx)("canvas",{ref:n,style:{maxHeight:"300px",cursor:"pointer"},onClick:()=>u(!0)})]})}function Q(e){let{table:t}=e,n=(0,l.useRef)(null),a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{var e;if(!n.current)return;a.current&&a.current.destroy();let s=Object.keys((null===(e=t.head.prompts[0].metrics)||void 0===e?void 0:e.namedScores)||{}),l=t.head.prompts.map((e,n)=>{let l=s.map(n=>{var s;let l=(null===(s=e.metrics)||void 0===s?void 0:s.namedScores[n])||0,a=Math.max(...t.head.prompts.map(e=>{var t;return(null===(t=e.metrics)||void 0===t?void 0:t.namedScores[n])||0}));return l/a});return{label:"".concat(t.head.prompts[n].provider),data:l,backgroundColor:Y[n%Y.length]}});a.current=new z.kL(n.current,{type:"bar",data:{labels:s,datasets:l},options:{scales:{x:{grid:{display:!1}},y:{ticks:{callback:function(e,t,n){let s=String(Math.round(100*Number(e)));return t===n.length-1&&(s+="%"),s}}}},plugins:{tooltip:{callbacks:{title:function(e){return e[0].dataset.label},label:function(e){let t=e.parsed.y;return"".concat(s[e.dataIndex],": ").concat((100*t).toFixed(2),"% pass rate")}}}}}})},[t]),(0,s.jsx)("canvas",{ref:n,style:{maxHeight:"300px"}})}z.kL.register(z.vn,z.ST,z.ho,z.uw,z.f$,z.ZL,z.jn,z.od,z.u,z.wL);var ee=l.memo(function(e){var t;let{columnVisibility:n}=e,a=(0,B.Z)();z.kL.defaults.color="dark"===a.palette.mode?"#aaa":"#666";let[i,r]=(0,l.useState)(!0),{table:o}=W();if(!o||!i||o.head.prompts.length<2)return null;let c=o.body.flatMap(e=>e.outputs.map(e=>e.score)),d=new Set(c);return 1===d.size?null:(0,s.jsx)(X.SV,{fallback:null,children:(0,s.jsxs)(J.Z,{style:{position:"relative",padding:a.spacing(3)},children:[(0,s.jsx)(H.Z,{style:{position:"absolute",right:0,top:0},onClick:()=>r(!1),children:(0,s.jsx)(G.Z,{})}),(0,s.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",width:"100%"},children:[(0,s.jsx)("div",{style:{width:"33%"},children:(0,s.jsx)($,{table:o})}),(0,s.jsx)("div",{style:{width:"33%"},children:d.size<=3&&Object.keys((null===(t=o.head.prompts[0].metrics)||void 0===t?void 0:t.namedScores)||{}).length>1?(0,s.jsx)(Q,{table:o}):(0,s.jsx)(q,{table:o})}),(0,s.jsx)("div",{style:{width:"33%"},children:(0,s.jsx)(K,{table:o})})]})]})})}),et=n(9116);n(4393);var en=n(459),es=n(6128),el=n(9317),ea=n(2268),ei=n(9682),er=n(8640),eo=n.n(er),ec=n(2701),ed=e=>{let{open:t,contextText:n,commentText:l,onClose:a,onSave:i,onChange:r}=e;return(0,s.jsxs)(D.Z,{open:t,onClose:a,fullWidth:!0,maxWidth:"sm",children:[(0,s.jsx)(V.Z,{children:"Edit Comment"}),(0,s.jsxs)(L.Z,{children:[(0,s.jsx)(p.Z,{sx:{backgroundColor:"#f0f0f0",padding:2,marginBottom:2},children:n}),(0,s.jsx)(E.Z,{autoFocus:!0,margin:"dense",type:"text",fullWidth:!0,multiline:!0,rows:4,value:l,onChange:e=>r(e.target.value)})]}),(0,s.jsxs)(ec.Z,{children:[(0,s.jsx)(h.Z,{onClick:i,color:"primary",variant:"contained",children:"Save"}),(0,s.jsx)(h.Z,{onClick:a,color:"primary",children:"Cancel"})]})]})};n(5974);var eu=e=>{let{lookup:t,onSearchTextChange:n}=e;return t&&Object.keys(t).length?(0,s.jsx)("div",{className:"custom-metric-container",children:Object.entries(t).map(e=>{let[t,l]=e;return t&&void 0!==l?(0,s.jsxs)("span",{onClick:()=>n&&n(t),className:n?"clickable":"",children:[t,": ",l.toFixed(2)]},t):null})}):null},ep=n(613),eh=n(5185),em=n(6110),ex=n(5068),eg=n(417),ej=n(1303),ev=n(1451),ef=n(6485),eb=n(21);function ey(e){let{gradingResults:t}=e;return t?(0,s.jsxs)(p.Z,{mt:2,children:[(0,s.jsx)(v.Z,{variant:"subtitle1",children:"Assertions"}),(0,s.jsx)(ev.Z,{children:(0,s.jsxs)(ex.Z,{children:[(0,s.jsx)(ef.Z,{children:(0,s.jsxs)(eb.Z,{children:[(0,s.jsx)(ej.Z,{style:{fontWeight:"bold"},children:"Pass"}),(0,s.jsx)(ej.Z,{style:{fontWeight:"bold"},children:"Score"}),(0,s.jsx)(ej.Z,{style:{fontWeight:"bold"},children:"Type"}),(0,s.jsx)(ej.Z,{style:{fontWeight:"bold"},children:"Value"}),(0,s.jsx)(ej.Z,{style:{fontWeight:"bold"},children:"Reason"})]})}),(0,s.jsx)(eg.Z,{children:t.map((e,t)=>{var n,l;return(0,s.jsxs)(eb.Z,{children:[(0,s.jsx)(ej.Z,{children:e.pass?"✅":"❌"}),(0,s.jsx)(ej.Z,{children:e.score.toFixed(2)}),(0,s.jsx)(ej.Z,{children:(null===(n=e.assertion)||void 0===n?void 0:n.type)||""}),(0,s.jsx)(ej.Z,{style:{whiteSpace:"pre-wrap"},children:(null===(l=e.assertion)||void 0===l?void 0:l.value)?String(e.assertion.value):"-"}),(0,s.jsx)(ej.Z,{style:{whiteSpace:"pre-wrap"},children:e.reason})]},t)})})]})})]}):null}function eZ(e){let{open:t,onClose:n,prompt:a,provider:i,output:r,gradingResults:o}=e,[c,d]=(0,l.useState)(!1);(0,l.useEffect)(()=>{d(!1)},[a]);let u=async e=>{await navigator.clipboard.writeText(e),d(!0)};return(0,s.jsxs)(D.Z,{open:t,onClose:n,fullWidth:!0,maxWidth:"lg",children:[(0,s.jsxs)(V.Z,{children:["Details",i&&": ".concat(i)]}),(0,s.jsxs)(L.Z,{children:[(0,s.jsxs)(p.Z,{mb:2,children:[(0,s.jsx)(v.Z,{variant:"subtitle1",style:{marginBottom:"1rem"},children:"Prompt"}),(0,s.jsx)(ep.u,{readOnly:!0,value:a,style:{width:"100%",padding:"0.75rem"},maxRows:20}),(0,s.jsx)(H.Z,{onClick:()=>u(a),style:{position:"absolute",right:"10px",top:"10px"},children:c?(0,s.jsx)(em.Z,{}):(0,s.jsx)(eh.Z,{})})]}),r&&(0,s.jsxs)(p.Z,{my:2,children:[(0,s.jsx)(v.Z,{variant:"subtitle1",style:{marginBottom:"1rem",marginTop:"1rem"},children:"Output"}),(0,s.jsx)(ep.u,{readOnly:!0,maxRows:20,value:r,style:{width:"100%",padding:"0.75rem"}})]}),(0,s.jsx)(ey,{gradingResults:o})]}),(0,s.jsx)(ec.Z,{children:(0,s.jsx)(h.Z,{onClick:n,children:"Close"})})]})}var eC=n(2431),ew=n(8541),ek=function(){let e=(0,B.Z)(),[t,n]=l.useState(!1),a=()=>{n(!1)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{style:{textAlign:"center",marginTop:20,marginBottom:40},children:(0,s.jsx)(h.Z,{variant:"text",color:"primary",startIcon:(0,s.jsx)(eC.Z,{}),onClick:()=>{n(!0)},children:"Generate test cases"})}),(0,s.jsxs)(D.Z,{open:t,onClose:a,children:[(0,s.jsx)(V.Z,{children:"Run on Command Line"}),(0,s.jsx)(L.Z,{children:(0,s.jsxs)(ew.Z,{children:[(0,s.jsx)("p",{children:"This feature is in beta. UI coming soon."}),(0,s.jsxs)("p",{children:["Run"," ",(0,s.jsx)(p.Z,{component:"code",sx:{backgroundColor:"dark"===e.palette.mode?"#424242":"#f0f0f0",padding:"2px 4px",borderRadius:"4px"},children:"promptfoo generate dataset"}),"to generate test cases on the command line."]})]})}),(0,s.jsx)(ec.Z,{children:(0,s.jsx)(h.Z,{onClick:a,color:"primary",children:"Close"})})]})]})},eS=n(9532);n(3207);let eN=(0,l.createContext)(void 0),eR=e=>{let{children:t}=e,[n,a]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let e=e=>{"Shift"===e.key&&a(!0)},t=e=>{"Shift"===e.key&&a(!1)};return window.addEventListener("keydown",e),window.addEventListener("keyup",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t)}},[]),(0,s.jsx)(eN.Provider,{value:n,children:t})},eE=()=>{let e=(0,l.useContext)(eN);if(void 0===e)throw Error("useShiftKey must be used within a ShiftKeyProvider");return e};function eI(e){return null===e||0===e||1===e?"":"(".concat(e.toFixed(2),")")}function eP(e){return"string"==typeof e||"number"==typeof e?e.toString().length:Array.isArray(e)?e.reduce((e,t)=>e+eP(t),0):l.isValidElement(e)&&e.props.children?l.Children.toArray(e.props.children).reduce((e,t)=>e+eP(t),0):0}let eO=l.memo(function(e){let t,{text:n,maxLength:a}=e,[i,r]=l.useState(!0),o=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if("string"==typeof e||"number"==typeof e){let n=e.toString();return n.slice(0,a-t)}if(Array.isArray(e)){let n=[],s=t;for(let t of e){let e=eP(t);if(s+e>a){n.push(o(t,s));break}n.push(t),s+=e}return n}if(l.isValidElement(e)&&e.props.children){let n=eP(e.props.children);if(n>a-t)return l.cloneElement(e,{...e.props,children:o(e.props.children,t)})}return e};t=l.isValidElement(n)||"string"==typeof n?n:JSON.stringify(n);let c=i?o(t):t,d=eP(t)>a;return(0,s.jsxs)("div",{style:{cursor:d?"pointer":"normal"},onClick:()=>{r(!i)},children:[c,i&&eP(t)>a&&(0,s.jsx)("span",{children:"..."})]})}),eT=l.memo(function(e){var t,n,a,i,r,o,c,d,u,p,h,m;let x,g,j,v,f,{output:b,maxTextLength:y,rowIndex:Z,promptIndex:C,onRating:w,firstOutput:k,showDiffs:S,searchText:N,showStats:R}=e,{renderMarkdown:E,prettifyJson:P,showPrompts:O}=W(),[T,F]=l.useState(!1),[M,D]=l.useState(!1),[L,U]=l.useState(null),A=e=>{U(e||null),D(!M)},[_,z]=l.useState(!1),[V,B]=l.useState((null===(t=b.gradingResult)||void 0===t?void 0:t.comment)||""),J=()=>{z(!0)},H="string"==typeof b.text?b.text:JSON.stringify(b.text),G=[];if(!b.pass&&H.includes("---")?H=(G=H.split("---")).slice(1).join("---"):G=[H],S&&k){let e,t="string"==typeof k.text?k.text:JSON.stringify(k.text);t.includes("---")&&(t=t.split("---").slice(1).join("---"));try{JSON.parse(t),JSON.parse(H),e=(0,et.CT)(t,H)}catch(n){e=t.includes(". ")&&H.includes(". ")?(0,et.SY)(t,H):(0,et.NV)(t,H)}x=(0,s.jsx)(s.Fragment,{children:e.map((e,t)=>e.added?(0,s.jsx)("ins",{children:e.value},t):e.removed?(0,s.jsx)("del",{children:e.value},t):(0,s.jsx)("span",{children:e.value},t))})}if(N)try{let e;let t=RegExp(N,"gi"),n=[];for(;null!==(e=t.exec(H));)n.push({start:e.index,end:t.lastIndex});x=(0,s.jsx)(s.Fragment,{children:n.length>0?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{children:H.substring(0,n[0].start)},"text-before"),n.map((e,t)=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"search-highlight",children:H.substring(e.start,e.end)},"match-"+t),(0,s.jsx)("span",{children:H.substring(e.end,n[t+1]?n[t+1].start:H.length)},"text-after-"+t)]}))]}):(0,s.jsx)("span",{children:H},"no-match")})}catch(e){console.error("Invalid regular expression:",e.message)}else if(E)x=(0,s.jsx)(en.U,{components:{img:e=>{let{src:t,alt:n}=e;return(0,s.jsx)("img",{loading:"lazy",src:t,alt:n,onClick:()=>A(t),style:{cursor:"pointer"}})}},children:H});else if(P)try{x=(0,s.jsx)("pre",{children:JSON.stringify(JSON.parse(H),null,2)})}catch(e){}let X=l.useCallback(e=>{var t;w(e,void 0,null===(t=b.gradingResult)||void 0===t?void 0:t.comment)},[w,null===(n=b.gradingResult)||void 0===n?void 0:n.comment]),Y=l.useCallback(()=>{let e=prompt("Set test score (0.0 - 1.0):",String(b.score));if(null!==e){let n=parseFloat(e);if(!isNaN(n)&&n>=0&&n<=1){var t;w(void 0,n,null===(t=b.gradingResult)||void 0===t?void 0:t.comment)}else alert("Invalid score. Please enter a value between 0.0 and 1.0.")}},[w,b.score,null===(a=b.gradingResult)||void 0===a?void 0:a.comment]),[q,$]=l.useState(!1),K=l.useCallback(()=>{navigator.clipboard.writeText(b.text),$(!0)},[b.text]);if(null===(i=b.tokenUsage)||void 0===i?void 0:i.completion){j=(0,s.jsxs)("span",{children:[Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(b.latencyMs)," ms"]});let e=b.tokenUsage.completion/(b.latencyMs/1e3);v=(0,s.jsx)("span",{children:Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e)})}if(b.cost&&(f=(0,s.jsxs)("span",{children:["$",b.cost.toPrecision(2)]})),null===(r=b.tokenUsage)||void 0===r?void 0:r.cached)g=(0,s.jsxs)("span",{children:[Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(b.tokenUsage.cached)," ","(cached)"]});else if(null===(o=b.tokenUsage)||void 0===o?void 0:o.total){let e=Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(null!==(h=b.tokenUsage.prompt)&&void 0!==h?h:0),t=Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(null!==(m=b.tokenUsage.completion)&&void 0!==m?m:0),n=Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(b.tokenUsage.total);g=(0,s.jsx)(I.Z,{title:"".concat(e," prompt tokens + ").concat(t," completion tokens = ").concat(n," total"),children:(0,s.jsxs)("span",{children:[n,("0"!==e||"0"!==t)&&" (".concat(e,"+").concat(t,")")]})})}let Q=(null===(c=b.gradingResult)||void 0===c?void 0:c.comment)&&"!highlight"!==b.gradingResult.comment?(0,s.jsx)("div",{className:"comment",onClick:J,children:b.gradingResult.comment}):null,ee=R?(0,s.jsxs)("div",{className:"cell-detail",children:[g&&(0,s.jsxs)("div",{className:"stat-item",children:[(0,s.jsx)("strong",{children:"Tokens:"})," ",g]}),j&&(0,s.jsxs)("div",{className:"stat-item",children:[(0,s.jsx)("strong",{children:"Latency:"})," ",j]}),v&&(0,s.jsxs)("div",{className:"stat-item",children:[(0,s.jsx)("strong",{children:"Tokens/Sec:"})," ",v]}),f&&(0,s.jsxs)("div",{className:"stat-item",children:[(0,s.jsx)("strong",{children:"Cost:"})," ",f]})]}):null,es=eE(),el=(0,s.jsxs)("div",{className:"cell-actions",children:[es&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"action",onClick:K,onMouseDown:e=>e.preventDefault(),children:(0,s.jsx)(I.Z,{title:"Copy output to clipboard",children:(0,s.jsx)("span",{children:q?"✅":"\uD83D\uDCCB"})})}),(0,s.jsx)("span",{className:"action",onClick:()=>{let e;V.startsWith("!highlight")?w(void 0,void 0,e=V.slice(10).trim()):w(void 0,void 0,e=("!highlight "+V).trim()),B(e)},onMouseDown:e=>e.preventDefault(),children:(0,s.jsx)(I.Z,{title:"Toggle test highlight",children:(0,s.jsx)("span",{children:"\uD83C\uDF1F"})})})]}),b.prompt&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"action",onClick:()=>{F(!0)},children:(0,s.jsx)(I.Z,{title:"View ouput and test details",children:(0,s.jsx)("span",{children:"\uD83D\uDD0E"})})}),(0,s.jsx)(eZ,{open:T,onClose:()=>{F(!1)},prompt:b.prompt,provider:b.provider,gradingResults:null===(d=b.gradingResult)||void 0===d?void 0:d.componentResults,output:H})]}),(0,s.jsx)("span",{className:"action",onClick:()=>X(!0),children:(0,s.jsx)(I.Z,{title:"Mark test passed (score 1.0)",children:(0,s.jsx)("span",{children:"\uD83D\uDC4D"})})}),(0,s.jsx)("span",{className:"action",onClick:()=>X(!1),children:(0,s.jsx)(I.Z,{title:"Mark test failed (score 0.0)",children:(0,s.jsx)("span",{children:"\uD83D\uDC4E"})})}),(0,s.jsx)("span",{className:"action",onClick:Y,children:(0,s.jsx)(I.Z,{title:"Set test score",children:(0,s.jsx)("span",{children:"\uD83D\uDD22"})})}),(0,s.jsx)("span",{className:"action",onClick:J,children:(0,s.jsx)(I.Z,{title:"Edit comment",children:(0,s.jsx)("span",{children:"✏️"})})})]}),ea={};return(null===(u=b.gradingResult)||void 0===u?void 0:u.comment)==="!highlight"&&(ea.backgroundColor="#ffffeb"),(0,s.jsxs)("div",{className:"cell",style:ea,children:[b.pass?(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{className:"status pass",children:[(0,s.jsxs)("div",{className:"pill",children:["PASS ",(0,s.jsx)("span",{className:"score",children:eI(b.score)})]}),(0,s.jsx)(eu,{lookup:b.namedScores})]})}):(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{className:"status fail",children:[(0,s.jsxs)("div",{className:"pill",children:["FAIL",b.score>0?" ":"",(0,s.jsx)("span",{className:"score",children:eI(b.score)})]}),(0,s.jsx)(eu,{lookup:b.namedScores}),(0,s.jsx)("span",{className:"fail-reason",children:null===(p=G[0])||void 0===p?void 0:p.trim().split("\n").map((e,t)=>(0,s.jsxs)(l.Fragment,{children:[e,(0,s.jsx)("br",{})]},t))})]})}),O&&k.prompt&&(0,s.jsxs)("div",{className:"prompt",children:[(0,s.jsx)("span",{className:"pill",children:"Prompt"}),b.prompt]}),(0,s.jsx)(eO,{text:x||H,maxLength:y}),Q,ee,el,M&&L&&(0,s.jsx)("div",{className:"lightbox",onClick:()=>A(),children:(0,s.jsx)("img",{src:L,alt:"Lightbox"})}),(0,s.jsx)(ed,{open:_,contextText:b.text,commentText:V,onClose:()=>{z(!1)},onSave:()=>{w(void 0,void 0,V),z(!1)},onChange:B})]})});function eF(e){let{text:t,maxLength:n,expandedText:a,resourceId:i,className:r}=e,[o,c]=l.useState(!1);return(0,s.jsxs)("div",{className:"".concat(r||""),children:[(0,s.jsx)(eO,{text:t,maxLength:n}),a&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(I.Z,{title:"View prompt",children:(0,s.jsx)("span",{className:"action",onClick:()=>{c(!0)},children:"\uD83D\uDD0E"})}),(0,s.jsx)(eZ,{open:o,onClose:()=>{c(!1)},prompt:a}),i&&(0,s.jsx)(I.Z,{title:"View other evals and datasets for this prompt",children:(0,s.jsx)("span",{className:"action",children:(0,s.jsx)(eo(),{href:"/prompts/?id=".concat(i),target:"_blank",children:(0,s.jsx)(ei.Z,{fontSize:"small"})})})})]})]})}var eM=l.memo(function(e){let{maxTextLength:t,columnVisibility:n,wordBreak:i,filterMode:r,failureFilter:o,searchText:c,showStats:d,onFailureFilterToggle:u,onSearchTextChange:x}=e,{evalId:g,table:j,setTable:f}=W();(0,a.Z)(j,"Table should be defined");let{head:b,body:y}=j,Z=l.useCallback(async(e,t,n,s,l)=>{var a;let i=[...y],r={...i[e]},o=[...r.outputs],c=null!=n?n:o[t].pass,d=void 0===s?n?1:0:s||0;o[t].pass=c,o[t].score=d;let u={...o[t].gradingResult||{},pass:c,score:d,reason:"Manual result (overrides all other grading results)",comment:l,assertion:(null===(a=o[t].gradingResult)||void 0===a?void 0:a.assertion)||null};o[t].gradingResult=u,r.outputs=o,i[e]=r;let p={head:b,body:i};f(p);try{let e=await fetch("".concat(await (0,eS.b)(),"/api/eval/").concat(g),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({table:p})});if(!e.ok)throw Error("Network response was not ok")}catch(e){console.error("Failed to update table:",e)}},[y,b,f,g]),w=Object.keys(n).length>0,S=l.useMemo(()=>{try{let e=RegExp(c,"i");return y.map((e,t)=>({...e,outputs:e.outputs.map((e,n)=>({...e,originalRowIndex:t,originalPromptIndex:n}))})).filter(t=>{let s=!0;return"failures"===r?s=t.outputs.some((e,t)=>{let s="Prompt ".concat(t+1);return o[s]&&!e.pass&&(!w||n[s])}):"different"===r?s=!t.outputs.every(e=>e.text===t.outputs[0].text):"highlights"===r&&(console.log(t.outputs[0].text),s=t.outputs.some(e=>{var t,n;return null===(n=e.gradingResult)||void 0===n?void 0:null===(t=n.comment)||void 0===t?void 0:t.startsWith("!highlight")})),!!s&&(!c||t.outputs.some(t=>{var n,s;let l="".concat(t.text," ").concat(Object.keys(t.namedScores)," ").concat((null===(n=t.gradingResult)||void 0===n?void 0:n.reason)||""," ").concat((null===(s=t.gradingResult)||void 0===s?void 0:s.comment)||"");return e.test(l)}))})}catch(e){return console.error("Invalid regular expression:",e.message),y}},[y,o,r,c,n,w]);l.useEffect(()=>{V(e=>({...e,pageIndex:0}))},[o,r,c]);let N=l.useMemo(()=>b.prompts.map((e,t)=>y.reduce((e,n)=>e+(n.outputs[t].pass?1:0),0)),[b.prompts,y]),R=l.useMemo(()=>b.prompts.map((e,t)=>y.reduce((e,n)=>{var s,l;return e+((null===(l=n.outputs[t].gradingResult)||void 0===l?void 0:null===(s=l.componentResults)||void 0===s?void 0:s.length)||0)},0)),[b.prompts,y]),I=l.useMemo(()=>b.prompts.map((e,t)=>y.reduce((e,n)=>{var s;let l=null===(s=n.outputs[t].gradingResult)||void 0===s?void 0:s.componentResults;return e+(l?l.filter(e=>e.pass).length:0)},0)),[b.prompts,y]),P=l.useMemo(()=>N.reduce((e,t,n,s)=>t>s[e]?n:e,0),[N]),O=N[P],T=l.useMemo(()=>(0,es.Cl)(),[]),{renderMarkdown:F}=W(),M=l.useMemo(()=>b.vars.length>0?[T.group({id:"vars",header:()=>(0,s.jsx)("span",{className:"font-bold",children:"Variables"}),columns:b.vars.map((e,n)=>T.accessor(e=>e.vars[n],{id:"Variable ".concat(n+1),header:()=>(0,s.jsx)(eF,{text:e,maxLength:t,className:"font-bold"}),cell:e=>{let n=e.getValue();return(0,s.jsx)("div",{className:"cell",children:F?(0,s.jsx)(en.U,{children:n}):(0,s.jsx)(eO,{text:n,maxLength:t})})},size:50}))})]:[],[T,b.vars,t,F]),D=l.useCallback((e,t)=>S[e].outputs[t],[S]),L=l.useCallback(e=>S[e].outputs[0],[S]),U=l.useMemo(()=>[T.group({id:"prompts",header:()=>(0,s.jsx)("span",{className:"font-bold",children:"Outputs"}),columns:b.prompts.map((e,n)=>T.accessor(e=>(function(e){if("string"==typeof e){let t=e.startsWith("[PASS]"),n=e;return e.startsWith("[PASS]")?n=n.slice(6):e.startsWith("[FAIL]")&&(n=n.slice(6)),{text:n,pass:t,score:t?1:0}}return e})(e.outputs[n]),{id:"Prompt ".concat(n+1),header:()=>{var l,a,i,c,p,h,g,j;let v=N[n]&&y.length?(N[n]/y.length*100).toFixed(2):"0.00",f=N[n]===O&&0!==O,b="Prompt ".concat(n+1),Z=o[b]||!1,C=d?(0,s.jsxs)("div",{className:"prompt-detail",children:[R[n]?(0,s.jsxs)("div",{children:[(0,s.jsx)("strong",{children:"Asserts:"})," ",I[n],"/",R[n]," passed"]}):null,(null===(l=e.metrics)||void 0===l?void 0:l.totalLatencyMs)?(0,s.jsxs)("div",{children:[(0,s.jsx)("strong",{children:"Avg Latency:"})," ",Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e.metrics.totalLatencyMs/y.length)," ","ms"]}):null,(null===(i=e.metrics)||void 0===i?void 0:null===(a=i.tokenUsage)||void 0===a?void 0:a.total)?(0,s.jsxs)("div",{children:[(0,s.jsx)("strong",{children:"Avg Tokens:"})," ",Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e.metrics.tokenUsage.total/y.length)]}):null,(null===(c=e.metrics)||void 0===c?void 0:c.totalLatencyMs)&&(null===(h=e.metrics)||void 0===h?void 0:null===(p=h.tokenUsage)||void 0===p?void 0:p.completion)?(0,s.jsxs)("div",{children:[(0,s.jsx)("strong",{children:"Tokens/Sec:"})," ",Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e.metrics.tokenUsage.completion/(e.metrics.totalLatencyMs/1e3))]}):null,(null===(g=e.metrics)||void 0===g?void 0:g.cost)?(0,s.jsxs)("div",{children:[(0,s.jsx)("strong",{children:"Cost:"})," $",e.metrics.cost.toPrecision(2)]}):null]}):null,w=e.provider?e.provider.split(":"):[],k=w.length>1?(0,s.jsxs)(s.Fragment,{children:[w[0],":",(0,s.jsx)("strong",{children:w.slice(1).join(":")})]}):(0,s.jsx)("strong",{children:e.provider});return(0,s.jsxs)("div",{className:"output-header",children:[(0,s.jsxs)("div",{className:"pills",children:[e.provider?(0,s.jsx)("div",{className:"provider",children:k}):null,(0,s.jsx)("div",{className:"summary",children:(0,s.jsxs)("div",{className:"highlight ".concat(f?"success":""),children:[(0,s.jsxs)("strong",{children:[v,"% passing"]})," (",N[n],"/",y.length," cases)"]})}),(null===(j=e.metrics)||void 0===j?void 0:j.namedScores)&&Object.keys(e.metrics.namedScores).length>0?(0,s.jsx)(eu,{lookup:e.metrics.namedScores,onSearchTextChange:x}):null]}),(0,s.jsx)(eF,{className:"prompt-container",text:e.label||e.display||e.raw,expandedText:e.raw,maxLength:t,resourceId:e.id}),C,"failures"===r&&(0,s.jsx)(ea.Z,{sx:{"& .MuiFormControlLabel-label":{fontSize:"0.75rem"}},control:(0,s.jsx)(m.Z,{checked:Z,onChange:e=>u(b,e.target.checked)}),label:"Show failures"})]})},cell:e=>{var l,a;let i=D(e.row.index,n);return(0,s.jsx)(eT,{output:i,maxTextLength:t,rowIndex:e.row.index,promptIndex:n,onRating:Z.bind(null,null!==(l=i.originalRowIndex)&&void 0!==l?l:e.row.index,null!==(a=i.originalPromptIndex)&&void 0!==a?a:n),firstOutput:L(e.row.index),showDiffs:"different"===r,searchText:c,showStats:d})}}))})],[T,b.prompts,N,y.length,O,o,d,R,I,t,u,r,c,D,L,Z,x]),A=l.useMemo(()=>{let e=y.some(e=>e.description);return e?{accessorFn:e=>e.description||"",id:"description",header:()=>(0,s.jsx)("span",{className:"font-bold",children:"Description"}),cell:e=>(0,s.jsx)(eO,{text:String(e.getValue()),maxLength:t}),size:50}:null},[y,t]),_=l.useMemo(()=>{let e=[];return A&&e.push(A),e.push(...M,...U),e},[A,M,U]),[z,V]=l.useState({pageIndex:0,pageSize:50}),B=(0,el.b7)({data:S,columns:_,columnResizeMode:"onChange",getCoreRowModel:(0,es.sC)(),getPaginationRowModel:(0,es.G_)(),state:{columnVisibility:n,pagination:z}});return(0,s.jsxs)("div",{children:[(0,s.jsxs)("table",{className:"results-table firefox-fix ".concat(t<=25?"compact":""),style:{wordBreak:i},children:[(0,s.jsx)("thead",{children:B.getHeaderGroups().map(e=>(0,s.jsx)("tr",{className:"header",children:e.headers.map(e=>(0,s.jsxs)("th",{colSpan:e.colSpan,style:{width:e.getSize()},children:[e.isPlaceholder?null:(0,el.ie)(e.column.columnDef.header,e.getContext()),(0,s.jsx)("div",{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),className:"resizer ".concat(e.column.getIsResizing()?"isResizing":"")})]},e.id))},e.id))}),(0,s.jsx)("tbody",{children:B.getRowModel().rows.map((e,t)=>{let n=!1;return(0,s.jsx)("tr",{children:e.getVisibleCells().map(e=>{let l=e.column.id.startsWith("Variable")||"description"===e.column.id,a=!l&&!n;return a&&(n=!0),(0,s.jsx)("td",{style:{width:e.column.getSize()},className:"".concat(l?"variable":""," ").concat(0!==t||l?"":"first-prompt-row"," ").concat(a?"first-prompt-col":""),children:(0,el.ie)(e.column.columnDef.cell,e.getContext())},e.id)})},e.id)})})]}),B.getPageCount()>1&&(0,s.jsxs)(p.Z,{className:"pagination",sx:{display:"flex",alignItems:"center",gap:2},children:[(0,s.jsx)(h.Z,{onClick:()=>{V(e=>({...e,pageIndex:Math.max(e.pageIndex-1,0)})),window.scrollTo(0,0)},disabled:0===B.getState().pagination.pageIndex,variant:"contained",children:"Previous"}),(0,s.jsxs)(v.Z,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:["Page",(0,s.jsx)(E.Z,{size:"small",type:"number",value:B.getState().pagination.pageIndex+1,onChange:e=>{let t=e.target.value?Number(e.target.value)-1:0;V(e=>({...e,pageIndex:Math.min(Math.max(t,0),B.getPageCount()-1)}))},InputProps:{style:{width:"60px",textAlign:"center"}},variant:"outlined"}),(0,s.jsxs)("span",{children:["of ",B.getPageCount()]})]}),(0,s.jsx)(h.Z,{onClick:()=>{V(e=>({...e,pageIndex:Math.min(e.pageIndex+1,B.getPageCount()-1)})),window.scrollTo(0,0)},disabled:B.getState().pagination.pageIndex+1>=B.getPageCount(),variant:"contained",children:"Next"}),(0,s.jsxs)(v.Z,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,s.jsxs)(k.Z,{value:z.pageSize,onChange:e=>{V({pageIndex:0,pageSize:Number(e.target.value)}),window.scrollTo(0,0)},displayEmpty:!0,inputProps:{"aria-label":"Results per page"},size:"small",sx:{m:1,minWidth:80},children:[(0,s.jsx)(C.Z,{value:10,children:"10"}),(0,s.jsx)(C.Z,{value:50,children:"50"}),(0,s.jsx)(C.Z,{value:100,children:"100"}),(0,s.jsx)(C.Z,{value:500,children:"500"}),(0,s.jsx)(C.Z,{value:1e3,children:"1000"})]}),(0,s.jsx)("span",{children:"results per page"})]})]}),(0,s.jsx)(ek,{})]})}),eD=n(9645);function eL(e){let{open:t,onClose:a}=e,{config:i}=W(),r=l.useRef(null),[o,c]=l.useState(!1),[d,u]=l.useState("");l.useEffect(()=>{t&&(async()=>{let{default:e}=await Promise.resolve().then(n.bind(n,4235));u(e.dump(i))})()},[t,i]);let m=()=>{c(!1),a()};return(0,s.jsxs)(D.Z,{open:t,onClose:m,"aria-labelledby":"config-dialog-title",maxWidth:"md",fullWidth:!0,children:[(0,s.jsx)(V.Z,{id:"config-dialog-title",children:(0,s.jsxs)(p.Z,{display:"flex",justifyContent:"space-between",alignItems:"center",children:[(0,s.jsx)(v.Z,{variant:"h6",style:{flexGrow:1},children:"Config"}),(0,s.jsxs)(p.Z,{children:[(0,s.jsx)(I.Z,{title:"Copy to clipboard",children:(0,s.jsx)(H.Z,{onClick:()=>{r.current&&(r.current.select(),document.execCommand("copy"),c(!0))},children:o?(0,s.jsx)(em.Z,{}):(0,s.jsx)(eD.Z,{})})}),(0,s.jsx)(I.Z,{title:"Download .yaml",children:(0,s.jsx)(H.Z,{onClick:()=>{let e=new Blob([d],{type:"text/yaml;charset=utf-8"}),t=URL.createObjectURL(e),n=document.createElement("a");n.href=t,n.download="config.yaml",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t)},children:(0,s.jsx)(M.Z,{})})})]})]})}),(0,s.jsx)(L.Z,{children:(0,s.jsx)(v.Z,{variant:"body1",component:"div",children:(0,s.jsx)("textarea",{ref:r,readOnly:!0,value:d,style:{width:"100%",minHeight:"400px",fontFamily:"monospace",border:"1px solid #ccc"}})})}),(0,s.jsx)(ec.Z,{children:(0,s.jsx)(h.Z,{onClick:m,color:"primary",children:"Close"})})]})}var eU=e=>{let{open:t,onClose:n,shareUrl:a}=e,i=(0,l.useRef)(null),[r,o]=(0,l.useState)(!1),c=()=>{n(),o(!1)};return(0,s.jsxs)(D.Z,{open:t,onClose:c,PaperProps:{style:{minWidth:"min(660px, 100%)"}},children:[(0,s.jsx)(V.Z,{children:"Your eval is ready to share"}),(0,s.jsxs)(L.Z,{children:[(0,s.jsx)(E.Z,{inputRef:i,value:a,fullWidth:!0,InputProps:{readOnly:!0,endAdornment:(0,s.jsx)(H.Z,{onClick:()=>{i.current&&(i.current.select(),document.execCommand("copy"),o(!0))},children:r?(0,s.jsx)(em.Z,{}):(0,s.jsx)(eD.Z,{})})}}),(0,s.jsx)(ew.Z,{sx:{fontSize:"0.75rem"},children:"Shared URLs are deleted after 2 weeks."})]}),(0,s.jsx)(ec.Z,{children:(0,s.jsx)(h.Z,{onClick:c,color:"primary",children:"Close"})})]})},eA=n(2695),eW=e=>{let{open:t,onClose:n}=e,{maxTextLength:l,setMaxTextLength:a,wordBreak:i,setWordBreak:r,showInferenceDetails:o,setShowInferenceDetails:c,renderMarkdown:d,setRenderMarkdown:u,prettifyJson:x,setPrettifyJson:g,showPrompts:j,setShowPrompts:f}=W();return(0,s.jsxs)(D.Z,{open:t,onClose:n,fullWidth:!0,maxWidth:"sm",children:[(0,s.jsx)(V.Z,{children:"Table View Settings"}),(0,s.jsxs)(L.Z,{children:[(0,s.jsx)(p.Z,{children:(0,s.jsx)(I.Z,{title:"Forcing line breaks makes it easier to adjust column widths to your liking",children:(0,s.jsx)(ea.Z,{control:(0,s.jsx)(m.Z,{checked:"break-all"===i,onChange:e=>r(e.target.checked?"break-all":"break-word")}),label:"Force line breaks"})})}),(0,s.jsx)(p.Z,{children:(0,s.jsx)(ea.Z,{control:(0,s.jsx)(m.Z,{checked:d,onChange:e=>u(e.target.checked)}),label:"Render model outputs as Markdown"})}),(0,s.jsx)(p.Z,{children:(0,s.jsx)(ea.Z,{control:(0,s.jsx)(m.Z,{checked:x,onChange:e=>g(e.target.checked)}),label:"Prettify JSON outputs"})}),(0,s.jsx)(p.Z,{children:(0,s.jsx)(I.Z,{title:"Show the final prompt that produced the output in each cell.",children:(0,s.jsx)(ea.Z,{control:(0,s.jsx)(m.Z,{checked:j,onChange:e=>f(e.target.checked)}),label:"Show full prompt in output cell"})})}),(0,s.jsx)(p.Z,{children:(0,s.jsx)(I.Z,{title:"Show detailed inference statistics such as latency, tokens used, cost, etc.",children:(0,s.jsx)(ea.Z,{control:(0,s.jsx)(m.Z,{checked:o,onChange:e=>c(e.target.checked)}),label:"Show inference details"})})}),(0,s.jsxs)(p.Z,{maxWidth:"sm",children:[(0,s.jsxs)(v.Z,{mt:2,children:["Max text length: ",l]}),(0,s.jsx)(eA.ZP,{min:25,max:1e3,value:l,onChange:(e,t)=>a(t)})]})]}),(0,s.jsx)(ec.Z,{children:(0,s.jsx)(h.Z,{onClick:n,children:"Close"})})]})},e_=n(7887),ez=n(7580);let eV=ez.env.NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL||ez.env.NEXT_PUBLIC_PROMPTFOO_BASE_URL||ez.env.PROMPTFOO_REMOTE_API_BASE_URL||"https://api.promptfoo.dev",eB=ez.env.NEXT_PUBLIC_PROMPTFOO_BASE_URL||ez.env.PROMPTFOO_REMOTE_APP_BASE_URL||"https://app.promptfoo.dev";n(8022);let eJ=(0,O.Z)(R.Z)(e=>{let{theme:t}=e;return{maxWidth:"100%",flexWrap:"wrap",[t.breakpoints.down("sm")]:{flexDirection:"column"}}});function eH(e){let{recentEvals:t,onRecentEvalSelected:n,defaultEvalId:r}=e,c=(0,o.useRouter)(),{table:R,config:O,setConfig:F,maxTextLength:M,wordBreak:D,showInferenceDetails:L,evalId:U}=W(),{setStateFromConfig:A}=(0,e_.o)(),[z,V]=l.useState(""),[B]=(0,T.Nr)(z,1e3),J=e=>{V(e)},[H,G]=l.useState({}),X=l.useCallback((e,t)=>{G(n=>({...n,[e]:t}))},[G]),[Y,q]=l.useState("all"),[$,K]=l.useState(!1),[Q,et]=l.useState(""),[en,es]=l.useState(!1),el=async()=>{es(!0);try{let e=await fetch("".concat(eV,"/api/eval"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:{version:2,createdAt:new Date().toISOString(),results:{table:R},config:O}})}),{id:t}=await e.json(),n="".concat(eB,"/eval/").concat(t);et(n),K(!0)}catch(e){alert("Sorry, something went wrong.")}finally{es(!1)}},[ea,ei]=l.useState(!1),[er,eo]=l.useState(!1);(0,a.Z)(R,"Table data must be loaded before rendering ResultsView");let{head:ec}=R,ed=async()=>{(0,a.Z)(O,"Config must be loaded before clicking its description");let e=window.prompt("Enter new description:",O.description);if(null!==e&&e!==O.description){let t={...O,description:e};try{let e=await fetch("".concat(await (0,eS.b)(),"/api/eval/").concat(U),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:t})});if(!e.ok)throw Error("Network response was not ok");F(t)}catch(e){console.error("Failed to update table:",e)}}},eu=async()=>{if(window.confirm("Are you sure you want to delete this evaluation?"))try{let e=await fetch("".concat(await (0,eS.b)(),"/api/eval/").concat(U),{method:"DELETE"});if(!e.ok)throw Error("Network response was not ok");c.push("/")}catch(e){console.error("Failed to delete evaluation:",e),alert("Failed to delete evaluation")}},ep=l.useMemo(()=>[...ec.vars.map((e,t)=>({value:"Variable ".concat(t+1),label:"Var ".concat(t+1,": ").concat(ec.vars[t].length>100?ec.vars[t].slice(0,97)+"...":ec.vars[t]),group:"Variables"})),...ec.prompts.map((e,t)=>{let n=ec.prompts[t],s=n.label||n.display||n.raw;return{value:"Prompt ".concat(t+1),label:"Prompt ".concat(t+1,": ").concat(s.length>100?s.slice(0,97)+"...":s),group:"Prompts"}})],[ec.vars,ec.prompts]),[eh,em]=l.useState({}),[ex,eg]=l.useState(ep.map(e=>e.value)),[ej,ev]=l.useState(null);return(0,s.jsxs)("div",{style:{marginLeft:"1rem",marginRight:"1rem"},children:[(0,s.jsx)(p.Z,{mb:2,sx:{display:"flex",alignItems:"center"},children:(0,s.jsxs)(v.Z,{variant:"h5",sx:{flexGrow:1},children:[(0,s.jsx)("span",{className:"description",onClick:ed,children:(null==O?void 0:O.description)||U})," ",(null==O?void 0:O.description)&&(0,s.jsx)("span",{className:"description-filepath",children:U})]})}),(0,s.jsx)(p.Z,{py:"md",children:(0,s.jsxs)(eJ,{direction:"row",spacing:4,alignItems:"center",children:[(0,s.jsx)(p.Z,{children:t&&t.length>0&&(0,s.jsx)(j.Z,{sx:{m:1,minWidth:200},size:"small",children:(0,s.jsx)(u.Z,{size:"small",options:t,renderOption:(e,t)=>(0,l.createElement)("li",{...e,key:t.id},t.label),style:{width:350},renderInput:e=>(0,s.jsx)(E.Z,{...e,label:"Eval run",variant:"outlined"}),defaultValue:t.find(e=>e.id===r)||t[0],onChange:(e,t)=>{t&&t.id&&n(t.id)},disableClearable:!0})})}),(0,s.jsx)(p.Z,{children:(0,s.jsxs)(j.Z,{sx:{m:1,minWidth:200,maxWidth:350},size:"small",children:[(0,s.jsx)(f.Z,{id:"visible-columns-label",children:"Columns"}),(0,s.jsx)(k.Z,{labelId:"visible-columns-label",id:"visible-columns",multiple:!0,value:ex,onChange:e=>{let{target:{value:t}}=e;eg("string"==typeof t?t.split(","):t);let n=[...ec.vars.map((e,t)=>"Variable ".concat(t+1)),...ec.prompts.map((e,t)=>"Prompt ".concat(t+1))],s={};n.forEach(e=>{s[e]=("string"==typeof t?t.split(","):t).includes(e)}),em(s)},input:(0,s.jsx)(w.Z,{label:"Visible columns"}),renderValue:e=>e.join(", "),children:ep.map(e=>(0,s.jsxs)(C.Z,{dense:!0,value:e.value,children:[(0,s.jsx)(m.Z,{checked:ex.indexOf(e.value)>-1}),(0,s.jsx)(b.Z,{primary:e.label})]},e.value))})]})}),(0,s.jsx)(p.Z,{children:(0,s.jsxs)(j.Z,{sx:{minWidth:180},size:"small",children:[(0,s.jsx)(f.Z,{id:"failure-filter-mode-label",children:"Display"}),(0,s.jsxs)(k.Z,{labelId:"filter-mode-label",id:"filter-mode",value:Y,onChange:e=>{let t=e.target.value;q(t);let n={};ec.prompts.forEach((e,s)=>{n["Prompt ".concat(s+1)]="failures"===t}),G(n)},label:"Filter",children:[(0,s.jsx)(C.Z,{value:"all",children:"Show all results"}),(0,s.jsx)(C.Z,{value:"failures",children:"Show failures only"}),(0,s.jsx)(C.Z,{value:"different",children:"Show different only"}),(0,s.jsx)(C.Z,{value:"highlights",children:"Show highlights only"})]})]})}),(0,s.jsx)(p.Z,{children:(0,s.jsx)(E.Z,{sx:{minWidth:180},size:"small",label:"Search",placeholder:"Text or regex",value:z,onChange:e=>J(e.target.value)})}),(0,s.jsx)(p.Z,{flexGrow:1}),(0,s.jsx)(p.Z,{display:"flex",justifyContent:"flex-end",children:(0,s.jsxs)(eJ,{direction:"row",spacing:2,children:[(0,s.jsx)(h.Z,{color:"primary",onClick:e=>{ev(e.currentTarget)},startIcon:(0,s.jsx)(d.Z,{}),children:"Eval actions"}),O&&(0,s.jsxs)(Z.Z,{id:"eval-actions-menu",anchorEl:ej,keepMounted:!0,open:!!ej,onClose:()=>{ev(null)},children:[(0,s.jsx)(I.Z,{title:"View the configuration that defines this eval",placement:"left",children:(0,s.jsxs)(C.Z,{onClick:()=>ei(!0),children:[(0,s.jsx)(y.Z,{children:(0,s.jsx)(P.Z,{fontSize:"small"})}),"View YAML"]})}),(0,s.jsx)(I.Z,{title:"Edit this eval in the web UI",placement:"left",children:(0,s.jsxs)(C.Z,{onClick:()=>{A(O),c.push("/setup/")},children:[(0,s.jsx)(y.Z,{children:(0,s.jsx)(g.Z,{fontSize:"small"})}),"Edit Eval"]})}),(0,s.jsx)(_,{}),(null==O?void 0:O.sharing)&&(0,s.jsx)(I.Z,{title:"Generate a unique URL that others can access",placement:"left",children:(0,s.jsxs)(C.Z,{onClick:el,disabled:en,children:[(0,s.jsx)(y.Z,{children:en?(0,s.jsx)(i.Z,{size:16}):(0,s.jsx)(N.Z,{fontSize:"small"})}),"Share"]})}),(0,s.jsx)(I.Z,{title:"Delete this eval",placement:"left",children:(0,s.jsxs)(C.Z,{onClick:eu,children:[(0,s.jsx)(y.Z,{children:(0,s.jsx)(x.Z,{fontSize:"small"})}),"Delete"]})})]}),(0,s.jsx)(I.Z,{title:"Edit table view settings",placement:"bottom",children:(0,s.jsx)(h.Z,{color:"primary",onClick:()=>eo(!0),startIcon:(0,s.jsx)(S.Z,{}),children:"Table Settings"})})]})})]})}),(0,s.jsx)(ee,{columnVisibility:eh}),(0,s.jsx)(eM,{maxTextLength:M,columnVisibility:eh,wordBreak:D,showStats:L,filterMode:Y,failureFilter:H,searchText:B,onFailureFilterToggle:X,onSearchTextChange:J}),(0,s.jsx)(eL,{open:ea,onClose:()=>ei(!1)}),(0,s.jsx)(eU,{open:$,onClose:()=>K(!1),shareUrl:Q}),(0,s.jsx)(eW,{open:er,onClose:()=>eo(!1)})]})}var eG=n(2428);async function eX(){let e=(0,c.createClientComponentClient)(),{data:{user:t}}=await e.auth.getUser();(0,a.Z)(t,"User not logged in");let{data:n,error:s}=await e.from("EvaluationResult").select("id, createdAt").eq("user_id",t.id).order("createdAt",{ascending:!1}).limit(100);return n||[]}async function eY(e){let t=(0,c.createClientComponentClient)(),{data:n,error:s}=await t.from("EvaluationResult").select("*").eq("id",e).single();return n}function eq(e){var t;let{fetchId:n,preloadedData:c,recentEvals:d,defaultEvalId:u}=e,p=(0,o.useRouter)(),{table:h,setTable:m,setConfig:x,setEvalId:g}=W(),[j,v]=l.useState(!1),[f,b]=l.useState(!1),[y,Z]=l.useState(d||[]),C=async()=>{let e=await fetch("".concat(await (0,eS.b)(),"/api/results"),{cache:"no-store"}),t=await e.json();return Z(t.data),t.data},w=l.useCallback(async e=>{let t=await fetch("".concat(await (0,eS.b)(),"/api/results/").concat(e),{cache:"no-store"}),n=await t.json();m(n.data.results.table),x(n.data.config),g(e)},[m,x,g]),k=async e=>{eG.Ox?(v(!1),p.push("/eval/remote:".concat(encodeURIComponent(e)))):p.push("/eval/?evalId=".concat(encodeURIComponent(e)))},[S,N]=l.useState(u||(null===(t=y[0])||void 0===t?void 0:t.id)),R=(0,o.useSearchParams)(),E=R?R.get("evalId"):null;return(l.useEffect(()=>{if(E){let e=async()=>{await w(E),v(!0),N(E),C()};e()}else if(c){var e;m(null===(e=c.data.results)||void 0===e?void 0:e.table),x(c.data.config),v(!0)}else if(n){let e=async()=>{var e;let t="".concat(eV,"/api/eval/").concat(n);console.log("Fetching eval from remote server",t);let s=await fetch(t);if(!s.ok){b(!0);return}let l=await s.json();m(null===(e=l.data.results)||void 0===e?void 0:e.table),x(l.data.config),v(!0)};e()}else if(eG.T8)(0,eS.b)().then(e=>{let t=(0,r.io)(e);return t.on("init",e=>{console.log("Initialized socket connection",e),v(!0),m(null==e?void 0:e.results.table),x(null==e?void 0:e.config),C().then(e=>{var t,n;N(null===(t=e[0])||void 0===t?void 0:t.id),g(null===(n=e[0])||void 0===n?void 0:n.id)})}),t.on("update",e=>{console.log("Received data update",e),m(e.results.table),x(e.config),C().then(e=>{var t;let n=null===(t=e[0])||void 0===t?void 0:t.id;n&&(N(n),g(n))})}),()=>{t.disconnect()}});else if(eG.Ox)eX().then(e=>{Z(e.map(e=>({id:e.id,label:e.createdAt}))),e.length>0&&eY(e[0].id).then(t=>{(0,a.Z)(t,"Eval not found");let n=t.results,s=t.config;N(e[0].id),m(n.table),x(s),v(!0)})});else{let e=async()=>{let e=await C();if(!(e.length>0))return(0,s.jsx)("div",{className:"notice",children:"No evals yet. Share some evals to this server and they will appear here."});{let t=await (0,eS.b)(),n=e[0].id,s=await fetch("".concat(t,"/api/results/").concat(n)),l=await s.json();m(l.data.results.table),x(l.data.config),v(!0),N(n),g(n)}};e()}},[n,m,x,g,w,c,N,E]),f)?(0,s.jsx)("div",{className:"notice",children:"404 Eval not found"}):j&&h?(0,s.jsx)(eR,{children:(0,s.jsx)(eH,{defaultEvalId:S,recentEvals:y,onRecentEvalSelected:k})}):(0,s.jsxs)("div",{className:"notice",children:[(0,s.jsx)("div",{children:(0,s.jsx)(i.Z,{size:22})}),(0,s.jsx)("div",{children:"Loading eval data"})]})}n(4455)},2428:function(e,t,n){"use strict";n.d(t,{Ox:function(){return a},T8:function(){return l},eA:function(){return i}});var s=n(7580);let l=!s.env.NEXT_PUBLIC_PROMPTFOO_BUILD_STANDALONE_SERVER,a=!!s.env.NEXT_PUBLIC_PROMPTFOO_USE_SUPABASE,i=""},7887:function(e,t,n){"use strict";n.d(t,{o:function(){return a}});var s=n(9685),l=n(4595);let a=(0,s.Ue)()((0,l.tJ)((e,t)=>({env:{},testCases:[],description:"",providers:[],prompts:[],defaultTest:{},evaluateOptions:{},setEnv:t=>e({env:t}),setTestCases:t=>e({testCases:t}),setDescription:t=>e({description:t}),setProviders:t=>e({providers:t}),setPrompts:t=>e({prompts:t}),setDefaultTest:t=>e({defaultTest:t}),setEvaluateOptions:t=>e({evaluateOptions:t}),setStateFromConfig:t=>{let n={};t.description&&(n.description=t.description||""),t.tests&&(n.testCases=t.tests),t.providers&&(n.providers=t.providers),t.prompts&&("string"==typeof t.prompts?n.prompts=[t.prompts]:Array.isArray(t.prompts)?n.prompts=t.prompts.filter(e=>"string"==typeof e&&!e.endsWith(".txt")&&!e.endsWith(".json")&&!e.endsWith(".yaml")):console.warn("Invalid prompts config",t.prompts)),t.defaultTest&&(n.defaultTest=t.defaultTest),t.evaluateOptions&&(n.evaluateOptions=t.evaluateOptions),e(n)},getTestSuite:()=>{let{description:e,testCases:n,providers:s,prompts:l,env:a}=t();return{env:a,description:e,providers:s,prompts:l,tests:n}}}),{name:"promptfoo",skipHydration:!0}))},5974:function(){},4455:function(){},3207:function(){},8022:function(){},4393:function(){}}]);