@@ -18,12 +18,6 @@ import {
1818 type ProjectKnowledgeSource ,
1919 type ThreadId ,
2020} from "@t3tools/contracts" ;
21- import {
22- addProjectMemorySuggestion ,
23- boundProjectMemorySuggestionQuery ,
24- isSubstantiveProjectMemoryQuery ,
25- selectProjectMemorySuggestions ,
26- } from "@t3tools/client-runtime/projectKnowledge" ;
2721import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime" ;
2822
2923import {
@@ -70,7 +64,6 @@ type Scope = {
7064 readonly projectId : ProjectId ;
7165 readonly draftKey : string ;
7266 readonly disabled : boolean ;
73- readonly suggest ?: boolean ;
7467} ;
7568type MessageCitation = { readonly threadId : ThreadId ; readonly messageId : MessageId } ;
7669// The digest is optional so a feed message can be cited before the server has
@@ -115,11 +108,7 @@ export function useOpenProjectMemory(
115108export function ProjectKnowledgeEntry ( props : Scope ) {
116109 const isFocused = useIsFocused ( ) ;
117110 const config = useAtomValue ( serverEnvironment . configValueAtom ( props . environmentId ) ) ;
118- const [ open , setOpen ] = useState < {
119- readonly seed : MessageCitation | null ;
120- readonly fact ?: ProjectFact ;
121- readonly source ?: KnowledgeMessageRef ;
122- } | null > ( null ) ;
111+ const [ open , setOpen ] = useState < { readonly seed : MessageCitation | null } | null > ( null ) ;
123112 const { environmentId, projectId, draftKey } = props ;
124113 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- registers this entry with the header and feed open requests while mounted
125114 useEffect ( ( ) => {
@@ -138,40 +127,24 @@ export function ProjectKnowledgeEntry(props: Scope) {
138127 } ;
139128 } , [ environmentId , projectId , draftKey , isFocused ] ) ;
140129 if ( config ?. environment . capabilities . projectKnowledge !== true || ! isFocused ) return null ;
141- return (
142- < >
143- { props . suggest && config . environment . capabilities . projectKnowledgePreview === true ? (
144- < ProjectMemorySuggestions
145- key = { `${ props . environmentId } :${ props . projectId } :${ props . draftKey } ` }
146- { ...props }
147- onUse = { ( fact ) => setOpen ( { seed : null , fact } ) }
148- onSource = { ( source ) => setOpen ( { seed : null , source } ) }
149- />
150- ) : null }
151- { open ? (
152- < ProjectKnowledgeSheet
153- key = { `${ props . environmentId } :${ props . projectId } :${ props . draftKey } :${ open . seed ?. messageId ?? open . source ?. messageId ?? open . fact ?. id ?? "" } ` }
154- { ...props }
155- // Older servers lack readFact, status and supersede.
156- history = { config . environment . capabilities . projectKnowledgeHistory === true }
157- assisted = { config . environment . capabilities . projectKnowledgeAssistedLearning === true }
158- seedMessage = { open . seed }
159- suggestedFact = { open . fact }
160- suggestedSource = { open . source }
161- onClose = { ( ) => setOpen ( null ) }
162- />
163- ) : null }
164- </ >
165- ) ;
130+ return open ? (
131+ < ProjectKnowledgeSheet
132+ key = { `${ props . environmentId } :${ props . projectId } :${ props . draftKey } :${ open . seed ?. messageId ?? "" } ` }
133+ { ...props }
134+ // Older servers lack readFact, status and supersede.
135+ history = { config . environment . capabilities . projectKnowledgeHistory === true }
136+ assisted = { config . environment . capabilities . projectKnowledgeAssistedLearning === true }
137+ seedMessage = { open . seed }
138+ onClose = { ( ) => setOpen ( null ) }
139+ />
140+ ) : null ;
166141}
167142
168143function ProjectKnowledgeSheet (
169144 props : Scope & {
170145 readonly history : boolean ;
171146 readonly assisted : boolean ;
172147 readonly seedMessage : MessageCitation | null ;
173- readonly suggestedFact ?: ProjectFact ;
174- readonly suggestedSource ?: KnowledgeMessageRef ;
175148 readonly onClose : ( ) => void ;
176149 } ,
177150) {
@@ -184,23 +157,14 @@ function ProjectKnowledgeSheet(
184157 const attachedInScope =
185158 attached && projectKnowledgeRecordInScope ( attached , scope ) ? attached : undefined ;
186159 const [ selections , setSelections ] = useState < ReadonlyArray < KnowledgeSelection > > (
187- props . suggestedFact
188- ? addProjectMemorySuggestion ( attachedInScope ?. knowledge . selections ?? [ ] , props . suggestedFact )
189- : ( attachedInScope ?. knowledge . selections ?? [ ] ) ,
160+ attachedInScope ?. knowledge . selections ?? [ ] ,
190161 ) ;
191162 // Set when a selection change removed the reference this sheet opened with.
192163 const [ detached , setDetached ] = useState ( false ) ;
193164 const [ stack , setStack ] = useState < ReadonlyArray < Page > > (
194- props . suggestedFact
195- ? [
196- { kind : "list" } ,
197- { kind : "fact" , factId : props . suggestedFact . id , snapshot : props . suggestedFact } ,
198- ]
199- : props . suggestedSource
200- ? [ { kind : "list" } , { kind : "source" , ref : props . suggestedSource } ]
201- : props . seedMessage
202- ? [ { kind : "list" } , { kind : "remember" , ref : props . seedMessage } ]
203- : [ { kind : "list" } ] ,
165+ props . seedMessage
166+ ? [ { kind : "list" } , { kind : "remember" , ref : props . seedMessage } ]
167+ : [ { kind : "list" } ] ,
204168 ) ;
205169 const page = stack . at ( - 1 ) ! ;
206170 const [ hints , setHints ] = useState < {
@@ -669,95 +633,3 @@ function RememberEditor(props: {
669633 />
670634 ) ;
671635}
672-
673- function ProjectMemorySuggestions (
674- props : Scope & {
675- readonly onUse : ( fact : ProjectFact ) => void ;
676- readonly onSource : ( source : KnowledgeMessageRef ) => void ;
677- } ,
678- ) {
679- const canUse = useAtomValue ( projectKnowledge . prepareContext . permissionAtom ( props . environmentId ) ) ;
680- const draft = useComposerDraft ( props . draftKey ) ;
681- const [ request , setRequest ] = useState < { query : string ; requestId : CommandId } | null > ( null ) ;
682- const [ dismissed , setDismissed ] = useState < ReadonlyArray < string > > ( [ ] ) ;
683- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- issues one recall request after the user pauses composing a substantive draft
684- useEffect ( ( ) => {
685- if ( request || ! isSubstantiveProjectMemoryQuery ( draft . text ) ) return ;
686- const timer = setTimeout (
687- ( ) =>
688- setRequest ( {
689- query : boundProjectMemorySuggestionQuery ( draft . text ) ,
690- requestId : CommandId . make ( uuidv4 ( ) ) ,
691- } ) ,
692- 1000 ,
693- ) ;
694- return ( ) => clearTimeout ( timer ) ;
695- } , [ draft . text , request ] ) ;
696- const result = useEnvironmentQuery (
697- request
698- ? projectKnowledge . search ( {
699- environmentId : props . environmentId ,
700- input : {
701- ...request ,
702- projectId : props . projectId ,
703- recordRetrieval : false ,
704- preview : true ,
705- minTrust : 0.5 ,
706- limit : 8 ,
707- messageLimit : 1 ,
708- } ,
709- } )
710- : null ,
711- ) ;
712- const suggestions = result . data
713- ? selectProjectMemorySuggestions ( result . data , request ?. query ) . filter (
714- ( { fact } ) => ! dismissed . includes ( fact . id ) ,
715- )
716- : [ ] ;
717- if ( ! request || ! draft . text . trimStart ( ) . startsWith ( request . query ) || ! suggestions . length )
718- return null ;
719- return (
720- < View accessibilityLabel = "Related project memory" className = "gap-1" >
721- { suggestions . map ( ( { fact, reason } ) => (
722- < View key = { fact . id } className = "gap-1" >
723- < AppText numberOfLines = { 2 } > Project memory: { fact . content } </ AppText >
724- < AppText > { reason } </ AppText >
725- < View className = "flex-row gap-1" >
726- { fact . sources . some ( ( source ) => source . kind === "user" ) ? (
727- < AppText > Saved by you</ AppText >
728- ) : null }
729- { fact . sources
730- . filter ( ( source ) => source . kind === "message" )
731- . slice ( 0 , 1 )
732- . flatMap ( ( source ) =>
733- source . kind === "message"
734- ? [
735- < Button
736- key = { source . messageId }
737- label = "Source"
738- size = "compact"
739- tone = "text"
740- onPress = { ( ) => props . onSource ( source ) }
741- /> ,
742- ]
743- : [ ] ,
744- ) }
745- < Button
746- label = "Use"
747- size = "compact"
748- tone = "text"
749- disabled = { props . disabled || ! canUse }
750- onPress = { ( ) => props . onUse ( fact ) }
751- />
752- < Button
753- label = "Dismiss"
754- size = "compact"
755- tone = "text"
756- onPress = { ( ) => setDismissed ( [ ...dismissed , fact . id ] ) }
757- />
758- </ View >
759- </ View >
760- ) ) }
761- </ View >
762- ) ;
763- }
0 commit comments