fix(ui): show full turn duration in assistant meta (#14378)
This commit is contained in:
@@ -104,6 +104,7 @@ export interface MessagePartProps {
|
|||||||
hideDetails?: boolean
|
hideDetails?: boolean
|
||||||
defaultOpen?: boolean
|
defaultOpen?: boolean
|
||||||
showAssistantCopyPartID?: string | null
|
showAssistantCopyPartID?: string | null
|
||||||
|
turnDurationMs?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PartComponent = Component<MessagePartProps>
|
export type PartComponent = Component<MessagePartProps>
|
||||||
@@ -275,6 +276,7 @@ function renderable(part: PartType) {
|
|||||||
export function AssistantParts(props: {
|
export function AssistantParts(props: {
|
||||||
messages: AssistantMessage[]
|
messages: AssistantMessage[]
|
||||||
showAssistantCopyPartID?: string | null
|
showAssistantCopyPartID?: string | null
|
||||||
|
turnDurationMs?: number
|
||||||
working?: boolean
|
working?: boolean
|
||||||
}) {
|
}) {
|
||||||
const data = useData()
|
const data = useData()
|
||||||
@@ -365,6 +367,7 @@ export function AssistantParts(props: {
|
|||||||
part={entry().part}
|
part={entry().part}
|
||||||
message={entry().message}
|
message={entry().message}
|
||||||
showAssistantCopyPartID={props.showAssistantCopyPartID}
|
showAssistantCopyPartID={props.showAssistantCopyPartID}
|
||||||
|
turnDurationMs={props.turnDurationMs}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Show>
|
</Show>
|
||||||
@@ -849,6 +852,7 @@ export function Part(props: MessagePartProps) {
|
|||||||
hideDetails={props.hideDetails}
|
hideDetails={props.hideDetails}
|
||||||
defaultOpen={props.defaultOpen}
|
defaultOpen={props.defaultOpen}
|
||||||
showAssistantCopyPartID={props.showAssistantCopyPartID}
|
showAssistantCopyPartID={props.showAssistantCopyPartID}
|
||||||
|
turnDurationMs={props.turnDurationMs}
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
)
|
)
|
||||||
@@ -1060,8 +1064,12 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
|
|||||||
if (props.message.role !== "assistant") return ""
|
if (props.message.role !== "assistant") return ""
|
||||||
const message = props.message as AssistantMessage
|
const message = props.message as AssistantMessage
|
||||||
const completed = message.time.completed
|
const completed = message.time.completed
|
||||||
if (typeof completed !== "number") return ""
|
const ms =
|
||||||
const ms = completed - message.time.created
|
typeof props.turnDurationMs === "number"
|
||||||
|
? props.turnDurationMs
|
||||||
|
: typeof completed === "number"
|
||||||
|
? completed - message.time.created
|
||||||
|
: -1
|
||||||
if (!(ms >= 0)) return ""
|
if (!(ms >= 0)) return ""
|
||||||
const total = Math.round(ms / 1000)
|
const total = Math.round(ms / 1000)
|
||||||
if (total < 60) return `${total}s`
|
if (total < 60) return `${total}s`
|
||||||
|
|||||||
@@ -247,6 +247,21 @@ export function SessionTurn(
|
|||||||
if (working()) return null
|
if (working()) return null
|
||||||
return showAssistantCopyPartID() ?? null
|
return showAssistantCopyPartID() ?? null
|
||||||
})
|
})
|
||||||
|
const turnDurationMs = createMemo(() => {
|
||||||
|
const start = message()?.time.created
|
||||||
|
if (typeof start !== "number") return undefined
|
||||||
|
|
||||||
|
const end = assistantMessages().reduce<number | undefined>((max, item) => {
|
||||||
|
const completed = item.time.completed
|
||||||
|
if (typeof completed !== "number") return max
|
||||||
|
if (max === undefined) return completed
|
||||||
|
return Math.max(max, completed)
|
||||||
|
}, undefined)
|
||||||
|
|
||||||
|
if (typeof end !== "number") return undefined
|
||||||
|
if (end < start) return undefined
|
||||||
|
return end - start
|
||||||
|
})
|
||||||
const assistantVisible = createMemo(() =>
|
const assistantVisible = createMemo(() =>
|
||||||
assistantMessages().reduce((count, message) => {
|
assistantMessages().reduce((count, message) => {
|
||||||
const parts = list(data.store.part?.[message.id], emptyParts)
|
const parts = list(data.store.part?.[message.id], emptyParts)
|
||||||
@@ -290,6 +305,7 @@ export function SessionTurn(
|
|||||||
<AssistantParts
|
<AssistantParts
|
||||||
messages={assistantMessages()}
|
messages={assistantMessages()}
|
||||||
showAssistantCopyPartID={assistantCopyPartID()}
|
showAssistantCopyPartID={assistantCopyPartID()}
|
||||||
|
turnDurationMs={turnDurationMs()}
|
||||||
working={working()}
|
working={working()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user