Skip to content

Commit 78a6325

Browse files
committed
improve model footer
1 parent c96923d commit 78a6325

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,11 @@ export function Session() {
860860
</Match>
861861
<Match when={message.role === "assistant"}>
862862
<AssistantMessage
863+
user={
864+
messages().findLast(
865+
(item) => item.id === (message as AssistantMessage).parentID,
866+
) as UserMessage
867+
}
863868
last={lastAssistant()?.id === message.id}
864869
message={message as AssistantMessage}
865870
parts={sync.data.part[message.id] ?? []}
@@ -993,7 +998,7 @@ function UserMessage(props: {
993998
)
994999
}
9951000

996-
function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; last: boolean }) {
1001+
function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; last: boolean; user: UserMessage }) {
9971002
const local = useLocal()
9981003
const { theme } = useTheme()
9991004
const ctx = use()
@@ -1038,13 +1043,15 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
10381043
>
10391044
<box paddingLeft={3}>
10401045
<text marginTop={1}>
1041-
<span style={{ fg: local.agent.color(props.message.mode) }}>{Locale.titlecase(props.message.mode)}</span>{" "}
1042-
<span style={{ fg: theme.textMuted }}>
1043-
{props.message.modelID}
1044-
{ctx.showTimestamps() &&
1045-
props.message.time.completed &&
1046-
` · ${Locale.todayTimeOrDateTime(props.message.time.completed)}`}
1047-
</span>
1046+
<span style={{ fg: local.agent.color(props.message.mode) }}></span>{" "}
1047+
<span style={{ fg: theme.text }}>{Locale.titlecase(props.message.mode)}</span>{" "}
1048+
<span style={{ fg: theme.textMuted }}>{props.message.modelID}</span>
1049+
<Show when={props.message.time.completed}>
1050+
<span style={{ fg: theme.textMuted }}>
1051+
{" "}
1052+
{Locale.duration(props.message.time.completed! - props.user.time.created)}
1053+
</span>
1054+
</Show>
10481055
</text>
10491056
</box>
10501057
</Match>

packages/opencode/src/util/locale.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ export namespace Locale {
3737
return num.toString()
3838
}
3939

40+
export function duration(input: number) {
41+
if (input < 1000) {
42+
return `${input}ms`
43+
}
44+
if (input < 60000) {
45+
return `${(input / 1000).toFixed(1)}s`
46+
}
47+
if (input < 3600000) {
48+
const minutes = Math.floor(input / 60000)
49+
const seconds = Math.floor((input % 60000) / 1000)
50+
return `${minutes}m ${seconds}s`
51+
}
52+
if (input < 86400000) {
53+
const hours = Math.floor(input / 3600000)
54+
const minutes = Math.floor((input % 3600000) / 60000)
55+
return `${hours}h ${minutes}m`
56+
}
57+
const hours = Math.floor(input / 3600000)
58+
const days = Math.floor((input % 3600000) / 86400000)
59+
return `${days}d ${hours}h`
60+
}
61+
4062
export function truncate(str: string, len: number): string {
4163
if (str.length <= len) return str
4264
return str.slice(0, len - 1) + "…"

0 commit comments

Comments
 (0)