{"version":3,"file":"TranscriptionStreamConverter.mjs","sources":["../../../../src/room/transcription/TranscriptionStreamConverter.ts"],"sourcesContent":["import {\n  Transcription,\n  TranscriptionSegment as TranscriptionSegmentModel,\n} from '@livekit/protocol';\nimport log from '../../logger';\nimport type { TextStreamReader } from '../data-stream/incoming/StreamReader';\nimport { ParticipantAgentAttributes } from '../participant/attributes';\n\nexport interface TranscriptionStreamConverterOptions {\n  /** Invoked with a synthesized `Transcription` for every transcription update. */\n  onTranscription: (transcription: Transcription) => void;\n  /** Resolves the sid of the microphone track published by `identity`, if it has one. */\n  getMicrophoneTrackSid: (identity: string) => string | undefined;\n  /**\n   * Resolves the identity of a participant whose `lk.publish_on_behalf` attribute names\n   * `identity` - an avatar worker speaking for an agent, if one is present.\n   */\n  getDelegatingPublisherIdentity: (identity: string) => string | undefined;\n}\n\ninterface PartialTranscription {\n  /** The stream this text came from; a different stream id for the same segment replaces it. */\n  streamId: string;\n  text: string;\n  /** Last values handed to `onTranscription`, used to avoid emitting an identical update twice. */\n  emittedText?: string;\n  emittedFinal?: boolean;\n}\n\n/**\n * Rebuilds legacy-shaped `Transcription` messages from `lk.transcription` text streams, so\n * transcription events keep flowing once agents stop publishing the legacy `Transcription` data\n * packet (client protocol 3).\n *\n * Two stream shapes arrive on this topic and they accumulate differently:\n *\n * - **Delta** (agent speech): one stream per segment, each chunk an increment, finality on the\n *   closing trailer.\n * - **Non-delta** (user speech-to-text): a fresh stream per update, all sharing one\n *   `lk.segment_id`, each carrying the full text, finality on the header.\n *\n * So a new stream id for a segment already in flight *replaces* the accumulated text, and\n * `lk.transcription_final` is trusted whenever present - a stream close only implies finality when\n * the attribute is missing entirely. Treating every close as final would wrongly finalize each\n * interim user transcript.\n */\nexport default class TranscriptionStreamConverter {\n  private log = log;\n\n  private options: TranscriptionStreamConverterOptions;\n\n  /** In-flight segments, keyed by `partialKey(senderIdentity, segmentId)`. */\n  private partials = new Map<string, PartialTranscription>();\n\n  constructor(options: TranscriptionStreamConverterOptions) {\n    this.options = options;\n  }\n\n  /** Drops all in-flight segment state. */\n  reset() {\n    this.partials.clear();\n  }\n\n  handleTextStream = async (reader: TextStreamReader, senderIdentity: string) => {\n    const segmentId =\n      reader.info.attributes?.[ParticipantAgentAttributes.TranscriptionSegmentId] || reader.info.id;\n    const key = partialKey(senderIdentity, segmentId);\n\n    const existing = this.partials.get(key);\n    if (!existing || existing.streamId !== reader.info.id) {\n      this.partials.set(key, { streamId: reader.info.id, text: '' });\n    }\n\n    // Chunk boundaries follow the transport's packet splitting, not the sender's writes, so\n    // payload decoding has to carry state across chunks for the lifetime of this stream.\n    const decoder = new TranscriptStreamDecoder();\n\n    let final: boolean;\n    try {\n      for await (const chunk of reader) {\n        const partial = this.partials.get(key);\n        if (!partial || partial.streamId !== reader.info.id) {\n          // A newer stream for this segment took over while this one was still draining.\n          return;\n        }\n        partial.text += decoder.push(chunk);\n        this.emitSegment(partial, segmentId, senderIdentity, reader, this.isFinal(reader) ?? false);\n      }\n      final = this.isFinal(reader) ?? true;\n    } catch (err) {\n      // The stream ended abnormally (sender disconnected mid-segment, decode failure). Whatever\n      // was accumulated is all there will ever be, so close the segment out.\n      this.log.debug('lk.transcription stream ended abnormally', err);\n      final = true;\n    }\n\n    this.closeSegment(key, segmentId, senderIdentity, reader, final, decoder.flush());\n  };\n\n  private closeSegment(\n    key: string,\n    segmentId: string,\n    senderIdentity: string,\n    reader: TextStreamReader,\n    final: boolean,\n    trailingText: string,\n  ) {\n    const partial = this.partials.get(key);\n    if (!partial || partial.streamId !== reader.info.id) {\n      return;\n    }\n    partial.text += trailingText;\n    this.emitSegment(partial, segmentId, senderIdentity, reader, final);\n    if (final) {\n      this.partials.delete(key);\n    }\n  }\n\n  /**\n   * Works out which participant and track a transcription should be attributed to, matching what\n   * the legacy channel reported.\n   *\n   * In an avatar session the legacy channel named the *delegating publisher* (the avatar worker)\n   * rather than the agent it speaks for, and the stream's `lk.transcribed_track_id` is absent\n   * because the agent publishes no microphone track of its own. Preferring the worker keeps the\n   * identity stable across the cutover and lets `CoreRoom.handleTranscription` resolve a publication.\n   */\n  private resolveSpeaker(senderIdentity: string, reader: TextStreamReader) {\n    // `||` rather than `??` throughout: a resolver that reports \"nothing found\" as an empty string\n    // rather than undefined should fall through to the next candidate, not pin the result to ''.\n    // An empty identity resolves no participant, and an empty track sid resolves no publication,\n    // so treating either as a real answer silently stops the transcription events from firing.\n    const identity = this.options.getDelegatingPublisherIdentity(senderIdentity) || senderIdentity;\n    const trackId =\n      reader.info.attributes?.[ParticipantAgentAttributes.TranscribedTrackId] ||\n      this.options.getMicrophoneTrackSid(identity) ||\n      this.options.getMicrophoneTrackSid(senderIdentity) ||\n      '';\n    return { identity, trackId };\n  }\n\n  private emitSegment(\n    partial: PartialTranscription,\n    segmentId: string,\n    senderIdentity: string,\n    reader: TextStreamReader,\n    final: boolean,\n  ) {\n    if (typeof partial.emittedText === 'undefined' && partial.text === '') {\n      // A stream that carried no content at all - nothing worth surfacing.\n      return;\n    }\n    if (partial.emittedText === partial.text && partial.emittedFinal === final) {\n      // Nothing changed since the last emission (e.g. a non-delta stream closing with the same\n      // finality its header already declared).\n      return;\n    }\n    partial.emittedText = partial.text;\n    partial.emittedFinal = final;\n\n    const { identity, trackId } = this.resolveSpeaker(senderIdentity, reader);\n\n    this.options.onTranscription(\n      new Transcription({\n        transcribedParticipantIdentity: identity,\n        trackId,\n        segments: [\n          new TranscriptionSegmentModel({\n            id: segmentId,\n            text: partial.text,\n            // Agents write zeroes and an empty language into legacy packets, so nothing is lost.\n            startTime: BigInt(0),\n            endTime: BigInt(0),\n            final,\n            language: '',\n          }),\n        ],\n      }),\n    );\n  }\n\n  /** `undefined` when the sender declared no finality at all. */\n  private isFinal(reader: TextStreamReader): boolean | undefined {\n    const raw = reader.info.attributes?.[ParticipantAgentAttributes.TranscriptionFinal];\n    if (typeof raw === 'undefined') {\n      return undefined;\n    }\n    // Agents send the string form even though the generated attribute typing calls it a boolean.\n    return raw === 'true' || raw === '1' || (raw as unknown) === true;\n  }\n}\n\nfunction partialKey(senderIdentity: string, segmentId: string) {\n  return `${senderIdentity}/${segmentId}`;\n}\n\n/**\n * Decodes the chunks of a single `lk.transcription` stream into transcript text, unwrapping the\n * payloads of an agent running with `json_format`. That mode wraps every write as a JSON\n * `TimedString` (`{\"text\": \"...\", \"start_time\": 1.5}`) terminated by a newline.\n *\n * There is no wire marker for this mode - no attribute, no distinct mime type - so the stream's\n * first chunk is sniffed: one opening with `{\"` puts the whole stream in JSON mode. A plain-text\n * transcript that happens to start that way still comes through intact, since lines that fail to\n * parse as a `TimedString` are passed through verbatim; it just isn't surfaced until each newline\n * (or the stream's close) arrives. The durable fix is a marker attribute on the agent side.\n *\n * A chunk is a transport packet, not a sender write: a `TimedString` larger than one packet arrives\n * split across chunks, and one chunk may hold several. So JSON mode buffers and only decodes\n * complete newline-terminated lines. Whatever is left unterminated when the stream closes (agents\n * write their final markup-stripped tail unencoded) is decoded by `flush`.\n *\n * Only the text is taken. `TimedString` also carries `start_time`/`end_time` as floating point\n * values in an undocumented unit, while the proto segment fields are `uint64` - and the legacy\n * channel always reported zero - so the timings are deliberately dropped rather than guessed at.\n */\nclass TranscriptStreamDecoder {\n  /** Whether the stream is in JSON mode; `undefined` until the first non-blank chunk decides. */\n  private json?: boolean;\n\n  /** JSON mode only: the trailing, not yet newline-terminated part of the stream. */\n  private buffered = '';\n\n  /** Returns the transcript text the chunk completes, possibly empty. */\n  push(chunk: string): string {\n    this.json ??= chunk.trim() === '' ? undefined : chunk.trim().startsWith('{\"');\n    if (!this.json) {\n      return chunk;\n    }\n\n    this.buffered += chunk;\n    const lines = this.buffered.split('\\n');\n    this.buffered = lines.pop() ?? '';\n    return lines.map((line) => unwrapTimedString(line) ?? `${line}\\n`).join('');\n  }\n\n  /** Returns any text still buffered at the end of the stream. */\n  flush(): string {\n    const rest = this.buffered;\n    this.buffered = '';\n    return unwrapTimedString(rest) ?? rest;\n  }\n}\n\n/** The `text` of a JSON `TimedString` line, or `undefined` if the line is not one. */\nfunction unwrapTimedString(line: string): string | undefined {\n  const trimmed = line.trim();\n  if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) {\n    return undefined;\n  }\n  try {\n    const parsed: unknown = JSON.parse(trimmed);\n    if (\n      parsed !== null &&\n      typeof parsed === 'object' &&\n      typeof (parsed as { text?: unknown }).text === 'string'\n    ) {\n      return (parsed as { text: string }).text;\n    }\n  } catch {\n    // Not JSON after all - it is ordinary transcript text that happens to be brace-wrapped.\n  }\n  return undefined;\n}\n"],"names":["TranscriptionStreamConverter","constructor","options","log","partials","Map","handleTextStream","reader","senderIdentity","__awaiter","segmentId","_e","info","attributes","ParticipantAgentAttributes","TranscriptionSegmentId","id","key","partialKey","existing","get","streamId","set","text","decoder","TranscriptStreamDecoder","final","_a","reader_1","__asyncValues","_d","reader_1_1","value","chunk","partial","push","emitSegment","_f","isFinal","_g","err","debug","closeSegment","flush","reset","clear","trailingText","delete","resolveSpeaker","identity","getDelegatingPublisherIdentity","trackId","TranscribedTrackId","getMicrophoneTrackSid","emittedText","emittedFinal","_this$resolveSpeaker","onTranscription","Transcription","transcribedParticipantIdentity","segments","TranscriptionSegmentModel","startTime","BigInt","endTime","language","raw","TranscriptionFinal","undefined","concat","buffered","json","trim","startsWith","lines","split","_b","pop","map","line","unwrapTimedString","join","rest","trimmed","endsWith","parsed","JSON","parse"],"mappings":"kOA6BA;;;;;;;;;;;;;;;;AAgBG;AACW,MAAOA,4BAA4B,CAAA;EAQ/CC,WAAAA,CAAYC,OAA4C,EAAA;IAPhD,IAAA,CAAAC,GAAG,GAAGA,aAAG;AAIjB;AACQ,IAAA,IAAA,CAAAC,QAAQ,GAAG,IAAIC,GAAG,EAAgC;AAW1D,IAAA,IAAA,CAAAC,gBAAgB,GAAG,CAAOC,MAAwB,EAAEC,cAAsB,KAAIC,SAAA,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,aAAA;;;;AAC5E,MAAA,MAAMC,SAAS,GACb,CAAA,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