Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

[Metabot] Display thinking duration in minutes + seconds for long duration replies (#83977)

Sloan Sparger8fc033ceb021
diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx
index 20b4cb46524..3c56da1dcc7 100644
--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx
@@ -149,6 +149,34 @@ describe("MetabotChainOfThought", () => {
expect(screen.queryByText(/Worked/)).not.toBeInTheDocument();
});
+ it("displays thinking >= 60 seconds in minutes and seconds", () => {
+ setup(
+ chain({
+ steps: [{ kind: "reasoning", text: "Weighing the join order" }],
+ startedAtMs: 1000,
+ endedAtMs: 697000,
+ }),
+ false,
+ );
+ expect(
+ screen.getAllByText("Thought for 11 minutes 36 seconds").length,
+ ).toBeGreaterThan(0);
+ });
+
+ it("displays even minute thinking durations without seconds", () => {
+ setup(
+ chain({
+ steps: [
+ { kind: "tool", id: "t1", name: "analyze_data", status: "ended" },
+ ],
+ startedAtMs: 1000,
+ endedAtMs: 61000,
+ }),
+ false,
+ );
+ expect(screen.getByText("Worked for 1 minute")).toBeInTheDocument();
+ });
+
it("rolls a sub-5s thinking-only turn up to Thought briefly", () => {
setup(
chain({
diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx
index bb3ccb3f250..1bbfd991a13 100644
--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx
@@ -223,19 +223,33 @@ const exactSeconds = (durationMs: number | undefined): number | null =>
? Math.round(durationMs / 1000)
: null;
+const formatDuration = (totalSeconds: number): string => {
+ const minutes = Math.floor(totalSeconds / 60);
+ const seconds = totalSeconds % 60;
+
+ if (minutes === 0) {
+ return ngettext(msgid`${seconds} second`, `${seconds} seconds`, seconds);
+ } else if (seconds === 0) {
+ return ngettext(msgid`${minutes} minute`, `${minutes} minutes`, minutes);
+ } else if (seconds === 1) {
+ return ngettext(
+ msgid`${minutes} minute ${seconds} second`,
+ `${minutes} minutes ${seconds} second`,
+ minutes,
+ );
+ } else {
+ return ngettext(
+ msgid`${minutes} minute ${seconds} seconds`,
+ `${minutes} minutes ${seconds} seconds`,
+ minutes,
+ );
+ }
+};
+
const thoughtFor = (seconds: number) =>
- ngettext(
- msgid`Thought for ${seconds} second`,
- `Thought for ${seconds} seconds`,
- seconds,
- );
+ t`Thought for ${formatDuration(seconds)}`;
-const workedFor = (seconds: number) =>
- ngettext(
- msgid`Worked for ${seconds} second`,
- `Worked for ${seconds} seconds`,
- seconds,
- );
+const workedFor = (seconds: number) => t`Worked for ${formatDuration(seconds)}`;
export const reasoningLabel = (durationMs: number | undefined): string => {
const seconds = exactSeconds(durationMs);