@composio/core 0.1.11-alpha.0 → 0.1.12-alpha.10
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/README.md +27 -7
- package/dist/index.cjs +894 -452
- package/dist/index.d.cts +957 -169
- package/dist/index.d.ts +957 -169
- package/dist/index.js +893 -452
- package/package.json +13 -12
- package/src/index.ts +0 -23
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
BaseTelemetryTransport: () => BaseTelemetryTransport,
|
|
38
38
|
Composio: () => Composio,
|
|
39
39
|
ComposioProvider: () => ComposioProvider,
|
|
40
|
+
ConsoleTelemetryTransport: () => ConsoleTelemetryTransport,
|
|
40
41
|
OpenAIProvider: () => OpenAIProvider,
|
|
41
42
|
ToolListParamsSchema: () => ToolListParamsSchema,
|
|
42
43
|
jsonSchemaToModel: () => jsonSchemaToModel
|
|
@@ -44,7 +45,7 @@ __export(index_exports, {
|
|
|
44
45
|
module.exports = __toCommonJS(index_exports);
|
|
45
46
|
|
|
46
47
|
// src/composio.ts
|
|
47
|
-
var
|
|
48
|
+
var import_client2 = __toESM(require("@composio/client"), 1);
|
|
48
49
|
|
|
49
50
|
// src/types/tool.types.ts
|
|
50
51
|
var import_zod = require("zod");
|
|
@@ -107,12 +108,14 @@ var ToolExecuteResponseSchema = import_zod.z.object({
|
|
|
107
108
|
// src/models/CustomTools.ts
|
|
108
109
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"), 1);
|
|
109
110
|
|
|
111
|
+
// src/utils/logger.ts
|
|
112
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
113
|
+
|
|
110
114
|
// src/utils/env.ts
|
|
111
115
|
var getEnvVariable = (name, defaultValue = void 0) => {
|
|
112
116
|
try {
|
|
113
117
|
return process.env[name] || defaultValue;
|
|
114
118
|
} catch (_e) {
|
|
115
|
-
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
116
119
|
return defaultValue;
|
|
117
120
|
}
|
|
118
121
|
};
|
|
@@ -131,7 +134,7 @@ var LOG_LEVELS = {
|
|
|
131
134
|
// Debug information
|
|
132
135
|
};
|
|
133
136
|
var getLogLevel = () => {
|
|
134
|
-
const envLevel = getEnvVariable("
|
|
137
|
+
const envLevel = getEnvVariable("COMPOSIO_LOG_LEVEL", "info")?.toLowerCase();
|
|
135
138
|
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
136
139
|
};
|
|
137
140
|
var Logger = class {
|
|
@@ -149,7 +152,7 @@ var Logger = class {
|
|
|
149
152
|
return formattedArgs;
|
|
150
153
|
}
|
|
151
154
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
152
|
-
return `${timestamp} - ${formattedArgs}`;
|
|
155
|
+
return `${import_chalk.default.gray(timestamp)} - ${formattedArgs}`;
|
|
153
156
|
}
|
|
154
157
|
shouldLog(level) {
|
|
155
158
|
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
@@ -313,6 +316,265 @@ var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
|
313
316
|
}
|
|
314
317
|
};
|
|
315
318
|
|
|
319
|
+
// src/types/telemetry.types.ts
|
|
320
|
+
var TELEMETRY_EVENTS = {
|
|
321
|
+
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
322
|
+
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
323
|
+
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
324
|
+
CLI_INVOKED: "CLI_INVOKED"
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/utils/constants.ts
|
|
328
|
+
var COMPOSIO_DIR = ".composio";
|
|
329
|
+
var USER_DATA_FILE_NAME = "user_data.json";
|
|
330
|
+
var DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
331
|
+
var TELEMETRY_URL = "https://app.composio.dev";
|
|
332
|
+
var IS_DEVELOPMENT_OR_CI = process.env.DEVELOPMENT || process.env.CI || false;
|
|
333
|
+
|
|
334
|
+
// src/telemetry/BatchProcessor.ts
|
|
335
|
+
var BatchProcessor = class {
|
|
336
|
+
batch = [];
|
|
337
|
+
time;
|
|
338
|
+
batchSize;
|
|
339
|
+
processBatchCallback;
|
|
340
|
+
timer = null;
|
|
341
|
+
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
342
|
+
this.batch = [];
|
|
343
|
+
this.time = time;
|
|
344
|
+
this.batchSize = batchSize;
|
|
345
|
+
this.processBatchCallback = processBatchCallback;
|
|
346
|
+
}
|
|
347
|
+
pushItem(item) {
|
|
348
|
+
this.batch.push(item);
|
|
349
|
+
if (this.batch.length >= this.batchSize) {
|
|
350
|
+
this.processBatch();
|
|
351
|
+
} else if (!this.timer) {
|
|
352
|
+
this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
processBatch() {
|
|
356
|
+
if (this.batch.length > 0) {
|
|
357
|
+
this.processBatchCallback(this.batch);
|
|
358
|
+
this.batch = [];
|
|
359
|
+
}
|
|
360
|
+
if (this.timer) {
|
|
361
|
+
clearTimeout(this.timer);
|
|
362
|
+
this.timer = null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// src/telemetry/transports/BrowserTransport.ts
|
|
368
|
+
var BrowserTelemetryTransport = class {
|
|
369
|
+
send(payload) {
|
|
370
|
+
if (typeof window === "undefined") {
|
|
371
|
+
return Promise.reject(
|
|
372
|
+
new Error("BrowserTelemetryTransport can only be used in browser environments")
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
return new Promise((resolve) => {
|
|
376
|
+
try {
|
|
377
|
+
const xhr = new XMLHttpRequest();
|
|
378
|
+
xhr.open(payload.method, payload.url, true);
|
|
379
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
380
|
+
Object.entries(payload.headers || {}).forEach(([key, value]) => {
|
|
381
|
+
xhr.setRequestHeader(key, value);
|
|
382
|
+
});
|
|
383
|
+
xhr.onload = function() {
|
|
384
|
+
resolve();
|
|
385
|
+
};
|
|
386
|
+
xhr.send(JSON.stringify(payload.data));
|
|
387
|
+
} catch (error) {
|
|
388
|
+
logger_default.error("Error sending error to telemetry", error);
|
|
389
|
+
resolve();
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// src/telemetry/transports/ProcessTransport.ts
|
|
396
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
397
|
+
var ProcessTelemetryTransport = class {
|
|
398
|
+
send(payload) {
|
|
399
|
+
if (typeof window !== "undefined") {
|
|
400
|
+
return Promise.reject(
|
|
401
|
+
new Error("ProcessTelemetryTransport can only be used in Node.js environments")
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
return new Promise((resolve) => {
|
|
405
|
+
try {
|
|
406
|
+
const url = new URL(payload.url);
|
|
407
|
+
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
408
|
+
const port = url.port || (url.protocol === "https:" ? 443 : 80);
|
|
409
|
+
const args = [
|
|
410
|
+
"-e",
|
|
411
|
+
`
|
|
412
|
+
const http = require('${protocol}');
|
|
413
|
+
const options = {
|
|
414
|
+
hostname: '${url.hostname}',
|
|
415
|
+
path: '${url.pathname}${url.search}',
|
|
416
|
+
port: ${port},
|
|
417
|
+
method: '${payload.method}',
|
|
418
|
+
headers: ${JSON.stringify(payload.headers)}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
const req = http.request(options, (res) => {
|
|
422
|
+
res.on('data', () => {});
|
|
423
|
+
res.on('end', () => {
|
|
424
|
+
process.exit(0);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
req.on('error', () => {
|
|
429
|
+
process.exit(0);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
req.write(JSON.stringify(${JSON.stringify(payload.data)}));
|
|
433
|
+
req.end();
|
|
434
|
+
`
|
|
435
|
+
];
|
|
436
|
+
import("child_process").then(({ spawn }) => {
|
|
437
|
+
spawn("node", args, {
|
|
438
|
+
stdio: "ignore",
|
|
439
|
+
detached: true,
|
|
440
|
+
shell: false
|
|
441
|
+
}).unref();
|
|
442
|
+
resolve();
|
|
443
|
+
}).catch(() => {
|
|
444
|
+
resolve();
|
|
445
|
+
});
|
|
446
|
+
logger_default.debug(import_chalk2.default.yellow("Process telemetry"), JSON.stringify(payload, null, 2));
|
|
447
|
+
} catch (error) {
|
|
448
|
+
logger_default.error("Error sending telemetry", error);
|
|
449
|
+
resolve();
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// src/telemetry/Telemetry.ts
|
|
456
|
+
var TelemetryService = class {
|
|
457
|
+
telemetryMetadata;
|
|
458
|
+
transport;
|
|
459
|
+
isTelemetryDisabled = true;
|
|
460
|
+
batchProcessor = new BatchProcessor(100, 10, async (data) => {
|
|
461
|
+
await this.sendTelemetry(data);
|
|
462
|
+
});
|
|
463
|
+
setup(metadata, transport) {
|
|
464
|
+
this.telemetryMetadata = metadata;
|
|
465
|
+
this.isTelemetryDisabled = false;
|
|
466
|
+
const isBrowser = typeof window !== "undefined";
|
|
467
|
+
if (transport) {
|
|
468
|
+
this.transport = transport;
|
|
469
|
+
} else if (isBrowser) {
|
|
470
|
+
this.transport = new BrowserTelemetryTransport();
|
|
471
|
+
this.telemetryMetadata.transport = "browser";
|
|
472
|
+
} else {
|
|
473
|
+
this.transport = new ProcessTelemetryTransport();
|
|
474
|
+
this.telemetryMetadata.transport = "process";
|
|
475
|
+
}
|
|
476
|
+
this.sendTelemetry([
|
|
477
|
+
{
|
|
478
|
+
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
479
|
+
data: {},
|
|
480
|
+
sdk_meta: this.telemetryMetadata
|
|
481
|
+
}
|
|
482
|
+
]);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Instrument the telemetry for the given instance.
|
|
486
|
+
*
|
|
487
|
+
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
488
|
+
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
489
|
+
* @param instance - any instance that extends InstrumentedInstance
|
|
490
|
+
* @param fileName - the file name of the instance
|
|
491
|
+
* @returns
|
|
492
|
+
*/
|
|
493
|
+
instrument(instance, fileName) {
|
|
494
|
+
const proto = Object.getPrototypeOf(instance);
|
|
495
|
+
const methodNames = Object.getOwnPropertyNames(proto).filter((key) => {
|
|
496
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
497
|
+
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
498
|
+
});
|
|
499
|
+
const instrumentedClassName = instance.constructor?.name || fileName || "unknown";
|
|
500
|
+
for (const name of methodNames) {
|
|
501
|
+
const originalMethod = instance[name];
|
|
502
|
+
instance[name] = async (...args) => {
|
|
503
|
+
const telemetryPayload = {
|
|
504
|
+
eventName: TELEMETRY_EVENTS.SDK_METHOD_INVOKED,
|
|
505
|
+
data: {
|
|
506
|
+
fileName: instrumentedClassName,
|
|
507
|
+
method: name,
|
|
508
|
+
params: args
|
|
509
|
+
},
|
|
510
|
+
sdk_meta: this.telemetryMetadata
|
|
511
|
+
};
|
|
512
|
+
this.batchProcessor.pushItem(telemetryPayload);
|
|
513
|
+
try {
|
|
514
|
+
return await originalMethod.apply(instance, args);
|
|
515
|
+
} catch (error) {
|
|
516
|
+
const telemetryPayload2 = {
|
|
517
|
+
eventName: TELEMETRY_EVENTS.SDK_METHOD_ERROR,
|
|
518
|
+
data: {
|
|
519
|
+
fileName: instrumentedClassName,
|
|
520
|
+
method: name,
|
|
521
|
+
params: args,
|
|
522
|
+
error
|
|
523
|
+
},
|
|
524
|
+
sdk_meta: this.telemetryMetadata
|
|
525
|
+
};
|
|
526
|
+
this.batchProcessor.pushItem(telemetryPayload2);
|
|
527
|
+
throw error;
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
return instance;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Check if the telemetry should be sent.
|
|
535
|
+
* @returns true if the telemetry should be sent, false otherwise
|
|
536
|
+
*/
|
|
537
|
+
shouldSendTelemetry() {
|
|
538
|
+
const devEnvironments = ["test", "development", "CI"];
|
|
539
|
+
const nodeEnv = (getEnvVariable("NODE_ENV", "development") || "").toLowerCase();
|
|
540
|
+
const isDevEnvironment = devEnvironments.includes(nodeEnv);
|
|
541
|
+
const isTelemetryDisabledByEnv = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
542
|
+
return this.transport && !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDevEnvironment;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Send the telemetry payload to the server.
|
|
546
|
+
* @param payload - the telemetry payload to send
|
|
547
|
+
* @returns
|
|
548
|
+
*/
|
|
549
|
+
async sendTelemetry(payload) {
|
|
550
|
+
if (!this.shouldSendTelemetry()) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
554
|
+
const reqPayload = {
|
|
555
|
+
data: payload,
|
|
556
|
+
url,
|
|
557
|
+
method: "POST",
|
|
558
|
+
headers: { "Content-Type": "application/json" }
|
|
559
|
+
};
|
|
560
|
+
this.transport.send(reqPayload);
|
|
561
|
+
}
|
|
562
|
+
async sendErrorTelemetry(error) {
|
|
563
|
+
if (!this.shouldSendTelemetry()) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const url = `${TELEMETRY_URL}/api/sdk_metrics/error`;
|
|
567
|
+
const reqPayload = {
|
|
568
|
+
data: { error },
|
|
569
|
+
url,
|
|
570
|
+
method: "POST",
|
|
571
|
+
headers: { "Content-Type": "application/json" }
|
|
572
|
+
};
|
|
573
|
+
this.transport.send(reqPayload);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
var telemetry = new TelemetryService();
|
|
577
|
+
|
|
316
578
|
// src/models/CustomTools.ts
|
|
317
579
|
var CustomTools = class {
|
|
318
580
|
client;
|
|
@@ -323,6 +585,7 @@ var CustomTools = class {
|
|
|
323
585
|
}
|
|
324
586
|
this.client = client;
|
|
325
587
|
this.customToolsRegistry = /* @__PURE__ */ new Map();
|
|
588
|
+
telemetry.instrument(this);
|
|
326
589
|
}
|
|
327
590
|
/**
|
|
328
591
|
* Create a custom tool and registers it in the registry.
|
|
@@ -417,8 +680,8 @@ var CustomTools = class {
|
|
|
417
680
|
});
|
|
418
681
|
}
|
|
419
682
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
420
|
-
|
|
421
|
-
|
|
683
|
+
toolkit_slugs: [toolkitSlug],
|
|
684
|
+
user_ids: [metadata.userId]
|
|
422
685
|
});
|
|
423
686
|
if (!connectedAccounts.items.length) {
|
|
424
687
|
throw new ComposioConnectedAccountNotFoundError(
|
|
@@ -485,7 +748,7 @@ var ValidationErrorCodes = {
|
|
|
485
748
|
};
|
|
486
749
|
var ValidationError = class extends ComposioError {
|
|
487
750
|
zodError;
|
|
488
|
-
constructor(zodError, message = "Input validation failed") {
|
|
751
|
+
constructor(zodError, message = "Input validation failed", meta) {
|
|
489
752
|
let zodErrorInstance;
|
|
490
753
|
if (!(zodError instanceof import_zod2.ZodError)) {
|
|
491
754
|
zodErrorInstance = new import_zod2.ZodError([
|
|
@@ -498,20 +761,16 @@ var ValidationError = class extends ComposioError {
|
|
|
498
761
|
} else {
|
|
499
762
|
zodErrorInstance = zodError;
|
|
500
763
|
}
|
|
764
|
+
const issues = zodErrorInstance.issues.map(
|
|
765
|
+
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
766
|
+
);
|
|
501
767
|
super(message, {
|
|
502
768
|
code: ValidationErrorCodes.VALIDATION_ERROR,
|
|
503
|
-
meta
|
|
504
|
-
|
|
505
|
-
zodErrorInstance.issues.map((issue) => ({
|
|
506
|
-
path: issue.path.join("."),
|
|
507
|
-
message: issue.message,
|
|
508
|
-
code: issue.code
|
|
509
|
-
}))
|
|
510
|
-
)
|
|
511
|
-
},
|
|
512
|
-
cause: zodErrorInstance
|
|
769
|
+
meta,
|
|
770
|
+
cause: issues.join("\n")
|
|
513
771
|
});
|
|
514
772
|
this.zodError = zodErrorInstance;
|
|
773
|
+
this.name = "ValidationError";
|
|
515
774
|
}
|
|
516
775
|
};
|
|
517
776
|
|
|
@@ -531,13 +790,21 @@ var Tools = class {
|
|
|
531
790
|
this.customTools = new CustomTools(client);
|
|
532
791
|
this.provider = provider;
|
|
533
792
|
this.execute = this.execute.bind(this);
|
|
793
|
+
this.provider._setExecuteToolFn(this.execute);
|
|
534
794
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
535
795
|
this.getRawComposioTools = this.getRawComposioTools.bind(this);
|
|
796
|
+
telemetry.instrument(this);
|
|
536
797
|
}
|
|
537
798
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
799
|
+
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
800
|
+
*
|
|
801
|
+
* This method standardizes the property naming convention for tools retrieved from the Composio API,
|
|
802
|
+
* making them more consistent with JavaScript/TypeScript conventions.
|
|
803
|
+
*
|
|
804
|
+
* @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
|
|
805
|
+
* @returns {Tool} The transformed tool with camelCase properties
|
|
806
|
+
*
|
|
807
|
+
* @private
|
|
541
808
|
*/
|
|
542
809
|
transformToolCases(tool) {
|
|
543
810
|
return ToolSchema.parse({
|
|
@@ -547,9 +814,15 @@ var Tools = class {
|
|
|
547
814
|
});
|
|
548
815
|
}
|
|
549
816
|
/**
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
817
|
+
* Transforms tool execution response from snake_case API format to camelCase.
|
|
818
|
+
*
|
|
819
|
+
* This method converts the response received from the Composio API to a standardized format
|
|
820
|
+
* with consistent property naming that follows JavaScript/TypeScript conventions.
|
|
821
|
+
*
|
|
822
|
+
* @param {ComposioToolExecuteResponse} response - The raw API response to transform
|
|
823
|
+
* @returns {ToolExecuteResponse} The transformed response with camelCase properties
|
|
824
|
+
*
|
|
825
|
+
* @private
|
|
553
826
|
*/
|
|
554
827
|
transformToolExecuteResponse(response) {
|
|
555
828
|
return ToolExecuteResponseSchema.parse({
|
|
@@ -634,9 +907,35 @@ var Tools = class {
|
|
|
634
907
|
return null;
|
|
635
908
|
}
|
|
636
909
|
/**
|
|
637
|
-
* Lists all tools available in the Composio SDK
|
|
638
|
-
*
|
|
639
|
-
*
|
|
910
|
+
* Lists all tools available in the Composio SDK including custom tools.
|
|
911
|
+
*
|
|
912
|
+
* This method fetches tools from the Composio API in raw format and combines them with
|
|
913
|
+
* any registered custom tools. The response can be filtered and modified as needed.
|
|
914
|
+
*
|
|
915
|
+
* @param {string} userId - The user ID for whom to fetch the tools
|
|
916
|
+
* @param {ToolListParams} [query={}] - Optional query parameters to filter the tools
|
|
917
|
+
* @param {TransformToolSchemaModifier} [modifier] - Optional function to transform tool schemas
|
|
918
|
+
* @returns {Promise<ToolList>} List of tools matching the query criteria
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```typescript
|
|
922
|
+
* // Get all tools
|
|
923
|
+
* const tools = await composio.tools.getRawComposioTools('default');
|
|
924
|
+
*
|
|
925
|
+
* // Get tools with filters
|
|
926
|
+
* const githubTools = await composio.tools.getRawComposioTools('default', {
|
|
927
|
+
* toolkits: ['github'],
|
|
928
|
+
* important: true
|
|
929
|
+
* });
|
|
930
|
+
*
|
|
931
|
+
* // Get tools with schema transformation
|
|
932
|
+
* const tools = await composio.tools.getRawComposioTools('default', {},
|
|
933
|
+
* (toolSlug, toolkitSlug, tool) => {
|
|
934
|
+
* // Add custom properties to tool schema
|
|
935
|
+
* return {...tool, customProperty: 'value'};
|
|
936
|
+
* }
|
|
937
|
+
* );
|
|
938
|
+
* ```
|
|
640
939
|
*/
|
|
641
940
|
async getRawComposioTools(userId, query = {}, modifier) {
|
|
642
941
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
@@ -672,6 +971,7 @@ var Tools = class {
|
|
|
672
971
|
}
|
|
673
972
|
/**
|
|
674
973
|
* Retrieves a tool by its Slug.
|
|
974
|
+
* This method is used to get the raw tools from the composio API.
|
|
675
975
|
* @param slug The ID of the tool to be retrieved
|
|
676
976
|
* @returns {Promise<Tool>} The tool
|
|
677
977
|
*
|
|
@@ -702,19 +1002,21 @@ var Tools = class {
|
|
|
702
1002
|
return modifiedToool;
|
|
703
1003
|
}
|
|
704
1004
|
/**
|
|
705
|
-
* Get a tool
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* @param
|
|
709
|
-
* @
|
|
1005
|
+
* Get a tool or list of tools based on the provided arguments.
|
|
1006
|
+
* This is an implementation method that handles both overloads.
|
|
1007
|
+
*
|
|
1008
|
+
* @param {string} userId - The user id to get the tool(s) for
|
|
1009
|
+
* @param {ToolListParams | string} arg2 - Either a slug string or filters object
|
|
1010
|
+
* @param {ProviderOptions<TProvider>} [options] - Optional provider options
|
|
1011
|
+
* @returns {Promise<TToolCollection>} The tool collection
|
|
710
1012
|
*/
|
|
711
1013
|
async get(userId, arg2, options) {
|
|
712
1014
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
713
1015
|
if (typeof arg2 === "string") {
|
|
714
|
-
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.
|
|
715
|
-
return this.provider.
|
|
1016
|
+
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
|
|
1017
|
+
return this.provider.wrapTools([tool], executeToolFn);
|
|
716
1018
|
} else {
|
|
717
|
-
const tools = await this.getRawComposioTools(userId, arg2, options?.
|
|
1019
|
+
const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
|
|
718
1020
|
return this.provider.wrapTools(tools, executeToolFn);
|
|
719
1021
|
}
|
|
720
1022
|
}
|
|
@@ -748,26 +1050,22 @@ var Tools = class {
|
|
|
748
1050
|
* @returns The response from the tool execution
|
|
749
1051
|
*/
|
|
750
1052
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
751
|
-
if (modifiers?.
|
|
752
|
-
if (typeof modifiers.
|
|
753
|
-
body = modifiers.
|
|
1053
|
+
if (modifiers?.beforeExecute) {
|
|
1054
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1055
|
+
body = modifiers.beforeExecute(tool.slug, "unkown", body);
|
|
754
1056
|
} else {
|
|
755
|
-
throw new ComposioInvalidModifierError(
|
|
756
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
757
|
-
);
|
|
1057
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
758
1058
|
}
|
|
759
1059
|
}
|
|
760
1060
|
let result = await this.customTools.executeCustomTool(tool.slug, body, {
|
|
761
1061
|
userId: body.userId || "default",
|
|
762
1062
|
connectedAccountId: body.connectedAccountId
|
|
763
1063
|
});
|
|
764
|
-
if (modifiers?.
|
|
765
|
-
if (typeof modifiers.
|
|
766
|
-
result = modifiers.
|
|
1064
|
+
if (modifiers?.afterExecute) {
|
|
1065
|
+
if (typeof modifiers.afterExecute === "function") {
|
|
1066
|
+
result = modifiers.afterExecute(tool.slug, "unkown", result);
|
|
767
1067
|
} else {
|
|
768
|
-
throw new ComposioInvalidModifierError(
|
|
769
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
770
|
-
);
|
|
1068
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
771
1069
|
}
|
|
772
1070
|
}
|
|
773
1071
|
return result;
|
|
@@ -781,13 +1079,11 @@ var Tools = class {
|
|
|
781
1079
|
* @returns The response from the tool execution
|
|
782
1080
|
*/
|
|
783
1081
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
784
|
-
if (modifiers?.
|
|
785
|
-
if (typeof modifiers.
|
|
786
|
-
body = modifiers.
|
|
1082
|
+
if (modifiers?.beforeExecute) {
|
|
1083
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1084
|
+
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug || "unkown", body);
|
|
787
1085
|
} else {
|
|
788
|
-
throw new ComposioInvalidModifierError(
|
|
789
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
790
|
-
);
|
|
1086
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
791
1087
|
}
|
|
792
1088
|
}
|
|
793
1089
|
let connectedAccountId = body.connectedAccountId;
|
|
@@ -804,25 +1100,53 @@ var Tools = class {
|
|
|
804
1100
|
text: body.text
|
|
805
1101
|
});
|
|
806
1102
|
result = this.transformToolExecuteResponse(result);
|
|
807
|
-
if (modifiers?.
|
|
808
|
-
if (typeof modifiers.
|
|
809
|
-
result = modifiers.
|
|
1103
|
+
if (modifiers?.afterExecute) {
|
|
1104
|
+
if (typeof modifiers.afterExecute === "function") {
|
|
1105
|
+
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug || "unkown", result);
|
|
810
1106
|
} else {
|
|
811
|
-
throw new ComposioInvalidModifierError(
|
|
812
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
813
|
-
);
|
|
1107
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
814
1108
|
}
|
|
815
1109
|
}
|
|
816
1110
|
return result;
|
|
817
1111
|
}
|
|
818
1112
|
/**
|
|
819
|
-
*
|
|
1113
|
+
* Executes a given tool with the provided parameters.
|
|
820
1114
|
*
|
|
821
|
-
* This method calls the Composio API to execute the tool and returns the response.
|
|
1115
|
+
* This method calls the Composio API or a custom tool handler to execute the tool and returns the response.
|
|
1116
|
+
* It automatically determines whether to use a custom tool or a Composio API tool based on the slug.
|
|
822
1117
|
*
|
|
823
|
-
* @param {string} slug - The ID of the tool to be executed
|
|
1118
|
+
* @param {string} slug - The slug/ID of the tool to be executed
|
|
824
1119
|
* @param {ToolExecuteParams} body - The parameters to be passed to the tool
|
|
1120
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional modifiers to transform the request or response
|
|
825
1121
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
1122
|
+
*
|
|
1123
|
+
* @throws {ComposioCustomToolsNotInitializedError} If the CustomTools instance is not initialized
|
|
1124
|
+
* @throws {ComposioToolNotFoundError} If the tool with the given slug is not found
|
|
1125
|
+
* @throws {ComposioToolExecutionError} If there is an error during tool execution
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```typescript
|
|
1129
|
+
* // Execute a Composio API tool
|
|
1130
|
+
* const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
|
|
1131
|
+
* userId: 'default',
|
|
1132
|
+
* arguments: { userId: 'pg' }
|
|
1133
|
+
* });
|
|
1134
|
+
*
|
|
1135
|
+
* // Execute with modifiers
|
|
1136
|
+
* const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
|
|
1137
|
+
* userId: 'default',
|
|
1138
|
+
* arguments: { owner: 'composio', repo: 'sdk' }
|
|
1139
|
+
* }, {
|
|
1140
|
+
* beforeExecute: (toolSlug, toolkitSlug, params) => {
|
|
1141
|
+
* // Modify params before execution
|
|
1142
|
+
* return params;
|
|
1143
|
+
* },
|
|
1144
|
+
* afterExecute: (toolSlug, toolkitSlug, result) => {
|
|
1145
|
+
* // Transform result after execution
|
|
1146
|
+
* return result;
|
|
1147
|
+
* }
|
|
1148
|
+
* });
|
|
1149
|
+
* ```
|
|
826
1150
|
*/
|
|
827
1151
|
async execute(slug, body, modifiers) {
|
|
828
1152
|
if (!this.customTools) {
|
|
@@ -879,9 +1203,39 @@ var Tools = class {
|
|
|
879
1203
|
return this.client.tools.proxy(body);
|
|
880
1204
|
}
|
|
881
1205
|
/**
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
1206
|
+
* Creates a custom tool that can be used within the Composio SDK.
|
|
1207
|
+
*
|
|
1208
|
+
* Custom tools allow you to extend the functionality of Composio with your own implementations
|
|
1209
|
+
* while keeping a consistent interface for both built-in and custom tools.
|
|
1210
|
+
*
|
|
1211
|
+
* @param {CustomToolOptions} body - The configuration for the custom tool
|
|
1212
|
+
* @returns {Promise<Tool>} The created custom tool
|
|
1213
|
+
*
|
|
1214
|
+
* @example
|
|
1215
|
+
* ```typescript
|
|
1216
|
+
* const customTool = await composio.tools.createCustomTool({
|
|
1217
|
+
* name: 'My Custom Tool',
|
|
1218
|
+
* description: 'A custom tool that does something specific',
|
|
1219
|
+
* slug: 'MY_CUSTOM_TOOL',
|
|
1220
|
+
* inputParameters: {
|
|
1221
|
+
* param1: {
|
|
1222
|
+
* type: 'string',
|
|
1223
|
+
* description: 'First parameter',
|
|
1224
|
+
* required: true
|
|
1225
|
+
* }
|
|
1226
|
+
* },
|
|
1227
|
+
* outputParameters: {
|
|
1228
|
+
* result: {
|
|
1229
|
+
* type: 'string',
|
|
1230
|
+
* description: 'The result of the operation'
|
|
1231
|
+
* }
|
|
1232
|
+
* },
|
|
1233
|
+
* handler: async (params, context) => {
|
|
1234
|
+
* // Custom logic here
|
|
1235
|
+
* return { data: { result: 'Success!' } };
|
|
1236
|
+
* }
|
|
1237
|
+
* });
|
|
1238
|
+
* ```
|
|
885
1239
|
*/
|
|
886
1240
|
async createCustomTool(body) {
|
|
887
1241
|
return this.customTools.createTool(body);
|
|
@@ -1039,7 +1393,7 @@ var AuthConfigRetrieveResponseSchema = import_zod4.z.object({
|
|
|
1039
1393
|
status: import_zod4.z.enum(["ENABLED", "DISABLED"]),
|
|
1040
1394
|
uuid: import_zod4.z.string(),
|
|
1041
1395
|
authScheme: AuthSchemeEnum.optional(),
|
|
1042
|
-
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.
|
|
1396
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional(),
|
|
1043
1397
|
expectedInputFields: import_zod4.z.array(import_zod4.z.unknown()).optional(),
|
|
1044
1398
|
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1045
1399
|
createdBy: import_zod4.z.string().optional(),
|
|
@@ -1077,6 +1431,7 @@ var AuthConfigs = class {
|
|
|
1077
1431
|
client;
|
|
1078
1432
|
constructor(client) {
|
|
1079
1433
|
this.client = client;
|
|
1434
|
+
telemetry.instrument(this);
|
|
1080
1435
|
}
|
|
1081
1436
|
/**
|
|
1082
1437
|
* Protected getter for the client instance.
|
|
@@ -1086,6 +1441,18 @@ var AuthConfigs = class {
|
|
|
1086
1441
|
getClient() {
|
|
1087
1442
|
return this.client;
|
|
1088
1443
|
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Transforms an auth config response from API format to SDK format.
|
|
1446
|
+
*
|
|
1447
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
1448
|
+
* the data structure to match the SDK's standardized format for auth configurations.
|
|
1449
|
+
*
|
|
1450
|
+
* @param {ComposioAuthConfigRetrieveResponse} authConfig - The raw API response to transform
|
|
1451
|
+
* @returns {AuthConfigRetrieveResponse} The transformed auth config data
|
|
1452
|
+
* @throws {ValidationError} If the response fails validation against the expected schema
|
|
1453
|
+
*
|
|
1454
|
+
* @private
|
|
1455
|
+
*/
|
|
1089
1456
|
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1090
1457
|
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
1091
1458
|
id: authConfig.id,
|
|
@@ -1111,10 +1478,30 @@ var AuthConfigs = class {
|
|
|
1111
1478
|
return result.data;
|
|
1112
1479
|
}
|
|
1113
1480
|
/**
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1481
|
+
* Lists authentication configurations based on provided filter criteria.
|
|
1482
|
+
*
|
|
1483
|
+
* This method retrieves auth configs from the Composio API, transforms them to the SDK format,
|
|
1484
|
+
* and supports filtering by various parameters.
|
|
1485
|
+
*
|
|
1486
|
+
* @param {AuthConfigListParams} [query] - Optional query parameters for filtering auth configs
|
|
1487
|
+
* @returns {Promise<AuthConfigListResponse>} A paginated list of auth configurations
|
|
1488
|
+
* @throws {ValidationError} If the query parameters or response fail validation
|
|
1489
|
+
*
|
|
1490
|
+
* @example
|
|
1491
|
+
* ```typescript
|
|
1492
|
+
* // List all auth configs
|
|
1493
|
+
* const allConfigs = await composio.authConfigs.list();
|
|
1494
|
+
*
|
|
1495
|
+
* // List auth configs for a specific toolkit
|
|
1496
|
+
* const githubConfigs = await composio.authConfigs.list({
|
|
1497
|
+
* toolkitSlug: 'github'
|
|
1498
|
+
* });
|
|
1499
|
+
*
|
|
1500
|
+
* // List Composio-managed auth configs
|
|
1501
|
+
* const managedConfigs = await composio.authConfigs.list({
|
|
1502
|
+
* isComposioManaged: true
|
|
1503
|
+
* });
|
|
1504
|
+
* ```
|
|
1118
1505
|
*/
|
|
1119
1506
|
async list(query) {
|
|
1120
1507
|
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
@@ -1152,7 +1539,7 @@ var AuthConfigs = class {
|
|
|
1152
1539
|
*
|
|
1153
1540
|
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
1154
1541
|
*/
|
|
1155
|
-
async create(toolkit, options) {
|
|
1542
|
+
async create(toolkit, options = { type: "use_composio_managed_auth" }) {
|
|
1156
1543
|
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1157
1544
|
if (parsedOptions.error) {
|
|
1158
1545
|
throw new ValidationError(parsedOptions.error);
|
|
@@ -1175,21 +1562,57 @@ var AuthConfigs = class {
|
|
|
1175
1562
|
return parsedResult.data;
|
|
1176
1563
|
}
|
|
1177
1564
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1565
|
+
* Retrieves a specific authentication configuration by its ID.
|
|
1566
|
+
*
|
|
1567
|
+
* This method fetches detailed information about a single auth config
|
|
1568
|
+
* and transforms the response to the SDK's standardized format.
|
|
1569
|
+
*
|
|
1570
|
+
* @param {string} nanoid - The unique identifier of the auth config to retrieve
|
|
1571
|
+
* @returns {Promise<AuthConfigRetrieveResponse>} The auth config details
|
|
1572
|
+
* @throws {Error} If the auth config cannot be found or an API error occurs
|
|
1573
|
+
* @throws {ValidationError} If the response fails validation
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* // Get an auth config by ID
|
|
1578
|
+
* const authConfig = await composio.authConfigs.get('auth_abc123');
|
|
1579
|
+
* console.log(authConfig.name); // e.g., 'GitHub Auth'
|
|
1580
|
+
* console.log(authConfig.toolkit.slug); // e.g., 'github'
|
|
1581
|
+
* ```
|
|
1182
1582
|
*/
|
|
1183
1583
|
async get(nanoid) {
|
|
1184
1584
|
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1185
1585
|
return this.parseAuthConfigRetrieveResponse(result);
|
|
1186
1586
|
}
|
|
1187
1587
|
/**
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1588
|
+
* Updates an existing authentication configuration.
|
|
1589
|
+
*
|
|
1590
|
+
* This method allows you to modify properties of an auth config such as credentials,
|
|
1591
|
+
* scopes, or tool restrictions. The update type (custom or default) determines which
|
|
1592
|
+
* fields can be updated.
|
|
1593
|
+
*
|
|
1594
|
+
* @param {string} nanoid - The unique identifier of the auth config to update
|
|
1595
|
+
* @param {AuthConfigUpdateParams} data - The data to update, which can be either custom or default type
|
|
1596
|
+
* @returns {Promise<AuthConfigUpdateResponse>} The updated auth config
|
|
1597
|
+
* @throws {ValidationError} If the update parameters are invalid
|
|
1598
|
+
* @throws {Error} If the auth config cannot be found or updated
|
|
1599
|
+
*
|
|
1600
|
+
* @example
|
|
1601
|
+
* ```typescript
|
|
1602
|
+
* // Update a custom auth config with new credentials
|
|
1603
|
+
* const updatedConfig = await composio.authConfigs.update('auth_abc123', {
|
|
1604
|
+
* type: 'custom',
|
|
1605
|
+
* credentials: {
|
|
1606
|
+
* apiKey: 'new-api-key-value'
|
|
1607
|
+
* }
|
|
1608
|
+
* });
|
|
1609
|
+
*
|
|
1610
|
+
* // Update a default auth config with new scopes
|
|
1611
|
+
* const updatedConfig = await composio.authConfigs.update('auth_abc123', {
|
|
1612
|
+
* type: 'default',
|
|
1613
|
+
* scopes: ['read:user', 'repo']
|
|
1614
|
+
* });
|
|
1615
|
+
* ```
|
|
1193
1616
|
*/
|
|
1194
1617
|
async update(nanoid, data) {
|
|
1195
1618
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
@@ -1210,38 +1633,85 @@ var AuthConfigs = class {
|
|
|
1210
1633
|
);
|
|
1211
1634
|
}
|
|
1212
1635
|
/**
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1636
|
+
* Deletes an authentication configuration.
|
|
1637
|
+
*
|
|
1638
|
+
* This method permanently removes an auth config from the Composio platform.
|
|
1639
|
+
* This action cannot be undone and will prevent any connected accounts that use
|
|
1640
|
+
* this auth config from functioning.
|
|
1641
|
+
*
|
|
1642
|
+
* @param {string} nanoid - The unique identifier of the auth config to delete
|
|
1643
|
+
* @returns {Promise<AuthConfigDeleteResponse>} The deletion response
|
|
1644
|
+
* @throws {Error} If the auth config doesn't exist or cannot be deleted
|
|
1645
|
+
*
|
|
1646
|
+
* @example
|
|
1647
|
+
* ```typescript
|
|
1648
|
+
* // Delete an auth config
|
|
1649
|
+
* await composio.authConfigs.delete('auth_abc123');
|
|
1650
|
+
* ```
|
|
1217
1651
|
*/
|
|
1218
1652
|
async delete(nanoid) {
|
|
1219
1653
|
return this.client.authConfigs.delete(nanoid);
|
|
1220
1654
|
}
|
|
1221
1655
|
/**
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1656
|
+
* Updates the status of an authentication configuration.
|
|
1657
|
+
*
|
|
1658
|
+
* This method allows you to enable or disable an auth config. When disabled,
|
|
1659
|
+
* the auth config cannot be used to create new connected accounts or authenticate
|
|
1660
|
+
* with third-party services.
|
|
1661
|
+
*
|
|
1662
|
+
* @param {string} status - The status to set ('ENABLED' or 'DISABLED')
|
|
1663
|
+
* @param {string} nanoid - The unique identifier of the auth config
|
|
1664
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1665
|
+
* @throws {Error} If the auth config cannot be found or the status cannot be updated
|
|
1666
|
+
*
|
|
1667
|
+
* @example
|
|
1668
|
+
* ```typescript
|
|
1669
|
+
* // Disable an auth config
|
|
1670
|
+
* await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
|
|
1671
|
+
*
|
|
1672
|
+
* // Enable an auth config
|
|
1673
|
+
* await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
|
|
1674
|
+
* ```
|
|
1227
1675
|
*/
|
|
1228
1676
|
async updateStatus(status, nanoid) {
|
|
1229
1677
|
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
1230
1678
|
}
|
|
1231
1679
|
/**
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1680
|
+
* Enables an authentication configuration.
|
|
1681
|
+
*
|
|
1682
|
+
* This is a convenience method that calls updateStatus with 'ENABLED'.
|
|
1683
|
+
* When enabled, the auth config can be used to create new connected accounts
|
|
1684
|
+
* and authenticate with third-party services.
|
|
1685
|
+
*
|
|
1686
|
+
* @param {string} nanoid - The unique identifier of the auth config to enable
|
|
1687
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1688
|
+
* @throws {Error} If the auth config cannot be found or enabled
|
|
1689
|
+
*
|
|
1690
|
+
* @example
|
|
1691
|
+
* ```typescript
|
|
1692
|
+
* // Enable an auth config
|
|
1693
|
+
* await composio.authConfigs.enable('auth_abc123');
|
|
1694
|
+
* ```
|
|
1236
1695
|
*/
|
|
1237
1696
|
async enable(nanoid) {
|
|
1238
1697
|
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
1239
1698
|
}
|
|
1240
1699
|
/**
|
|
1241
|
-
*
|
|
1242
|
-
*
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1700
|
+
* Disables an authentication configuration.
|
|
1701
|
+
*
|
|
1702
|
+
* This is a convenience method that calls updateStatus with 'DISABLED'.
|
|
1703
|
+
* When disabled, the auth config cannot be used to create new connected accounts
|
|
1704
|
+
* or authenticate with third-party services, but existing connections may continue to work.
|
|
1705
|
+
*
|
|
1706
|
+
* @param {string} nanoid - The unique identifier of the auth config to disable
|
|
1707
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1708
|
+
* @throws {Error} If the auth config cannot be found or disabled
|
|
1709
|
+
*
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```typescript
|
|
1712
|
+
* // Disable an auth config
|
|
1713
|
+
* await composio.authConfigs.disable('auth_abc123');
|
|
1714
|
+
* ```
|
|
1245
1715
|
*/
|
|
1246
1716
|
async disable(nanoid) {
|
|
1247
1717
|
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
@@ -1291,7 +1761,7 @@ var CreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
|
1291
1761
|
}),
|
|
1292
1762
|
connection: import_zod5.z.object({
|
|
1293
1763
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1294
|
-
|
|
1764
|
+
callbackUrl: import_zod5.z.string().optional(),
|
|
1295
1765
|
userId: import_zod5.z.string().optional()
|
|
1296
1766
|
})
|
|
1297
1767
|
});
|
|
@@ -1301,12 +1771,12 @@ var DefaultCreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
|
1301
1771
|
}),
|
|
1302
1772
|
connection: import_zod5.z.object({
|
|
1303
1773
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1304
|
-
|
|
1774
|
+
callback_url: import_zod5.z.string().optional(),
|
|
1305
1775
|
user_id: import_zod5.z.string().optional()
|
|
1306
1776
|
})
|
|
1307
1777
|
});
|
|
1308
1778
|
var CreateConnectedAccountOptionsSchema = import_zod5.z.object({
|
|
1309
|
-
|
|
1779
|
+
callbackUrl: import_zod5.z.string().optional(),
|
|
1310
1780
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional()
|
|
1311
1781
|
});
|
|
1312
1782
|
var CreateConnectedAccountResponseSchema = import_zod5.z.object({
|
|
@@ -1355,7 +1825,7 @@ var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
|
1355
1825
|
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1356
1826
|
userId: import_zod5.z.string(),
|
|
1357
1827
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1358
|
-
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1828
|
+
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1359
1829
|
status: ConnectedAccountStatusSchema,
|
|
1360
1830
|
statusReason: import_zod5.z.string().nullable(),
|
|
1361
1831
|
toolkit: import_zod5.z.object({
|
|
@@ -1366,8 +1836,24 @@ var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
|
1366
1836
|
createdAt: import_zod5.z.string(),
|
|
1367
1837
|
updatedAt: import_zod5.z.string()
|
|
1368
1838
|
});
|
|
1839
|
+
var ConnectedAccountListParamsSchema = import_zod5.z.object({
|
|
1840
|
+
authConfigIds: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
|
|
1841
|
+
cursor: import_zod5.z.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
|
|
1842
|
+
labels: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The labels of the connected accounts"),
|
|
1843
|
+
limit: import_zod5.z.number().nullable().optional().describe("The limit of the connected accounts to return"),
|
|
1844
|
+
orderBy: import_zod5.z.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
|
|
1845
|
+
statuses: import_zod5.z.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
|
|
1846
|
+
toolkitSlugs: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
|
|
1847
|
+
userIds: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The user ids of the connected accounts")
|
|
1848
|
+
});
|
|
1849
|
+
var ConnectedAccountListResponseSchema = import_zod5.z.object({
|
|
1850
|
+
items: import_zod5.z.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
|
|
1851
|
+
nextCursor: import_zod5.z.string().nullable().describe("The next cursor to paginate through the connected accounts"),
|
|
1852
|
+
totalPages: import_zod5.z.number().describe("The total number of pages of connected accounts")
|
|
1853
|
+
});
|
|
1369
1854
|
|
|
1370
1855
|
// src/models/ConnectionRequest.ts
|
|
1856
|
+
var import_client = __toESM(require("@composio/client"), 1);
|
|
1371
1857
|
var import_zod6 = require("zod");
|
|
1372
1858
|
|
|
1373
1859
|
// src/errors/ConnectionRequestError.ts
|
|
@@ -1397,19 +1883,27 @@ var ConnectionRequestFailedError = class extends ComposioError {
|
|
|
1397
1883
|
// src/models/ConnectionRequest.ts
|
|
1398
1884
|
var ConnectionRequest = class {
|
|
1399
1885
|
client;
|
|
1400
|
-
|
|
1401
|
-
|
|
1886
|
+
id;
|
|
1887
|
+
status;
|
|
1402
1888
|
redirectUrl;
|
|
1403
|
-
constructor(client, connectedAccountId,
|
|
1889
|
+
constructor(client, connectedAccountId, status, redirectUrl) {
|
|
1404
1890
|
this.client = client;
|
|
1405
|
-
this.
|
|
1406
|
-
this.
|
|
1891
|
+
this.id = connectedAccountId;
|
|
1892
|
+
this.status = status || ConnectedAccountStatuses.INITIATED;
|
|
1407
1893
|
this.redirectUrl = redirectUrl;
|
|
1894
|
+
telemetry.instrument(this);
|
|
1408
1895
|
}
|
|
1409
1896
|
/**
|
|
1410
|
-
*
|
|
1411
|
-
*
|
|
1412
|
-
*
|
|
1897
|
+
* Transforms the raw connected account response from the Composio API to the SDK format.
|
|
1898
|
+
*
|
|
1899
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
1900
|
+
* the data structure to match the SDK's standardized format.
|
|
1901
|
+
*
|
|
1902
|
+
* @param {OriginalConnectedAccountResponse} response - The raw API response to transform
|
|
1903
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The transformed response
|
|
1904
|
+
* @throws {ZodError} If the response fails validation against the expected schema
|
|
1905
|
+
*
|
|
1906
|
+
* @private
|
|
1413
1907
|
*/
|
|
1414
1908
|
async transformResponse(response) {
|
|
1415
1909
|
try {
|
|
@@ -1439,15 +1933,49 @@ var ConnectionRequest = class {
|
|
|
1439
1933
|
}
|
|
1440
1934
|
}
|
|
1441
1935
|
/**
|
|
1442
|
-
*
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
1936
|
+
* Waits for the connection request to complete and become active.
|
|
1937
|
+
*
|
|
1938
|
+
* This method continuously polls the Composio API to check the status of the connection request
|
|
1939
|
+
* until it either becomes active, enters a terminal error state, or times out.
|
|
1940
|
+
*
|
|
1941
|
+
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds before timing out (default: 60 seconds)
|
|
1942
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The final connected account response when successful
|
|
1943
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
|
|
1944
|
+
* @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
|
|
1945
|
+
* @throws {ConnectionRequestTimeoutError} If the connection request does not complete within the timeout period
|
|
1946
|
+
*
|
|
1947
|
+
* @example
|
|
1948
|
+
* ```typescript
|
|
1949
|
+
* // Wait for connection with default timeout (60 seconds)
|
|
1950
|
+
* try {
|
|
1951
|
+
* const connection = await connectionRequest.waitForConnection();
|
|
1952
|
+
* console.log('Connection established:', connection.id);
|
|
1953
|
+
* } catch (error) {
|
|
1954
|
+
* console.error('Connection failed:', error.message);
|
|
1955
|
+
* }
|
|
1956
|
+
*
|
|
1957
|
+
* // Wait for connection with custom timeout (2 minutes)
|
|
1958
|
+
* const connection = await connectionRequest.waitForConnection(120000);
|
|
1959
|
+
* ```
|
|
1446
1960
|
*/
|
|
1447
1961
|
async waitForConnection(timeout = 6e4) {
|
|
1448
|
-
|
|
1449
|
-
const response = await this.client.connectedAccounts.retrieve(this.
|
|
1450
|
-
|
|
1962
|
+
try {
|
|
1963
|
+
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
1964
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1965
|
+
this.status = ConnectedAccountStatuses.ACTIVE;
|
|
1966
|
+
return this.transformResponse(response);
|
|
1967
|
+
}
|
|
1968
|
+
} catch (error) {
|
|
1969
|
+
if (error instanceof import_client.default.NotFoundError) {
|
|
1970
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
1971
|
+
`Connected account with id ${this.id} not found`,
|
|
1972
|
+
{
|
|
1973
|
+
connectedAccountId: this.id
|
|
1974
|
+
}
|
|
1975
|
+
);
|
|
1976
|
+
} else {
|
|
1977
|
+
throw error;
|
|
1978
|
+
}
|
|
1451
1979
|
}
|
|
1452
1980
|
const terminalErrorStates = [
|
|
1453
1981
|
ConnectedAccountStatuses.FAILED,
|
|
@@ -1458,7 +1986,8 @@ var ConnectionRequest = class {
|
|
|
1458
1986
|
const pollInterval = 1e3;
|
|
1459
1987
|
while (Date.now() - start < timeout) {
|
|
1460
1988
|
try {
|
|
1461
|
-
const response = await this.client.connectedAccounts.retrieve(this.
|
|
1989
|
+
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
1990
|
+
this.status = response.status;
|
|
1462
1991
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1463
1992
|
return this.transformResponse(response);
|
|
1464
1993
|
}
|
|
@@ -1467,7 +1996,7 @@ var ConnectionRequest = class {
|
|
|
1467
1996
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1468
1997
|
{
|
|
1469
1998
|
userId: response.user_id,
|
|
1470
|
-
connectedAccountId: this.
|
|
1999
|
+
connectedAccountId: this.id,
|
|
1471
2000
|
status: response.status,
|
|
1472
2001
|
statusReason: response.status_reason
|
|
1473
2002
|
}
|
|
@@ -1478,9 +2007,7 @@ var ConnectionRequest = class {
|
|
|
1478
2007
|
throw error;
|
|
1479
2008
|
}
|
|
1480
2009
|
}
|
|
1481
|
-
throw new ConnectionRequestTimeoutError(
|
|
1482
|
-
`Connection request timed out for ${this.connectedAccountId}`
|
|
1483
|
-
);
|
|
2010
|
+
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
1484
2011
|
}
|
|
1485
2012
|
};
|
|
1486
2013
|
|
|
@@ -1489,15 +2016,97 @@ var ConnectedAccounts = class {
|
|
|
1489
2016
|
client;
|
|
1490
2017
|
constructor(client) {
|
|
1491
2018
|
this.client = client;
|
|
2019
|
+
telemetry.instrument(this);
|
|
2020
|
+
}
|
|
2021
|
+
transformConnectedAccountRetrieveResponse(response) {
|
|
2022
|
+
const result = ConnectedAccountRetrieveResponseSchema.safeParse({
|
|
2023
|
+
...response,
|
|
2024
|
+
userId: response.user_id,
|
|
2025
|
+
// Add the missing userId property
|
|
2026
|
+
authConfig: {
|
|
2027
|
+
...response.auth_config,
|
|
2028
|
+
authScheme: response.auth_config.auth_scheme,
|
|
2029
|
+
isComposioManaged: response.auth_config.is_composio_managed,
|
|
2030
|
+
isDisabled: response.auth_config.is_disabled
|
|
2031
|
+
},
|
|
2032
|
+
statusReason: response.status_reason,
|
|
2033
|
+
isDisabled: response.is_disabled,
|
|
2034
|
+
createdAt: response.created_at,
|
|
2035
|
+
updatedAt: response.updated_at,
|
|
2036
|
+
testRequestEndpoint: response.test_request_endpoint
|
|
2037
|
+
});
|
|
2038
|
+
if (!result.success) {
|
|
2039
|
+
throw new ValidationError(result.error);
|
|
2040
|
+
}
|
|
2041
|
+
return result.data;
|
|
1492
2042
|
}
|
|
1493
2043
|
/**
|
|
1494
|
-
*
|
|
1495
|
-
*
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
2044
|
+
* Lists all connected accounts based on provided filter criteria.
|
|
2045
|
+
*
|
|
2046
|
+
* This method retrieves connected accounts from the Composio API with optional filtering.
|
|
2047
|
+
*
|
|
2048
|
+
* @param {ConnectedAccountListParams} [query] - Optional query parameters for filtering connected accounts
|
|
2049
|
+
* @returns {Promise<ConnectedAccountListResponse>} A paginated list of connected accounts
|
|
2050
|
+
* @throws {ValidationError} If the query fails validation against the expected schema
|
|
2051
|
+
* @example
|
|
2052
|
+
* ```typescript
|
|
2053
|
+
* // List all connected accounts
|
|
2054
|
+
* const allAccounts = await composio.connectedAccounts.list();
|
|
2055
|
+
*
|
|
2056
|
+
* // List accounts for a specific user
|
|
2057
|
+
* const userAccounts = await composio.connectedAccounts.list({
|
|
2058
|
+
* userIds: ['user123']
|
|
2059
|
+
* });
|
|
2060
|
+
*
|
|
2061
|
+
* // List accounts for a specific toolkit
|
|
2062
|
+
* const githubAccounts = await composio.connectedAccounts.list({
|
|
2063
|
+
* toolkitSlugs: ['github']
|
|
2064
|
+
* });
|
|
2065
|
+
* ```
|
|
1498
2066
|
*/
|
|
1499
2067
|
async list(query) {
|
|
1500
|
-
|
|
2068
|
+
let rawQuery = void 0;
|
|
2069
|
+
if (query) {
|
|
2070
|
+
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
2071
|
+
if (!parsedQuery.success) {
|
|
2072
|
+
throw new ValidationError(parsedQuery.error);
|
|
2073
|
+
}
|
|
2074
|
+
rawQuery = {
|
|
2075
|
+
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
2076
|
+
cursor: parsedQuery.data.cursor,
|
|
2077
|
+
labels: parsedQuery.data.labels,
|
|
2078
|
+
limit: parsedQuery.data.limit,
|
|
2079
|
+
order_by: parsedQuery.data.orderBy,
|
|
2080
|
+
statuses: parsedQuery.data.statuses,
|
|
2081
|
+
toolkit_slugs: parsedQuery.data.toolkitSlugs,
|
|
2082
|
+
user_ids: parsedQuery.data.userIds
|
|
2083
|
+
};
|
|
2084
|
+
}
|
|
2085
|
+
const result = await this.client.connectedAccounts.list(rawQuery);
|
|
2086
|
+
const parsedResponse = ConnectedAccountListResponseSchema.safeParse({
|
|
2087
|
+
items: result.items.map(this.transformConnectedAccountRetrieveResponse),
|
|
2088
|
+
nextCursor: result.next_cursor,
|
|
2089
|
+
totalPages: result.total_pages
|
|
2090
|
+
});
|
|
2091
|
+
if (!parsedResponse.success) {
|
|
2092
|
+
throw new ValidationError(parsedResponse.error);
|
|
2093
|
+
}
|
|
2094
|
+
return parsedResponse.data;
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Transforms connected account data from API format to SDK format.
|
|
2098
|
+
*
|
|
2099
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
2100
|
+
* the data structure to match the SDK's standardized format for connected accounts.
|
|
2101
|
+
*
|
|
2102
|
+
* @param {ConnectedAccountRetrieveResponseRaw} response - The raw API response to transform
|
|
2103
|
+
* @returns {ConnectedAccountRetrieveResponse} The transformed connected account data
|
|
2104
|
+
* @throws {ValidationError} If the response fails validation against the expected schema
|
|
2105
|
+
*
|
|
2106
|
+
* @private
|
|
2107
|
+
*/
|
|
2108
|
+
transformConnectedAccountResponse(response) {
|
|
2109
|
+
return this.transformConnectedAccountRetrieveResponse(response);
|
|
1501
2110
|
}
|
|
1502
2111
|
/**
|
|
1503
2112
|
* Compound function to create a new connected account.
|
|
@@ -1524,35 +2133,94 @@ var ConnectedAccounts = class {
|
|
|
1524
2133
|
},
|
|
1525
2134
|
connection: {
|
|
1526
2135
|
data: options?.data,
|
|
1527
|
-
|
|
2136
|
+
callback_url: options?.callbackUrl,
|
|
1528
2137
|
user_id: userId
|
|
1529
2138
|
}
|
|
1530
2139
|
});
|
|
1531
|
-
return new ConnectionRequest(this.client, response.id, response.status, response.
|
|
2140
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_url);
|
|
1532
2141
|
}
|
|
1533
2142
|
/**
|
|
1534
|
-
*
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
2143
|
+
* Waits for a connection request to complete and become active.
|
|
2144
|
+
*
|
|
2145
|
+
* This method continuously polls the Composio API to check the status of a connection
|
|
2146
|
+
* until it either becomes active, enters a terminal error state, or times out.
|
|
2147
|
+
*
|
|
2148
|
+
* @param {string} connectedAccountId - The ID of the connected account to wait for
|
|
2149
|
+
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds (default: 60 seconds)
|
|
2150
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The finalized connected account data
|
|
2151
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
|
|
2152
|
+
* @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
|
|
2153
|
+
* @throws {ConnectionRequestTimeoutError} If the connection does not complete within the timeout period
|
|
2154
|
+
*
|
|
2155
|
+
* @example
|
|
2156
|
+
* ```typescript
|
|
2157
|
+
* // Wait for a connection to complete with default timeout
|
|
2158
|
+
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc');
|
|
2159
|
+
*
|
|
2160
|
+
* // Wait with a custom timeout of 2 minutes
|
|
2161
|
+
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc', 120000);
|
|
2162
|
+
* ```
|
|
2163
|
+
*/
|
|
2164
|
+
async waitForConnection(connectedAccountId, timeout = 6e4) {
|
|
2165
|
+
const connectionRequest = new ConnectionRequest(this.client, connectedAccountId);
|
|
2166
|
+
return connectionRequest.waitForConnection(timeout);
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* Retrieves a specific connected account by its ID.
|
|
2170
|
+
*
|
|
2171
|
+
* This method fetches detailed information about a single connected account
|
|
2172
|
+
* and transforms the response to the SDK's standardized format.
|
|
2173
|
+
*
|
|
2174
|
+
* @param {string} nanoid - The unique identifier of the connected account
|
|
2175
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The connected account details
|
|
2176
|
+
* @throws {Error} If the connected account cannot be found or an API error occurs
|
|
2177
|
+
*
|
|
2178
|
+
* @example
|
|
2179
|
+
* ```typescript
|
|
2180
|
+
* // Get a connected account by ID
|
|
2181
|
+
* const account = await composio.connectedAccounts.get('conn_abc123');
|
|
2182
|
+
* console.log(account.status); // e.g., 'ACTIVE'
|
|
2183
|
+
* console.log(account.toolkit.slug); // e.g., 'github'
|
|
2184
|
+
* ```
|
|
1538
2185
|
*/
|
|
1539
2186
|
async get(nanoid) {
|
|
1540
|
-
|
|
2187
|
+
const response = await this.client.connectedAccounts.retrieve(nanoid);
|
|
2188
|
+
return this.transformConnectedAccountResponse(response);
|
|
1541
2189
|
}
|
|
1542
2190
|
/**
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1546
|
-
*
|
|
2191
|
+
* Deletes a connected account.
|
|
2192
|
+
*
|
|
2193
|
+
* This method permanently removes a connected account from the Composio platform.
|
|
2194
|
+
* This action cannot be undone and will revoke any access tokens associated with the account.
|
|
2195
|
+
*
|
|
2196
|
+
* @param {string} nanoid - The unique identifier of the connected account to delete
|
|
2197
|
+
* @returns {Promise<ConnectedAccountDeleteResponse>} The deletion response
|
|
2198
|
+
* @throws {Error} If the account doesn't exist or cannot be deleted
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* ```typescript
|
|
2202
|
+
* // Delete a connected account
|
|
2203
|
+
* await composio.connectedAccounts.delete('conn_abc123');
|
|
2204
|
+
* ```
|
|
1547
2205
|
*/
|
|
1548
2206
|
async delete(nanoid) {
|
|
1549
2207
|
return this.client.connectedAccounts.delete(nanoid);
|
|
1550
2208
|
}
|
|
1551
2209
|
/**
|
|
1552
|
-
*
|
|
1553
|
-
*
|
|
1554
|
-
*
|
|
1555
|
-
*
|
|
2210
|
+
* Refreshes a connected account's authentication credentials.
|
|
2211
|
+
*
|
|
2212
|
+
* This method attempts to refresh OAuth tokens or other credentials associated with
|
|
2213
|
+
* the connected account. This is useful when a token has expired or is about to expire.
|
|
2214
|
+
*
|
|
2215
|
+
* @param {string} nanoid - The unique identifier of the connected account to refresh
|
|
2216
|
+
* @returns {Promise<ConnectedAccountRefreshResponse>} The response containing the refreshed account details
|
|
2217
|
+
* @throws {Error} If the account doesn't exist or credentials cannot be refreshed
|
|
2218
|
+
*
|
|
2219
|
+
* @example
|
|
2220
|
+
* ```typescript
|
|
2221
|
+
* // Refresh a connected account's credentials
|
|
2222
|
+
* const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
|
|
2223
|
+
* ```
|
|
1556
2224
|
*/
|
|
1557
2225
|
async refresh(nanoid) {
|
|
1558
2226
|
return this.client.connectedAccounts.refresh(nanoid);
|
|
@@ -1593,11 +2261,18 @@ var Toolkits = class {
|
|
|
1593
2261
|
constructor(client) {
|
|
1594
2262
|
this.client = client;
|
|
1595
2263
|
this.authorize = this.authorize.bind(this);
|
|
2264
|
+
telemetry.instrument(this);
|
|
1596
2265
|
}
|
|
1597
2266
|
/**
|
|
1598
|
-
*
|
|
1599
|
-
*
|
|
1600
|
-
*
|
|
2267
|
+
* Retrieves a list of toolkits based on the provided query parameters.
|
|
2268
|
+
*
|
|
2269
|
+
* This method fetches toolkits from the Composio API and transforms the response
|
|
2270
|
+
* from snake_case to camelCase format for consistency with JavaScript/TypeScript conventions.
|
|
2271
|
+
*
|
|
2272
|
+
* @param {ToolkitListParams} query - The query parameters to filter toolkits
|
|
2273
|
+
* @returns {Promise<ToolKitListResponse>} The transformed list of toolkits
|
|
2274
|
+
*
|
|
2275
|
+
* @private
|
|
1601
2276
|
*/
|
|
1602
2277
|
async getToolkits(query) {
|
|
1603
2278
|
const parsedQuery = ToolkitsListParamsSchema.parse(query);
|
|
@@ -1626,11 +2301,29 @@ var Toolkits = class {
|
|
|
1626
2301
|
return parsedResult;
|
|
1627
2302
|
}
|
|
1628
2303
|
/**
|
|
1629
|
-
*
|
|
1630
|
-
*
|
|
1631
|
-
* @param
|
|
1632
|
-
* @
|
|
1633
|
-
|
|
2304
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
2305
|
+
*
|
|
2306
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
2307
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
2308
|
+
*/
|
|
2309
|
+
async get(arg) {
|
|
2310
|
+
if (typeof arg === "string") {
|
|
2311
|
+
return this.getToolkitBySlug(arg);
|
|
2312
|
+
}
|
|
2313
|
+
return this.getToolkits(arg);
|
|
2314
|
+
}
|
|
2315
|
+
/**
|
|
2316
|
+
* Retrieves a specific toolkit by its slug identifier.
|
|
2317
|
+
*
|
|
2318
|
+
* This method fetches a single toolkit from the Composio API and transforms
|
|
2319
|
+
* the response to use camelCase property naming consistent with JavaScript/TypeScript conventions.
|
|
2320
|
+
*
|
|
2321
|
+
* @param {string} slug - The unique slug identifier of the toolkit to retrieve
|
|
2322
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The transformed toolkit object
|
|
2323
|
+
* @throws {ValidationError} If the response cannot be properly parsed
|
|
2324
|
+
* @throws {ComposioToolNotFoundError} If no toolkit with the given slug exists
|
|
2325
|
+
*
|
|
2326
|
+
* @private
|
|
1634
2327
|
*/
|
|
1635
2328
|
async getToolkitBySlug(slug) {
|
|
1636
2329
|
try {
|
|
@@ -1671,21 +2364,19 @@ var Toolkits = class {
|
|
|
1671
2364
|
}
|
|
1672
2365
|
}
|
|
1673
2366
|
/**
|
|
1674
|
-
*
|
|
1675
|
-
* This method retrieves the toolkit from the Composio API.
|
|
1676
|
-
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
1677
|
-
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
1678
|
-
*/
|
|
1679
|
-
async get(arg) {
|
|
1680
|
-
if (typeof arg === "string") {
|
|
1681
|
-
return this.getToolkitBySlug(arg);
|
|
1682
|
-
}
|
|
1683
|
-
return this.getToolkits(arg);
|
|
1684
|
-
}
|
|
1685
|
-
/**
|
|
1686
|
-
* Fetches all categories available in the Composio SDK
|
|
2367
|
+
* Retrieves all toolkit categories available in the Composio SDK.
|
|
1687
2368
|
*
|
|
1688
|
-
*
|
|
2369
|
+
* This method fetches the complete list of categories from the Composio API
|
|
2370
|
+
* and transforms the response to use camelCase property naming.
|
|
2371
|
+
*
|
|
2372
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} The list of toolkit categories
|
|
2373
|
+
*
|
|
2374
|
+
* @example
|
|
2375
|
+
* ```typescript
|
|
2376
|
+
* // Get all toolkit categories
|
|
2377
|
+
* const categories = await composio.toolkits.listCategories();
|
|
2378
|
+
* console.log(categories.items); // Array of category objects
|
|
2379
|
+
* ```
|
|
1689
2380
|
*/
|
|
1690
2381
|
async listCategories() {
|
|
1691
2382
|
const result = await this.client.toolkits.retrieveCategories();
|
|
@@ -1707,8 +2398,12 @@ var Toolkits = class {
|
|
|
1707
2398
|
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
1708
2399
|
* @param {string} userId - The user id of the user to authorize
|
|
1709
2400
|
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
1710
|
-
* @param {string} authConfigId - The id of the auth config to use
|
|
1711
2401
|
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
2402
|
+
*
|
|
2403
|
+
* @example
|
|
2404
|
+
* ```typescript
|
|
2405
|
+
* const connectionRequest = await composio.toolkits.authorize(userId, 'github');
|
|
2406
|
+
* ```
|
|
1712
2407
|
*/
|
|
1713
2408
|
async authorize(userId, toolkitSlug) {
|
|
1714
2409
|
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
@@ -1832,6 +2527,7 @@ var Session = class {
|
|
|
1832
2527
|
client;
|
|
1833
2528
|
constructor(client) {
|
|
1834
2529
|
this.client = client;
|
|
2530
|
+
telemetry.instrument(this);
|
|
1835
2531
|
}
|
|
1836
2532
|
/**
|
|
1837
2533
|
* Get the active session info
|
|
@@ -1847,6 +2543,7 @@ var Triggers = class {
|
|
|
1847
2543
|
client;
|
|
1848
2544
|
constructor(client) {
|
|
1849
2545
|
this.client = client;
|
|
2546
|
+
telemetry.instrument(this);
|
|
1850
2547
|
}
|
|
1851
2548
|
/**
|
|
1852
2549
|
* Fetch list of all the active triggers
|
|
@@ -1978,235 +2675,6 @@ var Triggers = class {
|
|
|
1978
2675
|
}
|
|
1979
2676
|
};
|
|
1980
2677
|
|
|
1981
|
-
// src/types/telemetry.types.ts
|
|
1982
|
-
var TELEMETRY_EVENTS = {
|
|
1983
|
-
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
1984
|
-
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
1985
|
-
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
1986
|
-
CLI_INVOKED: "CLI_INVOKED"
|
|
1987
|
-
};
|
|
1988
|
-
|
|
1989
|
-
// src/utils/constants.ts
|
|
1990
|
-
var COMPOSIO_DIR = ".composio";
|
|
1991
|
-
var USER_DATA_FILE_NAME = "user_data.json";
|
|
1992
|
-
var DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
1993
|
-
var TELEMETRY_URL = "https://app.composio.dev";
|
|
1994
|
-
var IS_DEVELOPMENT_OR_CI = process.env.DEVELOPMENT || process.env.CI || false;
|
|
1995
|
-
|
|
1996
|
-
// src/telemetry/BatchProcessor.ts
|
|
1997
|
-
var BatchProcessor = class {
|
|
1998
|
-
batch = [];
|
|
1999
|
-
time;
|
|
2000
|
-
batchSize;
|
|
2001
|
-
processBatchCallback;
|
|
2002
|
-
timer = null;
|
|
2003
|
-
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
2004
|
-
this.batch = [];
|
|
2005
|
-
this.time = time;
|
|
2006
|
-
this.batchSize = batchSize;
|
|
2007
|
-
this.processBatchCallback = processBatchCallback;
|
|
2008
|
-
}
|
|
2009
|
-
pushItem(item) {
|
|
2010
|
-
this.batch.push(item);
|
|
2011
|
-
if (this.batch.length >= this.batchSize) {
|
|
2012
|
-
this.processBatch();
|
|
2013
|
-
} else if (!this.timer) {
|
|
2014
|
-
this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
processBatch() {
|
|
2018
|
-
if (this.batch.length > 0) {
|
|
2019
|
-
this.processBatchCallback(this.batch);
|
|
2020
|
-
this.batch = [];
|
|
2021
|
-
}
|
|
2022
|
-
if (this.timer) {
|
|
2023
|
-
clearTimeout(this.timer);
|
|
2024
|
-
this.timer = null;
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
|
|
2029
|
-
// src/telemetry/transports/BrowserTransport.ts
|
|
2030
|
-
var BrowserTelemetryTransport = class {
|
|
2031
|
-
send(payload) {
|
|
2032
|
-
if (typeof window === "undefined") {
|
|
2033
|
-
return Promise.reject(
|
|
2034
|
-
new Error("BrowserTelemetryTransport can only be used in browser environments")
|
|
2035
|
-
);
|
|
2036
|
-
}
|
|
2037
|
-
return new Promise((resolve) => {
|
|
2038
|
-
try {
|
|
2039
|
-
const xhr = new XMLHttpRequest();
|
|
2040
|
-
xhr.open(payload.method, payload.url, true);
|
|
2041
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
2042
|
-
Object.entries(payload.headers || {}).forEach(([key, value]) => {
|
|
2043
|
-
xhr.setRequestHeader(key, value);
|
|
2044
|
-
});
|
|
2045
|
-
xhr.onload = function() {
|
|
2046
|
-
resolve();
|
|
2047
|
-
};
|
|
2048
|
-
xhr.send(JSON.stringify(payload.data));
|
|
2049
|
-
} catch (error) {
|
|
2050
|
-
logger_default.error("Error sending error to telemetry", error);
|
|
2051
|
-
resolve();
|
|
2052
|
-
}
|
|
2053
|
-
});
|
|
2054
|
-
}
|
|
2055
|
-
};
|
|
2056
|
-
|
|
2057
|
-
// src/telemetry/transports/ProcessTransport.ts
|
|
2058
|
-
var ProcessTelemetryTransport = class {
|
|
2059
|
-
send(payload) {
|
|
2060
|
-
if (typeof window !== "undefined") {
|
|
2061
|
-
return Promise.reject(
|
|
2062
|
-
new Error("ProcessTelemetryTransport can only be used in Node.js environments")
|
|
2063
|
-
);
|
|
2064
|
-
}
|
|
2065
|
-
return new Promise((resolve) => {
|
|
2066
|
-
try {
|
|
2067
|
-
const url = new URL(payload.url);
|
|
2068
|
-
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
2069
|
-
const port = url.port || (url.protocol === "https:" ? 443 : 80);
|
|
2070
|
-
const args = [
|
|
2071
|
-
"-e",
|
|
2072
|
-
`
|
|
2073
|
-
const http = require('${protocol}');
|
|
2074
|
-
const options = {
|
|
2075
|
-
hostname: '${url.hostname}',
|
|
2076
|
-
path: '${url.pathname}${url.search}',
|
|
2077
|
-
port: ${port},
|
|
2078
|
-
method: '${payload.method}',
|
|
2079
|
-
headers: ${JSON.stringify(payload.headers)}
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
|
-
const req = http.request(options, (res) => {
|
|
2083
|
-
res.on('data', () => {});
|
|
2084
|
-
res.on('end', () => {
|
|
2085
|
-
process.exit(0);
|
|
2086
|
-
});
|
|
2087
|
-
});
|
|
2088
|
-
|
|
2089
|
-
req.on('error', () => {
|
|
2090
|
-
process.exit(0);
|
|
2091
|
-
});
|
|
2092
|
-
|
|
2093
|
-
req.write(JSON.stringify(${JSON.stringify(payload.data)}));
|
|
2094
|
-
req.end();
|
|
2095
|
-
`
|
|
2096
|
-
];
|
|
2097
|
-
import("child_process").then(({ spawn }) => {
|
|
2098
|
-
spawn("node", args, {
|
|
2099
|
-
stdio: "ignore",
|
|
2100
|
-
detached: true,
|
|
2101
|
-
shell: false
|
|
2102
|
-
}).unref();
|
|
2103
|
-
resolve();
|
|
2104
|
-
}).catch(() => {
|
|
2105
|
-
resolve();
|
|
2106
|
-
});
|
|
2107
|
-
} catch (error) {
|
|
2108
|
-
logger_default.error("Error sending telemetry", error);
|
|
2109
|
-
resolve();
|
|
2110
|
-
}
|
|
2111
|
-
});
|
|
2112
|
-
}
|
|
2113
|
-
};
|
|
2114
|
-
|
|
2115
|
-
// src/telemetry/Telemetry.ts
|
|
2116
|
-
var Telemetry = class {
|
|
2117
|
-
telemetryMetadata;
|
|
2118
|
-
transport;
|
|
2119
|
-
batchProcessor = new BatchProcessor(100, 10, async (data) => {
|
|
2120
|
-
await this.sendTelemetry(data);
|
|
2121
|
-
});
|
|
2122
|
-
constructor(metadata, transport) {
|
|
2123
|
-
this.telemetryMetadata = metadata;
|
|
2124
|
-
const isBrowser = typeof window !== "undefined";
|
|
2125
|
-
if (transport) {
|
|
2126
|
-
this.transport = transport;
|
|
2127
|
-
} else if (isBrowser) {
|
|
2128
|
-
this.transport = new BrowserTelemetryTransport();
|
|
2129
|
-
} else {
|
|
2130
|
-
this.transport = new ProcessTelemetryTransport();
|
|
2131
|
-
}
|
|
2132
|
-
this.sendTelemetry([
|
|
2133
|
-
{
|
|
2134
|
-
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
2135
|
-
data: {},
|
|
2136
|
-
sdk_meta: this.telemetryMetadata
|
|
2137
|
-
}
|
|
2138
|
-
]);
|
|
2139
|
-
}
|
|
2140
|
-
/**
|
|
2141
|
-
* Instrument the telemetry for the given instance.
|
|
2142
|
-
*
|
|
2143
|
-
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
2144
|
-
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
2145
|
-
* @param instance - any instance that extends InstrumentedInstance
|
|
2146
|
-
* @param fileName - the file name of the instance
|
|
2147
|
-
* @returns
|
|
2148
|
-
*/
|
|
2149
|
-
instrumentTelemetry(instance, fileName) {
|
|
2150
|
-
const proto = Object.getPrototypeOf(instance);
|
|
2151
|
-
const methodNames = Object.getOwnPropertyNames(proto).filter((key) => {
|
|
2152
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
2153
|
-
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
2154
|
-
});
|
|
2155
|
-
const instrumentedClassName = instance.constructor?.name || fileName || "unknown";
|
|
2156
|
-
for (const name of methodNames) {
|
|
2157
|
-
const originalMethod = instance[name];
|
|
2158
|
-
instance[name] = async (...args) => {
|
|
2159
|
-
const telemetryPayload = {
|
|
2160
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_INVOKED,
|
|
2161
|
-
data: {
|
|
2162
|
-
fileName: instrumentedClassName,
|
|
2163
|
-
method: name,
|
|
2164
|
-
params: args
|
|
2165
|
-
},
|
|
2166
|
-
sdk_meta: this.telemetryMetadata
|
|
2167
|
-
};
|
|
2168
|
-
this.batchProcessor.pushItem(telemetryPayload);
|
|
2169
|
-
try {
|
|
2170
|
-
return await originalMethod.apply(instance, args);
|
|
2171
|
-
} catch (error) {
|
|
2172
|
-
const telemetryPayload2 = {
|
|
2173
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_ERROR,
|
|
2174
|
-
data: {
|
|
2175
|
-
fileName: instrumentedClassName,
|
|
2176
|
-
method: name,
|
|
2177
|
-
params: args,
|
|
2178
|
-
error
|
|
2179
|
-
},
|
|
2180
|
-
sdk_meta: this.telemetryMetadata
|
|
2181
|
-
};
|
|
2182
|
-
this.batchProcessor.pushItem(telemetryPayload2);
|
|
2183
|
-
throw error;
|
|
2184
|
-
}
|
|
2185
|
-
};
|
|
2186
|
-
}
|
|
2187
|
-
return instance;
|
|
2188
|
-
}
|
|
2189
|
-
/**
|
|
2190
|
-
* Send the telemetry payload to the server.
|
|
2191
|
-
* @param payload - the telemetry payload to send
|
|
2192
|
-
* @returns
|
|
2193
|
-
*/
|
|
2194
|
-
async sendTelemetry(payload) {
|
|
2195
|
-
const isTelemetryDisabled = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
2196
|
-
if (isTelemetryDisabled) {
|
|
2197
|
-
return;
|
|
2198
|
-
}
|
|
2199
|
-
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
2200
|
-
const reqPayload = {
|
|
2201
|
-
data: payload,
|
|
2202
|
-
url,
|
|
2203
|
-
method: "POST",
|
|
2204
|
-
headers: { "Content-Type": "application/json" }
|
|
2205
|
-
};
|
|
2206
|
-
this.transport.send(reqPayload);
|
|
2207
|
-
}
|
|
2208
|
-
};
|
|
2209
|
-
|
|
2210
2678
|
// src/utils/sdk.ts
|
|
2211
2679
|
var userDataPath = () => {
|
|
2212
2680
|
try {
|
|
@@ -2235,23 +2703,22 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
2235
2703
|
}
|
|
2236
2704
|
|
|
2237
2705
|
// src/utils/version.ts
|
|
2238
|
-
|
|
2239
|
-
const v1 = version1.split(".").map(Number);
|
|
2240
|
-
const v2 = version2.split(".").map(Number);
|
|
2241
|
-
for (let i = 0; i < 3; i++) {
|
|
2242
|
-
if (v1[i] > v2[i]) return true;
|
|
2243
|
-
if (v1[i] < v2[i]) return false;
|
|
2244
|
-
}
|
|
2245
|
-
return false;
|
|
2246
|
-
}
|
|
2706
|
+
var import_semver = __toESM(require("semver"), 1);
|
|
2247
2707
|
async function checkForLatestVersionFromNPM(currentVersion) {
|
|
2248
2708
|
try {
|
|
2249
|
-
const packageName = "composio
|
|
2709
|
+
const packageName = "@composio/core";
|
|
2250
2710
|
const currentVersionFromPackageJson = currentVersion;
|
|
2711
|
+
if (!import_semver.default.valid(currentVersionFromPackageJson)) {
|
|
2712
|
+
return;
|
|
2713
|
+
}
|
|
2714
|
+
const prerelease = import_semver.default.prerelease(currentVersionFromPackageJson);
|
|
2715
|
+
if (prerelease && (String(prerelease[0]).includes("alpha") || String(prerelease[0]).includes("beta"))) {
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2251
2718
|
const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`);
|
|
2252
2719
|
const data = await response.json();
|
|
2253
2720
|
const latestVersion = data.version;
|
|
2254
|
-
if (
|
|
2721
|
+
if (import_semver.default.gt(latestVersion, currentVersionFromPackageJson) && !IS_DEVELOPMENT_OR_CI) {
|
|
2255
2722
|
logger_default.info(
|
|
2256
2723
|
`\u{1F680} Upgrade available! Your composio-core version (${currentVersionFromPackageJson}) is behind. Latest version: ${latestVersion}.`
|
|
2257
2724
|
);
|
|
@@ -2465,7 +2932,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2465
2932
|
};
|
|
2466
2933
|
|
|
2467
2934
|
// package.json
|
|
2468
|
-
var version = "0.1.
|
|
2935
|
+
var version = "0.1.12-alpha.10";
|
|
2469
2936
|
|
|
2470
2937
|
// src/utils/uuid.ts
|
|
2471
2938
|
var import_uuid = require("uuid");
|
|
@@ -2485,7 +2952,6 @@ var Composio = class {
|
|
|
2485
2952
|
* @type {ComposioConfig<TProvider>}
|
|
2486
2953
|
*/
|
|
2487
2954
|
config;
|
|
2488
|
-
telemetry;
|
|
2489
2955
|
/**
|
|
2490
2956
|
* Core models for Composio.
|
|
2491
2957
|
*/
|
|
@@ -2495,10 +2961,8 @@ var Composio = class {
|
|
|
2495
2961
|
provider;
|
|
2496
2962
|
// auth configs
|
|
2497
2963
|
authConfigs;
|
|
2498
|
-
createAuthConfig;
|
|
2499
2964
|
// connected accounts
|
|
2500
2965
|
connectedAccounts;
|
|
2501
|
-
initiateConnection;
|
|
2502
2966
|
/**
|
|
2503
2967
|
* @param {Object} config Configuration for the Composio SDK.
|
|
2504
2968
|
* @param {string} config.apiKey The API key for the Composio SDK.
|
|
@@ -2516,56 +2980,44 @@ var Composio = class {
|
|
|
2516
2980
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2517
2981
|
logger_default.info(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2518
2982
|
}
|
|
2519
|
-
this.client = new
|
|
2983
|
+
this.client = new import_client2.default({
|
|
2520
2984
|
apiKey: apiKeyParsed,
|
|
2521
2985
|
baseURL: baseURLParsed
|
|
2522
2986
|
});
|
|
2523
2987
|
this.config = {
|
|
2524
2988
|
...config,
|
|
2525
|
-
allowTracking: config.allowTracking ?? true
|
|
2989
|
+
allowTracking: config.allowTracking ?? true,
|
|
2990
|
+
allowTracing: config.allowTracing ?? true
|
|
2526
2991
|
};
|
|
2527
2992
|
this.provider = config.provider ?? new OpenAIProvider();
|
|
2528
2993
|
this.tools = new Tools(this.client, this.provider);
|
|
2529
|
-
this.provider._setExecuteToolFn(this.tools.execute);
|
|
2530
2994
|
this.toolkits = new Toolkits(this.client);
|
|
2531
2995
|
this.triggers = new Triggers(this.client);
|
|
2532
2996
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2533
|
-
this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
|
|
2534
2997
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
this.initializeTelemetry(
|
|
2998
|
+
if (this.config.allowTracking) {
|
|
2999
|
+
telemetry.setup(
|
|
2538
3000
|
{
|
|
2539
3001
|
apiKey: apiKeyParsed ?? "",
|
|
2540
3002
|
baseUrl: baseURLParsed ?? "",
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
3003
|
+
framework: this.provider?.name || "unknown",
|
|
3004
|
+
isAgentic: this.provider?._isAgentic || false,
|
|
3005
|
+
source: "javascript",
|
|
3006
|
+
version,
|
|
3007
|
+
sdkType: "Typescript-V3",
|
|
2545
3008
|
isBrowser: typeof window !== "undefined",
|
|
2546
|
-
|
|
3009
|
+
// @TODO: Users might want to pass their own session id
|
|
3010
|
+
// @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
|
|
3011
|
+
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
2547
3012
|
// @TODO: get the session id
|
|
2548
3013
|
},
|
|
2549
3014
|
config.telemetryTransport
|
|
2550
3015
|
);
|
|
2551
3016
|
}
|
|
3017
|
+
telemetry.instrument(this);
|
|
3018
|
+
telemetry.instrument(this.provider);
|
|
2552
3019
|
checkForLatestVersionFromNPM(version);
|
|
2553
3020
|
}
|
|
2554
|
-
/**
|
|
2555
|
-
* Initialize the instrumentations and telemetry for the Composio SDK.
|
|
2556
|
-
* @param {TelemetryMetadata} config - The configuration for the telemetry.
|
|
2557
|
-
* @param {BaseTelemetryTransport} transport - The transport for the telemetry.
|
|
2558
|
-
*/
|
|
2559
|
-
initializeTelemetry(config, transport) {
|
|
2560
|
-
this.telemetry = new Telemetry(config, transport);
|
|
2561
|
-
this.telemetry.instrumentTelemetry(this);
|
|
2562
|
-
this.telemetry.instrumentTelemetry(this.tools);
|
|
2563
|
-
this.telemetry.instrumentTelemetry(this.toolkits);
|
|
2564
|
-
this.telemetry.instrumentTelemetry(this.triggers);
|
|
2565
|
-
this.telemetry.instrumentTelemetry(this.authConfigs);
|
|
2566
|
-
this.telemetry.instrumentTelemetry(this.connectedAccounts);
|
|
2567
|
-
this.telemetry.instrumentTelemetry(this.provider);
|
|
2568
|
-
}
|
|
2569
3021
|
/**
|
|
2570
3022
|
* Get the Composio SDK client.
|
|
2571
3023
|
* @returns {ComposioClient} The Composio API client.
|
|
@@ -2576,24 +3028,6 @@ var Composio = class {
|
|
|
2576
3028
|
}
|
|
2577
3029
|
return this.client;
|
|
2578
3030
|
}
|
|
2579
|
-
/**
|
|
2580
|
-
* Fetch all the tools from Composio.
|
|
2581
|
-
* @param {ToolListParams} params Parameters to fetch the tools.
|
|
2582
|
-
* @param {ProviderOptions<TProvider>} modifiers Modifiers to apply to the tools.
|
|
2583
|
-
* @returns {Promise<ReturnType<TProvider['getTools']>>} The tools from the provider.
|
|
2584
|
-
*/
|
|
2585
|
-
getTools(userId, filters, modifiers) {
|
|
2586
|
-
return this.tools.get(userId, filters, modifiers);
|
|
2587
|
-
}
|
|
2588
|
-
/**
|
|
2589
|
-
* Fetch a tool from Composio by its slug.
|
|
2590
|
-
* @param {string} slug slug of the tool
|
|
2591
|
-
* @param {ProviderOptions<TProvider>} modifiers to be applied to the tool
|
|
2592
|
-
* @returns {Promise<ReturnType<TProvider['getToolBySlug']>>} The tool from the provider.
|
|
2593
|
-
*/
|
|
2594
|
-
getToolBySlug(userId, slug, modifiers) {
|
|
2595
|
-
return this.tools.get(userId, slug, modifiers);
|
|
2596
|
-
}
|
|
2597
3031
|
};
|
|
2598
3032
|
|
|
2599
3033
|
// src/provider/ComposioProvider.ts
|
|
@@ -2608,8 +3042,15 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
2608
3042
|
};
|
|
2609
3043
|
|
|
2610
3044
|
// src/telemetry/TelemetryTransport.ts
|
|
3045
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
2611
3046
|
var BaseTelemetryTransport = class {
|
|
2612
3047
|
};
|
|
3048
|
+
var ConsoleTelemetryTransport = class {
|
|
3049
|
+
send(payload) {
|
|
3050
|
+
logger_default.debug(import_chalk3.default.yellow("telemetry"), JSON.stringify(payload, null, 2));
|
|
3051
|
+
return Promise.resolve();
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
2613
3054
|
|
|
2614
3055
|
// src/utils/jsonSchema.ts
|
|
2615
3056
|
var import_zod8 = require("zod");
|
|
@@ -2728,6 +3169,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2728
3169
|
BaseTelemetryTransport,
|
|
2729
3170
|
Composio,
|
|
2730
3171
|
ComposioProvider,
|
|
3172
|
+
ConsoleTelemetryTransport,
|
|
2731
3173
|
OpenAIProvider,
|
|
2732
3174
|
ToolListParamsSchema,
|
|
2733
3175
|
jsonSchemaToModel
|