Skip to content

Commit 6be088d

Browse files
committed
fix(trace): normalize keyed tool names and show credits in trace view
- Export normalizeToolId from tools/index.ts so trace-view can reuse it - Strip resource-id suffixes (knowledge_search_<uuid>, workflow_executor_<uuid>, table_*_<id>) from tool span names at display time so icons resolve and names are readable - Replace raw dollar formatting with credits in trace header and agent detail panel
1 parent 1a321c5 commit 6be088d

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

  • apps/sim

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ import {
3030
Tooltip,
3131
} from '@/components/emcn'
3232
import { AgentSkillsIcon, WorkflowIcon } from '@/components/icons'
33+
import { dollarsToCredits } from '@/lib/billing/credits/conversion'
3334
import { cn } from '@/lib/core/utils/cn'
3435
import type { TraceSpan } from '@/lib/logs/types'
3536
import { LoopTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/subflows/loop/loop-config'
3637
import { ParallelTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/subflows/parallel/parallel-config'
3738
import { getBlock, getBlockByToolName } from '@/blocks'
3839
import { useCodeViewerFeatures } from '@/hooks/use-code-viewer'
3940
import { PROVIDER_DEFINITIONS } from '@/providers/models'
41+
import { normalizeToolId } from '@/tools'
4042

4143
const DEFAULT_BLOCK_COLOR = '#6b7280'
4244
const DEFAULT_TREE_PANE_WIDTH = 360
@@ -153,8 +155,9 @@ function getDisplayChildren(span: TraceSpan): TraceSpan[] {
153155
function getBlockAppearance(type: string, toolName?: string, provider?: string): BlockAppearance {
154156
const lowerType = type.toLowerCase()
155157
if (lowerType === 'tool' && toolName) {
156-
if (toolName === 'load_skill') return { icon: AgentSkillsIcon, bgColor: '#8B5CF6' }
157-
const toolBlock = getBlockByToolName(toolName)
158+
const normalized = normalizeToolId(toolName)
159+
if (normalized === 'load_skill') return { icon: AgentSkillsIcon, bgColor: '#8B5CF6' }
160+
const toolBlock = getBlockByToolName(normalized)
158161
if (toolBlock) return { icon: toolBlock.icon, bgColor: toolBlock.bgColor }
159162
}
160163
if (lowerType === 'loop' || lowerType === 'loop-iteration')
@@ -191,8 +194,9 @@ function formatTokenCount(value: number | undefined): string | undefined {
191194

192195
function formatCostAmount(value: number | undefined): string | undefined {
193196
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) return undefined
194-
if (value < 0.0001) return '<$0.0001'
195-
return `$${value.toFixed(4)}`
197+
const credits = dollarsToCredits(value)
198+
if (credits <= 0) return undefined
199+
return `${credits.toLocaleString()} credits`
196200
}
197201

198202
function formatTtft(ms: number | undefined): string | undefined {
@@ -208,6 +212,11 @@ function formatTps(outputTokens: number | undefined, durationMs: number): string
208212
return tps > 0 ? `${tps.toLocaleString('en-US')} tok/s` : undefined
209213
}
210214

215+
function getDisplayName(span: TraceSpan): string {
216+
if (span.type?.toLowerCase() === 'tool') return normalizeToolId(span.name)
217+
return span.name
218+
}
219+
211220
/**
212221
* Flattens the visible (expanded) span tree into a linear list for keyboard
213222
* navigation, carrying depth, the chain of parent ids for indent drawing, and
@@ -294,7 +303,7 @@ function findSpan(spans: TraceSpan[], id: string | null): TraceSpan | null {
294303
*/
295304
function spanMatchesQuery(span: TraceSpan, query: string): boolean {
296305
if (!query) return true
297-
return (span.name ?? '').toLowerCase().includes(query.toLowerCase())
306+
return getDisplayName(span).toLowerCase().includes(query.toLowerCase())
298307
}
299308

300309
/**
@@ -431,12 +440,12 @@ const TraceTreeRow = memo(function TraceTreeRow({
431440
nameMatches && 'text-[var(--text-primary)]'
432441
)}
433442
>
434-
{span.name}
443+
{getDisplayName(span)}
435444
</span>
436445
</Tooltip.Trigger>
437446
<Tooltip.Content side='right' className='max-w-[320px]'>
438447
<div className='flex flex-col gap-0.5'>
439-
<span className='font-medium'>{span.name}</span>
448+
<span className='font-medium'>{getDisplayName(span)}</span>
440449
<span className='text-[var(--text-tertiary)] text-caption'>
441450
{formatDuration(duration, { precision: 2 }) || '—'}
442451
{offsetMs > 0 && ` · +${formatDuration(offsetMs, { precision: 2 })}`}
@@ -797,7 +806,7 @@ const TraceDetailPane = memo(function TraceDetailPane({ span }: { span: TraceSpa
797806
hasError ? 'text-[var(--text-error)]' : 'text-[var(--text-primary)]'
798807
)}
799808
>
800-
{span.name}
809+
{getDisplayName(span)}
801810
</h3>
802811
<div className='flex items-center gap-1.5 font-medium text-[var(--text-tertiary)] text-caption'>
803812
<Badge variant={hasError ? 'red' : 'green'} size='sm'>

apps/sim/tools/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ async function applyHostedKeyCostToResult(
556556
* Knowledge tools: 'knowledge_search_<uuid>' -> 'knowledge_search'
557557
* Table tools: 'table_query_rows_<tableId>' -> 'table_query_rows'
558558
*/
559-
function normalizeToolId(toolId: string): string {
559+
export function normalizeToolId(toolId: string): string {
560560
if (toolId.startsWith('workflow_executor_') && toolId.length > 'workflow_executor_'.length) {
561561
return 'workflow_executor'
562562
}

0 commit comments

Comments
 (0)