|
1 | 1 | import { Button } from "../../components/ui/Button"; |
2 | 2 | import * as Dialog from "../../components/ui/Dialog"; |
| 3 | +import { ASSISTANT_CITATION_MAX_TEXT_LENGTH, type AssistantCitation } from "@t3tools/contracts"; |
3 | 4 | import { useOpenPullRequest } from "../../native/useOpenPullRequest"; |
4 | 5 | import { useWorkspaceSettledContentWidth } from "../layout/workspace-content-width"; |
5 | 6 | import { ThreadMarkdownVideo, ThreadMediaVisibleContext } from "./ThreadMarkdownVideo"; |
@@ -54,7 +55,6 @@ import { |
54 | 55 | type ScheduledTaskId, |
55 | 56 | type ScopedThreadRef, |
56 | 57 | } from "@t3tools/contracts"; |
57 | | -import { renderAssistantCitationsAsText } from "@t3tools/shared/assistantCitations"; |
58 | 58 | import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard"; |
59 | 59 | import { parseThreadLinkHref } from "@t3tools/shared/threadLinks"; |
60 | 60 | import { PROMPT_LINK_MAX_PROMPT_LENGTH } from "@t3tools/shared/promptLinks"; |
@@ -365,6 +365,7 @@ export interface ThreadFeedProps { |
365 | 365 | readonly onEndFollowEnabledChange?: (enabled: boolean) => void; |
366 | 366 | readonly skills?: ReadonlyArray<SelectableMarkdownSkill>; |
367 | 367 | readonly onUseArtifactTemplate?: (template: CodexArtifactTemplate) => void; |
| 368 | + readonly onCiteAssistantText?: (citation: AssistantCitation) => void; |
368 | 369 | } |
369 | 370 |
|
370 | 371 | async function waitForThreadShell( |
@@ -900,6 +901,8 @@ function ArtifactTemplateCard(props: { |
900 | 901 | const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: { |
901 | 902 | readonly markdown: string; |
902 | 903 | readonly environmentId: EnvironmentId; |
| 904 | + readonly citationSource?: Pick<AssistantCitation, "threadId" | "messageId">; |
| 905 | + readonly onCiteAssistantText?: (citation: AssistantCitation) => void; |
903 | 906 | readonly markdownStyles: MarkdownStyleSet; |
904 | 907 | readonly linkHandlers: MarkdownLinkHandlers; |
905 | 908 | readonly onUseArtifactTemplate?: ((template: CodexArtifactTemplate) => void) | undefined; |
@@ -934,6 +937,32 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: { |
934 | 937 | markdown={markdown} |
935 | 938 | skills={props.skills} |
936 | 939 | textStyle={props.markdownStyles.nativeTextStyle} |
| 940 | + onCiteText={ |
| 941 | + props.onCiteAssistantText && props.citationSource |
| 942 | + ? (text) => { |
| 943 | + if (!text.trim()) return; |
| 944 | + if (text.length > ASSISTANT_CITATION_MAX_TEXT_LENGTH) { |
| 945 | + Dialog.alert( |
| 946 | + "Quote is too long", |
| 947 | + `Select up to ${ASSISTANT_CITATION_MAX_TEXT_LENGTH.toLocaleString()} characters to cite.`, |
| 948 | + ); |
| 949 | + return; |
| 950 | + } |
| 951 | + // Native offsets are local to Markdown blocks; navigation resolves the quote in its message. |
| 952 | + if (!props.citationSource) return; |
| 953 | + props.onCiteAssistantText?.({ |
| 954 | + version: 1, |
| 955 | + environmentId: props.environmentId, |
| 956 | + ...props.citationSource, |
| 957 | + text, |
| 958 | + start: 0, |
| 959 | + end: text.replace(/\s+/g, " ").length, |
| 960 | + prefix: "", |
| 961 | + suffix: "", |
| 962 | + }); |
| 963 | + } |
| 964 | + : undefined |
| 965 | + } |
937 | 966 | {...linkHandlers} |
938 | 967 | renderImage={props.renderImage} |
939 | 968 | /> |
@@ -1161,7 +1190,7 @@ function ThreadAutomationMessageRow(props: { |
1161 | 1190 | <View className="px-3.5 pb-2.5"> |
1162 | 1191 | <MarkdownImageAvailableWidthContext value={props.contentMaxWidth}> |
1163 | 1192 | <UserMessageContent |
1164 | | - text={renderAssistantCitationsAsText(props.text)} |
| 1193 | + text={props.text} |
1165 | 1194 | environmentId={props.environmentId} |
1166 | 1195 | context={props.context} |
1167 | 1196 | markdownStyles={props.markdownStyles} |
@@ -1300,6 +1329,7 @@ function renderFeedEntry( |
1300 | 1329 | ThreadFeedProps, |
1301 | 1330 | | "environmentId" |
1302 | 1331 | | "onUseArtifactTemplate" |
| 1332 | + | "onCiteAssistantText" |
1303 | 1333 | | "skills" |
1304 | 1334 | | "dispatchingMessageId" |
1305 | 1335 | | "onEditPendingMessage" |
@@ -1509,7 +1539,7 @@ function renderFeedEntry( |
1509 | 1539 | const { message } = entry; |
1510 | 1540 | const isUser = message.role === "user"; |
1511 | 1541 | const presentation = resolveUserMessagePresentation(message); |
1512 | | - const renderedText = renderAssistantCitationsAsText(presentation.text); |
| 1542 | + const renderedText = presentation.text; |
1513 | 1543 | const styles = isUser ? markdownStyles.user : markdownStyles.assistant; |
1514 | 1544 | const timestampLabel = formatMessageTime(isUser ? message.createdAt : message.updatedAt); |
1515 | 1545 | const attachments = message.attachments ?? []; |
@@ -1820,6 +1850,8 @@ function renderFeedEntry( |
1820 | 1850 | <AssistantMarkdownContent |
1821 | 1851 | markdown={renderedText} |
1822 | 1852 | environmentId={props.environmentId} |
| 1853 | + citationSource={{ threadId: props.threadId, messageId: message.id }} |
| 1854 | + onCiteAssistantText={props.onCiteAssistantText} |
1823 | 1855 | markdownStyles={styles} |
1824 | 1856 | linkHandlers={props.markdownLinkHandlers} |
1825 | 1857 | onUseArtifactTemplate={props.onUseArtifactTemplate} |
@@ -2694,6 +2726,7 @@ export const ThreadFeed = memo(function ThreadFeed({ |
2694 | 2726 | // Include turn completion so unchanged message rows reveal their footer and spacing |
2695 | 2727 | // even when the final message update arrives before the turn settles. |
2696 | 2728 | const listAppearanceData = { |
| 2729 | + onCiteAssistantText: props.onCiteAssistantText, |
2697 | 2730 | worktreeSetup: props.worktreeSetup, |
2698 | 2731 | setupWorkingStartedAt: props.setupWorkingStartedAt, |
2699 | 2732 | dispatchingMessageId: props.dispatchingMessageId, |
@@ -3143,6 +3176,7 @@ export const ThreadFeed = memo(function ThreadFeed({ |
3143 | 3176 | dispatchingMessageId: props.dispatchingMessageId, |
3144 | 3177 | onEditPendingMessage: props.onEditPendingMessage, |
3145 | 3178 | onUseArtifactTemplate: props.onUseArtifactTemplate, |
| 3179 | + onCiteAssistantText: props.onCiteAssistantText, |
3146 | 3180 | threadId: props.threadId, |
3147 | 3181 | copiedRowId, |
3148 | 3182 | expandedWorkRows, |
|
0 commit comments