@composio/core 0.24.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/{CustomTool-CnJxXr07.mjs → CustomTool-BYHB7sPs.mjs} +1 -1
  2. package/dist/{CustomTool-CNJysHMK.d.mts → CustomTool-DfP4ldQl.d.mts} +1 -1
  3. package/dist/{cancellation-BQibgpRG.mjs → cancellation-ZoRh6EJQ.mjs} +55 -3
  4. package/dist/{composio-BFTtZj82.d.mts → composio-BMDH-1Qj.d.mts} +35 -15
  5. package/dist/{customTool.types-D57QrTns.d.mts → customTool.types-BoOELgJF.d.mts} +346 -23
  6. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
  7. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +2 -2
  8. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +22 -22
  9. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -8
  10. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +2 -2
  11. package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -1
  12. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +2 -2
  13. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -5
  14. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
  15. package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -1
  16. package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -5
  17. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
  18. package/dist/docs/reference/sdk-reference/typescript/session.mdx +56 -21
  19. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +6 -6
  20. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +22 -22
  21. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -18
  22. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +25 -25
  23. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -6
  24. package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +14 -14
  25. package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -13
  26. package/dist/{errors-BN15NcCW.mjs → errors-Cly0vXFh.mjs} +5 -5
  27. package/dist/experimental/index.d.mts +2 -2
  28. package/dist/experimental/index.mjs +1 -1
  29. package/dist/index.d.mts +19 -11
  30. package/dist/index.mjs +693 -196
  31. package/dist/{types-q8TwAngA.d.mts → types-DHNV_T_z.d.mts} +2 -2
  32. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  33. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  34. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  35. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  36. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  37. package/package.json +5 -5
  38. package/src/composio.ts +81 -67
  39. package/src/errors/ToolRouterErrors.ts +5 -5
  40. package/src/lib/toolRouterMcp.ts +2 -0
  41. package/src/lib/toolRouterParams.ts +28 -16
  42. package/src/models/ConnectedAccounts.ts +7 -16
  43. package/src/models/ToolRouter.ts +8 -1
  44. package/src/models/ToolRouterSession.ts +17 -0
  45. package/src/models/Tools.ts +1 -4
  46. package/src/models/Triggers.ts +14 -7
  47. package/src/services/internal/InternalService.ts +3 -4
  48. package/src/services/pusher/Pusher.ts +170 -92
  49. package/src/types/connectedAccountAuthStates.types.ts +2 -1
  50. package/src/types/pusher.types.ts +2 -0
  51. package/src/types/requestOptions.types.ts +1 -10
  52. package/src/types/toolRouter.types.ts +104 -18
  53. package/src/utils/jsonSchema.ts +76 -4
  54. package/src/utils/sdk.ts +172 -11
  55. package/src/utils/session.ts +25 -47
  56. package/src/utils/toolkitDeprecation.ts +271 -0
  57. package/src/utils/transformers/connectedAccounts.ts +9 -20
  58. package/src/utils/transformers/mcp.ts +3 -10
  59. package/src/utils/userCallback.ts +41 -0
@@ -60,6 +60,7 @@ import { hmacSha256Base64, timingSafeEqual } from '../utils/crypto';
60
60
  import { CONFIG_DEFAULTS } from '../utils/config-defaults';
61
61
  import { ComposioRequestOptions } from '../types/requestOptions.types';
62
62
  import { withCancellation } from '../utils/cancellation';
63
+ import { invokeUserCallback } from '../utils/userCallback';
63
64
 
