mirror of
https://github.com/BillyOutlast/posthog.git
synced 2026-02-04 03:01:23 +01:00
fix(llma): unsafe string generation (#37311)
Co-authored-by: Radu Raicea <radu@raicea.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user