File tree Expand file tree Collapse file tree
apps/sim/lib/mothership/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { createLogger } from '@sim/logger'
2- import { truncate } from '@sim/utils/string'
32import type { z } from 'zod'
43import {
54 type mothershipResourceAttachmentSchema ,
@@ -13,9 +12,9 @@ import { CONTEXT_RESOLUTION_CONCURRENCY } from '@/lib/mothership/chat/context-li
1312import { resolveFileAttachment } from '@/lib/mothership/chat/file-attachment'
1413import { resolveActiveResourceContext } from '@/lib/mothership/chat/process-contents'
1514import {
16- CHAT_SELECTION_SOURCE_TITLE_MAX_LENGTH ,
1715 formatUntrustedJsonBlock ,
1816 safeBrowserSelectionUrl ,
17+ truncateSelectionTitle ,
1918} from '@/lib/mothership/chat/selection-context'
2019import type { ChatContextItem } from '@/lib/mothership/generated/protocol'
2120import { 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 ) ,
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments