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

Function applyPiEvent

apps/sim/executor/handlers/pi/events.ts:44–67  ·  view source on GitHub ↗
(totals: PiRunTotals, event: PiEvent)

Source from the content-addressed store, hash-verified

42 * `finalText`; usage events sum (Pi reports per-turn usage on `turn_end`).
43 */
44export function applyPiEvent(totals: PiRunTotals, event: PiEvent): void {
45 switch (event.type) {
46 case 'text':
47 totals.finalText += event.text
48 break
49 case 'final':
50 if (event.text && totals.finalText.length === 0) {
51 totals.finalText = event.text
52 }
53 break
54 case 'usage':
55 totals.inputTokens += event.inputTokens
56 totals.outputTokens += event.outputTokens
57 break
58 case 'tool_end':
59 totals.toolCalls.push({ name: event.toolName, isError: event.isError })
60 break
61 case 'error':
62 totals.errorMessage = event.message
63 break
64 default:
65 break
66 }
67}
68
69/** Returns the text to enqueue onto the content stream for an event, if any. */
70export function streamTextForEvent(event: PiEvent): string | null {

Callers 4

events.test.tsFile · 0.90
handleChunkFunction · 0.90
runCloudPiFunction · 0.90
runLocalPiFunction · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected