{"version":3,"file":"thinking-duration-formatter.mjs","names":[],"sources":["../../../../src/ai/thinking/thinking-duration-formatter.ts"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\n/**\n * Formats a duration in milliseconds to a human-readable representation with automatic unit selection.\n *\n * The function selects the most appropriate time unit (milliseconds, seconds, minutes, or hours)\n * based on the input value and applies smart rounding:\n * - Values under 10 in a given unit are rounded to 1 decimal place\n * - Values 10 or greater are rounded to whole numbers\n * - Unit names are automatically pluralized based on the value\n *\n * @param ms - The duration in milliseconds to format. Negative or NaN values return `{ unit: 'seconds', value: 0 }`\n * @returns An object containing:\n *   - `unit`: The time unit string (e.g., 'second', 'seconds', 'minute', 'minutes')\n *   - `value`: The numeric value in the selected unit\n *\n * @example\n * formatThinkingDuration(500)    // `{ unit: 'milliseconds', value: 500 }`\n * formatThinkingDuration(1500)   // `{ unit: 'seconds', value: 1.5 }`\n * formatThinkingDuration(65000)  // `{ unit: 'minutes', value: 1.1 }`\n * formatThinkingDuration(3600000) // `{ unit: 'hour', value: 1 }`\n */\nexport const formatThinkingDuration = (\n  ms: number,\n): { unit: string; value: number } => {\n  if (Number.isNaN(ms) || ms < 0) {\n    return { unit: 'seconds', value: 0 };\n  }\n\n  if (ms < 1000) {\n    const value = Math.round(ms);\n    const unit = value === 1 ? 'millisecond' : 'milliseconds';\n    return { unit, value };\n  }\n\n  const seconds = ms / 1000;\n\n  if (seconds < 60) {\n    const value =\n      seconds < 10 ? Math.round(seconds * 10) / 10 : Math.round(seconds);\n    const unit = value === 1 ? 'second' : 'seconds';\n    return { unit, value };\n  }\n\n  const minutes = seconds / 60;\n\n  if (minutes < 60) {\n    const value =\n      minutes < 10 ? Math.round(minutes * 10) / 10 : Math.round(minutes);\n    const unit = value === 1 ? 'minute' : 'minutes';\n    return { unit, value };\n  }\n\n  const hours = minutes / 60;\n  const value = hours < 10 ? Math.round(hours * 10) / 10 : Math.round(hours);\n  const unit = value === 1 ? 'hour' : 'hours';\n\n  return { unit, value };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,0BACX,OACoC;CACpC,IAAI,OAAO,MAAM,EAAE,KAAK,KAAK,GAC3B,OAAO;EAAE,MAAM;EAAW,OAAO;CAAE;CAGrC,IAAI,KAAK,KAAM;EACb,MAAM,QAAQ,KAAK,MAAM,EAAE;EAE3B,OAAO;GAAE,MADI,UAAU,IAAI,gBAAgB;GAC5B;EAAM;CACvB;CAEA,MAAM,UAAU,KAAK;CAErB,IAAI,UAAU,IAAI;EAChB,MAAM,QACJ,UAAU,KAAK,KAAK,MAAM,UAAU,EAAE,IAAI,KAAK,KAAK,MAAM,OAAO;EAEnE,OAAO;GAAE,MADI,UAAU,IAAI,WAAW;GACvB;EAAM;CACvB;CAEA,MAAM,UAAU,UAAU;CAE1B,IAAI,UAAU,IAAI;EAChB,MAAM,QACJ,UAAU,KAAK,KAAK,MAAM,UAAU,EAAE,IAAI,KAAK,KAAK,MAAM,OAAO;EAEnE,OAAO;GAAE,MADI,UAAU,IAAI,WAAW;GACvB;EAAM;CACvB;CAEA,MAAM,QAAQ,UAAU;CACxB,MAAM,QAAQ,QAAQ,KAAK,KAAK,MAAM,QAAQ,EAAE,IAAI,KAAK,KAAK,MAAM,KAAK;CAGzE,OAAO;EAAE,MAFI,UAAU,IAAI,SAAS;EAErB;CAAM;AACvB"}