The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): label a url chip with its host and path
Brooklyn Nicholsonee09162e4529
diff --git a/apps/desktop/src/app/chat/composer/rich-editor.ts b/apps/desktop/src/app/chat/composer/rich-editor.tsindex 21f0286c9f8..8978d6f1520 100644--- a/apps/desktop/src/app/chat/composer/rich-editor.ts+++ b/apps/desktop/src/app/chat/composer/rich-editor.ts@@ -11,11 +11,11 @@ import {directiveIconElement,directiveIconSvg,formatRefValue,+ refChipLabel,slashChipClass,type SlashChipKind,slashIconElement} from '@/components/assistant-ui/directive-text'-import { sessionRefFallbackLabel } from '@/lib/session-refs'export const RICH_INPUT_SLOT = 'composer-rich-input'@@ -35,10 +35,6 @@ export function unquoteRef(raw: string) {return quoted ? raw.slice(1, -1) : raw.replace(/[,.;!?]+$/, '')}-export function refLabel(id: string) {- return id.split(/[\\/]/).filter(Boolean).pop() || id-}-/** Always-quote variant of formatRefValue — chips need a fence even for safe values. */export function quoteRefValue(value: string) {if (!value.includes('`')) {@@ -60,9 +56,9 @@ export function refChipHtml(kind: string, rawValue: string, displayLabel?: strinconst id = unquoteRef(rawValue)const text = `@${kind}:${quoteRefValue(id)}`- const label = displayLabel || (kind === 'session' ? sessionRefFallbackLabel(id) : refLabel(id))+ const label = displayLabel || refChipLabel(kind, id)- return `<span contenteditable="false" data-ref-text="${escapeHtml(text)}" data-ref-id="${escapeHtml(id)}" data-ref-kind="${escapeHtml(kind)}" class="${DIRECTIVE_CHIP_CLASS}">${directiveIconSvg(kind)}<span class="truncate">${escapeHtml(label)}</span></span>`+ return `<span contenteditable="false" title="${escapeHtml(id)}" data-ref-text="${escapeHtml(text)}" data-ref-id="${escapeHtml(id)}" data-ref-kind="${escapeHtml(kind)}" class="${DIRECTIVE_CHIP_CLASS}">${directiveIconSvg(kind)}<span class="truncate">${escapeHtml(label)}</span></span>`}export function refChipElement(kind: string, rawValue: string, displayLabel?: string) {@@ -72,12 +68,13 @@ export function refChipElement(kind: string, rawValue: string, displayLabel?: stconst label = document.createElement('span')chip.contentEditable = 'false'+ chip.title = idchip.dataset.refText = textchip.dataset.refId = idchip.dataset.refKind = kindchip.className = DIRECTIVE_CHIP_CLASSlabel.className = 'truncate'- label.textContent = displayLabel || (kind === 'session' ? sessionRefFallbackLabel(id) : refLabel(id))+ label.textContent = displayLabel || refChipLabel(kind, id)chip.append(directiveIconElement(kind), label)return chipdiff --git a/apps/desktop/src/components/assistant-ui/directive-text.tsx b/apps/desktop/src/components/assistant-ui/directive-text.tsxindex 317489a96f8..312c7d9414d 100644--- a/apps/desktop/src/components/assistant-ui/directive-text.tsx+++ b/apps/desktop/src/components/assistant-ui/directive-text.tsx@@ -277,7 +277,7 @@ function parseDirectiveText(text: string): Unstable_DirectiveSegment[] {start: match.index ?? 0,end: (match.index ?? 0) + match[0].length,type: match[1] || 'file',- label: shortLabel(match[1] as HermesRefType, id),+ label: refChipLabel(match[1] || 'file', id),id}}),@@ -320,25 +320,30 @@ function parseDirectiveText(text: string): Unstable_DirectiveSegment[] {return segments}-function shortLabel(type: HermesRefType, id: string): string {+/** Display text for a `@kind:value` chip. Shared with the composer's+ * contenteditable chips so a link reads the same before and after send: the+ * host leads (scheme and `www.` are noise) and the path rides along for the+ * chip's `truncate` to cut — a bare hostname can't tell two links apart. */+export function refChipLabel(type: string, id: string): string {if (type === 'terminal') {return id || 'terminal'}+ if (type === 'session') {+ return sessionRefFallbackLabel(id)+ }+if (type === 'url') {try {- const parsed = new URL(id)+ const { hostname, pathname, search } = new URL(id)+ const path = `${pathname}${search}`.replace(/\/$/, '')- return parsed.hostname || id+ return `${hostname.replace(/^www\./i, '')}${path}` || id} catch {return id}}- if (type === 'session') {- return sessionRefFallbackLabel(id)- }-const tail = id.split(/[\\/]/).filter(Boolean).pop()return tail || id