feat(analytics): add official provider ops metrics

Build on existing pricing funnel events with official provider, TTS usage, second-turn activation, and Flux balance bucket metrics.
This commit is contained in:
Lovehsigure_520
2026-07-01 21:19:42 +08:00
committed by GitHub
parent 3edbe4eb99
commit 2da9d37add
24 changed files with 930 additions and 46 deletions
@@ -332,6 +332,7 @@ describe('createChatOrchestratorRuntime', () => {
expect(harness.telemetry.chatActivationStarted).toEqual([{
model: 'gpt-test',
provider: 'mock-provider',
sessionId: 'session-1',
source: 'voice',
}])
expect(harness.telemetry.chatActivationSucceeded).toEqual([{
@@ -359,6 +360,7 @@ describe('createChatOrchestratorRuntime', () => {
expect(harness.telemetry.chatActivationStarted).toEqual([{
model: 'gpt-test',
provider: 'mock-provider',
sessionId: 'session-1',
source: 'text',
}])
expect(harness.telemetry.chatActivationSucceeded).toEqual([])
@@ -192,6 +192,7 @@ export interface ChatOrchestratorRuntimeDeps {
onTrackFirstMessage?: () => void
/** Called when a user starts a chat activation attempt. */
onChatActivationStarted?: (event: {
sessionId: string
source: 'text' | 'voice'
model: string
provider: string
@@ -247,6 +248,10 @@ export interface ChatOrchestratorRuntimeDeps {
sessionId: string
message: Extract<ChatHistoryItem, { role: 'user' }> & { id: string }
messageText: string
source: 'text' | 'voice'
model: string
provider: string
turnIndex: number
}) => void
/** Called after the assistant message has been finalized into session history. */
onAssistantMessageAppended?: (event: {
@@ -426,6 +431,7 @@ export function createChatOrchestratorRuntime(deps: ChatOrchestratorRuntimeDeps)
const activeProvider = deps.getActiveProvider?.() ?? ''
deps.onTrackFirstMessage?.()
deps.onChatActivationStarted?.({
sessionId,
source: sendSource,
model: options.model,
provider: activeProvider,
@@ -475,6 +481,7 @@ export function createChatOrchestratorRuntime(deps: ChatOrchestratorRuntimeDeps)
id: userMessageId,
}
deps.session.appendSessionMessage(sessionId, userMessage)
const userTurnIndex = deps.session.getSessionMessages(sessionId).filter(message => message.role === 'user').length
// Cloud sync v1: only the raw text part round-trips; image attachments
// and other non-text parts stay local.
@@ -482,6 +489,10 @@ export function createChatOrchestratorRuntime(deps: ChatOrchestratorRuntimeDeps)
sessionId,
message: userMessage,
messageText: sendingMessage,
source: sendSource,
model: options.model,
provider: activeProvider,
turnIndex: userTurnIndex,
})
const sessionMessagesForSend = deps.session.getSessionMessages(sessionId)