@@ -8,7 +8,10 @@ import {
88 OpenAIMessage ,
99 OpenAIMessageRole ,
1010} from 'src/messages/entities/message.entity' ;
11- import { AgentRequestDto } from 'src/wizard/dto/agent-request.dto' ;
11+ import {
12+ AgentRequestDto ,
13+ WizardAgentRequestDto ,
14+ } from 'src/wizard/dto/agent-request.dto' ;
1215import { ResourcesService } from 'src/resources/resources.service' ;
1316import { Resource } from 'src/resources/resources.entity' ;
1417import { ChatResponse } from 'src/wizard/dto/chat-response.dto' ;
@@ -196,7 +199,7 @@ export class StreamService {
196199 mode : 'ask' | 'write' = 'ask' ,
197200 ) : Promise < Observable < MessageEvent > > {
198201 let parentId : string | undefined = undefined ;
199- let messages : Record < string , any > = [ ] ;
202+ let messages : Record < string , any > [ ] = [ ] ;
200203 let currentCiteCnt : number = 0 ;
201204 if ( body . parent_message_id ) {
202205 parentId = body . parent_message_id ;
@@ -211,43 +214,37 @@ export class StreamService {
211214
212215 if ( body . tools ) {
213216 for ( const tool of body . tools ) {
214- if ( tool . name === 'knowledge_search' ) {
215- // for knowledge_search, pass the resource with permission
216- if (
217- tool . resource_ids === undefined &&
218- tool . parent_ids === undefined
219- ) {
217+ if ( tool . name === 'private_search' ) {
218+ // for private_search, pass the resource with permission
219+ if ( ! tool . resources || tool . resources . length === 0 ) {
220220 const resources : Resource [ ] =
221221 await this . resourcesService . listAllUserAccessibleResources (
222222 tool . namespace_id ,
223223 user . id ,
224224 ) ;
225- tool . resource_ids = resources . map ( ( r ) => r . id ) ;
225+ tool . visible_resource_ids = resources . map ( ( r ) => r . id ) ;
226226 } else {
227- const resourceIds : string [ ] = [ ] ;
228- if ( tool . resource_ids ) {
229- resourceIds . push (
230- ...( await this . resourcesService . permissionFilter < string > (
231- tool . namespace_id ,
232- user . id ,
233- tool . resource_ids ,
234- ) ) ,
235- ) ;
236- }
237- if ( tool . parent_ids ) {
238- for ( const parentId of tool . parent_ids ) {
227+ tool . visible_resource_ids = [ ] ;
228+ tool . visible_resource_ids . push (
229+ ...( await this . resourcesService . permissionFilter < string > (
230+ tool . namespace_id ,
231+ user . id ,
232+ tool . resources . map ( ( r ) => r . id ) ,
233+ ) ) ,
234+ ) ;
235+ for ( const resource of tool . resources ) {
236+ if ( resource . type === 'folder' ) {
239237 const resources : Resource [ ] =
240238 await this . resourcesService . getAllSubResources (
241239 tool . namespace_id ,
242- parentId ,
240+ resource . id ,
243241 user . id ,
244- true ,
242+ false ,
245243 ) ;
246- resourceIds . push ( ...resources . map ( ( res ) => res . id ) ) ;
244+ resource . child_ids = resources . map ( ( r ) => r . id ) ;
245+ tool . visible_resource_ids . push ( ...resource . child_ids ) ;
247246 }
248- tool . parent_ids = undefined ;
249247 }
250- tool . resource_ids = resourceIds ;
251248 }
252249 }
253250 }
@@ -265,20 +262,19 @@ export class StreamService {
265262 user ,
266263 subscriber ,
267264 ) ;
268- this . stream (
269- `/api/v1/wizard/${ mode } ` ,
270- {
271- conversation_id : body . conversation_id ,
272- query : body . query ,
273- messages,
274- tools : body . tools ,
275- enable_thinking : body . enable_thinking ,
276- current_cite_cnt : currentCiteCnt ,
277- } ,
278- async ( data ) => {
279- await handler ( data , handlerContext ) ;
280- } ,
281- )
265+
266+ const wizardRequestBody : WizardAgentRequestDto = {
267+ conversation_id : body . conversation_id ,
268+ query : body . query ,
269+ messages,
270+ tools : body . tools ,
271+ enable_thinking : body . enable_thinking ,
272+ current_cite_cnt : currentCiteCnt ,
273+ } ;
274+
275+ this . stream ( `/api/v1/wizard/${ mode } ` , wizardRequestBody , async ( data ) => {
276+ await handler ( data , handlerContext ) ;
277+ } )
282278 . then ( ( ) => subscriber . complete ( ) )
283279 . catch ( ( err : Error ) => this . streamError ( subscriber , err ) ) ;
284280 } ) ;
0 commit comments