| 372 | } |
| 373 | |
| 374 | function getAssistantDiagnostics(message: any): AssistantDiagnostics | null { |
| 375 | if (!message || message.role !== "assistant") { |
| 376 | return null; |
| 377 | } |
| 378 | |
| 379 | const stopReason = message.stopReason ?? "unknown"; |
| 380 | const errorMessage = |
| 381 | message.errorMessage || |
| 382 | (stopReason === "error" || stopReason === "aborted" |
| 383 | ? `Request ${stopReason}` |
| 384 | : ""); |
| 385 | |
| 386 | const content = Array.isArray(message.content) ? message.content : []; |
| 387 | const text = content |
| 388 | .filter((item: any) => item?.type === "text") |
| 389 | .map((item: any) => item.text || "") |
| 390 | .join("") |
| 391 | .trim(); |
| 392 | const toolCalls = content.filter( |
| 393 | (item: any) => item?.type === "toolCall", |
| 394 | ).length; |
| 395 | |
| 396 | return { stopReason, errorMessage, hasText: text.length > 0, toolCalls }; |
| 397 | } |
| 398 | |
| 399 | function getLifecycleTrigger(channelId: string): LifecycleTrigger { |
| 400 | const platform = detectPlatformFromChannelId(channelId); |