|
7 | 7 |
|
8 | 8 | import { Config } from '../utils/config'; |
9 | 9 | import { logger } from '../utils/log'; |
10 | | -import { updateObjectProperties } from '../utils/resource'; |
| 10 | +import { listAllResourcesFunction, updateObjectProperties } from '../utils/resource'; |
11 | 11 |
|
12 | 12 | import { |
13 | 13 | ToolSetCreateInput, |
@@ -50,6 +50,8 @@ export class ToolSet implements ToolSetData { |
50 | 50 | return new ToolSetClient(); |
51 | 51 | } |
52 | 52 |
|
| 53 | + uniqIdCallback = () => this.name; |
| 54 | + |
53 | 55 | /** |
54 | 56 | * Create a new ToolSet |
55 | 57 | */ |
@@ -77,48 +79,70 @@ export class ToolSet implements ToolSetData { |
77 | 79 | /** |
78 | 80 | * List ToolSets |
79 | 81 | */ |
80 | | - static async list(input?: ToolSetListInput, config?: Config): Promise<ToolSet[]> { |
81 | | - return await ToolSet.getClient().list({ input, config }); |
82 | | - } |
83 | 82 |
|
84 | | - /** |
85 | | - * List all ToolSets with pagination |
86 | | - */ |
87 | | - static async listAll( |
88 | | - options?: { prefix?: string; labels?: Record<string, string> }, |
89 | | - config?: Config |
90 | | - ): Promise<ToolSet[]> { |
91 | | - const toolsets: ToolSet[] = []; |
92 | | - const pageSize = 50; |
93 | | - |
94 | | - // eslint-disable-next-line no-constant-condition |
95 | | - while (true) { |
96 | | - const result = await ToolSet.list( |
97 | | - { |
98 | | - prefix: options?.prefix, |
99 | | - labels: options?.labels, |
100 | | - pageSize, |
101 | | - }, |
102 | | - config |
103 | | - ); |
104 | | - |
105 | | - toolsets.push(...result); |
| 83 | + static list: /** |
| 84 | + * @deprecated |
| 85 | + */ |
| 86 | + | ((input?: ToolSetListInput, config?: Config) => Promise<ToolSet[]>) |
| 87 | + /** |
| 88 | + * 枚举 ToolSet 列表 / List ToolSet list |
| 89 | + */ |
| 90 | + | ((params?: { input?: ToolSetListInput; config?: Config }) => Promise<ToolSet[]>) = async ( |
| 91 | + ...args: any |
| 92 | + ): Promise<ToolSet[]> => { |
| 93 | + let input: ToolSetListInput | undefined; |
| 94 | + let config: Config | undefined; |
| 95 | + |
| 96 | + if (args.length >= 1 && 'input' in args[0]) { |
| 97 | + input = args[0].input; |
| 98 | + } else { |
| 99 | + input = args[0]; |
| 100 | + } |
106 | 101 |
|
107 | | - if (result.length < pageSize) { |
108 | | - break; |
109 | | - } |
| 102 | + if (args.length >= 1 && 'config' in args[0]) { |
| 103 | + config = args[0].config; |
| 104 | + } else if (args.length > 1 && args[1] instanceof Config) { |
| 105 | + config = args[1]; |
110 | 106 | } |
111 | 107 |
|
112 | | - // Deduplicate |
113 | | - const seen = new Set<string>(); |
114 | | - return toolsets.filter(t => { |
115 | | - if (!t.uid || seen.has(t.uid)) { |
116 | | - return false; |
117 | | - } |
118 | | - seen.add(t.uid); |
119 | | - return true; |
| 108 | + return await this.getClient().list({ |
| 109 | + input: { |
| 110 | + ...input, |
| 111 | + } as ToolSetListInput, |
| 112 | + config, |
120 | 113 | }); |
121 | | - } |
| 114 | + }; |
| 115 | + |
| 116 | + static listAll: /** |
| 117 | + * @deprecated |
| 118 | + */ |
| 119 | + | (( |
| 120 | + options?: { prefix?: string; labels?: Record<string, string> }, |
| 121 | + config?: Config |
| 122 | + ) => Promise<ToolSet[]>) |
| 123 | + /** |
| 124 | + * 枚举 ToolSet 列表 / List ToolSet list |
| 125 | + */ |
| 126 | + | ((params?: { input?: ToolSetListInput; config?: Config }) => Promise<ToolSet[]>) = async ( |
| 127 | + ...args: any |
| 128 | + ) => { |
| 129 | + let input: ToolSetListInput | undefined; |
| 130 | + let config: Config | undefined; |
| 131 | + |
| 132 | + if (args.length >= 1 && 'input' in args[0]) { |
| 133 | + input = args[0].input; |
| 134 | + } else { |
| 135 | + input = args[0]; |
| 136 | + } |
| 137 | + |
| 138 | + if (args.length >= 1 && 'config' in args[0]) { |
| 139 | + config = args[0].config; |
| 140 | + } else if (args.length > 1 && args[1] instanceof Config) { |
| 141 | + config = args[1]; |
| 142 | + } |
| 143 | + |
| 144 | + return await listAllResourcesFunction(this.list as any)({ ...input, config }); |
| 145 | + }; |
122 | 146 |
|
123 | 147 | /** |
124 | 148 | * Update a ToolSet by Name |
|
0 commit comments