Merge remote-tracking branch 'origin/main' into feat/support-agent-sandbox

This commit is contained in:
yyh 2026-01-13 14:19:04 +08:00
commit 1ed4ab4299
No known key found for this signature in database
4 changed files with 53 additions and 6 deletions

View File

@ -251,10 +251,7 @@ class AssistantPromptMessage(PromptMessage):
:return: True if prompt message is empty, False otherwise
"""
if not super().is_empty() and not self.tool_calls:
return False
return True
return super().is_empty() and not self.tool_calls
class SystemPromptMessage(PromptMessage):

View File

@ -54,7 +54,7 @@ const pageNameEnrichmentPlugin = (): amplitude.Types.EnrichmentPlugin => {
}
const AmplitudeProvider: FC<IAmplitudeProps> = ({
sessionReplaySampleRate = 1,
sessionReplaySampleRate = 0.5,
}) => {
useEffect(() => {
// Only enable in Saas edition with valid API key

View File

@ -19,6 +19,28 @@ describe('formatNumber', () => {
it('should correctly handle empty input', () => {
expect(formatNumber('')).toBe('')
})
it('should format very small numbers without scientific notation', () => {
expect(formatNumber(0.0000008)).toBe('0.0000008')
expect(formatNumber(0.0000001)).toBe('0.0000001')
expect(formatNumber(0.000001)).toBe('0.000001')
expect(formatNumber(0.00001)).toBe('0.00001')
})
it('should format negative small numbers without scientific notation', () => {
expect(formatNumber(-0.0000008)).toBe('-0.0000008')
expect(formatNumber(-0.0000001)).toBe('-0.0000001')
})
it('should handle small numbers from string input', () => {
expect(formatNumber('0.0000008')).toBe('0.0000008')
expect(formatNumber('8E-7')).toBe('0.0000008')
expect(formatNumber('1e-7')).toBe('0.0000001')
})
it('should handle small numbers with multi-digit mantissa in scientific notation', () => {
expect(formatNumber(1.23e-7)).toBe('0.000000123')
expect(formatNumber(1.234e-7)).toBe('0.0000001234')
expect(formatNumber(12.34e-7)).toBe('0.000001234')
expect(formatNumber(0.0001234)).toBe('0.0001234')
expect(formatNumber('1.23e-7')).toBe('0.000000123')
})
})
describe('formatFileSize', () => {
it('should return the input if it is falsy', () => {

View File

@ -26,11 +26,39 @@ import 'dayjs/locale/zh-tw'
* Formats a number with comma separators.
* @example formatNumber(1234567) will return '1,234,567'
* @example formatNumber(1234567.89) will return '1,234,567.89'
* @example formatNumber(0.0000008) will return '0.0000008'
*/
export const formatNumber = (num: number | string) => {
if (!num)
return num
const parts = num.toString().split('.')
const n = typeof num === 'string' ? Number(num) : num
let numStr: string
// Force fixed decimal for small numbers to avoid scientific notation
if (Math.abs(n) < 0.001 && n !== 0) {
const str = n.toString()
const match = str.match(/e-(\d+)$/)
let precision: number
if (match) {
// Scientific notation: precision is exponent + decimal digits in mantissa
const exponent = Number.parseInt(match[1], 10)
const mantissa = str.split('e')[0]
const mantissaDecimalPart = mantissa.split('.')[1]
precision = exponent + (mantissaDecimalPart?.length || 0)
}
else {
// Decimal notation: count decimal places
const decimalPart = str.split('.')[1]
precision = decimalPart?.length || 0
}
numStr = n.toFixed(precision)
}
else {
numStr = n.toString()
}
const parts = numStr.split('.')
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
return parts.join('.')
}