1+ import type { SelectableMarkdownTextProps } from "../../native/SelectableMarkdownText.types" ;
2+ import { ASSISTANT_CITATION_MAX_TEXT_LENGTH , type AssistantCitation } from "@t3tools/contracts" ;
13import { Button } from "../../components/ui/Button" ;
24import * as Dialog from "../../components/ui/Dialog" ;
35import { useOpenPullRequest } from "../../native/useOpenPullRequest" ;
@@ -373,6 +375,7 @@ export interface ThreadFeedProps {
373375 readonly onEndFollowEnabledChange ?: ( enabled : boolean ) => void ;
374376 readonly skills ?: ReadonlyArray < SelectableMarkdownSkill > ;
375377 readonly onUseArtifactTemplate ?: ( template : CodexArtifactTemplate ) => void ;
378+ readonly onCiteAssistantText ?: ( citation : AssistantCitation ) => void ;
376379}
377380
378381async function waitForThreadShell (
@@ -1179,6 +1182,7 @@ function ArtifactTemplateCard(props: {
11791182
11801183const AssistantMarkdownContent = memo ( function AssistantMarkdownContent ( props : {
11811184 readonly markdown : string ;
1185+ readonly onCiteSelection ?: SelectableMarkdownTextProps [ "onCiteSelection" ] ;
11821186 readonly environmentId : EnvironmentId ;
11831187 readonly markdownStyles : MarkdownStyleSet ;
11841188 readonly linkHandlers : MarkdownLinkHandlers ;
@@ -1197,6 +1201,7 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
11971201 return (
11981202 < AssistantMarkdownBlocks
11991203 markdown = { liveMarkdown }
1204+ onCiteSelection = { props . onCiteSelection }
12001205 markdownStyles = { props . markdownStyles }
12011206 linkHandlers = { linkHandlers }
12021207 onUseArtifactTemplate = { props . onUseArtifactTemplate }
@@ -1209,6 +1214,7 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
12091214// Folds split first, so an artifact card inside a fold stays inside it.
12101215function AssistantMarkdownBlocks ( props : {
12111216 readonly markdown : string ;
1217+ readonly onCiteSelection ?: SelectableMarkdownTextProps [ "onCiteSelection" ] ;
12121218 readonly markdownStyles : MarkdownStyleSet ;
12131219 readonly linkHandlers : MarkdownLinkHandlers ;
12141220 readonly onUseArtifactTemplate ?: ( ( template : CodexArtifactTemplate ) => void ) | undefined ;
@@ -1252,6 +1258,7 @@ function AssistantMarkdownBlocks(props: {
12521258 < SelectableMarkdownText
12531259 key = { `markdown:${ offset } ` }
12541260 markdown = { renderCodexInlineDirectivesAsMarkdown ( segment . markdown ) }
1261+ onCiteSelection = { props . onCiteSelection }
12551262 skills = { props . skills }
12561263 textStyle = { props . markdownStyles . nativeTextStyle }
12571264 { ...props . linkHandlers }
@@ -1656,6 +1663,7 @@ function renderFeedEntry(
16561663 ThreadFeedProps ,
16571664 | "environmentId"
16581665 | "onUseArtifactTemplate"
1666+ | "onCiteAssistantText"
16591667 | "skills"
16601668 | "dispatchingMessageId"
16611669 | "onEditPendingMessage"
@@ -2254,6 +2262,31 @@ function renderFeedEntry(
22542262 < MarkdownImageAvailableWidthContext value = { props . markdownContentWidth } >
22552263 < AssistantMarkdownContent
22562264 markdown = { renderedText }
2265+ onCiteSelection = {
2266+ props . onCiteAssistantText
2267+ ? ( { text, selection } ) => {
2268+ if ( ! text . trim ( ) ) return ;
2269+ if ( text . length > ASSISTANT_CITATION_MAX_TEXT_LENGTH ) {
2270+ Dialog . alert (
2271+ "Select a shorter quote" ,
2272+ `Quotes can contain up to ${ ASSISTANT_CITATION_MAX_TEXT_LENGTH . toLocaleString ( ) } characters.` ,
2273+ ) ;
2274+ return ;
2275+ }
2276+ props . onCiteAssistantText ?.( {
2277+ version : 1 ,
2278+ environmentId : props . environmentId ,
2279+ threadId : props . threadId ,
2280+ messageId : message . id ,
2281+ text,
2282+ start : selection . start ,
2283+ end : Math . max ( selection . end , selection . start + 1 ) ,
2284+ prefix : "" ,
2285+ suffix : "" ,
2286+ } ) ;
2287+ }
2288+ : undefined
2289+ }
22572290 environmentId = { props . environmentId }
22582291 markdownStyles = { styles }
22592292 linkHandlers = { props . markdownLinkHandlers }
@@ -3596,6 +3629,7 @@ export const ThreadFeed = memo(function ThreadFeed({
35963629 dispatchingMessageId : props . dispatchingMessageId ,
35973630 onEditPendingMessage : props . onEditPendingMessage ,
35983631 onUseArtifactTemplate : props . onUseArtifactTemplate ,
3632+ onCiteAssistantText : props . onCiteAssistantText ,
35993633 threadId : props . threadId ,
36003634 copiedRowId,
36013635 expandedWorkRows,
0 commit comments