fix(llma): unsafe string generation (#37311)

Co-authored-by: Radu Raicea <radu@raicea.com>
This commit is contained in:
Carlos Marchal
2025-08-28 23:20:49 +02:00
committed by GitHub
parent c0c96f5c57
commit 01b193cda3

View File

@@ -146,8 +146,7 @@ function LLMAnalyticsGenerations(): JSX.Element {
return <></>
}
const visualValue: string =
(value as string).slice(0, 4) + '...' + (value as string).slice(-4)
const visualValue = truncateValue(value)
if (!traceId) {
return <strong>{visualValue}</strong>
@@ -216,8 +215,7 @@ function LLMAnalyticsGenerations(): JSX.Element {
return <></>
}
const visualValue: string =
(value as string).slice(0, 4) + '...' + (value as string).slice(-4)
const visualValue = truncateValue(value)
return (
<Tooltip title={value as string}>
@@ -338,3 +336,17 @@ export function LLMAnalyticsScene(): JSX.Element {
</BindLogic>
)
}
function truncateValue(value: unknown): string {
if (value === null || value === undefined) {
return '-'
}
const stringValue = String(value)
if (stringValue.length <= 12) {
return stringValue
}
return stringValue.slice(0, 4) + '...' + stringValue.slice(-4)
}