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 22, 02:00 UTC
Cache no-auth toolkits as connected (#3036)
## Summary - Cache no-auth toolkits alongside the consumer’s connected toolkits in the short-term cache. - Normalize toolkit slugs to lowercase and deduplicate entries before persisting. - Add a regression test covering the combined cached result for connected and no-auth toolkits. ## Testing - `Not run` (not requested) - Added unit coverage in `ts/packages/cli/test/src/services/consumer-short-term-cache.test.ts` for the merged cache behavior
Rahul Tarak committed
Mar 26, 2026 at 22:58 UTC
fd79865380b71f72fba3d01540f9356363362abf
2 files changed
+169
-2
ts/packages/cli/src/services/consumer-short-term-cache.ts
+20
-2
@@ -4,6 +4,7 @@ import { Effect, Option } from 'effect';
4
import { setupCacheDir } from 'src/effects/setup-cache-dir';
5
import { NodeProcess } from 'src/services/node-process';
6
import {
7
+ ComposioToolkitsRepository,
8
getConsumerConnectedToolkits,
9
resolveConsumerProject,
10
} from 'src/services/composio-clients';
@@ -104,6 +105,21 @@ const writeCache = (state: CacheState) =>
105
yield* fs.writeFileString(cachePath(cacheDir), JSON.stringify(state, null, 2));
106
});
107
108
+const getAlwaysConnectedNoAuthToolkits = () =>
109
+ Effect.gen(function* () {
110
+ const toolkitsRepository = yield* ComposioToolkitsRepository;
111
+ const toolkits = yield* toolkitsRepository.getToolkits();
112
+
113
+ return toolkits
114
+ .filter(toolkit => toolkit.no_auth)
115
+ .map(toolkit => toolkit.slug.toLowerCase());
116
+ });
117
+
118
+const normalizeCachedToolkits = (
119
+ toolkits: ReadonlyArray<string>,
120
+ noAuthToolkits: ReadonlyArray<string>
121
+) => [...new Set([...toolkits, ...noAuthToolkits].map(toolkit => toolkit.toLowerCase()))];
122
+
123
export const getFreshConsumerConnectedToolkitsFromCache = (params: {
124
orgId: string;
125
consumerUserId: string;
@@ -193,6 +209,7 @@ export const refreshConsumerConnectedToolkitsCache = (params?: {
209
orgId: scope.orgId,
210
consumerUserId: scope.consumerUserId,
211
});
212
+ const noAuthToolkits = yield* getAlwaysConnectedNoAuthToolkits();
213
const state = yield* readCache();
214
const key = cacheKey(scope.orgId, scope.consumerUserId);
215
const currentEntry = state[key];
@@ -204,7 +221,7 @@ export const refreshConsumerConnectedToolkitsCache = (params?: {
221
yield* writeCache({
222
...state,
223
[key]: {
207
- toolkits: response.toolkits.map(toolkit => toolkit.toLowerCase()),
224
+ toolkits: normalizeCachedToolkits(response.toolkits, noAuthToolkits),
225
expiresAt: new Date(Date.now() + CACHE_TTL_MS).toISOString(),
226
...searchSessionFields,
227
},
@@ -217,6 +234,7 @@ export const writeConsumerConnectedToolkitsCache = (params: {
234
readonly toolkits: ReadonlyArray<string>;
235
}) =>
236
Effect.gen(function* () {
237
+ const noAuthToolkits = yield* getAlwaysConnectedNoAuthToolkits();
238
const state = yield* readCache();
239
const key = cacheKey(params.orgId, params.consumerUserId);
240
const currentEntry = state[key];
@@ -229,7 +247,7 @@ export const writeConsumerConnectedToolkitsCache = (params: {
247
yield* writeCache({
248
...state,
249
[key]: {
232
- toolkits: [...new Set(params.toolkits.map(toolkit => toolkit.toLowerCase()))],
250
+ toolkits: normalizeCachedToolkits(params.toolkits, noAuthToolkits),
251
expiresAt: new Date(Date.now() + CACHE_TTL_MS).toISOString(),
252
...searchSessionFields,
253
},
ts/packages/cli/test/src/services/consumer-short-term-cache.test.ts
new
+149
@@ -0,0 +1,149 @@
1
+import { describe, expect, layer } from '@effect/vitest';
2
+import { vi, afterEach } from 'vitest';
3
+import { ConfigProvider, Effect, Option } from 'effect';
4
+import { extendConfigProvider } from 'src/services/config';
5
+import * as composioClients from 'src/services/composio-clients';
6
+import {
7
+ getFreshConsumerConnectedToolkitsFromCache,
8
+ refreshConsumerConnectedToolkitsCache,
9
+ writeConsumerConnectedToolkitsCache,
10
+} from 'src/services/consumer-short-term-cache';
11
+import { TestLive } from 'test/__utils__';
12
+
13
+const testConfigProvider = ConfigProvider.fromMap(
14
+ new Map([
15
+ ['COMPOSIO_USER_API_KEY', 'test_api_key'],
16
+ ['COMPOSIO_BASE_URL', 'https://backend.composio.dev'],
17
+ ])
18
+).pipe(extendConfigProvider);
19
+
20
+describe('consumer short-term cache', () => {
21
+ afterEach(() => {
22
+ vi.restoreAllMocks();
23
+ });
24
+
25
+ layer(
26
+ TestLive({
27
+ baseConfigProvider: testConfigProvider,
28
+ toolkitsData: {
29
+ toolkits: [
30
+ {
31
+ name: 'GitHub',
32
+ slug: 'github',
33
+ auth_schemes: ['OAUTH2'],
34
+ composio_managed_auth_schemes: ['OAUTH2'],
35
+ is_local_toolkit: false,
36
+ no_auth: false,
37
+ meta: {
38
+ description: 'GitHub toolkit',
39
+ categories: [],
40
+ created_at: new Date('2024-05-03T11:44:32.061Z') as any,
41
+ updated_at: new Date('2024-05-03T11:44:32.061Z') as any,
42
+ available_versions: [],
43
+ tools_count: 0,
44
+ triggers_count: 0,
45
+ },
46
+ },
47
+ {
48
+ name: 'Hacker News',
49
+ slug: 'hackernews',
50
+ auth_schemes: [],
51
+ composio_managed_auth_schemes: [],
52
+ is_local_toolkit: false,
53
+ no_auth: true,
54
+ meta: {
55
+ description: 'No-auth toolkit',
56
+ categories: [],
57
+ created_at: new Date('2024-05-03T11:44:32.061Z') as any,
58
+ updated_at: new Date('2024-05-03T11:44:32.061Z') as any,
59
+ available_versions: [],
60
+ tools_count: 0,
61
+ triggers_count: 0,
62
+ },
63
+ },
64
+ ],
65
+ },
66
+ })
67
+ )('[Given] no-auth toolkits [Then] refresh caches them as connected', it => {
68
+ it.scoped('stores connected and no-auth toolkit slugs together', () =>
69
+ Effect.gen(function* () {
70
+ vi.spyOn(composioClients, 'getConsumerConnectedToolkits').mockReturnValue(
71
+ Effect.succeed({ toolkits: ['github'] })
72
+ );
73
+
74
+ yield* refreshConsumerConnectedToolkitsCache({
75
+ orgId: 'org_test',
76
+ consumerUserId: 'consumer-user-test',
77
+ });
78
+
79
+ const cached = yield* getFreshConsumerConnectedToolkitsFromCache({
80
+ orgId: 'org_test',
81
+ consumerUserId: 'consumer-user-test',
82
+ });
83
+
84
+ expect(cached).toEqual(Option.some(['github', 'hackernews']));
85
+ })
86
+ );
87
+ });
88
+
89
+ layer(
90
+ TestLive({
91
+ baseConfigProvider: testConfigProvider,
92
+ toolkitsData: {
93
+ toolkits: [
94
+ {
95
+ name: 'GitHub',
96
+ slug: 'github',
97
+ auth_schemes: ['OAUTH2'],
98
+ composio_managed_auth_schemes: ['OAUTH2'],
99
+ is_local_toolkit: false,
100
+ no_auth: false,
101
+ meta: {
102
+ description: 'GitHub toolkit',
103
+ categories: [],
104
+ created_at: new Date('2024-05-03T11:44:32.061Z') as any,
105
+ updated_at: new Date('2024-05-03T11:44:32.061Z') as any,
106
+ available_versions: [],
107
+ tools_count: 0,
108
+ triggers_count: 0,
109
+ },
110
+ },
111
+ {
112
+ name: 'Hacker News',
113
+ slug: 'hackernews',
114
+ auth_schemes: [],
115
+ composio_managed_auth_schemes: [],
116
+ is_local_toolkit: false,
117
+ no_auth: true,
118
+ meta: {
119
+ description: 'No-auth toolkit',
120
+ categories: [],
121
+ created_at: new Date('2024-05-03T11:44:32.061Z') as any,
122
+ updated_at: new Date('2024-05-03T11:44:32.061Z') as any,
123
+ available_versions: [],
124
+ tools_count: 0,
125
+ triggers_count: 0,
126
+ },
127
+ },
128
+ ],
129
+ },
130
+ })
131
+ )('[Given] a search cache write [Then] no-auth toolkits are preserved', it => {
132
+ it.scoped('stores active and no-auth toolkit slugs together', () =>
133
+ Effect.gen(function* () {
134
+ yield* writeConsumerConnectedToolkitsCache({
135
+ orgId: 'org_test',
136
+ consumerUserId: 'consumer-user-test',
137
+ toolkits: ['github'],
138
+ });
139
+
140
+ const cached = yield* getFreshConsumerConnectedToolkitsFromCache({
141
+ orgId: 'org_test',
142
+ consumerUserId: 'consumer-user-test',
143
+ });
144
+
145
+ expect(cached).toEqual(Option.some(['github', 'hackernews']));
146
+ })
147
+ );
148
+ });
149
+});