Skip to content

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

fix(cli): resolve pusher-js constructor across ESM/CJS interop shapes (#3926)

Billa84d05fc99f0
diff --git a/ts/packages/cli/CHANGELOG.md b/ts/packages/cli/CHANGELOG.md
index a8d90b62d..12f229fe6 100644
--- a/ts/packages/cli/CHANGELOG.md
+++ b/ts/packages/cli/CHANGELOG.md
@@ -15,6 +15,7 @@
### Patch Changes
+- Fix `composio listen` crashing with `TypeError: Object is not a constructor` in compiled release binaries (issue #3918). pusher-js 8.5.0 exports a namespace object (`module.exports = { Pusher }`) instead of the constructor (an undocumented upstream packaging regression, pusher/pusher-js#935, fixed in pusher-js 8.6.0), so the dynamic import's `.default` is not callable under Node or Bun; the realtime service now probes every observed interop shape (including the named `Pusher` export), constructs the client inside `Effect.try`, and fails with a typed error instead of crashing.
- Preserve the original CLI diagnostic when an adjacent source map is malformed or unusable instead of letting optional source-map enrichment abort error capture. Source-map enrichment is now best-effort end to end: a malformed, invalid, or unreadable `.map`, and a valid map pointing at an original source that was never shipped, all degrade to the raw stack location. `captureErrors` can no longer fail.
- Fix source-map resolution on Windows: original source paths are now resolved with the platform path separator instead of a hardcoded `/`, and the `node_modules` filter no longer mistakes directories such as `node_modules_local` for real dependency paths.
- Make `composio version --check` report `checkStatus: "unknown"` when GitHub cannot confirm the latest stable release, preserve the last successful cache on failed refreshes, and avoid racing the command with the startup update check.
diff --git a/ts/packages/cli/src/services/triggers-realtime.ts b/ts/packages/cli/src/services/triggers-realtime.ts
index 3b08555b1..618ff3f03 100644
--- a/ts/packages/cli/src/services/triggers-realtime.ts
+++ b/ts/packages/cli/src/services/triggers-realtime.ts
@@ -1,4 +1,4 @@
-import { Data, Effect, Either, Option, Runtime, Schema } from 'effect';
+import { Array as Arr, Data, Effect, Either, Option, Predicate, Runtime, Schema } from 'effect';
import { JsonRecordSchema } from 'src/effects/json';
import {
ComposioClientSingleton,
@@ -29,6 +29,47 @@ export class TriggerRealtimeSubscriptionError extends Data.TaggedError(
const subscriptionError = (message: string) => (cause: unknown) =>
new TriggerRealtimeSubscriptionError({ message, cause });
+type PusherConstructor = (typeof import('pusher-js'))['default'];
+
+const isPusherConstructor = (value: unknown): value is PusherConstructor =>
+ Predicate.isFunction(value);
+
+const propertyOf = (value: unknown, property: string): unknown =>
+ Predicate.hasProperty(value, property) ? value[property] : undefined;
+
+/**
+ * Resolves the Pusher constructor across ESM/CJS interop shapes. pusher-js
+ * ships CJS and has changed its export shape across versions: 8.4.x and 8.6.0
+ * export the constructor itself (`module.exports = Pusher`), while 8.5.0's
+ * Node bundle exports a namespace object (`module.exports = { Pusher }`) — an
+ * undocumented upstream packaging regression (pusher/pusher-js#935, fixed by
+ * pusher/pusher-js#936, first released in 8.6.0). With 8.5.0,
+ * `module.default` stops being callable under both Node and Bun — from source
+ * and in compiled binaries alike (issue #3918). The probes cover, in order: a
+ * defensively double-wrapped default (`module.default.default`), the direct
+ * class export (`module.default`, 8.4.0/8.6.0), a raw CJS module that is
+ * itself the constructor, and the named `Pusher` export on either level
+ * (`module.default.Pusher` is the 8.5.0 shape that crashed compiled release
+ * binaries; runtimes also hoist it to `module.Pusher`).
+ *
+ * Exported for tests.
+ */
+export const resolvePusherConstructor = (
+ pusherModule: unknown
+): Option.Option<PusherConstructor> => {
+ const moduleDefault = propertyOf(pusherModule, 'default');
+ return Arr.findFirst(
+ [
+ propertyOf(moduleDefault, 'default'),
+ moduleDefault,
+ pusherModule,
+ propertyOf(moduleDefault, 'Pusher'),
+ propertyOf(pusherModule, 'Pusher'),
+ ],
+ isPusherConstructor
+ );
+};
+
/**
* Service for listening to trigger events over Composio CLI realtime channels.
* Uses:
@@ -64,38 +105,46 @@ export class TriggersRealtime extends Effect.Service<TriggersRealtime>()(
catch: subscriptionError('Failed to load the realtime client'),
});
- const Pusher = pusherModule.default;
-
- const pusher = new Pusher(creds.pusher_key, {
- cluster: creds.pusher_cluster,
- channelAuthorization: {
- customHandler: (authOptions, callback) => {
- const channel_name = authOptions.channelName;
- const socket_id = authOptions.socketId;
-
- const doAuth = async () => {
- const response = await Runtime.runPromise(runtime)(
- params.authRealtimeChannel({
- channel_name,
- socket_id,
- })
- );
- // Pusher private channels verify signatures without channel_data.
- // Some auth endpoints may still return channel_data, which can cause
- // "Invalid signature" if included in the verification input.
- const normalizedResponse = channel_name.startsWith('private-')
- ? { auth: response.auth }
- : response;
- return normalizedResponse;
- };
-
- void doAuth()
- .then(data => callback(null, data))
- .catch(cause =>
- callback(cause instanceof Error ? cause : new Error(String(cause)), null)
- );
- },
- },
+ const Pusher = yield* resolvePusherConstructor(pusherModule).pipe(
+ Effect.mapError(
+ subscriptionError('Realtime client module does not expose a constructor')
+ )
+ );
+
+ const pusher = yield* Effect.try({
+ try: () =>
+ new Pusher(creds.pusher_key, {
+ cluster: creds.pusher_cluster,
+ channelAuthorization: {
+ customHandler: (authOptions, callback) => {
+ const channel_name = authOptions.channelName;
+ const socket_id = authOptions.socketId;
+
+ const doAuth = async () => {
+ const response = await Runtime.runPromise(runtime)(
+ params.authRealtimeChannel({
+ channel_name,
+ socket_id,
+ })
+ );
+ // Pusher private channels verify signatures without channel_data.
+ // Some auth endpoints may still return channel_data, which can cause
+ // "Invalid signature" if included in the verification input.
+ const normalizedResponse = channel_name.startsWith('private-')
+ ? { auth: response.auth }
+ : response;
+ return normalizedResponse;
+ };
+
+ void doAuth()
+ .then(data => callback(null, data))
+ .catch(cause =>
+ callback(cause instanceof Error ? cause : new Error(String(cause)), null)
+ );
+ },
+ },
+ }),
+ catch: subscriptionError('Failed to construct the realtime client'),
});
const channel = pusher.subscribe(channelName);
diff --git a/ts/packages/cli/test/src/services/triggers-realtime.test.ts b/ts/packages/cli/test/src/services/triggers-realtime.test.ts
new file mode 100644
index 000000000..cda166fa7
--- /dev/null
+++ b/ts/packages/cli/test/src/services/triggers-realtime.test.ts
@@ -0,0 +1,62 @@
+import { describe, expect, it } from '@effect/vitest';
+import { Option } from 'effect';
+import { resolvePusherConstructor } from 'src/services/triggers-realtime';
+
+/**
+ * Regression tests for issue #3918: `composio listen` crashed with
+ * `TypeError: Object is not a constructor` in compiled release binaries
+ * because pusher-js 8.5.0 exports a namespace object
+ * (`module.exports = { Pusher }`), so the dynamic import's `.default` is not
+ * the constructor.
+ */
+describe('resolvePusherConstructor', () => {
+ class FakePusher {}
+
+ it('resolves the constructor from `module.default` (Node interop, running from source)', () => {
+ expect(resolvePusherConstructor({ default: FakePusher })).toEqual(Option.some(FakePusher));
+ });
+
+ it('resolves the constructor from `module.default.default` (defensive double-wrapped interop)', () => {
+ expect(resolvePusherConstructor({ default: { default: FakePusher } })).toEqual(
+ Option.some(FakePusher)
+ );
+ });
+
+ it('prefers the nested constructor when both interop levels are callable', () => {
+ const outer = Object.assign(function outer() {}, { default: FakePusher });
+ expect(resolvePusherConstructor({ default: outer })).toEqual(Option.some(FakePusher));
+ });
+
+ it('falls back to the module object itself when it is the constructor', () => {
+ expect(resolvePusherConstructor(FakePusher)).toEqual(Option.some(FakePusher));
+ });
+
+ it('resolves a named `Pusher` export on the default namespace (pusher-js 8.5.0 shape, issue #3918)', () => {
+ expect(
+ resolvePusherConstructor({ default: { Pusher: FakePusher }, Pusher: FakePusher })
+ ).toEqual(Option.some(FakePusher));
+ });
+
+ it('resolves a named `Pusher` export on the module itself', () => {
+ expect(resolvePusherConstructor({ Pusher: FakePusher })).toEqual(Option.some(FakePusher));
+ });
+
+ it('resolves a `default.Pusher` namespace export without a top-level `Pusher` fallback', () => {
+ expect(resolvePusherConstructor({ default: { Pusher: FakePusher } })).toEqual(
+ Option.some(FakePusher)
+ );
+ });
+
+ it('resolves the constructor from the real installed pusher-js module', async () => {
+ const pusherModule = await import('pusher-js');
+ const resolved = resolvePusherConstructor(pusherModule);
+ expect(Option.isSome(resolved)).toBe(true);
+ });
+
+ it('returns none when no interop shape exposes a callable constructor', () => {
+ expect(resolvePusherConstructor({ default: { default: 'not-a-function' } })).toEqual(
+ Option.none()
+ );
+ expect(resolvePusherConstructor(undefined)).toEqual(Option.none());
+ });
+});