@composio/core 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseProvider-2__95v5V.d.cts +26875 -0
- package/dist/BaseProvider-D1UCDu8V.d.mts +26875 -0
- package/dist/FileToolModifier.utils.neutral-BN_L8usp.mjs +78 -0
- package/dist/FileToolModifier.utils.neutral-Bcl7LVf4.cjs +102 -0
- package/dist/Telemetry-Bn5VseVi.mjs +331 -0
- package/dist/Telemetry-DErMJqj0.cjs +337 -0
- package/dist/buffer-BFpVRahf.mjs +382 -0
- package/dist/buffer-CYf1Z6Sd.cjs +478 -0
- package/dist/composio-CFe2Q5BN.d.cts +6313 -0
- package/dist/composio-DtAsGWh4.d.mts +6313 -0
- package/dist/fileUtils.node-BJQeDcfa.cjs +233 -0
- package/dist/fileUtils.node-C6fQOgF0.mjs +220 -0
- package/dist/index.cjs +176 -399
- package/dist/index.d.cts +6 -33098
- package/dist/index.d.mts +6 -33098
- package/dist/index.mjs +85 -308
- package/dist/models/Files.node.cjs +6 -4
- package/dist/models/Files.node.d.cts +1 -1
- package/dist/models/Files.node.d.mts +1 -1
- package/dist/models/Files.node.mjs +4 -2
- package/dist/models/Files.workerd.cjs +1 -1
- package/dist/models/Files.workerd.mjs +1 -1
- package/dist/platform/node.cjs +6 -3
- package/dist/platform/node.d.cts +1 -1
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +6 -3
- package/dist/platform/workerd.d.cts +1 -1
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/{types-BaUqjuX3.d.mts → types-BF2OQZRP.d.cts} +8 -5
- package/dist/{types-BrsW5suw.d.cts → types-Cvt_yFsu.d.mts} +8 -5
- package/dist/types-Do-rlwX8.d.mts +13 -0
- package/dist/types-Ohe4pd-1.d.cts +13 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.cjs +10 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.cts +7 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +8 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.mjs +9 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.cjs +10 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.cts +7 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +8 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +9 -0
- package/dist/utils/modifiers/FileToolModifier.node.cjs +172 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.cts +21 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +21 -0
- package/dist/utils/modifiers/FileToolModifier.node.mjs +173 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.cjs +27 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.d.cts +20 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +20 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +27 -0
- package/generated/ably.ts +20 -0
- package/generated/accelo.ts +8 -0
- package/generated/acculynx.ts +17 -0
- package/generated/active_campaign.ts +30 -0
- package/generated/adobe.ts +8 -0
- package/generated/adyntel.ts +12 -0
- package/generated/aero_workflow.ts +8 -0
- package/generated/affinity.ts +29 -0
- package/generated/agencyzoom.ts +108 -0
- package/generated/ahrefs.ts +49 -0
- package/generated/airtable.ts +26 -0
- package/generated/alchemy.ts +16 -0
- package/generated/algolia.ts +39 -0
- package/generated/altoviz.ts +18 -0
- package/generated/amazon.ts +8 -0
- package/generated/amcards.ts +11 -0
- package/generated/amplitude.ts +25 -0
- package/generated/anthropic_administrator.ts +13 -0
- package/generated/apaleo.ts +38 -0
- package/generated/apollo.ts +40 -0
- package/generated/appdrag.ts +8 -0
- package/generated/appsflyer.ts +8 -0
- package/generated/asana.ts +95 -0
- package/generated/ashby.ts +8 -0
- package/generated/atlassian.ts +8 -0
- package/generated/attio.ts +20 -0
- package/generated/auth0.ts +8 -0
- package/generated/axonaut.ts +8 -0
- package/generated/bamboohr.ts +168 -0
- package/generated/bannerbear.ts +17 -0
- package/generated/baserow.ts +11 -0
- package/generated/battlenet.ts +8 -0
- package/generated/beeminder.ts +14 -0
- package/generated/bigmailer.ts +12 -0
- package/generated/bigml.ts +15 -0
- package/generated/bill.ts +218 -0
- package/generated/bitbucket.ts +25 -0
- package/generated/bitwarden.ts +8 -0
- package/generated/blackbaud.ts +8 -0
- package/generated/blackboard.ts +323 -0
- package/generated/boldsign.ts +8 -0
- package/generated/bolna.ts +24 -0
- package/generated/borneo.ts +162 -0
- package/generated/botbaba.ts +8 -0
- package/generated/box.ts +282 -0
- package/generated/braintree.ts +8 -0
- package/generated/brandfetch.ts +15 -0
- package/generated/breezy_hr.ts +8 -0
- package/generated/brevo.ts +28 -0
- package/generated/brex.ts +8 -0
- package/generated/brex_staging.ts +8 -0
- package/generated/brightpearl.ts +8 -0
- package/generated/brilliant_directories.ts +15 -0
- package/generated/browseai.ts +18 -0
- package/generated/browserbase_tool.ts +10 -0
- package/generated/browserhub.ts +8 -0
- package/generated/browserless.ts +16 -0
- package/generated/bubble.ts +8 -0
- package/generated/bugbug.ts +13 -0
- package/generated/builtwith.ts +21 -0
- package/generated/cal.ts +150 -0
- package/generated/calendly.ts +51 -0
- package/generated/canva.ts +41 -0
- package/generated/canvas.ts +100 -0
- package/generated/chatwork.ts +17 -0
- package/generated/chmeetings.ts +8 -0
- package/generated/clickup.ts +153 -0
- package/generated/clockify.ts +23 -0
- package/generated/close.ts +15 -0
- package/generated/cloudflare.ts +10 -0
- package/generated/coda.ts +115 -0
- package/generated/codeinterpreter.ts +14 -0
- package/generated/coinbase.ts +15 -0
- package/generated/coinmarketcal.ts +8 -0
- package/generated/composio.ts +34 -0
- package/generated/composio_search.ts +22 -0
- package/generated/confluence.ts +199 -0
- package/generated/contentful.ts +12 -0
- package/generated/crustdata.ts +23 -0
- package/generated/customer_io.ts +8 -0
- package/generated/cutt_ly.ts +10 -0
- package/generated/d2lbrightspace.ts +54 -0
- package/generated/dailybot.ts +15 -0
- package/generated/datadog.ts +47 -0
- package/generated/datagma.ts +8 -0
- package/generated/datarobot.ts +8 -0
- package/generated/deel.ts +8 -0
- package/generated/demio.ts +8 -0
- package/generated/dialpad.ts +201 -0
- package/generated/digicert.ts +15 -0
- package/generated/discord.ts +17 -0
- package/generated/discordbot.ts +173 -0
- package/generated/docmosis.ts +8 -0
- package/generated/docusign.ts +351 -0
- package/generated/dropbox.ts +20 -0
- package/generated/dropbox_sign.ts +8 -0
- package/generated/dynamics365.ts +25 -0
- package/generated/echtpost.ts +10 -0
- package/generated/elevenlabs.ts +70 -0
- package/generated/emailoctopus.ts +16 -0
- package/generated/enigma.ts +11 -0
- package/generated/entelligence.ts +11 -0
- package/generated/epic_games.ts +8 -0
- package/generated/eventbrite.ts +12 -0
- package/generated/exa.ts +13 -0
- package/generated/excel.ts +34 -0
- package/generated/exist.ts +8 -0
- package/generated/facebook.ts +8 -0
- package/generated/factorial.ts +8 -0
- package/generated/figma.ts +59 -0
- package/generated/finage.ts +19 -0
- package/generated/firecrawl.ts +16 -0
- package/generated/fireflies.ts +21 -0
- package/generated/fitbit.ts +8 -0
- package/generated/flutterwave.ts +33 -0
- package/generated/fomo.ts +10 -0
- package/generated/formcarry.ts +10 -0
- package/generated/formsite.ts +14 -0
- package/generated/foursquare.ts +14 -0
- package/generated/freshbooks.ts +11 -0
- package/generated/freshdesk.ts +16 -0
- package/generated/front.ts +8 -0
- package/generated/github.ts +967 -0
- package/generated/gitlab.ts +82 -0
- package/generated/gmail.d.ts +86 -0
- package/generated/gmail.js +13 -0
- package/generated/gmail.ts +95 -0
- package/generated/go_to_webinar.ts +8 -0
- package/generated/gong.ts +63 -0
- package/generated/google_analytics.ts +13 -0
- package/generated/google_maps.ts +16 -0
- package/generated/googleads.ts +14 -0
- package/generated/googlebigquery.ts +10 -0
- package/generated/googlecalendar.ts +39 -0
- package/generated/googledocs.ts +41 -0
- package/generated/googledrive.ts +62 -0
- package/generated/googlemeet.ts +18 -0
- package/generated/googlephotos.ts +22 -0
- package/generated/googlesheets.ts +40 -0
- package/generated/googleslides.ts +8 -0
- package/generated/googlesuper.ts +230 -0
- package/generated/googletasks.ts +23 -0
- package/generated/gorgias.ts +41 -0
- package/generated/gumroad.ts +14 -0
- package/generated/guru.ts +8 -0
- package/generated/hackernews.ts +15 -0
- package/generated/hackerrank_work.ts +8 -0
- package/generated/harvest.ts +56 -0
- package/generated/helcim.ts +8 -0
- package/generated/heygen.ts +44 -0
- package/generated/highlevel.ts +8 -0
- package/generated/hubspot.ts +252 -0
- package/generated/humanloop.ts +13 -0
- package/generated/icims_talent_cloud.ts +8 -0
- package/generated/idea_scale.ts +8 -0
- package/generated/index.ts +151 -0
- package/generated/insighto_ai.ts +19 -0
- package/generated/intercom.ts +52 -0
- package/generated/interzoid.ts +8 -0
- package/generated/jira.ts +59 -0
- package/generated/jotform.ts +15 -0
- package/generated/junglescout.ts +15 -0
- package/generated/keap.ts +8 -0
- package/generated/kibana.ts +58 -0
- package/generated/kit.ts +38 -0
- package/generated/klaviyo.ts +240 -0
- package/generated/klipfolio.ts +20 -0
- package/generated/kommo.ts +24 -0
- package/generated/lastpass.ts +8 -0
- package/generated/launch_darkly.ts +16 -0
- package/generated/leadfeeder.ts +13 -0
- package/generated/leadoku.ts +10 -0
- package/generated/lever.ts +8 -0
- package/generated/lever_sandbox.ts +8 -0
- package/generated/lexoffice.ts +8 -0
- package/generated/linear.ts +31 -0
- package/generated/linkedin.ts +13 -0
- package/generated/linkhut.ts +14 -0
- package/generated/linkup.ts +11 -0
- package/generated/listennotes.ts +35 -0
- package/generated/lmnt.ts +16 -0
- package/generated/lodgify.ts +10 -0
- package/generated/mailchimp.ts +285 -0
- package/generated/mailerlite.ts +8 -0
- package/generated/maintainx.ts +20 -0
- package/generated/make.ts +12 -0
- package/generated/mboum.ts +8 -0
- package/generated/mem0.ts +52 -0
- package/generated/metaads.ts +25 -0
- package/generated/metatextai.ts +8 -0
- package/generated/microsoft_clarity.ts +10 -0
- package/generated/microsoft_teams.ts +22 -0
- package/generated/microsoft_tenant.ts +8 -0
- package/generated/miro.ts +23 -0
- package/generated/mixpanel.ts +30 -0
- package/generated/mocean.ts +8 -0
- package/generated/monday.ts +30 -0
- package/generated/mopinion.ts +8 -0
- package/generated/more_trees.ts +10 -0
- package/generated/moxie.ts +8 -0
- package/generated/moz.ts +8 -0
- package/generated/mural.ts +14 -0
- package/generated/nasdaq.ts +15 -0
- package/generated/ncscale.ts +8 -0
- package/generated/neon.ts +78 -0
- package/generated/netsuite.ts +8 -0
- package/generated/nextdns.ts +11 -0
- package/generated/ngrok.ts +18 -0
- package/generated/notion.ts +40 -0
- package/generated/oncehub.ts +8 -0
- package/generated/one_drive.ts +49 -0
- package/generated/onepage.ts +11 -0
- package/generated/open_sea.ts +33 -0
- package/generated/outlook.ts +37 -0
- package/generated/pagerduty.ts +362 -0
- package/generated/pandadoc.ts +23 -0
- package/generated/peopledatalabs.ts +24 -0
- package/generated/perplexityai.ts +10 -0
- package/generated/piggy.ts +8 -0
- package/generated/pipedrive.ts +288 -0
- package/generated/placekey.ts +12 -0
- package/generated/posthog.ts +367 -0
- package/generated/precoro.ts +8 -0
- package/generated/printnode.ts +8 -0
- package/generated/process_street.ts +14 -0
- package/generated/productboard.ts +8 -0
- package/generated/qualaroo.ts +8 -0
- package/generated/quickbooks.ts +22 -0
- package/generated/rafflys.ts +8 -0
- package/generated/ragic.ts +10 -0
- package/generated/ramp.ts +17 -0
- package/generated/ravenseotools.ts +8 -0
- package/generated/recallai.ts +17 -0
- package/generated/reddit.ts +19 -0
- package/generated/resend.ts +27 -0
- package/generated/retellai.ts +19 -0
- package/generated/retently.ts +24 -0
- package/generated/ring_central.ts +8 -0
- package/generated/rippling.ts +8 -0
- package/generated/rocket_reach.ts +8 -0
- package/generated/rocketlane.ts +42 -0
- package/generated/rootly.ts +12 -0
- package/generated/rosette_text_analytics.ts +12 -0
- package/generated/sage.ts +8 -0
- package/generated/salesforce.ts +46 -0
- package/generated/scrape_do.ts +28 -0
- package/generated/scrapingant.ts +14 -0
- package/generated/screenshotone.ts +10 -0
- package/generated/seismic.ts +8 -0
- package/generated/semanticscholar.ts +23 -0
- package/generated/semrush.ts +45 -0
- package/generated/sendgrid.ts +384 -0
- package/generated/sentry.ts +185 -0
- package/generated/serpapi.ts +32 -0
- package/generated/servicem8.ts +37 -0
- package/generated/servicenow.ts +14 -0
- package/generated/share_point.ts +15 -0
- package/generated/shopify.ts +37 -0
- package/generated/shortcut.ts +131 -0
- package/generated/simplesat.ts +11 -0
- package/generated/slack.d.ts +16 -0
- package/generated/slack.js +11 -0
- package/generated/slack.ts +24 -0
- package/generated/slackbot.ts +205 -0
- package/generated/smartrecruiters.ts +8 -0
- package/generated/smugmug.ts +14 -0
- package/generated/snowflake.ts +15 -0
- package/generated/sourcegraph.ts +16 -0
- package/generated/square.ts +8 -0
- package/generated/stack_exchange.ts +17 -0
- package/generated/starton.ts +11 -0
- package/generated/storeganise.ts +12 -0
- package/generated/stripe.ts +50 -0
- package/generated/supabase.ts +86 -0
- package/generated/survey_monkey.ts +8 -0
- package/generated/tally.ts +25 -0
- package/generated/tapfiliate.ts +11 -0
- package/generated/tapform.ts +8 -0
- package/generated/tavily.ts +10 -0
- package/generated/terminus.ts +8 -0
- package/generated/text_to_pdf.ts +10 -0
- package/generated/textrazor.ts +22 -0
- package/generated/timecamp.ts +10 -0
- package/generated/timekit.ts +8 -0
- package/generated/timely.ts +11 -0
- package/generated/tinypng.ts +15 -0
- package/generated/tinyurl.ts +10 -0
- package/generated/tisane.ts +15 -0
- package/generated/todoist.ts +19 -0
- package/generated/toneden.ts +8 -0
- package/generated/tpscheck.ts +10 -0
- package/generated/trello.ts +360 -0
- package/generated/twitch.ts +8 -0
- package/generated/twitter.ts +82 -0
- package/generated/twitter_media.ts +10 -0
- package/generated/typefully.ts +14 -0
- package/generated/venly.ts +8 -0
- package/generated/vero.ts +8 -0
- package/generated/visme.ts +8 -0
- package/generated/waboxapp.ts +8 -0
- package/generated/wakatime.ts +8 -0
- package/generated/wave_accounting.ts +8 -0
- package/generated/weathermap.ts +10 -0
- package/generated/webex.ts +37 -0
- package/generated/webflow.ts +30 -0
- package/generated/whatsapp.ts +14 -0
- package/generated/wiz.ts +8 -0
- package/generated/workiom.ts +12 -0
- package/generated/wrike.ts +47 -0
- package/generated/xero.ts +13 -0
- package/generated/yandex.ts +13 -0
- package/generated/ynab.ts +8 -0
- package/generated/yousearch.ts +10 -0
- package/generated/youtube.ts +26 -0
- package/generated/zendesk.ts +23 -0
- package/generated/zenrows.ts +25 -0
- package/generated/zenserp.ts +20 -0
- package/generated/zoho.ts +33 -0
- package/generated/zoho_bigin.ts +21 -0
- package/generated/zoho_books.ts +8 -0
- package/generated/zoho_desk.ts +8 -0
- package/generated/zoho_inventory.ts +8 -0
- package/generated/zoho_invoice.ts +15 -0
- package/generated/zoho_mail.ts +8 -0
- package/generated/zoom.ts +181 -0
- package/generated/zoominfo.ts +26 -0
- package/package.json +26 -2
- package/src/platform/index.ts +1 -1
- package/src/platform/node.ts +17 -9
- package/src/platform/types.ts +9 -5
- package/src/platform/workerd.ts +7 -3
- package/dist/fileUtils-BbE-aKW0.cjs +0 -983
- package/dist/fileUtils-BxTR8M_c.mjs +0 -904
- /package/dist/{chunk-0j-ceAHr.mjs → chunk-Dx2NuYGI.mjs} +0 -0
- /package/dist/{files.types-B7P5A1Z5.d.mts → files.types-BDqIUdfP.d.mts} +0 -0
- /package/dist/{files.types-D-RzIOHq.d.cts → files.types-nK6eTNnc.d.cts} +0 -0
|
@@ -1,904 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-0j-ceAHr.mjs";
|
|
2
|
-
import { BadRequestError, ComposioError } from "@composio/client";
|
|
3
|
-
import { ZodError } from "zod/v3";
|
|
4
|
-
import chalk from "chalk";
|
|
5
|
-
import crypto from "node:crypto";
|
|
6
|
-
import { platform } from "#platform";
|
|
7
|
-
|
|
8
|
-
//#region src/utils/env.ts
|
|
9
|
-
const getEnvVariable = (name, defaultValue = void 0) => {
|
|
10
|
-
try {
|
|
11
|
-
return process.env[name] || defaultValue;
|
|
12
|
-
} catch (_e) {
|
|
13
|
-
return defaultValue;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Method to return all the envs based on a specific prefix
|
|
18
|
-
* @param prefix
|
|
19
|
-
* @example
|
|
20
|
-
* COMPOSIO_TOOLKIT_VERSION_GITHUB=20250902_00
|
|
21
|
-
* COMPOSIO_TOOLKIT_VERSION_SLACK=20250902_00
|
|
22
|
-
* COMPOSIO_TOOLKIT_VERSION_GMAIL=latest
|
|
23
|
-
* @returns {Record<string, unknown>}
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
const getEnvsWithPrefix = (prefix) => {
|
|
27
|
-
try {
|
|
28
|
-
if (process && process.env) return Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith(prefix)));
|
|
29
|
-
else return {};
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/utils/constants.ts
|
|
37
|
-
var constants_exports = /* @__PURE__ */ __exportAll({
|
|
38
|
-
CLIENT_PUSHER_KEY: () => CLIENT_PUSHER_KEY,
|
|
39
|
-
COMPOSIO_DIR: () => COMPOSIO_DIR,
|
|
40
|
-
COMPOSIO_LOG_LEVEL: () => COMPOSIO_LOG_LEVEL,
|
|
41
|
-
DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
|
|
42
|
-
DEFAULT_WEB_URL: () => DEFAULT_WEB_URL,
|
|
43
|
-
IS_DEVELOPMENT_OR_CI: () => IS_DEVELOPMENT_OR_CI,
|
|
44
|
-
TELEMETRY_URL: () => TELEMETRY_URL$1,
|
|
45
|
-
TEMP_FILES_DIRECTORY_NAME: () => TEMP_FILES_DIRECTORY_NAME,
|
|
46
|
-
USER_DATA_FILE_NAME: () => USER_DATA_FILE_NAME
|
|
47
|
-
});
|
|
48
|
-
const COMPOSIO_DIR = ".composio";
|
|
49
|
-
const USER_DATA_FILE_NAME = "user_data.json";
|
|
50
|
-
const TEMP_FILES_DIRECTORY_NAME = "files";
|
|
51
|
-
const DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
52
|
-
const DEFAULT_WEB_URL = "https://platform.composio.dev";
|
|
53
|
-
const TELEMETRY_URL$1 = "https://app.composio.dev";
|
|
54
|
-
const CLIENT_PUSHER_KEY = getEnvVariable("CLIENT_PUSHER_KEY") || "ff9f18c208855d77a152";
|
|
55
|
-
const COMPOSIO_LOG_LEVEL = getEnvVariable("COMPOSIO_LOG_LEVEL");
|
|
56
|
-
const IS_DEVELOPMENT_OR_CI = getEnvVariable("DEVELOPMENT") || getEnvVariable("CI") || false;
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/utils/logger.ts
|
|
60
|
-
const LOG_LEVELS = {
|
|
61
|
-
silent: -1,
|
|
62
|
-
error: 0,
|
|
63
|
-
warn: 1,
|
|
64
|
-
info: 2,
|
|
65
|
-
debug: 3
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Get the current log level from environment variables.
|
|
69
|
-
* Defaults to 'info' if not set or invalid.
|
|
70
|
-
* @returns {LogLevel} The current log level
|
|
71
|
-
*/
|
|
72
|
-
const getLogLevel = () => {
|
|
73
|
-
const envLevel = (COMPOSIO_LOG_LEVEL ?? "info")?.toLowerCase();
|
|
74
|
-
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
75
|
-
};
|
|
76
|
-
var Logger = class {
|
|
77
|
-
level;
|
|
78
|
-
includeTimestamp;
|
|
79
|
-
console;
|
|
80
|
-
constructor(options = {}) {
|
|
81
|
-
this.level = options.level ?? getLogLevel();
|
|
82
|
-
this.includeTimestamp = options.includeTimestamp ?? true;
|
|
83
|
-
this.console = console;
|
|
84
|
-
}
|
|
85
|
-
formatMessage(args) {
|
|
86
|
-
const formattedArgs = args.map((arg, index) => {
|
|
87
|
-
if (typeof arg === "object") return JSON.stringify(arg);
|
|
88
|
-
else {
|
|
89
|
-
if (index === 0) if (args.length > 1) return chalk.yellow(`${arg}`);
|
|
90
|
-
else return String(arg);
|
|
91
|
-
return String(arg);
|
|
92
|
-
}
|
|
93
|
-
}).join("\n");
|
|
94
|
-
if (!this.includeTimestamp) return formattedArgs;
|
|
95
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
96
|
-
return `${chalk.gray(timestamp)} - ${formattedArgs}`;
|
|
97
|
-
}
|
|
98
|
-
shouldLog(level) {
|
|
99
|
-
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
100
|
-
}
|
|
101
|
-
error(...args) {
|
|
102
|
-
if (this.shouldLog("error")) this.console.error(this.formatMessage(args));
|
|
103
|
-
}
|
|
104
|
-
warn(...args) {
|
|
105
|
-
if (this.shouldLog("warn")) this.console.warn(this.formatMessage(args));
|
|
106
|
-
}
|
|
107
|
-
info(...args) {
|
|
108
|
-
if (this.shouldLog("info")) this.console.info(this.formatMessage(args));
|
|
109
|
-
}
|
|
110
|
-
debug(...args) {
|
|
111
|
-
if (this.shouldLog("debug")) this.console.debug(this.formatMessage(args));
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const logger = new Logger();
|
|
115
|
-
var logger_default = logger;
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/errors/ComposioError.ts
|
|
119
|
-
/**
|
|
120
|
-
* @fileoverview Error class for Composio.
|
|
121
|
-
*
|
|
122
|
-
* This error class is used to create custom errors for Composio.
|
|
123
|
-
* It extends the built-in Error class and adds additional properties for code, status code, cause, meta, and possible fixes.
|
|
124
|
-
*
|
|
125
|
-
* @author Musthaq Ahamad <musthaq@composio.dev>
|
|
126
|
-
* @module errors/ComposioError
|
|
127
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
|
|
128
|
-
*/
|
|
129
|
-
/**
|
|
130
|
-
* Base error class for all Composio errors
|
|
131
|
-
*/
|
|
132
|
-
var ComposioError$1 = class ComposioError$1 extends Error {
|
|
133
|
-
/** @readonly Error name */
|
|
134
|
-
name = "ComposioError";
|
|
135
|
-
code;
|
|
136
|
-
possibleFixes;
|
|
137
|
-
errorId;
|
|
138
|
-
/**
|
|
139
|
-
* Creates a new ComposioError
|
|
140
|
-
* @param message Error message
|
|
141
|
-
* @param options Additional error options
|
|
142
|
-
*/
|
|
143
|
-
constructor(message, options = {}) {
|
|
144
|
-
super(message);
|
|
145
|
-
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
146
|
-
const statusCode = options.statusCode || (options.cause instanceof BadRequestError ? options.cause.status : void 0);
|
|
147
|
-
this.code = `TS-SDK::${options.code}`;
|
|
148
|
-
this.possibleFixes = options.possibleFixes;
|
|
149
|
-
this.definePropertyIfExists("statusCode", statusCode);
|
|
150
|
-
this.definePropertyIfExists("cause", options.cause);
|
|
151
|
-
const combinedStack = options.cause instanceof Error ? ComposioError$1.combineStackTraces(options.cause.stack, this.stack) : options.stack ?? this.stack;
|
|
152
|
-
this.definePropertyIfExists("stack", combinedStack);
|
|
153
|
-
if (options.meta && Object.keys(options.meta).length > 0) this.definePropertyIfExists("meta", options.meta);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Helper method to define a property only if it has a value
|
|
157
|
-
* @param propertyName Name of the property to define
|
|
158
|
-
* @param value Value to assign to the property
|
|
159
|
-
* @private
|
|
160
|
-
*/
|
|
161
|
-
definePropertyIfExists(propertyName, value) {
|
|
162
|
-
if (value !== void 0) Object.defineProperty(this, propertyName, {
|
|
163
|
-
value,
|
|
164
|
-
enumerable: true,
|
|
165
|
-
writable: false,
|
|
166
|
-
configurable: true
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Helper method to combine stack traces when wrapping errors
|
|
171
|
-
* This ensures the full call chain is preserved
|
|
172
|
-
* @param originalStack The stack of the error being wrapped
|
|
173
|
-
* @param currentStack The stack of the wrapper error
|
|
174
|
-
* @returns Combined stack trace
|
|
175
|
-
* @private
|
|
176
|
-
*/
|
|
177
|
-
static combineStackTraces(originalStack, currentStack) {
|
|
178
|
-
if (!originalStack) return currentStack;
|
|
179
|
-
if (!currentStack) return originalStack;
|
|
180
|
-
const currentHeader = currentStack.split("\n")[0];
|
|
181
|
-
const originalStackBody = originalStack.split("\n").slice(1).join("\n");
|
|
182
|
-
return `${currentHeader}\n${currentStack.split("\n").slice(1).join("\n")}\n\nCaused by:\n${originalStackBody}`;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Extract and normalize error data for formatting
|
|
186
|
-
* @param includeStack Whether to include stack trace information
|
|
187
|
-
* @returns Structured error data for formatting
|
|
188
|
-
* @private
|
|
189
|
-
*/
|
|
190
|
-
getErrorData(includeStack = false) {
|
|
191
|
-
const data = {
|
|
192
|
-
name: this.name,
|
|
193
|
-
message: this.message
|
|
194
|
-
};
|
|
195
|
-
const { cause, code, stack, statusCode, meta, possibleFixes } = this;
|
|
196
|
-
if (cause !== void 0) {
|
|
197
|
-
const rawCause = cause;
|
|
198
|
-
data.cause = rawCause instanceof Error ? rawCause.message : String(rawCause);
|
|
199
|
-
}
|
|
200
|
-
if (code) data.code = code;
|
|
201
|
-
if (statusCode !== void 0) data.statusCode = statusCode;
|
|
202
|
-
if (meta) data.meta = meta;
|
|
203
|
-
if (possibleFixes) data.possibleFixes = possibleFixes;
|
|
204
|
-
if (includeStack && stack) if (stack.includes("Caused by:")) {
|
|
205
|
-
const [currentStack, causeStack] = stack.split("Caused by:");
|
|
206
|
-
data.stack = [
|
|
207
|
-
...currentStack.split("\n").slice(1),
|
|
208
|
-
"Caused by:",
|
|
209
|
-
...causeStack.split("\n")
|
|
210
|
-
];
|
|
211
|
-
} else data.stack = stack.split("\n").slice(1);
|
|
212
|
-
return data;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Prints a user-friendly, colorful representation of the error to the logger
|
|
216
|
-
* @param includeStack Whether to include the stack trace in the output (default: false)
|
|
217
|
-
*/
|
|
218
|
-
prettyPrint(includeStack = false) {
|
|
219
|
-
const data = this.getErrorData(includeStack);
|
|
220
|
-
let output = "\n" + chalk.bgRed.white.bold(" ERROR ") + " " + chalk.white.bold(data.message) + "\n";
|
|
221
|
-
if (data.code) output += chalk.yellow(`Error Code: ${data.code}`) + "\n";
|
|
222
|
-
if (data.statusCode !== void 0) output += chalk.yellow(`Status: ${data.statusCode}`) + "\n";
|
|
223
|
-
if (data.cause) {
|
|
224
|
-
output += chalk.gray("Reason:") + "\n";
|
|
225
|
-
output += " " + chalk.white(data.cause) + "\n";
|
|
226
|
-
}
|
|
227
|
-
if (data.meta) {
|
|
228
|
-
output += chalk.gray("Additional Information:") + "\n";
|
|
229
|
-
output += " " + chalk.white(JSON.stringify(data.meta, null, 2).replace(/\n/g, "\n ")) + "\n";
|
|
230
|
-
}
|
|
231
|
-
if (data.possibleFixes?.length) {
|
|
232
|
-
output += "\n" + chalk.cyan.bold("Try the following:") + "\n";
|
|
233
|
-
const fixes = data.possibleFixes?.map((fix, index) => ` ${index + 1}. ` + chalk.white(fix));
|
|
234
|
-
output += fixes?.join("\n") + "\n";
|
|
235
|
-
}
|
|
236
|
-
if (data.stack?.length) {
|
|
237
|
-
output += "\n" + chalk.gray("Stack Trace:") + "\n";
|
|
238
|
-
output += chalk.gray(data.stack.join("\n")) + "\n";
|
|
239
|
-
}
|
|
240
|
-
output += "\n";
|
|
241
|
-
logger_default.error(output);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Static factory method to create and pretty print an error in one step
|
|
245
|
-
* @param message Error message
|
|
246
|
-
* @param options Error options
|
|
247
|
-
* @param includeStack Whether to include the stack trace in the output
|
|
248
|
-
* @returns The created error instance
|
|
249
|
-
*/
|
|
250
|
-
static createAndPrint(message, options = {}, includeStack = false) {
|
|
251
|
-
const error = new ComposioError$1(message, options);
|
|
252
|
-
error.prettyPrint(includeStack);
|
|
253
|
-
return error;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Utility function to handle errors in a consistent way
|
|
257
|
-
* This properly displays the error without throwing
|
|
258
|
-
* @param error The error to handle
|
|
259
|
-
* @param options Options for error handling
|
|
260
|
-
*/
|
|
261
|
-
static handle(error, options = {}) {
|
|
262
|
-
const { includeStack = false, exitProcess = false } = options;
|
|
263
|
-
if (error instanceof ComposioError$1) error.prettyPrint(includeStack);
|
|
264
|
-
else if (error instanceof ZodError) this.handleZodError(error, includeStack);
|
|
265
|
-
else if (error instanceof Error) this.handleStandardError(error, includeStack);
|
|
266
|
-
else this.handleUnknownError(error);
|
|
267
|
-
if (exitProcess) this.throwError(error);
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Utility function to handle errors and then throw them
|
|
271
|
-
* This properly displays the error and then throws it, allowing callers to catch it.
|
|
272
|
-
* Use this for fatal errors that should stop execution.
|
|
273
|
-
* @param error The error to handle and throw
|
|
274
|
-
* @param includeStack Whether to include the stack trace in the output
|
|
275
|
-
* @throws ComposioError - Always throws after displaying the error
|
|
276
|
-
*/
|
|
277
|
-
static handleAndThrow(error, includeStack = false) {
|
|
278
|
-
this.handle(error, { includeStack });
|
|
279
|
-
this.throwError(error);
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Helper method to throw an error as a ComposioError
|
|
283
|
-
* @param error The error to throw
|
|
284
|
-
* @private
|
|
285
|
-
*/
|
|
286
|
-
static throwError(error) {
|
|
287
|
-
if (error instanceof ComposioError$1) throw error;
|
|
288
|
-
else if (error instanceof Error) throw new ComposioError$1(error.message, { cause: error });
|
|
289
|
-
else throw new ComposioError$1(String(error));
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Helper method to handle Zod validation errors
|
|
293
|
-
* @param error The Zod error to handle
|
|
294
|
-
* @param includeStack Whether to include the stack trace
|
|
295
|
-
* @private
|
|
296
|
-
*/
|
|
297
|
-
static handleZodError(error, includeStack) {
|
|
298
|
-
logger_default.error("\n" + chalk.bgRed.white.bold(" ERROR ") + " " + chalk.white.bold(error.message));
|
|
299
|
-
logger_default.error(chalk.gray("Invalid parameters:"));
|
|
300
|
-
error.errors.forEach((err) => {
|
|
301
|
-
logger_default.error(chalk.yellow(err.path.join(".")) + " " + chalk.white(err.message));
|
|
302
|
-
});
|
|
303
|
-
logger_default.error(chalk.gray("Expected parameters:"));
|
|
304
|
-
error.errors.forEach((err) => {
|
|
305
|
-
logger_default.error(chalk.yellow(err.path.join(".")) + " " + chalk.white(err.message));
|
|
306
|
-
});
|
|
307
|
-
if (includeStack) {
|
|
308
|
-
logger_default.error("\n" + chalk.gray("Validation Errors:"));
|
|
309
|
-
error.errors.forEach((err) => {
|
|
310
|
-
const path = err.path.join(".");
|
|
311
|
-
logger_default.error(chalk.gray(" • ") + chalk.yellow(path ? `${path}: ` : "") + chalk.white(err.message));
|
|
312
|
-
});
|
|
313
|
-
if (error.stack) {
|
|
314
|
-
logger_default.error("\n" + chalk.gray("Stack Trace:"));
|
|
315
|
-
const stackLines = error.stack.split("\n").slice(1);
|
|
316
|
-
logger_default.error(chalk.gray(stackLines.join("\n")));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
logger_default.error("");
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Helper method to handle standard Error objects
|
|
323
|
-
* @param error The standard error to handle
|
|
324
|
-
* @param includeStack Whether to include the stack trace
|
|
325
|
-
* @private
|
|
326
|
-
*/
|
|
327
|
-
static handleStandardError(error, includeStack) {
|
|
328
|
-
logger_default.error("\n" + chalk.bgRed.white.bold(" ERROR ") + " " + chalk.white.bold(error.message));
|
|
329
|
-
if (includeStack && error.stack) {
|
|
330
|
-
logger_default.error("\n" + chalk.gray("Stack Trace:"));
|
|
331
|
-
const stackLines = error.stack.split("\n").slice(1);
|
|
332
|
-
logger_default.error(chalk.gray(stackLines.join("\n")));
|
|
333
|
-
}
|
|
334
|
-
logger_default.error("");
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Helper method to handle unknown error types
|
|
338
|
-
* @param error The unknown error value
|
|
339
|
-
* @private
|
|
340
|
-
*/
|
|
341
|
-
static handleUnknownError(error) {
|
|
342
|
-
logger_default.error("\n" + chalk.bgRed.white.bold(" ERROR ") + " " + chalk.white.bold("Unknown error occurred"));
|
|
343
|
-
if (error !== null && error !== void 0) {
|
|
344
|
-
logger_default.error(chalk.gray("Error details:"));
|
|
345
|
-
logger_default.error(" " + chalk.white(String(error)));
|
|
346
|
-
}
|
|
347
|
-
logger_default.error("");
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
//#endregion
|
|
352
|
-
//#region src/types/telemetry.types.ts
|
|
353
|
-
const TELEMETRY_EVENTS = {
|
|
354
|
-
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
355
|
-
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
356
|
-
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
357
|
-
CLI_INVOKED: "CLI_INVOKED"
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
//#endregion
|
|
361
|
-
//#region src/telemetry/BatchProcessor.ts
|
|
362
|
-
var BatchProcessor = class {
|
|
363
|
-
batch = [];
|
|
364
|
-
time;
|
|
365
|
-
batchSize;
|
|
366
|
-
processBatchCallback;
|
|
367
|
-
timer = null;
|
|
368
|
-
pendingBatches = /* @__PURE__ */ new Set();
|
|
369
|
-
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
370
|
-
this.batch = [];
|
|
371
|
-
this.time = time;
|
|
372
|
-
this.batchSize = batchSize;
|
|
373
|
-
this.processBatchCallback = processBatchCallback;
|
|
374
|
-
}
|
|
375
|
-
pushItem(item) {
|
|
376
|
-
this.batch.push(item);
|
|
377
|
-
if (this.batch.length >= this.batchSize) this.processBatch();
|
|
378
|
-
else if (!this.timer) this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
379
|
-
}
|
|
380
|
-
processBatch() {
|
|
381
|
-
if (this.batch.length > 0) {
|
|
382
|
-
const batchToProcess = this.batch;
|
|
383
|
-
this.batch = [];
|
|
384
|
-
const pending = this.processBatchCallback(batchToProcess).catch(() => {}).finally(() => {
|
|
385
|
-
this.pendingBatches.delete(pending);
|
|
386
|
-
});
|
|
387
|
-
this.pendingBatches.add(pending);
|
|
388
|
-
}
|
|
389
|
-
if (this.timer) {
|
|
390
|
-
clearTimeout(this.timer);
|
|
391
|
-
this.timer = null;
|
|
392
|
-
}
|
|
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
|
-
}
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
//#endregion
|
|
405
|
-
//#region src/utils/uuid.ts
|
|
406
|
-
function getRandomUUID() {
|
|
407
|
-
return globalThis.crypto.randomUUID();
|
|
408
|
-
}
|
|
409
|
-
function getRandomShortId() {
|
|
410
|
-
return getRandomUUID().slice(0, 8).replace(/-/g, "");
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
//#endregion
|
|
414
|
-
//#region src/services/telemetry/TelemetryService.ts
|
|
415
|
-
const TELEMETRY_URL = "https://telemetry.composio.dev/v1";
|
|
416
|
-
var TelemetryService = class {
|
|
417
|
-
/**
|
|
418
|
-
* Sends a metric to the Telemetry API.
|
|
419
|
-
* @param payload - The payload to send to the Telemetry API.
|
|
420
|
-
* @returns The response from the Telemetry API.
|
|
421
|
-
*/
|
|
422
|
-
static async sendMetric(payload) {
|
|
423
|
-
try {
|
|
424
|
-
return await fetch(`${TELEMETRY_URL}/metrics/invocations`, {
|
|
425
|
-
method: "POST",
|
|
426
|
-
headers: { "Content-Type": "application/json" },
|
|
427
|
-
body: JSON.stringify(payload)
|
|
428
|
-
});
|
|
429
|
-
} catch (error) {
|
|
430
|
-
logger_default.debug("Error sending metric telemetry", error);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Sends an error log to the Telemetry API.
|
|
435
|
-
* @param payload - The payload to send to the Telemetry API.
|
|
436
|
-
* @returns The response from the Telemetry API.
|
|
437
|
-
*/
|
|
438
|
-
static async sendErrorLog(payload) {
|
|
439
|
-
try {
|
|
440
|
-
return await fetch(`${TELEMETRY_URL}/errors`, {
|
|
441
|
-
method: "POST",
|
|
442
|
-
headers: { "Content-Type": "application/json" },
|
|
443
|
-
body: JSON.stringify(payload)
|
|
444
|
-
});
|
|
445
|
-
} catch (error) {
|
|
446
|
-
logger_default.debug("Error sending error telemetry", error);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
//#endregion
|
|
452
|
-
//#region src/telemetry/Telemetry.ts
|
|
453
|
-
/**
|
|
454
|
-
* The Telemetry class is used to log the telemetry for any given instance which extends InstrumentedInstance.
|
|
455
|
-
*
|
|
456
|
-
* This class is used to instrument the telemetry for the given instance and send the telemetry to the server.
|
|
457
|
-
* This class is also used to create a global error handler for the given instance.
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
*
|
|
461
|
-
* const telemetry = new Telemetry({...});
|
|
462
|
-
* const composio = new Composio({...})
|
|
463
|
-
*
|
|
464
|
-
* telemetry.instrument(composio);
|
|
465
|
-
* telemetry.instrument(composio.tools);
|
|
466
|
-
* telemetry.instrument(composio.toolkits);
|
|
467
|
-
* telemetry.instrument(composio.triggers);
|
|
468
|
-
*
|
|
469
|
-
*/
|
|
470
|
-
var TelemetryTransport = class {
|
|
471
|
-
telemetryMetadata;
|
|
472
|
-
isTelemetryDisabled = true;
|
|
473
|
-
telemetrySource;
|
|
474
|
-
telemetrySourceName = "typescript-sdk";
|
|
475
|
-
telemetryServiceName = "sdk";
|
|
476
|
-
telemetryLanguage = "typescript";
|
|
477
|
-
exitHandlersRegistered = false;
|
|
478
|
-
batchProcessor = new BatchProcessor(200, 10, async (data) => {
|
|
479
|
-
logger_default.debug("Sending batch of telemetry metrics", data);
|
|
480
|
-
await TelemetryService.sendMetric(data);
|
|
481
|
-
});
|
|
482
|
-
setup(metadata) {
|
|
483
|
-
this.telemetryMetadata = metadata;
|
|
484
|
-
this.isTelemetryDisabled = false;
|
|
485
|
-
this.telemetrySource = {
|
|
486
|
-
host: this.telemetryMetadata?.host ?? this.telemetrySourceName,
|
|
487
|
-
service: this.telemetryServiceName,
|
|
488
|
-
language: this.telemetryLanguage,
|
|
489
|
-
version: this.telemetryMetadata?.version,
|
|
490
|
-
platform: this.telemetryMetadata?.isBrowser ? "browser" : "node",
|
|
491
|
-
environment: getEnvVariable("NODE_ENV", "production")
|
|
492
|
-
};
|
|
493
|
-
this.registerExitHandlers();
|
|
494
|
-
this.sendMetric([{
|
|
495
|
-
functionName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
496
|
-
durationMs: 0,
|
|
497
|
-
timestamp: Date.now() / 1e3,
|
|
498
|
-
props: {},
|
|
499
|
-
source: this.telemetrySource,
|
|
500
|
-
metadata: { provider: this.telemetryMetadata?.provider ?? "openai" },
|
|
501
|
-
error: void 0
|
|
502
|
-
}]);
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Instrument the telemetry for the given instance.
|
|
506
|
-
*
|
|
507
|
-
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
508
|
-
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
509
|
-
* @param instance - any instance that extends InstrumentedInstance
|
|
510
|
-
* @param fileName - the file name of the instance
|
|
511
|
-
* @returns
|
|
512
|
-
*/
|
|
513
|
-
instrument(instance, fileName) {
|
|
514
|
-
const proto = Object.getPrototypeOf(instance);
|
|
515
|
-
const methodNames = Object.getOwnPropertyNames(proto).filter((key) => {
|
|
516
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
517
|
-
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
518
|
-
});
|
|
519
|
-
const instrumentedClassName = fileName ?? instance.constructor?.name ?? "unknown";
|
|
520
|
-
for (const name of methodNames) {
|
|
521
|
-
const originalMethod = instance[name];
|
|
522
|
-
instance[name] = async (...args) => {
|
|
523
|
-
const telemetryEnabled = this.shouldSendTelemetry();
|
|
524
|
-
const startTime = telemetryEnabled ? Date.now() : void 0;
|
|
525
|
-
try {
|
|
526
|
-
const result = await originalMethod.apply(instance, args);
|
|
527
|
-
if (telemetryEnabled && startTime !== void 0) {
|
|
528
|
-
const durationMs = Date.now() - startTime;
|
|
529
|
-
const telemetryPayload = {
|
|
530
|
-
functionName: `${instrumentedClassName}.${name}`,
|
|
531
|
-
durationMs,
|
|
532
|
-
timestamp: startTime / 1e3,
|
|
533
|
-
props: {
|
|
534
|
-
fileName: instrumentedClassName,
|
|
535
|
-
method: name,
|
|
536
|
-
params: args
|
|
537
|
-
},
|
|
538
|
-
metadata: { provider: this.telemetryMetadata?.provider ?? "openai" },
|
|
539
|
-
error: void 0,
|
|
540
|
-
source: this.telemetrySource
|
|
541
|
-
};
|
|
542
|
-
this.batchProcessor.pushItem(telemetryPayload);
|
|
543
|
-
}
|
|
544
|
-
return result;
|
|
545
|
-
} catch (error) {
|
|
546
|
-
if (error instanceof Error) {
|
|
547
|
-
if (!error.errorId) {
|
|
548
|
-
error.errorId = getRandomUUID();
|
|
549
|
-
if (telemetryEnabled && startTime !== void 0) {
|
|
550
|
-
const durationMs = Date.now() - startTime;
|
|
551
|
-
await this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args, startTime, durationMs);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
throw error;
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
return instance;
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Check if the telemetry should be sent.
|
|
563
|
-
* @returns true if the telemetry should be sent, false otherwise
|
|
564
|
-
*/
|
|
565
|
-
shouldSendTelemetry() {
|
|
566
|
-
const telemetryDisabledEnvironments = ["test", "ci"];
|
|
567
|
-
const nodeEnv = (getEnvVariable("NODE_ENV", "development") || "").toLowerCase();
|
|
568
|
-
const isDisabledEnvironment = telemetryDisabledEnvironments.includes(nodeEnv);
|
|
569
|
-
const isTelemetryDisabledByEnv = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
570
|
-
return !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDisabledEnvironment;
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* Prepare and send the error telemetry.
|
|
574
|
-
*
|
|
575
|
-
* @TODO This currently blocks the thread and sends the telemetry to the server.
|
|
576
|
-
*
|
|
577
|
-
* @param {unknown} error - The error to send.
|
|
578
|
-
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
579
|
-
* @param {string} name - The name of the method that threw the error.
|
|
580
|
-
* @param {unknown[]} args - The arguments passed to the method.
|
|
581
|
-
* @param {number} startTime - The start time of the method invocation in milliseconds.
|
|
582
|
-
* @param {number} durationMs - The duration of the method invocation in milliseconds.
|
|
583
|
-
*/
|
|
584
|
-
async prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args, startTime, durationMs) {
|
|
585
|
-
const telemetryPayload = {
|
|
586
|
-
functionName: `${instrumentedClassName}.${name}`,
|
|
587
|
-
durationMs,
|
|
588
|
-
timestamp: startTime / 1e3,
|
|
589
|
-
props: {
|
|
590
|
-
fileName: instrumentedClassName,
|
|
591
|
-
method: name,
|
|
592
|
-
params: args
|
|
593
|
-
},
|
|
594
|
-
metadata: { provider: this.telemetryMetadata?.provider ?? "openai" },
|
|
595
|
-
source: this.telemetrySource
|
|
596
|
-
};
|
|
597
|
-
if (error instanceof ComposioError) telemetryPayload.error = {
|
|
598
|
-
errorId: error.errorId,
|
|
599
|
-
name: error.name,
|
|
600
|
-
message: error.message,
|
|
601
|
-
stack: error.stack
|
|
602
|
-
};
|
|
603
|
-
else if (error instanceof ComposioError$1) telemetryPayload.error = {
|
|
604
|
-
errorId: error.errorId,
|
|
605
|
-
name: error.name,
|
|
606
|
-
code: error.code,
|
|
607
|
-
message: error.message,
|
|
608
|
-
stack: error.stack
|
|
609
|
-
};
|
|
610
|
-
else if (error instanceof Error) telemetryPayload.error = {
|
|
611
|
-
errorId: error.errorId,
|
|
612
|
-
name: error.name ?? "Unknown error",
|
|
613
|
-
message: error.message,
|
|
614
|
-
stack: error.stack
|
|
615
|
-
};
|
|
616
|
-
await this.sendErrorTelemetry(telemetryPayload);
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* Send the telemetry payload to the server.
|
|
620
|
-
* @param payload - the telemetry payload to send
|
|
621
|
-
* @returns
|
|
622
|
-
*/
|
|
623
|
-
async sendMetric(payload) {
|
|
624
|
-
if (!this.shouldSendTelemetry()) {
|
|
625
|
-
logger_default.debug("Telemetry is disabled, skipping metric telemetry", payload);
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
try {
|
|
629
|
-
logger_default.debug("SDK Metric", payload);
|
|
630
|
-
await TelemetryService.sendMetric(payload);
|
|
631
|
-
} catch (error) {
|
|
632
|
-
logger_default.error("Error sending metric telemetry", error);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
async sendErrorTelemetry(payload) {
|
|
636
|
-
if (!this.shouldSendTelemetry()) {
|
|
637
|
-
logger_default.debug("Telemetry is disabled, skipping metric telemetry", payload);
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
try {
|
|
641
|
-
logger_default.debug("SDK Error Telemetry", payload);
|
|
642
|
-
await TelemetryService.sendErrorLog(payload);
|
|
643
|
-
} catch (error) {
|
|
644
|
-
logger_default.error("Error sending error telemetry", error);
|
|
645
|
-
}
|
|
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
|
-
}
|
|
684
|
-
};
|
|
685
|
-
const telemetry = new TelemetryTransport();
|
|
686
|
-
|
|
687
|
-
//#endregion
|
|
688
|
-
//#region src/utils/fileUtils.ts
|
|
689
|
-
const getExtensionFromMimeType = (mimeType) => {
|
|
690
|
-
const mimeToExt = {
|
|
691
|
-
"text/plain": "txt",
|
|
692
|
-
"text/html": "html",
|
|
693
|
-
"text/css": "css",
|
|
694
|
-
"text/javascript": "js",
|
|
695
|
-
"application/json": "json",
|
|
696
|
-
"application/xml": "xml",
|
|
697
|
-
"application/pdf": "pdf",
|
|
698
|
-
"application/zip": "zip",
|
|
699
|
-
"application/x-zip-compressed": "zip",
|
|
700
|
-
"application/gzip": "gz",
|
|
701
|
-
"application/x-tar": "tar",
|
|
702
|
-
"application/msword": "doc",
|
|
703
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
704
|
-
"application/vnd.ms-excel": "xls",
|
|
705
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
706
|
-
"application/vnd.ms-powerpoint": "ppt",
|
|
707
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
|
|
708
|
-
"image/jpeg": "jpg",
|
|
709
|
-
"image/jpg": "jpg",
|
|
710
|
-
"image/png": "png",
|
|
711
|
-
"image/gif": "gif",
|
|
712
|
-
"image/svg+xml": "svg",
|
|
713
|
-
"image/webp": "webp",
|
|
714
|
-
"image/bmp": "bmp",
|
|
715
|
-
"image/tiff": "tiff",
|
|
716
|
-
"audio/mpeg": "mp3",
|
|
717
|
-
"audio/wav": "wav",
|
|
718
|
-
"audio/ogg": "ogg",
|
|
719
|
-
"video/mp4": "mp4",
|
|
720
|
-
"video/mpeg": "mpeg",
|
|
721
|
-
"video/quicktime": "mov",
|
|
722
|
-
"video/x-msvideo": "avi",
|
|
723
|
-
"video/webm": "webm"
|
|
724
|
-
};
|
|
725
|
-
const cleanMimeType = mimeType.split(";")[0].toLowerCase().trim();
|
|
726
|
-
if (mimeToExt[cleanMimeType]) return mimeToExt[cleanMimeType];
|
|
727
|
-
const parts = cleanMimeType.split("/");
|
|
728
|
-
if (parts.length === 2) {
|
|
729
|
-
const cleanSubtype = parts[1].toLowerCase();
|
|
730
|
-
if (cleanSubtype.includes("+")) {
|
|
731
|
-
const plusParts = cleanSubtype.split("+");
|
|
732
|
-
const prefix = plusParts[0];
|
|
733
|
-
const suffix = plusParts[plusParts.length - 1];
|
|
734
|
-
if ([
|
|
735
|
-
"svg",
|
|
736
|
-
"atom",
|
|
737
|
-
"rss"
|
|
738
|
-
].includes(prefix)) return prefix;
|
|
739
|
-
if ([
|
|
740
|
-
"json",
|
|
741
|
-
"xml",
|
|
742
|
-
"yaml",
|
|
743
|
-
"zip",
|
|
744
|
-
"gzip"
|
|
745
|
-
].includes(suffix)) return suffix;
|
|
746
|
-
return suffix;
|
|
747
|
-
}
|
|
748
|
-
return cleanSubtype || "txt";
|
|
749
|
-
}
|
|
750
|
-
return "txt";
|
|
751
|
-
};
|
|
752
|
-
const generateTimestampedFilename = (extension, prefix) => {
|
|
753
|
-
return `${prefix || "file_ts"}${Date.now()}${getRandomShortId()}.${extension}`;
|
|
754
|
-
};
|
|
755
|
-
const readFileContent = async (filePath) => {
|
|
756
|
-
try {
|
|
757
|
-
if (!platform.supportsFileSystem) throw new Error("File system operations are not supported in this runtime environment");
|
|
758
|
-
const content = platform.readFileSync(filePath);
|
|
759
|
-
return {
|
|
760
|
-
fileName: generateTimestampedFilename(filePath.split(".").pop() || "txt"),
|
|
761
|
-
content: Buffer.isBuffer(content) ? content.toString("base64") : Buffer.from(content).toString("base64"),
|
|
762
|
-
mimeType: "application/octet-stream"
|
|
763
|
-
};
|
|
764
|
-
} catch (error) {
|
|
765
|
-
throw new Error(`Error reading file at ${filePath}: ${error}`);
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
const readFileContentFromURL = async (path) => {
|
|
769
|
-
const response = await fetch(path);
|
|
770
|
-
if (!response.ok) throw new Error(`Failed to fetch file: ${response.statusText}`);
|
|
771
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
772
|
-
const content = Buffer.from(arrayBuffer);
|
|
773
|
-
const mimeType = response.headers.get("content-type") || "application/octet-stream";
|
|
774
|
-
const pathname = new URL(path).pathname;
|
|
775
|
-
let fileName = platform.basename(pathname);
|
|
776
|
-
if (!fileName || fileName === "/") fileName = generateTimestampedFilename(getExtensionFromMimeType(mimeType));
|
|
777
|
-
else if (!fileName.includes(".")) fileName = generateTimestampedFilename(getExtensionFromMimeType(mimeType));
|
|
778
|
-
return {
|
|
779
|
-
content: content.toString("base64"),
|
|
780
|
-
mimeType,
|
|
781
|
-
fileName
|
|
782
|
-
};
|
|
783
|
-
};
|
|
784
|
-
const uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType, client) => {
|
|
785
|
-
const response = await client.files.createPresignedURL({
|
|
786
|
-
filename: fileName,
|
|
787
|
-
mimetype: mimeType,
|
|
788
|
-
md5: crypto.createHash("md5").update(Buffer.from(content, "base64")).digest("hex"),
|
|
789
|
-
tool_slug: toolSlug,
|
|
790
|
-
toolkit_slug: toolkitSlug
|
|
791
|
-
});
|
|
792
|
-
const { key, type } = response;
|
|
793
|
-
if (type === "new" || type === "update") {
|
|
794
|
-
logger_default.debug(`Uploading ${key} file to S3: ${key}`);
|
|
795
|
-
const buffer = Buffer.from(content, "base64");
|
|
796
|
-
const signedURL = response.type === "update" ? response.update_presigned_url : response.new_presigned_url;
|
|
797
|
-
const uploadResponse = await fetch(signedURL, {
|
|
798
|
-
method: "PUT",
|
|
799
|
-
body: buffer,
|
|
800
|
-
headers: {
|
|
801
|
-
"Content-Type": mimeType,
|
|
802
|
-
"Content-Length": buffer.length.toString()
|
|
803
|
-
}
|
|
804
|
-
});
|
|
805
|
-
if (!uploadResponse.ok) throw new Error(`Failed to upload file to S3: ${uploadResponse.statusText}`);
|
|
806
|
-
} else logger_default.debug(`File already exists in S3: ${key}`);
|
|
807
|
-
return key;
|
|
808
|
-
};
|
|
809
|
-
const readFile = async (file) => {
|
|
810
|
-
if (file instanceof File) {
|
|
811
|
-
const content = await file.arrayBuffer();
|
|
812
|
-
return {
|
|
813
|
-
fileName: file.name,
|
|
814
|
-
content: Buffer.from(content).toString("base64"),
|
|
815
|
-
mimeType: file.type
|
|
816
|
-
};
|
|
817
|
-
} else if (typeof file === "string") if (file.startsWith("http")) return await readFileContentFromURL(file);
|
|
818
|
-
else return await readFileContent(file);
|
|
819
|
-
throw new Error("Invalid file type");
|
|
820
|
-
};
|
|
821
|
-
const getFileDataAfterUploadingToS3 = async (file, { toolSlug, toolkitSlug, client }) => {
|
|
822
|
-
if (!file) throw new Error("Either path or blob must be provided");
|
|
823
|
-
const fileData = await readFile(file);
|
|
824
|
-
logger_default.debug(`Uploading file to S3...`);
|
|
825
|
-
const s3key = await uploadFileToS3(platform.basename(fileData.fileName), fileData.content, toolSlug, toolkitSlug, fileData.mimeType, client);
|
|
826
|
-
logger_default.debug(`Done! File uploaded to S3: ${s3key}`, JSON.stringify(fileData, null, 2));
|
|
827
|
-
return {
|
|
828
|
-
name: fileData.fileName,
|
|
829
|
-
mimetype: fileData.mimeType,
|
|
830
|
-
s3key
|
|
831
|
-
};
|
|
832
|
-
};
|
|
833
|
-
const downloadFileFromS3 = async ({ toolSlug, s3Url, mimeType }) => {
|
|
834
|
-
const response = await fetch(s3Url);
|
|
835
|
-
if (!response.ok) throw new Error(`Failed to download file: ${response.statusText}`);
|
|
836
|
-
const data = await response.arrayBuffer();
|
|
837
|
-
const fileName = generateTimestampedFilename(getExtensionFromMimeType(mimeType), `${toolSlug}_`);
|
|
838
|
-
return {
|
|
839
|
-
name: fileName,
|
|
840
|
-
mimeType,
|
|
841
|
-
s3Url,
|
|
842
|
-
filePath: saveFile(fileName, Buffer.from(data), true)
|
|
843
|
-
};
|
|
844
|
-
};
|
|
845
|
-
/**
|
|
846
|
-
* Gets the Composio directory.
|
|
847
|
-
* @param createDirIfNotExists - Whether to create the directory if it doesn't exist.
|
|
848
|
-
* @returns The path to the Composio directory.
|
|
849
|
-
*/
|
|
850
|
-
const getComposioDir = (createDirIfNotExists = false) => {
|
|
851
|
-
try {
|
|
852
|
-
const homeDir = platform.homedir();
|
|
853
|
-
if (!homeDir) return null;
|
|
854
|
-
const composioDir = platform.joinPath(homeDir, COMPOSIO_DIR);
|
|
855
|
-
if (createDirIfNotExists && platform.supportsFileSystem && !platform.existsSync(composioDir)) platform.mkdirSync(composioDir);
|
|
856
|
-
return composioDir;
|
|
857
|
-
} catch (_error) {
|
|
858
|
-
return null;
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
/**
|
|
862
|
-
* Gets the Composio temporary files directory.
|
|
863
|
-
* @param createDirIfNotExists - Whether to create the directory if it doesn't exist.
|
|
864
|
-
* @returns The path to the Composio temporary files directory.
|
|
865
|
-
*/
|
|
866
|
-
const getComposioTempFilesDir = (createDirIfNotExists = false) => {
|
|
867
|
-
try {
|
|
868
|
-
const homeDir = platform.homedir();
|
|
869
|
-
if (!homeDir) return null;
|
|
870
|
-
const composioFilesDir = platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
|
|
871
|
-
if (createDirIfNotExists && platform.supportsFileSystem && !platform.existsSync(composioFilesDir)) platform.mkdirSync(composioFilesDir);
|
|
872
|
-
return composioFilesDir;
|
|
873
|
-
} catch (_error) {
|
|
874
|
-
return null;
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
/**
|
|
878
|
-
* Saves a file to the Composio directory.
|
|
879
|
-
* @param file - The name of the file to save.
|
|
880
|
-
* @param content - The content of the file to save. Can be a string or Buffer.
|
|
881
|
-
* @param isTempFile - Whether the file is a temporary file.
|
|
882
|
-
* @returns The path to the saved file.
|
|
883
|
-
*/
|
|
884
|
-
const saveFile = (file, content, isTempFile = false) => {
|
|
885
|
-
try {
|
|
886
|
-
if (!platform.supportsFileSystem) {
|
|
887
|
-
logger_default.debug("File system operations are not supported in this runtime environment");
|
|
888
|
-
return null;
|
|
889
|
-
}
|
|
890
|
-
const composioFilesDir = isTempFile ? getComposioTempFilesDir(true) : getComposioDir(true);
|
|
891
|
-
if (!composioFilesDir) return null;
|
|
892
|
-
const filePath = platform.joinPath(composioFilesDir, platform.basename(file));
|
|
893
|
-
logger_default.info(`Saving file to: ${filePath}`);
|
|
894
|
-
if (Buffer.isBuffer(content)) platform.writeFileSync(filePath, content);
|
|
895
|
-
else platform.writeFileSync(filePath, content, "utf8");
|
|
896
|
-
return filePath;
|
|
897
|
-
} catch (_error) {
|
|
898
|
-
logger_default.debug(`Error saving file: ${_error}`);
|
|
899
|
-
return null;
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
|
|
903
|
-
//#endregion
|
|
904
|
-
export { logger_default as a, DEFAULT_BASE_URL as c, constants_exports as d, getEnvVariable as f, ComposioError$1 as i, IS_DEVELOPMENT_OR_CI as l, getFileDataAfterUploadingToS3 as n, COMPOSIO_DIR as o, getEnvsWithPrefix as p, telemetry as r, COMPOSIO_LOG_LEVEL as s, downloadFileFromS3 as t, USER_DATA_FILE_NAME as u };
|