@@ -2,10 +2,12 @@ import * as Haptics from "expo-haptics";
22import { KeyboardAwareLegendList } from "@legendapp/list/keyboard" ;
33import { type LegendListRef } from "@legendapp/list/react-native" ;
44import type { EnvironmentId , MessageId , ThreadId , TurnId } from "@t3tools/contracts" ;
5+ import type { CodexArtifactTemplate } from "@t3tools/client-runtime/codex-artifact-templates" ;
56import { classifyMarkdownImageSource } from "@t3tools/client-runtime/markdown-images" ;
7+ import { splitCodexArtifactTemplateMarkdown } from "@t3tools/client-runtime/codex-markdown-directives" ;
68import { CHAT_LIST_ANCHOR_OFFSET , resolveChatListAnchoredEndSpace } from "@t3tools/shared/chatList" ;
79import { formatElapsed } from "@t3tools/shared/orchestrationTiming" ;
8- import { SymbolView } from "../../components/AppSymbol" ;
10+ import { SymbolView , type AppSymbolName } from "../../components/AppSymbol" ;
911import { HeaderHeightContext } from "@react-navigation/elements" ;
1012import { useNavigation } from "@react-navigation/native" ;
1113import {
@@ -173,6 +175,7 @@ export interface ThreadFeedProps {
173175 readonly onHeaderMaterialVisibilityChange ?: ( visible : boolean ) => void ;
174176 readonly onEndFollowEnabledChange ?: ( enabled : boolean ) => void ;
175177 readonly skills ?: ReadonlyArray < SelectableMarkdownSkill > ;
178+ readonly onUseArtifactTemplate ?: ( template : CodexArtifactTemplate ) => void ;
176179 /** Non-null when older turns exist beyond the loaded window. */
177180 readonly loadEarlier ?: {
178181 readonly loading : boolean ;
@@ -435,6 +438,128 @@ const MarkdownExternalLink = memo(function MarkdownExternalLink(props: {
435438 ) ;
436439} ) ;
437440
441+ const ARTIFACT_TEMPLATE_LABEL_BY_KIND : Record < CodexArtifactTemplate [ "artifactKind" ] , string > = {
442+ document : "Document template" ,
443+ presentation : "Presentation template" ,
444+ spreadsheet : "Spreadsheet template" ,
445+ site : "Site template" ,
446+ "google-docs" : "Google Doc template" ,
447+ "google-slides" : "Google Slides template" ,
448+ "google-sheets" : "Google Sheet template" ,
449+ image : "Image template" ,
450+ email : "Email template" ,
451+ slack : "Slack template" ,
452+ } ;
453+
454+ const ARTIFACT_TEMPLATE_SYMBOL_BY_KIND : Record <
455+ CodexArtifactTemplate [ "artifactKind" ] ,
456+ AppSymbolName
457+ > = {
458+ document : "doc.text" ,
459+ presentation : "chart.bar.xaxis" ,
460+ spreadsheet : "chart.bar.xaxis" ,
461+ site : "safari" ,
462+ "google-docs" : "doc.text" ,
463+ "google-slides" : "chart.bar.xaxis" ,
464+ "google-sheets" : "chart.bar.xaxis" ,
465+ image : "camera" ,
466+ email : "text.bubble" ,
467+ slack : "text.bubble" ,
468+ } ;
469+
470+ function ArtifactTemplateCard ( props : {
471+ readonly template : CodexArtifactTemplate ;
472+ readonly onUse ?: ( ( template : CodexArtifactTemplate ) => void ) | undefined ;
473+ } ) {
474+ return (
475+ < View
476+ className = "my-2 min-w-0 flex-row items-center gap-3 rounded-2xl border border-border bg-card px-3 py-3"
477+ >
478+ < View className = "relative h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-border bg-subtle" >
479+ < SymbolView
480+ name = { ARTIFACT_TEMPLATE_SYMBOL_BY_KIND [ props . template . artifactKind ] }
481+ size = { 20 }
482+ tintColorClassName = "accent-foreground-muted"
483+ type = "monochrome"
484+ />
485+ < View className = "absolute -right-1 -bottom-1 h-4 w-4 items-center justify-center rounded-full bg-fuchsia-500" >
486+ < SymbolView
487+ name = { { ios : "sparkles" , android : "auto_awesome" } }
488+ size = { 9 }
489+ tintColor = "white"
490+ type = "monochrome"
491+ />
492+ </ View >
493+ </ View >
494+ < View className = "min-w-0 flex-1" >
495+ < Text className = "font-t3-bold text-sm text-foreground" numberOfLines = { 1 } >
496+ { props . template . displayName }
497+ </ Text >
498+ < Text className = "text-xs text-foreground-muted" >
499+ { ARTIFACT_TEMPLATE_LABEL_BY_KIND [ props . template . artifactKind ] }
500+ </ Text >
501+ </ View >
502+ { props . onUse ? (
503+ < Pressable
504+ accessibilityRole = "button"
505+ accessibilityLabel = { `Use ${ props . template . displayName } template` }
506+ className = "min-h-9 justify-center rounded-lg border border-border bg-subtle px-3 active:opacity-65"
507+ onPress = { ( ) => props . onUse ?.( props . template ) }
508+ >
509+ < Text className = "font-t3-bold text-xs text-foreground" > Use template</ Text >
510+ </ Pressable >
511+ ) : null }
512+ </ View >
513+ ) ;
514+ }
515+
516+ const AssistantMarkdownContent = memo ( function AssistantMarkdownContent ( props : {
517+ readonly markdown : string ;
518+ readonly markdownStyles : MarkdownStyleSet ;
519+ readonly onLinkPress : ( href : string ) => void ;
520+ readonly onUseArtifactTemplate ?: ( ( template : CodexArtifactTemplate ) => void ) | undefined ;
521+ readonly renderImage : MarkdownImageRenderer ;
522+ readonly skills ?: ReadonlyArray < SelectableMarkdownSkill > | undefined ;
523+ } ) {
524+ const segments = useMemo (
525+ ( ) => splitCodexArtifactTemplateMarkdown ( props . markdown ) ,
526+ [ props . markdown ] ,
527+ ) ;
528+
529+ return segments . map ( ( segment ) =>
530+ segment . kind === "artifact-template" ? (
531+ < ArtifactTemplateCard
532+ key = { `artifact-template:${ segment . sourceOffset } ` }
533+ template = { segment . template }
534+ onUse = { props . onUseArtifactTemplate }
535+ />
536+ ) : segment . markdown . trim ( ) . length > 0 ? (
537+ hasNativeSelectableMarkdownText ( ) ? (
538+ < SelectableMarkdownText
539+ key = { `markdown:${ segment . sourceOffset } ` }
540+ markdown = { segment . markdown }
541+ plugins = { CODEX_FILE_CITATION_MARKDOWN_PLUGINS }
542+ skills = { props . skills }
543+ textStyle = { props . markdownStyles . nativeTextStyle }
544+ onLinkPress = { props . onLinkPress }
545+ renderImage = { props . renderImage }
546+ />
547+ ) : (
548+ < Markdown
549+ key = { `markdown:${ segment . sourceOffset } ` }
550+ options = { { gfm : true } }
551+ plugins = { CODEX_FILE_CITATION_MARKDOWN_PLUGINS }
552+ renderers = { props . markdownStyles . renderers }
553+ styles = { props . markdownStyles . styles }
554+ theme = { props . markdownStyles . theme }
555+ >
556+ { segment . markdown }
557+ </ Markdown >
558+ )
559+ ) : null ,
560+ ) ;
561+ } ) ;
562+
438563function MarkdownCodeBlock ( props : {
439564 readonly backgroundColor : string ;
440565 readonly borderColor : string ;
@@ -966,7 +1091,7 @@ function useMarkdownStyles(
9661091
9671092function renderFeedEntry (
9681093 info : { item : ThreadFeedEntry ; index : number } ,
969- props : Pick < ThreadFeedProps , "environmentId" | "skills" > & {
1094+ props : Pick < ThreadFeedProps , "environmentId" | "onUseArtifactTemplate" | " skills"> & {
9701095 readonly copiedRowId : string | null ;
9711096 readonly expandedWorkRows : Record < string , boolean > ;
9721097 readonly terminalAssistantMessageIds : ReadonlySet < string > ;
@@ -1128,26 +1253,14 @@ function renderFeedEntry(
11281253 { ...( enterAnimated ? { entering : FadeIn . duration ( 220 ) } : { } ) }
11291254 >
11301255 { renderedText . trim ( ) . length > 0 ? (
1131- hasNativeSelectableMarkdownText ( ) ? (
1132- < SelectableMarkdownText
1133- markdown = { renderedText }
1134- plugins = { CODEX_FILE_CITATION_MARKDOWN_PLUGINS }
1135- skills = { props . skills }
1136- textStyle = { styles . nativeTextStyle }
1137- onLinkPress = { props . onMarkdownLinkPress }
1138- renderImage = { props . renderMarkdownImage }
1139- />
1140- ) : (
1141- < Markdown
1142- options = { { gfm : true } }
1143- plugins = { CODEX_FILE_CITATION_MARKDOWN_PLUGINS }
1144- renderers = { styles . renderers }
1145- styles = { styles . styles }
1146- theme = { styles . theme }
1147- >
1148- { renderedText }
1149- </ Markdown >
1150- )
1256+ < AssistantMarkdownContent
1257+ markdown = { renderedText }
1258+ markdownStyles = { styles }
1259+ onLinkPress = { props . onMarkdownLinkPress }
1260+ onUseArtifactTemplate = { props . onUseArtifactTemplate }
1261+ renderImage = { props . renderMarkdownImage }
1262+ skills = { props . skills }
1263+ />
11511264 ) : null }
11521265 { attachments . map ( ( attachment ) => {
11531266 return (
@@ -2034,6 +2147,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
20342147 reviewCommentBubbleWidth,
20352148 userBubbleMaxWidth,
20362149 skills : props . skills ,
2150+ onUseArtifactTemplate : props . onUseArtifactTemplate ,
20372151 } ) ,
20382152 [
20392153 copiedRowId ,
@@ -2053,6 +2167,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
20532167 onToggleWorkGroup ,
20542168 onToggleWorkRow ,
20552169 props . environmentId ,
2170+ props . onUseArtifactTemplate ,
20562171 props . skills ,
20572172 renderMarkdownImage ,
20582173 ] ,
0 commit comments