🪢 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): add linter to json inputs (#2171)
Marc Klingened043578152d
diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b3aeab063b..760f691612 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -222,6 +222,9 @@ importers:'@codemirror/lang-json':specifier: ^6.0.1version: 6.0.1+ '@codemirror/lint':+ specifier: ^6.8.0+ version: 6.8.0'@headlessui/react':specifier: 1.7.18version: 1.7.18([email protected])([email protected])@@ -380,7 +383,7 @@ importers:version: 4.22.1(@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])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected])([email protected])([email protected])+ version: 4.21.25(@babel/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected])([email protected])([email protected])ai:specifier: ^3.0.23version: 3.0.23([email protected])([email protected])([email protected])([email protected])([email protected])@@ -2084,6 +2087,14 @@ packages:crelt: 1.0.6dev: false+ /@codemirror/[email protected]:+ resolution: {integrity: sha512-lsFofvaw0lnPRJlQylNsC4IRt/1lI4OD/yYslrSGVndOJfStc58v+8p9dgGiD90ktOfL7OhBWns1ZETYgz0EJA==}+ dependencies:+ '@codemirror/state': 6.4.1+ '@codemirror/view': 6.26.3+ crelt: 1.0.6+ dev: false+/@codemirror/[email protected]:resolution: {integrity: sha512-rpMgcsh7o0GuCDUXKPvww+muLA1pDJaFrpq/CCHtpQJYz8xopu4D1hPcKRoDD0YlF8gZaqTNIRa4VRBWyhyy7Q==}dependencies:@@ -7111,7 +7122,7 @@ packages:eslint-visitor-keys: 3.4.3dev: true- /@uiw/[email protected](@codemirror/[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])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected]):resolution: {integrity: sha512-eeUKlmEE8aSoSgelS8OR2elcPGntpRo669XinAqPCLa0eKorT2B0d3ts+AE+njAeGk744tiyAEbHb2n+6OQmJw==}peerDependencies:'@codemirror/autocomplete': '>=6.0.0'@@ -7125,7 +7136,7 @@ packages:'@codemirror/autocomplete': 6.16.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])'@codemirror/commands': 6.3.3'@codemirror/language': 6.10.1- '@codemirror/lint': 6.7.1+ '@codemirror/lint': 6.8.0'@codemirror/search': 6.5.6'@codemirror/state': 6.4.1'@codemirror/view': 6.26.3@@ -7175,7 +7186,7 @@ packages:'@codemirror/view': 6.26.3dev: false- /@uiw/[email protected](@babel/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[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])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected])([email protected])([email protected]):resolution: {integrity: sha512-mBrCoiffQ+hbTqV1JoixFEcH7BHXkS3PjTyNH7dE8Gzf3GSBRazhtSM5HrAFIiQ5FIRGFs8Gznc4UAdhtevMmw==}peerDependencies:'@babel/runtime': '>=7.11.0'@@ -7191,7 +7202,7 @@ packages:'@codemirror/state': 6.4.1'@codemirror/theme-one-dark': 6.1.2'@codemirror/view': 6.26.3- '@uiw/codemirror-extensions-basic-setup': 4.21.25(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])+ '@uiw/codemirror-extensions-basic-setup': 4.21.25(@codemirror/[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])diff --git a/web/package.json b/web/package.jsonindex 2021f78a7a..d0a06ba9cf 100644--- a/web/package.json+++ b/web/package.json@@ -25,6 +25,7 @@"@aws-sdk/lib-storage": "^3.568.0","@aws-sdk/s3-request-presigner": "^3.554.0","@codemirror/lang-json": "^6.0.1",+ "@codemirror/lint": "^6.8.0","@headlessui/react": "1.7.18","@headlessui/tailwindcss": "0.2.0","@heroicons/react": "^2.1.3",diff --git a/web/src/components/json-editor.tsx b/web/src/components/json-editor.tsxindex 1436ccd6ba..912e984f7c 100644--- a/web/src/components/json-editor.tsx+++ b/web/src/components/json-editor.tsx@@ -1,9 +1,11 @@import CodeMirror, { EditorView } from "@uiw/react-codemirror";import { githubLight } from "@uiw/codemirror-theme-github";import { tokyoNight } from "@uiw/codemirror-theme-tokyo-night";-import { json } from "@codemirror/lang-json";+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";// todo: add json linting@@ -22,6 +24,11 @@ export function JsonEditor({}) {const { theme } = useTheme();const codeMirrorTheme = theme === "dark" ? tokyoNight : githubLight;++ // used to disable linter when field is empty+ const [linterEnabled, setLinterEnabled] = useState<boolean>(+ !!defaultValue && defaultValue !== "",+ );return (<CodeMirrorvalue={defaultValue}@@ -30,9 +37,16 @@ export function JsonEditor({foldGutter: true,}}lang={"json"}- extensions={[json(), ...(lineWrapping ? [EditorView.lineWrapping] : [])]}+ extensions={[+ json(),+ ...(linterEnabled ? [linter(jsonParseLinter())] : []),+ ...(lineWrapping ? [EditorView.lineWrapping] : []),+ ]}defaultValue={defaultValue}- onChange={onChange}+ onChange={(c) => {+ if (onChange) onChange(c);+ setLinterEnabled(c !== "");+ }}className={cn("overflow-hidden rounded-md border", className)}editable={editable}/>