@composio/core 0.18.1 → 0.20.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/{CustomTool-VRfWzMix.d.mts → CustomTool-B3m-188G.d.mts} +1 -1
- package/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-fYEFjSLM.mjs} +1 -1
- package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-DiQldIdC.mjs} +32 -17
- package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
- package/dist/{cancellation-P5YUlcfz.mjs → cancellation-Dwa9lGHA.mjs} +7 -5
- package/dist/{composio-Cb3d1jFe.d.mts → composio-B36OXii1.d.mts} +3017 -144
- package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-C436M_D0.d.mts} +525 -101
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +8 -15
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +7 -0
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
- package/dist/docs/reference/sdk-reference/typescript/meta.json +8 -1
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +117 -24
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -10
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +151 -14
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +50 -40
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +26 -25
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +162 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +218 -0
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +20 -0
- package/dist/{errors-Ue9wMrPK.mjs → errors-D_A4b2c2.mjs} +143 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-DNLhLg0W.mjs} +8 -6
- package/dist/index.d.mts +418 -146
- package/dist/index.mjs +2728 -349
- package/dist/models/Files.node.d.mts +2 -3
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +2 -3
- package/dist/platform/node.d.mts +2 -3
- package/dist/platform/workerd.d.mts +2 -3
- package/dist/{sensitiveFileUploadPaths-QN7w4n8v.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
- package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-BZ270bcu.mjs} +104 -14
- package/dist/{types-CGdgK442.d.mts → types-Br3GBya5.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +19 -10
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +12 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +9 -9
- package/src/composio.ts +207 -10
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/SDKErrors.ts +52 -0
- package/src/errors/ToolErrors.ts +24 -0
- package/src/errors/ToolRouterErrors.ts +57 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +15 -0
- package/src/lib/toolRouterMcp.ts +132 -0
- package/src/lib/toolRouterParams.ts +116 -29
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomToolkits.ts +169 -0
- package/src/models/Experimental.ts +27 -0
- package/src/models/Keyring.ts +65 -0
- package/src/models/Logs.ts +101 -0
- package/src/models/MCP.ts +29 -15
- package/src/models/ToolRouter.ts +43 -14
- package/src/models/ToolRouterSession.ts +224 -16
- package/src/models/Toolkits.ts +181 -2
- package/src/models/Tools.ts +58 -26
- package/src/models/Triggers.ts +10 -90
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/pusher/Pusher.ts +46 -16
- package/src/types/authConfigs.types.ts +2 -0
- package/src/types/connectedAccounts.types.ts +54 -0
- package/src/types/customToolkits.types.ts +102 -0
- package/src/types/keyring.types.ts +32 -0
- package/src/types/logs.types.ts +108 -0
- package/src/types/toolRouter.types.ts +259 -14
- package/src/types/toolkit.types.ts +161 -0
- package/src/types/usage.types.ts +81 -0
- package/src/types/webhooks.types.ts +143 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/jsonSchema.ts +4 -1
- package/src/utils/logger.ts +39 -7
- package/src/utils/sdk.ts +385 -22
- package/src/utils/ssrfGuard.node.ts +127 -13
- package/src/utils/ssrfGuard.workerd.ts +11 -1
- package/src/utils/transformers/connectedAccounts.ts +37 -2
- package/src/utils/transformers/customToolkits.ts +98 -0
- package/src/utils/transformers/keyring.ts +24 -0
- package/src/utils/transformers/logs.ts +85 -0
- package/src/utils/transformers/toolkits.ts +183 -3
- package/src/utils/transformers/triggers.ts +2 -2
- package/src/utils/transformers/usage.ts +77 -0
- package/src/utils/transformers/webhooks.ts +139 -0
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { A as
|
|
3
|
-
import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, o as FileModifierErrorCodes, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "./FileModifierErrors-
|
|
4
|
-
import { n as dropEmptyFileUploads, o as isPlainObject, s as schemaHasFileUploadable } from "./FileToolModifier.utils.neutral-
|
|
5
|
-
import { a as jsonSchemaToZodSchema, c as toStrictJsonSchema, i as ensureObjectTypeOnProperties, n as deduplicateJsonSchemaRequiredArrays, o as omitNullToolArguments, r as dereferenceJsonSchema, s as removeNonRequiredProperties, t as withCancellation } from "./cancellation-
|
|
6
|
-
import { t as telemetry } from "./Telemetry-
|
|
7
|
-
import { a as
|
|
8
|
-
import { a as createCustomToolkit, c as getPreloadedCustomToolSlugs, d as CreateCustomToolBaseSchema, f as CreateCustomToolkitBaseSchema, i as createCustomTool, l as serializeCustomToolkits, n as buildCustomToolsMap, o as findCustomToolMapEntryByFinalSlug, p as CustomToolSlugSchema, r as buildCustomToolsMapFromResponse, s as findCustomToolMapEntryByToolkitAndOriginalSlug, t as assertNoCustomToolSlugsInPreload, u as serializeCustomTools } from "./CustomTool-
|
|
9
|
-
import ComposioClient, { APIError, BadRequestError } from "@composio/client";
|
|
1
|
+
import { c as DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID, d as USER_DATA_FILE_NAME, f as constants_exports, i as logger, l as IS_DEVELOPMENT_OR_CI, m as getEnvsWithPrefix, n as SsrfErrorCodes, o as COMPOSIO_DIR, p as getEnvVariable, r as ComposioError, s as DEFAULT_BASE_URL, t as ComposioBlockedInternalUrlError, u as TEMP_FILES_DIRECTORY_NAME } from "./SsrfErrors-DiQldIdC.mjs";
|
|
2
|
+
import { A as ComposioInvalidToolArgumentsError, B as ConnectionRequestTimeoutError, C as ValidationErrorCodes, D as ComposioGlobalExecuteToolFnNotSetError, E as ToolkitErrorCodes, F as ComposioToolVersionRequiredError, G as ComposioFailedToCreateConnectedAccountLink, H as ComposioConnectedAccountNotFoundError, I as ToolErrorCodes, J as ComposioSharedAccessDeniedError, K as ComposioLegacyConnectedAccountsEndpointRetiredError, L as handleToolExecutionError, M as ComposioToolExecutionError, N as ComposioToolFetchError, O as ComposioInvalidExecuteFunctionError, P as ComposioToolNotFoundError, Q as ComposioAuthConfigNotFoundError, R as ConnectionRequestErrorCodes, S as ValidationError, T as ComposioToolkitNotFoundError, U as ComposioConnectedAccountNotRevokableError, V as ComposioAclOnlyForSharedError, W as ComposioConnectedAccountRevocationNotSupportedError, X as ConnectedAccountErrorCodes, Y as ComposioSharedConnectionNotAccessibleError, Z as AuthConfigErrorCodes, _ as ComposioScopeConfigError, a as RemoteFileErrorCodes, b as JsonSchemaRefResolutionError, c as ComposioFailedToSubscribeToPusherChannelError, d as ComposioWebhookPayloadError, f as ComposioWebhookSignatureVerificationError, g as ComposioRequestCancelledError, h as ComposioNoAPIKeyError, i as RemoteFileDownloadError, j as ComposioProviderNotDefinedError, k as ComposioInvalidModifierError, l as ComposioFailedToUnsubscribeFromPusherChannelError, m as ComposioAPIKeyKindError, n as ComposioSessionConfigConflictError, o as ComposioFailedToCreatePusherClientError, p as TriggerErrorCodes, q as ComposioMultipleConnectedAccountsError, r as ToolRouterErrorCodes, s as ComposioFailedToGetSDKRealtimeCredentialsError, t as ComposioMCPDestinationError, u as ComposioTriggerTypeNotFoundError, v as SDKErrorCodes, w as ComposioToolkitFetchError, x as JsonSchemaToZodError, y as isRequestAbortError, z as ConnectionRequestFailedError } from "./errors-D_A4b2c2.mjs";
|
|
3
|
+
import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, o as FileModifierErrorCodes, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "./FileModifierErrors-CdGSABoq.mjs";
|
|
4
|
+
import { n as dropEmptyFileUploads, o as isPlainObject, s as schemaHasFileUploadable } from "./FileToolModifier.utils.neutral-DWFpnsj2.mjs";
|
|
5
|
+
import { a as jsonSchemaToZodSchema, c as toStrictJsonSchema, i as ensureObjectTypeOnProperties, n as deduplicateJsonSchemaRequiredArrays, o as omitNullToolArguments, r as dereferenceJsonSchema, s as removeNonRequiredProperties, t as withCancellation } from "./cancellation-Dwa9lGHA.mjs";
|
|
6
|
+
import { t as telemetry } from "./Telemetry-JRJJYS4I.mjs";
|
|
7
|
+
import { a as readResponseBodyWithLimit, i as MAX_URL_UPLOAD_SIZE_BYTES, l as getRandomShortId, n as assertSafeFileUploadPath, o as arrayBufferToBase64, r as isBlockedSensitiveFileUploadPath, t as BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS } from "./sensitiveFileUploadPaths-BlLp-Yo2.mjs";
|
|
8
|
+
import { a as createCustomToolkit, c as getPreloadedCustomToolSlugs, d as CreateCustomToolBaseSchema, f as CreateCustomToolkitBaseSchema, i as createCustomTool, l as serializeCustomToolkits, n as buildCustomToolsMap, o as findCustomToolMapEntryByFinalSlug, p as CustomToolSlugSchema, r as buildCustomToolsMapFromResponse, s as findCustomToolMapEntryByToolkitAndOriginalSlug, t as assertNoCustomToolSlugsInPreload, u as serializeCustomTools } from "./CustomTool-fYEFjSLM.mjs";
|
|
9
|
+
import ComposioClient, { APIError, BadRequestError, ConflictError } from "@composio/client";
|
|
10
10
|
import { FileToolModifier } from "#file_tool_modifier";
|
|
11
11
|
import z, { z as z$1 } from "zod/v3";
|
|
12
12
|
import { CONFIG_DEFAULTS } from "#config_defaults";
|
|
13
13
|
import { platform } from "#platform";
|
|
14
|
-
import { APIError as APIError$1 } from "openai";
|
|
15
14
|
import semver from "semver";
|
|
16
15
|
import { Files } from "#files";
|
|
17
16
|
import { ssrfSafeFetch, ssrfSafeFetchWhereSupported } from "#ssrf_guard";
|
|
@@ -35,6 +34,7 @@ const AuthSchemeTypes = {
|
|
|
35
34
|
SERVICE_ACCOUNT: "SERVICE_ACCOUNT",
|
|
36
35
|
SAML: "SAML",
|
|
37
36
|
DCR_OAUTH: "DCR_OAUTH",
|
|
37
|
+
CIMD_OAUTH: "CIMD_OAUTH",
|
|
38
38
|
S2S_OAUTH2: "S2S_OAUTH2"
|
|
39
39
|
};
|
|
40
40
|
const AuthConfigCreationToolAccessConfigSchema = z$1.object({ toolsForConnectedAccountCreation: z$1.array(z$1.string()).optional() });
|
|
@@ -56,6 +56,7 @@ const AuthSchemeEnum = z$1.enum([
|
|
|
56
56
|
"SERVICE_ACCOUNT",
|
|
57
57
|
"SAML",
|
|
58
58
|
"DCR_OAUTH",
|
|
59
|
+
"CIMD_OAUTH",
|
|
59
60
|
"S2S_OAUTH2"
|
|
60
61
|
]);
|
|
61
62
|
const CreateCustomAuthConfigParamsSchema = z$1.object({
|
|
@@ -1333,14 +1334,16 @@ var Tools = class {
|
|
|
1333
1334
|
toolkitSlug,
|
|
1334
1335
|
params
|
|
1335
1336
|
}, modifiers?.beforeFileUpload, requestOptions);
|
|
1336
|
-
if (modifiers?.beforeExecute)
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1337
|
+
if (modifiers?.beforeExecute) {
|
|
1338
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1339
|
+
modifiedParams = await modifiers.beforeExecute({
|
|
1340
|
+
toolSlug,
|
|
1341
|
+
toolkitSlug,
|
|
1342
|
+
params: modifiedParams
|
|
1343
|
+
});
|
|
1344
|
+
if (requestOptions?.signal?.aborted) throw new ComposioRequestCancelledError();
|
|
1345
|
+
} else throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1346
|
+
}
|
|
1344
1347
|
return modifiedParams;
|
|
1345
1348
|
}
|
|
1346
1349
|
/**
|
|
@@ -1389,12 +1392,14 @@ var Tools = class {
|
|
|
1389
1392
|
result: modifiedResult,
|
|
1390
1393
|
signal: requestOptions?.signal
|
|
1391
1394
|
});
|
|
1392
|
-
if (modifier)
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1395
|
+
if (modifier) {
|
|
1396
|
+
if (typeof modifier === "function") modifiedResult = await modifier({
|
|
1397
|
+
toolSlug,
|
|
1398
|
+
toolkitSlug,
|
|
1399
|
+
result: modifiedResult
|
|
1400
|
+
});
|
|
1401
|
+
else throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1402
|
+
}
|
|
1398
1403
|
return modifiedResult;
|
|
1399
1404
|
}
|
|
1400
1405
|
/**
|
|
@@ -1471,7 +1476,7 @@ var Tools = class {
|
|
|
1471
1476
|
...limit ? { limit } : {},
|
|
1472
1477
|
..."tags" in queryParams.data ? { tags: queryParams.data.tags } : {},
|
|
1473
1478
|
..."scopes" in queryParams.data ? { scopes: queryParams.data.scopes } : {},
|
|
1474
|
-
..."search" in queryParams.data ? {
|
|
1479
|
+
..."search" in queryParams.data ? { query: queryParams.data.search } : {},
|
|
1475
1480
|
..."authConfigIds" in queryParams.data ? { auth_config_ids: queryParams.data.authConfigIds } : {},
|
|
1476
1481
|
...effectiveImportant ? { important: "true" } : {},
|
|
1477
1482
|
toolkit_versions: this.toolkitVersions
|
|
@@ -1593,7 +1598,14 @@ var Tools = class {
|
|
|
1593
1598
|
tool = await withCancellation(() => this.client.tools.retrieve(slug, retrieveParams, requestOptions), requestOptions?.signal);
|
|
1594
1599
|
} catch (error) {
|
|
1595
1600
|
if (error instanceof ComposioRequestCancelledError) throw error;
|
|
1596
|
-
throw new ComposioToolNotFoundError(`
|
|
1601
|
+
if (error instanceof APIError && (error.status === 404 || error.status === 400)) throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`, {
|
|
1602
|
+
meta: { slug },
|
|
1603
|
+
cause: error
|
|
1604
|
+
});
|
|
1605
|
+
throw new ComposioToolFetchError(`Unable to retrieve tool with slug ${slug}`, {
|
|
1606
|
+
meta: { slug },
|
|
1607
|
+
cause: error
|
|
1608
|
+
});
|
|
1597
1609
|
}
|
|
1598
1610
|
let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
|
|
1599
1611
|
if (options?.modifySchema) {
|
|
@@ -1801,6 +1813,10 @@ var Tools = class {
|
|
|
1801
1813
|
*
|
|
1802
1814
|
* @example Execute with a specific version (recommended for production)
|
|
1803
1815
|
* ```typescript
|
|
1816
|
+
* // Look up the tool's current version once, then pin that string in your code or config
|
|
1817
|
+
* const { version } = await composio.tools.getRawComposioToolBySlug('GITHUB_GET_REPOS');
|
|
1818
|
+
* console.log(version); // e.g. '20250909_00'
|
|
1819
|
+
*
|
|
1804
1820
|
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
1805
1821
|
* userId: 'default',
|
|
1806
1822
|
* version: '20250909_00',
|
|
@@ -1926,47 +1942,62 @@ var Tools = class {
|
|
|
1926
1942
|
return withCancellation(() => this.client.tools.retrieveEnum(requestOptions), requestOptions?.signal);
|
|
1927
1943
|
}
|
|
1928
1944
|
/**
|
|
1929
|
-
*
|
|
1945
|
+
* Generates arguments for a tool from a natural-language description of the task.
|
|
1930
1946
|
*
|
|
1931
|
-
*
|
|
1947
|
+
* Composio uses an LLM to fill the tool's input parameters from `text`. Review the
|
|
1948
|
+
* generated arguments before passing them to `tools.execute()`.
|
|
1932
1949
|
*
|
|
1933
|
-
* @param {string} slug - The
|
|
1934
|
-
* @param {ToolGetInputParams} body - The
|
|
1935
|
-
* @
|
|
1950
|
+
* @param {string} slug - The slug of the tool to generate arguments for
|
|
1951
|
+
* @param {ToolGetInputParams} body - The generation request
|
|
1952
|
+
* @param {string} body.text - What you want the tool to do, in natural language
|
|
1953
|
+
* @param {string} [body.custom_description] - Extra context about the tool for the LLM
|
|
1954
|
+
* @param {string} [body.system_prompt] - System prompt that steers the LLM
|
|
1955
|
+
* @param {string} [body.version] - Tool version to generate arguments for
|
|
1956
|
+
* @returns {Promise<ToolGetInputResponse>} The generated `arguments`, or an `error` when generation fails
|
|
1936
1957
|
*
|
|
1937
1958
|
* @example
|
|
1938
1959
|
* ```typescript
|
|
1939
|
-
*
|
|
1940
|
-
*
|
|
1941
|
-
*
|
|
1960
|
+
* const { arguments: args, error } = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
|
|
1961
|
+
* text: 'Open an issue in composiohq/composio titled "Docs typo" describing the broken link',
|
|
1962
|
+
* version: '20250909_00',
|
|
1942
1963
|
* });
|
|
1943
|
-
*
|
|
1964
|
+
* if (error) throw new Error(error);
|
|
1965
|
+
* console.log(args); // { owner: 'composiohq', repo: 'composio', title: 'Docs typo', ... }
|
|
1944
1966
|
* ```
|
|
1945
1967
|
*/
|
|
1946
1968
|
async getInput(slug, body, requestOptions) {
|
|
1947
1969
|
return withCancellation(() => this.client.tools.getInput(slug, body, requestOptions), requestOptions?.signal);
|
|
1948
1970
|
}
|
|
1949
1971
|
/**
|
|
1950
|
-
*
|
|
1972
|
+
* Sends an HTTP request to a toolkit's API, authenticated as a connected account.
|
|
1951
1973
|
*
|
|
1952
|
-
*
|
|
1953
|
-
*
|
|
1974
|
+
* Use it to call an endpoint that no predefined tool covers. Composio injects the
|
|
1975
|
+
* connected account's credentials on the server side.
|
|
1954
1976
|
*
|
|
1955
|
-
*
|
|
1956
|
-
*
|
|
1977
|
+
* A relative `endpoint` is appended to the toolkit's base URL, and that base URL can
|
|
1978
|
+
* already include a path. Google Calendar's base URL is
|
|
1979
|
+
* `https://www.googleapis.com/calendar/v3`, so pass `/users/me/calendarList`, not
|
|
1980
|
+
* `/calendar/v3/users/me/calendarList` (which resolves to `/calendar/v3/calendar/v3/...`
|
|
1981
|
+
* and returns a 404 from Google). An absolute URL on the same domain is sent as-is.
|
|
1982
|
+
*
|
|
1983
|
+
* @param {ToolProxyParams} body - The proxy request
|
|
1984
|
+
* @param {string} body.endpoint - Path relative to the toolkit's base URL, or an absolute URL
|
|
1985
|
+
* @param {'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'} body.method - HTTP method
|
|
1986
|
+
* @param {string} [body.connectedAccountId] - The connected account to authenticate as
|
|
1987
|
+
* @param {unknown} [body.body] - JSON request body
|
|
1988
|
+
* @param {Array<{ in: 'query' | 'header'; name: string; value: string | number }>} [body.parameters] - Extra query parameters or headers
|
|
1989
|
+
* @returns {Promise<ToolProxyResponse>} The upstream status, headers, and parsed body
|
|
1957
1990
|
*
|
|
1958
1991
|
* @example
|
|
1959
1992
|
* ```typescript
|
|
1960
|
-
* //
|
|
1961
|
-
* const
|
|
1962
|
-
*
|
|
1963
|
-
*
|
|
1964
|
-
*
|
|
1965
|
-
*
|
|
1966
|
-
* method: 'GET'
|
|
1967
|
-
* }
|
|
1993
|
+
* // Google Calendar's base URL is https://www.googleapis.com/calendar/v3
|
|
1994
|
+
* const { status, data } = await composio.tools.proxyExecute({
|
|
1995
|
+
* endpoint: '/users/me/calendarList',
|
|
1996
|
+
* method: 'GET',
|
|
1997
|
+
* connectedAccountId: 'ca_...',
|
|
1998
|
+
* parameters: [{ in: 'query', name: 'maxResults', value: 10 }],
|
|
1968
1999
|
* });
|
|
1969
|
-
* console.log(
|
|
2000
|
+
* console.log(status, data);
|
|
1970
2001
|
* ```
|
|
1971
2002
|
*/
|
|
1972
2003
|
async proxyExecute(body, requestOptions) {
|
|
@@ -2017,6 +2048,12 @@ const ToolkitsListParamsSchema = z$1.object({
|
|
|
2017
2048
|
limit: z$1.number().optional()
|
|
2018
2049
|
});
|
|
2019
2050
|
/**
|
|
2051
|
+
* Toolkit getMany params — the slugs to fetch plus the same filters `list`
|
|
2052
|
+
* accepts.
|
|
2053
|
+
*/
|
|
2054
|
+
const ToolkitGetManySlugsSchema = z$1.array(z$1.string().min(1)).min(1);
|
|
2055
|
+
const ToolkitsGetManyParamsSchema = ToolkitsListParamsSchema;
|
|
2056
|
+
/**
|
|
2020
2057
|
* Toolkits response
|
|
2021
2058
|
*/
|
|
2022
2059
|
const ToolKitMetaSchema = z$1.object({
|
|
@@ -2052,11 +2089,41 @@ const ToolkitAuthFieldSchema = z$1.object({
|
|
|
2052
2089
|
required: z$1.boolean(),
|
|
2053
2090
|
name: z$1.string(),
|
|
2054
2091
|
type: z$1.string(),
|
|
2055
|
-
default: z$1.string().nullable().optional()
|
|
2092
|
+
default: z$1.string().nullable().optional(),
|
|
2093
|
+
/**
|
|
2094
|
+
* Whether this field holds a secret/credential value. Clients use it to
|
|
2095
|
+
* decide whether to mask the input when collecting the value in their own
|
|
2096
|
+
* UI. The property is absent when the API omits the flag for the field.
|
|
2097
|
+
*/
|
|
2098
|
+
isSecret: z$1.boolean().optional(),
|
|
2099
|
+
/**
|
|
2100
|
+
* The legacy template name the API reports for this field, mapped from
|
|
2101
|
+
* `legacy_template_name`. The API declares it as an optional string without
|
|
2102
|
+
* further documenting its semantics.
|
|
2103
|
+
*/
|
|
2104
|
+
legacyTemplateName: z$1.string().optional(),
|
|
2105
|
+
/**
|
|
2106
|
+
* Whether the hosted connect flow shows this field to the end user, mapped
|
|
2107
|
+
* from `user_visible`. A field with `false` is never required: its `default`
|
|
2108
|
+
* applies unless the auth config supplies a value. Absent when the API omits
|
|
2109
|
+
* the flag.
|
|
2110
|
+
*/
|
|
2111
|
+
userVisible: z$1.boolean().optional()
|
|
2056
2112
|
});
|
|
2057
2113
|
const ToolkitAuthConfigDetailsSchema = z$1.object({
|
|
2058
2114
|
name: z$1.string(),
|
|
2059
2115
|
mode: z$1.string(),
|
|
2116
|
+
/**
|
|
2117
|
+
* URL to a page where users can obtain or configure credentials for this
|
|
2118
|
+
* authentication method, e.g. `https://github.com/settings/tokens`.
|
|
2119
|
+
*/
|
|
2120
|
+
authHintUrl: z$1.string().nullable().optional(),
|
|
2121
|
+
/**
|
|
2122
|
+
* OAuth scopes always requested for this auth method regardless of the
|
|
2123
|
+
* tool-specific scopes, such as token refresh (`offline_access`) and identity
|
|
2124
|
+
* scopes. Mapped from `required_scopes`; absent when the API omits it.
|
|
2125
|
+
*/
|
|
2126
|
+
requiredScopes: z$1.array(z$1.string()).optional(),
|
|
2060
2127
|
fields: z$1.object({
|
|
2061
2128
|
authConfigCreation: z$1.object({
|
|
2062
2129
|
optional: z$1.array(ToolkitAuthFieldSchema),
|
|
@@ -2092,6 +2159,108 @@ const ToolkitRetrieveCategoriesResponseSchema = z$1.object({
|
|
|
2092
2159
|
nextCursor: z$1.string().nullable(),
|
|
2093
2160
|
totalPages: z$1.number()
|
|
2094
2161
|
});
|
|
2162
|
+
/**
|
|
2163
|
+
* Toolkit changelog response
|
|
2164
|
+
*/
|
|
2165
|
+
const ToolkitVersionChangelogSchema = z$1.object({
|
|
2166
|
+
version: z$1.string(),
|
|
2167
|
+
changelog: z$1.string()
|
|
2168
|
+
});
|
|
2169
|
+
const ToolkitChangelogItemSchema = z$1.object({
|
|
2170
|
+
slug: z$1.string(),
|
|
2171
|
+
name: z$1.string(),
|
|
2172
|
+
displayName: z$1.string(),
|
|
2173
|
+
/** Most recent versions first; the API returns up to the last 10 per toolkit. */
|
|
2174
|
+
versions: z$1.array(ToolkitVersionChangelogSchema)
|
|
2175
|
+
});
|
|
2176
|
+
const ToolkitChangelogResponseSchema = z$1.object({ items: z$1.array(ToolkitChangelogItemSchema) });
|
|
2177
|
+
/**
|
|
2178
|
+
* Params for `composio.toolkits.recommendScopes()`.
|
|
2179
|
+
* **Experimental — shape may change in future releases.**
|
|
2180
|
+
*/
|
|
2181
|
+
const ToolkitRecommendScopesParamsSchema = z$1.object({
|
|
2182
|
+
/** Tool slugs to cover. Pass `[]` to cover every tool in the toolkit. */
|
|
2183
|
+
tools: z$1.array(z$1.string()),
|
|
2184
|
+
/** Auth scheme the connection will use. The API defaults to `OAUTH2`. */
|
|
2185
|
+
authScheme: AuthSchemeEnum.optional(),
|
|
2186
|
+
/** Toolkit version to compute from. The API defaults to the latest published version. */
|
|
2187
|
+
toolkitVersion: z$1.string().min(1).optional(),
|
|
2188
|
+
/**
|
|
2189
|
+
* Context the scopes will be granted in, as dimension → selected value,
|
|
2190
|
+
* for example `{ account_type: 'Google Workspace' }`. Discover the
|
|
2191
|
+
* dimensions with `composio.toolkits.listGrantContexts()`.
|
|
2192
|
+
*/
|
|
2193
|
+
grantContext: z$1.record(z$1.string(), z$1.string()).optional(),
|
|
2194
|
+
/** Scopes the recommendation must include, whether or not the tools need them. */
|
|
2195
|
+
include: z$1.array(z$1.string()).optional(),
|
|
2196
|
+
/** Scopes the recommendation must not include; the API picks documented alternatives or fails. */
|
|
2197
|
+
exclude: z$1.array(z$1.string()).optional(),
|
|
2198
|
+
/** Scopes your OAuth app can request. The recommendation never goes outside this list. */
|
|
2199
|
+
availableScopes: z$1.array(z$1.string()).optional()
|
|
2200
|
+
});
|
|
2201
|
+
const ToolkitConditionalScopeSchema = z$1.object({
|
|
2202
|
+
/** The scope needed only when the `when` guard matches. */
|
|
2203
|
+
scope: z$1.string(),
|
|
2204
|
+
/** Input field name → qualifying values. Any value matches within a field; all fields must match. */
|
|
2205
|
+
when: z$1.record(z$1.string(), z$1.array(z$1.string())),
|
|
2206
|
+
/** Tool slugs that need this scope under the guard. */
|
|
2207
|
+
for: z$1.array(z$1.string())
|
|
2208
|
+
});
|
|
2209
|
+
/**
|
|
2210
|
+
* Response of `composio.toolkits.recommendScopes()`.
|
|
2211
|
+
* **Experimental — shape may change in future releases.**
|
|
2212
|
+
*/
|
|
2213
|
+
const ToolkitRecommendScopesResponseSchema = z$1.object({
|
|
2214
|
+
/** Auth scheme the recommendation was computed under. */
|
|
2215
|
+
authScheme: z$1.string(),
|
|
2216
|
+
/** Concrete toolkit version the answer was computed from; pass it back as `toolkitVersion` to pin. */
|
|
2217
|
+
toolkitVersion: z$1.string(),
|
|
2218
|
+
/** The effective grant context: the toolkit default overlaid with your overrides. */
|
|
2219
|
+
grantContext: z$1.record(z$1.string(), z$1.string()),
|
|
2220
|
+
scopes: z$1.object({
|
|
2221
|
+
/** Narrowest documented option per requirement. */
|
|
2222
|
+
leastPrivilege: z$1.array(z$1.string()),
|
|
2223
|
+
/** Smallest scope set covering all requirements. */
|
|
2224
|
+
fewest: z$1.array(z$1.string()),
|
|
2225
|
+
/**
|
|
2226
|
+
* Scopes needed only for particular call-time inputs. Both lists above
|
|
2227
|
+
* already include them, so a caller that knows its inputs may drop the rest.
|
|
2228
|
+
*/
|
|
2229
|
+
conditional: z$1.array(ToolkitConditionalScopeSchema)
|
|
2230
|
+
})
|
|
2231
|
+
});
|
|
2232
|
+
/**
|
|
2233
|
+
* Params for `composio.toolkits.listGrantContexts()`.
|
|
2234
|
+
* **Experimental — shape may change in future releases.**
|
|
2235
|
+
*/
|
|
2236
|
+
const ToolkitListGrantContextsParamsSchema = z$1.object({
|
|
2237
|
+
/** Auth scheme the connection will use. The API defaults to `OAUTH2`. */
|
|
2238
|
+
authScheme: AuthSchemeEnum.optional(),
|
|
2239
|
+
/** Toolkit version to read the scope catalog from. The API defaults to the latest published version. */
|
|
2240
|
+
toolkitVersion: z$1.string().min(1).optional()
|
|
2241
|
+
});
|
|
2242
|
+
const ToolkitGrantContextDimensionSchema = z$1.object({
|
|
2243
|
+
/** Dimension name to use as a `grantContext` key. */
|
|
2244
|
+
dimension: z$1.string(),
|
|
2245
|
+
/** What the dimension means and when to pass it. */
|
|
2246
|
+
description: z$1.string(),
|
|
2247
|
+
/** Values the dimension can take. */
|
|
2248
|
+
values: z$1.array(z$1.string())
|
|
2249
|
+
});
|
|
2250
|
+
/**
|
|
2251
|
+
* Response of `composio.toolkits.listGrantContexts()`.
|
|
2252
|
+
* **Experimental — shape may change in future releases.**
|
|
2253
|
+
*/
|
|
2254
|
+
const ToolkitListGrantContextsResponseSchema = z$1.object({
|
|
2255
|
+
/** Auth scheme whose scope catalog the dimensions were read from. */
|
|
2256
|
+
authScheme: z$1.string(),
|
|
2257
|
+
/** Concrete toolkit version the answer was computed from. */
|
|
2258
|
+
toolkitVersion: z$1.string(),
|
|
2259
|
+
/** Dimensions the toolkit accepts in `grantContext`; empty when no scope depends on one. */
|
|
2260
|
+
grantContextDimensions: z$1.array(ToolkitGrantContextDimensionSchema),
|
|
2261
|
+
/** The grant context assumed when you pass none. */
|
|
2262
|
+
defaultGrantContext: z$1.record(z$1.string(), z$1.string())
|
|
2263
|
+
});
|
|
2095
2264
|
const ToolkitAuthFieldsResponseSchema = z$1.array(ToolkitAuthFieldSchema.extend({ required: z$1.boolean().optional() }));
|
|
2096
2265
|
|
|
2097
2266
|
//#endregion
|
|
@@ -2252,7 +2421,8 @@ var AuthConfigs = class {
|
|
|
2252
2421
|
show_disabled: parsedQuery?.showDisabled,
|
|
2253
2422
|
toolkit_slug: parsedQuery?.toolkit
|
|
2254
2423
|
};
|
|
2255
|
-
|
|
2424
|
+
const result = await withCancellation(() => this.client.authConfigs.list(listParams, requestOptions), requestOptions?.signal);
|
|
2425
|
+
return transformAuthConfigListResponse(result);
|
|
2256
2426
|
}
|
|
2257
2427
|
/**
|
|
2258
2428
|
* Create a new auth config
|
|
@@ -2296,7 +2466,8 @@ var AuthConfigs = class {
|
|
|
2296
2466
|
tool_access_config: parsedOptions.data.toolAccessConfig ? { tools_for_connected_account_creation: parsedOptions.data.toolAccessConfig.toolsForConnectedAccountCreation } : void 0
|
|
2297
2467
|
}
|
|
2298
2468
|
};
|
|
2299
|
-
|
|
2469
|
+
const result = await withCancellation(() => this.client.authConfigs.create(createBody, requestOptions), requestOptions?.signal);
|
|
2470
|
+
return transformCreateAuthConfigResponse(result);
|
|
2300
2471
|
}
|
|
2301
2472
|
/**
|
|
2302
2473
|
* Retrieves a specific authentication configuration by its ID.
|
|
@@ -2318,7 +2489,8 @@ var AuthConfigs = class {
|
|
|
2318
2489
|
* ```
|
|
2319
2490
|
*/
|
|
2320
2491
|
async get(nanoid, requestOptions) {
|
|
2321
|
-
|
|
2492
|
+
const result = await withCancellation(() => this.client.authConfigs.retrieve(nanoid, requestOptions), requestOptions?.signal);
|
|
2493
|
+
return transformAuthConfigRetrieveResponse(result);
|
|
2322
2494
|
}
|
|
2323
2495
|
/**
|
|
2324
2496
|
* Updates an existing authentication configuration.
|
|
@@ -2683,6 +2855,10 @@ const CreateConnectedAccountLinkOptionsSchema = z$1.object({
|
|
|
2683
2855
|
const CreateConnectedAccountLinkResponseSchema = z$1.object({ redirectUrl: z$1.string() });
|
|
2684
2856
|
const ConnectedAccountRefreshOptionsSchema = z$1.object({
|
|
2685
2857
|
redirectUrl: z$1.string().optional(),
|
|
2858
|
+
/**
|
|
2859
|
+
* @deprecated The Composio API no longer accepts this field. It is ignored
|
|
2860
|
+
* and `refresh()` logs a warning when it is set.
|
|
2861
|
+
*/
|
|
2686
2862
|
validateCredentials: z$1.boolean().optional()
|
|
2687
2863
|
});
|
|
2688
2864
|
const UpdateConnectedAccountParamsSchema = z$1.object({ enabled: z$1.boolean() });
|
|
@@ -2699,6 +2875,44 @@ const UpdateConnectedAccountParamsSchema = z$1.object({ enabled: z$1.boolean() }
|
|
|
2699
2875
|
* empty object is rejected as a no-op.
|
|
2700
2876
|
*/
|
|
2701
2877
|
const UpdateConnectedAccountAclParamsSchema = ConnectedAccountAclConfigSchema.refine((acl) => acl.allowAllUsers !== void 0 || acl.allowedUserIds !== void 0 || acl.notAllowedUserIds !== void 0, { message: "At least one of allowAllUsers, allowedUserIds, or notAllowedUserIds must be provided" });
|
|
2878
|
+
/**
|
|
2879
|
+
* Response of `composio.connectedAccounts.revoke()`.
|
|
2880
|
+
*/
|
|
2881
|
+
const ConnectedAccountRevokedTokenSchema = z$1.enum([
|
|
2882
|
+
"access_token",
|
|
2883
|
+
"refresh_token",
|
|
2884
|
+
"credential"
|
|
2885
|
+
]);
|
|
2886
|
+
const ConnectedAccountRevokeResponseSchema = z$1.object({
|
|
2887
|
+
/**
|
|
2888
|
+
* Tokens revoked at the provider on this call. An empty array means the
|
|
2889
|
+
* connection was already revoked (no upstream dispatch).
|
|
2890
|
+
*/
|
|
2891
|
+
revokedTokens: z$1.array(ConnectedAccountRevokedTokenSchema),
|
|
2892
|
+
connectedAccount: z$1.object({
|
|
2893
|
+
id: z$1.string(),
|
|
2894
|
+
/** The connection status after this call (`REVOKED` on success). */
|
|
2895
|
+
status: ConnectedAccountStatusSchema
|
|
2896
|
+
})
|
|
2897
|
+
});
|
|
2898
|
+
/**
|
|
2899
|
+
* Params for `composio.connectedAccounts.completeAuth()`.
|
|
2900
|
+
*/
|
|
2901
|
+
const ConnectedAccountCompleteAuthParamsSchema = z$1.object({
|
|
2902
|
+
/** The user the connection was initiated for. Must match the connection owner. */
|
|
2903
|
+
userId: z$1.string().min(1),
|
|
2904
|
+
/** The opaque, single-use session URI your OAuth callback verifier received. */
|
|
2905
|
+
sessionUri: z$1.string().min(1)
|
|
2906
|
+
});
|
|
2907
|
+
/**
|
|
2908
|
+
* Response of `composio.connectedAccounts.completeAuth()`.
|
|
2909
|
+
*/
|
|
2910
|
+
const ConnectedAccountCompleteAuthResponseSchema = z$1.object({
|
|
2911
|
+
/** The connection that was completed; it is now `ACTIVE`. */
|
|
2912
|
+
connectedAccountId: z$1.string(),
|
|
2913
|
+
/** The toolkit the connection belongs to. */
|
|
2914
|
+
toolkitSlug: z$1.string()
|
|
2915
|
+
});
|
|
2702
2916
|
|
|
2703
2917
|
//#endregion
|
|
2704
2918
|
//#region src/utils/transformers/connectedAccounts.ts
|
|
@@ -2772,6 +2986,21 @@ function transformConnectedAccountListResponse(response) {
|
|
|
2772
2986
|
totalPages: response.total_pages
|
|
2773
2987
|
}));
|
|
2774
2988
|
}
|
|
2989
|
+
const transformConnectedAccountRevokeResponse = (response) => {
|
|
2990
|
+
return transform(response).with(ConnectedAccountRevokeResponseSchema).using((response) => ({
|
|
2991
|
+
revokedTokens: response.revoked_tokens,
|
|
2992
|
+
connectedAccount: {
|
|
2993
|
+
id: response.connected_account.id,
|
|
2994
|
+
status: response.connected_account.status
|
|
2995
|
+
}
|
|
2996
|
+
}));
|
|
2997
|
+
};
|
|
2998
|
+
const transformConnectedAccountCompleteAuthResponse = (response) => {
|
|
2999
|
+
return transform(response).with(ConnectedAccountCompleteAuthResponseSchema).using((response) => ({
|
|
3000
|
+
connectedAccountId: response.connected_account_id,
|
|
3001
|
+
toolkitSlug: response.toolkit_slug
|
|
3002
|
+
}));
|
|
3003
|
+
};
|
|
2775
3004
|
|
|
2776
3005
|
//#endregion
|
|
2777
3006
|
//#region src/models/ConnectionRequest.ts
|
|
@@ -2870,6 +3099,440 @@ function createConnectionRequest(client, connectedAccountId, status, redirectUrl
|
|
|
2870
3099
|
};
|
|
2871
3100
|
}
|
|
2872
3101
|
|
|
3102
|
+
//#endregion
|
|
3103
|
+
//#region src/types/usage.types.ts
|
|
3104
|
+
/**
|
|
3105
|
+
* Filters shared by the usage summary and breakdown queries.
|
|
3106
|
+
* **Experimental — shape may change in future releases.**
|
|
3107
|
+
*/
|
|
3108
|
+
const UsageFiltersSchema = z$1.object({
|
|
3109
|
+
/** Only count events for these external end-user IDs (OR logic). */
|
|
3110
|
+
userId: z$1.array(z$1.string()).nullable().optional(),
|
|
3111
|
+
/** Only count events for these session IDs (OR logic). */
|
|
3112
|
+
sessionId: z$1.array(z$1.string()).nullable().optional()
|
|
3113
|
+
});
|
|
3114
|
+
/**
|
|
3115
|
+
* Params for `composio.experimental.usage.summary()`.
|
|
3116
|
+
* **Experimental — shape may change in future releases.**
|
|
3117
|
+
*/
|
|
3118
|
+
const UsageSummaryParamsSchema = z$1.object({
|
|
3119
|
+
/** Inclusive range start (Unix epoch milliseconds). Defaults to 30 days before `to`. */
|
|
3120
|
+
from: z$1.number().optional(),
|
|
3121
|
+
/** Exclusive range end (Unix epoch milliseconds). Defaults to now. */
|
|
3122
|
+
to: z$1.number().optional(),
|
|
3123
|
+
/** Restrict to these metering entity types. Omit for all types. */
|
|
3124
|
+
entityTypes: z$1.array(z$1.string()).optional(),
|
|
3125
|
+
filters: UsageFiltersSchema.optional()
|
|
3126
|
+
});
|
|
3127
|
+
const UsageOrderBySchema = z$1.enum([
|
|
3128
|
+
"key",
|
|
3129
|
+
"total_quantity",
|
|
3130
|
+
"event_count"
|
|
3131
|
+
]);
|
|
3132
|
+
const UsageOrderDirectionSchema = z$1.enum(["asc", "desc"]);
|
|
3133
|
+
/**
|
|
3134
|
+
* Params for `composio.experimental.usage.breakdown()`.
|
|
3135
|
+
* **Experimental — shape may change in future releases.**
|
|
3136
|
+
*/
|
|
3137
|
+
const UsageBreakdownParamsSchema = z$1.object({
|
|
3138
|
+
/** Inclusive range start (Unix epoch milliseconds). Defaults to 30 days before `to`. */
|
|
3139
|
+
from: z$1.number().optional(),
|
|
3140
|
+
/** Exclusive range end (Unix epoch milliseconds). Defaults to now. */
|
|
3141
|
+
to: z$1.number().optional(),
|
|
3142
|
+
/** Dimension to group by. Defaults to `tool_slug` for tool_calls and `user_id` for sessions. */
|
|
3143
|
+
groupBy: z$1.string().optional(),
|
|
3144
|
+
/** Field to order groups by. Defaults to `total_quantity`. */
|
|
3145
|
+
orderBy: UsageOrderBySchema.optional(),
|
|
3146
|
+
/** Sort direction. Defaults to `desc`. */
|
|
3147
|
+
orderDirection: UsageOrderDirectionSchema.optional(),
|
|
3148
|
+
/** Maximum number of groups to return. Defaults to 100, max 1000. */
|
|
3149
|
+
limit: z$1.number().optional(),
|
|
3150
|
+
filters: UsageFiltersSchema.optional()
|
|
3151
|
+
});
|
|
3152
|
+
const UsageEntitySummarySchema = z$1.object({
|
|
3153
|
+
unit: z$1.string(),
|
|
3154
|
+
totalQuantity: z$1.string(),
|
|
3155
|
+
eventCount: z$1.number()
|
|
3156
|
+
});
|
|
3157
|
+
const UsageSummaryResponseSchema = z$1.object({
|
|
3158
|
+
/** Aggregates keyed by metering entity type (e.g. `tool_calls`, `sessions`). */
|
|
3159
|
+
entities: z$1.record(z$1.string(), UsageEntitySummarySchema) });
|
|
3160
|
+
const UsageBreakdownGroupSchema = z$1.object({
|
|
3161
|
+
key: z$1.string(),
|
|
3162
|
+
totalQuantity: z$1.string(),
|
|
3163
|
+
eventCount: z$1.number()
|
|
3164
|
+
});
|
|
3165
|
+
const UsageBreakdownResponseSchema = z$1.object({
|
|
3166
|
+
entityType: z$1.string(),
|
|
3167
|
+
unit: z$1.string(),
|
|
3168
|
+
totalQuantity: z$1.string(),
|
|
3169
|
+
eventCount: z$1.number(),
|
|
3170
|
+
groups: z$1.array(UsageBreakdownGroupSchema)
|
|
3171
|
+
});
|
|
3172
|
+
|
|
3173
|
+
//#endregion
|
|
3174
|
+
//#region src/utils/transformers/usage.ts
|
|
3175
|
+
const transformUsageFilters = (filters) => filters ? {
|
|
3176
|
+
user_id: filters.userId,
|
|
3177
|
+
session_id: filters.sessionId
|
|
3178
|
+
} : void 0;
|
|
3179
|
+
const transformUsageSummaryParams = (params) => ({
|
|
3180
|
+
from: params.from,
|
|
3181
|
+
to: params.to,
|
|
3182
|
+
entity_types: params.entityTypes,
|
|
3183
|
+
filters: transformUsageFilters(params.filters)
|
|
3184
|
+
});
|
|
3185
|
+
const transformUsageBreakdownParams = (params) => ({
|
|
3186
|
+
from: params.from,
|
|
3187
|
+
to: params.to,
|
|
3188
|
+
group_by: params.groupBy,
|
|
3189
|
+
order_by: params.orderBy,
|
|
3190
|
+
order_direction: params.orderDirection,
|
|
3191
|
+
limit: params.limit,
|
|
3192
|
+
filters: transformUsageFilters(params.filters)
|
|
3193
|
+
});
|
|
3194
|
+
const transformUsageSummaryResponse = (response) => {
|
|
3195
|
+
return transform(response).with(UsageSummaryResponseSchema).using((response) => ({ entities: Object.fromEntries(Object.entries(response.entities).map(([entityType, entity]) => [entityType, {
|
|
3196
|
+
unit: entity.unit,
|
|
3197
|
+
totalQuantity: entity.total_quantity,
|
|
3198
|
+
eventCount: entity.event_count
|
|
3199
|
+
}])) }));
|
|
3200
|
+
};
|
|
3201
|
+
const transformUsageBreakdownResponse = (response) => {
|
|
3202
|
+
return transform(response).with(UsageBreakdownResponseSchema).using((response) => ({
|
|
3203
|
+
entityType: response.entity_type,
|
|
3204
|
+
unit: response.unit,
|
|
3205
|
+
totalQuantity: response.total_quantity,
|
|
3206
|
+
eventCount: response.event_count,
|
|
3207
|
+
groups: response.groups.map((group) => ({
|
|
3208
|
+
key: group.key,
|
|
3209
|
+
totalQuantity: group.total_quantity,
|
|
3210
|
+
eventCount: group.event_count
|
|
3211
|
+
}))
|
|
3212
|
+
}));
|
|
3213
|
+
};
|
|
3214
|
+
|
|
3215
|
+
//#endregion
|
|
3216
|
+
//#region src/models/Usage.ts
|
|
3217
|
+
/**
|
|
3218
|
+
* `composio.experimental.usage` — metering for the project the API key
|
|
3219
|
+
* belongs to. **Experimental — shape may change in future releases.**
|
|
3220
|
+
*
|
|
3221
|
+
* @example
|
|
3222
|
+
* ```typescript
|
|
3223
|
+
* const summary = await composio.experimental.usage.summary();
|
|
3224
|
+
* console.log(summary.entities.tool_calls?.totalQuantity);
|
|
3225
|
+
*
|
|
3226
|
+
* const byTool = await composio.experimental.usage.breakdown('tool_calls', {
|
|
3227
|
+
* groupBy: 'tool_slug',
|
|
3228
|
+
* limit: 10,
|
|
3229
|
+
* });
|
|
3230
|
+
* ```
|
|
3231
|
+
*/
|
|
3232
|
+
var Usage = class {
|
|
3233
|
+
client;
|
|
3234
|
+
constructor(client) {
|
|
3235
|
+
this.client = client;
|
|
3236
|
+
telemetry.instrument(this, "Usage");
|
|
3237
|
+
}
|
|
3238
|
+
/**
|
|
3239
|
+
* Usage totals per metering entity type for a time range.
|
|
3240
|
+
* **Experimental — shape may change in future releases.**
|
|
3241
|
+
*
|
|
3242
|
+
* @param {UsageSummaryParams} [params] - Optional range, `entityTypes` and filters
|
|
3243
|
+
* @returns {Promise<UsageSummaryResponse>} Totals keyed by entity type
|
|
3244
|
+
* @throws {ValidationError} If the params fail validation
|
|
3245
|
+
*
|
|
3246
|
+
* @example
|
|
3247
|
+
* ```typescript
|
|
3248
|
+
* const summary = await composio.experimental.usage.summary({
|
|
3249
|
+
* from: Date.now() - 7 * 24 * 60 * 60 * 1000,
|
|
3250
|
+
* filters: { userId: ['user_123'] },
|
|
3251
|
+
* });
|
|
3252
|
+
* ```
|
|
3253
|
+
*/
|
|
3254
|
+
async summary(params, requestOptions) {
|
|
3255
|
+
const parsedParams = UsageSummaryParamsSchema.safeParse(params ?? {});
|
|
3256
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse usage summary params", { cause: parsedParams.error });
|
|
3257
|
+
const body = transformUsageSummaryParams(parsedParams.data);
|
|
3258
|
+
const result = await withCancellation(() => this.client.project.usage.retrieveSummary(body, requestOptions), requestOptions?.signal);
|
|
3259
|
+
return transformUsageSummaryResponse(result);
|
|
3260
|
+
}
|
|
3261
|
+
/**
|
|
3262
|
+
* Usage for one metering entity type, grouped by a dimension.
|
|
3263
|
+
* **Experimental — shape may change in future releases.**
|
|
3264
|
+
*
|
|
3265
|
+
* @param {string} entityType - Entity type to break down (e.g. `tool_calls`, `sessions`)
|
|
3266
|
+
* @param {UsageBreakdownParams} [params] - Optional range, `groupBy`, ordering, `limit` and filters
|
|
3267
|
+
* @returns {Promise<UsageBreakdownResponse>} Totals plus per-group rows
|
|
3268
|
+
* @throws {ValidationError} If the params fail validation
|
|
3269
|
+
*
|
|
3270
|
+
* @example
|
|
3271
|
+
* ```typescript
|
|
3272
|
+
* const byUser = await composio.experimental.usage.breakdown('sessions', {
|
|
3273
|
+
* groupBy: 'user_id',
|
|
3274
|
+
* orderBy: 'event_count',
|
|
3275
|
+
* });
|
|
3276
|
+
* ```
|
|
3277
|
+
*/
|
|
3278
|
+
async breakdown(entityType, params, requestOptions) {
|
|
3279
|
+
const parsedParams = UsageBreakdownParamsSchema.safeParse(params ?? {});
|
|
3280
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse usage breakdown params", { cause: parsedParams.error });
|
|
3281
|
+
const body = transformUsageBreakdownParams(parsedParams.data);
|
|
3282
|
+
const result = await withCancellation(() => this.client.project.usage.retrieve(entityType, body, requestOptions), requestOptions?.signal);
|
|
3283
|
+
return transformUsageBreakdownResponse(result);
|
|
3284
|
+
}
|
|
3285
|
+
};
|
|
3286
|
+
|
|
3287
|
+
//#endregion
|
|
3288
|
+
//#region src/types/customToolkits.types.ts
|
|
3289
|
+
/**
|
|
3290
|
+
* How end users authenticate to a custom toolkit.
|
|
3291
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3292
|
+
*/
|
|
3293
|
+
const CustomToolkitAuthSchemeSchema = z$1.discriminatedUnion("mode", [
|
|
3294
|
+
z$1.object({ mode: z$1.literal("NO_AUTH") }),
|
|
3295
|
+
z$1.object({
|
|
3296
|
+
mode: z$1.literal("API_KEY"),
|
|
3297
|
+
/**
|
|
3298
|
+
* Headers sent with each request. Write `{{generic_api_key}}` where the
|
|
3299
|
+
* end user's API key goes, for example
|
|
3300
|
+
* `{ Authorization: 'Bearer {{generic_api_key}}' }`.
|
|
3301
|
+
*/
|
|
3302
|
+
headers: z$1.record(z$1.string(), z$1.string()),
|
|
3303
|
+
/** End-user copy for the API key input on the connect page. */
|
|
3304
|
+
apiKeyField: z$1.object({
|
|
3305
|
+
displayName: z$1.string().min(1).max(100).optional(),
|
|
3306
|
+
description: z$1.string().min(1).max(500).optional()
|
|
3307
|
+
}).optional()
|
|
3308
|
+
}),
|
|
3309
|
+
z$1.object({
|
|
3310
|
+
mode: z$1.literal("DCR_OAUTH"),
|
|
3311
|
+
/**
|
|
3312
|
+
* Where to fetch the full auth scheme, usually the
|
|
3313
|
+
* `/.well-known/oauth-authorization-server` path of your MCP URL.
|
|
3314
|
+
*/
|
|
3315
|
+
discoveryUrl: z$1.string().url()
|
|
3316
|
+
})
|
|
3317
|
+
]);
|
|
3318
|
+
/**
|
|
3319
|
+
* Params for `composio.experimental.customToolkits.upsert()`.
|
|
3320
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3321
|
+
*/
|
|
3322
|
+
const CustomToolkitUpsertParamsSchema = z$1.object({
|
|
3323
|
+
/**
|
|
3324
|
+
* Letters, digits, underscores or spaces, up to 30 characters. The API
|
|
3325
|
+
* prefixes it with `CUSTOM_` and turns spaces into underscores.
|
|
3326
|
+
*/
|
|
3327
|
+
slug: z$1.string().min(1).max(30).regex(/^[a-zA-Z0-9_\s]+$/),
|
|
3328
|
+
toolkitConfig: z$1.object({
|
|
3329
|
+
/** Human-readable toolkit name. */
|
|
3330
|
+
name: z$1.string().min(1).max(200),
|
|
3331
|
+
/** The app URL. For an MCP app, the MCP server URL. */
|
|
3332
|
+
appUrl: z$1.string().url(),
|
|
3333
|
+
/** Square PNG or JPEG logo (256-1024px, max 3MB), base64-encoded. Defaults to the Composio logo. */
|
|
3334
|
+
logoFile: z$1.object({
|
|
3335
|
+
content: z$1.string().min(1),
|
|
3336
|
+
mimeType: z$1.enum(["image/png", "image/jpeg"])
|
|
3337
|
+
}).optional(),
|
|
3338
|
+
/** At least one scheme. The schemes cannot change once the toolkit exists. */
|
|
3339
|
+
authSchemes: z$1.array(CustomToolkitAuthSchemeSchema).min(1)
|
|
3340
|
+
})
|
|
3341
|
+
});
|
|
3342
|
+
const CustomToolkitUpsertResponseSchema = z$1.object({
|
|
3343
|
+
/** Slug of the created or updated toolkit. */
|
|
3344
|
+
slug: z$1.string() });
|
|
3345
|
+
/**
|
|
3346
|
+
* Params for `composio.experimental.customToolkits.sync()`.
|
|
3347
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3348
|
+
*/
|
|
3349
|
+
const CustomToolkitSyncParamsSchema = z$1.object({
|
|
3350
|
+
/** Connected account to use when fetching the remote tool definitions. */
|
|
3351
|
+
connectedAccountId: z$1.string().optional() });
|
|
3352
|
+
const CustomToolkitSyncResponseSchema = z$1.object({
|
|
3353
|
+
slug: z$1.string(),
|
|
3354
|
+
/** Toolkit version after the sync. */
|
|
3355
|
+
version: z$1.string(),
|
|
3356
|
+
/** Number of tools synced. */
|
|
3357
|
+
syncedCount: z$1.number()
|
|
3358
|
+
});
|
|
3359
|
+
const CustomToolkitDeleteResponseSchema = z$1.object({
|
|
3360
|
+
/** Slug of the deleted toolkit. */
|
|
3361
|
+
slug: z$1.string(),
|
|
3362
|
+
deleted: z$1.boolean(),
|
|
3363
|
+
/** Background jobs revoking the credentials of the toolkit's connected accounts. */
|
|
3364
|
+
revokeJobIds: z$1.array(z$1.string()),
|
|
3365
|
+
authConfigsDeleted: z$1.number(),
|
|
3366
|
+
connectedAccountsDeleted: z$1.number()
|
|
3367
|
+
});
|
|
3368
|
+
|
|
3369
|
+
//#endregion
|
|
3370
|
+
//#region src/utils/transformers/customToolkits.ts
|
|
3371
|
+
const transformCustomToolkitAuthScheme = (scheme) => {
|
|
3372
|
+
switch (scheme.mode) {
|
|
3373
|
+
case "NO_AUTH": return { mode: "NO_AUTH" };
|
|
3374
|
+
case "API_KEY": return {
|
|
3375
|
+
mode: "API_KEY",
|
|
3376
|
+
headers: scheme.headers,
|
|
3377
|
+
api_key_field: scheme.apiKeyField && {
|
|
3378
|
+
display_name: scheme.apiKeyField.displayName,
|
|
3379
|
+
description: scheme.apiKeyField.description
|
|
3380
|
+
}
|
|
3381
|
+
};
|
|
3382
|
+
case "DCR_OAUTH": return {
|
|
3383
|
+
mode: "DCR_OAUTH",
|
|
3384
|
+
discovery_url: scheme.discoveryUrl
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
};
|
|
3388
|
+
const transformCustomToolkitUpsertParams = (params) => ({
|
|
3389
|
+
slug: params.slug,
|
|
3390
|
+
toolkit_config: {
|
|
3391
|
+
name: params.toolkitConfig.name,
|
|
3392
|
+
app_url: params.toolkitConfig.appUrl,
|
|
3393
|
+
logo_file: params.toolkitConfig.logoFile && {
|
|
3394
|
+
content: params.toolkitConfig.logoFile.content,
|
|
3395
|
+
mime_type: params.toolkitConfig.logoFile.mimeType
|
|
3396
|
+
},
|
|
3397
|
+
auth_schemes: params.toolkitConfig.authSchemes.map(transformCustomToolkitAuthScheme)
|
|
3398
|
+
}
|
|
3399
|
+
});
|
|
3400
|
+
const transformCustomToolkitUpsertResponse = (response) => {
|
|
3401
|
+
return transform(response).with(CustomToolkitUpsertResponseSchema).using((response) => ({ slug: response.slug }));
|
|
3402
|
+
};
|
|
3403
|
+
const transformCustomToolkitSyncParams = (slug, params) => ({
|
|
3404
|
+
slug,
|
|
3405
|
+
connected_account_id: params.connectedAccountId
|
|
3406
|
+
});
|
|
3407
|
+
const transformCustomToolkitSyncResponse = (response) => {
|
|
3408
|
+
return transform(response).with(CustomToolkitSyncResponseSchema).using((response) => ({
|
|
3409
|
+
slug: response.slug,
|
|
3410
|
+
version: response.version,
|
|
3411
|
+
syncedCount: response.synced_count
|
|
3412
|
+
}));
|
|
3413
|
+
};
|
|
3414
|
+
const transformCustomToolkitDeleteResponse = (response) => {
|
|
3415
|
+
return transform(response).with(CustomToolkitDeleteResponseSchema).using((response) => ({
|
|
3416
|
+
slug: response.slug,
|
|
3417
|
+
deleted: response.deleted,
|
|
3418
|
+
revokeJobIds: response.revoke_job_ids,
|
|
3419
|
+
authConfigsDeleted: response.auth_configs_deleted,
|
|
3420
|
+
connectedAccountsDeleted: response.connected_accounts_deleted
|
|
3421
|
+
}));
|
|
3422
|
+
};
|
|
3423
|
+
|
|
3424
|
+
//#endregion
|
|
3425
|
+
//#region src/models/CustomToolkits.ts
|
|
3426
|
+
/**
|
|
3427
|
+
* `composio.experimental.customToolkits` — toolkits your project registers
|
|
3428
|
+
* from its own app or MCP server, with their own auth configs and connected
|
|
3429
|
+
* accounts. **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3430
|
+
*
|
|
3431
|
+
* These live on the Composio platform. They are unrelated to the in-process
|
|
3432
|
+
* toolkits built with `experimental_createToolkit()`, which run inside your
|
|
3433
|
+
* application.
|
|
3434
|
+
*
|
|
3435
|
+
* @example
|
|
3436
|
+
* ```typescript
|
|
3437
|
+
* const { slug } = await composio.experimental.customToolkits.upsert({
|
|
3438
|
+
* slug: 'MY_TOOLKIT',
|
|
3439
|
+
* toolkitConfig: {
|
|
3440
|
+
* name: 'My Toolkit',
|
|
3441
|
+
* appUrl: 'https://mcp.example.com/mcp',
|
|
3442
|
+
* authSchemes: [{ mode: 'DCR_OAUTH', discoveryUrl: 'https://mcp.example.com/.well-known/oauth-authorization-server' }],
|
|
3443
|
+
* },
|
|
3444
|
+
* });
|
|
3445
|
+
* await composio.experimental.customToolkits.sync(slug);
|
|
3446
|
+
* ```
|
|
3447
|
+
*/
|
|
3448
|
+
var CustomToolkits = class {
|
|
3449
|
+
client;
|
|
3450
|
+
constructor(client) {
|
|
3451
|
+
this.client = client;
|
|
3452
|
+
telemetry.instrument(this, "CustomToolkits");
|
|
3453
|
+
}
|
|
3454
|
+
/**
|
|
3455
|
+
* Creates a custom toolkit, or updates its display metadata (name, API key
|
|
3456
|
+
* field copy) when the project already owns a toolkit with this slug.
|
|
3457
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3458
|
+
*
|
|
3459
|
+
* `appUrl` and `authSchemes` cannot change on an existing toolkit:
|
|
3460
|
+
* re-sending them unchanged is a no-op, and changing them fails with a 409.
|
|
3461
|
+
* Delete and re-register the toolkit instead, which revokes its connections.
|
|
3462
|
+
*
|
|
3463
|
+
* @param {CustomToolkitUpsertParams} params - The slug and toolkit configuration
|
|
3464
|
+
* @returns {Promise<CustomToolkitUpsertResponse>} The toolkit's slug
|
|
3465
|
+
* @throws {ValidationError} If the params fail validation
|
|
3466
|
+
*
|
|
3467
|
+
* @example
|
|
3468
|
+
* ```typescript
|
|
3469
|
+
* await composio.experimental.customToolkits.upsert({
|
|
3470
|
+
* slug: 'INTERNAL_API',
|
|
3471
|
+
* toolkitConfig: {
|
|
3472
|
+
* name: 'Internal API',
|
|
3473
|
+
* appUrl: 'https://mcp.internal.example.com/mcp',
|
|
3474
|
+
* authSchemes: [
|
|
3475
|
+
* { mode: 'API_KEY', headers: { Authorization: 'Bearer {{generic_api_key}}' } },
|
|
3476
|
+
* ],
|
|
3477
|
+
* },
|
|
3478
|
+
* });
|
|
3479
|
+
* ```
|
|
3480
|
+
*/
|
|
3481
|
+
async upsert(params, requestOptions) {
|
|
3482
|
+
const parsedParams = CustomToolkitUpsertParamsSchema.safeParse(params);
|
|
3483
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse custom toolkit upsert params", { cause: parsedParams.error });
|
|
3484
|
+
const body = transformCustomToolkitUpsertParams(parsedParams.data);
|
|
3485
|
+
const result = await withCancellation(() => this.client.custom.upsert(body, requestOptions), requestOptions?.signal);
|
|
3486
|
+
return transformCustomToolkitUpsertResponse(result);
|
|
3487
|
+
}
|
|
3488
|
+
/**
|
|
3489
|
+
* Re-fetches the tool definitions of a custom toolkit from its remote MCP
|
|
3490
|
+
* server. Call it when automatic sync fails or the remote tools change.
|
|
3491
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3492
|
+
*
|
|
3493
|
+
* @param {string} slug - The custom toolkit slug (`CUSTOM_...`)
|
|
3494
|
+
* @param {CustomToolkitSyncParams} [params] - Optional connected account to fetch the definitions with
|
|
3495
|
+
* @returns {Promise<CustomToolkitSyncResponse>} The toolkit version and number of tools synced
|
|
3496
|
+
* @throws {ValidationError} If the params fail validation
|
|
3497
|
+
*
|
|
3498
|
+
* @example
|
|
3499
|
+
* ```typescript
|
|
3500
|
+
* const { version, syncedCount } = await composio.experimental.customToolkits.sync(
|
|
3501
|
+
* 'CUSTOM_MY_TOOLKIT',
|
|
3502
|
+
* { connectedAccountId: 'ca_abc123' }
|
|
3503
|
+
* );
|
|
3504
|
+
* ```
|
|
3505
|
+
*/
|
|
3506
|
+
async sync(slug, params, requestOptions) {
|
|
3507
|
+
const parsedParams = CustomToolkitSyncParamsSchema.safeParse(params ?? {});
|
|
3508
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse custom toolkit sync params", { cause: parsedParams.error });
|
|
3509
|
+
const body = transformCustomToolkitSyncParams(slug, parsedParams.data);
|
|
3510
|
+
const result = await withCancellation(() => this.client.custom.sync(body, requestOptions), requestOptions?.signal);
|
|
3511
|
+
return transformCustomToolkitSyncResponse(result);
|
|
3512
|
+
}
|
|
3513
|
+
/**
|
|
3514
|
+
* Deletes a custom toolkit owned by the project, with its tools, auth
|
|
3515
|
+
* configs and connected accounts. The credentials behind those connected
|
|
3516
|
+
* accounts are revoked in background jobs (`revokeJobIds`).
|
|
3517
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3518
|
+
*
|
|
3519
|
+
* Composio-managed toolkits cannot be deleted; the API answers 403.
|
|
3520
|
+
*
|
|
3521
|
+
* @param {string} slug - The custom toolkit slug (`CUSTOM_...`)
|
|
3522
|
+
* @returns {Promise<CustomToolkitDeleteResponse>} What was deleted
|
|
3523
|
+
*
|
|
3524
|
+
* @example
|
|
3525
|
+
* ```typescript
|
|
3526
|
+
* const result = await composio.experimental.customToolkits.delete('CUSTOM_MY_TOOLKIT');
|
|
3527
|
+
* console.log(result.connectedAccountsDeleted);
|
|
3528
|
+
* ```
|
|
3529
|
+
*/
|
|
3530
|
+
async delete(slug, requestOptions) {
|
|
3531
|
+
const result = await withCancellation(() => this.client.custom.deleteToolkit(slug, requestOptions), requestOptions?.signal);
|
|
3532
|
+
return transformCustomToolkitDeleteResponse(result);
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
|
|
2873
3536
|
//#endregion
|
|
2874
3537
|
//#region src/models/Experimental.ts
|
|
2875
3538
|
/**
|
|
@@ -2935,8 +3598,31 @@ async function updateConnectedAccountAcl(client, nanoid, params) {
|
|
|
2935
3598
|
}
|
|
2936
3599
|
var Experimental = class {
|
|
2937
3600
|
client;
|
|
3601
|
+
/**
|
|
3602
|
+
* Project-scoped usage metering (`summary()` / `breakdown()`).
|
|
3603
|
+
* **Experimental — shape may change in future releases.**
|
|
3604
|
+
*
|
|
3605
|
+
* @example
|
|
3606
|
+
* ```typescript
|
|
3607
|
+
* const summary = await composio.experimental.usage.summary();
|
|
3608
|
+
* const byTool = await composio.experimental.usage.breakdown('tool_calls');
|
|
3609
|
+
* ```
|
|
3610
|
+
*/
|
|
3611
|
+
usage;
|
|
3612
|
+
/**
|
|
3613
|
+
* Register and manage project-owned custom toolkits (`upsert()` / `sync()` / `delete()`).
|
|
3614
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
3615
|
+
*
|
|
3616
|
+
* @example
|
|
3617
|
+
* ```typescript
|
|
3618
|
+
* await composio.experimental.customToolkits.sync('CUSTOM_MY_TOOLKIT');
|
|
3619
|
+
* ```
|
|
3620
|
+
*/
|
|
3621
|
+
customToolkits;
|
|
2938
3622
|
constructor(client) {
|
|
2939
3623
|
this.client = client;
|
|
3624
|
+
this.usage = new Usage(client);
|
|
3625
|
+
this.customToolkits = new CustomToolkits(client);
|
|
2940
3626
|
telemetry.instrument(this, "Experimental");
|
|
2941
3627
|
}
|
|
2942
3628
|
/**
|
|
@@ -3065,7 +3751,8 @@ var ConnectedAccounts = class {
|
|
|
3065
3751
|
...parsedQuery.data.accountType !== void 0 && { account_type: parsedQuery.data.accountType }
|
|
3066
3752
|
};
|
|
3067
3753
|
}
|
|
3068
|
-
|
|
3754
|
+
const result = await withCancellation(() => this.client.connectedAccounts.list(rawQuery, requestOptions), requestOptions?.signal);
|
|
3755
|
+
return transformConnectedAccountListResponse(result);
|
|
3069
3756
|
}
|
|
3070
3757
|
/**
|
|
3071
3758
|
* Compound function to create a new connected account.
|
|
@@ -3280,7 +3967,8 @@ var ConnectedAccounts = class {
|
|
|
3280
3967
|
* ```
|
|
3281
3968
|
*/
|
|
3282
3969
|
async get(nanoid, requestOptions) {
|
|
3283
|
-
|
|
3970
|
+
const response = await withCancellation(() => this.client.connectedAccounts.retrieve(nanoid, requestOptions), requestOptions?.signal);
|
|
3971
|
+
return transformConnectedAccountResponse(response);
|
|
3284
3972
|
}
|
|
3285
3973
|
/**
|
|
3286
3974
|
* Deletes a connected account.
|
|
@@ -3316,29 +4004,104 @@ var ConnectedAccounts = class {
|
|
|
3316
4004
|
* // Refresh a connected account's credentials
|
|
3317
4005
|
* const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
|
|
3318
4006
|
* ```
|
|
4007
|
+
*
|
|
4008
|
+
* @deprecated The `POST /connected_accounts/{id}/refresh` endpoint is deprecated by the
|
|
4009
|
+
* Composio API. Re-initiate authentication instead: `composio.connectedAccounts.link(userId, authConfigId)`
|
|
4010
|
+
* for a fresh connection, or `session.authorize(toolkit)` from a session. Behaviour is unchanged
|
|
4011
|
+
* while the endpoint remains available; do not generate new code against `refresh`.
|
|
3319
4012
|
*/
|
|
3320
4013
|
async refresh(nanoid, options, requestOptions) {
|
|
3321
4014
|
let params = void 0;
|
|
3322
4015
|
if (options) {
|
|
3323
4016
|
const parsedOptions = ConnectedAccountRefreshOptionsSchema.safeParse(options);
|
|
3324
4017
|
if (!parsedOptions.success) throw new ValidationError("Failed to parse connected account refresh options", { cause: parsedOptions.error });
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
validate_credentials: parsedOptions.data.validateCredentials
|
|
3328
|
-
};
|
|
4018
|
+
if (parsedOptions.data.validateCredentials !== void 0) logger.warn("connectedAccounts.refresh(): the Composio API no longer accepts `validateCredentials`; the option is ignored.");
|
|
4019
|
+
params = { query_redirect_url: parsedOptions.data.redirectUrl };
|
|
3329
4020
|
}
|
|
3330
4021
|
return withCancellation(() => this.client.connectedAccounts.refresh(nanoid, params, requestOptions), requestOptions?.signal);
|
|
3331
4022
|
}
|
|
3332
4023
|
/**
|
|
3333
|
-
*
|
|
3334
|
-
*
|
|
3335
|
-
*
|
|
3336
|
-
*
|
|
4024
|
+
* Revoke a connected account at the upstream provider.
|
|
4025
|
+
*
|
|
4026
|
+
* Best-effort upstream revocation of the stored tokens/credentials; on
|
|
4027
|
+
* success the connection status becomes `REVOKED`. Revoking an already
|
|
4028
|
+
* revoked connection returns an empty `revokedTokens` list without an
|
|
4029
|
+
* upstream call.
|
|
4030
|
+
*
|
|
4031
|
+
* @param {string} nanoid - The unique identifier of the connected account to revoke
|
|
4032
|
+
* @returns {Promise<ConnectedAccountRevokeResponse>} Which tokens were revoked and the resulting status
|
|
4033
|
+
* @throws {ComposioConnectedAccountRevocationNotSupportedError} If the toolkit does not support programmatic revocation (400)
|
|
4034
|
+
* @throws {ComposioConnectedAccountNotRevokableError} If the connection is not in a revokable state (409)
|
|
3337
4035
|
*
|
|
3338
4036
|
* @example
|
|
3339
4037
|
* ```typescript
|
|
3340
|
-
*
|
|
3341
|
-
*
|
|
4038
|
+
* const result = await composio.connectedAccounts.revoke('conn_abc123');
|
|
4039
|
+
* console.log(result.connectedAccount.status); // 'REVOKED'
|
|
4040
|
+
* console.log(result.revokedTokens); // e.g. ['access_token', 'refresh_token']
|
|
4041
|
+
* ```
|
|
4042
|
+
*/
|
|
4043
|
+
async revoke(nanoid, requestOptions) {
|
|
4044
|
+
try {
|
|
4045
|
+
const result = await withCancellation(() => this.client.connectedAccounts.revoke(nanoid, requestOptions), requestOptions?.signal);
|
|
4046
|
+
return transformConnectedAccountRevokeResponse(result);
|
|
4047
|
+
} catch (error) {
|
|
4048
|
+
if (error instanceof BadRequestError) throw new ComposioConnectedAccountRevocationNotSupportedError(`Connected account ${nanoid} cannot be revoked programmatically: ${error.message}`, {
|
|
4049
|
+
cause: error,
|
|
4050
|
+
meta: { nanoid }
|
|
4051
|
+
});
|
|
4052
|
+
if (error instanceof ConflictError) throw new ComposioConnectedAccountNotRevokableError(`Connected account ${nanoid} is not in a revokable state: ${error.message}`, {
|
|
4053
|
+
cause: error,
|
|
4054
|
+
meta: { nanoid }
|
|
4055
|
+
});
|
|
4056
|
+
throw error;
|
|
4057
|
+
}
|
|
4058
|
+
}
|
|
4059
|
+
/**
|
|
4060
|
+
* Complete a deferred OAuth connection once you have verified the user's
|
|
4061
|
+
* identity.
|
|
4062
|
+
*
|
|
4063
|
+
* When your project has an OAuth callback verifier configured, Composio
|
|
4064
|
+
* does not activate a new OAuth connection by itself: it redirects to your
|
|
4065
|
+
* verifier with a single-use session URI. After confirming who the user is,
|
|
4066
|
+
* redeem that session URI here; Composio checks that your project owns the
|
|
4067
|
+
* pending connection and that `userId` is its owner, completes the token
|
|
4068
|
+
* exchange, and the connection becomes `ACTIVE`.
|
|
4069
|
+
*
|
|
4070
|
+
* The session URI is single-use: redeeming it twice, or after it expires,
|
|
4071
|
+
* fails with a 404 from the API.
|
|
4072
|
+
*
|
|
4073
|
+
* @param {ConnectedAccountCompleteAuthParams} params - `userId` the connection was initiated for and the verifier's `sessionUri`
|
|
4074
|
+
* @returns {Promise<ConnectedAccountCompleteAuthResponse>} The completed connection's ID and toolkit
|
|
4075
|
+
* @throws {ValidationError} If the params fail validation
|
|
4076
|
+
*
|
|
4077
|
+
* @example
|
|
4078
|
+
* ```typescript
|
|
4079
|
+
* // In your verifier route, after authenticating the user:
|
|
4080
|
+
* const { connectedAccountId, toolkitSlug } = await composio.connectedAccounts.completeAuth({
|
|
4081
|
+
* userId: 'user_123',
|
|
4082
|
+
* sessionUri, // the session URI from the verifier redirect
|
|
4083
|
+
* });
|
|
4084
|
+
* ```
|
|
4085
|
+
*/
|
|
4086
|
+
async completeAuth(params, requestOptions) {
|
|
4087
|
+
const parsedParams = ConnectedAccountCompleteAuthParamsSchema.safeParse(params);
|
|
4088
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse connected account completeAuth params", { cause: parsedParams.error });
|
|
4089
|
+
const result = await withCancellation(() => this.client.connectedAccounts.completeAuth({
|
|
4090
|
+
user_id: parsedParams.data.userId,
|
|
4091
|
+
session_uri: parsedParams.data.sessionUri
|
|
4092
|
+
}, requestOptions), requestOptions?.signal);
|
|
4093
|
+
return transformConnectedAccountCompleteAuthResponse(result);
|
|
4094
|
+
}
|
|
4095
|
+
/**
|
|
4096
|
+
* Update the status of a connected account
|
|
4097
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
4098
|
+
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
4099
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
4100
|
+
*
|
|
4101
|
+
* @example
|
|
4102
|
+
* ```typescript
|
|
4103
|
+
* // Enable a connected account
|
|
4104
|
+
* const updatedAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
3342
4105
|
* enabled: true
|
|
3343
4106
|
* });
|
|
3344
4107
|
*
|
|
@@ -3445,6 +4208,37 @@ var ConnectedAccounts = class {
|
|
|
3445
4208
|
|
|
3446
4209
|
//#endregion
|
|
3447
4210
|
//#region src/utils/transformers/toolkits.ts
|
|
4211
|
+
const transformToolkitAuthField = (field) => ({
|
|
4212
|
+
name: field.name,
|
|
4213
|
+
displayName: field.displayName,
|
|
4214
|
+
description: field.description,
|
|
4215
|
+
type: field.type,
|
|
4216
|
+
required: field.required,
|
|
4217
|
+
...field.default !== void 0 && { default: field.default },
|
|
4218
|
+
...field.is_secret !== void 0 && { isSecret: field.is_secret },
|
|
4219
|
+
...field.legacy_template_name !== void 0 && { legacyTemplateName: field.legacy_template_name },
|
|
4220
|
+
...field.user_visible !== void 0 && { userVisible: field.user_visible }
|
|
4221
|
+
});
|
|
4222
|
+
/**
|
|
4223
|
+
* Normalize one field group to empty lists when the API omits it, the way this
|
|
4224
|
+
* repo's own docs pipeline does (`docs/lib/toolkit-api.ts` defaults a missing
|
|
4225
|
+
* group to `{ required: [], optional: [] }`).
|
|
4226
|
+
*
|
|
4227
|
+
* The generated client declares both groups and both lists as required, but a
|
|
4228
|
+
* response that omits one reached zod and failed validation there. Mapping it
|
|
4229
|
+
* eagerly would instead throw a `TypeError` on the property access, before
|
|
4230
|
+
* validation, turning a handled validation error into a crash of
|
|
4231
|
+
* `toolkits.get()`. Normalizing also leaves the other group usable, which is
|
|
4232
|
+
* typically the one the caller asked for.
|
|
4233
|
+
*/
|
|
4234
|
+
const transformToolkitAuthFieldGroup = (group) => ({
|
|
4235
|
+
required: (group?.required ?? []).map(transformToolkitAuthField),
|
|
4236
|
+
optional: (group?.optional ?? []).map(transformToolkitAuthField)
|
|
4237
|
+
});
|
|
4238
|
+
/**
|
|
4239
|
+
* `GET /toolkits` and `POST /toolkits/multi` return the same item shape; the
|
|
4240
|
+
* generated client only names them differently per operation.
|
|
4241
|
+
*/
|
|
3448
4242
|
const transformToolkitListResponse = (response) => {
|
|
3449
4243
|
return transform(response).with(ToolKitListResponseSchema).using((response) => response.items.map((item) => ({
|
|
3450
4244
|
name: item.name,
|
|
@@ -3490,9 +4284,11 @@ const transformToolkitRetrieveResponse = (response) => {
|
|
|
3490
4284
|
authConfigDetails: response.auth_config_details?.map((authConfig) => ({
|
|
3491
4285
|
name: authConfig.name,
|
|
3492
4286
|
mode: authConfig.mode,
|
|
4287
|
+
...authConfig.auth_hint_url !== void 0 && { authHintUrl: authConfig.auth_hint_url },
|
|
4288
|
+
...authConfig.required_scopes !== void 0 && { requiredScopes: authConfig.required_scopes },
|
|
3493
4289
|
fields: {
|
|
3494
|
-
authConfigCreation: authConfig.fields
|
|
3495
|
-
connectedAccountInitiation: authConfig.fields
|
|
4290
|
+
authConfigCreation: transformToolkitAuthFieldGroup(authConfig.fields?.auth_config_creation),
|
|
4291
|
+
connectedAccountInitiation: transformToolkitAuthFieldGroup(authConfig.fields?.connected_account_initiation)
|
|
3496
4292
|
},
|
|
3497
4293
|
proxy: { baseUrl: authConfig.proxy?.base_url }
|
|
3498
4294
|
})),
|
|
@@ -3501,6 +4297,17 @@ const transformToolkitRetrieveResponse = (response) => {
|
|
|
3501
4297
|
getCurrentUserEndpointMethod: response.get_current_user_endpoint_method
|
|
3502
4298
|
}));
|
|
3503
4299
|
};
|
|
4300
|
+
const transformToolkitChangelogResponse = (response) => {
|
|
4301
|
+
return transform(response).with(ToolkitChangelogResponseSchema).using((response) => ({ items: response.items.map((item) => ({
|
|
4302
|
+
slug: item.slug,
|
|
4303
|
+
name: item.name,
|
|
4304
|
+
displayName: item.display_name,
|
|
4305
|
+
versions: item.versions.map((version) => ({
|
|
4306
|
+
version: version.version,
|
|
4307
|
+
changelog: version.changelog
|
|
4308
|
+
}))
|
|
4309
|
+
})) }));
|
|
4310
|
+
};
|
|
3504
4311
|
const transformToolkitRetrieveCategoriesResponse = (response) => {
|
|
3505
4312
|
return transform(response).with(ToolkitRetrieveCategoriesResponseSchema).using((response) => ({
|
|
3506
4313
|
items: response.items.map((item) => ({
|
|
@@ -3511,6 +4318,47 @@ const transformToolkitRetrieveCategoriesResponse = (response) => {
|
|
|
3511
4318
|
totalPages: response.total_pages
|
|
3512
4319
|
}));
|
|
3513
4320
|
};
|
|
4321
|
+
const transformToolkitRecommendScopesParams = (params) => ({
|
|
4322
|
+
tools: params.tools,
|
|
4323
|
+
auth_scheme: params.authScheme,
|
|
4324
|
+
toolkit_version: params.toolkitVersion,
|
|
4325
|
+
grant_context: params.grantContext,
|
|
4326
|
+
include: params.include,
|
|
4327
|
+
exclude: params.exclude,
|
|
4328
|
+
available_scopes: params.availableScopes
|
|
4329
|
+
});
|
|
4330
|
+
const transformToolkitRecommendScopesResponse = (response) => {
|
|
4331
|
+
return transform(response).with(ToolkitRecommendScopesResponseSchema).using((response) => ({
|
|
4332
|
+
authScheme: response.auth_scheme,
|
|
4333
|
+
toolkitVersion: response.toolkit_version,
|
|
4334
|
+
grantContext: response.grant_context,
|
|
4335
|
+
scopes: {
|
|
4336
|
+
leastPrivilege: response.scopes.least_privilege,
|
|
4337
|
+
fewest: response.scopes.fewest,
|
|
4338
|
+
conditional: response.scopes.conditional.map((condition) => ({
|
|
4339
|
+
scope: condition.scope,
|
|
4340
|
+
when: condition.when,
|
|
4341
|
+
for: condition.for
|
|
4342
|
+
}))
|
|
4343
|
+
}
|
|
4344
|
+
}));
|
|
4345
|
+
};
|
|
4346
|
+
const transformToolkitListGrantContextsParams = (params) => ({
|
|
4347
|
+
auth_scheme: params.authScheme,
|
|
4348
|
+
toolkit_version: params.toolkitVersion
|
|
4349
|
+
});
|
|
4350
|
+
const transformToolkitListGrantContextsResponse = (response) => {
|
|
4351
|
+
return transform(response).with(ToolkitListGrantContextsResponseSchema).using((response) => ({
|
|
4352
|
+
authScheme: response.auth_scheme,
|
|
4353
|
+
toolkitVersion: response.toolkit_version,
|
|
4354
|
+
grantContextDimensions: response.grant_context_dimensions.map((dimension) => ({
|
|
4355
|
+
dimension: dimension.dimension,
|
|
4356
|
+
description: dimension.description,
|
|
4357
|
+
values: dimension.values
|
|
4358
|
+
})),
|
|
4359
|
+
defaultGrantContext: response.default_grant_context
|
|
4360
|
+
}));
|
|
4361
|
+
};
|
|
3514
4362
|
|
|
3515
4363
|
//#endregion
|
|
3516
4364
|
//#region src/models/Toolkits.ts
|
|
@@ -3549,7 +4397,8 @@ var Toolkits = class {
|
|
|
3549
4397
|
cursor: parsedQuery.data.cursor,
|
|
3550
4398
|
limit: parsedQuery.data.limit
|
|
3551
4399
|
};
|
|
3552
|
-
|
|
4400
|
+
const result = await withCancellation(() => this.client.toolkits.list(listParams, requestOptions), requestOptions?.signal);
|
|
4401
|
+
return transformToolkitListResponse(result);
|
|
3553
4402
|
} catch (error) {
|
|
3554
4403
|
if (error instanceof ComposioRequestCancelledError) throw error;
|
|
3555
4404
|
throw new ComposioToolkitFetchError("Failed to fetch toolkits", { cause: error });
|
|
@@ -3570,10 +4419,11 @@ var Toolkits = class {
|
|
|
3570
4419
|
*/
|
|
3571
4420
|
async getToolkitBySlug(slug, requestOptions) {
|
|
3572
4421
|
try {
|
|
3573
|
-
|
|
4422
|
+
const result = await withCancellation(() => this.client.toolkits.retrieve(slug, void 0, requestOptions), requestOptions?.signal);
|
|
4423
|
+
return transformToolkitRetrieveResponse(result);
|
|
3574
4424
|
} catch (error) {
|
|
3575
4425
|
if (error instanceof ComposioRequestCancelledError) throw error;
|
|
3576
|
-
if (error instanceof APIError
|
|
4426
|
+
if (error instanceof APIError && (error.status === 404 || error.status === 400)) throw new ComposioToolkitNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
3577
4427
|
meta: { slug },
|
|
3578
4428
|
cause: error
|
|
3579
4429
|
});
|
|
@@ -3594,6 +4444,125 @@ var Toolkits = class {
|
|
|
3594
4444
|
if (typeof arg === "string") return this.getToolkitBySlug(arg, requestOptions);
|
|
3595
4445
|
return this.getToolkits(arg ?? {}, requestOptions);
|
|
3596
4446
|
}
|
|
4447
|
+
/**
|
|
4448
|
+
* Retrieves several toolkits by slug in a single request.
|
|
4449
|
+
*
|
|
4450
|
+
* Returns the same transformed shape as `composio.toolkits.get({ ... })`.
|
|
4451
|
+
* Unknown slugs are simply absent from the result.
|
|
4452
|
+
*
|
|
4453
|
+
* @param {string[]} slugs - The toolkit slugs to retrieve (at least one)
|
|
4454
|
+
* @param {ToolkitGetManyParams} [params] - Optional filters and pagination, as for `list`
|
|
4455
|
+
* @returns {Promise<ToolKitListResponse>} The matching toolkits
|
|
4456
|
+
* @throws {ValidationError} If `slugs` is empty or the params fail validation
|
|
4457
|
+
* @throws {ComposioToolkitFetchError} If the request fails
|
|
4458
|
+
*
|
|
4459
|
+
* @example
|
|
4460
|
+
* ```typescript
|
|
4461
|
+
* const toolkits = await composio.toolkits.getMany(['github', 'slack']);
|
|
4462
|
+
* console.log(toolkits.map(toolkit => toolkit.name)); // ['GitHub', 'Slack']
|
|
4463
|
+
* ```
|
|
4464
|
+
*/
|
|
4465
|
+
async getMany(slugs, params, requestOptions) {
|
|
4466
|
+
const parsedSlugs = ToolkitGetManySlugsSchema.safeParse(slugs);
|
|
4467
|
+
if (!parsedSlugs.success) throw new ValidationError("Failed to parse toolkit slugs", { cause: parsedSlugs.error });
|
|
4468
|
+
const parsedParams = ToolkitsGetManyParamsSchema.safeParse(params ?? {});
|
|
4469
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse toolkit getMany params", { cause: parsedParams.error });
|
|
4470
|
+
const body = {
|
|
4471
|
+
toolkits: parsedSlugs.data,
|
|
4472
|
+
category: parsedParams.data.category,
|
|
4473
|
+
managed_by: parsedParams.data.managedBy,
|
|
4474
|
+
sort_by: parsedParams.data.sortBy,
|
|
4475
|
+
cursor: parsedParams.data.cursor,
|
|
4476
|
+
limit: parsedParams.data.limit
|
|
4477
|
+
};
|
|
4478
|
+
try {
|
|
4479
|
+
const result = await withCancellation(() => this.client.toolkits.retrieveMulti(body, requestOptions), requestOptions?.signal);
|
|
4480
|
+
return transformToolkitListResponse(result);
|
|
4481
|
+
} catch (error) {
|
|
4482
|
+
if (error instanceof ComposioRequestCancelledError) throw error;
|
|
4483
|
+
throw new ComposioToolkitFetchError("Failed to fetch toolkits", {
|
|
4484
|
+
meta: { slugs: parsedSlugs.data },
|
|
4485
|
+
cause: error
|
|
4486
|
+
});
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
/**
|
|
4490
|
+
* Retrieves the version changelog of every toolkit (the last 10 versions
|
|
4491
|
+
* per toolkit).
|
|
4492
|
+
*
|
|
4493
|
+
* @returns {Promise<ToolkitChangelogResponse>} Toolkits with their recent version changelogs
|
|
4494
|
+
*
|
|
4495
|
+
* @example
|
|
4496
|
+
* ```typescript
|
|
4497
|
+
* const { items } = await composio.toolkits.changelog();
|
|
4498
|
+
* const github = items.find(item => item.slug === 'github');
|
|
4499
|
+
* console.log(github?.versions[0]); // { version: '20250909_00', changelog: '...' }
|
|
4500
|
+
* ```
|
|
4501
|
+
*/
|
|
4502
|
+
async changelog(requestOptions) {
|
|
4503
|
+
const result = await withCancellation(() => this.client.toolkits.retrieveChangelog(requestOptions), requestOptions?.signal);
|
|
4504
|
+
return transformToolkitChangelogResponse(result);
|
|
4505
|
+
}
|
|
4506
|
+
/**
|
|
4507
|
+
* Recommends the OAuth scopes to request so a connection can run the given
|
|
4508
|
+
* tools.
|
|
4509
|
+
* **Experimental — the API marks this endpoint beta; shape may change.**
|
|
4510
|
+
*
|
|
4511
|
+
* The answer comes in two variants: `leastPrivilege` (narrowest documented
|
|
4512
|
+
* scope per requirement) and `fewest` (smallest set covering everything).
|
|
4513
|
+
* Pass `toolkitVersion` from a previous answer to pin the computation.
|
|
4514
|
+
*
|
|
4515
|
+
* @param {string} toolkitSlug - The toolkit to recommend scopes for
|
|
4516
|
+
* @param {ToolkitRecommendScopesParams} params - Tools to cover (`[]` for the whole toolkit), auth scheme, grant context and scope constraints
|
|
4517
|
+
* @returns {Promise<ToolkitRecommendScopesResponse>} The recommended scope sets
|
|
4518
|
+
* @throws {ValidationError} If the params fail validation
|
|
4519
|
+
*
|
|
4520
|
+
* @example
|
|
4521
|
+
* ```typescript
|
|
4522
|
+
* const { scopes } = await composio.toolkits.recommendScopes('gmail', {
|
|
4523
|
+
* tools: ['GMAIL_SEND_EMAIL', 'GMAIL_FETCH_EMAILS'],
|
|
4524
|
+
* });
|
|
4525
|
+
* console.log(scopes.leastPrivilege);
|
|
4526
|
+
* ```
|
|
4527
|
+
*/
|
|
4528
|
+
async recommendScopes(toolkitSlug, params, requestOptions) {
|
|
4529
|
+
const parsedParams = ToolkitRecommendScopesParamsSchema.safeParse(params);
|
|
4530
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse toolkit recommendScopes params", { cause: parsedParams.error });
|
|
4531
|
+
const body = transformToolkitRecommendScopesParams(parsedParams.data);
|
|
4532
|
+
const result = await withCancellation(() => this.client.toolkits.recommendScopes(toolkitSlug, body, requestOptions), requestOptions?.signal);
|
|
4533
|
+
return transformToolkitRecommendScopesResponse(result);
|
|
4534
|
+
}
|
|
4535
|
+
/**
|
|
4536
|
+
* Lists the grant-context dimensions a toolkit's scope recommendation
|
|
4537
|
+
* depends on (for example the Google account type), with their allowed
|
|
4538
|
+
* values and the default the API assumes.
|
|
4539
|
+
* **Experimental — the API marks this endpoint beta; shape may change.**
|
|
4540
|
+
*
|
|
4541
|
+
* Pass a dimension and a value as `grantContext` to
|
|
4542
|
+
* `composio.toolkits.recommendScopes()` to tailor the recommendation.
|
|
4543
|
+
*
|
|
4544
|
+
* @param {string} toolkitSlug - The toolkit to list grant contexts for
|
|
4545
|
+
* @param {ToolkitListGrantContextsParams} [params] - Optional auth scheme and toolkit version
|
|
4546
|
+
* @returns {Promise<ToolkitListGrantContextsResponse>} The dimensions and the default grant context
|
|
4547
|
+
* @throws {ValidationError} If the params fail validation
|
|
4548
|
+
*
|
|
4549
|
+
* @example
|
|
4550
|
+
* ```typescript
|
|
4551
|
+
* const { grantContextDimensions } = await composio.toolkits.listGrantContexts('gmail');
|
|
4552
|
+
* const [accountType] = grantContextDimensions;
|
|
4553
|
+
* const { scopes } = await composio.toolkits.recommendScopes('gmail', {
|
|
4554
|
+
* tools: ['GMAIL_SEND_EMAIL'],
|
|
4555
|
+
* grantContext: { [accountType.dimension]: accountType.values[0] },
|
|
4556
|
+
* });
|
|
4557
|
+
* ```
|
|
4558
|
+
*/
|
|
4559
|
+
async listGrantContexts(toolkitSlug, params, requestOptions) {
|
|
4560
|
+
const parsedParams = ToolkitListGrantContextsParamsSchema.safeParse(params ?? {});
|
|
4561
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse toolkit listGrantContexts params", { cause: parsedParams.error });
|
|
4562
|
+
const query = transformToolkitListGrantContextsParams(parsedParams.data);
|
|
4563
|
+
const result = await withCancellation(() => this.client.toolkits.retrieveScopesGrantContext(toolkitSlug, query, requestOptions), requestOptions?.signal);
|
|
4564
|
+
return transformToolkitListGrantContextsResponse(result);
|
|
4565
|
+
}
|
|
3597
4566
|
async getAuthConfigFields(toolkitSlug, authScheme, authConfigType, requiredOnly) {
|
|
3598
4567
|
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
3599
4568
|
if (!toolkit.authConfigDetails) throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", { meta: { toolkitSlug } });
|
|
@@ -3650,7 +4619,8 @@ var Toolkits = class {
|
|
|
3650
4619
|
* ```
|
|
3651
4620
|
*/
|
|
3652
4621
|
async listCategories(requestOptions) {
|
|
3653
|
-
|
|
4622
|
+
const result = await withCancellation(() => this.client.toolkits.retrieveCategories(requestOptions), requestOptions?.signal);
|
|
4623
|
+
return transformToolkitRetrieveCategoriesResponse(result);
|
|
3654
4624
|
}
|
|
3655
4625
|
/**
|
|
3656
4626
|
* Authorizes a user to use a toolkit.
|
|
@@ -3670,20 +4640,22 @@ var Toolkits = class {
|
|
|
3670
4640
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
3671
4641
|
let authConfigIdToUse = authConfigId;
|
|
3672
4642
|
if (!authConfigIdToUse) authConfigIdToUse = (await composioAuthConfig.list({ toolkit: toolkitSlug }, requestOptions)).items[0]?.id;
|
|
3673
|
-
if (!authConfigIdToUse)
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
4643
|
+
if (!authConfigIdToUse) {
|
|
4644
|
+
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) try {
|
|
4645
|
+
authConfigIdToUse = (await composioAuthConfig.create(toolkitSlug, {
|
|
4646
|
+
type: "use_composio_managed_auth",
|
|
4647
|
+
name: `${toolkit.name} Auth Config`
|
|
4648
|
+
}, requestOptions)).id;
|
|
4649
|
+
} catch (error) {
|
|
4650
|
+
if (error instanceof ComposioClient.APIError && error.status === 400) throw new ComposioAuthConfigNotFoundError(`No Default auth config found for toolkit ${toolkitSlug}`, {
|
|
4651
|
+
meta: { toolkitSlug },
|
|
4652
|
+
cause: error,
|
|
4653
|
+
possibleFixes: [`Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`]
|
|
4654
|
+
});
|
|
4655
|
+
throw error;
|
|
4656
|
+
}
|
|
4657
|
+
else throw new ComposioAuthConfigNotFoundError(`No auth configs found for toolkit ${toolkitSlug}`, { meta: { toolkitSlug } });
|
|
3685
4658
|
}
|
|
3686
|
-
else throw new ComposioAuthConfigNotFoundError(`No auth configs found for toolkit ${toolkitSlug}`, { meta: { toolkitSlug } });
|
|
3687
4659
|
return await new ConnectedAccounts(this.client).initiate(userId, authConfigIdToUse, { allowMultiple: true }, requestOptions);
|
|
3688
4660
|
}
|
|
3689
4661
|
};
|
|
@@ -3906,6 +4878,479 @@ const VerifyWebhookParamsSchema = z$1.object({
|
|
|
3906
4878
|
tolerance: z$1.number().optional().default(300)
|
|
3907
4879
|
});
|
|
3908
4880
|
|
|
4881
|
+
//#endregion
|
|
4882
|
+
//#region src/types/webhooks.types.ts
|
|
4883
|
+
/**
|
|
4884
|
+
* Webhook payload versions accepted by the webhook subscription endpoints.
|
|
4885
|
+
*/
|
|
4886
|
+
const WebhookVersionSchema = z$1.enum([
|
|
4887
|
+
"V1",
|
|
4888
|
+
"V2",
|
|
4889
|
+
"V3"
|
|
4890
|
+
]);
|
|
4891
|
+
/**
|
|
4892
|
+
* A project webhook subscription in the SDK's camelCase shape. The signing
|
|
4893
|
+
* `secret` is returned by the API on every subscription read/write.
|
|
4894
|
+
*/
|
|
4895
|
+
const WebhookSubscriptionSchema = z$1.object({
|
|
4896
|
+
id: z$1.string(),
|
|
4897
|
+
webhookUrl: z$1.string(),
|
|
4898
|
+
version: WebhookVersionSchema,
|
|
4899
|
+
enabledEvents: z$1.array(z$1.string()),
|
|
4900
|
+
secret: z$1.string().optional(),
|
|
4901
|
+
createdAt: z$1.string().optional(),
|
|
4902
|
+
updatedAt: z$1.string().optional()
|
|
4903
|
+
});
|
|
4904
|
+
const WebhookSubscriptionListParamsSchema = z$1.object({
|
|
4905
|
+
/** Number of items per page, max allowed is 50. */
|
|
4906
|
+
limit: z$1.number().optional(),
|
|
4907
|
+
/** Cursor for pagination, taken from a previous response's `nextCursor`. */
|
|
4908
|
+
cursor: z$1.string().optional()
|
|
4909
|
+
});
|
|
4910
|
+
const WebhookSubscriptionListResponseSchema = z$1.object({
|
|
4911
|
+
items: z$1.array(WebhookSubscriptionSchema),
|
|
4912
|
+
nextCursor: z$1.string().nullable(),
|
|
4913
|
+
totalPages: z$1.number(),
|
|
4914
|
+
currentPage: z$1.number(),
|
|
4915
|
+
totalItems: z$1.number()
|
|
4916
|
+
});
|
|
4917
|
+
/**
|
|
4918
|
+
* Params for `composio.webhooks.subscriptions.set()`. Identical to the
|
|
4919
|
+
* params accepted by `composio.triggers.setWebhookSubscription()`.
|
|
4920
|
+
*/
|
|
4921
|
+
const WebhookSubscriptionSetParamsSchema = SetWebhookSubscriptionParamsSchema;
|
|
4922
|
+
const WebhookSubscriptionUpdateParamsSchema = z$1.object({
|
|
4923
|
+
/** HTTPS URL to receive webhook events. */
|
|
4924
|
+
webhookUrl: z$1.string().min(1).optional(),
|
|
4925
|
+
/** Event types to subscribe to. */
|
|
4926
|
+
enabledEvents: z$1.array(z$1.string()).min(1).optional(),
|
|
4927
|
+
/** Webhook payload version. */
|
|
4928
|
+
version: WebhookVersionSchema.optional()
|
|
4929
|
+
});
|
|
4930
|
+
const WebhookSubscriptionDeleteResponseSchema = z$1.object({ success: z$1.boolean() });
|
|
4931
|
+
const WebhookSubscriptionRotateSecretResponseSchema = z$1.object({
|
|
4932
|
+
id: z$1.string(),
|
|
4933
|
+
/** The new signing secret. Store it — the previous secret stops validating. */
|
|
4934
|
+
secret: z$1.string()
|
|
4935
|
+
});
|
|
4936
|
+
const WebhookSubscriptionEventTypeSchema = z$1.object({
|
|
4937
|
+
eventType: z$1.string(),
|
|
4938
|
+
description: z$1.string(),
|
|
4939
|
+
supportedVersions: z$1.array(WebhookVersionSchema)
|
|
4940
|
+
});
|
|
4941
|
+
const WebhookSubscriptionEventTypesResponseSchema = z$1.object({ items: z$1.array(WebhookSubscriptionEventTypeSchema) });
|
|
4942
|
+
const WebhookEndpointListParamsSchema = z$1.object({
|
|
4943
|
+
/** Only return endpoints for this toolkit slug. */
|
|
4944
|
+
toolkitSlug: z$1.string().optional() });
|
|
4945
|
+
const WebhookEndpointListItemSchema = z$1.object({
|
|
4946
|
+
id: z$1.string(),
|
|
4947
|
+
toolkitSlug: z$1.string(),
|
|
4948
|
+
clientId: z$1.string().nullable()
|
|
4949
|
+
});
|
|
4950
|
+
const WebhookEndpointListResponseSchema = z$1.object({ items: z$1.array(WebhookEndpointListItemSchema) });
|
|
4951
|
+
const WebhookEndpointSchema = z$1.object({
|
|
4952
|
+
id: z$1.string(),
|
|
4953
|
+
toolkitSlug: z$1.string(),
|
|
4954
|
+
clientId: z$1.string().nullable(),
|
|
4955
|
+
/** The inbound URL to register with the third-party provider. */
|
|
4956
|
+
webhookUrl: z$1.string(),
|
|
4957
|
+
/** Configured setup fields with secret values masked. */
|
|
4958
|
+
data: z$1.record(z$1.string(), z$1.string()).nullable(),
|
|
4959
|
+
createdAt: z$1.string()
|
|
4960
|
+
});
|
|
4961
|
+
const WebhookEndpointCreateParamsSchema = z$1.object({
|
|
4962
|
+
/** Toolkit identifier (e.g. `slack`, `discord`). */
|
|
4963
|
+
toolkitSlug: z$1.string().min(1),
|
|
4964
|
+
/** OAuth app client ID — identifies which app this endpoint is for. */
|
|
4965
|
+
clientId: z$1.string().min(1)
|
|
4966
|
+
});
|
|
4967
|
+
const WebhookEndpointReplaceParamsSchema = z$1.object({
|
|
4968
|
+
/** Key-value pairs for ALL required setup fields of the toolkit. */
|
|
4969
|
+
data: z$1.record(z$1.string(), z$1.string()) });
|
|
4970
|
+
const WebhookEndpointUpdateParamsSchema = z$1.object({
|
|
4971
|
+
/** Key-value pairs to merge into the setup fields. Omitted fields are preserved. */
|
|
4972
|
+
data: z$1.record(z$1.string(), z$1.string()) });
|
|
4973
|
+
|
|
4974
|
+
//#endregion
|
|
4975
|
+
//#region src/utils/transformers/webhooks.ts
|
|
4976
|
+
const transformWebhookSubscription = (response) => {
|
|
4977
|
+
return transform(response).with(WebhookSubscriptionSchema).using((response) => ({
|
|
4978
|
+
id: response.id,
|
|
4979
|
+
webhookUrl: response.webhook_url,
|
|
4980
|
+
version: response.version,
|
|
4981
|
+
enabledEvents: response.enabled_events,
|
|
4982
|
+
secret: response.secret,
|
|
4983
|
+
createdAt: response.created_at,
|
|
4984
|
+
updatedAt: response.updated_at
|
|
4985
|
+
}));
|
|
4986
|
+
};
|
|
4987
|
+
const transformWebhookSubscriptionListResponse = (response) => {
|
|
4988
|
+
return transform(response).with(WebhookSubscriptionListResponseSchema).using((response) => ({
|
|
4989
|
+
items: response.items.map(transformWebhookSubscription),
|
|
4990
|
+
nextCursor: response.next_cursor ?? null,
|
|
4991
|
+
totalPages: response.total_pages,
|
|
4992
|
+
currentPage: response.current_page,
|
|
4993
|
+
totalItems: response.total_items
|
|
4994
|
+
}));
|
|
4995
|
+
};
|
|
4996
|
+
const transformWebhookSubscriptionDeleteResponse = (response) => {
|
|
4997
|
+
return transform(response).with(WebhookSubscriptionDeleteResponseSchema).using((response) => ({ success: response.success }));
|
|
4998
|
+
};
|
|
4999
|
+
const transformWebhookSubscriptionRotateSecretResponse = (response) => {
|
|
5000
|
+
return transform(response).with(WebhookSubscriptionRotateSecretResponseSchema).using((response) => ({
|
|
5001
|
+
id: response.id,
|
|
5002
|
+
secret: response.secret
|
|
5003
|
+
}));
|
|
5004
|
+
};
|
|
5005
|
+
const transformWebhookSubscriptionEventTypesResponse = (response) => {
|
|
5006
|
+
return transform(response).with(WebhookSubscriptionEventTypesResponseSchema).using((response) => ({ items: response.items.map((item) => ({
|
|
5007
|
+
eventType: item.event_type,
|
|
5008
|
+
description: item.description,
|
|
5009
|
+
supportedVersions: item.supported_versions
|
|
5010
|
+
})) }));
|
|
5011
|
+
};
|
|
5012
|
+
const transformWebhookEndpoint = (response) => {
|
|
5013
|
+
return transform(response).with(WebhookEndpointSchema).using((response) => ({
|
|
5014
|
+
id: response.id,
|
|
5015
|
+
toolkitSlug: response.toolkit_slug,
|
|
5016
|
+
clientId: response.client_id,
|
|
5017
|
+
webhookUrl: response.webhook_url,
|
|
5018
|
+
data: response.data,
|
|
5019
|
+
createdAt: response.created_at
|
|
5020
|
+
}));
|
|
5021
|
+
};
|
|
5022
|
+
const transformWebhookEndpointListResponse = (response) => {
|
|
5023
|
+
return transform(response).with(WebhookEndpointListResponseSchema).using((response) => ({ items: response.items.map((item) => ({
|
|
5024
|
+
id: item.id,
|
|
5025
|
+
toolkitSlug: item.toolkit_slug,
|
|
5026
|
+
clientId: item.client_id
|
|
5027
|
+
})) }));
|
|
5028
|
+
};
|
|
5029
|
+
|
|
5030
|
+
//#endregion
|
|
5031
|
+
//#region src/models/Webhooks.ts
|
|
5032
|
+
/**
|
|
5033
|
+
* The only part of the `list({ limit: 1 })` probe the upsert needs: the id of
|
|
5034
|
+
* the first (and, since the API allows one subscription per project, only)
|
|
5035
|
+
* subscription. Parsed at the boundary so a malformed payload never reaches
|
|
5036
|
+
* the update path.
|
|
5037
|
+
*/
|
|
5038
|
+
const FirstWebhookSubscriptionIdSchema = z$1.object({ items: z$1.array(z$1.object({ id: z$1.string().min(1) }).passthrough()) }).passthrough().transform((response) => response.items[0]?.id);
|
|
5039
|
+
/**
|
|
5040
|
+
* Create-or-update the project webhook subscription.
|
|
5041
|
+
*
|
|
5042
|
+
* Shared by `composio.webhooks.subscriptions.set()` and the legacy
|
|
5043
|
+
* `composio.triggers.setWebhookSubscription()` so both issue the exact same
|
|
5044
|
+
* call sequence: `webhookSubscriptions.list({ limit: 1 })`, then
|
|
5045
|
+
* `webhookSubscriptions.update(id, body)` when a subscription exists,
|
|
5046
|
+
* otherwise `webhookSubscriptions.create(body)`.
|
|
5047
|
+
*
|
|
5048
|
+
* @internal
|
|
5049
|
+
*/
|
|
5050
|
+
async function upsertWebhookSubscription(client, params, requestOptions) {
|
|
5051
|
+
const parsedParams = WebhookSubscriptionSetParamsSchema.safeParse(params);
|
|
5052
|
+
if (!parsedParams.success) throw new ValidationError(`Invalid parameters passed to set webhook subscription`, { cause: parsedParams.error });
|
|
5053
|
+
const body = {
|
|
5054
|
+
webhook_url: parsedParams.data.webhookUrl,
|
|
5055
|
+
enabled_events: parsedParams.data.enabledEvents ?? [...DefaultWebhookSubscriptionEvents],
|
|
5056
|
+
version: parsedParams.data.version ?? WebhookVersions.V3
|
|
5057
|
+
};
|
|
5058
|
+
const existing = await withCancellation(() => client.webhookSubscriptions.list({ limit: 1 }, requestOptions), requestOptions?.signal);
|
|
5059
|
+
const parsedExisting = FirstWebhookSubscriptionIdSchema.safeParse(existing);
|
|
5060
|
+
if (!parsedExisting.success) throw new ValidationError("Failed to parse webhook subscription list response", { cause: parsedExisting.error });
|
|
5061
|
+
const subscriptionId = parsedExisting.data;
|
|
5062
|
+
const subscription = await withCancellation(() => subscriptionId ? client.webhookSubscriptions.update(subscriptionId, body, requestOptions) : client.webhookSubscriptions.create(body, requestOptions), requestOptions?.signal);
|
|
5063
|
+
return transformWebhookSubscription(subscription);
|
|
5064
|
+
}
|
|
5065
|
+
/**
|
|
5066
|
+
* `composio.webhooks.subscriptions` — the project's outbound webhook
|
|
5067
|
+
* subscription. The API allows one subscription per project; every response
|
|
5068
|
+
* includes the signing `secret` used to verify deliveries with
|
|
5069
|
+
* `composio.triggers.verifyWebhook()` / `composio.triggers.parse()`.
|
|
5070
|
+
*/
|
|
5071
|
+
var WebhookSubscriptions = class {
|
|
5072
|
+
client;
|
|
5073
|
+
constructor(client) {
|
|
5074
|
+
this.client = client;
|
|
5075
|
+
telemetry.instrument(this, "WebhookSubscriptions");
|
|
5076
|
+
}
|
|
5077
|
+
/**
|
|
5078
|
+
* List the project's webhook subscriptions.
|
|
5079
|
+
*
|
|
5080
|
+
* @param {WebhookSubscriptionListParams} [query] - Pagination options
|
|
5081
|
+
* @returns {Promise<WebhookSubscriptionListResponse>} Paginated subscriptions
|
|
5082
|
+
*
|
|
5083
|
+
* @example
|
|
5084
|
+
* ```typescript
|
|
5085
|
+
* const { items } = await composio.webhooks.subscriptions.list();
|
|
5086
|
+
* console.log(items[0]?.webhookUrl);
|
|
5087
|
+
* ```
|
|
5088
|
+
*/
|
|
5089
|
+
async list(query, requestOptions) {
|
|
5090
|
+
const parsedQuery = WebhookSubscriptionListParamsSchema.safeParse(query ?? {});
|
|
5091
|
+
if (!parsedQuery.success) throw new ValidationError("Failed to parse webhook subscription list query", { cause: parsedQuery.error });
|
|
5092
|
+
const listParams = {
|
|
5093
|
+
limit: parsedQuery.data.limit,
|
|
5094
|
+
cursor: parsedQuery.data.cursor
|
|
5095
|
+
};
|
|
5096
|
+
const result = await withCancellation(() => this.client.webhookSubscriptions.list(listParams, requestOptions), requestOptions?.signal);
|
|
5097
|
+
return transformWebhookSubscriptionListResponse(result);
|
|
5098
|
+
}
|
|
5099
|
+
/**
|
|
5100
|
+
* Retrieve a webhook subscription by id.
|
|
5101
|
+
*
|
|
5102
|
+
* @param {string} id - The subscription id
|
|
5103
|
+
* @returns {Promise<WebhookSubscription>} The subscription, including its signing secret
|
|
5104
|
+
*
|
|
5105
|
+
* @example
|
|
5106
|
+
* ```typescript
|
|
5107
|
+
* const subscription = await composio.webhooks.subscriptions.get('whs_abc123');
|
|
5108
|
+
* console.log(subscription.enabledEvents);
|
|
5109
|
+
* ```
|
|
5110
|
+
*/
|
|
5111
|
+
async get(id, requestOptions) {
|
|
5112
|
+
const result = await withCancellation(() => this.client.webhookSubscriptions.retrieve(id, requestOptions), requestOptions?.signal);
|
|
5113
|
+
return transformWebhookSubscription(result);
|
|
5114
|
+
}
|
|
5115
|
+
/**
|
|
5116
|
+
* Create or update the project webhook subscription.
|
|
5117
|
+
*
|
|
5118
|
+
* If a subscription already exists it is updated in place, otherwise a new
|
|
5119
|
+
* one is created. By default this subscribes to V3 trigger message events.
|
|
5120
|
+
*
|
|
5121
|
+
* @param {WebhookSubscriptionSetParams} params - `webhookUrl`, optional `enabledEvents` and `version`
|
|
5122
|
+
* @returns {Promise<WebhookSubscription>} The resulting subscription
|
|
5123
|
+
* @throws {ValidationError} If the params fail validation
|
|
5124
|
+
*
|
|
5125
|
+
* @example
|
|
5126
|
+
* ```typescript
|
|
5127
|
+
* const subscription = await composio.webhooks.subscriptions.set({
|
|
5128
|
+
* webhookUrl: `${APP_URL}/webhooks/composio`,
|
|
5129
|
+
* enabledEvents: ['composio.trigger.message', 'composio.connected_account.expired'],
|
|
5130
|
+
* });
|
|
5131
|
+
* process.env.COMPOSIO_WEBHOOK_SECRET = subscription.secret;
|
|
5132
|
+
* ```
|
|
5133
|
+
*/
|
|
5134
|
+
async set(params, requestOptions) {
|
|
5135
|
+
return upsertWebhookSubscription(this.client, params, requestOptions);
|
|
5136
|
+
}
|
|
5137
|
+
/**
|
|
5138
|
+
* Update an existing webhook subscription. Only the provided fields change.
|
|
5139
|
+
*
|
|
5140
|
+
* @param {string} id - The subscription id
|
|
5141
|
+
* @param {WebhookSubscriptionUpdateParams} params - Fields to update
|
|
5142
|
+
* @returns {Promise<WebhookSubscription>} The updated subscription
|
|
5143
|
+
* @throws {ValidationError} If the params fail validation
|
|
5144
|
+
*
|
|
5145
|
+
* @example
|
|
5146
|
+
* ```typescript
|
|
5147
|
+
* await composio.webhooks.subscriptions.update('whs_abc123', {
|
|
5148
|
+
* enabledEvents: ['composio.trigger.message'],
|
|
5149
|
+
* });
|
|
5150
|
+
* ```
|
|
5151
|
+
*/
|
|
5152
|
+
async update(id, params, requestOptions) {
|
|
5153
|
+
const parsedParams = WebhookSubscriptionUpdateParamsSchema.safeParse(params);
|
|
5154
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse webhook subscription update params", { cause: parsedParams.error });
|
|
5155
|
+
const body = {
|
|
5156
|
+
webhook_url: parsedParams.data.webhookUrl,
|
|
5157
|
+
enabled_events: parsedParams.data.enabledEvents,
|
|
5158
|
+
version: parsedParams.data.version
|
|
5159
|
+
};
|
|
5160
|
+
const result = await withCancellation(() => this.client.webhookSubscriptions.update(id, body, requestOptions), requestOptions?.signal);
|
|
5161
|
+
return transformWebhookSubscription(result);
|
|
5162
|
+
}
|
|
5163
|
+
/**
|
|
5164
|
+
* Delete a webhook subscription. Deliveries stop immediately.
|
|
5165
|
+
*
|
|
5166
|
+
* @param {string} id - The subscription id
|
|
5167
|
+
* @returns {Promise<WebhookSubscriptionDeleteResponse>} `{ success }`
|
|
5168
|
+
*
|
|
5169
|
+
* @example
|
|
5170
|
+
* ```typescript
|
|
5171
|
+
* await composio.webhooks.subscriptions.delete('whs_abc123');
|
|
5172
|
+
* ```
|
|
5173
|
+
*/
|
|
5174
|
+
async delete(id, requestOptions) {
|
|
5175
|
+
const result = await withCancellation(() => this.client.webhookSubscriptions.delete(id, requestOptions), requestOptions?.signal);
|
|
5176
|
+
return transformWebhookSubscriptionDeleteResponse(result);
|
|
5177
|
+
}
|
|
5178
|
+
/**
|
|
5179
|
+
* Rotate the signing secret of a webhook subscription. The previous secret
|
|
5180
|
+
* stops validating, so update your verifier with the returned `secret`.
|
|
5181
|
+
*
|
|
5182
|
+
* @param {string} id - The subscription id
|
|
5183
|
+
* @returns {Promise<WebhookSubscriptionRotateSecretResponse>} `{ id, secret }`
|
|
5184
|
+
*
|
|
5185
|
+
* @example
|
|
5186
|
+
* ```typescript
|
|
5187
|
+
* const { secret } = await composio.webhooks.subscriptions.rotateSecret('whs_abc123');
|
|
5188
|
+
* ```
|
|
5189
|
+
*/
|
|
5190
|
+
async rotateSecret(id, requestOptions) {
|
|
5191
|
+
const result = await withCancellation(() => this.client.webhookSubscriptions.rotateSecret(id, requestOptions), requestOptions?.signal);
|
|
5192
|
+
return transformWebhookSubscriptionRotateSecretResponse(result);
|
|
5193
|
+
}
|
|
5194
|
+
/**
|
|
5195
|
+
* List the event types a subscription can enable, with the payload
|
|
5196
|
+
* versions each one supports.
|
|
5197
|
+
*
|
|
5198
|
+
* @returns {Promise<WebhookSubscriptionEventTypesResponse>} The available event types
|
|
5199
|
+
*
|
|
5200
|
+
* @example
|
|
5201
|
+
* ```typescript
|
|
5202
|
+
* const { items } = await composio.webhooks.subscriptions.listEventTypes();
|
|
5203
|
+
* console.log(items.map(item => item.eventType));
|
|
5204
|
+
* ```
|
|
5205
|
+
*/
|
|
5206
|
+
async listEventTypes(requestOptions) {
|
|
5207
|
+
const result = await withCancellation(() => this.client.webhookSubscriptions.listEventTypes(requestOptions), requestOptions?.signal);
|
|
5208
|
+
return transformWebhookSubscriptionEventTypesResponse(result);
|
|
5209
|
+
}
|
|
5210
|
+
};
|
|
5211
|
+
/**
|
|
5212
|
+
* `composio.webhooks.endpoints` — inbound webhook endpoints. Each endpoint is
|
|
5213
|
+
* the ingress URL Composio exposes for one toolkit + OAuth app pair, which you
|
|
5214
|
+
* register with the third-party provider so it can push events to Composio.
|
|
5215
|
+
*/
|
|
5216
|
+
var WebhookEndpoints = class {
|
|
5217
|
+
client;
|
|
5218
|
+
constructor(client) {
|
|
5219
|
+
this.client = client;
|
|
5220
|
+
telemetry.instrument(this, "WebhookEndpoints");
|
|
5221
|
+
}
|
|
5222
|
+
/**
|
|
5223
|
+
* List webhook endpoints, optionally filtered by toolkit.
|
|
5224
|
+
*
|
|
5225
|
+
* @param {WebhookEndpointListParams} [query] - Optional `toolkitSlug` filter
|
|
5226
|
+
* @returns {Promise<WebhookEndpointListResponse>} The endpoints
|
|
5227
|
+
*
|
|
5228
|
+
* @example
|
|
5229
|
+
* ```typescript
|
|
5230
|
+
* const { items } = await composio.webhooks.endpoints.list({ toolkitSlug: 'slack' });
|
|
5231
|
+
* ```
|
|
5232
|
+
*/
|
|
5233
|
+
async list(query, requestOptions) {
|
|
5234
|
+
const parsedQuery = WebhookEndpointListParamsSchema.safeParse(query ?? {});
|
|
5235
|
+
if (!parsedQuery.success) throw new ValidationError("Failed to parse webhook endpoint list query", { cause: parsedQuery.error });
|
|
5236
|
+
const listParams = { toolkit_slug: parsedQuery.data.toolkitSlug };
|
|
5237
|
+
const result = await withCancellation(() => this.client.webhookEndpoints.list(listParams, requestOptions), requestOptions?.signal);
|
|
5238
|
+
return transformWebhookEndpointListResponse(result);
|
|
5239
|
+
}
|
|
5240
|
+
/**
|
|
5241
|
+
* Retrieve a webhook endpoint by its nano id.
|
|
5242
|
+
*
|
|
5243
|
+
* @param {string} nanoId - The endpoint nano id (e.g. `we_abc123`)
|
|
5244
|
+
* @returns {Promise<WebhookEndpoint>} The endpoint, with secret setup values masked
|
|
5245
|
+
*
|
|
5246
|
+
* @example
|
|
5247
|
+
* ```typescript
|
|
5248
|
+
* const endpoint = await composio.webhooks.endpoints.get('we_abc123');
|
|
5249
|
+
* console.log(endpoint.webhookUrl);
|
|
5250
|
+
* ```
|
|
5251
|
+
*/
|
|
5252
|
+
async get(nanoId, requestOptions) {
|
|
5253
|
+
const result = await withCancellation(() => this.client.webhookEndpoints.retrieve(nanoId, requestOptions), requestOptions?.signal);
|
|
5254
|
+
return transformWebhookEndpoint(result);
|
|
5255
|
+
}
|
|
5256
|
+
/**
|
|
5257
|
+
* Create a webhook endpoint for a toolkit + OAuth app pair. Returns the
|
|
5258
|
+
* existing endpoint when one already exists for that pair.
|
|
5259
|
+
*
|
|
5260
|
+
* @param {WebhookEndpointCreateParams} params - `toolkitSlug` and `clientId`
|
|
5261
|
+
* @returns {Promise<WebhookEndpoint>} The endpoint; register `webhookUrl` with the provider
|
|
5262
|
+
* @throws {ValidationError} If the params fail validation
|
|
5263
|
+
*
|
|
5264
|
+
* @example
|
|
5265
|
+
* ```typescript
|
|
5266
|
+
* const endpoint = await composio.webhooks.endpoints.create({
|
|
5267
|
+
* toolkitSlug: 'slack',
|
|
5268
|
+
* clientId: 'my-slack-app-client-id',
|
|
5269
|
+
* });
|
|
5270
|
+
* ```
|
|
5271
|
+
*/
|
|
5272
|
+
async create(params, requestOptions) {
|
|
5273
|
+
const parsedParams = WebhookEndpointCreateParamsSchema.safeParse(params);
|
|
5274
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse webhook endpoint create params", { cause: parsedParams.error });
|
|
5275
|
+
const body = {
|
|
5276
|
+
toolkit_slug: parsedParams.data.toolkitSlug,
|
|
5277
|
+
client_id: parsedParams.data.clientId
|
|
5278
|
+
};
|
|
5279
|
+
const result = await withCancellation(() => this.client.webhookEndpoints.create(body, requestOptions), requestOptions?.signal);
|
|
5280
|
+
return transformWebhookEndpoint(result);
|
|
5281
|
+
}
|
|
5282
|
+
/**
|
|
5283
|
+
* Replace the setup fields of a webhook endpoint. All required setup fields
|
|
5284
|
+
* for the toolkit must be provided — this is the initial configuration.
|
|
5285
|
+
*
|
|
5286
|
+
* @param {string} nanoId - The endpoint nano id
|
|
5287
|
+
* @param {WebhookEndpointReplaceParams} params - `data` with every required setup field
|
|
5288
|
+
* @returns {Promise<WebhookEndpoint>} The configured endpoint
|
|
5289
|
+
* @throws {ValidationError} If the params fail validation
|
|
5290
|
+
*
|
|
5291
|
+
* @example
|
|
5292
|
+
* ```typescript
|
|
5293
|
+
* await composio.webhooks.endpoints.replace('we_abc123', {
|
|
5294
|
+
* data: { signing_secret: process.env.SLACK_SIGNING_SECRET! },
|
|
5295
|
+
* });
|
|
5296
|
+
* ```
|
|
5297
|
+
*/
|
|
5298
|
+
async replace(nanoId, params, requestOptions) {
|
|
5299
|
+
const parsedParams = WebhookEndpointReplaceParamsSchema.safeParse(params);
|
|
5300
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse webhook endpoint replace params", { cause: parsedParams.error });
|
|
5301
|
+
const result = await withCancellation(() => this.client.webhookEndpoints.replace(nanoId, { data: parsedParams.data.data }, requestOptions), requestOptions?.signal);
|
|
5302
|
+
return transformWebhookEndpoint(result);
|
|
5303
|
+
}
|
|
5304
|
+
/**
|
|
5305
|
+
* Merge setup fields into a webhook endpoint. Omitted fields are preserved.
|
|
5306
|
+
*
|
|
5307
|
+
* @param {string} nanoId - The endpoint nano id
|
|
5308
|
+
* @param {WebhookEndpointUpdateParams} params - `data` with the fields to change
|
|
5309
|
+
* @returns {Promise<WebhookEndpoint>} The updated endpoint
|
|
5310
|
+
* @throws {ValidationError} If the params fail validation
|
|
5311
|
+
*
|
|
5312
|
+
* @example
|
|
5313
|
+
* ```typescript
|
|
5314
|
+
* await composio.webhooks.endpoints.update('we_abc123', {
|
|
5315
|
+
* data: { signing_secret: 'rotated-secret' },
|
|
5316
|
+
* });
|
|
5317
|
+
* ```
|
|
5318
|
+
*/
|
|
5319
|
+
async update(nanoId, params, requestOptions) {
|
|
5320
|
+
const parsedParams = WebhookEndpointUpdateParamsSchema.safeParse(params);
|
|
5321
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse webhook endpoint update params", { cause: parsedParams.error });
|
|
5322
|
+
const result = await withCancellation(() => this.client.webhookEndpoints.update(nanoId, { data: parsedParams.data.data }, requestOptions), requestOptions?.signal);
|
|
5323
|
+
return transformWebhookEndpoint(result);
|
|
5324
|
+
}
|
|
5325
|
+
};
|
|
5326
|
+
/**
|
|
5327
|
+
* `composio.webhooks` namespace.
|
|
5328
|
+
*
|
|
5329
|
+
* - `subscriptions`: the project's outbound webhook subscription (where
|
|
5330
|
+
* Composio delivers trigger and lifecycle events).
|
|
5331
|
+
* - `endpoints`: inbound ingress URLs for third-party providers, one per
|
|
5332
|
+
* toolkit + OAuth app pair.
|
|
5333
|
+
*
|
|
5334
|
+
* @example
|
|
5335
|
+
* ```typescript
|
|
5336
|
+
* const subscription = await composio.webhooks.subscriptions.set({
|
|
5337
|
+
* webhookUrl: 'https://example.com/webhooks/composio',
|
|
5338
|
+
* });
|
|
5339
|
+
* const endpoints = await composio.webhooks.endpoints.list({ toolkitSlug: 'slack' });
|
|
5340
|
+
* ```
|
|
5341
|
+
*/
|
|
5342
|
+
var Webhooks = class {
|
|
5343
|
+
/** Manage the project's outbound webhook subscription. */
|
|
5344
|
+
subscriptions;
|
|
5345
|
+
/** Manage inbound webhook endpoints per toolkit + OAuth app. */
|
|
5346
|
+
endpoints;
|
|
5347
|
+
constructor(client) {
|
|
5348
|
+
this.subscriptions = new WebhookSubscriptions(client);
|
|
5349
|
+
this.endpoints = new WebhookEndpoints(client);
|
|
5350
|
+
telemetry.instrument(this, "Webhooks");
|
|
5351
|
+
}
|
|
5352
|
+
};
|
|
5353
|
+
|
|
3909
5354
|
//#endregion
|
|
3910
5355
|
//#region src/services/internal/InternalService.types.ts
|
|
3911
5356
|
const SDKRealtimeCredentialsResponseSchema = z$1.object({
|
|
@@ -3923,25 +5368,309 @@ var InternalService = class {
|
|
|
3923
5368
|
this.client = client;
|
|
3924
5369
|
this.client = client;
|
|
3925
5370
|
}
|
|
3926
|
-
/**
|
|
3927
|
-
* Get the SDK realtime credentials
|
|
3928
|
-
* @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
|
|
3929
|
-
*/
|
|
3930
|
-
async getSDKRealtimeCredentials() {
|
|
3931
|
-
const response = await this.client.request({
|
|
3932
|
-
method: "get",
|
|
3933
|
-
path: SDK_REALTIME_CREDENTIALS_ENDPOINT
|
|
3934
|
-
});
|
|
3935
|
-
const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
|
|
3936
|
-
pusherKey: response.pusher_key,
|
|
3937
|
-
projectId: response.project_id,
|
|
3938
|
-
pusherCluster: response.pusher_cluster
|
|
3939
|
-
});
|
|
3940
|
-
logger.debug(`[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}`);
|
|
3941
|
-
if (!parsedResponse.success) throw new ValidationError(`Failed to parse SDK realtime credentials`, { cause: parsedResponse.error });
|
|
3942
|
-
return parsedResponse.data;
|
|
5371
|
+
/**
|
|
5372
|
+
* Get the SDK realtime credentials
|
|
5373
|
+
* @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
|
|
5374
|
+
*/
|
|
5375
|
+
async getSDKRealtimeCredentials() {
|
|
5376
|
+
const response = await this.client.request({
|
|
5377
|
+
method: "get",
|
|
5378
|
+
path: SDK_REALTIME_CREDENTIALS_ENDPOINT
|
|
5379
|
+
});
|
|
5380
|
+
const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
|
|
5381
|
+
pusherKey: response.pusher_key,
|
|
5382
|
+
projectId: response.project_id,
|
|
5383
|
+
pusherCluster: response.pusher_cluster
|
|
5384
|
+
});
|
|
5385
|
+
logger.debug(`[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}`);
|
|
5386
|
+
if (!parsedResponse.success) throw new ValidationError(`Failed to parse SDK realtime credentials`, { cause: parsedResponse.error });
|
|
5387
|
+
return parsedResponse.data;
|
|
5388
|
+
}
|
|
5389
|
+
};
|
|
5390
|
+
|
|
5391
|
+
//#endregion
|
|
5392
|
+
//#region src/utils/sdk.ts
|
|
5393
|
+
/**
|
|
5394
|
+
* Header that carries a Composio user API key (`uak_...`) instead of a project
|
|
5395
|
+
* API key. It is the only default header the credential resolver reads.
|
|
5396
|
+
*/
|
|
5397
|
+
const USER_API_KEY_HEADER = "x-user-api-key";
|
|
5398
|
+
/** Prefix of Composio user API keys as issued by `composio login`. */
|
|
5399
|
+
const USER_API_KEY_PREFIX = "uak_";
|
|
5400
|
+
/**
|
|
5401
|
+
* Header that carries the project API key. The SDK only ever sets it from the
|
|
5402
|
+
* resolved `apiKey`; a caller-placed entry in `defaultHeaders` is rejected
|
|
5403
|
+
* when project-key auth is disabled.
|
|
5404
|
+
*/
|
|
5405
|
+
const PROJECT_API_KEY_HEADER = "x-api-key";
|
|
5406
|
+
/** Header carrying the organization nano ID that scopes user-key requests. */
|
|
5407
|
+
const ORG_ID_HEADER = "x-org-id";
|
|
5408
|
+
/** Header carrying the project nano ID that scopes user-key requests. */
|
|
5409
|
+
const PROJECT_ID_HEADER = "x-project-id";
|
|
5410
|
+
const userDataPath = () => {
|
|
5411
|
+
try {
|
|
5412
|
+
const homeDir = platform.homedir();
|
|
5413
|
+
if (!homeDir) return null;
|
|
5414
|
+
return platform.joinPath(homeDir, COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
5415
|
+
} catch (_error) {
|
|
5416
|
+
logger.debug("Environment", `Unable to get user data path`);
|
|
5417
|
+
return null;
|
|
5418
|
+
}
|
|
5419
|
+
};
|
|
5420
|
+
/**
|
|
5421
|
+
* Shape of `~/.composio/user_data.json`. The file is written by the Composio
|
|
5422
|
+
* CLI; only the two fields the SDK consumes are validated, everything else is
|
|
5423
|
+
* carried through untouched.
|
|
5424
|
+
*/
|
|
5425
|
+
const UserDataFileSchema = z$1.object({
|
|
5426
|
+
api_key: z$1.string().nullish(),
|
|
5427
|
+
base_url: z$1.string().nullish()
|
|
5428
|
+
}).passthrough();
|
|
5429
|
+
/**
|
|
5430
|
+
* Reads and validates the user data JSON file from the Composio directory.
|
|
5431
|
+
* File contents never appear in the returned diagnostics.
|
|
5432
|
+
*/
|
|
5433
|
+
const readUserDataFile = () => {
|
|
5434
|
+
if (!platform.supportsFileSystem) return { status: "missing" };
|
|
5435
|
+
const dataPath = userDataPath();
|
|
5436
|
+
if (!dataPath) return { status: "missing" };
|
|
5437
|
+
let raw;
|
|
5438
|
+
try {
|
|
5439
|
+
raw = platform.readFileSync(dataPath, "utf8");
|
|
5440
|
+
} catch (_error) {
|
|
5441
|
+
logger.debug("Environment", "No user data file found");
|
|
5442
|
+
return { status: "missing" };
|
|
5443
|
+
}
|
|
5444
|
+
let json;
|
|
5445
|
+
try {
|
|
5446
|
+
json = JSON.parse(typeof raw === "string" ? raw : new TextDecoder().decode(raw));
|
|
5447
|
+
} catch (_error) {
|
|
5448
|
+
logger.debug("Environment", `User data file at ${dataPath} could not be parsed as JSON`);
|
|
5449
|
+
return {
|
|
5450
|
+
status: "malformed",
|
|
5451
|
+
path: dataPath,
|
|
5452
|
+
reason: "could not be parsed as JSON"
|
|
5453
|
+
};
|
|
5454
|
+
}
|
|
5455
|
+
const parsed = UserDataFileSchema.safeParse(json);
|
|
5456
|
+
if (!parsed.success) {
|
|
5457
|
+
const fields = parsed.error.issues.map((issue) => issue.path.join(".")).filter(Boolean).join(", ");
|
|
5458
|
+
const reason = fields ? `has an unexpected shape (invalid field${fields.includes(",") ? "s" : ""}: ${fields})` : "has an unexpected shape (expected a JSON object)";
|
|
5459
|
+
logger.debug("Environment", `User data file at ${dataPath} ${reason}`);
|
|
5460
|
+
return {
|
|
5461
|
+
status: "malformed",
|
|
5462
|
+
path: dataPath,
|
|
5463
|
+
reason
|
|
5464
|
+
};
|
|
3943
5465
|
}
|
|
5466
|
+
return {
|
|
5467
|
+
status: "ok",
|
|
5468
|
+
path: dataPath,
|
|
5469
|
+
data: parsed.data
|
|
5470
|
+
};
|
|
5471
|
+
};
|
|
5472
|
+
const findHeader = (headers, name) => {
|
|
5473
|
+
if (!headers) return;
|
|
5474
|
+
const wanted = name.toLowerCase();
|
|
5475
|
+
for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === wanted) return {
|
|
5476
|
+
name: key,
|
|
5477
|
+
value
|
|
5478
|
+
};
|
|
5479
|
+
};
|
|
5480
|
+
/**
|
|
5481
|
+
* Returns the `x-user-api-key` entry from a header map, if it carries a
|
|
5482
|
+
* non-empty value. Matches the header name case-insensitively and ignores
|
|
5483
|
+
* every other header.
|
|
5484
|
+
*/
|
|
5485
|
+
const getUserApiKeyHeader = (headers) => {
|
|
5486
|
+
const header = findHeader(headers, USER_API_KEY_HEADER);
|
|
5487
|
+
return header && typeof header.value === "string" && header.value.length > 0 ? header : void 0;
|
|
5488
|
+
};
|
|
5489
|
+
/**
|
|
5490
|
+
* The single credential header that mirrors what the API client puts on the
|
|
5491
|
+
* wire for an SDK instance. A non-empty `x-user-api-key` entry in the default
|
|
5492
|
+
* headers wins: the client treats a caller-placed credential header as the
|
|
5493
|
+
* credential and suppresses the configured keys. Otherwise the project key
|
|
5494
|
+
* travels as `x-api-key`, otherwise the resolved user API key as
|
|
5495
|
+
* `x-user-api-key`. Empty when no credential is held. The environment is
|
|
5496
|
+
* never consulted here.
|
|
5497
|
+
*/
|
|
5498
|
+
const resolveCredentialHeaders = (input) => {
|
|
5499
|
+
const userApiKeyHeader = getUserApiKeyHeader(input.defaultHeaders);
|
|
5500
|
+
if (userApiKeyHeader) return { [USER_API_KEY_HEADER]: userApiKeyHeader.value };
|
|
5501
|
+
if (hasValue(input.apiKey)) return { [PROJECT_API_KEY_HEADER]: input.apiKey };
|
|
5502
|
+
if (hasValue(input.userApiKey)) return { [USER_API_KEY_HEADER]: input.userApiKey };
|
|
5503
|
+
return {};
|
|
5504
|
+
};
|
|
5505
|
+
const resolveScopeValue = (option, headers, headerName, optionName) => {
|
|
5506
|
+
const header = findHeader(headers, headerName);
|
|
5507
|
+
const headerValue = header && header.value.length > 0 ? header.value : void 0;
|
|
5508
|
+
const optionValue = hasValue(option) ? option : void 0;
|
|
5509
|
+
if (optionValue !== void 0 && headerValue !== void 0 && optionValue !== headerValue) throw new ComposioScopeConfigError(`\`${optionName}\` and the \`${headerName}\` default header disagree`, {
|
|
5510
|
+
cause: `The ${optionName} option and the ${headerName} entry in defaultHeaders carry different values; the SDK keeps a single scope source`,
|
|
5511
|
+
meta: {
|
|
5512
|
+
option: optionName,
|
|
5513
|
+
header: headerName
|
|
5514
|
+
}
|
|
5515
|
+
});
|
|
5516
|
+
return optionValue ?? headerValue;
|
|
3944
5517
|
};
|
|
5518
|
+
/**
|
|
5519
|
+
* Resolves the organization/project scope of an SDK instance.
|
|
5520
|
+
*
|
|
5521
|
+
* The scope comes from the `orgId` / `projectId` options, or from the
|
|
5522
|
+
* `x-org-id` / `x-project-id` default headers when the options are omitted.
|
|
5523
|
+
* A value present in both places must agree, and the two IDs must be supplied
|
|
5524
|
+
* together: a user API key without an explicit scope keeps the API default
|
|
5525
|
+
* (the developer project), so a half-configured scope is rejected instead of
|
|
5526
|
+
* silently selecting a project.
|
|
5527
|
+
*/
|
|
5528
|
+
function resolveSDKScope(options) {
|
|
5529
|
+
const orgId = resolveScopeValue(options.orgId, options.defaultHeaders, ORG_ID_HEADER, "orgId");
|
|
5530
|
+
const projectId = resolveScopeValue(options.projectId, options.defaultHeaders, PROJECT_ID_HEADER, "projectId");
|
|
5531
|
+
if (orgId === void 0 !== (projectId === void 0)) throw new ComposioScopeConfigError(orgId === void 0 ? "`projectId` requires `orgId`: the organization and project nano IDs scope requests together" : "`orgId` requires `projectId`: the organization and project nano IDs scope requests together", {
|
|
5532
|
+
cause: "Only one of the two scope identifiers was configured",
|
|
5533
|
+
meta: {
|
|
5534
|
+
orgId: orgId !== void 0,
|
|
5535
|
+
projectId: projectId !== void 0
|
|
5536
|
+
}
|
|
5537
|
+
});
|
|
5538
|
+
return orgId === void 0 || projectId === void 0 ? {} : {
|
|
5539
|
+
orgId,
|
|
5540
|
+
projectId
|
|
5541
|
+
};
|
|
5542
|
+
}
|
|
5543
|
+
/** The `x-org-id` / `x-project-id` headers for a resolved scope. */
|
|
5544
|
+
const getScopeHeaders = (scope) => scope.orgId && scope.projectId ? {
|
|
5545
|
+
[ORG_ID_HEADER]: scope.orgId,
|
|
5546
|
+
[PROJECT_ID_HEADER]: scope.projectId
|
|
5547
|
+
} : {};
|
|
5548
|
+
const hasValue = (value) => typeof value === "string" && value.length > 0;
|
|
5549
|
+
/**
|
|
5550
|
+
* Mirrors how the API client resolves `userApiKey` / `orgApiKey`: an explicit
|
|
5551
|
+
* value (including `null`) is final, `undefined` falls back to the environment.
|
|
5552
|
+
*/
|
|
5553
|
+
const resolveAlternateCredential = (explicit, envName) => {
|
|
5554
|
+
if (explicit !== void 0) return hasValue(explicit) ? explicit : void 0;
|
|
5555
|
+
const fromEnv = getEnvVariable(envName);
|
|
5556
|
+
return hasValue(fromEnv) ? fromEnv : void 0;
|
|
5557
|
+
};
|
|
5558
|
+
/**
|
|
5559
|
+
* The user API key the API client will hold: the `userApiKey` option when it
|
|
5560
|
+
* was passed (including `null`, which disables the fallback), otherwise
|
|
5561
|
+
* `COMPOSIO_USER_API_KEY`.
|
|
5562
|
+
*/
|
|
5563
|
+
const resolveUserApiKey = (userApiKey) => resolveAlternateCredential(userApiKey, "COMPOSIO_USER_API_KEY");
|
|
5564
|
+
/**
|
|
5565
|
+
* Whether the instance holds a credential other than the project key: a user
|
|
5566
|
+
* or organization API key (explicit or environment-resolved, as the API client
|
|
5567
|
+
* will see it), or a user API key placed in the default headers.
|
|
5568
|
+
*/
|
|
5569
|
+
const hasAlternateCredential = (options) => resolveUserApiKey(options.userApiKey) !== void 0 || resolveAlternateCredential(options.orgApiKey, "COMPOSIO_ORG_API_KEY") !== void 0 || getUserApiKeyHeader(options.defaultHeaders) !== void 0;
|
|
5570
|
+
/**
|
|
5571
|
+
* Resolves the base URL and project API key the SDK will use.
|
|
5572
|
+
*
|
|
5573
|
+
* Project key resolution distinguishes three caller intents:
|
|
5574
|
+
* - a non-empty string is used as-is and nothing else is consulted;
|
|
5575
|
+
* - `undefined` (or an empty string) falls back to `COMPOSIO_API_KEY`, then to
|
|
5576
|
+
* the `api_key` stored by the CLI in `~/.composio/user_data.json`;
|
|
5577
|
+
* - `null` disables project-key auth: neither `COMPOSIO_API_KEY` nor the stored
|
|
5578
|
+
* `api_key` is read, and the resolver only succeeds when the instance holds
|
|
5579
|
+
* another credential: a `userApiKey` or `orgApiKey` (explicit, or resolved
|
|
5580
|
+
* from `COMPOSIO_USER_API_KEY` / `COMPOSIO_ORG_API_KEY` the way the API
|
|
5581
|
+
* client does), or a non-empty `x-user-api-key` entry in `defaultHeaders`.
|
|
5582
|
+
* An `x-api-key` entry in `defaultHeaders` (any letter case) is rejected in
|
|
5583
|
+
* that mode: the project credential is only ever set from `apiKey`.
|
|
5584
|
+
*
|
|
5585
|
+
* A stored `uak_` user key is never used as a project key: when it is the only
|
|
5586
|
+
* candidate the resolver throws a {@link ComposioAPIKeyKindError} that names the
|
|
5587
|
+
* problem without echoing the key.
|
|
5588
|
+
*/
|
|
5589
|
+
function getSDKConfig(baseUrl, apiKey, options = {}) {
|
|
5590
|
+
let userData;
|
|
5591
|
+
const readUserData = () => {
|
|
5592
|
+
userData ??= readUserDataFile();
|
|
5593
|
+
return userData;
|
|
5594
|
+
};
|
|
5595
|
+
const userDataValue = (field) => {
|
|
5596
|
+
const read = readUserData();
|
|
5597
|
+
return read.status === "ok" && hasValue(read.data[field]) ? read.data[field] : void 0;
|
|
5598
|
+
};
|
|
5599
|
+
const resolveApiKey = () => {
|
|
5600
|
+
if (apiKey === null) {
|
|
5601
|
+
const projectKeyHeader = findHeader(options.defaultHeaders, PROJECT_API_KEY_HEADER);
|
|
5602
|
+
if (projectKeyHeader) throw new ComposioNoAPIKeyError(`Project API key resolution is disabled, but \`defaultHeaders\` carries a \`${projectKeyHeader.name}\` entry`, {
|
|
5603
|
+
cause: "`apiKey: null` sends no project key, so a raw x-api-key default header would bypass that choice; the SDK keeps a single source for the project credential",
|
|
5604
|
+
possibleFixes: [`Pass the project API key via \`apiKey\` instead of a raw \`${PROJECT_API_KEY_HEADER}\` default header`, `Remove the \`${projectKeyHeader.name}\` entry from \`defaultHeaders\` to authenticate with the user or organization API key alone`]
|
|
5605
|
+
});
|
|
5606
|
+
if (hasAlternateCredential(options)) return null;
|
|
5607
|
+
throw new ComposioNoAPIKeyError("Project API key resolution is disabled", {
|
|
5608
|
+
cause: "`apiKey: null` turns off the COMPOSIO_API_KEY and user config file fallbacks, and no user or organization API key was configured",
|
|
5609
|
+
possibleFixes: [
|
|
5610
|
+
"Pass a project API key via `apiKey`, or omit it to fall back to COMPOSIO_API_KEY",
|
|
5611
|
+
"To authenticate with a user API key instead, keep `apiKey: null` and pass `userApiKey` (or set COMPOSIO_USER_API_KEY)",
|
|
5612
|
+
`Alternatively, keep \`apiKey: null\` and set the \`${USER_API_KEY_HEADER}\` default header`
|
|
5613
|
+
]
|
|
5614
|
+
});
|
|
5615
|
+
}
|
|
5616
|
+
if (hasValue(apiKey)) return apiKey;
|
|
5617
|
+
const envApiKey = getEnvVariable("COMPOSIO_API_KEY");
|
|
5618
|
+
if (hasValue(envApiKey)) return envApiKey;
|
|
5619
|
+
const read = readUserData();
|
|
5620
|
+
const storedApiKey = userDataValue("api_key");
|
|
5621
|
+
if (read.status === "ok" && hasValue(storedApiKey)) {
|
|
5622
|
+
if (storedApiKey.startsWith(USER_API_KEY_PREFIX)) throw new ComposioAPIKeyKindError(void 0, {
|
|
5623
|
+
cause: `The user config file at ${read.path} holds a user API key written by the Composio CLI; it cannot authenticate SDK requests as a project`,
|
|
5624
|
+
meta: { userDataFilePath: read.path }
|
|
5625
|
+
});
|
|
5626
|
+
return storedApiKey;
|
|
5627
|
+
}
|
|
5628
|
+
if (read.status === "malformed") throw new ComposioNoAPIKeyError("No Composio API key provided", { cause: `No API key was passed in the params or in COMPOSIO_API_KEY, and the user config file at ${read.path} ${read.reason}` });
|
|
5629
|
+
throw new ComposioNoAPIKeyError();
|
|
5630
|
+
};
|
|
5631
|
+
let apiKeyParsed;
|
|
5632
|
+
try {
|
|
5633
|
+
apiKeyParsed = resolveApiKey();
|
|
5634
|
+
} catch (error) {
|
|
5635
|
+
ComposioError.handleAndThrow(error);
|
|
5636
|
+
}
|
|
5637
|
+
const baseURLParsed = (hasValue(baseUrl) ? baseUrl : void 0) ?? getEnvVariable("COMPOSIO_BASE_URL") ?? userDataValue("base_url") ?? "https://backend.composio.dev";
|
|
5638
|
+
logger.debug("Environment", apiKeyParsed === null ? "API Key: [DISABLED]" : "API Key: [REDACTED]");
|
|
5639
|
+
logger.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
5640
|
+
return {
|
|
5641
|
+
baseURL: baseURLParsed,
|
|
5642
|
+
apiKey: apiKeyParsed
|
|
5643
|
+
};
|
|
5644
|
+
}
|
|
5645
|
+
/**
|
|
5646
|
+
* Gets toolkit versions configuration by merging environment variables, user-provided defaults, and fallbacks.
|
|
5647
|
+
*
|
|
5648
|
+
* Priority order:
|
|
5649
|
+
* 1. If defaultVersions is a string, use it as global version for all toolkits
|
|
5650
|
+
* 2. User-provided toolkit version mappings (defaultVersions object)
|
|
5651
|
+
* 3. Environment variables (COMPOSIO_TOOLKIT_VERSION_<TOOLKIT_NAME>)
|
|
5652
|
+
* 4. Fallback to 'latest' if no versions are configured
|
|
5653
|
+
*
|
|
5654
|
+
* @param defaultVersions - Optional default versions configuration (string for global version or object mapping toolkit names to versions)
|
|
5655
|
+
* @returns Toolkit versions configuration - either a global version string, toolkit-specific version mapping, or 'latest'
|
|
5656
|
+
*/
|
|
5657
|
+
function getToolkitVersionsFromEnv(defaultVersions) {
|
|
5658
|
+
if (defaultVersions && typeof defaultVersions === "string") return defaultVersions;
|
|
5659
|
+
const envPrefixedVersions = getEnvsWithPrefix(`COMPOSIO_TOOLKIT_VERSION_`);
|
|
5660
|
+
const toolkitVersionsFromEnv = Object.entries(envPrefixedVersions).reduce((acc, [key, value]) => {
|
|
5661
|
+
const toolkitName = key.replace("COMPOSIO_TOOLKIT_VERSION_", "");
|
|
5662
|
+
acc[normalizeToolkitSlug(toolkitName)] = value;
|
|
5663
|
+
return acc;
|
|
5664
|
+
}, {});
|
|
5665
|
+
let userProvidedToolkitVersions = {};
|
|
5666
|
+
if (defaultVersions && typeof defaultVersions === "object") userProvidedToolkitVersions = Object.fromEntries(Object.entries(defaultVersions).map(([key, value]) => [normalizeToolkitSlug(key), value]));
|
|
5667
|
+
const toolkitVersions = {
|
|
5668
|
+
...toolkitVersionsFromEnv,
|
|
5669
|
+
...userProvidedToolkitVersions
|
|
5670
|
+
};
|
|
5671
|
+
if (Object.keys(toolkitVersions).length === 0) return "latest";
|
|
5672
|
+
return toolkitVersions;
|
|
5673
|
+
}
|
|
3945
5674
|
|
|
3946
5675
|
//#endregion
|
|
3947
5676
|
//#region src/services/pusher/Pusher.ts
|
|
@@ -3951,13 +5680,17 @@ var PusherService = class {
|
|
|
3951
5680
|
pusherCluster;
|
|
3952
5681
|
pusherChannel;
|
|
3953
5682
|
pusherBaseURL;
|
|
3954
|
-
|
|
5683
|
+
authHeaders;
|
|
3955
5684
|
pusherClient;
|
|
3956
5685
|
composioClient;
|
|
3957
|
-
constructor(client) {
|
|
5686
|
+
constructor(client, options = {}) {
|
|
3958
5687
|
this.composioClient = client;
|
|
3959
5688
|
this.pusherBaseURL = client.baseURL;
|
|
3960
|
-
this.
|
|
5689
|
+
this.authHeaders = resolveCredentialHeaders({
|
|
5690
|
+
apiKey: client.apiKey,
|
|
5691
|
+
userApiKey: client.userApiKey,
|
|
5692
|
+
defaultHeaders: options.defaultHeaders
|
|
5693
|
+
});
|
|
3961
5694
|
telemetry.instrument(this, "PusherService");
|
|
3962
5695
|
}
|
|
3963
5696
|
/**
|
|
@@ -3986,7 +5719,7 @@ var PusherService = class {
|
|
|
3986
5719
|
cluster: this.pusherCluster,
|
|
3987
5720
|
channelAuthorization: {
|
|
3988
5721
|
endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
|
|
3989
|
-
headers: {
|
|
5722
|
+
headers: { ...this.authHeaders },
|
|
3990
5723
|
transport: "ajax"
|
|
3991
5724
|
}
|
|
3992
5725
|
});
|
|
@@ -4048,14 +5781,28 @@ var PusherService = class {
|
|
|
4048
5781
|
* @param channelName - The name of the Pusher channel to subscribe to
|
|
4049
5782
|
* @param event - The event to subscribe to
|
|
4050
5783
|
* @param fn - The function to call when the event is received
|
|
5784
|
+
* @param onSubscriptionError - Optional callback invoked with the raw payload when the
|
|
5785
|
+
* Pusher subscription fails (for example on auth or permission rejection). Errors thrown
|
|
5786
|
+
* from — or promises rejected by — this callback are contained and logged, never rethrown.
|
|
4051
5787
|
*/
|
|
4052
|
-
async subscribe(fn) {
|
|
5788
|
+
async subscribe(fn, onSubscriptionError) {
|
|
4053
5789
|
try {
|
|
4054
5790
|
logger.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
|
|
4055
5791
|
const channel = await (await this.getPusherClient()).subscribe(this.pusherChannel);
|
|
5792
|
+
const logCallbackFailure = (callbackError) => {
|
|
5793
|
+
const errorMessage = callbackError instanceof Error ? callbackError.message : String(callbackError);
|
|
5794
|
+
logger.error("❌ Error in subscription error callback:", errorMessage);
|
|
5795
|
+
};
|
|
4056
5796
|
channel.bind("pusher:subscription_error", (data) => {
|
|
4057
|
-
|
|
4058
|
-
|
|
5797
|
+
logger.error("Trigger subscription error:", data);
|
|
5798
|
+
try {
|
|
5799
|
+
Promise.resolve(onSubscriptionError?.(data)).catch(logCallbackFailure);
|
|
5800
|
+
} catch (callbackError) {
|
|
5801
|
+
logCallbackFailure(callbackError);
|
|
5802
|
+
}
|
|
5803
|
+
});
|
|
5804
|
+
channel.bind("pusher:subscription_succeeded", () => {
|
|
5805
|
+
logger.info(`✅ Subscribed to triggers. You should start receiving events now.`);
|
|
4059
5806
|
});
|
|
4060
5807
|
const safeCallback = (data) => {
|
|
4061
5808
|
try {
|
|
@@ -4066,7 +5813,6 @@ var PusherService = class {
|
|
|
4066
5813
|
}
|
|
4067
5814
|
};
|
|
4068
5815
|
this.bindWithChunking(channel, "trigger_to_client", safeCallback);
|
|
4069
|
-
logger.info(`✅ Subscribed to triggers. You should start receiving events now.`);
|
|
4070
5816
|
} catch (error) {
|
|
4071
5817
|
throw new ComposioFailedToSubscribeToPusherChannelError("Failed to subscribe to Pusher channel", { cause: error });
|
|
4072
5818
|
}
|
|
@@ -4153,8 +5899,8 @@ function transformTriggerInstanceListActiveItem(response) {
|
|
|
4153
5899
|
id: response.id,
|
|
4154
5900
|
connectedAccountId: response.connected_account_id,
|
|
4155
5901
|
disabledAt: response.disabled_at,
|
|
4156
|
-
state: response.state,
|
|
4157
|
-
triggerConfig: response.trigger_config,
|
|
5902
|
+
state: response.state ?? {},
|
|
5903
|
+
triggerConfig: response.trigger_config ?? {},
|
|
4158
5904
|
triggerName: response.trigger_name,
|
|
4159
5905
|
updatedAt: response.updated_at,
|
|
4160
5906
|
triggerData: response.trigger_data,
|
|
@@ -4182,7 +5928,8 @@ async function hmacSha256Base64(secret, message) {
|
|
|
4182
5928
|
hash: "SHA-256"
|
|
4183
5929
|
}, false, ["sign"]);
|
|
4184
5930
|
const signatureData = encoder.encode(message);
|
|
4185
|
-
|
|
5931
|
+
const signatureBuffer = await globalThis.crypto.subtle.sign("HMAC", key, signatureData);
|
|
5932
|
+
return arrayBufferToBase64(signatureBuffer);
|
|
4186
5933
|
}
|
|
4187
5934
|
/**
|
|
4188
5935
|
* Constant-time comparison of two strings to prevent timing attacks
|
|
@@ -4206,26 +5953,6 @@ const toStringOrDefault = (value, defaultValue) => {
|
|
|
4206
5953
|
const str = String(value);
|
|
4207
5954
|
return str.length > 0 ? str : defaultValue;
|
|
4208
5955
|
};
|
|
4209
|
-
const WEBHOOK_SUBSCRIPTIONS_PATH = "/api/v3.1/webhook_subscriptions";
|
|
4210
|
-
const asRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
4211
|
-
const firstString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
4212
|
-
const stringArray = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
4213
|
-
const transformWebhookSubscription = (subscription) => {
|
|
4214
|
-
const raw = asRecord(subscription);
|
|
4215
|
-
return {
|
|
4216
|
-
id: firstString(raw.id) ?? "",
|
|
4217
|
-
webhookUrl: firstString(raw.webhook_url) ?? firstString(raw.webhookUrl) ?? "",
|
|
4218
|
-
version: firstString(raw.version) ?? WebhookVersions.V3,
|
|
4219
|
-
enabledEvents: stringArray(raw.enabled_events).length ? stringArray(raw.enabled_events) : stringArray(raw.enabledEvents),
|
|
4220
|
-
secret: firstString(raw.secret),
|
|
4221
|
-
createdAt: firstString(raw.created_at) ?? firstString(raw.createdAt),
|
|
4222
|
-
updatedAt: firstString(raw.updated_at) ?? firstString(raw.updatedAt)
|
|
4223
|
-
};
|
|
4224
|
-
};
|
|
4225
|
-
const firstWebhookSubscriptionId = (response) => {
|
|
4226
|
-
const firstItem = Array.isArray(response.items) ? response.items[0] : void 0;
|
|
4227
|
-
return firstString(asRecord(firstItem).id);
|
|
4228
|
-
};
|
|
4229
5956
|
/**
|
|
4230
5957
|
* The signature header names Composio sends with every webhook delivery.
|
|
4231
5958
|
* @private
|
|
@@ -4279,7 +6006,7 @@ var Triggers = class {
|
|
|
4279
6006
|
toolkitVersions;
|
|
4280
6007
|
constructor(client, config) {
|
|
4281
6008
|
this.client = client;
|
|
4282
|
-
this.pusherService = new PusherService(client);
|
|
6009
|
+
this.pusherService = new PusherService(client, { defaultHeaders: config?.defaultHeaders });
|
|
4283
6010
|
this.toolkitVersions = config?.toolkitVersions ?? CONFIG_DEFAULTS.toolkitVersions;
|
|
4284
6011
|
telemetry.instrument(this, "Triggers");
|
|
4285
6012
|
}
|
|
@@ -4297,17 +6024,7 @@ var Triggers = class {
|
|
|
4297
6024
|
* ```
|
|
4298
6025
|
*/
|
|
4299
6026
|
async setWebhookSubscription(params) {
|
|
4300
|
-
|
|
4301
|
-
if (!parsedParams.success) throw new ValidationError(`Invalid parameters passed to set webhook subscription`, { cause: parsedParams.error });
|
|
4302
|
-
const body = {
|
|
4303
|
-
webhook_url: parsedParams.data.webhookUrl,
|
|
4304
|
-
enabled_events: parsedParams.data.enabledEvents ?? [...DefaultWebhookSubscriptionEvents],
|
|
4305
|
-
version: parsedParams.data.version ?? WebhookVersions.V3
|
|
4306
|
-
};
|
|
4307
|
-
const existing = await this.client.get(WEBHOOK_SUBSCRIPTIONS_PATH, { query: { limit: 1 } });
|
|
4308
|
-
const subscriptionId = firstWebhookSubscriptionId(existing);
|
|
4309
|
-
const subscription = subscriptionId ? await this.client.patch(`${WEBHOOK_SUBSCRIPTIONS_PATH}/${encodeURIComponent(subscriptionId)}`, { body }) : await this.client.post(WEBHOOK_SUBSCRIPTIONS_PATH, { body });
|
|
4310
|
-
return transformWebhookSubscription(subscription);
|
|
6027
|
+
return upsertWebhookSubscription(this.client, params);
|
|
4311
6028
|
}
|
|
4312
6029
|
/**
|
|
4313
6030
|
* Fetch list of all the active triggers
|
|
@@ -4338,7 +6055,8 @@ var Triggers = class {
|
|
|
4338
6055
|
trigger_ids: parsedParams.data.triggerIds,
|
|
4339
6056
|
trigger_names: parsedParams.data.triggerNames
|
|
4340
6057
|
} : void 0;
|
|
4341
|
-
|
|
6058
|
+
const result = await withCancellation(() => this.client.triggerInstances.listActive(listParams, requestOptions), requestOptions?.signal);
|
|
6059
|
+
return transformTriggerInstanceListActiveResponse(result);
|
|
4342
6060
|
}
|
|
4343
6061
|
/**
|
|
4344
6062
|
* Create a new trigger instance for a user
|
|
@@ -4431,7 +6149,8 @@ var Triggers = class {
|
|
|
4431
6149
|
toolkit_slugs: parsedQuery.toolkits,
|
|
4432
6150
|
toolkit_versions: this.toolkitVersions
|
|
4433
6151
|
};
|
|
4434
|
-
|
|
6152
|
+
const result = await withCancellation(() => this.client.triggersTypes.list(listParams, requestOptions), requestOptions?.signal);
|
|
6153
|
+
return transformTriggerTypeListResponse(result);
|
|
4435
6154
|
}
|
|
4436
6155
|
/**
|
|
4437
6156
|
* Retrieve a trigger type by its slug for the provided version of the app
|
|
@@ -4442,7 +6161,8 @@ var Triggers = class {
|
|
|
4442
6161
|
*/
|
|
4443
6162
|
async getType(slug, requestOptions) {
|
|
4444
6163
|
const retrieveParams = { toolkit_versions: this.toolkitVersions };
|
|
4445
|
-
|
|
6164
|
+
const result = await withCancellation(() => this.client.triggersTypes.retrieve(slug, retrieveParams, requestOptions), requestOptions?.signal);
|
|
6165
|
+
return transformTriggerTypeRetrieveResponse(result);
|
|
4446
6166
|
}
|
|
4447
6167
|
/**
|
|
4448
6168
|
* Fetches the list of all the available trigger enums
|
|
@@ -4495,6 +6215,10 @@ var Triggers = class {
|
|
|
4495
6215
|
*
|
|
4496
6216
|
* @param fn - The function to call when a trigger is received
|
|
4497
6217
|
* @param filters - The filters to apply to the triggers
|
|
6218
|
+
* @param onSubscriptionError - Optional callback invoked with the raw Pusher payload when
|
|
6219
|
+
* the underlying subscription fails (for example on auth or permission rejection). The
|
|
6220
|
+
* subscribe promise still resolves; this is the only programmatic signal of the failure.
|
|
6221
|
+
* Errors thrown from — or promises rejected by — the callback are contained and logged.
|
|
4498
6222
|
*
|
|
4499
6223
|
* @example
|
|
4500
6224
|
* ```ts
|
|
@@ -4504,7 +6228,7 @@ var Triggers = class {
|
|
|
4504
6228
|
* }, );
|
|
4505
6229
|
* ```
|
|
4506
6230
|
*/
|
|
4507
|
-
async subscribe(fn, filters = {}) {
|
|
6231
|
+
async subscribe(fn, filters = {}, onSubscriptionError) {
|
|
4508
6232
|
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
4509
6233
|
const parsedFilters = TriggerSubscribeParamSchema.safeParse(filters);
|
|
4510
6234
|
if (!parsedFilters.success) throw new ValidationError(`Invalid parameters passed to subscribe to triggers`, { cause: parsedFilters.error });
|
|
@@ -4518,7 +6242,7 @@ var Triggers = class {
|
|
|
4518
6242
|
logger.error("❌ Error in trigger callback:", error);
|
|
4519
6243
|
}
|
|
4520
6244
|
else logger.debug("Trigger does not match filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
4521
|
-
});
|
|
6245
|
+
}, onSubscriptionError);
|
|
4522
6246
|
}
|
|
4523
6247
|
/**
|
|
4524
6248
|
* Tries to parse data as V1, V2, or V3 webhook payload format.
|
|
@@ -4711,11 +6435,14 @@ var Triggers = class {
|
|
|
4711
6435
|
const id = getHeader(headers, WEBHOOK_HEADERS.id);
|
|
4712
6436
|
const timestamp = getHeader(headers, WEBHOOK_HEADERS.timestamp);
|
|
4713
6437
|
const signature = getHeader(headers, WEBHOOK_HEADERS.signature);
|
|
4714
|
-
if (!id || !timestamp || !signature)
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
6438
|
+
if (!id || !timestamp || !signature) {
|
|
6439
|
+
const missing = [
|
|
6440
|
+
!id ? `'${WEBHOOK_HEADERS.id}'` : void 0,
|
|
6441
|
+
!timestamp ? `'${WEBHOOK_HEADERS.timestamp}'` : void 0,
|
|
6442
|
+
!signature ? `'${WEBHOOK_HEADERS.signature}'` : void 0
|
|
6443
|
+
].filter((header) => header !== void 0);
|
|
6444
|
+
throw new ValidationError(`Cannot verify webhook: missing signature header(s) ${missing.join(", ")}. Pass the raw, unparsed request body and ensure the Composio signature headers (${WEBHOOK_HEADERS.id}, ${WEBHOOK_HEADERS.timestamp}, ${WEBHOOK_HEADERS.signature}) are forwarded to triggers.parse(). To parse without verifying, omit 'verifySecret'.`);
|
|
6445
|
+
}
|
|
4719
6446
|
return this.verifyWebhook({
|
|
4720
6447
|
payload: body,
|
|
4721
6448
|
signature,
|
|
@@ -4963,7 +6690,8 @@ var Triggers = class {
|
|
|
4963
6690
|
if (version === "v1" && value) v1Signatures.push(value);
|
|
4964
6691
|
}
|
|
4965
6692
|
if (v1Signatures.length === 0) throw new ComposioWebhookSignatureVerificationError("No valid v1 signature found in the webhook-signature header. Expected format: 'v1,base64EncodedSignature'");
|
|
4966
|
-
const
|
|
6693
|
+
const toSign = `${webhookId}.${webhookTimestamp}.${payload}`;
|
|
6694
|
+
const expectedSignature = await hmacSha256Base64(secret, toSign);
|
|
4967
6695
|
let isValid = false;
|
|
4968
6696
|
for (const providedSignature of v1Signatures) if (timingSafeEqual(providedSignature, expectedSignature)) {
|
|
4969
6697
|
isValid = true;
|
|
@@ -5150,17 +6878,19 @@ var MCP = class {
|
|
|
5150
6878
|
if (config.error) throw new ValidationError("Invalid parameters passed to create mcp config", { cause: config.error });
|
|
5151
6879
|
const toolkits = [];
|
|
5152
6880
|
const auth_config_ids = [];
|
|
5153
|
-
const
|
|
6881
|
+
const allowed_tools = config.data.allowedTools ?? [];
|
|
5154
6882
|
config.data.toolkits.forEach((toolkit) => {
|
|
5155
6883
|
if (typeof toolkit === "string") toolkits.push(toolkit);
|
|
5156
|
-
else
|
|
5157
|
-
|
|
6884
|
+
else {
|
|
6885
|
+
if (toolkit.toolkit) toolkits.push(toolkit.toolkit);
|
|
6886
|
+
if (toolkit.authConfigId) auth_config_ids.push(toolkit.authConfigId);
|
|
6887
|
+
}
|
|
5158
6888
|
});
|
|
5159
6889
|
const createBody = {
|
|
5160
6890
|
name,
|
|
5161
6891
|
toolkits,
|
|
5162
6892
|
auth_config_ids,
|
|
5163
|
-
|
|
6893
|
+
allowed_tools,
|
|
5164
6894
|
managed_auth_via_composio: config.data.manuallyManageConnections ? false : true
|
|
5165
6895
|
};
|
|
5166
6896
|
const server = await withCancellation(() => this.client.mcp.custom.create(createBody, requestOptions), requestOptions?.signal);
|
|
@@ -5220,7 +6950,8 @@ var MCP = class {
|
|
|
5220
6950
|
auth_config_ids: params.authConfigs?.length > 0 ? params.authConfigs.join(",") : void 0,
|
|
5221
6951
|
name: params.name
|
|
5222
6952
|
};
|
|
5223
|
-
|
|
6953
|
+
const listResponse = await withCancellation(() => this.client.mcp.list(listParams, requestOptions), requestOptions?.signal);
|
|
6954
|
+
return transform(listResponse).with(MCPListResponseSchema).using((raw) => ({
|
|
5224
6955
|
currentPage: raw.current_page,
|
|
5225
6956
|
totalPages: raw.total_pages,
|
|
5226
6957
|
items: raw.items.map((item) => ({
|
|
@@ -5354,152 +7085,401 @@ var MCP = class {
|
|
|
5354
7085
|
* authConfigId: "auth_gmail_prod",
|
|
5355
7086
|
* }
|
|
5356
7087
|
* ],
|
|
5357
|
-
* allowedTools: ["GMAIL_SEND_EMAIL", "GMAIL_FETCH_EMAILS"]
|
|
5358
|
-
* manuallyManageConnections: false
|
|
7088
|
+
* allowedTools: ["GMAIL_SEND_EMAIL", "GMAIL_FETCH_EMAILS"]
|
|
7089
|
+
* manuallyManageConnections: false
|
|
7090
|
+
* });
|
|
7091
|
+
*
|
|
7092
|
+
* console.log("Updated server:", fullyUpdatedServer.name);
|
|
7093
|
+
* console.log("New tools:", fullyUpdatedServer.allowedTools);
|
|
7094
|
+
* ```
|
|
7095
|
+
*
|
|
7096
|
+
* @throws {ValidationError} When the update parameters are invalid or malformed
|
|
7097
|
+
* @throws {Error} When the server ID doesn't exist or update fails
|
|
7098
|
+
*
|
|
7099
|
+
* @note Only provided fields will be updated. Omitted fields will retain their current values.
|
|
7100
|
+
* @note When updating toolkits, the entire toolkit configuration is replaced, not merged.
|
|
7101
|
+
*/
|
|
7102
|
+
async update(serverId, config, requestOptions) {
|
|
7103
|
+
const { data: params, error } = MCPUpdateParamsSchema.safeParse(config);
|
|
7104
|
+
if (error) throw new ValidationError("Failed to validate update params", { cause: error });
|
|
7105
|
+
const toolkits = [];
|
|
7106
|
+
const auth_config_ids = [];
|
|
7107
|
+
params.toolkits?.forEach((toolkit) => {
|
|
7108
|
+
if (typeof toolkit === "string") toolkits.push(toolkit);
|
|
7109
|
+
else {
|
|
7110
|
+
if (toolkit.toolkit) toolkits.push(toolkit.toolkit);
|
|
7111
|
+
if (toolkit.authConfigId) auth_config_ids.push(toolkit.authConfigId);
|
|
7112
|
+
}
|
|
7113
|
+
});
|
|
7114
|
+
const updateBody = {
|
|
7115
|
+
...params.name !== void 0 ? { name: params.name } : {},
|
|
7116
|
+
...params.toolkits !== void 0 ? {
|
|
7117
|
+
toolkits,
|
|
7118
|
+
auth_config_ids
|
|
7119
|
+
} : {},
|
|
7120
|
+
...params.allowedTools !== void 0 ? { allowed_tools: params.allowedTools } : {},
|
|
7121
|
+
...params.manuallyManageConnections !== void 0 ? { managed_auth_via_composio: !params.manuallyManageConnections } : {}
|
|
7122
|
+
};
|
|
7123
|
+
return transformMCPItemResponse(await withCancellation(() => this.client.mcp.update(serverId, updateBody, requestOptions), requestOptions?.signal));
|
|
7124
|
+
}
|
|
7125
|
+
/**
|
|
7126
|
+
* Get server URLs for an existing MCP server.
|
|
7127
|
+
* The response is wrapped according to the provider's specifications.
|
|
7128
|
+
*
|
|
7129
|
+
* @example
|
|
7130
|
+
* ```typescript
|
|
7131
|
+
* import { Composio } from "@composio/code";
|
|
7132
|
+
*
|
|
7133
|
+
* const composio = new Composio();
|
|
7134
|
+
* const mcp = await composio.experimental.mcp.generate("default", "<mcp_config_id>");
|
|
7135
|
+
* ```
|
|
7136
|
+
*
|
|
7137
|
+
* @param userId {string} external user id from your database for whom you want the server for
|
|
7138
|
+
* @param mcpConfigId {string} config id of the MCPConfig for which you want to create a server for
|
|
7139
|
+
* @param options {object} additional options
|
|
7140
|
+
* @param options.isChatAuth {boolean} Authenticate the users via chat when they use the MCP Server
|
|
7141
|
+
*/
|
|
7142
|
+
async generate(userId, mcpConfigId, options, requestOptions) {
|
|
7143
|
+
const server = await withCancellation(() => this.client.mcp.retrieve(mcpConfigId, requestOptions), requestOptions?.signal);
|
|
7144
|
+
const params = MCPGetInstanceParamsSchema.safeParse(options ?? { manuallyManageConnections: false });
|
|
7145
|
+
if (params.error) throw new ValidationError("Invalid params passed for Get Instance Params", { cause: params.error });
|
|
7146
|
+
const urlBody = {
|
|
7147
|
+
mcp_server_id: mcpConfigId,
|
|
7148
|
+
user_ids: [userId],
|
|
7149
|
+
managed_auth_by_composio: options?.manuallyManageConnections ? false : true
|
|
7150
|
+
};
|
|
7151
|
+
const userIdsURL = (await withCancellation(() => this.client.mcp.generate.url(urlBody, requestOptions), requestOptions?.signal)).user_ids_url[0];
|
|
7152
|
+
const serverInstance = MCPServerInstanceSchema.safeParse({
|
|
7153
|
+
id: server.id,
|
|
7154
|
+
name: server.name,
|
|
7155
|
+
type: "streamable_http",
|
|
7156
|
+
url: userIdsURL,
|
|
7157
|
+
userId,
|
|
7158
|
+
allowedTools: server.allowed_tools,
|
|
7159
|
+
authConfigs: server.auth_config_ids
|
|
7160
|
+
});
|
|
7161
|
+
if (serverInstance.error) throw new ValidationError("Failed to parse MCP server instance", { cause: serverInstance.error });
|
|
7162
|
+
return serverInstance.data;
|
|
7163
|
+
}
|
|
7164
|
+
};
|
|
7165
|
+
|
|
7166
|
+
//#endregion
|
|
7167
|
+
//#region src/types/logs.types.ts
|
|
7168
|
+
/**
|
|
7169
|
+
* Fields a tool-execution log search can filter on.
|
|
7170
|
+
*/
|
|
7171
|
+
const LogSearchFilterFieldSchema = z$1.enum([
|
|
7172
|
+
"tool_slug",
|
|
7173
|
+
"toolkit_slug",
|
|
7174
|
+
"connected_account_id",
|
|
7175
|
+
"auth_config_id",
|
|
7176
|
+
"status",
|
|
7177
|
+
"user_id",
|
|
7178
|
+
"session_id",
|
|
7179
|
+
"sandbox_id",
|
|
7180
|
+
"request_id",
|
|
7181
|
+
"log_id"
|
|
7182
|
+
]);
|
|
7183
|
+
const LogSearchFilterOperatorSchema = z$1.enum([
|
|
7184
|
+
"==",
|
|
7185
|
+
"!=",
|
|
7186
|
+
"contains",
|
|
7187
|
+
"not_contains"
|
|
7188
|
+
]);
|
|
7189
|
+
const LogSearchFilterSchema = z$1.object({
|
|
7190
|
+
field: LogSearchFilterFieldSchema,
|
|
7191
|
+
operator: LogSearchFilterOperatorSchema,
|
|
7192
|
+
value: z$1.string()
|
|
7193
|
+
});
|
|
7194
|
+
const LogSearchTimeRangeSchema = z$1.object({
|
|
7195
|
+
/** Start time in epoch milliseconds (inclusive). */
|
|
7196
|
+
from: z$1.number(),
|
|
7197
|
+
/** End time in epoch milliseconds. */
|
|
7198
|
+
to: z$1.number()
|
|
7199
|
+
});
|
|
7200
|
+
/**
|
|
7201
|
+
* Params for `composio.logs.search()`.
|
|
7202
|
+
*/
|
|
7203
|
+
const LogSearchParamsSchema = z$1.object({
|
|
7204
|
+
limit: z$1.number().optional(),
|
|
7205
|
+
cursor: z$1.string().nullable().optional(),
|
|
7206
|
+
filters: z$1.array(LogSearchFilterSchema).optional(),
|
|
7207
|
+
timeRange: LogSearchTimeRangeSchema.optional()
|
|
7208
|
+
});
|
|
7209
|
+
const ToolExecutionLogStatusSchema = z$1.enum(["success", "failed"]);
|
|
7210
|
+
const ToolExecutionLogLevelSchema = z$1.enum([
|
|
7211
|
+
"info",
|
|
7212
|
+
"error",
|
|
7213
|
+
"warn"
|
|
7214
|
+
]);
|
|
7215
|
+
const ToolExecutionLogParentSchema = z$1.object({
|
|
7216
|
+
logId: z$1.string(),
|
|
7217
|
+
toolSlug: z$1.string()
|
|
7218
|
+
}).nullable();
|
|
7219
|
+
/**
|
|
7220
|
+
* A tool-execution log entry as returned by `composio.logs.search()`.
|
|
7221
|
+
*/
|
|
7222
|
+
const ToolExecutionLogSchema = z$1.object({
|
|
7223
|
+
id: z$1.string(),
|
|
7224
|
+
/** ISO 8601 timestamp. */
|
|
7225
|
+
timestamp: z$1.string(),
|
|
7226
|
+
/** Log event type, e.g. `tool.execution`. */
|
|
7227
|
+
type: z$1.string(),
|
|
7228
|
+
status: ToolExecutionLogStatusSchema,
|
|
7229
|
+
level: ToolExecutionLogLevelSchema,
|
|
7230
|
+
message: z$1.string().optional(),
|
|
7231
|
+
metadata: z$1.record(z$1.string(), z$1.unknown()),
|
|
7232
|
+
metrics: z$1.record(z$1.string(), z$1.unknown()),
|
|
7233
|
+
parent: ToolExecutionLogParentSchema
|
|
7234
|
+
});
|
|
7235
|
+
const LogSearchResponseSchema = z$1.object({
|
|
7236
|
+
logs: z$1.array(ToolExecutionLogSchema),
|
|
7237
|
+
nextCursor: z$1.string().nullable()
|
|
7238
|
+
});
|
|
7239
|
+
/**
|
|
7240
|
+
* A single tool-execution log with its full detail, as returned by
|
|
7241
|
+
* `composio.logs.get()`.
|
|
7242
|
+
*/
|
|
7243
|
+
const ToolExecutionLogDetailSchema = ToolExecutionLogSchema.extend({
|
|
7244
|
+
timings: z$1.object({
|
|
7245
|
+
/** Epoch milliseconds. */
|
|
7246
|
+
startTime: z$1.number(),
|
|
7247
|
+
/** Epoch milliseconds. */
|
|
7248
|
+
endTime: z$1.number()
|
|
7249
|
+
}).optional(),
|
|
7250
|
+
context: z$1.object({
|
|
7251
|
+
sessionId: z$1.string().optional(),
|
|
7252
|
+
traceId: z$1.string().optional(),
|
|
7253
|
+
requestId: z$1.string().optional()
|
|
7254
|
+
}),
|
|
7255
|
+
source: z$1.object({
|
|
7256
|
+
host: z$1.string().optional(),
|
|
7257
|
+
framework: z$1.string().optional(),
|
|
7258
|
+
language: z$1.string().optional()
|
|
7259
|
+
}),
|
|
7260
|
+
data: z$1.record(z$1.string(), z$1.unknown())
|
|
7261
|
+
});
|
|
7262
|
+
|
|
7263
|
+
//#endregion
|
|
7264
|
+
//#region src/utils/transformers/logs.ts
|
|
7265
|
+
const transformLogSearchParams = (params) => ({
|
|
7266
|
+
limit: params.limit,
|
|
7267
|
+
cursor: params.cursor,
|
|
7268
|
+
filters: params.filters,
|
|
7269
|
+
time_range: params.timeRange
|
|
7270
|
+
});
|
|
7271
|
+
const transformToolExecutionLog = (response) => {
|
|
7272
|
+
return transform(response).with(ToolExecutionLogSchema).using((response) => ({
|
|
7273
|
+
id: response.id,
|
|
7274
|
+
timestamp: response.timestamp,
|
|
7275
|
+
type: response.type,
|
|
7276
|
+
status: response.status,
|
|
7277
|
+
level: response.level,
|
|
7278
|
+
message: response.message,
|
|
7279
|
+
metadata: response.metadata,
|
|
7280
|
+
metrics: response.metrics,
|
|
7281
|
+
parent: response.parent ? {
|
|
7282
|
+
logId: response.parent.log_id,
|
|
7283
|
+
toolSlug: response.parent.tool_slug
|
|
7284
|
+
} : null
|
|
7285
|
+
}));
|
|
7286
|
+
};
|
|
7287
|
+
const transformLogSearchResponse = (response) => {
|
|
7288
|
+
return transform(response).with(LogSearchResponseSchema).using((response) => ({
|
|
7289
|
+
logs: response.logs.map(transformToolExecutionLog),
|
|
7290
|
+
nextCursor: response.next_cursor
|
|
7291
|
+
}));
|
|
7292
|
+
};
|
|
7293
|
+
const transformToolExecutionLogDetail = (response) => {
|
|
7294
|
+
return transform(response).with(ToolExecutionLogDetailSchema).using((response) => ({
|
|
7295
|
+
id: response.id,
|
|
7296
|
+
timestamp: response.timestamp,
|
|
7297
|
+
type: response.type,
|
|
7298
|
+
status: response.status,
|
|
7299
|
+
level: response.level,
|
|
7300
|
+
message: response.message,
|
|
7301
|
+
metadata: response.metadata,
|
|
7302
|
+
metrics: response.metrics,
|
|
7303
|
+
parent: response.parent ? {
|
|
7304
|
+
logId: response.parent.log_id,
|
|
7305
|
+
toolSlug: response.parent.tool_slug
|
|
7306
|
+
} : null,
|
|
7307
|
+
timings: response.timings ? {
|
|
7308
|
+
startTime: response.timings.start_time,
|
|
7309
|
+
endTime: response.timings.end_time
|
|
7310
|
+
} : void 0,
|
|
7311
|
+
context: {
|
|
7312
|
+
sessionId: response.context.session_id,
|
|
7313
|
+
traceId: response.context.trace_id,
|
|
7314
|
+
requestId: response.context.request_id
|
|
7315
|
+
},
|
|
7316
|
+
source: {
|
|
7317
|
+
host: response.source.host,
|
|
7318
|
+
framework: response.source.framework,
|
|
7319
|
+
language: response.source.language
|
|
7320
|
+
},
|
|
7321
|
+
data: response.data
|
|
7322
|
+
}));
|
|
7323
|
+
};
|
|
7324
|
+
|
|
7325
|
+
//#endregion
|
|
7326
|
+
//#region src/models/Logs.ts
|
|
7327
|
+
/**
|
|
7328
|
+
* `composio.logs` — tool-execution logs.
|
|
7329
|
+
*
|
|
7330
|
+
* @example
|
|
7331
|
+
* ```typescript
|
|
7332
|
+
* const { logs, nextCursor } = await composio.logs.search({
|
|
7333
|
+
* filters: [{ field: 'toolkit_slug', operator: '==', value: 'github' }],
|
|
7334
|
+
* limit: 20,
|
|
7335
|
+
* });
|
|
7336
|
+
* const detail = await composio.logs.get(logs[0].id);
|
|
7337
|
+
* ```
|
|
7338
|
+
*/
|
|
7339
|
+
var Logs = class {
|
|
7340
|
+
client;
|
|
7341
|
+
constructor(client) {
|
|
7342
|
+
this.client = client;
|
|
7343
|
+
telemetry.instrument(this, "Logs");
|
|
7344
|
+
}
|
|
7345
|
+
/**
|
|
7346
|
+
* Search tool-execution logs with filters, a time range and cursor
|
|
7347
|
+
* pagination.
|
|
7348
|
+
*
|
|
7349
|
+
* @param {LogSearchParams} [params] - Filters, `timeRange`, `limit` and `cursor`
|
|
7350
|
+
* @returns {Promise<LogSearchResponse>} Matching logs and the next cursor
|
|
7351
|
+
* @throws {ValidationError} If the params fail validation
|
|
7352
|
+
*
|
|
7353
|
+
* @example
|
|
7354
|
+
* ```typescript
|
|
7355
|
+
* const { logs } = await composio.logs.search({
|
|
7356
|
+
* filters: [
|
|
7357
|
+
* { field: 'status', operator: '==', value: 'failed' },
|
|
7358
|
+
* { field: 'user_id', operator: '==', value: 'user_123' },
|
|
7359
|
+
* ],
|
|
7360
|
+
* timeRange: { from: Date.now() - 24 * 60 * 60 * 1000, to: Date.now() },
|
|
5359
7361
|
* });
|
|
5360
|
-
*
|
|
5361
|
-
* console.log("Updated server:", fullyUpdatedServer.name);
|
|
5362
|
-
* console.log("New tools:", fullyUpdatedServer.allowedTools);
|
|
5363
7362
|
* ```
|
|
5364
|
-
*
|
|
5365
|
-
* @throws {ValidationError} When the update parameters are invalid or malformed
|
|
5366
|
-
* @throws {Error} When the server ID doesn't exist or update fails
|
|
5367
|
-
*
|
|
5368
|
-
* @note Only provided fields will be updated. Omitted fields will retain their current values.
|
|
5369
|
-
* @note When updating toolkits, the entire toolkit configuration is replaced, not merged.
|
|
5370
7363
|
*/
|
|
5371
|
-
async
|
|
5372
|
-
const
|
|
5373
|
-
if (
|
|
5374
|
-
const
|
|
5375
|
-
const
|
|
5376
|
-
|
|
5377
|
-
params.toolkits?.forEach((toolkit) => {
|
|
5378
|
-
if (typeof toolkit === "string") toolkits.push(toolkit);
|
|
5379
|
-
else if (toolkit.toolkit) toolkits.push(toolkit.toolkit);
|
|
5380
|
-
else if (toolkit.authConfigId) auth_config_ids.push(toolkit.authConfigId);
|
|
5381
|
-
});
|
|
5382
|
-
const updateBody = {
|
|
5383
|
-
name: params.name ?? void 0,
|
|
5384
|
-
...params.toolkits ? {
|
|
5385
|
-
custom_tools,
|
|
5386
|
-
toolkits,
|
|
5387
|
-
auth_config_ids
|
|
5388
|
-
} : {},
|
|
5389
|
-
managed_auth_via_composio: params.manuallyManageConnections ?? void 0
|
|
5390
|
-
};
|
|
5391
|
-
return transformMCPItemResponse(await withCancellation(() => this.client.mcp.update(serverId, updateBody, requestOptions), requestOptions?.signal));
|
|
7364
|
+
async search(params, requestOptions) {
|
|
7365
|
+
const parsedParams = LogSearchParamsSchema.safeParse(params ?? {});
|
|
7366
|
+
if (!parsedParams.success) throw new ValidationError("Failed to parse log search params", { cause: parsedParams.error });
|
|
7367
|
+
const body = transformLogSearchParams(parsedParams.data);
|
|
7368
|
+
const result = await withCancellation(() => this.client.logs.createToolExecution(body, requestOptions), requestOptions?.signal);
|
|
7369
|
+
return transformLogSearchResponse(result);
|
|
5392
7370
|
}
|
|
5393
7371
|
/**
|
|
5394
|
-
*
|
|
5395
|
-
*
|
|
7372
|
+
* Retrieve one tool-execution log with its full detail (timings, context,
|
|
7373
|
+
* source and raw `data`).
|
|
7374
|
+
*
|
|
7375
|
+
* @param {string} id - The log id
|
|
7376
|
+
* @returns {Promise<ToolExecutionLogDetail>} The log detail
|
|
5396
7377
|
*
|
|
5397
7378
|
* @example
|
|
5398
7379
|
* ```typescript
|
|
5399
|
-
*
|
|
5400
|
-
*
|
|
5401
|
-
* const composio = new Composio();
|
|
5402
|
-
* const mcp = await composio.experimental.mcp.generate("default", "<mcp_config_id>");
|
|
7380
|
+
* const log = await composio.logs.get('log_abc123');
|
|
7381
|
+
* console.log(log.status, log.timings?.endTime);
|
|
5403
7382
|
* ```
|
|
5404
|
-
*
|
|
5405
|
-
* @param userId {string} external user id from your database for whom you want the server for
|
|
5406
|
-
* @param mcpConfigId {string} config id of the MCPConfig for which you want to create a server for
|
|
5407
|
-
* @param options {object} additional options
|
|
5408
|
-
* @param options.isChatAuth {boolean} Authenticate the users via chat when they use the MCP Server
|
|
5409
7383
|
*/
|
|
5410
|
-
async
|
|
5411
|
-
const
|
|
5412
|
-
|
|
5413
|
-
if (params.error) throw new ValidationError("Invalid params passed for Get Instance Params", { cause: params.error });
|
|
5414
|
-
const urlBody = {
|
|
5415
|
-
mcp_server_id: mcpConfigId,
|
|
5416
|
-
user_ids: [userId],
|
|
5417
|
-
managed_auth_by_composio: options?.manuallyManageConnections ? false : true
|
|
5418
|
-
};
|
|
5419
|
-
const userIdsURL = (await withCancellation(() => this.client.mcp.generate.url(urlBody, requestOptions), requestOptions?.signal)).user_ids_url[0];
|
|
5420
|
-
const serverInstance = MCPServerInstanceSchema.safeParse({
|
|
5421
|
-
id: server.id,
|
|
5422
|
-
name: server.name,
|
|
5423
|
-
type: "streamable_http",
|
|
5424
|
-
url: userIdsURL,
|
|
5425
|
-
userId,
|
|
5426
|
-
allowedTools: server.allowed_tools,
|
|
5427
|
-
authConfigs: server.auth_config_ids
|
|
5428
|
-
});
|
|
5429
|
-
if (serverInstance.error) throw new ValidationError("Failed to parse MCP server instance", { cause: serverInstance.error });
|
|
5430
|
-
return serverInstance.data;
|
|
7384
|
+
async get(id, requestOptions) {
|
|
7385
|
+
const result = await withCancellation(() => this.client.logs.retrieveToolExecution(id, requestOptions), requestOptions?.signal);
|
|
7386
|
+
return transformToolExecutionLogDetail(result);
|
|
5431
7387
|
}
|
|
5432
7388
|
};
|
|
5433
7389
|
|
|
5434
7390
|
//#endregion
|
|
5435
|
-
//#region src/
|
|
5436
|
-
const userDataPath = () => {
|
|
5437
|
-
try {
|
|
5438
|
-
const homeDir = platform.homedir();
|
|
5439
|
-
if (!homeDir) return null;
|
|
5440
|
-
return platform.joinPath(homeDir, COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
5441
|
-
} catch (_error) {
|
|
5442
|
-
logger.debug("Environment", `Unable to get user data path`);
|
|
5443
|
-
return null;
|
|
5444
|
-
}
|
|
5445
|
-
};
|
|
7391
|
+
//#region src/types/keyring.types.ts
|
|
5446
7392
|
/**
|
|
5447
|
-
*
|
|
5448
|
-
*
|
|
5449
|
-
* @returns The parsed user data object containing user configuration (api_key, base_url, etc.), or empty object if file doesn't exist or can't be read
|
|
7393
|
+
* A public JWK a secret can be sealed to. Fields keep their JWK names so a
|
|
7394
|
+
* key can be handed straight to WebCrypto or a JOSE library.
|
|
5450
7395
|
*/
|
|
5451
|
-
const
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
7396
|
+
const KeyringTransferKeySchema = z$1.object({
|
|
7397
|
+
/** Key type. Always `RSA`. */
|
|
7398
|
+
kty: z$1.string(),
|
|
7399
|
+
/** RSA modulus, base64url-encoded. */
|
|
7400
|
+
n: z$1.string(),
|
|
7401
|
+
/** RSA public exponent, base64url-encoded. */
|
|
7402
|
+
e: z$1.string(),
|
|
7403
|
+
/** Key-management algorithm for the JWE (`RSA-OAEP-256`). Pair it with `A256GCM` content encryption. */
|
|
7404
|
+
alg: z$1.string(),
|
|
7405
|
+
/** Key use. Always `enc`. */
|
|
7406
|
+
use: z$1.string(),
|
|
7407
|
+
/** Key identifier. Put it in the JWE protected header. */
|
|
7408
|
+
kid: z$1.string()
|
|
7409
|
+
});
|
|
7410
|
+
/**
|
|
7411
|
+
* Response of `composio.keyring.listTransferKeys()`.
|
|
7412
|
+
*/
|
|
7413
|
+
const KeyringTransferKeysResponseSchema = z$1.object({
|
|
7414
|
+
/** The `kid` of the key to seal new secrets to. */
|
|
7415
|
+
activeKid: z$1.string(),
|
|
7416
|
+
/** Every currently accepted transfer key, newest first. */
|
|
7417
|
+
keys: z$1.array(KeyringTransferKeySchema)
|
|
7418
|
+
});
|
|
7419
|
+
|
|
7420
|
+
//#endregion
|
|
7421
|
+
//#region src/utils/transformers/keyring.ts
|
|
7422
|
+
const transformKeyringTransferKeysResponse = (response) => {
|
|
7423
|
+
return transform(response).with(KeyringTransferKeysResponseSchema).using((response) => ({
|
|
7424
|
+
activeKid: response.active_kid,
|
|
7425
|
+
keys: response.keys.map((key) => ({
|
|
7426
|
+
kty: key.kty,
|
|
7427
|
+
n: key.n,
|
|
7428
|
+
e: key.e,
|
|
7429
|
+
alg: key.alg,
|
|
7430
|
+
use: key.use,
|
|
7431
|
+
kid: key.kid
|
|
7432
|
+
}))
|
|
7433
|
+
}));
|
|
5461
7434
|
};
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
const apiKeyParsed = apiKey || getEnvVariable("COMPOSIO_API_KEY") || apiKeyFromUserConfig || "";
|
|
5466
|
-
if (!apiKeyParsed) ComposioError.handleAndThrow(new ComposioNoAPIKeyError());
|
|
5467
|
-
logger.debug("Environment", "API Key: [REDACTED]");
|
|
5468
|
-
logger.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
5469
|
-
return {
|
|
5470
|
-
baseURL: baseURLParsed,
|
|
5471
|
-
apiKey: apiKeyParsed
|
|
5472
|
-
};
|
|
5473
|
-
}
|
|
7435
|
+
|
|
7436
|
+
//#endregion
|
|
7437
|
+
//#region src/models/Keyring.ts
|
|
5474
7438
|
/**
|
|
5475
|
-
*
|
|
5476
|
-
*
|
|
5477
|
-
* Priority order:
|
|
5478
|
-
* 1. If defaultVersions is a string, use it as global version for all toolkits
|
|
5479
|
-
* 2. User-provided toolkit version mappings (defaultVersions object)
|
|
5480
|
-
* 3. Environment variables (COMPOSIO_TOOLKIT_VERSION_<TOOLKIT_NAME>)
|
|
5481
|
-
* 4. Fallback to 'latest' if no versions are configured
|
|
7439
|
+
* `composio.keyring` — the organization's customer-managed keyring.
|
|
5482
7440
|
*
|
|
5483
|
-
* @
|
|
5484
|
-
*
|
|
7441
|
+
* @example
|
|
7442
|
+
* ```typescript
|
|
7443
|
+
* const { activeKid, keys } = await composio.keyring.listTransferKeys();
|
|
7444
|
+
* const sealingKey = keys.find(key => key.kid === activeKid);
|
|
7445
|
+
* ```
|
|
5485
7446
|
*/
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
7447
|
+
var Keyring = class {
|
|
7448
|
+
client;
|
|
7449
|
+
constructor(client) {
|
|
7450
|
+
this.client = client;
|
|
7451
|
+
telemetry.instrument(this, "Keyring");
|
|
7452
|
+
}
|
|
7453
|
+
/**
|
|
7454
|
+
* Lists the public transfer keys of the organization's active customer
|
|
7455
|
+
* keyring, the keys a secret is sealed to before it is sent to Composio.
|
|
7456
|
+
*
|
|
7457
|
+
* Always seal new secrets to the key whose `kid` is `activeKid`: a JWE with
|
|
7458
|
+
* `RSA-OAEP-256` key management, `A256GCM` content encryption, and the
|
|
7459
|
+
* `kid` in the protected header. Older keys stay listed so values sealed to
|
|
7460
|
+
* them remain openable.
|
|
7461
|
+
*
|
|
7462
|
+
* The organization behind the API key must have an ACTIVE customer keyring
|
|
7463
|
+
* instance; otherwise the API answers 404.
|
|
7464
|
+
*
|
|
7465
|
+
* @returns {Promise<KeyringTransferKeysResponse>} The active key ID and every accepted public JWK, newest first
|
|
7466
|
+
*
|
|
7467
|
+
* @example
|
|
7468
|
+
* ```typescript
|
|
7469
|
+
* import { CompactEncrypt, importJWK } from 'jose';
|
|
7470
|
+
*
|
|
7471
|
+
* const { activeKid, keys } = await composio.keyring.listTransferKeys();
|
|
7472
|
+
* const jwk = keys.find(key => key.kid === activeKid)!;
|
|
7473
|
+
* const sealed = await new CompactEncrypt(new TextEncoder().encode(secret))
|
|
7474
|
+
* .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM', kid: activeKid })
|
|
7475
|
+
* .encrypt(await importJWK(jwk, 'RSA-OAEP-256'));
|
|
7476
|
+
* ```
|
|
7477
|
+
*/
|
|
7478
|
+
async listTransferKeys(requestOptions) {
|
|
7479
|
+
const result = await withCancellation(() => this.client.keyring.listTransferKeys(requestOptions), requestOptions?.signal);
|
|
7480
|
+
return transformKeyringTransferKeysResponse(result);
|
|
7481
|
+
}
|
|
7482
|
+
};
|
|
5503
7483
|
|
|
5504
7484
|
//#endregion
|
|
5505
7485
|
//#region src/utils/version.ts
|
|
@@ -6017,7 +7997,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
6017
7997
|
|
|
6018
7998
|
//#endregion
|
|
6019
7999
|
//#region package.json
|
|
6020
|
-
var version = "0.
|
|
8000
|
+
var version = "0.20.0";
|
|
6021
8001
|
|
|
6022
8002
|
//#endregion
|
|
6023
8003
|
//#region src/utils/session.ts
|
|
@@ -6149,7 +8129,7 @@ const ToolRouterConfigToolsSchema = z.union([
|
|
|
6149
8129
|
});
|
|
6150
8130
|
const ToolRouterCreateSessionConfigBaseSchema = z.object({
|
|
6151
8131
|
sessionPreset: z.literal(SessionPreset.DIRECT_TOOLS).optional().describe("Shortcut to expose every tool allowed by the session filters directly in session.tools() and the MCP tool list. This disables meta tools by default (search, multi-execute, manage-connections, and workbench). Use when all tools are known upfront and helper/meta tools are not needed. Without this preset, ToolRouter uses its default configuration with meta tools enabled."),
|
|
6152
|
-
mcp: z.boolean().optional().describe("When true, the returned session surfaces its hosted MCP endpoint (`session.mcp.url` / `session.mcp.headers`) in the type. The endpoint exists on every session at runtime regardless of this flag, but is only typed when `mcp: true` is passed. Default native tools (`session.tools()`) are unaffected. See https://docs.composio.dev/docs/sessions-via-mcp"),
|
|
8132
|
+
mcp: z.boolean().optional().describe("When true, the returned session surfaces its hosted MCP endpoint (`session.mcp.url` / `session.mcp.headers`) in the type, and an MCP URL that is not on the API base URL origin throws `ComposioMCPDestinationError` instead of leaving `session.mcp.headers` empty with a warning. The endpoint exists on every session at runtime regardless of this flag, but is only typed when `mcp: true` is passed. Default native tools (`session.tools()`) are unaffected. See https://docs.composio.dev/docs/sessions-via-mcp"),
|
|
6153
8133
|
tools: z.record(z.string(), z.union([ToolRouterToolsParamSchema, ToolRouterConfigToolsSchema])).optional().describe("The tools to use in the tool router session"),
|
|
6154
8134
|
tags: ToolRouterConfigTagsSchema.optional().describe("Global tags to filter the tools by"),
|
|
6155
8135
|
toolkits: z.union([
|
|
@@ -6316,29 +8296,76 @@ const SessionProxyExecuteParamsSchema = z.object({
|
|
|
6316
8296
|
value: z.union([z.string(), z.number()])
|
|
6317
8297
|
})).optional()
|
|
6318
8298
|
});
|
|
8299
|
+
/**
|
|
8300
|
+
* `manageConnections` shape accepted by `session.update()`. Unlike the create
|
|
8301
|
+
* schema, `callbackUrl: null` removes the stored callback URL while leaving
|
|
8302
|
+
* the sibling connection settings untouched.
|
|
8303
|
+
*/
|
|
8304
|
+
const ToolRouterUpdateManageConnectionsSchema = z.object({
|
|
8305
|
+
enable: z.boolean().optional().describe("Whether to use tools to manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually"),
|
|
8306
|
+
callbackUrl: z.string().nullable().optional().describe("The callback url to use in the tool router session. `null` removes the stored callback url; sibling settings are untouched"),
|
|
8307
|
+
waitForConnections: z.boolean().optional().describe("Whether to wait for users to finish authenticating connections before proceeding to the next step. Defaults to false, if set to true, a wait for connections tool call will happen and finish when the connections are ready"),
|
|
8308
|
+
enableConnectionRemoval: z.boolean().nullable().optional().describe("Whether the session exposes the connection removal tool. `null` removes the stored override")
|
|
8309
|
+
}).strict();
|
|
8310
|
+
const ToolRouterElicitationDefaultSchema = z.enum([
|
|
8311
|
+
"allow_all",
|
|
8312
|
+
"ask_every_call",
|
|
8313
|
+
"ask_once_per_session"
|
|
8314
|
+
]);
|
|
8315
|
+
const ToolRouterElicitationOverrideSchema = z.enum([
|
|
8316
|
+
"always_allow",
|
|
8317
|
+
"always_deny",
|
|
8318
|
+
"ask_once",
|
|
8319
|
+
"ask_always"
|
|
8320
|
+
]);
|
|
8321
|
+
/**
|
|
8322
|
+
* `experimental` block accepted by `session.update()`. Each leaf follows the
|
|
8323
|
+
* PATCH contract of the API: omit to keep the stored value, `null` to remove
|
|
8324
|
+
* it, a value to replace it.
|
|
8325
|
+
*/
|
|
8326
|
+
const ToolRouterUpdateExperimentalSchema = z.object({
|
|
8327
|
+
permissions: z.object({
|
|
8328
|
+
default: ToolRouterElicitationDefaultSchema,
|
|
8329
|
+
overrides: z.record(z.string(), ToolRouterElicitationOverrideSchema).optional()
|
|
8330
|
+
}).strict().nullable().optional().describe("Per-tool elicitation permission config. `null` removes the stored block"),
|
|
8331
|
+
linkUrlOverwrite: z.string().nullable().optional().describe("Base URL override for connection link redirects. `null` removes the stored override"),
|
|
8332
|
+
fastMode: z.boolean().nullable().optional().describe("Fast search mode. `null` removes the stored override"),
|
|
8333
|
+
submitFeedback: z.object({ enable: z.boolean() }).strict().nullable().optional().describe("Exposes the COMPOSIO_SUBMIT_FEEDBACK helper tool. `null` removes the stored block"),
|
|
8334
|
+
sessionConfigId: z.string().optional().describe("Apply the latest active Session config from this project to this session")
|
|
8335
|
+
}).strict();
|
|
8336
|
+
/**
|
|
8337
|
+
* Options for `session.update()`. For every policy block, omitting the key
|
|
8338
|
+
* preserves the stored value and `null` removes the stored override (which can
|
|
8339
|
+
* increase access: `toolkits: null` restores the unrestricted default, unlike
|
|
8340
|
+
* `toolkits: []`, which denies every app toolkit).
|
|
8341
|
+
*/
|
|
6319
8342
|
const ToolRouterUpdateSessionConfigSchema = z.object({
|
|
6320
8343
|
toolkits: z.union([
|
|
6321
8344
|
ToolRouterToolkitsParamSchema,
|
|
6322
8345
|
ToolRouterToolkitsDisabledConfigSchema,
|
|
6323
8346
|
ToolRouterToolkitsEnabledConfigSchema
|
|
6324
|
-
]).optional(),
|
|
6325
|
-
tools: z.record(z.string(), z.union([ToolRouterToolsParamSchema, ToolRouterConfigToolsSchema])).optional(),
|
|
6326
|
-
tags: ToolRouterConfigTagsSchema.optional(),
|
|
6327
|
-
authConfigs: z.record(z.string(), z.string()).optional(),
|
|
8347
|
+
]).nullable().optional().describe("Toolkit policy. An empty allowlist (`[]` or `{ enable: [] }`) is sent as-is and denies every app toolkit; `null` removes the stored policy and restores the unrestricted default"),
|
|
8348
|
+
tools: z.record(z.string(), z.union([ToolRouterToolsParamSchema, ToolRouterConfigToolsSchema])).nullable().optional().describe("Replaces the entire stored tools map; `null` removes the override"),
|
|
8349
|
+
tags: ToolRouterConfigTagsSchema.nullable().optional().describe("Replaces the global tag policy; `null` removes the override"),
|
|
8350
|
+
authConfigs: z.record(z.string(), z.string()).nullable().optional().describe("Replaces the entire stored auth config map; `null` removes the override"),
|
|
6328
8351
|
connectedAccounts: z.record(z.string(), z.union([z.string(), z.array(z.string())])).transform((rec) => {
|
|
6329
8352
|
const out = {};
|
|
6330
8353
|
for (const [k, v] of Object.entries(rec)) out[k] = typeof v === "string" ? [v] : v;
|
|
6331
8354
|
return out;
|
|
6332
|
-
}).optional(),
|
|
6333
|
-
manageConnections: z.union([z.boolean(),
|
|
8355
|
+
}).nullable().optional().describe("Replaces the entire stored connected accounts map; `null` removes the override"),
|
|
8356
|
+
manageConnections: z.union([z.boolean(), ToolRouterUpdateManageConnectionsSchema]).nullable().optional(),
|
|
6334
8357
|
sandbox: ToolRouterSandboxConfigSchema.partial().nullable().optional(),
|
|
6335
8358
|
workbench: ToolRouterSandboxConfigSchema.partial().nullable().optional(),
|
|
6336
8359
|
multiAccount: z.object({
|
|
6337
8360
|
enable: z.boolean().optional(),
|
|
6338
|
-
maxAccountsPerToolkit: z.number().int().min(2).max(10).optional(),
|
|
8361
|
+
maxAccountsPerToolkit: z.number().int().min(2).max(10).nullable().optional().describe("`null` removes the stored maximum so the default applies again"),
|
|
6339
8362
|
requireExplicitSelection: z.boolean().optional()
|
|
6340
|
-
}).nullable().optional(),
|
|
6341
|
-
preload: z.object({ tools: z.union([z.array(z.string()), z.literal("all")]).optional() }).strict().optional()
|
|
8363
|
+
}).nullable().optional().describe("`null` removes the session override; the mode then resolves to disabled"),
|
|
8364
|
+
preload: z.object({ tools: z.union([z.array(z.string()), z.literal("all")]).optional() }).strict().nullable().optional().describe("Replaces the stored preload; `null` removes it"),
|
|
8365
|
+
search: z.object({ enable: z.boolean().optional() }).strict().nullable().optional().describe("Replaces the search block; `null` removes it and restores the defaults"),
|
|
8366
|
+
execute: z.object({ enableMultiExecute: z.boolean().optional() }).strict().nullable().optional().describe("Replaces the execute block; `null` removes it and restores the defaults"),
|
|
8367
|
+
experimental: ToolRouterUpdateExperimentalSchema.nullable().optional().describe("Experimental settings; `null` removes the stored block"),
|
|
8368
|
+
expectedConfigVersion: z.union([z.number().int().positive(), z.literal(false)]).optional().describe("Precondition sent as `expected_config_version`. Omitted: the session sends the configVersion it last observed, so a concurrent change surfaces as ComposioSessionConfigConflictError instead of being overwritten. A positive integer sends that version instead. `false` sends no precondition (last writer wins)")
|
|
6342
8369
|
}).partial().superRefine((config, ctx) => {
|
|
6343
8370
|
if (config.sandbox !== void 0 && config.workbench !== void 0) ctx.addIssue({
|
|
6344
8371
|
code: z.ZodIssueCode.custom,
|
|
@@ -6350,6 +8377,22 @@ const ToolRouterSessionDeleteResponseSchema = z.object({
|
|
|
6350
8377
|
sessionId: z.string(),
|
|
6351
8378
|
deleted: z.literal(true)
|
|
6352
8379
|
});
|
|
8380
|
+
/**
|
|
8381
|
+
* Options for `session.listConfigHistory()`.
|
|
8382
|
+
*/
|
|
8383
|
+
const ToolRouterSessionListConfigHistoryOptionsSchema = z.object({
|
|
8384
|
+
/** Cursor from a previous response's `nextCursor`. */
|
|
8385
|
+
cursor: z.string().optional(),
|
|
8386
|
+
/** Number of items per page, max allowed is 100. */
|
|
8387
|
+
limit: z.number().optional()
|
|
8388
|
+
});
|
|
8389
|
+
const ToolRouterSessionEnsureConnectedOptionsSchema = z.object({
|
|
8390
|
+
callbackUrl: z.string().optional(),
|
|
8391
|
+
alias: z.string().optional(),
|
|
8392
|
+
experimental: ConnectedAccountExperimentalSchema.optional(),
|
|
8393
|
+
/** Max time to wait for a newly-initiated connection to become active, in milliseconds. Defaults to 60000. */
|
|
8394
|
+
timeout: z.number().int().positive().optional()
|
|
8395
|
+
});
|
|
6353
8396
|
|
|
6354
8397
|
//#endregion
|
|
6355
8398
|
//#region src/lib/toolRouterParams.ts
|
|
@@ -6406,19 +8449,25 @@ const transformToolRouterSandboxParams = (params) => {
|
|
|
6406
8449
|
sandbox_size: params.sandboxSize
|
|
6407
8450
|
};
|
|
6408
8451
|
};
|
|
6409
|
-
/**
|
|
6410
|
-
* PATCH-safe variant of transformToolRouterManageConnectionsParams.
|
|
6411
|
-
* Does NOT apply defaults — only includes fields explicitly present in the input.
|
|
6412
|
-
*/
|
|
6413
8452
|
const transformToolRouterUpdateManageConnectionsParams = (params) => {
|
|
6414
8453
|
if (typeof params === "boolean") return { enable: params };
|
|
6415
|
-
const parsedResult =
|
|
8454
|
+
const parsedResult = ToolRouterUpdateManageConnectionsSchema.safeParse(params);
|
|
6416
8455
|
if (!parsedResult.success) throw new ValidationError("Failed to parse manage connections config", { cause: parsedResult.error });
|
|
6417
8456
|
const config = parsedResult.data;
|
|
6418
8457
|
const result = {};
|
|
6419
8458
|
if (config.enable !== void 0) result.enable = config.enable;
|
|
6420
8459
|
if (config.callbackUrl !== void 0) result.callback_url = config.callbackUrl;
|
|
6421
8460
|
if (config.waitForConnections !== void 0) result.enable_wait_for_connections = config.waitForConnections;
|
|
8461
|
+
if (config.enableConnectionRemoval !== void 0) result.enable_connection_removal = config.enableConnectionRemoval;
|
|
8462
|
+
return result;
|
|
8463
|
+
};
|
|
8464
|
+
const transformToolRouterUpdateExperimentalParams = (config) => {
|
|
8465
|
+
const result = {};
|
|
8466
|
+
if (config.permissions !== void 0) result.permissions = config.permissions;
|
|
8467
|
+
if (config.linkUrlOverwrite !== void 0) result.link_url_overwrite = config.linkUrlOverwrite;
|
|
8468
|
+
if (config.fastMode !== void 0) result.fast_mode = config.fastMode;
|
|
8469
|
+
if (config.submitFeedback !== void 0) result.submit_feedback = config.submitFeedback;
|
|
8470
|
+
if (config.sessionConfigId !== void 0) result.session_config_id = config.sessionConfigId;
|
|
6422
8471
|
return result;
|
|
6423
8472
|
};
|
|
6424
8473
|
/**
|
|
@@ -6448,34 +8497,118 @@ const transformToolRouterToolkitsParams = (params) => {
|
|
|
6448
8497
|
if (Array.isArray(params)) return { enable: params };
|
|
6449
8498
|
return params;
|
|
6450
8499
|
};
|
|
8500
|
+
/**
|
|
8501
|
+
* Request body of `session.update()`. Every key present in `config` is sent,
|
|
8502
|
+
* including `null` (remove the stored override) and empty collections (an
|
|
8503
|
+
* empty toolkit allowlist denies every app toolkit). The
|
|
8504
|
+
* `expectedConfigVersion` option is not a body field here: the session
|
|
8505
|
+
* resolves the precondition against its observed `configVersion`.
|
|
8506
|
+
*/
|
|
6451
8507
|
const transformToolRouterUpdateParams = (config) => {
|
|
6452
8508
|
const params = {};
|
|
6453
|
-
if (config.toolkits !== void 0) params.toolkits = transformToolRouterToolkitsParams(config.toolkits);
|
|
6454
|
-
if (config.tools !== void 0) params.tools = transformToolRouterToolsParams(config.tools);
|
|
6455
|
-
if (config.tags !== void 0) params.tags = transformToolRouterTagsParams(config.tags);
|
|
8509
|
+
if (config.toolkits !== void 0) params.toolkits = config.toolkits === null ? null : transformToolRouterToolkitsParams(config.toolkits);
|
|
8510
|
+
if (config.tools !== void 0) params.tools = config.tools === null ? null : transformToolRouterToolsParams(config.tools);
|
|
8511
|
+
if (config.tags !== void 0) params.tags = config.tags === null ? null : transformToolRouterTagsParams(config.tags);
|
|
6456
8512
|
if (config.authConfigs !== void 0) params.auth_configs = config.authConfigs;
|
|
6457
|
-
if (config.connectedAccounts !== void 0)
|
|
6458
|
-
|
|
6459
|
-
for (const [k, v] of Object.entries(config.connectedAccounts)) coerced[k] = typeof v === "string" ? [v] : v;
|
|
6460
|
-
params.connected_accounts = coerced;
|
|
6461
|
-
}
|
|
6462
|
-
if (config.manageConnections !== void 0) if (config.manageConnections === null) params.manage_connections = null;
|
|
6463
|
-
else params.manage_connections = transformToolRouterUpdateManageConnectionsParams(config.manageConnections);
|
|
8513
|
+
if (config.connectedAccounts !== void 0) params.connected_accounts = config.connectedAccounts;
|
|
8514
|
+
if (config.manageConnections !== void 0) params.manage_connections = config.manageConnections === null ? null : transformToolRouterUpdateManageConnectionsParams(config.manageConnections);
|
|
6464
8515
|
const sandboxConfig = config.sandbox !== void 0 ? config.sandbox : config.workbench;
|
|
6465
|
-
if (sandboxConfig !== void 0)
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
8516
|
+
if (sandboxConfig !== void 0) params.workbench = sandboxConfig === null ? null : transformToolRouterUpdateSandboxParams(sandboxConfig);
|
|
8517
|
+
if (config.multiAccount !== void 0) {
|
|
8518
|
+
if (config.multiAccount === null) params.multi_account = null;
|
|
8519
|
+
else {
|
|
8520
|
+
const ma = {};
|
|
8521
|
+
if (config.multiAccount.enable !== void 0) ma.enable = config.multiAccount.enable;
|
|
8522
|
+
if (config.multiAccount.maxAccountsPerToolkit !== void 0) ma.max_accounts_per_toolkit = config.multiAccount.maxAccountsPerToolkit;
|
|
8523
|
+
if (config.multiAccount.requireExplicitSelection !== void 0) ma.require_explicit_selection = config.multiAccount.requireExplicitSelection;
|
|
8524
|
+
params.multi_account = ma;
|
|
8525
|
+
}
|
|
6474
8526
|
}
|
|
6475
8527
|
if (config.preload !== void 0) params.preload = config.preload;
|
|
8528
|
+
if (config.search !== void 0) params.search = config.search;
|
|
8529
|
+
if (config.execute !== void 0) params.execute = config.execute === null ? null : config.execute.enableMultiExecute === void 0 ? {} : { enable_multi_execute: config.execute.enableMultiExecute };
|
|
8530
|
+
if (config.experimental !== void 0) params.experimental = config.experimental === null ? null : transformToolRouterUpdateExperimentalParams(config.experimental);
|
|
6476
8531
|
return params;
|
|
6477
8532
|
};
|
|
6478
8533
|
|
|
8534
|
+
//#endregion
|
|
8535
|
+
//#region src/lib/toolRouterMcp.ts
|
|
8536
|
+
/**
|
|
8537
|
+
* Returns the tuple origin (`scheme://host[:port]`) of an absolute URL.
|
|
8538
|
+
*
|
|
8539
|
+
* URLs without a tuple origin (`data:`, `file:`, `blob:` without a base, and
|
|
8540
|
+
* similar) serialize their origin as the opaque string `null`. Two such URLs
|
|
8541
|
+
* would compare equal, so they are rejected before any comparison happens.
|
|
8542
|
+
*/
|
|
8543
|
+
const parseOrigin = (url, role) => {
|
|
8544
|
+
let parsed;
|
|
8545
|
+
try {
|
|
8546
|
+
parsed = new URL(url);
|
|
8547
|
+
} catch (_error) {
|
|
8548
|
+
return { error: new ComposioMCPDestinationError(`The ${role} is not a valid absolute URL`, { meta: { role } }) };
|
|
8549
|
+
}
|
|
8550
|
+
if (parsed.origin === "null") return { error: new ComposioMCPDestinationError(`The ${role} has an opaque origin`, { meta: { role } }) };
|
|
8551
|
+
return { origin: parsed.origin };
|
|
8552
|
+
};
|
|
8553
|
+
/**
|
|
8554
|
+
* Returns the error describing why the MCP URL must not receive the session
|
|
8555
|
+
* credential, or `undefined` when it shares the API origin.
|
|
8556
|
+
*/
|
|
8557
|
+
const destinationRejection = (apiBaseURL, mcpUrl) => {
|
|
8558
|
+
const api = parseOrigin(apiBaseURL, "API base URL");
|
|
8559
|
+
if ("error" in api) return api.error;
|
|
8560
|
+
const mcp = parseOrigin(mcpUrl, "MCP URL");
|
|
8561
|
+
if ("error" in mcp) return mcp.error;
|
|
8562
|
+
if (mcp.origin === api.origin) return;
|
|
8563
|
+
return new ComposioMCPDestinationError(`The session MCP endpoint origin ${mcp.origin} does not match the API origin ${api.origin}; the session credential was not attached`, { meta: {
|
|
8564
|
+
mcpOrigin: mcp.origin,
|
|
8565
|
+
apiOrigin: api.origin
|
|
8566
|
+
} });
|
|
8567
|
+
};
|
|
8568
|
+
/**
|
|
8569
|
+
* Builds the MCP server config exported on a session.
|
|
8570
|
+
*
|
|
8571
|
+
* The headers mirror the effective auth context of the session request: the
|
|
8572
|
+
* project key as `x-api-key` when one is configured, otherwise the resolved
|
|
8573
|
+
* user API key (the `userApiKey` option, then the `x-user-api-key` default
|
|
8574
|
+
* header) as `x-user-api-key`, plus `x-org-id` / `x-project-id` when the
|
|
8575
|
+
* instance carries an explicit scope. No other default header is copied and
|
|
8576
|
+
* the environment is never re-read.
|
|
8577
|
+
*
|
|
8578
|
+
* The headers are only attached when the MCP URL has the same origin as the
|
|
8579
|
+
* API base URL the session was created against, whatever scheme the caller
|
|
8580
|
+
* configured: that origin already receives them on every SDK request. Any
|
|
8581
|
+
* other destination (a different origin, an opaque origin, or a URL that does
|
|
8582
|
+
* not parse) never receives the credential. When the caller asked for MCP
|
|
8583
|
+
* (`mcpRequested`), that raises {@link ComposioMCPDestinationError} naming
|
|
8584
|
+
* both origins; otherwise the session is returned with empty `headers` and a
|
|
8585
|
+
* warning naming both origins is logged, so callers who only use the native
|
|
8586
|
+
* tools are not blocked by an endpoint they never consume. The SDK itself
|
|
8587
|
+
* never connects to the MCP URL and does not follow redirects for it; an MCP
|
|
8588
|
+
* client consuming this config must not forward these headers to a different
|
|
8589
|
+
* origin.
|
|
8590
|
+
*/
|
|
8591
|
+
const buildMCPServerConfig = (input) => {
|
|
8592
|
+
const rejection = destinationRejection(input.apiBaseURL, input.url);
|
|
8593
|
+
if (rejection) {
|
|
8594
|
+
if (input.mcpRequested) throw rejection;
|
|
8595
|
+
logger.warn(`${rejection.message}. session.mcp.headers was left empty; pass \`mcp: true\` to make this an error`);
|
|
8596
|
+
return {
|
|
8597
|
+
type: input.type,
|
|
8598
|
+
url: input.url,
|
|
8599
|
+
headers: {}
|
|
8600
|
+
};
|
|
8601
|
+
}
|
|
8602
|
+
const headers = resolveCredentialHeaders(input);
|
|
8603
|
+
if (input.orgId) headers[ORG_ID_HEADER] = input.orgId;
|
|
8604
|
+
if (input.projectId) headers[PROJECT_ID_HEADER] = input.projectId;
|
|
8605
|
+
return {
|
|
8606
|
+
type: input.type,
|
|
8607
|
+
url: input.url,
|
|
8608
|
+
headers
|
|
8609
|
+
};
|
|
8610
|
+
};
|
|
8611
|
+
|
|
6479
8612
|
//#endregion
|
|
6480
8613
|
//#region src/utils/transformers/toolRouterResponseTransform.ts
|
|
6481
8614
|
function transformSearchResult(raw) {
|
|
@@ -7287,27 +9420,45 @@ const AuthorizeOptionsSchema = z$1.object({
|
|
|
7287
9420
|
*/
|
|
7288
9421
|
var ToolRouterSession = class {
|
|
7289
9422
|
client;
|
|
7290
|
-
|
|
9423
|
+
sdkConfig;
|
|
7291
9424
|
customToolsMap;
|
|
7292
9425
|
userId;
|
|
7293
9426
|
sessionId;
|
|
7294
9427
|
/** Hosted MCP endpoint (`session.mcp.url` / `session.mcp.headers`). Exists on every session at runtime, but only surfaced in the type when the session is created with `{ mcp: true }` (which returns `Session`); the default `SessionWithoutMcp` omits `mcp`, so MCP is an explicit opt-in. See https://docs.composio.dev/docs/sessions-via-mcp */
|
|
7295
9428
|
mcp;
|
|
7296
9429
|
experimental;
|
|
9430
|
+
/**
|
|
9431
|
+
* Server-side session configuration (toolkit/tool allowlists, tags, preload,
|
|
9432
|
+
* sandbox, manage_connections) as returned by the API. Refreshed in place by
|
|
9433
|
+
* `update()`.
|
|
9434
|
+
*/
|
|
9435
|
+
config;
|
|
7297
9436
|
preload;
|
|
7298
9437
|
/** Resolved sandbox (code-execution) config returned by the API. `enable` defaults to `true` server-side. */
|
|
7299
9438
|
sandbox;
|
|
9439
|
+
/**
|
|
9440
|
+
* Version of the server-side configuration this object last observed.
|
|
9441
|
+
* Refreshed in place by `update()`, which sends it as the
|
|
9442
|
+
* `expected_config_version` precondition by default.
|
|
9443
|
+
*/
|
|
7300
9444
|
configVersion;
|
|
7301
9445
|
warnings;
|
|
7302
9446
|
preloadedCustomToolSlugs;
|
|
7303
9447
|
inlineCustomToolsPayload;
|
|
7304
9448
|
/** Singleton session context — shared across all custom tool executions */
|
|
7305
9449
|
sessionContext;
|
|
7306
|
-
constructor(client,
|
|
9450
|
+
constructor(client, sdkConfig, sessionId, mcp, experimentalOverrides, customToolsMap, userId, metadata) {
|
|
7307
9451
|
this.client = client;
|
|
7308
|
-
this.
|
|
9452
|
+
this.sdkConfig = sdkConfig;
|
|
7309
9453
|
this.customToolsMap = customToolsMap;
|
|
7310
9454
|
this.userId = userId;
|
|
9455
|
+
const config = metadata?.config ?? {
|
|
9456
|
+
user_id: userId ?? "",
|
|
9457
|
+
execute: {},
|
|
9458
|
+
search: {},
|
|
9459
|
+
preload: { tools: [] },
|
|
9460
|
+
premium_usage: false
|
|
9461
|
+
};
|
|
7311
9462
|
if (customToolsMap && !userId) throw new Error("userId is required when custom tools are bound to a session.");
|
|
7312
9463
|
this.sessionId = sessionId;
|
|
7313
9464
|
this.mcp = mcp;
|
|
@@ -7315,8 +9466,9 @@ var ToolRouterSession = class {
|
|
|
7315
9466
|
assistivePrompt: experimentalOverrides?.assistivePrompt,
|
|
7316
9467
|
files: new ToolRouterSessionFilesMount(client, sessionId)
|
|
7317
9468
|
};
|
|
7318
|
-
this.
|
|
7319
|
-
this.
|
|
9469
|
+
this.config = config;
|
|
9470
|
+
this.preload = metadata?.preload ?? config.preload;
|
|
9471
|
+
this.sandbox = metadata?.workbench ?? config.workbench;
|
|
7320
9472
|
this.configVersion = metadata?.configVersion;
|
|
7321
9473
|
this.warnings = metadata?.warnings ?? [];
|
|
7322
9474
|
this.preloadedCustomToolSlugs = metadata?.preloadedCustomToolSlugs ?? [];
|
|
@@ -7343,7 +9495,7 @@ var ToolRouterSession = class {
|
|
|
7343
9495
|
* is intercepted: local tools are executed in-process, remote tools are sent to the backend.
|
|
7344
9496
|
*/
|
|
7345
9497
|
async tools(modifiers, requestOptions) {
|
|
7346
|
-
const ToolsModel = new Tools(this.client, this.
|
|
9498
|
+
const ToolsModel = new Tools(this.client, this.sdkConfig);
|
|
7347
9499
|
const rawTools = await ToolsModel.getRawToolRouterSessionTools(this.sessionId, void 0, requestOptions);
|
|
7348
9500
|
const tools = await this.applySchemaModifier(rawTools, modifiers?.modifySchema);
|
|
7349
9501
|
const sessionTools = await this.addPreloadedCustomTools(tools, modifiers);
|
|
@@ -7356,8 +9508,8 @@ var ToolRouterSession = class {
|
|
|
7356
9508
|
assertUnambiguousCustomToolSlug(this.customToolsMap, toolSlug);
|
|
7357
9509
|
return this.executeBackendSessionTool(ToolsModel, toolSlug, input, modifiers, rawToolBySlug.get(toolSlug.toUpperCase()));
|
|
7358
9510
|
};
|
|
7359
|
-
if (!this.
|
|
7360
|
-
return this.
|
|
9511
|
+
if (!this.sdkConfig?.provider) throw new Error("A provider is required when using custom tools with session.tools(). Pass a provider in the Composio constructor.");
|
|
9512
|
+
return this.sdkConfig.provider.wrapTools(sessionTools, routingExecuteFn);
|
|
7361
9513
|
}
|
|
7362
9514
|
return modifiers?.modifySchema ? ToolsModel.wrapToolsForToolRouter(this.sessionId, sessionTools, modifiers, rawTools) : ToolsModel.wrapToolsForToolRouter(this.sessionId, sessionTools, modifiers);
|
|
7363
9515
|
}
|
|
@@ -7496,6 +9648,69 @@ var ToolRouterSession = class {
|
|
|
7496
9648
|
return createConnectionRequest(this.client, response.connected_account_id, ConnectedAccountStatuses.INITIATED, response.redirect_url);
|
|
7497
9649
|
}
|
|
7498
9650
|
/**
|
|
9651
|
+
* Ensure a toolkit has an active connection in this session, reconciling
|
|
9652
|
+
* `authorize()`/`session.link` with the session's active connection state.
|
|
9653
|
+
*
|
|
9654
|
+
* If the session already resolves an ACTIVE connection (or the toolkit is
|
|
9655
|
+
* no-auth), this returns immediately without creating a link — unlike
|
|
9656
|
+
* `authorize()`, which always starts a new link flow, even when one is
|
|
9657
|
+
* already connected. Otherwise it starts the authorization flow and waits
|
|
9658
|
+
* for the new connection to become ACTIVE.
|
|
9659
|
+
*
|
|
9660
|
+
* For interactive flows that should surface the redirect URL instead of
|
|
9661
|
+
* blocking, use `authorize()` and its `waitForConnection()` directly.
|
|
9662
|
+
*
|
|
9663
|
+
* @param toolkit - The toolkit slug to ensure a connection for (e.g. 'github')
|
|
9664
|
+
* @param options - Optional authorization options plus `timeout` (ms to wait
|
|
9665
|
+
* for a newly-initiated connection, default 60000)
|
|
9666
|
+
* @returns The toolkit's canonical slug, whether it was already connected,
|
|
9667
|
+
* and the active connected account (omitted for no-auth toolkits)
|
|
9668
|
+
* @throws {ValidationError} If the options fail validation
|
|
9669
|
+
* @throws {ConnectionRequestTimeoutError} If a newly-initiated connection does
|
|
9670
|
+
* not become active within `timeout`
|
|
9671
|
+
* @throws {ConnectionRequestFailedError} If the new connection enters a failed,
|
|
9672
|
+
* expired, or revoked state
|
|
9673
|
+
*
|
|
9674
|
+
* @example
|
|
9675
|
+
* ```typescript
|
|
9676
|
+
* const session = await composio.sessions.create({ toolkits: ['github'] });
|
|
9677
|
+
* const { wasConnected, connectedAccount } = await session.ensureConnected('github');
|
|
9678
|
+
* if (!wasConnected) console.log('Newly linked:', connectedAccount?.id);
|
|
9679
|
+
* ```
|
|
9680
|
+
*/
|
|
9681
|
+
async ensureConnected(toolkit, options, requestOptions) {
|
|
9682
|
+
const parsedOptions = ToolRouterSessionEnsureConnectedOptionsSchema.safeParse(options ?? {});
|
|
9683
|
+
if (!parsedOptions.success) throw new ValidationError("Failed to parse tool router ensureConnected options", { cause: parsedOptions.error });
|
|
9684
|
+
const { callbackUrl, alias, experimental, timeout } = parsedOptions.data;
|
|
9685
|
+
const existing = (await this.toolkits({ toolkits: [toolkit] }, requestOptions)).items.find((item) => item.slug.toLowerCase() === toolkit.toLowerCase());
|
|
9686
|
+
if (existing?.isNoAuth) return {
|
|
9687
|
+
toolkit: existing.slug,
|
|
9688
|
+
wasConnected: true
|
|
9689
|
+
};
|
|
9690
|
+
const activeAccount = existing?.connection?.connectedAccount;
|
|
9691
|
+
if (existing?.connection?.isActive && activeAccount) return {
|
|
9692
|
+
toolkit: existing.slug,
|
|
9693
|
+
wasConnected: true,
|
|
9694
|
+
connectedAccount: {
|
|
9695
|
+
id: activeAccount.id,
|
|
9696
|
+
status: activeAccount.status
|
|
9697
|
+
}
|
|
9698
|
+
};
|
|
9699
|
+
const account = await (await this.authorize(toolkit, {
|
|
9700
|
+
...callbackUrl !== void 0 && { callbackUrl },
|
|
9701
|
+
...alias !== void 0 && { alias },
|
|
9702
|
+
...experimental !== void 0 && { experimental }
|
|
9703
|
+
}, requestOptions)).waitForConnection(timeout);
|
|
9704
|
+
return {
|
|
9705
|
+
toolkit: existing?.slug ?? toolkit,
|
|
9706
|
+
wasConnected: false,
|
|
9707
|
+
connectedAccount: {
|
|
9708
|
+
id: account.id,
|
|
9709
|
+
status: account.status
|
|
9710
|
+
}
|
|
9711
|
+
};
|
|
9712
|
+
}
|
|
9713
|
+
/**
|
|
7499
9714
|
* Query the connection state of toolkits in the session.
|
|
7500
9715
|
* Supports pagination and filtering by toolkit slugs.
|
|
7501
9716
|
*/
|
|
@@ -7546,7 +9761,8 @@ var ToolRouterSession = class {
|
|
|
7546
9761
|
...params.toolkits?.length ? { toolkits: params.toolkits } : {},
|
|
7547
9762
|
...experimental ? { experimental } : {}
|
|
7548
9763
|
};
|
|
7549
|
-
const
|
|
9764
|
+
const response = await withCancellation(() => this.client.toolRouter.session.search(this.sessionId, searchParams, requestOptions), requestOptions?.signal);
|
|
9765
|
+
const transformed = transformSearchResponse(response);
|
|
7550
9766
|
return ToolRouterSessionSearchResponseSchema.parse(transformed);
|
|
7551
9767
|
}
|
|
7552
9768
|
/**
|
|
@@ -7560,7 +9776,7 @@ var ToolRouterSession = class {
|
|
|
7560
9776
|
* @param toolSlug - The tool slug to execute
|
|
7561
9777
|
* @param arguments_ - Optional tool arguments
|
|
7562
9778
|
* @param options - Optional execution options
|
|
7563
|
-
* @param options.account - Account identifier for direct app tool execution in multi-account sessions. Helper/meta tools either ignore this top-level field or define their own account-selection fields.
|
|
9779
|
+
* @param options.account - Account identifier for direct app tool execution. Accepted on every project: in multi-account sessions it picks the account; on single-account projects it must match one of the session's active connections for the toolkit. Helper/meta tools either ignore this top-level field or define their own account-selection fields.
|
|
7564
9780
|
* @returns The tool execution result
|
|
7565
9781
|
*/
|
|
7566
9782
|
async execute(toolSlug, arguments_, options, requestOptions) {
|
|
@@ -7582,7 +9798,8 @@ var ToolRouterSession = class {
|
|
|
7582
9798
|
if (options?.account) executeParams.account = options.account;
|
|
7583
9799
|
const experimental = inlineCustomToolsExperimental(this.inlineCustomToolsPayload);
|
|
7584
9800
|
if (experimental) executeParams.experimental = experimental;
|
|
7585
|
-
const
|
|
9801
|
+
const response = await withCancellation(() => this.client.toolRouter.session.execute(this.sessionId, executeParams, requestOptions), requestOptions?.signal);
|
|
9802
|
+
const transformed = transformExecuteResponse(response);
|
|
7586
9803
|
return ToolRouterSessionExecuteResponseSchema.parse(transformed);
|
|
7587
9804
|
}
|
|
7588
9805
|
/**
|
|
@@ -7611,16 +9828,56 @@ var ToolRouterSession = class {
|
|
|
7611
9828
|
}
|
|
7612
9829
|
/**
|
|
7613
9830
|
* Partially update the session configuration.
|
|
7614
|
-
*
|
|
7615
|
-
*
|
|
9831
|
+
*
|
|
9832
|
+
* Only the fields provided are changed; omitted fields are preserved. For
|
|
9833
|
+
* each policy block `null` removes the stored override (which can increase
|
|
9834
|
+
* access: `toolkits: null` restores the unrestricted default, while
|
|
9835
|
+
* `toolkits: []` denies every app toolkit and is sent as-is). Supplied
|
|
9836
|
+
* `tools`, `authConfigs` and `connectedAccounts` maps replace the stored
|
|
9837
|
+
* map entirely. `manageConnections.callbackUrl: null` removes only the
|
|
9838
|
+
* stored callback URL.
|
|
9839
|
+
*
|
|
9840
|
+
* The request carries the `configVersion` this object last observed as the
|
|
9841
|
+
* `expected_config_version` precondition, so a concurrent change surfaces as
|
|
9842
|
+
* {@link ComposioSessionConfigConflictError} (HTTP 409) instead of being
|
|
9843
|
+
* overwritten. Pass `expectedConfigVersion` to send another version, or
|
|
9844
|
+
* `expectedConfigVersion: false` to send no precondition (last writer
|
|
9845
|
+
* wins). The PATCH is never retried by the transport, so a 409 is reported
|
|
9846
|
+
* exactly once. On conflict this object is left unchanged: re-fetch the
|
|
9847
|
+
* session with `sessions.use(sessionId)` and retry against the fresh
|
|
9848
|
+
* `configVersion`.
|
|
9849
|
+
*
|
|
9850
|
+
* `config`, `configVersion`, `preload`, `sandbox` and `warnings` are
|
|
9851
|
+
* refreshed in place only after a successful response, and the updated
|
|
9852
|
+
* `config` is returned.
|
|
7616
9853
|
*/
|
|
7617
9854
|
async update(config, requestOptions) {
|
|
7618
|
-
const
|
|
7619
|
-
const
|
|
9855
|
+
const parsed = ToolRouterUpdateSessionConfigSchema.parse(config);
|
|
9856
|
+
const body = transformToolRouterUpdateParams(parsed);
|
|
9857
|
+
const expectedConfigVersion = parsed.expectedConfigVersion === false ? void 0 : parsed.expectedConfigVersion ?? this.configVersion;
|
|
9858
|
+
if (expectedConfigVersion !== void 0) body.expected_config_version = expectedConfigVersion;
|
|
9859
|
+
let response;
|
|
9860
|
+
try {
|
|
9861
|
+
response = await withCancellation(() => this.client.toolRouter.session.patch(this.sessionId, body, {
|
|
9862
|
+
...requestOptions,
|
|
9863
|
+
maxRetries: 0
|
|
9864
|
+
}), requestOptions?.signal);
|
|
9865
|
+
} catch (error) {
|
|
9866
|
+
if (error instanceof ConflictError) throw new ComposioSessionConfigConflictError(expectedConfigVersion === void 0 ? `Session ${this.sessionId} configuration changed while this update was in flight; re-fetch the session and retry the update` : `Session ${this.sessionId} configuration is no longer at version ${expectedConfigVersion}; re-fetch the session and retry the update`, {
|
|
9867
|
+
cause: error,
|
|
9868
|
+
meta: {
|
|
9869
|
+
sessionId: this.sessionId,
|
|
9870
|
+
expectedConfigVersion
|
|
9871
|
+
}
|
|
9872
|
+
});
|
|
9873
|
+
throw error;
|
|
9874
|
+
}
|
|
7620
9875
|
this.configVersion = response.config_version;
|
|
9876
|
+
this.config = response.config;
|
|
7621
9877
|
this.preload = response.config.preload;
|
|
7622
9878
|
this.sandbox = response.config.workbench;
|
|
7623
9879
|
this.warnings = response.warnings ?? [];
|
|
9880
|
+
return this.config;
|
|
7624
9881
|
}
|
|
7625
9882
|
/**
|
|
7626
9883
|
* Delete this session.
|
|
@@ -7631,6 +9888,43 @@ var ToolRouterSession = class {
|
|
|
7631
9888
|
async delete(requestOptions) {
|
|
7632
9889
|
return deleteToolRouterSession(this.client, this.sessionId, requestOptions);
|
|
7633
9890
|
}
|
|
9891
|
+
/**
|
|
9892
|
+
* Page through this session's configuration history, newest first. The
|
|
9893
|
+
* first page starts with the live config (`isCurrent: true`); every
|
|
9894
|
+
* `session.update()` archives the previous version as a history row.
|
|
9895
|
+
*
|
|
9896
|
+
* @param options - Optional `cursor` and `limit` (max 100)
|
|
9897
|
+
* @returns The config versions on this page plus pagination info
|
|
9898
|
+
* @throws {ValidationError} If the options fail validation
|
|
9899
|
+
*
|
|
9900
|
+
* @example
|
|
9901
|
+
* ```typescript
|
|
9902
|
+
* const { items, nextCursor } = await session.listConfigHistory({ limit: 10 });
|
|
9903
|
+
* console.log(items[0].version, items[0].isCurrent); // e.g. 3, true
|
|
9904
|
+
* console.log(items[1].config.toolkits);
|
|
9905
|
+
* ```
|
|
9906
|
+
*/
|
|
9907
|
+
async listConfigHistory(options, requestOptions) {
|
|
9908
|
+
const parsedOptions = ToolRouterSessionListConfigHistoryOptionsSchema.safeParse(options ?? {});
|
|
9909
|
+
if (!parsedOptions.success) throw new ValidationError("Failed to parse config history options", { cause: parsedOptions.error });
|
|
9910
|
+
const query = {
|
|
9911
|
+
cursor: parsedOptions.data.cursor,
|
|
9912
|
+
limit: parsedOptions.data.limit
|
|
9913
|
+
};
|
|
9914
|
+
const response = await withCancellation(() => this.client.toolRouter.session.configHistory(this.sessionId, query, requestOptions), requestOptions?.signal);
|
|
9915
|
+
return {
|
|
9916
|
+
items: response.items.map((item) => ({
|
|
9917
|
+
version: item.version,
|
|
9918
|
+
createdAt: item.created_at,
|
|
9919
|
+
isCurrent: item.is_current,
|
|
9920
|
+
config: item.config
|
|
9921
|
+
})),
|
|
9922
|
+
nextCursor: response.next_cursor ?? null,
|
|
9923
|
+
totalPages: response.total_pages,
|
|
9924
|
+
currentPage: response.current_page,
|
|
9925
|
+
totalItems: response.total_items
|
|
9926
|
+
};
|
|
9927
|
+
}
|
|
7634
9928
|
/** Check if this session has any custom tools bound. */
|
|
7635
9929
|
hasCustomTools() {
|
|
7636
9930
|
return (this.customToolsMap?.byFinalSlug.size ?? 0) > 0;
|
|
@@ -7757,6 +10051,7 @@ var ToolRouterSession = class {
|
|
|
7757
10051
|
//#region src/models/ToolRouter.ts
|
|
7758
10052
|
function getSessionMetadata(session) {
|
|
7759
10053
|
return {
|
|
10054
|
+
config: session.config,
|
|
7760
10055
|
preload: session.config.preload,
|
|
7761
10056
|
workbench: session.config.workbench,
|
|
7762
10057
|
configVersion: session.config_version,
|
|
@@ -7768,7 +10063,8 @@ function preloadsAllCustomTools(preload) {
|
|
|
7768
10063
|
}
|
|
7769
10064
|
function prepareInlineCustomTools(options) {
|
|
7770
10065
|
const { customTools, customToolkits, defaultPreload = false, preloadTools } = options;
|
|
7771
|
-
|
|
10066
|
+
const localCustomToolsMap = !!(customTools?.length || customToolkits?.length) ? buildCustomToolsMap(customTools ?? [], customToolkits) : void 0;
|
|
10067
|
+
assertNoCustomToolSlugsInPreload(preloadTools, localCustomToolsMap);
|
|
7772
10068
|
const serializedTools = customTools?.length ? serializeCustomTools(customTools, { defaultPreload }) : void 0;
|
|
7773
10069
|
const serializedToolkits = customToolkits?.length ? serializeCustomToolkits(customToolkits, { defaultPreload }) : void 0;
|
|
7774
10070
|
return serializedTools || serializedToolkits ? {
|
|
@@ -7784,12 +10080,27 @@ var ToolRouter = class {
|
|
|
7784
10080
|
this.config = config;
|
|
7785
10081
|
telemetry.instrument(this, "ToolRouter");
|
|
7786
10082
|
}
|
|
7787
|
-
|
|
7788
|
-
|
|
10083
|
+
/**
|
|
10084
|
+
* Derives the MCP config for a session from the auth context the session
|
|
10085
|
+
* request was made with: the project key when one is configured, otherwise
|
|
10086
|
+
* the resolved user API key, plus the org/project scope when configured.
|
|
10087
|
+
* Headers are only attached when the MCP URL shares the client's API
|
|
10088
|
+
* origin. Any other destination throws when the caller passed `mcp: true`
|
|
10089
|
+
* and otherwise yields empty headers plus a warning; see
|
|
10090
|
+
* `buildMCPServerConfig`.
|
|
10091
|
+
*/
|
|
10092
|
+
createMCPServerConfig({ type, url }, mcpRequested) {
|
|
10093
|
+
return buildMCPServerConfig({
|
|
7789
10094
|
type,
|
|
7790
10095
|
url,
|
|
7791
|
-
|
|
7792
|
-
|
|
10096
|
+
apiBaseURL: this.client.baseURL,
|
|
10097
|
+
apiKey: this.config?.apiKey,
|
|
10098
|
+
userApiKey: this.config?.userApiKey,
|
|
10099
|
+
defaultHeaders: this.config?.defaultHeaders,
|
|
10100
|
+
orgId: this.config?.orgId,
|
|
10101
|
+
projectId: this.config?.projectId,
|
|
10102
|
+
mcpRequested
|
|
10103
|
+
});
|
|
7793
10104
|
}
|
|
7794
10105
|
async create(userId, config, requestOptions) {
|
|
7795
10106
|
const routerConfig = ToolRouterCreateSessionConfigSchema.parse(config ?? {});
|
|
@@ -7836,7 +10147,7 @@ var ToolRouter = class {
|
|
|
7836
10147
|
inlineCustomToolsPayload
|
|
7837
10148
|
};
|
|
7838
10149
|
const assistivePrompt = session.experimental?.assistive_prompt;
|
|
7839
|
-
return new ToolRouterSession(this.client, this.config, session.session_id, this.createMCPServerConfig(session.mcp), { assistivePrompt }, customToolsMap, userId, metadata);
|
|
10150
|
+
return new ToolRouterSession(this.client, this.config, session.session_id, this.createMCPServerConfig(session.mcp, routerConfig.mcp === true), { assistivePrompt }, customToolsMap, userId, metadata);
|
|
7840
10151
|
}
|
|
7841
10152
|
async use(id, options, requestOptions) {
|
|
7842
10153
|
const customTools = options?.customTools;
|
|
@@ -7869,7 +10180,7 @@ var ToolRouter = class {
|
|
|
7869
10180
|
preloadedCustomToolSlugs: getPreloadedCustomToolSlugs(customToolsMap, defaultCustomPreload),
|
|
7870
10181
|
inlineCustomToolsPayload
|
|
7871
10182
|
};
|
|
7872
|
-
return new ToolRouterSession(this.client, this.config, session.session_id, this.createMCPServerConfig(session.mcp), void 0, customToolsMap, userId, metadata);
|
|
10183
|
+
return new ToolRouterSession(this.client, this.config, session.session_id, this.createMCPServerConfig(session.mcp, options?.mcp === true), void 0, customToolsMap, userId, metadata);
|
|
7873
10184
|
}
|
|
7874
10185
|
/**
|
|
7875
10186
|
* Delete a tool router session by ID.
|
|
@@ -7900,6 +10211,29 @@ var Sessions = class extends ToolRouter {
|
|
|
7900
10211
|
//#endregion
|
|
7901
10212
|
//#region src/composio.ts
|
|
7902
10213
|
/**
|
|
10214
|
+
* Level for the API client given the SDK level. The client logs each request's
|
|
10215
|
+
* lifecycle at `info`, which is debug-grade for SDK users, so the client stays
|
|
10216
|
+
* at `warn` unless the SDK is at `debug`. The client's `LogLevel` has
|
|
10217
|
+
* `'off'` where the SDK has `'silent'`.
|
|
10218
|
+
*/
|
|
10219
|
+
const toClientLogLevel = (level) => {
|
|
10220
|
+
if (level === "silent") return "off";
|
|
10221
|
+
if (level === "info") return "warn";
|
|
10222
|
+
return level;
|
|
10223
|
+
};
|
|
10224
|
+
/**
|
|
10225
|
+
* Forwards the API client's log records to the SDK singleton so they pick up
|
|
10226
|
+
* the SDK's formatting, redaction, and configured sink. Methods are looked up
|
|
10227
|
+
* at call time so a later `logger.configure()` is honoured. The client's
|
|
10228
|
+
* `info` records (per-request lifecycle) are forwarded as SDK `debug`.
|
|
10229
|
+
*/
|
|
10230
|
+
const clientLoggerAdapter = {
|
|
10231
|
+
error: (...args) => logger.error(...args),
|
|
10232
|
+
warn: (...args) => logger.warn(...args),
|
|
10233
|
+
info: (...args) => logger.debug(...args),
|
|
10234
|
+
debug: (...args) => logger.debug(...args)
|
|
10235
|
+
};
|
|
10236
|
+
/**
|
|
7903
10237
|
* This is the core class for Composio.
|
|
7904
10238
|
* It is used to initialize the Composio SDK and provide a global configuration.
|
|
7905
10239
|
*/
|
|
@@ -7932,6 +10266,15 @@ var Composio = class Composio {
|
|
|
7932
10266
|
/** Manage authenticated connections */
|
|
7933
10267
|
connectedAccounts;
|
|
7934
10268
|
/**
|
|
10269
|
+
* Manage the project's webhook subscription (`webhooks.subscriptions`) and
|
|
10270
|
+
* inbound per-toolkit webhook endpoints (`webhooks.endpoints`).
|
|
10271
|
+
*/
|
|
10272
|
+
webhooks;
|
|
10273
|
+
/** Search and inspect tool-execution logs */
|
|
10274
|
+
logs;
|
|
10275
|
+
/** Public transfer keys of the organization's customer-managed keyring */
|
|
10276
|
+
keyring;
|
|
10277
|
+
/**
|
|
7935
10278
|
* Experimental SDK methods whose shape may change in future releases.
|
|
7936
10279
|
* Prefer domain-specific mounts (for example
|
|
7937
10280
|
* `composio.connectedAccounts.updateAcl(...)`) when available; this
|
|
@@ -8036,7 +10379,25 @@ var Composio = class Composio {
|
|
|
8036
10379
|
* ```
|
|
8037
10380
|
*/
|
|
8038
10381
|
constructor(config) {
|
|
8039
|
-
const
|
|
10382
|
+
const scope = resolveSDKScope({
|
|
10383
|
+
orgId: config?.orgId,
|
|
10384
|
+
projectId: config?.projectId,
|
|
10385
|
+
defaultHeaders: config?.defaultHeaders
|
|
10386
|
+
});
|
|
10387
|
+
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(config?.baseURL, config?.apiKey, {
|
|
10388
|
+
defaultHeaders: config?.defaultHeaders,
|
|
10389
|
+
userApiKey: config?.userApiKey,
|
|
10390
|
+
orgApiKey: config?.orgApiKey
|
|
10391
|
+
});
|
|
10392
|
+
const userApiKey = apiKeyParsed === null ? resolveUserApiKey(config?.userApiKey) : void 0;
|
|
10393
|
+
const defaultHeadersInput = userApiKey !== void 0 && !getUserApiKeyHeader(config?.defaultHeaders) ? {
|
|
10394
|
+
...config?.defaultHeaders,
|
|
10395
|
+
[USER_API_KEY_HEADER]: userApiKey
|
|
10396
|
+
} : config?.defaultHeaders;
|
|
10397
|
+
if (config?.logger !== void 0 || config?.logLevel !== void 0) logger.configure({
|
|
10398
|
+
level: config.logLevel,
|
|
10399
|
+
sink: config.logger
|
|
10400
|
+
});
|
|
8040
10401
|
if (IS_DEVELOPMENT_OR_CI) logger.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
8041
10402
|
/**
|
|
8042
10403
|
* Set the default provider, if not provided by the user.
|
|
@@ -8050,6 +10411,7 @@ var Composio = class Composio {
|
|
|
8050
10411
|
...config,
|
|
8051
10412
|
baseURL: baseURLParsed,
|
|
8052
10413
|
apiKey: apiKeyParsed,
|
|
10414
|
+
defaultHeaders: defaultHeadersInput,
|
|
8053
10415
|
toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
|
|
8054
10416
|
allowTracking: config?.allowTracking ?? CONFIG_DEFAULTS.allowTracking,
|
|
8055
10417
|
dangerouslyAllowAutoUploadDownloadFiles: config?.dangerouslyAllowAutoUploadDownloadFiles ?? CONFIG_DEFAULTS.dangerouslyAllowAutoUploadDownloadFiles,
|
|
@@ -8057,19 +10419,29 @@ var Composio = class Composio {
|
|
|
8057
10419
|
fileUploadPathDenySegments: config?.fileUploadPathDenySegments,
|
|
8058
10420
|
fileUploadDirs: expandHomeAndResolveMany(config?.fileUploadDirs),
|
|
8059
10421
|
fileDownloadDir: expandHomeAndResolve(config?.fileDownloadDir),
|
|
8060
|
-
provider: config?.provider ?? this.provider
|
|
10422
|
+
provider: config?.provider ?? this.provider,
|
|
10423
|
+
orgId: scope.orgId,
|
|
10424
|
+
projectId: scope.projectId
|
|
8061
10425
|
};
|
|
8062
|
-
const defaultHeaders = getDefaultHeaders(
|
|
10426
|
+
const defaultHeaders = getDefaultHeaders({
|
|
10427
|
+
...this.config.defaultHeaders,
|
|
10428
|
+
...getScopeHeaders(scope)
|
|
10429
|
+
}, this.provider);
|
|
8063
10430
|
/**
|
|
8064
10431
|
* Initialize the Composio SDK client.
|
|
8065
10432
|
* The client is used to make API calls to the Composio API.
|
|
8066
10433
|
*/
|
|
8067
10434
|
this.client = new ComposioClient({
|
|
8068
10435
|
apiKey: apiKeyParsed,
|
|
10436
|
+
userApiKey: config?.userApiKey,
|
|
10437
|
+
orgApiKey: config?.orgApiKey,
|
|
8069
10438
|
baseURL: baseURLParsed,
|
|
8070
10439
|
defaultHeaders,
|
|
8071
|
-
|
|
10440
|
+
logger: clientLoggerAdapter,
|
|
10441
|
+
logLevel: toClientLogLevel(logger.getLevel())
|
|
8072
10442
|
});
|
|
10443
|
+
this.config.userApiKey = this.client.userApiKey;
|
|
10444
|
+
this.config.orgApiKey = this.client.orgApiKey;
|
|
8073
10445
|
this.tools = new Tools(this.client, this.config);
|
|
8074
10446
|
this.mcp = new MCP(this.client);
|
|
8075
10447
|
this.toolkits = new Toolkits(this.client);
|
|
@@ -8081,6 +10453,9 @@ var Composio = class Composio {
|
|
|
8081
10453
|
fileDownloadDir: this.config.fileDownloadDir
|
|
8082
10454
|
});
|
|
8083
10455
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
10456
|
+
this.webhooks = new Webhooks(this.client);
|
|
10457
|
+
this.logs = new Logs(this.client);
|
|
10458
|
+
this.keyring = new Keyring(this.client);
|
|
8084
10459
|
this.experimental = new Experimental(this.client);
|
|
8085
10460
|
this.sessions = new Sessions(this.client, this.config);
|
|
8086
10461
|
this.toolRouter = this.sessions;
|
|
@@ -8169,7 +10544,11 @@ var Composio = class Composio {
|
|
|
8169
10544
|
* ```
|
|
8170
10545
|
*/
|
|
8171
10546
|
createSession(options) {
|
|
8172
|
-
const
|
|
10547
|
+
const userApiKeyHeader = getUserApiKeyHeader(options?.headers) ? void 0 : getUserApiKeyHeader(this.config.defaultHeaders);
|
|
10548
|
+
const sessionHeaders = getDefaultHeaders(userApiKeyHeader ? {
|
|
10549
|
+
[userApiKeyHeader.name]: userApiKeyHeader.value,
|
|
10550
|
+
...options?.headers
|
|
10551
|
+
} : options?.headers, this.provider);
|
|
8173
10552
|
return new Composio({
|
|
8174
10553
|
...this.config,
|
|
8175
10554
|
defaultHeaders: sessionHeaders
|
|
@@ -9004,4 +11383,4 @@ const ComposioMcpUpdateResponseSchema = z$1.object({
|
|
|
9004
11383
|
});
|
|
9005
11384
|
|
|
9006
11385
|
//#endregion
|
|
9007
|
-
export { AuthConfigCreationToolAccessConfigSchema, AuthConfigErrorCodes, AuthConfigListParamsSchema, AuthConfigListResponseSchema, AuthConfigRetrieveResponseSchema, AuthConfigToolAccessConfigSchema, AuthConfigTypes, AuthConfigUpdateParamsSchema, AuthCustomConfigUpdateParamsSchema, AuthDefaultConfigUpdateParamsSchema, AuthScheme, AuthSchemeEnum, AuthSchemeTypes, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS, BaseAgenticProvider, BaseNonAgenticProvider, BillcomAuthConnectionDataSchema, Composio, ComposioAclOnlyForSharedError, ComposioAuthConfigNotFoundError, ComposioBlockedInternalUrlError, ComposioConnectedAccountNotFoundError, ComposioCustomCreateResponseSchema, ComposioError, ComposioFailedToCreateConnectedAccountLink, ComposioFailedToCreatePusherClientError, ComposioFailedToGetSDKRealtimeCredentialsError, ComposioFailedToSubscribeToPusherChannelError, ComposioFailedToUnsubscribeFromPusherChannelError, ComposioFileNotFoundError, ComposioFileUploadAbortedError, ComposioFileUploadError, ComposioFileUploadPathNotAllowedError, ComposioGenerateURLParamsSchema, ComposioGenerateURLResponseSchema, ComposioGlobalExecuteToolFnNotSetError, ComposioInvalidExecuteFunctionError, ComposioInvalidModifierError, ComposioInvalidToolArgumentsError, ComposioLegacyConnectedAccountsEndpointRetiredError, ComposioMcpDeleteResponseSchema, ComposioMcpListResponseSchema, ComposioMcpRetrieveResponseSchema, ComposioMcpUpdateResponseSchema, ComposioMultipleConnectedAccountsError, ComposioNoAPIKeyError, ComposioProvider, ComposioProviderNotDefinedError, ComposioRequestCancelledError, ComposioSensitiveFilePathBlockedError, ComposioSharedAccessDeniedError, ComposioSharedConnectionNotAccessibleError, ComposioToolExecutionError, ComposioToolNotFoundError, ComposioToolVersionRequiredError, ComposioToolkitFetchError, ComposioToolkitNotFoundError, ComposioTriggerTypeNotFoundError, ComposioWebhookPayloadError, ComposioWebhookSignatureVerificationError, ConnectedAccountAclConfigResponseSchema, ConnectedAccountAclConfigSchema, ConnectedAccountAuthConfigSchema, ConnectedAccountErrorCodes, ConnectedAccountExperimentalResponseSchema, ConnectedAccountExperimentalSchema, ConnectedAccountListParamsSchema, ConnectedAccountListResponseSchema, ConnectedAccountRefreshOptionsSchema, ConnectedAccountRetrieveResponseSchema, ConnectedAccountStatusSchema, ConnectedAccountStatuses, ConnectedAccountTypeSchema, ConnectedAccountTypes, ConnectionDataSchema, ConnectionExpiredEventSchema, ConnectionRequestErrorCodes, ConnectionRequestFailedError, ConnectionRequestTimeoutError, ConnectionStatus, ConnectionStatuses, CreateAuthConfigParamsSchema, CreateAuthConfigResponseSchema, CreateComposioManagedAuthConfigParamsSchema, CreateConnectedAccountLinkOptionsSchema, CreateConnectedAccountLinkResponseSchema, CreateConnectedAccountOptionsSchema, CreateConnectedAccountParamsSchema, CreateConnectedAccountResponseSchema, CreateCustomAuthConfigParamsSchema, CreateCustomToolBaseSchema, CreateCustomToolkitBaseSchema, CustomAuthParamsSchema, CustomConnectionDataSchema, CustomCreateResponseSchema, CustomOauth1ConnectionDataSchema, CustomOauth2ConnectionDataSchema, CustomToolSlugSchema, DefaultCreateConnectedAccountParamsSchema, DefaultWebhookSubscriptionEvents, Experimental, FileDeleteResponseSchema, FileListResponseSchema, FileModifierErrorCodes, GenerateURLParamsSchema, GenerateURLResponseSchema, IncomingTriggerPayloadSchema, JSONSchemaPropertySchema, JsonSchemaRefResolutionError, JsonSchemaToZodError, MCP, MCPAuthOptionsSchema, MCPGenerateURLParamsSchema, MCPGetServerParamsSchema, MCPMultiAppServerSchema, MCPServerCreateResponseSchema, MCPServerListResponseSchema, MCPServerSchema, MCPServerTypeSchema, MCPServerUpdateParamsSchema, MCPSingleAppServerSchema, MCPToolkitConfigSchema, MCPToolkitConfigsArraySchema, McpDeleteResponseSchema, McpListResponseSchema, McpRetrieveResponseSchema, McpUpdateResponseSchema, Oauth1ActiveConnectionDataSchema, Oauth1ConnectionDataSchema, Oauth1ExpiredConnectionDataSchema, Oauth1FailedConnectionDataSchema, Oauth1InactiveConnectionDataSchema, Oauth1InitiatedConnectionDataSchema, Oauth1InitiatingConnectionDataSchema, Oauth2ActiveConnectionDataSchema, Oauth2ConnectionDataSchema, Oauth2ExpiredConnectionDataSchema, Oauth2FailedConnectionDataSchema, Oauth2InactiveConnectionDataSchema, Oauth2InitiatedConnectionDataSchema, Oauth2InitiatingConnectionDataSchema, Oauth2RevokedConnectionDataSchema, OpenAIProvider, RedirectableAuthSchemeSchema, RemoteFile, RemoteFileDataSchema, RemoteFileDownloadError, RemoteFileErrorCodes, SDKErrorCodes, SandboxSizeSchema, SessionPreset, SessionProxyExecuteParamsSchema, Sessions, SetWebhookSubscriptionParamsSchema, SingleConnectedAccountDetailedResponseSchema, SsrfErrorCodes, ToolErrorCodes, ToolExecuteMetaParamsSchema, ToolExecuteParamsSchema, ToolExecuteResponseSchema, ToolKitItemSchema, ToolKitListResponseSchema, ToolKitMetaSchema, ToolListParamsSchema, ToolListResponseSchema, ToolProxyParamsSchema, ToolRouterConfigManageConnectionsSchema, ToolRouterConfigTagsSchema, ToolRouterConfigToolsSchema, ToolRouterCreateSessionConfigSchema, ToolRouterMCPServerConfigSchema, ToolRouterManageConnectionsConfigSchema, ToolRouterSandboxConfigSchema, ToolRouterSession, ToolRouterSessionDeleteResponseSchema, ToolRouterSessionExecuteResponseSchema, ToolRouterSessionFilesMountDeleteOptionsSchema, ToolRouterSessionFilesMountDownloadOptionsSchema, ToolRouterSessionFilesMountListOptionsSchema, ToolRouterSessionFilesMountUploadOptionsSchema, ToolRouterSessionSearchResponseSchema, ToolRouterTagsEnableDisableSchema, ToolRouterTagsParamSchema, ToolRouterToolkitsDisabledConfigSchema, ToolRouterToolkitsEnabledConfigSchema, ToolRouterToolkitsOptionsSchema, ToolRouterToolkitsParamSchema, ToolRouterToolsParamSchema, ToolRouterUpdateSessionConfigSchema, ToolSchema, ToolkitAuthConfigDetailsSchema, ToolkitAuthFieldSchema, ToolkitAuthFieldsResponseSchema, ToolkitCategorySchema, ToolkitConnectionStateSchema, ToolkitConnectionsDetailsSchema, ToolkitErrorCodes, ToolkitLatestVersionSchema, ToolkitMangedByEnumSchema, ToolkitRetrieveCategoriesResponseSchema, ToolkitRetrieveResponseSchema, ToolkitSchema, ToolkitSortByEnumSchema, ToolkitVersionParamSchema, ToolkitVersionSchema, ToolkitVersionsSchema, ToolkitsListParamsSchema, TriggerErrorCodes, TriggerInstanceListActiveParamsSchema, TriggerInstanceListActiveResponseItemSchema, TriggerInstanceListActiveResponseSchema, TriggerInstanceManageDeleteResponseSchema, TriggerInstanceManageUpdateParamsSchema, TriggerInstanceManageUpdateResponseSchema, TriggerInstanceUpsertParamsSchema, TriggerInstanceUpsertResponseSchema, TriggerStatusEnum, TriggerStatuses, TriggerSubscribeParamSchema, TriggerTypeSchema, TriggersTypeListParamsSchema, TriggersTypeListResponseSchema, UpdateConnectedAccountAclParamsSchema, UpdateConnectedAccountParamsSchema, ValidationError, ValidationErrorCodes, VerifyWebhookParamsSchema, WebhookConnectedAccountAuthConfigSchema, WebhookConnectionMetadataSchema, WebhookConnectionStateSchema, WebhookEventSchema, WebhookEventTypes, WebhookPayloadSchema, WebhookPayloadV1Schema, WebhookPayloadV2Schema, WebhookPayloadV3Schema, WebhookTriggerPayloadV3Schema, WebhookVersions, assertSafeFileUploadPath, constants_exports as constants, createConnectionRequest, deduplicateJsonSchemaRequiredArrays, dereferenceJsonSchema, ensureObjectTypeOnProperties, createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit, getExtensionFromMimeType, handleToolExecutionError, isBlockedSensitiveFileUploadPath, isRequestAbortError, jsonSchemaToZodSchema, logger, mappingHasRenames, normalizeToolArguments, omitNullToolArguments, removeNonRequiredProperties, restoreOriginalKeys, sanitizeSchemaPropertyKeys, telemetry, toStrictJsonSchema };
|
|
11386
|
+
export { AuthConfigCreationToolAccessConfigSchema, AuthConfigErrorCodes, AuthConfigListParamsSchema, AuthConfigListResponseSchema, AuthConfigRetrieveResponseSchema, AuthConfigToolAccessConfigSchema, AuthConfigTypes, AuthConfigUpdateParamsSchema, AuthCustomConfigUpdateParamsSchema, AuthDefaultConfigUpdateParamsSchema, AuthScheme, AuthSchemeEnum, AuthSchemeTypes, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS, BaseAgenticProvider, BaseNonAgenticProvider, BillcomAuthConnectionDataSchema, Composio, ComposioAPIKeyKindError, ComposioAclOnlyForSharedError, ComposioAuthConfigNotFoundError, ComposioBlockedInternalUrlError, ComposioConnectedAccountNotFoundError, ComposioConnectedAccountNotRevokableError, ComposioConnectedAccountRevocationNotSupportedError, ComposioCustomCreateResponseSchema, ComposioError, ComposioFailedToCreateConnectedAccountLink, ComposioFailedToCreatePusherClientError, ComposioFailedToGetSDKRealtimeCredentialsError, ComposioFailedToSubscribeToPusherChannelError, ComposioFailedToUnsubscribeFromPusherChannelError, ComposioFileNotFoundError, ComposioFileUploadAbortedError, ComposioFileUploadError, ComposioFileUploadPathNotAllowedError, ComposioGenerateURLParamsSchema, ComposioGenerateURLResponseSchema, ComposioGlobalExecuteToolFnNotSetError, ComposioInvalidExecuteFunctionError, ComposioInvalidModifierError, ComposioInvalidToolArgumentsError, ComposioLegacyConnectedAccountsEndpointRetiredError, ComposioMCPDestinationError, ComposioMcpDeleteResponseSchema, ComposioMcpListResponseSchema, ComposioMcpRetrieveResponseSchema, ComposioMcpUpdateResponseSchema, ComposioMultipleConnectedAccountsError, ComposioNoAPIKeyError, ComposioProvider, ComposioProviderNotDefinedError, ComposioRequestCancelledError, ComposioScopeConfigError, ComposioSensitiveFilePathBlockedError, ComposioSessionConfigConflictError, ComposioSharedAccessDeniedError, ComposioSharedConnectionNotAccessibleError, ComposioToolExecutionError, ComposioToolFetchError, ComposioToolNotFoundError, ComposioToolVersionRequiredError, ComposioToolkitFetchError, ComposioToolkitNotFoundError, ComposioTriggerTypeNotFoundError, ComposioWebhookPayloadError, ComposioWebhookSignatureVerificationError, ConnectedAccountAclConfigResponseSchema, ConnectedAccountAclConfigSchema, ConnectedAccountAuthConfigSchema, ConnectedAccountCompleteAuthParamsSchema, ConnectedAccountCompleteAuthResponseSchema, ConnectedAccountErrorCodes, ConnectedAccountExperimentalResponseSchema, ConnectedAccountExperimentalSchema, ConnectedAccountListParamsSchema, ConnectedAccountListResponseSchema, ConnectedAccountRefreshOptionsSchema, ConnectedAccountRetrieveResponseSchema, ConnectedAccountRevokeResponseSchema, ConnectedAccountRevokedTokenSchema, ConnectedAccountStatusSchema, ConnectedAccountStatuses, ConnectedAccountTypeSchema, ConnectedAccountTypes, ConnectionDataSchema, ConnectionExpiredEventSchema, ConnectionRequestErrorCodes, ConnectionRequestFailedError, ConnectionRequestTimeoutError, ConnectionStatus, ConnectionStatuses, CreateAuthConfigParamsSchema, CreateAuthConfigResponseSchema, CreateComposioManagedAuthConfigParamsSchema, CreateConnectedAccountLinkOptionsSchema, CreateConnectedAccountLinkResponseSchema, CreateConnectedAccountOptionsSchema, CreateConnectedAccountParamsSchema, CreateConnectedAccountResponseSchema, CreateCustomAuthConfigParamsSchema, CreateCustomToolBaseSchema, CreateCustomToolkitBaseSchema, CustomAuthParamsSchema, CustomConnectionDataSchema, CustomCreateResponseSchema, CustomOauth1ConnectionDataSchema, CustomOauth2ConnectionDataSchema, CustomToolSlugSchema, CustomToolkitAuthSchemeSchema, CustomToolkitDeleteResponseSchema, CustomToolkitSyncParamsSchema, CustomToolkitSyncResponseSchema, CustomToolkitUpsertParamsSchema, CustomToolkitUpsertResponseSchema, CustomToolkits, DefaultCreateConnectedAccountParamsSchema, DefaultWebhookSubscriptionEvents, Experimental, FileDeleteResponseSchema, FileListResponseSchema, FileModifierErrorCodes, GenerateURLParamsSchema, GenerateURLResponseSchema, IncomingTriggerPayloadSchema, JSONSchemaPropertySchema, JsonSchemaRefResolutionError, JsonSchemaToZodError, Keyring, KeyringTransferKeySchema, KeyringTransferKeysResponseSchema, LogSearchFilterFieldSchema, LogSearchFilterOperatorSchema, LogSearchFilterSchema, LogSearchParamsSchema, LogSearchResponseSchema, LogSearchTimeRangeSchema, Logs, MAX_URL_UPLOAD_SIZE_BYTES, MCP, MCPAuthOptionsSchema, MCPGenerateURLParamsSchema, MCPGetServerParamsSchema, MCPMultiAppServerSchema, MCPServerCreateResponseSchema, MCPServerListResponseSchema, MCPServerSchema, MCPServerTypeSchema, MCPServerUpdateParamsSchema, MCPSingleAppServerSchema, MCPToolkitConfigSchema, MCPToolkitConfigsArraySchema, McpDeleteResponseSchema, McpListResponseSchema, McpRetrieveResponseSchema, McpUpdateResponseSchema, Oauth1ActiveConnectionDataSchema, Oauth1ConnectionDataSchema, Oauth1ExpiredConnectionDataSchema, Oauth1FailedConnectionDataSchema, Oauth1InactiveConnectionDataSchema, Oauth1InitiatedConnectionDataSchema, Oauth1InitiatingConnectionDataSchema, Oauth2ActiveConnectionDataSchema, Oauth2ConnectionDataSchema, Oauth2ExpiredConnectionDataSchema, Oauth2FailedConnectionDataSchema, Oauth2InactiveConnectionDataSchema, Oauth2InitiatedConnectionDataSchema, Oauth2InitiatingConnectionDataSchema, Oauth2RevokedConnectionDataSchema, OpenAIProvider, RedirectableAuthSchemeSchema, RemoteFile, RemoteFileDataSchema, RemoteFileDownloadError, RemoteFileErrorCodes, SDKErrorCodes, SandboxSizeSchema, SessionPreset, SessionProxyExecuteParamsSchema, Sessions, SetWebhookSubscriptionParamsSchema, SingleConnectedAccountDetailedResponseSchema, SsrfErrorCodes, ToolErrorCodes, ToolExecuteMetaParamsSchema, ToolExecuteParamsSchema, ToolExecuteResponseSchema, ToolExecutionLogDetailSchema, ToolExecutionLogLevelSchema, ToolExecutionLogParentSchema, ToolExecutionLogSchema, ToolExecutionLogStatusSchema, ToolKitItemSchema, ToolKitListResponseSchema, ToolKitMetaSchema, ToolListParamsSchema, ToolListResponseSchema, ToolProxyParamsSchema, ToolRouterConfigManageConnectionsSchema, ToolRouterConfigTagsSchema, ToolRouterConfigToolsSchema, ToolRouterCreateSessionConfigSchema, ToolRouterErrorCodes, ToolRouterMCPServerConfigSchema, ToolRouterManageConnectionsConfigSchema, ToolRouterSandboxConfigSchema, ToolRouterSession, ToolRouterSessionDeleteResponseSchema, ToolRouterSessionEnsureConnectedOptionsSchema, ToolRouterSessionExecuteResponseSchema, ToolRouterSessionFilesMountDeleteOptionsSchema, ToolRouterSessionFilesMountDownloadOptionsSchema, ToolRouterSessionFilesMountListOptionsSchema, ToolRouterSessionFilesMountUploadOptionsSchema, ToolRouterSessionListConfigHistoryOptionsSchema, ToolRouterSessionSearchResponseSchema, ToolRouterTagsEnableDisableSchema, ToolRouterTagsParamSchema, ToolRouterToolkitsDisabledConfigSchema, ToolRouterToolkitsEnabledConfigSchema, ToolRouterToolkitsOptionsSchema, ToolRouterToolkitsParamSchema, ToolRouterToolsParamSchema, ToolRouterUpdateExperimentalSchema, ToolRouterUpdateManageConnectionsSchema, ToolRouterUpdateSessionConfigSchema, ToolSchema, ToolkitAuthConfigDetailsSchema, ToolkitAuthFieldSchema, ToolkitAuthFieldsResponseSchema, ToolkitCategorySchema, ToolkitChangelogItemSchema, ToolkitChangelogResponseSchema, ToolkitConditionalScopeSchema, ToolkitConnectionStateSchema, ToolkitConnectionsDetailsSchema, ToolkitErrorCodes, ToolkitGetManySlugsSchema, ToolkitGrantContextDimensionSchema, ToolkitLatestVersionSchema, ToolkitListGrantContextsParamsSchema, ToolkitListGrantContextsResponseSchema, ToolkitMangedByEnumSchema, ToolkitRecommendScopesParamsSchema, ToolkitRecommendScopesResponseSchema, ToolkitRetrieveCategoriesResponseSchema, ToolkitRetrieveResponseSchema, ToolkitSchema, ToolkitSortByEnumSchema, ToolkitVersionChangelogSchema, ToolkitVersionParamSchema, ToolkitVersionSchema, ToolkitVersionsSchema, ToolkitsGetManyParamsSchema, ToolkitsListParamsSchema, TriggerErrorCodes, TriggerInstanceListActiveParamsSchema, TriggerInstanceListActiveResponseItemSchema, TriggerInstanceListActiveResponseSchema, TriggerInstanceManageDeleteResponseSchema, TriggerInstanceManageUpdateParamsSchema, TriggerInstanceManageUpdateResponseSchema, TriggerInstanceUpsertParamsSchema, TriggerInstanceUpsertResponseSchema, TriggerStatusEnum, TriggerStatuses, TriggerSubscribeParamSchema, TriggerTypeSchema, TriggersTypeListParamsSchema, TriggersTypeListResponseSchema, UpdateConnectedAccountAclParamsSchema, UpdateConnectedAccountParamsSchema, Usage, UsageBreakdownGroupSchema, UsageBreakdownParamsSchema, UsageBreakdownResponseSchema, UsageEntitySummarySchema, UsageFiltersSchema, UsageOrderBySchema, UsageOrderDirectionSchema, UsageSummaryParamsSchema, UsageSummaryResponseSchema, ValidationError, ValidationErrorCodes, VerifyWebhookParamsSchema, WebhookConnectedAccountAuthConfigSchema, WebhookConnectionMetadataSchema, WebhookConnectionStateSchema, WebhookEndpointCreateParamsSchema, WebhookEndpointListItemSchema, WebhookEndpointListParamsSchema, WebhookEndpointListResponseSchema, WebhookEndpointReplaceParamsSchema, WebhookEndpointSchema, WebhookEndpointUpdateParamsSchema, WebhookEndpoints, WebhookEventSchema, WebhookEventTypes, WebhookPayloadSchema, WebhookPayloadV1Schema, WebhookPayloadV2Schema, WebhookPayloadV3Schema, WebhookSubscriptionDeleteResponseSchema, WebhookSubscriptionEventTypeSchema, WebhookSubscriptionEventTypesResponseSchema, WebhookSubscriptionListParamsSchema, WebhookSubscriptionListResponseSchema, WebhookSubscriptionRotateSecretResponseSchema, WebhookSubscriptionSchema, WebhookSubscriptionSetParamsSchema, WebhookSubscriptionUpdateParamsSchema, WebhookSubscriptions, WebhookTriggerPayloadV3Schema, WebhookVersionSchema, WebhookVersions, Webhooks, assertSafeFileUploadPath, constants_exports as constants, createConnectionRequest, deduplicateJsonSchemaRequiredArrays, dereferenceJsonSchema, ensureObjectTypeOnProperties, createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit, getExtensionFromMimeType, handleToolExecutionError, isBlockedSensitiveFileUploadPath, isRequestAbortError, jsonSchemaToZodSchema, logger, mappingHasRenames, normalizeToolArguments, omitNullToolArguments, readResponseBodyWithLimit, removeNonRequiredProperties, restoreOriginalKeys, sanitizeSchemaPropertyKeys, telemetry, toStrictJsonSchema };
|