Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions packages/ui/src/ui-component/json/JsonEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ export const JsonEditorInput = ({
isDarkMode = false,
isSequentialAgent = false
}) => {
const [myValue, setMyValue] = useState(value ? JSON.parse(value) : {})
const [myValue, setMyValue] = useState(() => {
if (!value || value === '') return {}
try {
return JSON.parse(value)
} catch (error) {
console.warn('Invalid JSON value provided to JsonEditorInput:', error)
return {}
}
})
const [availableNodesForVariable, setAvailableNodesForVariable] = useState([])
const [mouseUpKey, setMouseUpKey] = useState('')

Expand All @@ -39,11 +47,21 @@ export const JsonEditorInput = ({
}

const onClipboardCopy = (e) => {
const src = e.src
if (Array.isArray(src) || typeof src === 'object') {
navigator.clipboard.writeText(JSON.stringify(src, null, ' '))
} else {
navigator.clipboard.writeText(src)
// Check if clipboard API is available
if (!navigator.clipboard || !navigator.clipboard.writeText) {
console.warn('Clipboard API not available')
return
}

try {
const src = e.src
if (Array.isArray(src) || typeof src === 'object') {
navigator.clipboard.writeText(JSON.stringify(src, null, ' '))
} else {
navigator.clipboard.writeText(src || '')
}
} catch (error) {
console.error('Error copying to clipboard:', error)
}
}

Expand All @@ -54,6 +72,23 @@ export const JsonEditorInput = ({
}
}, [disabled, inputParam, nodes, edges, nodeId])

// Handle value changes safely
useEffect(() => {
if (value !== undefined) {
try {
if (!value || value === '') {
setMyValue({})
} else {
const parsedValue = JSON.parse(value)
setMyValue(parsedValue)
}
} catch (error) {
console.warn('Invalid JSON value provided to JsonEditorInput:', error)
setMyValue({})
}
}
}, [value])

return (
<>
<FormControl sx={{ mt: 1, width: '100%' }} size='small'>
Expand Down
20 changes: 15 additions & 5 deletions packages/ui/src/views/agentexecutions/NodeExecutionDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,21 @@ export const NodeExecutionDetails = ({ data, label, status, metadata, isPublic,
}

const onClipboardCopy = (e) => {
const src = e.src
if (Array.isArray(src) || typeof src === 'object') {
navigator.clipboard.writeText(JSON.stringify(src, null, ' '))
} else {
navigator.clipboard.writeText(src)
// Check if clipboard API is available
if (!navigator.clipboard || !navigator.clipboard.writeText) {
console.warn('Clipboard API not available')
return
}

try {
const src = e.src
if (Array.isArray(src) || typeof src === 'object') {
navigator.clipboard.writeText(JSON.stringify(src, null, ' '))
} else {
navigator.clipboard.writeText(src || '')
}
} catch (error) {
console.error('Error copying to clipboard:', error)
}
}

Expand Down
20 changes: 15 additions & 5 deletions packages/ui/src/views/docstore/ExpandedChunkDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ const ExpandedChunkDialog = ({ show, dialogProps, onCancel, onChunkEdit, onDelet
const [metadata, setMetadata] = useState({})

const onClipboardCopy = (e) => {
const src = e.src
if (Array.isArray(src) || typeof src === 'object') {
navigator.clipboard.writeText(JSON.stringify(src, null, ' '))
} else {
navigator.clipboard.writeText(src)
// Check if clipboard API is available
if (!navigator.clipboard || !navigator.clipboard.writeText) {
console.warn('Clipboard API not available')
return
}

try {
const src = e.src
if (Array.isArray(src) || typeof src === 'object') {
navigator.clipboard.writeText(JSON.stringify(src, null, ' '))
} else {
navigator.clipboard.writeText(src || '')
}
} catch (error) {
console.error('Error copying to clipboard:', error)
}
}

Expand Down