🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ui): use codemirror for text area input, highlighting/linting of prompt variables (#5296)
Marc Klingenfa75fb92451a
diff --git a/packages/shared/src/utils/stringChecks.ts b/packages/shared/src/utils/stringChecks.tsindex e74e3d5449..c66495dec7 100644--- a/packages/shared/src/utils/stringChecks.ts+++ b/packages/shared/src/utils/stringChecks.ts@@ -4,22 +4,26 @@ export function getIsCharOrUnderscore(value: string): boolean {return charOrUnderscore.test(value);}-export function extractVariables(mustacheString: string): string[] {- const mustacheRegex = /\{\{(.*?)\}\}/g;- const uniqueVariables = new Set<string>();+// Regex for valid variable names (letters, underscores, starting with letter)+export const VARIABLE_REGEX = /^[a-zA-Z][a-zA-Z_]*$/;- for (const match of mustacheString.matchAll(mustacheRegex)) {- uniqueVariables.add(match[1]);- }+// Regex to find variables in mustache syntax+export const MUSTACHE_REGEX = /{{([^}]*)}}/g;- for (const variable of uniqueVariables) {- // if validated fails, remove from set- if (!getIsCharOrUnderscore(variable)) {- uniqueVariables.delete(variable);- }- }+// Regex to find multiline variables+export const MULTILINE_VARIABLE_REGEX = /{{[^}]*\n[^}]*}}/g;++// Regex to find unclosed variables+export const UNCLOSED_VARIABLE_REGEX = /{{(?![^{]*}})/g;- return Array.from(uniqueVariables);+export function isValidVariableName(variable: string): boolean {+ return VARIABLE_REGEX.test(variable);+}++export function extractVariables(mustacheString: string): string[] {+ return Array.from(mustacheString.matchAll(MUSTACHE_REGEX))+ .map((match) => match[1])+ .filter(isValidVariableName);}export function stringifyValue(value: unknown) {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex d147a2291e..7433bcd17c 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -331,9 +331,12 @@ importers:'@codemirror/lang-json':specifier: ^6.0.1version: 6.0.1+ '@codemirror/language':+ specifier: ^6.10.1+ version: 6.10.8'@codemirror/lint':- specifier: ^6.8.0- version: 6.8.0+ specifier: ^6.4.2+ version: 6.8.4'@dnd-kit/core':specifier: ^6.1.0@@ -536,14 +539,11 @@ importers:specifier: ^10.45.0version: 10.45.2'@uiw/codemirror-theme-github':- specifier: ^4.23.0- version: 4.23.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])- '@uiw/codemirror-theme-tokyo-night':- specifier: ^4.23.5- version: 4.23.5(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])+ specifier: ^4.21.24+ version: 4.23.7(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])'@uiw/react-codemirror':- specifier: ^4.21.25- version: 4.21.25(@babel/[email protected])(@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected](@lezer/[email protected]))([email protected]([email protected]))([email protected])+ specifier: ^4.21.24+ version: 4.23.7(@babel/[email protected])(@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected](@lezer/[email protected]))([email protected]([email protected]))([email protected])ai:specifier: ^3.4.9version: 3.4.9([email protected]([email protected]))([email protected])([email protected])([email protected]([email protected]))([email protected])([email protected]([email protected]))([email protected])@@ -1695,44 +1695,29 @@ packages:'@codemirror/view': ^6.0.0'@lezer/common': ^1.0.0- '@codemirror/[email protected]':- resolution: {integrity: sha512-dO4hcF0fGT9tu1Pj1D2PvGvxjeGkbC6RGcZw6Qs74TH+Ed1gw98jmUgd2axWvIZEqTeTuFrg1lEB1KV6cK9h1A==}-'@codemirror/[email protected]':resolution: {integrity: sha512-llTrboQYw5H4THfhN4U3qCnSZ1SOJ60ohhz+SzU0ADGtwlc533DtklQP0vSFaQuCPDn3BPpOd1GbbnUtwNjsrw==}'@codemirror/[email protected]':resolution: {integrity: sha512-+T1flHdgpqDDlJZ2Lkil/rLiRy684WMLc74xUnjJH48GQdfJo/pudlTRreZmKwzP8/tGdKf83wlbAdOCzlJOGQ==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-5GrXzrhq6k+gL5fjkAwt90nYDmjlzTIJV8THnxNFtNKWotMIlzzN+CpqxqwXOECnUdOndmSeWntVrVcv5axWRQ==}-- '@codemirror/[email protected]':- resolution: {integrity: sha512-kgbTYTo0Au6dCSc/TFy7fK3fpJmgHDv1sG1KNQKJXVi+xBTEeBPY/M30YXiU6mMXeH+YIDLsbrT4ZwNRdtF+SA==}-- '@codemirror/[email protected]':- resolution: {integrity: sha512-lsFofvaw0lnPRJlQylNsC4IRt/1lI4OD/yYslrSGVndOJfStc58v+8p9dgGiD90ktOfL7OhBWns1ZETYgz0EJA==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-wcP8XPPhDH2vTqf181U8MbZnW+tDyPYy0UzVOa+oHORjyT+mhhom9vBd7dApJwoDz9Nb/a8kHjJIsuA/t8vNFw==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-PDFG5DjHxSEjOXk9TQYYVjZDqlZTFaDBfhQixHnQOEVDDNHUbEh/hstAjcQJaA6FQdZTD1hquXTK0rVBLADR1g==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-u4q7PnZlJUojeRe8FJa/njJcMctISGgPQ4PnWsd9268R4ZTtU+tfFYmwkBvgcrK2+QQ8tYFVALVb5fVJykKc5A==}'@codemirror/[email protected]':resolution: {integrity: sha512-rpMgcsh7o0GuCDUXKPvww+muLA1pDJaFrpq/CCHtpQJYz8xopu4D1hPcKRoDD0YlF8gZaqTNIRa4VRBWyhyy7Q==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-3rA9lcwciEB47ZevqvD8qgbzhM9qMb8vCcQCNmDfVRPQG4JT9mSb0Jg8H7YjKGGQcFnLN323fj9jdnG59Kx6bg==}'@codemirror/[email protected]':resolution: {integrity: sha512-F+sH0X16j/qFLMAfbciKTxVOwkdAS336b7AXTKOZhy8BR3eH/RelsnLgLFINrpST63mmN2OuwUt0W2ndUgYwUA==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-j6V48PlFC/O7ERAR5vRW5QKDdchzmyyfojDdt+zPsB0YXoWgcjlC1IWjmlYfx08aQZ3HN5BtALcgGgtSKGMe7A==}-- '@codemirror/[email protected]':- resolution: {integrity: sha512-gmqxkPALZjkgSxIeeweY/wGQXBfwTUaLs8h7OKtSwfbj9Ct3L11lD+u1sS7XHppxFQoMDiMDp07P9f3I2jWOHw==}-- '@codemirror/[email protected]':- resolution: {integrity: sha512-fo7CelaUDKWIyemw4b+J57cWuRkOu4SWCCPfNDkPvfWkGjM9D5racHQXr4EQeYCD6zEBIBxGCeaKkQo+ysl0gA==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-DZ6ONbs8qdJK0fdN7AB82CgI6tYXf4HWk1wSVa0+9bhVznCuuvhQtX8bFBoy3dv8rZSQqUd8GvhVAcielcidrA==}'@colors/[email protected]':resolution: {integrity: sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==}@@ -2451,27 +2436,21 @@ packages:peerDependencies:'@langchain/core': '>=0.2.21 <0.4.0'- '@lezer/[email protected]':- resolution: {integrity: sha512-yemX0ZD2xS/73llMZIK6KplkjIjf2EvAHcinDi/TfJ9hS25G0388+ClHt6/3but0oOxinTcQHJLDXh6w1crzFQ==}-'@lezer/[email protected]':resolution: {integrity: sha512-w7ojc8ejBqr2REPsWxJjrMFsA/ysDCFICn8zEOR9mrqzOu2amhITYuLD8ag6XZf0CFXDrhKqw7+tW8cX66NaDA==}- '@lezer/[email protected]':- resolution: {integrity: sha512-WrS5Mw51sGrpqjlh3d4/fOwpEV2Hd3YOkp9DBt4k8XZQcoTHZFB7sx030A6OcahF4J1nDQAa3jXlTVVYH50IFA==}-'@lezer/[email protected]':resolution: {integrity: sha512-Z5duk4RN/3zuVO7Jq0pGLJ3qynpxUVsh7IbUbGj88+uV2ApSAn6kWg2au3iJb+0Zi7kKtqffIESgNcRXWZWmSA==}'@lezer/[email protected]':resolution: {integrity: sha512-xHT2P4S5eeCYECyKNPhr4cbEL9tc8w83SPwRC373o9uEdrvGKTZoJVAGxpOsZckMlEh9W23Pc72ew918RWQOBQ==}- '@lezer/[email protected]':- resolution: {integrity: sha512-Wst46p51km8gH0ZUmeNrtpRYmdlRHUpN1DQd3GFAyKANi8WVz8c2jHYTf1CVScFaCjQw1iO3ZZdqGDxQPRErTg==}-'@lezer/[email protected]':resolution: {integrity: sha512-pu0K1jCIdnQ12aWNaAVU5bzi7Bd1w54J3ECgANPmYLtQKP0HBj2cE/5coBD66MT10xbtIuUr7tg0Shbsvk0mDA==}+ '@marijn/[email protected]':+ resolution: {integrity: sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==}+'@marsidev/[email protected]':resolution: {integrity: sha512-cloUDkEcJm+G7p3J8DwPtRNNB2GZqVi/nlIbgu9o3VzNyV5K/bWcSfOyWouRiR3umAQZmsFpR3OFYa4mCmy4AQ==}peerDependencies:@@ -5102,8 +5081,8 @@ packages:resolution: {integrity: sha512-9RMXwQF8knsZvfv9tdi+4D/j7dMG28X/wMJ8Jj6eOHyHWwDW4ngQJcqEczSsqIKKjFiLFr40Mnr7a5ulDD3vmw==}engines: {node: ^18.18.0 || >=20.0.0}- '@uiw/[email protected]':- resolution: {integrity: sha512-eeUKlmEE8aSoSgelS8OR2elcPGntpRo669XinAqPCLa0eKorT2B0d3ts+AE+njAeGk744tiyAEbHb2n+6OQmJw==}+ '@uiw/[email protected]':+ resolution: {integrity: sha512-9/2EUa1Lck4kFKkR2BkxlZPpgD/EWuKHnOlysf1yHKZGraaZmZEaUw+utDK4QcuJc8Iz097vsLz4f4th5EU27g==}peerDependencies:'@codemirror/autocomplete': '>=6.0.0''@codemirror/commands': '>=6.0.0'@@ -5113,28 +5092,18 @@ packages:'@codemirror/state': '>=6.0.0''@codemirror/view': '>=6.0.0'- '@uiw/[email protected]':- resolution: {integrity: sha512-1pJ9V7LQXoojfgYXgI4yn8CfaYBm9HS919xC32/rs81Wl1lhYEOhiYRmNcpnJQDu9ZMgO8ebPMgAVU21z/C76g==}+ '@uiw/[email protected]':+ resolution: {integrity: sha512-r9SstBZD7Ow1sQ8F0EpsRGx9b11K552M2FayvyLWTkal64YJmQMKW0S2KcWykgCMKLWhmDFi7LX+h8cg6nek8g==}- '@uiw/[email protected]':- resolution: {integrity: sha512-vevM3Z8ry5Ifo6IkuVm3oZzyOw1wSKI7lTjNAj7Rw7E93b+LB9JttTGKMmGV9b5kmet72MGilBP/Zs2pGdcKBw==}-- '@uiw/[email protected]':- resolution: {integrity: sha512-9fiji9xooZyBQozR1i6iTr56YP7j/Dr/VgsNWbqf5Szv+g+4WM1iZuiDGwNXmFMWX8gbkDzp6ASE21VCPSofWw==}- peerDependencies:- '@codemirror/language': '>=6.0.0'- '@codemirror/state': '>=6.0.0'- '@codemirror/view': '>=6.0.0'-- '@uiw/[email protected]':- resolution: {integrity: sha512-yWUTpaVroxIxjKASQAmKaYy+ZYtF+YB6d8sVmSRK2TVD13M+EWvVT2jBGFLqR1UVg7G0W/McAy8xdeTg+a3slg==}+ '@uiw/[email protected]':+ resolution: {integrity: sha512-UNf1XOx1hG9OmJnrtT86PxKcdcwhaNhbrcD+nsk8WxRJ3n5c8nH6euDvgVPdVLPwbizsaQcZTILACgA/FjRpVg==}peerDependencies:'@codemirror/language': '>=6.0.0''@codemirror/state': '>=6.0.0''@codemirror/view': '>=6.0.0'- '@uiw/[email protected]':- resolution: {integrity: sha512-mBrCoiffQ+hbTqV1JoixFEcH7BHXkS3PjTyNH7dE8Gzf3GSBRazhtSM5HrAFIiQ5FIRGFs8Gznc4UAdhtevMmw==}+ '@uiw/[email protected]':+ resolution: {integrity: sha512-Nh/0P6W+kWta+ARp9YpnKPD9ick5teEnwmtNoPQnyd6NPv0EQP3Ui4YmRVNj1nkUEo+QjrAUaEfcejJ2up/HZA==}peerDependencies:'@babel/runtime': '>=7.11.0''@codemirror/state': '>=6.0.0'@@ -11523,7 +11492,7 @@ snapshots:'@aws-crypto/[email protected]':dependencies:'@aws-crypto/util': 5.2.0- '@aws-sdk/types': 3.667.0+ '@aws-sdk/types': 3.679.0tslib: 2.6.3'@aws-crypto/[email protected]':@@ -11546,7 +11515,7 @@ snapshots:'@aws-crypto/sha256-js': 5.2.0'@aws-crypto/supports-web-crypto': 5.2.0'@aws-crypto/util': 5.2.0- '@aws-sdk/types': 3.667.0+ '@aws-sdk/types': 3.679.0'@aws-sdk/util-locate-window': 3.568.0'@smithy/util-utf8': 2.3.0tslib: 2.6.3@@ -11554,7 +11523,7 @@ snapshots:'@aws-crypto/[email protected]':dependencies:'@aws-crypto/util': 5.2.0- '@aws-sdk/types': 3.667.0+ '@aws-sdk/types': 3.679.0tslib: 2.6.3'@aws-crypto/[email protected]':@@ -11563,7 +11532,7 @@ snapshots:'@aws-crypto/[email protected]':dependencies:- '@aws-sdk/types': 3.667.0+ '@aws-sdk/types': 3.679.0'@smithy/util-utf8': 2.3.0tslib: 2.6.3@@ -12158,6 +12127,25 @@ snapshots:- '@aws-sdk/client-sso-oidc'- aws-crt+ '@aws-sdk/[email protected]':+ dependencies:+ '@aws-sdk/core': 3.667.0+ '@aws-sdk/credential-provider-env': 3.667.0+ '@aws-sdk/credential-provider-http': 3.667.0+ '@aws-sdk/credential-provider-process': 3.667.0+ '@aws-sdk/credential-provider-sso': 3.675.0+ '@aws-sdk/credential-provider-web-identity': 3.667.0(@aws-sdk/[email protected])+ '@aws-sdk/types': 3.667.0+ '@smithy/credential-provider-imds': 3.2.4+ '@smithy/property-provider': 3.1.7+ '@smithy/shared-ini-file-loader': 3.1.8+ '@smithy/types': 3.5.0+ tslib: 2.6.3+ transitivePeerDependencies:+ - '@aws-sdk/client-sso-oidc'+ - aws-crt+ optional: true+'@aws-sdk/[email protected](@aws-sdk/[email protected](@aws-sdk/[email protected]))(@aws-sdk/[email protected])':dependencies:'@aws-sdk/client-sts': 3.668.0@@ -12219,10 +12207,10 @@ snapshots:dependencies:'@aws-sdk/credential-provider-env': 3.667.0'@aws-sdk/credential-provider-http': 3.667.0- '@aws-sdk/credential-provider-ini': 3.675.0(@aws-sdk/[email protected](@aws-sdk/[email protected]))(@aws-sdk/[email protected])+ '@aws-sdk/credential-provider-ini': 3.675.0'@aws-sdk/credential-provider-process': 3.667.0- '@aws-sdk/credential-provider-sso': 3.675.0(@aws-sdk/[email protected](@aws-sdk/[email protected]))- '@aws-sdk/credential-provider-web-identity': 3.667.0(@aws-sdk/[email protected])+ '@aws-sdk/credential-provider-sso': 3.675.0+ '@aws-sdk/credential-provider-web-identity': 3.667.0(@aws-sdk/[email protected])'@aws-sdk/types': 3.667.0'@smithy/credential-provider-imds': 3.2.4'@smithy/property-provider': 3.1.7@@ -12296,6 +12284,21 @@ snapshots:- '@aws-sdk/client-sso-oidc'- aws-crt+ '@aws-sdk/[email protected]':+ dependencies:+ '@aws-sdk/client-sso': 3.675.0+ '@aws-sdk/core': 3.667.0+ '@aws-sdk/token-providers': 3.667.0(@aws-sdk/[email protected](@aws-sdk/[email protected]))+ '@aws-sdk/types': 3.667.0+ '@smithy/property-provider': 3.1.7+ '@smithy/shared-ini-file-loader': 3.1.8+ '@smithy/types': 3.5.0+ tslib: 2.6.3+ transitivePeerDependencies:+ - '@aws-sdk/client-sso-oidc'+ - aws-crt+ optional: true+dependencies:'@aws-sdk/client-sso': 3.675.0@@ -12713,7 +12716,7 @@ snapshots:'@babel/traverse': 7.24.1'@babel/types': 7.24.0convert-source-map: 2.0.0- debug: 4.3.7([email protected])+ debug: 4.3.7gensync: 1.0.0-beta.2json5: 2.2.3semver: 6.3.1@@ -12936,7 +12939,7 @@ snapshots:'@babel/helper-split-export-declaration': 7.22.6'@babel/parser': 7.24.1'@babel/types': 7.24.0- debug: 4.3.7([email protected])+ debug: 4.3.7globals: 11.12.0transitivePeerDependencies:- supports-color@@ -12948,7 +12951,7 @@ snapshots:'@babel/parser': 7.26.2'@babel/template': 7.25.9'@babel/types': 7.26.0- debug: 4.3.7([email protected])+ debug: 4.3.7globals: 11.12.0transitivePeerDependencies:- supports-color@@ -13026,92 +13029,60 @@ snapshots:dependencies:'@clickhouse/client-common': 1.4.0- '@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])':+ '@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])':dependencies:- '@codemirror/language': 6.10.2- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/language': 6.10.8+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2'@lezer/common': 1.2.3- '@codemirror/[email protected]':- dependencies:- '@codemirror/language': 6.10.1- '@codemirror/state': 6.4.1- '@codemirror/view': 6.26.2- '@lezer/common': 1.2.1-'@codemirror/[email protected]':dependencies:- '@codemirror/language': 6.10.2- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/language': 6.10.8+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2'@lezer/common': 1.2.3'@codemirror/[email protected]':dependencies:- '@codemirror/language': 6.10.1+ '@codemirror/language': 6.10.8'@lezer/json': 1.0.2- '@codemirror/[email protected]':- dependencies:- '@codemirror/state': 6.4.1- '@codemirror/view': 6.26.2- '@lezer/common': 1.2.1- '@lezer/highlight': 1.2.0- '@lezer/lr': 1.4.0- style-mod: 4.1.2-- '@codemirror/[email protected]':+ '@codemirror/[email protected]':dependencies:- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2'@lezer/common': 1.2.3'@lezer/highlight': 1.2.1'@lezer/lr': 1.4.2style-mod: 4.1.2- '@codemirror/[email protected]':+ '@codemirror/[email protected]':dependencies:- '@codemirror/state': 6.4.1- '@codemirror/view': 6.26.3- crelt: 1.0.6-- '@codemirror/[email protected]':- dependencies:- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2crelt: 1.0.6'@codemirror/[email protected]':dependencies:- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2crelt: 1.0.6- '@codemirror/[email protected]': {}+ '@codemirror/[email protected]':+ dependencies:+ '@marijn/find-cluster-break': 1.0.2'@codemirror/[email protected]':dependencies:- '@codemirror/language': 6.10.2- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/language': 6.10.8+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2'@lezer/highlight': 1.2.1- '@codemirror/[email protected]':- dependencies:- '@codemirror/state': 6.4.1- style-mod: 4.1.2- w3c-keyname: 2.2.8-- '@codemirror/[email protected]':+ '@codemirror/[email protected]':dependencies:- '@codemirror/state': 6.4.1- style-mod: 4.1.2- w3c-keyname: 2.2.8-- '@codemirror/[email protected]':- dependencies:- '@codemirror/state': 6.4.1+ '@codemirror/state': 6.5.1style-mod: 4.1.2w3c-keyname: 2.2.8@@ -13439,7 +13410,7 @@ snapshots:'@eslint/[email protected]':dependencies:ajv: 6.12.6- debug: 4.3.7([email protected])+ debug: 4.3.7espree: 9.6.1globals: 13.24.0ignore: 5.3.1@@ -13543,7 +13514,7 @@ snapshots:'@humanwhocodes/[email protected]':dependencies:'@humanwhocodes/object-schema': 2.0.2- debug: 4.3.7([email protected])+ debug: 4.3.7minimatch: 3.1.2transitivePeerDependencies:- supports-color@@ -13561,7 +13532,7 @@ snapshots:'@antfu/install-pkg': 0.4.1'@antfu/utils': 0.7.10'@iconify/types': 2.0.0- debug: 4.3.7([email protected])+ debug: 4.3.7kolorist: 1.8.0local-pkg: 0.5.0mlly: 1.7.1@@ -13949,32 +13920,24 @@ snapshots:'@langchain/core': 0.3.18([email protected]([email protected]))js-tiktoken: 1.0.15- '@lezer/[email protected]': {}-'@lezer/[email protected]': {}- '@lezer/[email protected]':- dependencies:- '@lezer/common': 1.2.1-'@lezer/[email protected]':dependencies:'@lezer/common': 1.2.3'@lezer/[email protected]':dependencies:- '@lezer/common': 1.2.1- '@lezer/highlight': 1.2.0- '@lezer/lr': 1.4.0-- '@lezer/[email protected]':- dependencies:- '@lezer/common': 1.2.1+ '@lezer/common': 1.2.3+ '@lezer/highlight': 1.2.1+ '@lezer/lr': 1.4.2'@lezer/[email protected]':dependencies:'@lezer/common': 1.2.3+ '@marijn/[email protected]': {}+dependencies:react: 18.2.0@@ -16879,7 +16842,7 @@ snapshots:'@types/[email protected]':dependencies:- '@types/node': 20.14.8+ '@types/node': 20.10.5optional: true'@typescript-eslint/[email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])':@@ -16959,7 +16922,7 @@ snapshots:dependencies:'@typescript-eslint/typescript-estree': 6.21.0([email protected])'@typescript-eslint/utils': 6.21.0([email protected])([email protected])- debug: 4.3.7([email protected])+ debug: 4.3.7eslint: 8.57.0ts-api-utils: 1.3.0([email protected])optionalDependencies:@@ -16971,7 +16934,7 @@ snapshots:dependencies:'@typescript-eslint/typescript-estree': 7.3.1([email protected])'@typescript-eslint/utils': 7.3.1([email protected])([email protected])- debug: 4.3.7([email protected])+ debug: 4.3.7eslint: 8.57.0ts-api-utils: 1.3.0([email protected])optionalDependencies:@@ -17005,7 +16968,7 @@ snapshots:dependencies:'@typescript-eslint/types': 6.21.0'@typescript-eslint/visitor-keys': 6.21.0- debug: 4.3.7([email protected])+ debug: 4.3.7globby: 11.1.0is-glob: 4.0.3minimatch: 9.0.3@@ -17020,7 +16983,7 @@ snapshots:dependencies:'@typescript-eslint/types': 7.12.0'@typescript-eslint/visitor-keys': 7.12.0- debug: 4.3.7([email protected])+ debug: 4.3.7globby: 11.1.0is-glob: 4.0.3minimatch: 9.0.5@@ -17035,7 +16998,7 @@ snapshots:dependencies:'@typescript-eslint/types': 7.3.1'@typescript-eslint/visitor-keys': 7.3.1- debug: 4.3.7([email protected])+ debug: 4.3.7globby: 11.1.0is-glob: 4.0.3minimatch: 9.0.3@@ -17109,52 +17072,38 @@ snapshots:'@typescript-eslint/types': 7.3.1eslint-visitor-keys: 3.4.3- '@uiw/[email protected](@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':+ '@uiw/[email protected](@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':dependencies:- '@codemirror/autocomplete': 6.17.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])- '@codemirror/commands': 6.3.3- '@codemirror/language': 6.10.2- '@codemirror/lint': 6.8.0+ '@codemirror/autocomplete': 6.17.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ '@codemirror/commands': 6.7.1+ '@codemirror/language': 6.10.8+ '@codemirror/lint': 6.8.4'@codemirror/search': 6.5.6- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2- '@uiw/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':+ '@uiw/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':dependencies:- '@uiw/codemirror-themes': 4.23.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])+ '@uiw/codemirror-themes': 4.23.7(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])transitivePeerDependencies:- '@codemirror/language'- '@codemirror/state'- '@codemirror/view'- '@uiw/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':+ '@uiw/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':dependencies:- '@uiw/codemirror-themes': 4.23.5(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])- transitivePeerDependencies:- - '@codemirror/language'- - '@codemirror/state'- - '@codemirror/view'-- '@uiw/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':- dependencies:- '@codemirror/language': 6.10.2- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/language': 6.10.8+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2- '@uiw/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':- dependencies:- '@codemirror/language': 6.10.2- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0-- '@uiw/[email protected](@babel/[email protected])(@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected](@lezer/[email protected]))([email protected]([email protected]))([email protected])':+ '@uiw/[email protected](@babel/[email protected])(@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected](@lezer/[email protected]))([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.26.0- '@codemirror/commands': 6.3.3- '@codemirror/state': 6.4.1+ '@codemirror/commands': 6.7.1+ '@codemirror/state': 6.5.1'@codemirror/theme-one-dark': 6.1.2- '@codemirror/view': 6.28.0- '@uiw/codemirror-extensions-basic-setup': 4.21.25(@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])+ '@codemirror/view': 6.36.2+ '@uiw/codemirror-extensions-basic-setup': 4.23.7(@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])codemirror: 6.0.1(@lezer/[email protected])react: 18.2.0react-dom: 18.2.0([email protected])@@ -17220,7 +17169,7 @@ snapshots:dependencies:'@vitest/spy': 2.1.2estree-walker: 3.0.3- magic-string: 0.30.11+ magic-string: 0.30.13optionalDependencies:vite: 5.2.14(@types/[email protected])optional: true@@ -17237,7 +17186,7 @@ snapshots:'@vitest/[email protected]':dependencies:'@vitest/pretty-format': 2.1.2- magic-string: 0.30.11+ magic-string: 0.30.13pathe: 1.1.2'@vitest/[email protected]':@@ -17425,7 +17374,7 @@ snapshots:dependencies:- debug: 4.3.7([email protected])+ debug: 4.3.7transitivePeerDependencies:- supports-color@@ -18099,13 +18048,13 @@ snapshots:[email protected](@lezer/[email protected]):dependencies:- '@codemirror/autocomplete': 6.17.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])+ '@codemirror/autocomplete': 6.17.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])'@codemirror/commands': 6.7.1- '@codemirror/language': 6.10.2- '@codemirror/lint': 6.8.2+ '@codemirror/language': 6.10.8+ '@codemirror/lint': 6.8.4'@codemirror/search': 6.5.6- '@codemirror/state': 6.4.1- '@codemirror/view': 6.28.0+ '@codemirror/state': 6.5.1+ '@codemirror/view': 6.36.2transitivePeerDependencies:- '@lezer/common'@@ -18616,6 +18565,10 @@ snapshots:dependencies:ms: 2.1.2+ dependencies:+ ms: 2.1.3+dependencies:ms: 2.1.3@@ -19087,7 +19040,7 @@ snapshots:[email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected]):dependencies:- debug: 4.3.7([email protected])+ debug: 4.3.7enhanced-resolve: 5.17.1eslint: 8.57.0eslint-module-utils: 2.8.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected]))([email protected])@@ -19164,7 +19117,7 @@ snapshots:doctrine: 2.1.0eslint: 8.57.0eslint-import-resolver-node: 0.3.9- eslint-module-utils: 2.8.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected])+ eslint-module-utils: 2.8.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected]))([email protected])hasown: 2.0.2is-core-module: 2.15.1is-glob: 4.0.3@@ -19545,7 +19498,7 @@ snapshots:dependencies:- debug: 4.3.7([email protected])+ debug: 4.3.7get-stream: 5.2.0yauzl: 2.10.0optionalDependencies:@@ -20088,7 +20041,7 @@ snapshots:dependencies:'@tootallnate/once': 2.0.0agent-base: 6.0.2- debug: 4.3.7([email protected])+ debug: 4.3.7transitivePeerDependencies:- supports-color@@ -20109,7 +20062,7 @@ snapshots:dependencies:agent-base: 6.0.2- debug: 4.3.7([email protected])+ debug: 4.3.7transitivePeerDependencies:- supports-color@@ -20123,7 +20076,7 @@ snapshots:dependencies:agent-base: 7.1.3- debug: 4.3.7([email protected])+ debug: 4.3.7transitivePeerDependencies:- supports-color@@ -20499,7 +20452,7 @@ snapshots:dependencies:- debug: 4.3.7([email protected])+ debug: 4.3.7istanbul-lib-coverage: 3.2.2source-map: 0.6.1transitivePeerDependencies:@@ -20919,7 +20872,7 @@ snapshots:dependencies:- '@types/node': 20.14.8+ '@types/node': 20.10.5merge-stream: 2.0.0supports-color: 8.1.1@@ -21775,7 +21728,7 @@ snapshots:dependencies:'@types/debug': 4.1.8- debug: 4.3.7([email protected])+ debug: 4.3.7decode-named-character-reference: 1.0.2devlop: 1.1.0micromark-core-commonmark: 2.0.1@@ -23167,7 +23120,7 @@ snapshots:dependencies:- debug: 4.3.7([email protected])+ debug: 4.3.7module-details-from-path: 1.0.3resolve: 1.22.8transitivePeerDependencies:@@ -24314,7 +24267,7 @@ snapshots:[email protected](@types/[email protected]):dependencies:cac: 6.7.14- debug: 4.3.7([email protected])+ debug: 4.3.7pathe: 1.1.2vite: 5.2.14(@types/[email protected])transitivePeerDependencies:@@ -24374,8 +24327,8 @@ snapshots:'@vitest/spy': 2.1.2'@vitest/utils': 2.1.2chai: 5.1.1- debug: 4.3.7([email protected])- magic-string: 0.30.11+ debug: 4.3.7+ magic-string: 0.30.13pathe: 1.1.2std-env: 3.7.0tinybench: 2.9.0diff --git a/web/package.json b/web/package.jsonindex 9ed9497aad..028eda86b4 100644--- a/web/package.json+++ b/web/package.json@@ -26,7 +26,8 @@"@appsignal/opentelemetry-instrumentation-bullmq": "^0.7.3","@baselime/trpc-opentelemetry-middleware": "^0.1.2","@codemirror/lang-json": "^6.0.1",- "@codemirror/lint": "^6.8.0",+ "@codemirror/language": "^6.10.1",+ "@codemirror/lint": "^6.4.2","@dnd-kit/core": "^6.1.0","@dnd-kit/modifiers": "^7.0.0","@dnd-kit/sortable": "^8.0.0",@@ -94,9 +95,8 @@"@trpc/next": "^10.45.0","@trpc/react-query": "^10.45.0","@trpc/server": "^10.45.0",- "@uiw/codemirror-theme-github": "^4.23.0",- "@uiw/codemirror-theme-tokyo-night": "^4.23.5",- "@uiw/react-codemirror": "^4.21.25",+ "@uiw/codemirror-theme-github": "^4.21.24",+ "@uiw/react-codemirror": "^4.21.24","ai": "^3.4.9","bcryptjs": "^2.4.3","bullmq": "^5.34.10",diff --git a/web/src/components/ChatMessages/ChatMessageComponent.tsx b/web/src/components/ChatMessages/ChatMessageComponent.tsxindex 2e37314c1a..13efdb758f 100644--- a/web/src/components/ChatMessages/ChatMessageComponent.tsx+++ b/web/src/components/ChatMessages/ChatMessageComponent.tsx@@ -1,10 +1,10 @@import { capitalize } from "lodash";import { GripVertical, MinusCircleIcon } from "lucide-react";-import { type ChangeEvent, useEffect, useState, useRef } from "react";+import { useState } from "react";import { ChatMessageRole, type ChatMessageWithId } from "@langfuse/shared";import { Button } from "@/src/components/ui/button";import { Card, CardContent } from "@/src/components/ui/card";-import { Textarea } from "@/src/components/ui/textarea";+import { CodeMirrorEditor } from "@/src/components/editor";import type { MessagesContext } from "./types";import { useSortable } from "@dnd-kit/sortable";import { cn } from "@/src/utils/tailwind";@@ -22,8 +22,6 @@ export const ChatMessageComponent: React.FC<ChatMessageProps> = ({availableRoles,index,}) => {- const textAreaRef = useRef<HTMLTextAreaElement | null>(null);- const [textAreaRows, setTextAreaRows] = useState(1);const [roleIndex, setRoleIndex] = useState(1);const {@@ -58,21 +56,8 @@ export const ChatMessageComponent: React.FC<ChatMessageProps> = ({}};- const handleContentChange = (event: ChangeEvent<HTMLTextAreaElement>) => {- updateMessage(message.id, "content", event.target.value);- };-const placeholder = `Enter ${message.role === ChatMessageRole.User ? "a user" : message.role === ChatMessageRole.System ? "a system" : "an assistant"} message here.`;- useEffect(() => {- const textAreaWidth = textAreaRef.current?.clientWidth ?? 0;- const charsPerRow = Math.floor(textAreaWidth / 10);-- setTextAreaRows(- countContentRows(message.content, charsPerRow || undefined),- );- }, [message.content]);-return (<Cardref={setNodeRef}@@ -105,15 +90,15 @@ export const ChatMessageComponent: React.FC<ChatMessageProps> = ({{capitalize(message.role)}</Button></div>-- <Textarea- ref={textAreaRef}- id={message.id}- className="height-[auto] min-h-6 w-full font-mono text-xs focus:outline-none"- placeholder={placeholder}+ <CodeMirrorEditorvalue={message.content}- onChange={handleContentChange}- rows={textAreaRows}+ onChange={(value) => updateMessage(message.id, "content", value)}+ mode="prompt"+ minHeight={30}+ className="w-full"+ editable={true}+ lineNumbers={false}+ placeholder={placeholder}/><Buttonvariant="ghost"@@ -127,15 +112,3 @@ export const ChatMessageComponent: React.FC<ChatMessageProps> = ({</Card>);};--function countContentRows(str: string, charsPerRow = 80) {- const lines = str.split("\n");-- const totalRows = lines.reduce((acc, line) => {- const additionalRows = Math.max(1, Math.ceil(line.length / charsPerRow));-- return acc + additionalRows;- }, 0);-- return totalRows;-}diff --git a/web/src/components/editor.tsx b/web/src/components/editor.tsxnew file mode 100644index 0000000000..d73789cf46--- /dev/null+++ b/web/src/components/editor.tsx@@ -0,0 +1,159 @@+import CodeMirror, { EditorView } from "@uiw/react-codemirror";+import { githubLight, githubDark } from "@uiw/codemirror-theme-github";+import { json, jsonParseLinter } from "@codemirror/lang-json";+import { linter, type Diagnostic } from "@codemirror/lint";+import { useTheme } from "next-themes";+import { cn } from "@/src/utils/tailwind";+import { useState } from "react";+import { LanguageSupport, StreamLanguage } from "@codemirror/language";+import type { StringStream } from "@codemirror/language";+import {+ isValidVariableName,+ MULTILINE_VARIABLE_REGEX,+ MUSTACHE_REGEX,+ UNCLOSED_VARIABLE_REGEX,+} from "@langfuse/shared";++// Custom language mode for prompts that highlights mustache variables+const promptLanguage = StreamLanguage.define({+ name: "prompt",+ startState: () => ({}),+ token: (stream: StringStream) => {+ if (stream.match("{{")) {+ const start = stream.pos;+ stream.skipTo("}}") || stream.skipToEnd();+ const content = stream.string.slice(start, stream.pos);+ stream.match("}}");+ return isValidVariableName(content) ? "variable" : "error";+ }+ stream.next();+ return null;+ },+});++// Linter for prompt variables+const promptLinter = linter((view) => {+ const diagnostics: Diagnostic[] = [];+ const content = view.state.doc.toString();++ // Check for multiline variables+ for (const match of content.matchAll(MULTILINE_VARIABLE_REGEX)) {+ diagnostics.push({+ from: match.index,+ to: match.index + match[0].length,+ severity: "error",+ message: "Variables cannot span multiple lines",+ });+ }++ // Check for unclosed variables+ for (const match of content.matchAll(UNCLOSED_VARIABLE_REGEX)) {+ diagnostics.push({+ from: match.index,+ to: match.index + 2,+ severity: "error",+ message: "Unclosed variable brackets",+ });+ }++ // Check variable format+ for (const match of content.matchAll(MUSTACHE_REGEX)) {+ const variable = match[1];+ if (!variable || variable.trim() === "") {+ diagnostics.push({+ from: match.index,+ to: match.index + match[0].length,+ severity: "error",+ message: "Empty variable is not allowed",+ });+ } else if (!isValidVariableName(variable)) {+ diagnostics.push({+ from: match.index,+ to: match.index + match[0].length,+ severity: "error",+ message:+ "Variable must start with a letter and can only contain letters and underscores",+ });+ }+ }++ return diagnostics;+});++// Create a language support instance that combines the language and its configuration+const promptSupport = new LanguageSupport(promptLanguage);++export function CodeMirrorEditor({+ value,+ onChange,+ editable = true,+ lineWrapping = true,+ lineNumbers = true,+ className,+ onBlur,+ mode,+ minHeight,+ placeholder,+}: {+ value: string;+ onChange?: (value: string) => void;+ editable?: boolean;+ onBlur?: () => void;+ lineNumbers?: boolean;+ lineWrapping?: boolean;+ className?: string;+ mode: "json" | "text" | "prompt";+ minHeight: "none" | 30 | 100 | 200;+ placeholder?: string;+}) {+ const { resolvedTheme } = useTheme();+ const codeMirrorTheme = resolvedTheme === "dark" ? githubDark : githubLight;++ // used to disable linter when field is empty+ const [linterEnabled, setLinterEnabled] = useState<boolean>(+ !!value && value !== "",+ );++ return (+ <CodeMirror+ value={value}+ theme={codeMirrorTheme}+ basicSetup={{+ foldGutter: true,+ highlightActiveLine: false,+ lineNumbers: lineNumbers,+ }}+ lang={mode === "json" ? "json" : undefined}+ extensions={[+ // Extend gutter to full height when minHeight > content height+ // This also enlarges the text area to minHeight+ ...(minHeight === "none"+ ? []+ : [+ EditorView.theme({+ ".cm-gutter,.cm-content": { minHeight: `${minHeight}px` },+ ".cm-scroller": { overflow: "auto" },+ }),+ ]),+ ...(mode === "json" ? [json()] : []),+ ...(mode === "json" && linterEnabled+ ? [linter(jsonParseLinter())]+ : []),+ ...(mode === "prompt" ? [promptSupport, promptLinter] : []),+ ...(lineWrapping ? [EditorView.lineWrapping] : []),+ ]}+ defaultValue={value}+ onChange={(c) => {+ if (onChange) onChange(c);+ setLinterEnabled(c !== "");+ }}+ onBlur={onBlur}+ className={cn(+ "overflow-hidden overflow-y-auto rounded-md border text-xs",+ className,+ )}+ editable={editable}+ placeholder={placeholder}+ />+ );+}diff --git a/web/src/components/json-editor.tsx b/web/src/components/json-editor.tsxdeleted file mode 100644index feabb803ac..0000000000--- a/web/src/components/json-editor.tsx+++ /dev/null@@ -1,55 +0,0 @@-import CodeMirror, { EditorView } from "@uiw/react-codemirror";-import { githubLight } from "@uiw/codemirror-theme-github";-import { tokyoNight } from "@uiw/codemirror-theme-tokyo-night";-import { json, jsonParseLinter } from "@codemirror/lang-json";-import { linter } from "@codemirror/lint";-import { useTheme } from "next-themes";-import { cn } from "@/src/utils/tailwind";-import { useState } from "react";--export function JsonEditor({- defaultValue,- onChange,- editable = true,- lineWrapping = true,- className,- onBlur,-}: {- defaultValue: string;- onChange?: (value: string) => void;- editable?: boolean;- onBlur?: () => void;- lineWrapping?: boolean;- className?: string;-}) {- const { resolvedTheme } = useTheme();- const codeMirrorTheme = resolvedTheme === "dark" ? tokyoNight : githubLight;-- // used to disable linter when field is empty- const [linterEnabled, setLinterEnabled] = useState<boolean>(- !!defaultValue && defaultValue !== "",- );- return (- <CodeMirror- value={defaultValue}- theme={codeMirrorTheme}- basicSetup={{- foldGutter: true,- }}- lang={"json"}- extensions={[- json(),- ...(linterEnabled ? [linter(jsonParseLinter())] : []),- ...(lineWrapping ? [EditorView.lineWrapping] : []),- ]}- defaultValue={defaultValue}- onChange={(c) => {- if (onChange) onChange(c);- setLinterEnabled(c !== "");- }}- onBlur={onBlur}- className={cn("overflow-hidden rounded-md border text-xs", className)}- editable={editable}- />- );-}diff --git a/web/src/features/datasets/components/DatasetForm.tsx b/web/src/features/datasets/components/DatasetForm.tsxindex 54f49523f5..54670809a5 100644--- a/web/src/features/datasets/components/DatasetForm.tsx+++ b/web/src/features/datasets/components/DatasetForm.tsx@@ -13,7 +13,7 @@ import {import { api } from "@/src/utils/api";import { useState } from "react";import { Input } from "@/src/components/ui/input";-import { JsonEditor } from "@/src/components/json-editor";+import { CodeMirrorEditor } from "@/src/components/editor";import { type Prisma } from "@langfuse/shared";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { Label } from "@/src/components/ui/label";@@ -229,11 +229,13 @@ export const DatasetForm = (props: DatasetFormProps) => {<FormItem><FormLabel>Metadata (optional)</FormLabel><FormControl>- <JsonEditor- defaultValue={field.value}+ <CodeMirrorEditor+ mode="json"+ value={field.value}onChange={(v) => {field.onChange(v);}}+ minHeight="none"/></FormControl><FormMessage />diff --git a/web/src/features/datasets/components/EditDatasetItem.tsx b/web/src/features/datasets/components/EditDatasetItem.tsxindex 0374b8b200..d3a4893a14 100644--- a/web/src/features/datasets/components/EditDatasetItem.tsx+++ b/web/src/features/datasets/components/EditDatasetItem.tsx@@ -13,7 +13,7 @@ import {} from "@/src/components/ui/form";import { Button } from "@/src/components/ui/button";import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";-import { JsonEditor } from "@/src/components/json-editor";+import { CodeMirrorEditor } from "@/src/components/editor";import { type RouterOutput } from "@/src/utils/types";const formSchema = z.object({@@ -127,80 +127,20 @@ export const EditDatasetItem = ({}return (- <div>+ <div className="flex h-full flex-col"><Form {...form}><form// eslint-disable-next-line @typescript-eslint/no-misused-promisesonSubmit={form.handleSubmit(onSubmit)}- className="space-y-4"+ className="flex h-full flex-col"onChange={() => setHasChanges(true)}>- <div className="grid gap-4 md:grid-cols-2">- <FormField- control={form.control}- name="input"- render={({ field }) => (- <FormItem>- <FormLabel>Input</FormLabel>- <FormControl>- <JsonEditor- defaultValue={field.value}- onChange={(v) => {- setHasChanges(true);- field.onChange(v);- }}- editable={hasAccess}- className="max-h-[500px] overflow-y-auto"- />- </FormControl>- <FormMessage />- </FormItem>- )}- />- <FormField- control={form.control}- name="expectedOutput"- render={({ field }) => (- <FormItem>- <FormLabel>Expected output</FormLabel>- <FormControl>- <JsonEditor- defaultValue={field.value}- onChange={(v) => {- setHasChanges(true);- field.onChange(v);- }}- editable={hasAccess}- className="max-h-[500px] overflow-y-auto"- />- </FormControl>- <FormMessage />- </FormItem>- )}- />- </div>- <FormField- control={form.control}- name="metadata"- render={({ field }) => (- <FormItem>- <FormLabel>Metadata</FormLabel>- <FormControl>- <JsonEditor- defaultValue={field.value}- onChange={(v) => {- setHasChanges(true);- field.onChange(v);- }}- editable={hasAccess}- className="max-h-[200px] overflow-y-auto"- />- </FormControl>- <FormMessage />- </FormItem>- )}- />- <div className="flex justify-end">+ <div className="flex items-center justify-end gap-4 py-4">+ {formError ? (+ <p className="text-red text-center">+ <span className="font-bold">Error:</span> {formError}+ </p>+ ) : null}<Buttontype="submit"loading={updateDatasetItemMutation.isLoading}@@ -210,13 +150,80 @@ export const EditDatasetItem = ({{hasChanges ? "Save changes" : "Saved"}</Button></div>+ <div className="flex-1 overflow-auto">+ <div className="space-y-4 py-4">+ <div className="grid gap-4 md:grid-cols-2">+ <FormField+ control={form.control}+ name="input"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Input</FormLabel>+ <FormControl>+ <CodeMirrorEditor+ mode="json"+ value={field.value}+ onChange={(v) => {+ setHasChanges(true);+ field.onChange(v);+ }}+ editable={hasAccess}+ minHeight={200}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="expectedOutput"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Expected output</FormLabel>+ <FormControl>+ <CodeMirrorEditor+ mode="json"+ value={field.value}+ onChange={(v) => {+ setHasChanges(true);+ field.onChange(v);+ }}+ editable={hasAccess}+ minHeight={200}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+ <FormField+ control={form.control}+ name="metadata"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Metadata</FormLabel>+ <FormControl>+ <CodeMirrorEditor+ mode="json"+ value={field.value}+ onChange={(v) => {+ setHasChanges(true);+ field.onChange(v);+ }}+ editable={hasAccess}+ minHeight={100}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+ </div></form></Form>- {formError ? (- <p className="text-red text-center">- <span className="font-bold">Error:</span> {formError}- </p>- ) : null}</div>);};diff --git a/web/src/features/datasets/components/NewDatasetItemForm.tsx b/web/src/features/datasets/components/NewDatasetItemForm.tsxindex 56a4d7f683..c5839acac3 100644--- a/web/src/features/datasets/components/NewDatasetItemForm.tsx+++ b/web/src/features/datasets/components/NewDatasetItemForm.tsx@@ -19,7 +19,7 @@ import {} from "@/src/components/ui/select";import { api } from "@/src/utils/api";import { useState } from "react";-import { JsonEditor } from "@/src/components/json-editor";+import { CodeMirrorEditor } from "@/src/components/editor";import { type Prisma } from "@langfuse/shared";import { cn } from "@/src/utils/tailwind";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";@@ -135,59 +135,88 @@ export const NewDatasetItemForm = (props: {<form// eslint-disable-next-line @typescript-eslint/no-misused-promisesonSubmit={form.handleSubmit(onSubmit)}- className={cn("flex flex-col gap-6", props.className)}+ className={cn("flex h-full flex-col gap-6", props.className)}>- <FormField- control={form.control}- name="datasetId"- render={({ field }) => (- <FormItem>- <FormLabel>Dataset</FormLabel>- <Select onValueChange={field.onChange} defaultValue={field.value}>- <FormControl>- <SelectTrigger>- <SelectValue placeholder="Select a dataset" />- </SelectTrigger>- </FormControl>- <SelectContent>- {datasets.data?.map((dataset) => (- <SelectItem value={dataset.id} key={dataset.id}>- {dataset.name}- </SelectItem>- ))}- </SelectContent>- </Select>- <FormMessage />- </FormItem>- )}- />- <div className="grid gap-4 md:grid-cols-2">+ <div className="flex-none"><FormFieldcontrol={form.control}- name="input"+ name="datasetId"render={({ field }) => (- <FormItem className="flex flex-col gap-2">- <FormLabel>Input</FormLabel>- <FormControl>- <JsonEditor- defaultValue={field.value}- onChange={field.onChange}- />- </FormControl>+ <FormItem>+ <FormLabel>Dataset</FormLabel>+ <Select+ onValueChange={field.onChange}+ defaultValue={field.value}+ >+ <FormControl>+ <SelectTrigger>+ <SelectValue placeholder="Select a dataset" />+ </SelectTrigger>+ </FormControl>+ <SelectContent>+ {datasets.data?.map((dataset) => (+ <SelectItem value={dataset.id} key={dataset.id}>+ {dataset.name}+ </SelectItem>+ ))}+ </SelectContent>+ </Select><FormMessage /></FormItem>)}/>+ </div>+ <div className="min-h-0 flex-1 overflow-y-auto">+ <div className="grid gap-4 md:grid-cols-2">+ <FormField+ control={form.control}+ name="input"+ render={({ field }) => (+ <FormItem className="flex flex-col gap-2">+ <FormLabel>Input</FormLabel>+ <FormControl>+ <CodeMirrorEditor+ mode="json"+ value={field.value}+ onChange={field.onChange}+ minHeight={200}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="expectedOutput"+ render={({ field }) => (+ <FormItem className="flex flex-col gap-2">+ <FormLabel>Expected output</FormLabel>+ <FormControl>+ <CodeMirrorEditor+ mode="json"+ value={field.value}+ onChange={field.onChange}+ minHeight={200}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div><FormFieldcontrol={form.control}- name="expectedOutput"+ name="metadata"render={({ field }) => (- <FormItem className="flex flex-col gap-2">- <FormLabel>Expected output</FormLabel>+ <FormItem className="mt-4 flex flex-col gap-2">+ <FormLabel>Metadata</FormLabel><FormControl>- <JsonEditor- defaultValue={field.value}+ <CodeMirrorEditor+ mode="json"+ value={field.value}onChange={field.onChange}+ minHeight={100}/></FormControl><FormMessage />@@ -195,35 +224,21 @@ export const NewDatasetItemForm = (props: {)}/></div>- <FormField- control={form.control}- name="metadata"- render={({ field }) => (- <FormItem className="flex flex-col gap-2">- <FormLabel>Metadata</FormLabel>- <FormControl>- <JsonEditor- defaultValue={field.value}- onChange={field.onChange}- />- </FormControl>- <FormMessage />- </FormItem>- )}- />- <Button- type="submit"- loading={createDatasetItemMutation.isLoading}- className="mt-auto w-full"- >- Add to dataset- </Button>+ <div className="mt-3 flex-none">+ <Button+ type="submit"+ loading={createDatasetItemMutation.isLoading}+ className="w-full"+ >+ Add to dataset+ </Button>+ {formError ? (+ <p className="text-red mt-2 text-center">+ <span className="font-bold">Error:</span> {formError}+ </p>+ ) : null}+ </div></form>- {formError ? (- <p className="text-red text-center">- <span className="font-bold">Error:</span> {formError}- </p>- ) : null}</Form>);};diff --git a/web/src/features/models/components/UpsertModelFormDrawer.tsx b/web/src/features/models/components/UpsertModelFormDrawer.tsxindex 8f9e69bc65..8c62356673 100644--- a/web/src/features/models/components/UpsertModelFormDrawer.tsx+++ b/web/src/features/models/components/UpsertModelFormDrawer.tsx@@ -4,7 +4,7 @@ import { useEffect, useState } from "react";import { useForm } from "react-hook-form";import * as z from "zod";-import { JsonEditor } from "@/src/components/json-editor";+import { CodeMirrorEditor } from "@/src/components/editor";import { Button } from "@/src/components/ui/button";import {Drawer,@@ -437,9 +437,11 @@ export const UpsertModelFormDrawer = ({render={({ field }) => (<FormItem><FormLabel>Tokenizer Config</FormLabel>- <JsonEditor- defaultValue={field.value ?? "{}"}+ <CodeMirrorEditor+ mode="json"+ value={field.value ?? "{}"}onChange={field.onChange}+ minHeight="none"/><FormDescription>The config for the tokenizer. Required for openai. See the{" "}diff --git a/web/src/features/prompts/components/NewPromptForm/index.tsx b/web/src/features/prompts/components/NewPromptForm/index.tsxindex 42650f435a..881270e9aa 100644--- a/web/src/features/prompts/components/NewPromptForm/index.tsx+++ b/web/src/features/prompts/components/NewPromptForm/index.tsx@@ -44,12 +44,11 @@ import { Input } from "@/src/components/ui/input";import Link from "next/link";import { ArrowTopRightIcon } from "@radix-ui/react-icons";import { PromptDescription } from "@/src/features/prompts/components/prompt-description";-import { JsonEditor } from "@/src/components/json-editor";+import { CodeMirrorEditor } from "@/src/components/editor";import { PRODUCTION_LABEL } from "@/src/features/prompts/constants";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import usePlaygroundCache from "@/src/ee/features/playground/page/hooks/usePlaygroundCache";import { useQueryParam } from "use-query-params";-import { Switch } from "@/src/components/ui/switch";import { usePromptNameValidation } from "@/src/features/prompts/hooks/usePromptNameValidation";type NewPromptFormProps = {@@ -64,7 +63,6 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {const [formError, setFormError] = useState<string | null>(null);const { playgroundCache } = usePlaygroundCache();const [initialMessages, setInitialMessages] = useState<unknown>([]);- const [showJsonEditor, setShowJsonEditor] = useState(false);const utils = api.useUtils();const capture = usePostHogClientCapture();@@ -241,24 +239,7 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {{/* Prompt content field - text vs. chat */}<><FormItem>- <FormLabel className="flex flex-row items-center justify-between">- <div>Prompt</div>- {form.watch("type") === PromptType.Text ? (- <div className="flex flex-row items-center">- <p className="mr-1 text-xs text-muted-foreground">- JSON editor- </p>-- <Switch- checked={showJsonEditor}- className={- showJsonEditor ? "data-[state=checked]:bg-dark-green" : ""- }- onCheckedChange={setShowJsonEditor}- />- </div>- ) : null}- </FormLabel>+ <FormLabel>Prompt</FormLabel><Tabsvalue={form.watch("type")}onValueChange={(e) => {@@ -296,18 +277,13 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {render={({ field }) => (<><FormControl>- {showJsonEditor ? (- <JsonEditor- defaultValue={field.value}- onChange={field.onChange}- editable- />- ) : (- <Textarea- {...field}- className="min-h-[200px] flex-1 font-mono text-xs"- />- )}+ <CodeMirrorEditor+ value={field.value}+ onChange={field.onChange}+ editable+ mode="prompt"+ minHeight={200}+ /></FormControl><FormMessage /></>@@ -343,11 +319,13 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {render={({ field }) => (<FormItem><FormLabel>Config</FormLabel>- <JsonEditor- defaultValue={field.value}+ <CodeMirrorEditor+ value={field.value}onChange={field.onChange}onBlur={field.onBlur}editable+ mode="json"+ minHeight="none"/><FormDescription>Track configs for LLM API calls such as function definitions or