Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion webview-ui/src/components/history/HistoryView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useState } from "react"
import React, { memo, useState, useMemo } from "react"
import { DeleteTaskDialog } from "./DeleteTaskDialog"
import { BatchDeleteTaskDialog } from "./BatchDeleteTaskDialog"
import prettyBytes from "pretty-bytes"
Expand Down Expand Up @@ -74,6 +74,14 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
}
}

// Calculate total API cost for current tasks
const totalApiCost = useMemo(() => {
return tasks.reduce((sum, task) => {
const cost = typeof task.totalCost === "string" ? parseFloat(task.totalCost) : task.totalCost
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a case where totalCost is a string?
i'm guessing the type is a string, but i'm a bit confused as to where it's being used since free model is 0 right? instead of some other string value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more of a safeguard really, I can always change it

return sum + (isNaN(cost) ? 0 : cost)
}, 0)
}, [tasks])

return (
<Tab>
<TabHeader className="flex flex-col gap-2">
Expand All @@ -96,6 +104,9 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
<Button onClick={onDone}>{t("history:done")}</Button>
</div>
</div>
<div className="text-vscode-descriptionForeground text-sm font-semibold">
{`Total ${t("history:apiCostLabel")}`} ${totalApiCost.toFixed(4)}
</div>
<div className="flex flex-col gap-2">
<VSCodeTextField
style={{ width: "100%" }}
Expand Down