@composio/core 0.5.0 → 0.5.2

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.
@@ -367,6 +367,7 @@ var BatchProcessor = class {
367
367
  batchSize;
368
368
  processBatchCallback;
369
369
  timer = null;
370
+ pendingBatches = /* @__PURE__ */ new Set();
370
371
  constructor(time = 2e3, batchSize = 100, processBatchCallback) {
371
372
  this.batch = [];
372
373
  this.time = time;
@@ -380,14 +381,26 @@ var BatchProcessor = class {
380
381
  }
381
382
  processBatch() {
382
383
  if (this.batch.length > 0) {
383
- this.processBatchCallback(this.batch);
384
+ const batchToProcess = this.batch;
384
385
  this.batch = [];
386
+ const pending = this.processBatchCallback(batchToProcess).catch(() => {}).finally(() => {
387
+ this.pendingBatches.delete(pending);
388
+ });
389
+ this.pendingBatches.add(pending);
385
390
  }
386
391
  if (this.timer) {
387
392
  clearTimeout(this.timer);
388
393
  this.timer = null;
389
394
  }
390
395
  }
396
+ /**
397
+ * Flush any pending batches and wait for all of them to complete.
398
+ * Useful for ensuring telemetry is sent before process exit.
399
+ */
400
+ async flush() {
401
+ this.processBatch();
402
+ if (this.pendingBatches.size > 0) await Promise.all(this.pendingBatches);
403
+ }
391
404
  };
392
405
 
393
406
  //#endregion
@@ -463,6 +476,7 @@ var TelemetryTransport = class {
463
476
  telemetrySourceName = "typescript-sdk";
464
477
  telemetryServiceName = "sdk";
465
478
  telemetryLanguage = "typescript";
479
+ exitHandlersRegistered = false;
466
480
  batchProcessor = new BatchProcessor(200, 10, async (data) => {
467
481
  logger_default.debug("Sending batch of telemetry metrics", data);
468
482
  await TelemetryService.sendMetric(data);
@@ -478,6 +492,7 @@ var TelemetryTransport = class {
478
492
  platform: this.telemetryMetadata?.isBrowser ? "browser" : "node",
479
493
  environment: getEnvVariable("NODE_ENV", "production")
480
494
  };
495
+ this.registerExitHandlers();
481
496
  this.sendMetric([{
482
497
  functionName: TELEMETRY_EVENTS.SDK_INITIALIZED,
483
498
  durationMs: 0,
@@ -631,6 +646,43 @@ var TelemetryTransport = class {
631
646
  logger_default.error("Error sending error telemetry", error);
632
647
  }
633
648
  }
649
+ /**
650
+ * Flush any pending telemetry and wait for it to complete.
651
+ * This is automatically called on process exit in Node.js environments.
652
+ */
653
+ async flush() {
654
+ await this.batchProcessor.flush();
655
+ }
656
+ /**
657
+ * Register process exit handlers to automatically flush telemetry.
658
+ * Only registers handlers in Node.js environments (not in browsers).
659
+ */
660
+ registerExitHandlers() {
661
+ if (this.exitHandlersRegistered || typeof process === "undefined" || !process.on) return;
662
+ this.exitHandlersRegistered = true;
663
+ const flushSync = () => {
664
+ this.flush().catch((error) => {
665
+ logger_default.debug("Error flushing telemetry on exit", error);
666
+ });
667
+ };
668
+ process.on("beforeExit", () => {
669
+ flushSync();
670
+ });
671
+ const createSignalHandler = (signal) => {
672
+ const handler = () => {
673
+ logger_default.debug(`Received ${signal}, flushing telemetry...`);
674
+ this.flush().catch((error) => {
675
+ logger_default.debug("Error flushing telemetry on signal", error);
676
+ }).finally(() => {
677
+ process.removeListener(signal, handler);
678
+ process.kill(process.pid, signal);
679
+ });
680
+ };
681
+ return handler;
682
+ };
683
+ process.on("SIGINT", createSignalHandler("SIGINT"));
684
+ process.on("SIGTERM", createSignalHandler("SIGTERM"));
685
+ }
634
686
  };
635
687
  const telemetry = new TelemetryTransport();
636
688
 
@@ -365,6 +365,7 @@ var BatchProcessor = class {
365
365
  batchSize;
366
366
  processBatchCallback;
367
367
  timer = null;
368
+ pendingBatches = /* @__PURE__ */ new Set();
368
369
  constructor(time = 2e3, batchSize = 100, processBatchCallback) {
369
370
  this.batch = [];
370
371
  this.time = time;
@@ -378,14 +379,26 @@ var BatchProcessor = class {
378
379
  }
379
380
  processBatch() {
380
381
  if (this.batch.length > 0) {
381
- this.processBatchCallback(this.batch);
382
+ const batchToProcess = this.batch;
382
383
  this.batch = [];
384
+ const pending = this.processBatchCallback(batchToProcess).catch(() => {}).finally(() => {
385
+ this.pendingBatches.delete(pending);
386
+ });
387
+ this.pendingBatches.add(pending);
383
388
  }
384
389
  if (this.timer) {
385
390
  clearTimeout(this.timer);
386
391
  this.timer = null;
387
392
  }
388
393
  }
394
+ /**
395
+ * Flush any pending batches and wait for all of them to complete.
396
+ * Useful for ensuring telemetry is sent before process exit.
397
+ */
398
+ async flush() {
399
+ this.processBatch();
400
+ if (this.pendingBatches.size > 0) await Promise.all(this.pendingBatches);
401
+ }
389
402
  };
390
403
 
391
404
  //#endregion
@@ -461,6 +474,7 @@ var TelemetryTransport = class {
461
474
  telemetrySourceName = "typescript-sdk";
462
475
  telemetryServiceName = "sdk";
463
476
  telemetryLanguage = "typescript";
477
+ exitHandlersRegistered = false;
464
478
  batchProcessor = new BatchProcessor(200, 10, async (data) => {
465
479
  logger_default.debug("Sending batch of telemetry metrics", data);
466
480
  await TelemetryService.sendMetric(data);
@@ -476,6 +490,7 @@ var TelemetryTransport = class {
476
490
  platform: this.telemetryMetadata?.isBrowser ? "browser" : "node",
477
491
  environment: getEnvVariable("NODE_ENV", "production")
478
492
  };
493
+ this.registerExitHandlers();
479
494
  this.sendMetric([{
480
495
  functionName: TELEMETRY_EVENTS.SDK_INITIALIZED,
481
496
  durationMs: 0,
@@ -629,6 +644,43 @@ var TelemetryTransport = class {
629
644
  logger_default.error("Error sending error telemetry", error);
630
645
  }
631
646
  }
647
+ /**
648
+ * Flush any pending telemetry and wait for it to complete.
649
+ * This is automatically called on process exit in Node.js environments.
650
+ */
651
+ async flush() {
652
+ await this.batchProcessor.flush();
653
+ }
654
+ /**
655
+ * Register process exit handlers to automatically flush telemetry.
656
+ * Only registers handlers in Node.js environments (not in browsers).
657
+ */
658
+ registerExitHandlers() {
659
+ if (this.exitHandlersRegistered || typeof process === "undefined" || !process.on) return;
660
+ this.exitHandlersRegistered = true;
661
+ const flushSync = () => {
662
+ this.flush().catch((error) => {
663
+ logger_default.debug("Error flushing telemetry on exit", error);
664
+ });
665
+ };
666
+ process.on("beforeExit", () => {
667
+ flushSync();
668
+ });
669
+ const createSignalHandler = (signal) => {
670
+ const handler = () => {
671
+ logger_default.debug(`Received ${signal}, flushing telemetry...`);
672
+ this.flush().catch((error) => {
673
+ logger_default.debug("Error flushing telemetry on signal", error);
674
+ }).finally(() => {
675
+ process.removeListener(signal, handler);
676
+ process.kill(process.pid, signal);
677
+ });
678
+ };
679
+ return handler;
680
+ };
681
+ process.on("SIGINT", createSignalHandler("SIGINT"));
682
+ process.on("SIGTERM", createSignalHandler("SIGTERM"));
683
+ }
632
684
  };
633
685
  const telemetry = new TelemetryTransport();
634
686
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CQwRTUmo.cjs');
2
- const require_fileUtils = require('./fileUtils-CJjp8sBn.cjs');
2
+ const require_fileUtils = require('./fileUtils-BbE-aKW0.cjs');
3
3
  let _composio_client = require("@composio/client");
4
4
  _composio_client = require_chunk.__toESM(_composio_client);
5
5
  let zod_v3 = require("zod/v3");
@@ -68,17 +68,18 @@ const CreateCustomAuthConfigParamsSchema = zod_v3.z.object({
68
68
  proxyUrl: zod_v3.z.string(),
69
69
  proxyAuthKey: zod_v3.z.string().optional()
70
70
  }).optional(),
71
- toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional()
71
+ toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional(),
72
+ isEnabledForToolRouter: zod_v3.z.boolean().optional()
72
73
  });
73
74
  const CreateComposioManagedAuthConfigParamsSchema = zod_v3.z.object({
74
75
  type: zod_v3.z.literal("use_composio_managed_auth"),
75
76
  name: zod_v3.z.string().optional(),
76
- credentials: zod_v3.z.record(zod_v3.z.string(), zod_v3.z.union([
77
- zod_v3.z.string(),
78
- zod_v3.z.number(),
79
- zod_v3.z.boolean()
80
- ])).optional(),
81
- toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional()
77
+ credentials: zod_v3.z.object({
78
+ scopes: zod_v3.z.union([zod_v3.z.string(), zod_v3.z.array(zod_v3.z.string())]).optional(),
79
+ user_scopes: zod_v3.z.union([zod_v3.z.string(), zod_v3.z.array(zod_v3.z.string())]).optional()
80
+ }).passthrough().optional(),
81
+ toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional(),
82
+ isEnabledForToolRouter: zod_v3.z.boolean().optional()
82
83
  });
83
84
  /**
84
85
  * Discriminated union of all possible auth config types.
@@ -103,6 +104,7 @@ const AuthConfigRetrieveResponseSchema = zod_v3.z.object({
103
104
  authScheme: AuthSchemeEnum.optional(),
104
105
  credentials: zod_v3.z.record(zod_v3.z.string(), zod_v3.z.unknown()).optional(),
105
106
  expectedInputFields: zod_v3.z.array(zod_v3.z.unknown()).optional(),
107
+ isEnabledForToolRouter: zod_v3.z.boolean().optional(),
106
108
  restrictToFollowingTools: zod_v3.z.array(zod_v3.z.string()).optional(),
107
109
  isComposioManaged: zod_v3.z.boolean().optional(),
108
110
  createdBy: zod_v3.z.string().optional(),
@@ -122,14 +124,19 @@ const AuthConfigListResponseSchema = zod_v3.z.object({
122
124
  totalPages: zod_v3.z.number()
123
125
  });
124
126
  const AuthCustomConfigUpdateParamsSchema = zod_v3.z.object({
125
- credentials: zod_v3.z.record(zod_v3.z.string(), zod_v3.z.union([zod_v3.z.string(), zod_v3.z.unknown()])),
126
127
  type: zod_v3.z.literal("custom"),
128
+ credentials: zod_v3.z.object({
129
+ scopes: zod_v3.z.union([zod_v3.z.string(), zod_v3.z.array(zod_v3.z.string())]).optional(),
130
+ user_scopes: zod_v3.z.union([zod_v3.z.string(), zod_v3.z.array(zod_v3.z.string())]).optional()
131
+ }).passthrough().optional(),
132
+ isEnabledForToolRouter: zod_v3.z.boolean().optional(),
127
133
  restrictToFollowingTools: zod_v3.z.array(zod_v3.z.string()).optional(),
128
134
  toolAccessConfig: AuthConfigToolAccessConfigSchema.optional()
129
135
  });
130
136
  const AuthDefaultConfigUpdateParamsSchema = zod_v3.z.object({
131
- scopes: zod_v3.z.string().optional(),
132
137
  type: zod_v3.z.literal("default"),
138
+ scopes: zod_v3.z.string().optional(),
139
+ isEnabledForToolRouter: zod_v3.z.boolean().optional(),
133
140
  restrictToFollowingTools: zod_v3.z.array(zod_v3.z.string()).optional(),
134
141
  toolAccessConfig: AuthConfigToolAccessConfigSchema.optional()
135
142
  });
@@ -2765,6 +2772,7 @@ function transformAuthConfigRetrieveResponse(authConfig) {
2765
2772
  logo: authConfig$1.toolkit.logo,
2766
2773
  slug: authConfig$1.toolkit.slug
2767
2774
  },
2775
+ isEnabledForToolRouter: authConfig$1.is_enabled_for_tool_router,
2768
2776
  uuid: authConfig$1.uuid,
2769
2777
  authScheme: authConfig$1.auth_scheme,
2770
2778
  credentials: authConfig$1.credentials,
@@ -2903,6 +2911,7 @@ var AuthConfigs = class {
2903
2911
  name: parsedOptions.data.name,
2904
2912
  authScheme: parsedOptions.data.authScheme,
2905
2913
  credentials: parsedOptions.data.credentials,
2914
+ is_enabled_for_tool_router: parsedOptions.data.isEnabledForToolRouter,
2906
2915
  proxy_config: parsedOptions.data.proxyConfig ? {
2907
2916
  proxy_url: parsedOptions.data.proxyConfig.proxyUrl,
2908
2917
  proxy_auth_key: parsedOptions.data.proxyConfig.proxyAuthKey
@@ -2912,6 +2921,7 @@ var AuthConfigs = class {
2912
2921
  type: parsedOptions.data.type,
2913
2922
  credentials: parsedOptions.data.credentials,
2914
2923
  name: parsedOptions.data.name,
2924
+ is_enabled_for_tool_router: parsedOptions.data.isEnabledForToolRouter,
2915
2925
  tool_access_config: parsedOptions.data.toolAccessConfig ? { tools_for_connected_account_creation: parsedOptions.data.toolAccessConfig.toolsForConnectedAccountCreation } : void 0
2916
2926
  }
2917
2927
  }));
@@ -2974,6 +2984,7 @@ var AuthConfigs = class {
2974
2984
  return this.client.authConfigs.update(nanoid, parsedData.data.type === "custom" ? {
2975
2985
  type: "custom",
2976
2986
  credentials: parsedData.data.credentials,
2987
+ is_enabled_for_tool_router: parsedData.data.isEnabledForToolRouter,
2977
2988
  tool_access_config: {
2978
2989
  tools_for_connected_account_creation: parsedData.data.toolAccessConfig?.toolsForConnectedAccountCreation,
2979
2990
  tools_available_for_execution: parsedData.data.toolAccessConfig?.toolsAvailableForExecution ?? parsedData.data.restrictToFollowingTools
@@ -2981,6 +2992,7 @@ var AuthConfigs = class {
2981
2992
  } : {
2982
2993
  type: "default",
2983
2994
  scopes: parsedData.data.scopes,
2995
+ is_enabled_for_tool_router: parsedData.data.isEnabledForToolRouter,
2984
2996
  tool_access_config: {
2985
2997
  tools_for_connected_account_creation: parsedData.data.toolAccessConfig?.toolsForConnectedAccountCreation,
2986
2998
  tools_available_for_execution: parsedData.data.toolAccessConfig?.toolsAvailableForExecution ?? parsedData.data.restrictToFollowingTools
@@ -5626,7 +5638,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
5626
5638
 
5627
5639
  //#endregion
5628
5640
  //#region package.json
5629
- var version = "0.5.0";
5641
+ var version = "0.5.2";
5630
5642
 
5631
5643
  //#endregion
5632
5644
  //#region src/utils/session.ts
@@ -6247,6 +6259,36 @@ var Composio = class Composio {
6247
6259
  defaultHeaders: sessionHeaders
6248
6260
  });
6249
6261
  }
6262
+ /**
6263
+ * Flush any pending telemetry and wait for it to complete.
6264
+ *
6265
+ * In Node.js-compatible environments, telemetry is automatically flushed on process exit.
6266
+ * However, in environments like Cloudflare Workers that don't support process exit events,
6267
+ * you should call this method manually to ensure all telemetry is sent.
6268
+ *
6269
+ * @returns {Promise<void>} A promise that resolves when all pending telemetry has been sent.
6270
+ *
6271
+ * @example
6272
+ * ```typescript
6273
+ * // In a Cloudflare Worker, use ctx.waitUntil to ensure telemetry is flushed
6274
+ * export default {
6275
+ * async fetch(request: Request, env: Env, ctx: ExecutionContext) {
6276
+ * const composio = new Composio({ apiKey: env.COMPOSIO_API_KEY });
6277
+ *
6278
+ * // Do your work...
6279
+ * const result = await composio.tools.execute(...);
6280
+ *
6281
+ * // Ensure telemetry flushes before worker terminates
6282
+ * ctx.waitUntil(composio.flush());
6283
+ *
6284
+ * return new Response(JSON.stringify(result));
6285
+ * }
6286
+ * };
6287
+ * ```
6288
+ */
6289
+ async flush() {
6290
+ await require_fileUtils.telemetry.flush();
6291
+ }
6250
6292
  };
6251
6293
 
6252
6294
  //#endregion