@@ -7,13 +7,19 @@ import {
7
7
DEFAULT_CONVERSATION_SEARCH_ACTION_NAME ,
8
8
} from "@app/lib/actions/constants" ;
9
9
import { makeConversationIncludeFileConfiguration } from "@app/lib/actions/conversation/include_file" ;
10
- import type { ConversationAttachmentType } from "@app/lib/actions/conversation/list_files" ;
10
+ import type {
11
+ ConversationAttachmentType ,
12
+ ConversationContentNodeType ,
13
+ } from "@app/lib/actions/conversation/list_files" ;
11
14
import {
12
15
isConversationContentNodeType ,
13
16
isConversationFileType ,
14
17
makeConversationListFilesAction ,
15
18
} from "@app/lib/actions/conversation/list_files" ;
16
- import type { RetrievalConfigurationType } from "@app/lib/actions/retrieval" ;
19
+ import type {
20
+ DataSourceConfiguration ,
21
+ RetrievalConfigurationType ,
22
+ } from "@app/lib/actions/retrieval" ;
17
23
import { getRunnerForActionConfiguration } from "@app/lib/actions/runners" ;
18
24
import type { TablesQueryConfigurationType } from "@app/lib/actions/tables_query" ;
19
25
import type { ActionConfigurationType } from "@app/lib/actions/types/agent" ;
@@ -66,10 +72,8 @@ async function getJITActions(
66
72
filesUsableAsRetrievalQuery . length > 0
67
73
) {
68
74
// Get the datasource view for the conversation.
69
- const dataSourceView = await DataSourceViewResource . fetchByConversation (
70
- auth ,
71
- conversation
72
- ) ;
75
+ const conversationDataSourceView =
76
+ await DataSourceViewResource . fetchByConversation ( auth , conversation ) ;
73
77
74
78
if ( filesUsableAsTableQuery . length > 0 ) {
75
79
const action : TablesQueryConfigurationType = {
@@ -83,12 +87,12 @@ async function getJITActions(
83
87
tables : filesUsableAsTableQuery . flatMap ( ( f ) => {
84
88
if ( isConversationFileType ( f ) ) {
85
89
assert (
86
- dataSourceView ,
90
+ conversationDataSourceView ,
87
91
"No conversation datasource view found for table when trying to get JIT actions"
88
92
) ;
89
93
return f . generatedTables . map ( ( tableId ) => ( {
90
94
workspaceId : auth . getNonNullableWorkspace ( ) . sId ,
91
- dataSourceViewId : dataSourceView . sId ,
95
+ dataSourceViewId : conversationDataSourceView . sId ,
92
96
tableId,
93
97
} ) ) ;
94
98
} else if ( isConversationContentNodeType ( f ) ) {
@@ -104,14 +108,31 @@ async function getJITActions(
104
108
actions . push ( action ) ;
105
109
}
106
110
107
- if (
108
- filesUsableAsRetrievalQuery . filter ( ( f ) => isConversationFileType ( f ) )
109
- . length > 0
110
- ) {
111
- assert (
112
- dataSourceView ,
113
- "No conversation datasource view found for retrieval when trying to get JIT actions"
114
- ) ;
111
+ if ( filesUsableAsRetrievalQuery . length > 0 ) {
112
+ const dataSources : DataSourceConfiguration [ ] =
113
+ filesUsableAsRetrievalQuery
114
+ // For each searchable content node, we add its datasourceview with itself as parent filter.
115
+ . filter ( ( f ) => isConversationContentNodeType ( f ) )
116
+ . map ( ( f ) => ( {
117
+ workspaceId : auth . getNonNullableWorkspace ( ) . sId ,
118
+ // Cast ok here because of the filter above.
119
+ dataSourceViewId : ( f as ConversationContentNodeType )
120
+ . nodeDataSourceViewId ,
121
+ filter : {
122
+ parents : {
123
+ in : [ ( f as ConversationContentNodeType ) . contentNodeId ] ,
124
+ not : [ ] ,
125
+ } ,
126
+ tags : null ,
127
+ } ,
128
+ } ) ) ;
129
+ if ( conversationDataSourceView ) {
130
+ dataSources . push ( {
131
+ workspaceId : auth . getNonNullableWorkspace ( ) . sId ,
132
+ dataSourceViewId : conversationDataSourceView . sId ,
133
+ filter : { parents : null , tags : null } ,
134
+ } ) ;
135
+ }
115
136
const action : RetrievalConfigurationType = {
116
137
description : DEFAULT_CONVERSATION_SEARCH_ACTION_DATA_DESCRIPTION ,
117
138
type : "retrieval_configuration" ,
@@ -121,13 +142,7 @@ async function getJITActions(
121
142
topK : "auto" ,
122
143
query : "auto" ,
123
144
relativeTimeFrame : "auto" ,
124
- dataSources : [
125
- {
126
- workspaceId : conversation . owner . sId ,
127
- dataSourceViewId : dataSourceView . sId ,
128
- filter : { parents : null , tags : null } ,
129
- } ,
130
- ] ,
145
+ dataSources,
131
146
} ;
132
147
actions . push ( action ) ;
133
148
}
0 commit comments