mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
fix: truncate long ai chat tool labels and fold extra tool kinds into +N (#12185)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c04180c5d6
commit
8dd97a5a2d
@@ -4,6 +4,7 @@
|
||||
import { fade, slide } from 'svelte/transition'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { HeldValue, LABEL_MIN_MS } from './heldValue.svelte'
|
||||
import Tooltip from '$lib/components/meltComponents/Tooltip.svelte'
|
||||
|
||||
interface Props {
|
||||
label: string
|
||||
@@ -12,6 +13,8 @@
|
||||
* label weight, because a caller emphasising the label is also setting a proportional
|
||||
* typeface, whose medium reads heavier than the mono one at this size. */
|
||||
labelPrefix?: string
|
||||
/** Parts left out of the label, shown as `+N` after it and listed on hover. */
|
||||
labelMore?: string[]
|
||||
expanded: boolean
|
||||
onToggle: () => void
|
||||
// A card with nothing to reveal keeps the header inert (no chevron, no
|
||||
@@ -43,6 +46,7 @@
|
||||
let {
|
||||
label,
|
||||
labelPrefix,
|
||||
labelMore,
|
||||
expanded,
|
||||
onToggle,
|
||||
toggleable = true,
|
||||
@@ -63,11 +67,11 @@
|
||||
// right after its last status would show the running label, shimmer or line beside the
|
||||
// settled others.
|
||||
const held = new HeldValue(
|
||||
() => ({ prefix: labelPrefix, label, shimmer, liveLine }),
|
||||
() => ({ prefix: labelPrefix, label, more: labelMore, shimmer, liveLine }),
|
||||
() => (settleLabel ? LABEL_MIN_MS : 0)
|
||||
)
|
||||
const shown = $derived(
|
||||
settleLabel ? held.current : { prefix: labelPrefix, label, shimmer, liveLine }
|
||||
settleLabel ? held.current : { prefix: labelPrefix, label, more: labelMore, shimmer, liveLine }
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -88,7 +92,7 @@
|
||||
{#snippet headerButton()}
|
||||
<button
|
||||
class={twMerge(
|
||||
'min-w-0 py-0.5 my-0.5 rounded-md hover:bg-surface-hover transition-colors inline-flex items-center gap-2 text-left',
|
||||
'min-w-0 max-w-full py-0.5 my-0.5 rounded-md hover:bg-surface-hover transition-colors inline-flex items-center gap-2 text-left',
|
||||
headerClass
|
||||
)}
|
||||
onclick={onToggle}
|
||||
@@ -115,6 +119,18 @@
|
||||
{:else}
|
||||
{@render labelText(false)}
|
||||
{/if}
|
||||
{#if shown.more?.length}
|
||||
<Tooltip small placement="top" class="shrink-0 pl-1">
|
||||
<span class="text-2xs font-medium text-tertiary">+{shown.more.length}</span>
|
||||
{#snippet text()}
|
||||
<div class="text-xs">
|
||||
{#each shown.more ?? [] as part (part)}
|
||||
<div>{part}</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/snippet}
|
||||
</Tooltip>
|
||||
{/if}
|
||||
</span>
|
||||
{/key}
|
||||
{#if toggleable}
|
||||
|
||||
@@ -366,7 +366,7 @@
|
||||
? 'opacity-60 hover:opacity-100 transition-opacity'
|
||||
: ''}
|
||||
headerClass={message.needsConfirmation || pendingOutOfScope ? 'opacity-80' : ''}
|
||||
labelClass={showPreviewChip ? 'truncate' : ''}
|
||||
labelClass="truncate"
|
||||
contentClass="space-y-3"
|
||||
headerRight={showPreviewChip ? previewChip : message.jobId ? jobLink : undefined}
|
||||
headerLeft={mcpServer?.workspace ? serverMark : undefined}
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
<ChatCollapsibleCard
|
||||
labelPrefix={header.prefix}
|
||||
label={header.label}
|
||||
labelMore={header.more}
|
||||
{expanded}
|
||||
onToggle={() => (expanded = !expanded)}
|
||||
shimmer={running}
|
||||
|
||||
@@ -289,6 +289,22 @@ describe('groupToolRuns', () => {
|
||||
const other = tool('call_mcp_read_tool', { server: 'f/team/github', tool: 'get_issue' })
|
||||
expect(header([mcp('list_issues'), other])).toBe('List issues, get issue')
|
||||
})
|
||||
|
||||
it('names the first three kinds of call and leaves the rest to `more`', () => {
|
||||
const group = groupToolRuns([
|
||||
tool('search_workspace'),
|
||||
tool('list_runs'),
|
||||
tool('read_workspace_item'),
|
||||
tool('search_docs'),
|
||||
tool('search_workspace'),
|
||||
tool('list_workers')
|
||||
]).find((item) => item.kind === 'group') as ToolGroup
|
||||
expect(groupHeader(group, 'settled')).toEqual({
|
||||
prefix: '',
|
||||
label: 'Search workspace 2 times, list runs, read workspace item',
|
||||
more: ['search docs', 'list workers']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('createChatItemGrouper', () => {
|
||||
|
||||
@@ -385,21 +385,27 @@ function repeated(name: string, n: number): string {
|
||||
* says what will happen rather than what did. */
|
||||
export type GroupState = 'queued' | 'running' | 'settled'
|
||||
|
||||
// Past this many kinds of call the header names the rest only as a count, so a long read run
|
||||
// keeps its first kinds legible instead of being cut off by the row's ellipsis.
|
||||
const LISTED_KINDS = 3
|
||||
|
||||
/** The group's header, e.g. `Edited` + `f/a/flow · 3 changes`,
|
||||
* `search workspace 2 times, read 2 workspace item`, `github` + `list issues, get issue 2 times`. */
|
||||
* `search workspace 2 times, read 2 workspace item`, `github` + `list issues, get issue 2 times`.
|
||||
* `more` holds the kinds left out of `label`. */
|
||||
export function groupHeader(
|
||||
group: ToolGroup,
|
||||
state: GroupState
|
||||
): { prefix: string; label: string } {
|
||||
): { prefix: string; label: string; more: string[] } {
|
||||
const calls = group.entries
|
||||
.map((e) => e.message)
|
||||
.filter((m): m is ToolDisplayMessage => m.role === 'tool')
|
||||
if (group.groupKind === 'waiting') {
|
||||
// A queued row's content is its imperative label, e.g. `Execute SQL on "main"`.
|
||||
const names = [...new Set(calls.map((m) => m.content))].join(', ')
|
||||
const names = [...new Set(calls.map((m) => m.content))]
|
||||
return {
|
||||
prefix: `${plural(calls.length, 'more call')} waiting:`,
|
||||
label: names
|
||||
label: names.slice(0, LISTED_KINDS).join(', '),
|
||||
more: names.slice(LISTED_KINDS)
|
||||
}
|
||||
}
|
||||
if (group.groupKind === 'edit') {
|
||||
@@ -408,18 +414,21 @@ export function groupHeader(
|
||||
).length
|
||||
return {
|
||||
prefix: { queued: 'Edit', running: 'Editing', settled: 'Edited' }[state],
|
||||
label: `${group.target || 'the flow'} · ${plural(edits, 'change')}`
|
||||
label: `${group.target || 'the flow'} · ${plural(edits, 'change')}`,
|
||||
more: []
|
||||
}
|
||||
}
|
||||
const counts = new Map<string, number>()
|
||||
for (const call of calls) counts.set(callName(call), (counts.get(callName(call)) ?? 0) + 1)
|
||||
const list = [...counts].map(([name, n]) => repeated(name, n)).join(', ')
|
||||
const kinds = [...counts].map(([name, n]) => repeated(name, n))
|
||||
const list = kinds.slice(0, LISTED_KINDS).join(', ')
|
||||
const more = kinds.slice(LISTED_KINDS)
|
||||
// A tool search spans every server and usually comes right before the calls it found, so it
|
||||
// does not stop the group from reading as one server's.
|
||||
const servers = new Set(
|
||||
calls.filter((call) => call.toolName !== 'search_mcp_tools').map(mcpServerPath)
|
||||
)
|
||||
const [server] = servers
|
||||
if (servers.size === 1 && server) return { prefix: server.split('/').at(-1)!, label: list }
|
||||
return { prefix: '', label: list.charAt(0).toUpperCase() + list.slice(1) }
|
||||
if (servers.size === 1 && server) return { prefix: server.split('/').at(-1)!, label: list, more }
|
||||
return { prefix: '', label: list.charAt(0).toUpperCase() + list.slice(1), more }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user