Skip to content

Commit e8f7139

Browse files
committed
refactor(trace): move formatCostAmount and getDisplayName to shared utils, normalize tool names in trace-spans
1 parent 669c35e commit e8f7139

3 files changed

Lines changed: 18 additions & 23 deletions

File tree

apps/sim/app/workspace/[workspaceId]/logs/components/log-details/components/trace-spans/trace-spans.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ import {
1919
Search as SearchIcon,
2020
Tooltip,
2121
} from '@/components/emcn'
22-
import { dollarsToCredits } from '@/lib/billing/credits/conversion'
2322
import { cn } from '@/lib/core/utils/cn'
2423
import type { TraceSpan } from '@/lib/logs/types'
2524
import {
25+
formatCostAmount,
2626
formatTokensSummary,
2727
formatTps,
2828
formatTtft,
2929
getBlockIconAndColor,
30+
getDisplayName,
3031
hasErrorInTree,
3132
hasUnhandledErrorInTree,
3233
isIterationType,
@@ -58,13 +59,6 @@ function useSetToggle() {
5859
)
5960
}
6061

61-
function formatCostAmount(value: number | undefined): string | undefined {
62-
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) return undefined
63-
const credits = dollarsToCredits(value)
64-
if (credits <= 0) return '<1 credit'
65-
return `${credits.toLocaleString('en-US')} ${credits === 1 ? 'credit' : 'credits'}`
66-
}
67-
6862
function formatCostSummary(cost: TraceSpan['cost']): string | undefined {
6963
if (!cost) return undefined
7064
const parts: string[] = []
@@ -535,7 +529,7 @@ const TraceSpanNode = memo(function TraceSpanNode({
535529
className='min-w-0 max-w-[180px] truncate font-medium text-caption'
536530
style={{ color: showErrorStyle ? 'var(--text-error)' : 'var(--text-secondary)' }}
537531
>
538-
{span.name}
532+
{getDisplayName(span)}
539533
</span>
540534
{isToggleable && (
541535
<ChevronDown

apps/sim/app/workspace/[workspaceId]/logs/components/log-details/components/trace-view/trace-view.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ import {
2929
Search as SearchIcon,
3030
Tooltip,
3131
} from '@/components/emcn'
32-
import { dollarsToCredits } from '@/lib/billing/credits/conversion'
3332
import { cn } from '@/lib/core/utils/cn'
3433
import type { TraceSpan } from '@/lib/logs/types'
3534
import {
35+
formatCostAmount,
3636
formatTokenCount,
3737
formatTps,
3838
formatTtft,
3939
getBlockIconAndColor,
40+
getDisplayName,
4041
hasErrorInTree,
4142
hasUnhandledErrorInTree,
4243
isIterationType,
4344
parseTime,
4445
} from '@/app/workspace/[workspaceId]/logs/components/log-details/utils'
4546
import { useCodeViewerFeatures } from '@/hooks/use-code-viewer'
46-
import { normalizeToolId } from '@/tools/normalize'
4747

4848
const DEFAULT_TREE_PANE_WIDTH = 360
4949
const MIN_TREE_PANE_WIDTH = 200
@@ -120,18 +120,6 @@ function iconColorClass(bgColor: string): string {
120120
return r * 299 + g * 587 + b * 114 > 160_000 ? 'text-[#111111]' : 'text-white'
121121
}
122122

123-
function formatCostAmount(value: number | undefined): string | undefined {
124-
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) return undefined
125-
const credits = dollarsToCredits(value)
126-
if (credits <= 0) return '<1 credit'
127-
return `${credits.toLocaleString('en-US')} ${credits === 1 ? 'credit' : 'credits'}`
128-
}
129-
130-
function getDisplayName(span: TraceSpan): string {
131-
if (span.type?.toLowerCase() === 'tool') return normalizeToolId(span.name)
132-
return span.name
133-
}
134-
135123
/**
136124
* Flattens the visible (expanded) span tree into a linear list for keyboard
137125
* navigation, carrying depth, the chain of parent ids for indent drawing, and

apps/sim/app/workspace/[workspaceId]/logs/components/log-details/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type React from 'react'
22
import { AgentSkillsIcon, WorkflowIcon } from '@/components/icons'
3+
import { dollarsToCredits } from '@/lib/billing/credits/conversion'
34
import type { TraceSpan } from '@/lib/logs/types'
45
import { LoopTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/subflows/loop/loop-config'
56
import { ParallelTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/subflows/parallel/parallel-config'
@@ -88,6 +89,18 @@ export function formatTps(
8889
return tps > 0 ? `${tps.toLocaleString('en-US')} tok/s` : undefined
8990
}
9091

92+
export function getDisplayName(span: TraceSpan): string {
93+
if (span.type?.toLowerCase() === 'tool') return normalizeToolId(span.name)
94+
return span.name
95+
}
96+
97+
export function formatCostAmount(value: number | undefined): string | undefined {
98+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) return undefined
99+
const credits = dollarsToCredits(value)
100+
if (credits <= 0) return '<1 credit'
101+
return `${credits.toLocaleString('en-US')} ${credits === 1 ? 'credit' : 'credits'}`
102+
}
103+
91104
export function formatTokensSummary(tokens: TraceSpan['tokens']): string | undefined {
92105
if (!tokens) return undefined
93106
const parts: string[] = []

0 commit comments

Comments
 (0)