@devries-cameron20 / composio Mirror · read-only / commits / b2b9d3817
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

fix(core): match the triggers toolkit filter for underscore toolkit slugs (#4948)

## Summary `triggers.subscribe(fn, { toolkits: ['one_drive'] })` never calls `fn`. Realtime trigger payloads don't carry a toolkit slug, so `Triggers` derives one from the first `_` segment of the trigger slug: `ONE_DRIVE_FILE_CREATED_TRIGGER` becomes `ONE`. The `toolkits` filter then compares `one_drive` against `one` and drops the event. This hits every toolkit whose slug has an underscore and that ships triggers. In the toolkit data under `docs/public/data/toolkits.json` that is `one_drive` (9 triggers), `launch_darkly` (16) and `agent_mail` (1), so 26 of the 671 listed triggers. Every listed trigger slug starts with `<TOOLKIT>_`, which is what the fix relies on. Fixes #4947 Designated PR reviewer: @jkomyno ## Changes - `shouldSendTriggerAfterFilters`: a `toolkits` entry matches when it equals the derived `toolkitSlug` (unchanged) or when the trigger slug starts with `<toolkit>_`, case-insensitively. - Three tests in `test/models/triggers.test.ts`: `one_drive` matches a OneDrive V3 payload, `ONE_DRIVE` matches it too, and `one_drive` does not match a slug that only shares the prefix (`ONE_DRIVEX_...`). - Patch changeset for `@composio/core`. The derived `toolkitSlug` on the payload handed to the callback is still `ONE`. Fixing that needs the toolkit slug from the backend (it isn't in the V3 metadata), so I left it alone and only fixed the filter. The Python SDK has the same derivation (`_build_trigger_event_from_v3`) and its `toolkit` filter in `_filters_match` drops these events the same way. I kept this PR to TypeScript and can send the Python side as a follow-up if you want both. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? - With the new tests and without the fix: 2 failed, 61 passed in `test/models/triggers.test.ts` (`expected "vi.fn()" to be called 1 times, but got 0 times` for the two `one_drive` cases). - With the fix: 63 passed in `test/models/triggers.test.ts`. - `pnpm --filter @composio/core test`: 1912 passed, 2 expected fail. `test/providers/refContract.test.ts` fails to load in my checkout with and without this change because it scans `ts/packages/providers`, which I didn't have checked out. - `pnpm --filter @composio/core typecheck`: clean. - `oxlint` on the two touched files: no new warnings (the existing unused `ok` in `parseWebhookPayload` is unchanged). `prettier --check`: clean. - `node ts/scripts/validate-changesets.mjs`: passed. Node 24.19.0, pnpm 11.8.0. ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I have read and understand every line of this diff, including any LLM-generated code - [x] Any third-party docs links or promotional content follow the third-party links policy - [x] I ran linters/tests locally and they passed - [ ] I updated documentation as needed - [x] I added tests or explain why not applicable - [x] I added a changeset if this change affects published packages ## Additional context No docs change: the filter takes toolkit slugs, and this makes the three affected slugs behave like every other one.

Abhishek B R committed Nov 13, 2026 at 19:11 UTC b2b9d38170d6025cd14d829aa13192dcd8bb70e8
3 files changed +53 -2
.changeset/trigger-toolkit-filter-underscore.md new
+7
@@ -0,0 +1,7 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Match the `toolkits` filter of `triggers.subscribe()` for toolkits whose slug contains an underscore
6 +
7 +The toolkit of an incoming event is derived from the first `_` segment of its trigger slug, so `ONE_DRIVE_FILE_CREATED_TRIGGER` was attributed to `ONE` and `subscribe(fn, { toolkits: ['one_drive'] })` dropped every OneDrive event. The same happened to `launch_darkly` and `agent_mail`. A `toolkits` entry now also matches when the trigger slug starts with `<toolkit>_`.
ts/packages/core/src/models/Triggers.ts
+8 -2
@@ -451,12 +451,18 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
451 filters: TriggerSubscribeParams,
452 data: IncomingTriggerPayload
453 ): boolean {
454 - // Check if toolkits filter is provided and matches
454 + // Check if toolkits filter is provided and matches.
455 + // Payloads don't carry the toolkit slug, so `data.toolkitSlug` is the trigger slug's
456 + // first `_` segment, which is wrong for toolkits whose slug contains an underscore
457 + // (`ONE_DRIVE_FILE_CREATED_TRIGGER` gives `ONE`). Trigger slugs start with
458 + // `<TOOLKIT>_`, so a filter also matches on that prefix.
459 + const toolkitSlug = data.toolkitSlug.toLowerCase();
460 + const triggerSlug = data.triggerSlug.toLowerCase();
461 if (
462 filters.toolkits?.length &&
463 !filters.toolkits
464 .map(toolkit => toolkit.toLowerCase())
459 - .includes(data.toolkitSlug.toLowerCase())
465 + .some(toolkit => toolkit === toolkitSlug || triggerSlug.startsWith(`${toolkit}_`))
466 ) {
467 logger.debug(
468 'Trigger does not match toolkits filter',
ts/packages/core/test/models/triggers.test.ts
+38
@@ -1569,5 +1569,43 @@ describe('Triggers', () => {
1569
1570 expect(mockCallback).toHaveBeenCalledTimes(1);
1571 });
1572 +
1573 + // Toolkit slugs such as `one_drive`, `launch_darkly` and `agent_mail` contain an
1574 + // underscore, so the toolkit derived from the trigger slug's first segment is
1575 + // `ONE`, not `ONE_DRIVE`.
1576 + const oneDriveV3Payload = {
1577 + ...mockV3Payload,
1578 + metadata: { ...mockV3Payload.metadata, trigger_slug: 'ONE_DRIVE_FILE_CREATED_TRIGGER' },
1579 + };
1580 +
1581 + it('should match a toolkit filter whose slug contains an underscore', async () => {
1582 + await triggers.subscribe(mockCallback, { toolkits: ['one_drive'] });
1583 + const filterCallback = vi.mocked(mockPusherService.subscribe).mock.calls[0][0];
1584 +
1585 + filterCallback(oneDriveV3Payload);
1586 +
1587 + expect(mockCallback).toHaveBeenCalledTimes(1);
1588 + });
1589 +
1590 + it('should match an underscore toolkit filter case-insensitively', async () => {
1591 + await triggers.subscribe(mockCallback, { toolkits: ['ONE_DRIVE'] });
1592 + const filterCallback = vi.mocked(mockPusherService.subscribe).mock.calls[0][0];
1593 +
1594 + filterCallback(oneDriveV3Payload);
1595 +
1596 + expect(mockCallback).toHaveBeenCalledTimes(1);
1597 + });
1598 +
1599 + it('should not match a toolkit filter that only shares a prefix with the trigger slug', async () => {
1600 + await triggers.subscribe(mockCallback, { toolkits: ['one_drive'] });
1601 + const filterCallback = vi.mocked(mockPusherService.subscribe).mock.calls[0][0];
1602 +
1603 + filterCallback({
1604 + ...mockV3Payload,
1605 + metadata: { ...mockV3Payload.metadata, trigger_slug: 'ONE_DRIVEX_FILE_CREATED' },
1606 + });
1607 +
1608 + expect(mockCallback).not.toHaveBeenCalled();
1609 + });
1610 });
1611 });