MCPcopy Index your code
hub / github.com/simstudioai/sim / build

Method build

apps/sim/lib/copilot/request/trace.ts:62–125  ·  view source on GitHub ↗
(params: {
    outcome: RequestTraceV1Outcome
    simRequestId: string
    streamId?: string
    chatId?: string
    runId?: string
    executionId?: string
    // Original user prompt, surfaced on the `request_traces.message`
    // column at row-insert time so it's queryable from the DB without
    // going through Tempo. Sim already has this at chat-POST time; it's
    // threaded through here to the trace report so the row is complete
    // the moment it's first written instead of waiting on the late
    // analytics UPDATE.
    userMessage?: string
    usage?: {
      prompt: number
      completion: number
      cacheAttemptedRequests?: number
      cacheHitRequests?: number
      cacheWriteRequests?: number
      cacheReadTokens?: number
      cacheWriteTokens?: number
      cacheSavingsRate?: number
    }
    cost?: { input: number; output: number; total: number }
  })

Source from the content-addressed store, hash-verified

60 }
61
62 build(params: {
63 outcome: RequestTraceV1Outcome
64 simRequestId: string
65 streamId?: string
66 chatId?: string
67 runId?: string
68 executionId?: string
69 // Original user prompt, surfaced on the `request_traces.message`
70 // column at row-insert time so it's queryable from the DB without
71 // going through Tempo. Sim already has this at chat-POST time; it's
72 // threaded through here to the trace report so the row is complete
73 // the moment it's first written instead of waiting on the late
74 // analytics UPDATE.
75 userMessage?: string
76 usage?: {
77 prompt: number
78 completion: number
79 cacheAttemptedRequests?: number
80 cacheHitRequests?: number
81 cacheWriteRequests?: number
82 cacheReadTokens?: number
83 cacheWriteTokens?: number
84 cacheSavingsRate?: number
85 }
86 cost?: { input: number; output: number; total: number }
87 }): RequestTraceV1SimReport {
88 const endMs = Date.now()
89 const usage: RequestTraceV1UsageSummary | undefined = params.usage
90 ? {
91 inputTokens: params.usage.prompt,
92 outputTokens: params.usage.completion,
93 cacheAttemptedRequests: params.usage.cacheAttemptedRequests ?? 0,
94 cacheHitRequests: params.usage.cacheHitRequests ?? 0,
95 cacheWriteRequests: params.usage.cacheWriteRequests ?? 0,
96 cacheReadTokens: params.usage.cacheReadTokens ?? 0,
97 cacheWriteTokens: params.usage.cacheWriteTokens ?? 0,
98 cacheSavingsRate: params.usage.cacheSavingsRate ?? 0,
99 }
100 : undefined
101
102 const cost: RequestTraceV1CostSummary | undefined = params.cost
103 ? {
104 rawTotalCost: params.cost.total,
105 billedTotalCost: params.cost.total,
106 }
107 : undefined
108
109 return {
110 simRequestId: params.simRequestId,
111 goTraceId: this.goTraceId,
112 streamId: params.streamId,
113 chatId: params.chatId,
114 runId: params.runId,
115 executionId: params.executionId,
116 ...(params.userMessage ? { userMessage: params.userMessage } : {}),
117 startMs: this.startMs,
118 endMs,
119 durationMs: endMs - this.startMs,

Callers 3

stream.test.tsFile · 0.45
mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected