File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
src/components/tools/tool-usage Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { type LoaderContextType } from '@seedcompany/data-loader' ;
1
2
import { type ID , type Resource } from '~/common' ;
2
3
import {
3
4
type DataLoaderStrategy ,
4
5
LoaderFactory ,
5
6
type LoaderOptionsOf ,
6
7
} from '~/core/data-loader' ;
8
+ import { ToolLoader } from '../tool/tool.loader' ;
7
9
import { type ToolUsage } from './dto' ;
10
+ import { ToolUsageLoader } from './tool-usage.loader' ;
8
11
import { ToolUsageService } from './tool-usage.service' ;
9
12
10
13
export interface UsagesByContainer {
@@ -27,7 +30,17 @@ export class ToolUsageByContainerLoader
27
30
28
31
async loadMany (
29
32
ids : readonly Resource [ ] ,
33
+ ctx : LoaderContextType ,
30
34
) : Promise < readonly UsagesByContainer [ ] > {
31
- return await this . usages . readManyForContainers ( ids ) ;
35
+ const res = await this . usages . readManyForContainers ( ids ) ;
36
+
37
+ const canonicalUsages = await ctx . getLoader ( ToolUsageLoader ) ;
38
+ const usages = res . flatMap ( ( u ) => u . usages ) ;
39
+ canonicalUsages . primeAll ( usages ) ;
40
+
41
+ const canonicalTools = await ctx . getLoader ( ToolLoader ) ;
42
+ canonicalTools . primeAll ( usages . map ( ( x ) => x . tool ) ) ;
43
+
44
+ return res ;
32
45
}
33
46
}
Original file line number Diff line number Diff line change
1
+ import type { LoaderContextType } from '@seedcompany/data-loader' ;
1
2
import { type ID } from '~/common' ;
2
3
import {
3
4
type DataLoaderStrategy ,
6
7
} from '~/core/data-loader' ;
7
8
import { type Tool } from '../tool/dto' ;
8
9
import { type ToolUsage } from './dto' ;
10
+ import { ToolUsageLoader } from './tool-usage.loader' ;
9
11
import { ToolUsageService } from './tool-usage.service' ;
10
12
11
13
export interface UsagesByTool {
@@ -26,7 +28,16 @@ export class ToolUsageByToolLoader
26
28
} satisfies LoaderOptionsOf < ToolUsageByToolLoader > ;
27
29
}
28
30
29
- async loadMany ( tools : readonly Tool [ ] ) : Promise < readonly UsagesByTool [ ] > {
30
- return await this . usages . readManyForTools ( tools ) ;
31
+ async loadMany (
32
+ tools : readonly Tool [ ] ,
33
+ ctx : LoaderContextType ,
34
+ ) : Promise < readonly UsagesByTool [ ] > {
35
+ const res = await this . usages . readManyForTools ( tools ) ;
36
+
37
+ const canonicalUsages = await ctx . getLoader ( ToolUsageLoader ) ;
38
+ const usages = res . flatMap ( ( u ) => u . usages ) ;
39
+ canonicalUsages . primeAll ( usages ) ;
40
+
41
+ return res ;
31
42
}
32
43
}
You can’t perform that action at this time.
0 commit comments