@composio/core 0.5.1 → 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.
- package/dist/{fileUtils-CJjp8sBn.cjs → fileUtils-BbE-aKW0.cjs} +53 -1
- package/dist/{fileUtils-XEoNI39Q.mjs → fileUtils-BxTR8M_c.mjs} +53 -1
- package/dist/index.cjs +32 -2
- package/dist/index.d.cts +94 -66
- package/dist/index.d.mts +94 -66
- package/dist/index.mjs +32 -2
- package/dist/models/Files.node.cjs +1 -1
- package/dist/models/Files.node.mjs +1 -1
- package/package.json +2 -2
|
@@ -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.
|
|
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.
|
|
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-
|
|
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");
|
|
@@ -5638,7 +5638,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5638
5638
|
|
|
5639
5639
|
//#endregion
|
|
5640
5640
|
//#region package.json
|
|
5641
|
-
var version = "0.5.
|
|
5641
|
+
var version = "0.5.2";
|
|
5642
5642
|
|
|
5643
5643
|
//#endregion
|
|
5644
5644
|
//#region src/utils/session.ts
|
|
@@ -6259,6 +6259,36 @@ var Composio = class Composio {
|
|
|
6259
6259
|
defaultHeaders: sessionHeaders
|
|
6260
6260
|
});
|
|
6261
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
|
+
}
|
|
6262
6292
|
};
|
|
6263
6293
|
|
|
6264
6294
|
//#endregion
|