{"version":3,"file":"workflowStepMessage.mjs","names":[],"sources":["../../../../src/tui/workflow/workflowStepMessage.ts"],"sourcesContent":["import type { Theme } from '@earendil-works/pi-coding-agent';\nimport { Box, type Component, Text, truncateToWidth } from '@earendil-works/pi-tui';\n\nimport type { StepReport } from './workflowStatusRow';\n\nexport interface WorkflowStepMessageDetails {\n  displayName: string;\n  duration?: string;\n  job: string;\n  status: StepReport['status'];\n  step: string;\n}\n\nexport function workflowStepMessageDetails(displayName: string, report: StepReport): WorkflowStepMessageDetails {\n  return {\n    displayName,\n    job: report.job,\n    status: report.status,\n    step: report.step,\n    ...(report.duration ? { duration: report.duration } : {}),\n  };\n}\n\nexport function formatWorkflowStepMessage(details: WorkflowStepMessageDetails): string {\n  const transition = details.duration\n    ? `${details.status}::${details.duration}::${details.step}`\n    : `${details.status}::${details.step}`;\n  return `[${details.displayName}]: ${details.job}\\n${transition}`;\n}\n\nexport function isWorkflowStepMessageDetails(value: unknown): value is WorkflowStepMessageDetails {\n  if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n  const candidate = value as Partial<WorkflowStepMessageDetails>;\n  return (\n    typeof candidate.displayName === 'string' &&\n    typeof candidate.job === 'string' &&\n    typeof candidate.step === 'string' &&\n    (candidate.status === 'STARTED' || candidate.status === 'FINISHED' || candidate.status === 'FAILED') &&\n    (candidate.duration === undefined || typeof candidate.duration === 'string')\n  );\n}\n\nclass WorkflowStepMessageLines implements Component {\n  constructor(\n    private readonly details: WorkflowStepMessageDetails,\n    private readonly theme: Theme,\n  ) {}\n\n  render(width: number): string[] {\n    const header = `${this.theme.fg('accent', `[${this.details.displayName}]:`)} ${this.details.job}`;\n    const transition = this.details.duration\n      ? `${this.details.status}::${this.details.duration}::${this.details.step}`\n      : `${this.details.status}::${this.details.step}`;\n    const colour =\n      this.details.status === 'FAILED' ? 'error' : this.details.status === 'FINISHED' ? 'success' : 'accent';\n    return [truncateToWidth(header, width), truncateToWidth(this.theme.fg(colour, transition), width)];\n  }\n\n  invalidate(): void {}\n}\n\nexport function renderWorkflowStepMessage(\n  details: WorkflowStepMessageDetails | undefined,\n  fallback: string,\n  outputPad: number,\n  theme: Theme,\n): Component {\n  const box = new Box(outputPad, 1, (text) => theme.bg('customMessageBg', text));\n  box.addChild(details ? new WorkflowStepMessageLines(details, theme) : new Text(fallback, 0, 0));\n  return box;\n}\n"],"mappings":";;AA8BA,SAAgB,6BAA6B,OAAqD;CAChG,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO;CACxE,MAAM,YAAY;CAClB,OACE,OAAO,UAAU,gBAAgB,YACjC,OAAO,UAAU,QAAQ,YACzB,OAAO,UAAU,SAAS,aACzB,UAAU,WAAW,aAAa,UAAU,WAAW,cAAc,UAAU,WAAW,cAC1F,UAAU,aAAa,KAAA,KAAa,OAAO,UAAU,aAAa;AAEvE;AAEA,IAAM,2BAAN,MAAoD;CAE/B;CACA;CAFnB,YACE,SACA,OACA;EAFiB,KAAA,UAAA;EACA,KAAA,QAAA;CAChB;CAEH,OAAO,OAAyB;EAC9B,MAAM,SAAS,GAAG,KAAK,MAAM,GAAG,UAAU,IAAI,KAAK,QAAQ,YAAY,GAAG,EAAE,GAAG,KAAK,QAAQ;EAC5F,MAAM,aAAa,KAAK,QAAQ,WAC5B,GAAG,KAAK,QAAQ,OAAO,IAAI,KAAK,QAAQ,SAAS,IAAI,KAAK,QAAQ,SAClE,GAAG,KAAK,QAAQ,OAAO,IAAI,KAAK,QAAQ;EAC5C,MAAM,SACJ,KAAK,QAAQ,WAAW,WAAW,UAAU,KAAK,QAAQ,WAAW,aAAa,YAAY;EAChG,OAAO,CAAC,gBAAgB,QAAQ,KAAK,GAAG,gBAAgB,KAAK,MAAM,GAAG,QAAQ,UAAU,GAAG,KAAK,CAAC;CACnG;CAEA,aAAmB,CAAC;AACtB;AAEA,SAAgB,0BACd,SACA,UACA,WACA,OACW;CACX,MAAM,MAAM,IAAI,IAAI,WAAW,IAAI,SAAS,MAAM,GAAG,mBAAmB,IAAI,CAAC;CAC7E,IAAI,SAAS,UAAU,IAAI,yBAAyB,SAAS,KAAK,IAAI,IAAI,KAAK,UAAU,GAAG,CAAC,CAAC;CAC9F,OAAO;AACT"}