Skip to content

Commit 8ba721a

Browse files
committed
fix(chat): keep truncated browser tab titles within the title bound
1 parent 126dc10 commit 8ba721a

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎apps/sim/lib/mothership/chat/resource-attachments.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createLogger } from '@sim/logger'
2-
import { truncate } from '@sim/utils/string'
32
import type { z } from 'zod'
43
import {
54
type mothershipResourceAttachmentSchema,
@@ -13,9 +12,9 @@ import { CONTEXT_RESOLUTION_CONCURRENCY } from '@/lib/mothership/chat/context-li
1312
import { resolveFileAttachment } from '@/lib/mothership/chat/file-attachment'
1413
import { resolveActiveResourceContext } from '@/lib/mothership/chat/process-contents'
1514
import {
16-
CHAT_SELECTION_SOURCE_TITLE_MAX_LENGTH,
1715
formatUntrustedJsonBlock,
1816
safeBrowserSelectionUrl,
17+
truncateSelectionTitle,
1918
} from '@/lib/mothership/chat/selection-context'
2019
import type { ChatContextItem } from '@/lib/mothership/generated/protocol'
2120
import { persistChatResources } from '@/lib/mothership/resources/persistence'
@@ -115,7 +114,7 @@ export async function resolveResourceAttachmentContexts(params: {
115114
: 'This attachment supplies only the title and URL; browser tools are unavailable.'
116115
}`,
117116
{
118-
...(title ? { title: truncate(title, CHAT_SELECTION_SOURCE_TITLE_MAX_LENGTH) } : {}),
117+
...(title ? { title: truncateSelectionTitle(title) } : {}),
119118
...(url ? { url } : {}),
120119
}
121120
),

‎apps/sim/lib/mothership/chat/selection-context.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export function truncateSelectionText(text: string): string {
4545
return truncate(text, MAX_FILE_SELECTION_TEXT_LENGTH - TRUNCATE_SUFFIX_LENGTH)
4646
}
4747

48+
/** Truncates a page title so the result, ellipsis included, fits {@link CHAT_SELECTION_SOURCE_TITLE_MAX_LENGTH}. */
49+
export function truncateSelectionTitle(title: string): string {
50+
return truncate(title, CHAT_SELECTION_SOURCE_TITLE_MAX_LENGTH - TRUNCATE_SUFFIX_LENGTH)
51+
}
52+
4853
/**
4954
* Keeps only public web URLs in browser-selection source metadata: http/https
5055
* with no embedded credentials. The URL is advisory context, so anything else

0 commit comments

Comments
 (0)