Skip to content

Commit e22a6f1

Browse files
authored
feat!: make tool.when accept a context object (#125)
1 parent 33e4e20 commit e22a6f1

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async function getTools(
183183
// Filter extraTools based on templateName
184184
const filteredExtraTools = extraTools?.filter((tool) => {
185185
const when = tool.when ?? (() => true);
186-
return templateName ? when(templateName) : true;
186+
return templateName ? when({ templateName }) : true;
187187
});
188188

189189
if (parsedTools !== null) {
@@ -367,7 +367,7 @@ type ExtraTool = {
367367
* If returns false, the tool will not be shown in the selection.
368368
* @default () => true
369369
*/
370-
when?: (templateName: string) => boolean;
370+
when?: (context: { templateName: string }) => boolean;
371371
};
372372

373373
type ExtraSkill = {

test/custom-tools.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ test('should filter extra tools based on template name', async () => {
237237
value: 'filtered-tool',
238238
label: 'Filtered Tool',
239239
// This tool should be filtered out for 'vanilla' template
240-
when: (templateName) => templateName !== 'vanilla',
240+
when: ({ templateName }) => templateName !== 'vanilla',
241241
action: () => {
242242
filteredToolCalled = true;
243243
},
@@ -246,7 +246,7 @@ test('should filter extra tools based on template name', async () => {
246246
value: 'allowed-tool',
247247
label: 'Allowed Tool',
248248
// This tool should be allowed for 'vanilla' template
249-
when: (templateName) => templateName === 'vanilla',
249+
when: ({ templateName }) => templateName === 'vanilla',
250250
action: () => {
251251
allowedToolCalled = true;
252252
},

0 commit comments

Comments
 (0)