{"version":3,"file":"protocolTimeline.mjs","names":[],"sources":["../../../src/web/lib/protocolTimeline.ts"],"sourcesContent":["import type {\n  AssistantTranscriptItem,\n  ToolTranscriptItem,\n  TranscriptItem,\n  UserTranscriptItem,\n} from '@agimon-ai/po-core/sessionProtocol';\nimport type { ToolResultView } from '@agimon-ai/po-core/web';\n\nimport {\n  assistantFailureText,\n  imagesFromContent,\n  summariseArgs,\n  type AssistantEntry,\n  type QueuedEntry,\n  type TimelineEntry,\n  type ToolEntry,\n  type UserEntry,\n} from './sessionModel';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction userEntry(item: UserTranscriptItem): UserEntry & { timestamp: number } {\n  const text = item.content\n    .filter((part): part is { type: 'text'; text: string } => part.type === 'text')\n    .map((part) => part.text)\n    .join('');\n  const images = imagesFromContent(item.content);\n  return { kind: 'user', id: item.id, text, timestamp: item.timestamp, ...(images.length > 0 ? { images } : {}) };\n}\n\nfunction assistantEntry(item: AssistantTranscriptItem): AssistantEntry & { timestamp: number } {\n  let text = '';\n  let thinking = '';\n  for (const part of item.content) {\n    if (part.type === 'text') text += part.text;\n    else if (part.type === 'thinking') thinking += part.thinking;\n  }\n  return {\n    kind: 'assistant',\n    id: item.id,\n    text: [text, assistantFailureText(item)].filter(Boolean).join('\\n\\n'),\n    thinking,\n    streaming: item.status === 'streaming',\n    timestamp: item.timestamp,\n  };\n}\n\n/**\n * Rebuilds the tool card's view from the protocol item.\n *\n * `details` is the one field the protocol leaves open on a tool item, which is\n * where a Po tool's own payload travels; handing it back whole is what\n * lets the owning plugin render its call the way it does in the terminal.\n */\nfunction toolEntry(item: ToolTranscriptItem): ToolEntry & { timestamp: number } {\n  const output = item.content\n    .filter((part): part is { type: 'text'; text: string } => part.type === 'text')\n    .map((part) => part.text)\n    .join('\\n');\n  const result: ToolResultView | null =\n    item.content.length > 0 || item.details !== undefined\n      ? { content: [...item.content], details: item.details }\n      : null;\n  return {\n    kind: 'tool',\n    id: item.id,\n    toolCallId: item.toolCallId,\n    name: item.toolName,\n    args: isRecord(item.input) ? item.input : {},\n    argSummary: summariseArgs(item.input),\n    result,\n    output,\n    isError: item.isError,\n    running: item.status === 'running',\n    timestamp: item.timestamp,\n  };\n}\n\nconst projectedEntries = new WeakMap<TranscriptItem, TimelineEntry>();\n\n/** Projects one immutable protocol item once, so updates do not rebuild settled history. */\nfunction timelineEntry(item: TranscriptItem): TimelineEntry {\n  const cached = projectedEntries.get(item);\n  if (cached !== undefined) return cached;\n  const projected =\n    item.role === 'user' ? userEntry(item) : item.role === 'assistant' ? assistantEntry(item) : toolEntry(item);\n  projectedEntries.set(item, projected);\n  return projected;\n}\n\n/** Projects the protocol transcript onto the timeline the cockpit renders. */\nexport function toTimelineEntries(transcript: readonly TranscriptItem[]): TimelineEntry[] {\n  return transcript.map(timelineEntry);\n}\n\n/** Projects the protocol's authoritative pending steer queue onto composer rows. */\nexport function toQueuedEntries(queue: readonly UserTranscriptItem[]): QueuedEntry[] {\n  return queue.map((item) => {\n    const { timestamp: _timestamp, ...entry } = userEntry(item);\n    return { ...entry, kind: 'queued', delivery: 'steer' };\n  });\n}\n"],"mappings":";;AAmBA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,UAAU,MAA6D;CAC9E,MAAM,OAAO,KAAK,QACf,QAAQ,SAAiD,KAAK,SAAS,MAAM,CAAC,CAC9E,KAAK,SAAS,KAAK,IAAI,CAAC,CACxB,KAAK,EAAE;CACV,MAAM,SAAS,kBAAkB,KAAK,OAAO;CAC7C,OAAO;EAAE,MAAM;EAAQ,IAAI,KAAK;EAAI;EAAM,WAAW,KAAK;EAAW,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;CAAG;AAChH;AAEA,SAAS,eAAe,MAAuE;CAC7F,IAAI,OAAO;CACX,IAAI,WAAW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