64
65
  /**
65
66
  * Safely converts a value to a string, returning the default if the value is null, undefined, or empty.
@@ -157,7 +158,12 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
157
158
 
158
159
  constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
159
160
  this.client = client;
160
- this.pusherService = new PusherService(client, { defaultHeaders: config?.defaultHeaders });
161
+ this.pusherService = new PusherService(client, {
162
+ apiKey: config?.apiKey,
163
+ userApiKey: config?.userApiKey,
164
+ orgApiKey: config?.orgApiKey,
165
+ defaultHeaders: config?.defaultHeaders,
166
+ });
161
167
  this.toolkitVersions = config?.toolkitVersions ?? CONFIG_DEFAULTS.toolkitVersions;
162
168
  telemetry.instrument(this, 'Triggers');
163
169
  }
@@ -525,7 +531,8 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
525
531
  /**
526
532
  * Subscribe to all the triggers
527
533
  *
528
- * @param fn - The function to call when a trigger is received
534
+ * @param fn - The function to call when a trigger is received. It may be `async`. Errors
535
+ * thrown from — or promises rejected by — the function are contained and logged.
529
536
  * @param filters - The filters to apply to the triggers
530
537
  * @param onSubscriptionError - Optional callback invoked with the raw Pusher payload when
531
538
  * the underlying subscription fails (for example on auth or permission rejection). The
@@ -563,11 +570,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
563
570
  const parsedData = this.parsePusherPayload(_data);
564
571
 
565
572
  if (this.shouldSendTriggerAfterFilters(parsedFilters.data, parsedData)) {
566
- try {
567
- fn(parsedData);
568
- } catch (error) {
569
- logger.error('❌ Error in trigger callback:', error);
570
- }
573
+ invokeUserCallback('❌ Error in trigger callback:', () => fn(parsedData));
571
574
  } else {
572
575
  logger.debug('Trigger does not match filters', JSON.stringify(parsedFilters.data, null, 2));
573
576
  }
@@ -700,6 +703,10 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
700
703
  /**
701
704
  * Unsubscribe from all the triggers
702
705
  *
706
+ * Ends every subscription made with {@link subscribe} on this instance, including one that is
707
+ * still connecting, and closes the realtime connection so that a script can exit. A later
708
+ * `subscribe()` opens a new connection.
709
+ *
703
710
  * @returns {Promise<void>}
704
711
  *
705
712
  * @example
@@ -24,10 +24,9 @@ export class InternalService {
24
24
  * @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
25
25
  */
26
26
  async getSDKRealtimeCredentials(): Promise<SDKRealtimeCredentialsResponse> {
27
- const response = await this.client.request<ComposioSDKRealtimeCredentialsResponse>({
28
- method: 'get',
29
- path: SDK_REALTIME_CREDENTIALS_ENDPOINT,
30
- });
27
+ const response = await this.client.get<ComposioSDKRealtimeCredentialsResponse>(
28
+ SDK_REALTIME_CREDENTIALS_ENDPOINT
29
+ );
31
30
 
32
31
  const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
33
32
  pusherKey: response.pusher_key,
@@ -1,5 +1,5 @@
1
1
  import ComposioClient from '@composio/client';
2
- import { PusherClient, TChunkedTriggerData } from '../../types/pusher.types';
2
+ import { PusherChannel, PusherClient, TChunkedTriggerData } from '../../types/pusher.types';
3
3
  import { InternalService } from '../internal/InternalService';
4
4
  import { SDKRealtimeCredentialsResponse } from '../internal/InternalService.types';
5
5
  import {
@@ -8,89 +8,153 @@ import {
8
8
  ComposioFailedToSubscribeToPusherChannelError,
9
9
  } from '../../errors/TriggerErrors';
10
10
  import logger from '../../utils/logger';
11
+ import { invokeUserCallback } from '../../utils/userCallback';
11
12
  import { telemetry } from '../../telemetry/Telemetry';
12
13
  import { resolveCredentialHeaders } from '../../utils/sdk';
13
14
  import type { ComposioRequestHeaders } from '../../types/composio.types';
14
15
 
15
16
  export type PusherServiceOptions = {
17
+ /** The project API key the owning SDK instance resolved, or `null` when disabled. */
18
+ apiKey?: string | null;
19
+ /** The user API key the owning SDK instance resolved, or `null`. */
20
+ userApiKey?: string | null;
21
+ /** The organization API key the owning SDK instance resolved, or `null`. */
22
+ orgApiKey?: string | null;
16
23
  /** Default headers of the owning SDK instance; only `x-user-api-key` is consulted. */
17
24
  defaultHeaders?: ComposioRequestHeaders;
18
25
  };
19
26
 
27
+ /** A pusher-js client and the triggers channel it subscribed to. */
28
+ type TriggerConnection = {
29
+ client: PusherClient;
30
+ channel: PusherChannel;
31
+ channelName: string;
32
+ };
33
+
34
+ /**
35
+ * Setup of the connection for one subscription period, which runs from the first `subscribe()`
36
+ * to the next `unsubscribe()`. Concurrent `subscribe()` calls share `ready`; `unsubscribe()`
37
+ * aborts `controller` so that setup still in flight neither connects nor installs handlers.
38
+ */
39
+ type ConnectionAttempt = {
40
+ controller: AbortController;
41
+ ready: Promise<TriggerConnection>;
42
+ };
43
+
44
+ /**
45
+ * Owns the realtime connection that delivers trigger events.
46
+ *
47
+ * Each subscription period gets its own pusher-js client, which `unsubscribe()` disconnects.
48
+ * Reusing one client across periods is unsafe: pusher-js keeps a channel, its bound handlers and
49
+ * its cancellation flag through `disconnect()` and resubscribes every kept channel on the next
50
+ * `connect()`, and a channel-auth reply requested on the old socket can arrive after a reconnect
51
+ * and be sent on the new one.
52
+ */
20
53
  export class PusherService {
21
- // these values are set via the Apollo API `/internal/sdk/realtime/credentials` endpoint
22
- private clientId!: string;
23
- private pusherKey!: string;
24
- private pusherCluster!: string;
25
- private pusherChannel!: string;
26
54
  // these details are set via the client SDK
27
55
  private pusherBaseURL!: string;
28
56
  private authHeaders!: Record<string, string>;
29
- private pusherClient!: PusherClient;
30
57
  private composioClient!: ComposioClient;
58
+ private attempt?: ConnectionAttempt;
59
+ // Set as soon as the current attempt creates its client, so that `unsubscribe()` can close it
60
+ // before the `subscribe()` calls waiting on `attempt.ready` resume.
61
+ private connection?: TriggerConnection;
31
62
 
32
63
  constructor(client: ComposioClient, options: PusherServiceOptions = {}) {
33
64
  this.composioClient = client;
34
65
  this.pusherBaseURL = client.baseURL;
35
- // Channel authorization mirrors the client's effective auth; the
36
- // environment is never consulted here.
66
+ // Channel authorization mirrors the SDK instance's effective auth, from the
67
+ // keys the SDK resolved; the environment is never consulted here.
37
68
  this.authHeaders = resolveCredentialHeaders({
38
- apiKey: client.apiKey,
39
- userApiKey: client.userApiKey,
69
+ apiKey: options.apiKey,
70
+ userApiKey: options.userApiKey,
71
+ orgApiKey: options.orgApiKey,
40
72
  defaultHeaders: options.defaultHeaders,
41
73
  });
42
74
  telemetry.instrument(this, 'PusherService');
43
75
  }
44
76
 
45
77
  /**
46
- * Creates a Pusher client
47
- *
48
- * This method is called when the Pusher client is first used.
49
- * It will fetch the SDK realtime credentials from the Apollo API and create a Pusher client.
78
+ * Returns the connection attempt of the current subscription period, starting one if needed.
79
+ * A failed attempt is forgotten, so the next `subscribe()` retries.
50
80
  */
51
- private async getPusherClient() {
52
- if (!this.pusherClient) {
53
- const internalService = new InternalService(this.composioClient);
54
- let sdkRealtimeCredentials: SDKRealtimeCredentialsResponse;
55
- try {
56
- sdkRealtimeCredentials = await internalService.getSDKRealtimeCredentials();
57
- } catch (error) {
58
- throw new ComposioFailedToGetSDKRealtimeCredentialsError(
59
- 'Failed to get SDK realtime credentials',
60
- {
61
- cause: error,
62
- }
63
- );
64
- }
81
+ private connect(): ConnectionAttempt {
82
+ if (this.attempt) return this.attempt;
65
83
 
66
- this.clientId = sdkRealtimeCredentials.projectId;
67
- this.pusherKey = sdkRealtimeCredentials.pusherKey;
68
- this.pusherCluster = sdkRealtimeCredentials.pusherCluster;
69
- this.pusherChannel = `private-${this.clientId}_triggers`;
84
+ const controller = new AbortController();
85
+ const ready = this.openConnection(controller.signal);
86
+ const attempt = { controller, ready };
87
+ this.attempt = attempt;
88
+ ready.catch(() => {
89
+ if (this.attempt === attempt) this.attempt = undefined;
90
+ });
91
+ return attempt;
92
+ }
70
93
 
71
- logger.debug(
72
- `[PusherService] Creating Pusher client for client ID: ${this.clientId} in cluster ${this.pusherCluster}`
94
+ /**
95
+ * Fetches the SDK realtime credentials from the Apollo API, creates a Pusher client and
96
+ * subscribes it to the triggers channel.
97
+ */
98
+ private async openConnection(signal: AbortSignal): Promise<TriggerConnection> {
99
+ const internalService = new InternalService(this.composioClient);
100
+ let sdkRealtimeCredentials: SDKRealtimeCredentialsResponse;
101
+ try {
102
+ sdkRealtimeCredentials = await internalService.getSDKRealtimeCredentials();
103
+ } catch (error) {
104
+ throw new ComposioFailedToGetSDKRealtimeCredentialsError(
105
+ 'Failed to get SDK realtime credentials',
106
+ {
107
+ cause: error,
108
+ }
73
109
  );
110
+ }
74
111
 
75
- // create the Pusher client
76
- try {
77
- const { default: Pusher } = await import('pusher-js');
78
- this.pusherClient = new Pusher(this.pusherKey, {
79
- cluster: this.pusherCluster,
80
- channelAuthorization: {
81
- endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
82
- headers: { ...this.authHeaders },
83
- transport: 'ajax',
84
- },
85
- });
86
- } catch (error) {
87
- throw new ComposioFailedToCreatePusherClientError('Failed to create Pusher client', {
88
- cause: error,
89
- });
90
- }
112
+ const { projectId, pusherKey, pusherCluster } = sdkRealtimeCredentials;
113
+ const channelName = `private-${projectId}_triggers`;
114
+
115
+ let Pusher: (typeof import('pusher-js'))['default'];
116
+ try {
117
+ ({ default: Pusher } = await import('pusher-js'));
118
+ } catch (error) {
119
+ throw new ComposioFailedToCreatePusherClientError('Failed to create Pusher client', {
120
+ cause: error,
121
+ });
122
+ }
123
+
124
+ // unsubscribe() ran while the credentials or pusher-js were loading. Everything below is
125
+ // synchronous, so this is the last point at which it can cancel the attempt.
126
+ if (signal.aborted) {
127
+ throw new Error('Connection attempt cancelled by unsubscribe()');
91
128
  }
92
129
 
93
- return this.pusherClient;
130
+ logger.debug(
131
+ `[PusherService] Creating Pusher client for client ID: ${projectId} in cluster ${pusherCluster}`
132
+ );
133
+
134
+ let client: PusherClient;
135
+ try {
136
+ client = new Pusher(pusherKey, {
137
+ cluster: pusherCluster,
138
+ channelAuthorization: {
139
+ endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
140
+ headers: { ...this.authHeaders },
141
+ transport: 'ajax',
142
+ },
143
+ });
144
+ } catch (error) {
145
+ throw new ComposioFailedToCreatePusherClientError('Failed to create Pusher client', {
146
+ cause: error,
147
+ });
148
+ }
149
+
150
+ logger.debug(`[PusherService] Subscribing to channel: ${channelName}`);
151
+ try {
152
+ this.connection = { client, channel: client.subscribe(channelName), channelName };
153
+ } catch (error) {
154
+ client.disconnect();
155
+ throw error;
156
+ }
157
+ return this.connection;
94
158
  }
95
159
 
96
160
  /**
@@ -102,7 +166,7 @@ export class PusherService {
102
166
  * @param callback - The function to call when the event is received
103
167
  */
104
168
  private bindWithChunking(
105
- channel: PusherClient,
169
+ channel: PusherChannel,
106
170
  event: string,
107
171
  callback: (data: Record<string, unknown>) => void
108
172
  ): void {
@@ -167,11 +231,10 @@ export class PusherService {
167
231
  /**
168
232
  * Subscribes to pusher to receive events from the server
169
233
  *
170
- * This method is used to subscribe to a Pusher channel.
171
- * It will create a Pusher client if it doesn't exist.
234
+ * The first call of a subscription period creates the Pusher client; concurrent calls share
235
+ * it. A call still waiting for the client when `unsubscribe()` runs resolves without
236
+ * subscribing.
172
237
  *
173
- * @param channelName - The name of the Pusher channel to subscribe to
174
- * @param event - The event to subscribe to
175
238
  * @param fn - The function to call when the event is received
176
239
  * @param onSubscriptionError - Optional callback invoked with the raw payload when the
177
240
  * Pusher subscription fails (for example on auth or permission rejection). Errors thrown
@@ -181,30 +244,38 @@ export class PusherService {
181
244
  fn: (data: Record<string, unknown>) => void,
182
245
  onSubscriptionError?: (data: Record<string, unknown>) => void
183
246
  ) {
247
+ const attempt = this.connect();
248
+ let connection: TriggerConnection;
184
249
  try {
185
- logger.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
186
- const pusherClient = await this.getPusherClient();
187
- const channel = await pusherClient.subscribe(this.pusherChannel);
250
+ connection = await attempt.ready;
251
+ } catch (error) {
252
+ if (attempt.controller.signal.aborted) {
253
+ logger.debug('[PusherService] Subscribe cancelled by unsubscribe() before it connected');
254
+ return;
255
+ }
256
+ throw new ComposioFailedToSubscribeToPusherChannelError(
257
+ 'Failed to subscribe to Pusher channel',
258
+ {
259
+ cause: error,
260
+ }
261
+ );
262
+ }
263
+ // unsubscribe() ran after the client was created but before this call resumed.
264
+ if (attempt.controller.signal.aborted) {
265
+ logger.debug('[PusherService] Subscribe cancelled by unsubscribe() before it connected');
266
+ return;
267
+ }
188
268
 
189
- // add subscription error handling
190
- const logCallbackFailure = (callbackError: unknown) => {
191
- const errorMessage =
192
- callbackError instanceof Error ? callbackError.message : String(callbackError);
193
- logger.error('❌ Error in subscription error callback:', errorMessage);
194
- };
269
+ try {
270
+ const { channel } = connection;
195
271
  channel.bind('pusher:subscription_error', (data: Record<string, unknown>) => {
196
272
  logger.error('Trigger subscription error:', data);
197
273
 
198
274
  // surface the failure to the caller without letting a faulty
199
275
  // handler crash the host (same containment as the trigger callback).
200
- // A handler may be async: contain rejected promises too, or the
201
- // rejection escapes as an unhandled rejection after subscribe()
202
- // already resolved.
203
- try {
204
- Promise.resolve(onSubscriptionError?.(data)).catch(logCallbackFailure);
205
- } catch (callbackError: unknown) {
206
- logCallbackFailure(callbackError);
207
- }
276
+ invokeUserCallback('❌ Error in subscription error callback:', () =>
277
+ onSubscriptionError?.(data)
278
+ );
208
279
  });
209
280
 
210
281
  // log success only when Pusher itself confirms the subscription
@@ -212,18 +283,12 @@ export class PusherService {
212
283
  logger.info(`✅ Subscribed to triggers. You should start receiving events now.`);
213
284
  });
214
285
 
215
- // wrap the callback to handle errors
286
+ // don't let a failing callback break the subscription
216
287
  const safeCallback = (data: Record<string, unknown>) => {
217
- try {
218
- fn(data);
219
- } catch (error: unknown) {
220
- const errorMessage = error instanceof Error ? error.message : String(error);
221
- logger.error('❌ Error in trigger callback:', errorMessage);
222
- // don't throw here to prevent breaking the subscription
223
- }
288
+ invokeUserCallback('❌ Error in trigger callback:', () => fn(data));
224
289
  };
225
290
 
226
- this.bindWithChunking(channel as PusherClient, 'trigger_to_client', safeCallback);
291
+ this.bindWithChunking(channel, 'trigger_to_client', safeCallback);
227
292
  } catch (error) {
228
293
  throw new ComposioFailedToSubscribeToPusherChannelError(
229
294
  'Failed to subscribe to Pusher channel',
@@ -235,19 +300,29 @@ export class PusherService {
235
300
  }
236
301
 
237
302
  /**
238
- * Unsubscribes from a Pusher channel
239
- *
240
- * This method is used to unsubscribe from a Pusher channel.
241
- * It will create a Pusher client if it doesn't exist.
303
+ * Unsubscribes from the triggers channel and closes the connection
242
304
  *
243
- * @param channelName - The name of the Pusher channel to unsubscribe from
305
+ * This ends the subscription period: setup still in flight is cancelled, the handlers bound by
306
+ * every `subscribe()` call are removed, and the Pusher client is disconnected. Without a prior
307
+ * `subscribe()` this does nothing; it never creates a client or fetches credentials.
244
308
  */
245
309
  async unsubscribe() {
310
+ const { attempt, connection } = this;
311
+ this.attempt = undefined;
312
+ this.connection = undefined;
313
+ attempt?.controller.abort();
314
+
315
+ if (!connection) {
316
+ logger.debug('[PusherService] No open connection to unsubscribe from');
317
+ return;
318
+ }
319
+
320
+ logger.debug(`[PusherService] Unsubscribing from channel: ${connection.channelName}`);
246
321
  try {
247
- logger.debug(`[PusherService] Unsubscribing from channel: ${this.pusherChannel}`);
248
- const pusherClient = await this.getPusherClient();
249
- await pusherClient.unsubscribe(this.pusherChannel);
250
- logger.info(`✅ Unsubscribed from triggers.`);
322
+ // pusher-js keeps a reference to every client it creates, so release the handlers this
323
+ // service bound and the user callbacks they hold.
324
+ connection.channel.unbind_all();
325
+ connection.client.unsubscribe(connection.channelName);
251
326
  } catch (error) {
252
327
  throw new ComposioFailedToSubscribeToPusherChannelError(
253
328
  'Failed to unsubscribe from Pusher channel',
@@ -255,6 +330,9 @@ export class PusherService {
255
330
  cause: error,
256
331
  }
257
332
  );
333
+ } finally {
334
+ connection.client.disconnect();
258
335
  }
336
+ logger.info(`✅ Unsubscribed from triggers.`);
259
337
  }
260
338
  }
@@ -222,7 +222,8 @@ const S2SOauth2ConnectionDataSchema = z.discriminatedUnion('status', [
222
222
  }).catchall(z.unknown()),
223
223
  ]);
224
224
  const CustomS2SOauth2ConnectionDataSchema = BaseSchemeRaw.extend({
225
- access_token: z.string().optional(),
225
+ // Required by the API: custom connection data supplies the token itself.
226
+ access_token: z.string(),
226
227
  id_token: z.string().optional(),
227
228
  token_type: z.string().optional(),
228
229
  refresh_token: z.string().nullish().optional(),
@@ -2,12 +2,14 @@ export interface PusherClient {
2
2
  subscribe: (channelName: string) => PusherChannel;
3
3
  unsubscribe: (channelName: string) => void;
4
4
  bind: (event: string, callback: (data: Record<string, unknown>) => void) => void;
5
+ disconnect: () => void;
5
6
  }
6
7
 
7
8
  export interface PusherChannel {
8
9
  subscribe: (channelName: string) => unknown;
9
10
  unsubscribe: (channelName: string) => void;
10
11
  bind: (event: string, callback: (data: Record<string, unknown>) => void) => void;
12
+ unbind_all: () => void;
11
13
  }
12
14
 
13
15
  export type TChunkedTriggerData = {
@@ -1,4 +1,4 @@
1
- import type ComposioClient from '@composio/client';
1
+ import type { RequestOptions as ClientRequestOptions } from '@composio/client';
2
2
 
3
3
  /**
4
4
  * Per-request transport options for cancelling an SDK call.
@@ -38,15 +38,6 @@ export type ComposioRequestOptions = {
38
38
  signal?: AbortSignal;
39
39
  };
40
40
 
41
- /**
42
- * The `@composio/client` per-request transport options, reached via a public
43
- * method whose only parameter is that type (`tools.retrieveEnum`). The
44
- * `internal/*` subpath that declares `RequestOptions` is not in the package's
45
- * `exports`, so we derive it structurally instead of deep-importing it.
46
- * @internal
47
- */
48
- type ClientRequestOptions = NonNullable<Parameters<ComposioClient['tools']['retrieveEnum']>[0]>;
49
-
50
41
  /**
51
42
  * Compile-time guards: {@link ComposioRequestOptions} is forwarded verbatim to
52
43
  * every `@composio/client` call, so it MUST stay a structural subset of the