@composio/core 0.31.0 → 0.32.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.
Files changed (84) hide show
  1. package/dist/{CustomTool-9Vlb4XaS.mjs → CustomTool-B4dQn2M5.mjs} +1 -1
  2. package/dist/{CustomTool-Ds5aLDth.d.mts → CustomTool-CBx9kzea.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-WrqokuIF.mjs → FileModifierErrors-D-AKc3ds.mjs} +1 -1
  4. package/dist/{SsrfErrors-BSVMW915.mjs → SsrfErrors-BekZPeWY.mjs} +59 -12
  5. package/dist/{Telemetry-a7SOQXcg.mjs → Telemetry-BWKZmDxM.mjs} +2 -2
  6. package/dist/composio-CPf6NHnB.d.mts +20334 -0
  7. package/dist/{customTool.types-DHxXBU6E.d.mts → customTool.types-BSbIG1OG.d.mts} +291 -68
  8. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +20 -12
  9. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +28 -10
  10. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +44 -32
  11. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -6
  12. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +4 -3
  13. package/dist/docs/reference/sdk-reference/typescript/index.mdx +4 -2
  14. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +6 -3
  15. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -3
  16. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +53 -42
  17. package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
  18. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +5 -14
  19. package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -3
  20. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +7 -5
  21. package/dist/docs/reference/sdk-reference/typescript/session-webhooks.mdx +64 -0
  22. package/dist/docs/reference/sdk-reference/typescript/session.mdx +16 -16
  23. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +36 -8
  24. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +14 -11
  25. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +16 -18
  26. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +42 -30
  27. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -4
  28. package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +9 -7
  29. package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -9
  30. package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +3 -1
  31. package/dist/{errors-xC13uvaA.mjs → errors-CtIKA9BH.mjs} +2 -2
  32. package/dist/experimental/index.d.mts +2 -2
  33. package/dist/experimental/index.mjs +1 -1
  34. package/dist/{fileUtils.node-CAwIbWYH.mjs → fileUtils.node-BJUYMEph.mjs} +7 -7
  35. package/dist/index.d.mts +6 -11
  36. package/dist/index.mjs +526 -233
  37. package/dist/{jsonSchema-Cc4EtHRw.mjs → jsonSchema-BZoXGUCr.mjs} +2 -2
  38. package/dist/models/Files.node.mjs +3 -3
  39. package/dist/{sensitiveFileUploadPaths-CSyJ3Ku8.mjs → sensitiveFileUploadPaths-CcbMAYCC.mjs} +21 -15
  40. package/dist/{ssrfGuard.node-CdIkwqVu.mjs → ssrfGuard.node-B749ae5Q.mjs} +1 -1
  41. package/dist/{types-DcdZy5Nc.d.mts → types-ns3Q_WrP.d.mts} +2 -2
  42. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  43. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  44. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  45. package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
  46. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  47. package/dist/utils/ssrfGuard.node.mjs +1 -1
  48. package/dist/utils/ssrfGuard.workerd.mjs +1 -1
  49. package/package.json +2 -2
  50. package/src/composio.ts +26 -7
  51. package/src/errors/ComposioError.ts +3 -2
  52. package/src/index.ts +19 -0
  53. package/src/lib/toolRouterParams.ts +38 -14
  54. package/src/models/AuthConfigs.ts +10 -3
  55. package/src/models/ConnectedAccounts.ts +30 -17
  56. package/src/models/CustomTool.ts +0 -10
  57. package/src/models/Keyring.ts +2 -1
  58. package/src/models/MCP.ts +43 -35
  59. package/src/models/SessionWebhooks.ts +136 -0
  60. package/src/models/ToolRouter.ts +39 -4
  61. package/src/models/ToolRouterSession.ts +2 -2
  62. package/src/models/ToolRouterSessionFileMount.ts +3 -1
  63. package/src/models/Toolkits.ts +1 -0
  64. package/src/models/Tools.ts +4 -8
  65. package/src/models/Triggers.ts +48 -213
  66. package/src/models/Webhooks.ts +2 -0
  67. package/src/provider/ComposioProvider.ts +0 -1
  68. package/src/telemetry/BatchProcessor.ts +1 -1
  69. package/src/telemetry/Telemetry.ts +1 -1
  70. package/src/types/connectedAccountAuthStates.types.ts +0 -1
  71. package/src/types/provider.types.ts +0 -1
  72. package/src/types/sessionWebhooks.types.ts +292 -0
  73. package/src/types/toolRouter.types.ts +33 -4
  74. package/src/types/triggers.types.ts +4 -0
  75. package/src/utils/crypto.ts +6 -5
  76. package/src/utils/env.ts +2 -5
  77. package/src/utils/fileUtils.node.ts +4 -3
  78. package/src/utils/logger.ts +19 -9
  79. package/src/utils/pusher.ts +5 -2
  80. package/src/utils/readResponseBody.ts +30 -17
  81. package/src/utils/transformers/authConfigs.ts +0 -1
  82. package/src/utils/userCallback.ts +3 -1
  83. package/src/utils/webhookVerification.ts +211 -0
  84. package/dist/composio-Ba89XGHL.d.mts +0 -9736
@@ -1,5 +1,5 @@
1
- import { g as JsonSchemaToZodError, h as JsonSchemaRefResolutionError } from "./errors-xC13uvaA.mjs";
2
- import { s as logger } from "./SsrfErrors-BSVMW915.mjs";
1
+ import { g as JsonSchemaToZodError, h as JsonSchemaRefResolutionError } from "./errors-CtIKA9BH.mjs";
2
+ import { l as logger } from "./SsrfErrors-BekZPeWY.mjs";
3
3
  import { o as isPlainObject } from "./FileToolModifier.utils.neutral-BQP85ZJj.mjs";
4
4
  import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
5
5
 
@@ -1,6 +1,6 @@
1
- import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-CAwIbWYH.mjs";
2
- import { d as withCancellation } from "../sensitiveFileUploadPaths-CSyJ3Ku8.mjs";
3
- import { t as telemetry } from "../Telemetry-a7SOQXcg.mjs";
1
+ import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-BJUYMEph.mjs";
2
+ import { p as withCancellation } from "../sensitiveFileUploadPaths-CcbMAYCC.mjs";
3
+ import { t as telemetry } from "../Telemetry-BWKZmDxM.mjs";
4
4
 
5
5
  // src/models/Files.node.ts
6
6
  var Files = class {
@@ -1,4 +1,4 @@
1
- import { a as ComposioSensitiveFilePathBlockedError, f as isRequestAbortError, l as ComposioRequestCancelledError } from "./FileModifierErrors-WrqokuIF.mjs";
1
+ import { a as ComposioSensitiveFilePathBlockedError, f as isRequestAbortError, l as ComposioRequestCancelledError } from "./FileModifierErrors-D-AKc3ds.mjs";
2
2
  import { platform } from "#platform";
3
3
 
4
4
  // src/utils/uuid.ts
@@ -50,25 +50,28 @@ const uint8ArrayToBase64 = (bytes) => {
50
50
  /** Maximum size accepted for files fetched from user-supplied URLs (100 MiB). */
51
51
  const MAX_URL_UPLOAD_SIZE_BYTES = 104857600;
52
52
  const sizeLimitError = (actualSize, maxBytes) => /* @__PURE__ */ new Error(`File size (${actualSize} bytes) exceeds maximum allowed size (${maxBytes} bytes)`);
53
+ const assertValidBodyLimit = (maxBytes) => {
54
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) throw new RangeError("maxBytes must be a non-negative safe integer");
55
+ };
53
56
  /**
54
- * Read a fetch response without allowing an untrusted server to exhaust memory.
57
+ * Read a Fetch request or response within a byte limit.
55
58
  *
56
59
  * `Content-Length` is checked as an early rejection, but the streamed byte
57
60
  * count is authoritative because the header can be absent or dishonest.
58
61
  */
59
- const readResponseBodyWithLimit = async (response, maxBytes = MAX_URL_UPLOAD_SIZE_BYTES) => {
60
- if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) throw new RangeError("maxBytes must be a non-negative safe integer");
61
- const contentLength = response.headers.get("content-length")?.trim();
62
+ const readBodyWithLimit = async ({ body, headers }, maxBytes, makeSizeLimitError) => {
63
+ assertValidBodyLimit(maxBytes);
64
+ const contentLength = headers.get("content-length")?.trim();
62
65
  if (contentLength && /^\d+$/.test(contentLength)) {
63
66
  const declaredSize = Number(contentLength);
64
67
  if (!Number.isSafeInteger(declaredSize) || declaredSize > maxBytes) {
65
- const error = sizeLimitError(declaredSize, maxBytes);
66
- await response.body?.cancel(error).catch(() => void 0);
68
+ const error = makeSizeLimitError(declaredSize, maxBytes);
69
+ body?.cancel(error).catch(() => void 0);
67
70
  throw error;
68
71
  }
69
72
  }
70
- if (!response.body) return /* @__PURE__ */ new Uint8Array();
71
- const reader = response.body.getReader();
73
+ if (!body) return /* @__PURE__ */ new Uint8Array();
74
+ const reader = body.getReader();
72
75
  const chunks = [];
73
76
  let totalBytes = 0;
74
77
  try {
@@ -78,22 +81,25 @@ const readResponseBodyWithLimit = async (response, maxBytes = MAX_URL_UPLOAD_SIZ
78
81
  if (!value || value.byteLength === 0) continue;
79
82
  totalBytes += value.byteLength;
80
83
  if (totalBytes > maxBytes) {
81
- await reader.cancel(sizeLimitError(totalBytes, maxBytes));
82
- throw sizeLimitError(totalBytes, maxBytes);
84
+ const error = makeSizeLimitError(totalBytes, maxBytes);
85
+ reader.cancel(error).catch(() => void 0);
86
+ throw error;
83
87
  }
84
88
  chunks.push(value);
85
89
  }
86
90
  } finally {
87
91
  reader.releaseLock();
88
92
  }
89
- const body = new Uint8Array(totalBytes);
93
+ const bytes = new Uint8Array(totalBytes);
90
94
  let offset = 0;
91
95
  for (const chunk of chunks) {
92
- body.set(chunk, offset);
96
+ bytes.set(chunk, offset);
93
97
  offset += chunk.byteLength;
94
98
  }
95
- return body;
99
+ return bytes;
96
100
  };
101
+ /** Read a Fetch response within the file size limit. */
102
+ const readResponseBodyWithLimit = (response, maxBytes = MAX_URL_UPLOAD_SIZE_BYTES) => readBodyWithLimit(response, maxBytes, sizeLimitError);
97
103
 
98
104
  // src/utils/mime.ts
99
105
  /**
@@ -595,4 +601,4 @@ function assertSafeFileUploadPath(filePath, options) {
595
601
  }
596
602
  }
597
603
 
598
- export { getMimeTypeFromFileName as a, arrayBufferToBase64 as c, withCancellation as d, getRandomShortId as f, getExtensionFromMimeType as i, base64ToUint8Array as l, assertSafeFileUploadPath as n, MAX_URL_UPLOAD_SIZE_BYTES as o, getRandomUUID as p, isBlockedSensitiveFileUploadPath as r, readResponseBodyWithLimit as s, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS as t, uint8ArrayToBase64 as u };
604
+ export { getMimeTypeFromFileName as a, readBodyWithLimit as c, base64ToUint8Array as d, uint8ArrayToBase64 as f, getRandomUUID as h, getExtensionFromMimeType as i, readResponseBodyWithLimit as l, getRandomShortId as m, assertSafeFileUploadPath as n, MAX_URL_UPLOAD_SIZE_BYTES as o, withCancellation as p, isBlockedSensitiveFileUploadPath as r, assertValidBodyLimit as s, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS as t, arrayBufferToBase64 as u };
@@ -1,4 +1,4 @@
1
- import { t as ComposioBlockedInternalUrlError } from "./SsrfErrors-BSVMW915.mjs";
1
+ import { t as ComposioBlockedInternalUrlError } from "./SsrfErrors-BekZPeWY.mjs";
2
2
  import { lookup } from "node:dns/promises";
3
3
  import { isIP } from "node:net";
4
4
  import { request } from "node:http";
@@ -1,5 +1,5 @@
1
- import { n as ComposioConfig } from "./composio-Ba89XGHL.mjs";
2
- import { jr as BaseComposioProvider } from "./customTool.types-DHxXBU6E.mjs";
1
+ import { n as ComposioConfig } from "./composio-CPf6NHnB.mjs";
2
+ import { Nr as BaseComposioProvider } from "./customTool.types-BSbIG1OG.mjs";
3
3
  /**
4
4
  * Configuration defaults for Composio.
5
5
  * These are the required fields that must have default values.
@@ -1,2 +1,2 @@
1
- import { t as ConfigDefaults } from "../../types-DcdZy5Nc.mjs";
1
+ import { t as ConfigDefaults } from "../../types-ns3Q_WrP.mjs";
2
2
  export declare const CONFIG_DEFAULTS: ConfigDefaults;
@@ -1,2 +1,2 @@
1
- import { t as ConfigDefaults } from "../../types-DcdZy5Nc.mjs";
1
+ import { t as ConfigDefaults } from "../../types-ns3Q_WrP.mjs";
2
2
  export declare const CONFIG_DEFAULTS: ConfigDefaults;
@@ -1,4 +1,4 @@
1
- import { Qa as ToolExecuteResponse, Xa as ToolExecuteParams, qa as Tool } from "../../customTool.types-DHxXBU6E.mjs";
1
+ import { Qa as ToolExecuteParams, Ya as Tool, eo as ToolExecuteResponse } from "../../customTool.types-BSbIG1OG.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  export declare class FileToolModifier {
4
4
  private client;
@@ -1,9 +1,9 @@
1
- import { s as logger } from "../../SsrfErrors-BSVMW915.mjs";
2
- import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, l as ComposioRequestCancelledError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-WrqokuIF.mjs";
3
- import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-CAwIbWYH.mjs";
1
+ import { l as logger } from "../../SsrfErrors-BekZPeWY.mjs";
2
+ import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, l as ComposioRequestCancelledError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-D-AKc3ds.mjs";
3
+ import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-BJUYMEph.mjs";
4
4
  import { a as isEmptyFileValue, c as transformProperties, i as getSchemaVariants, l as walkFileUploadableLeaves, o as isPlainObject, r as findSchemaVariantWithFileProperty, t as DELETE_VALUE } from "../../FileToolModifier.utils.neutral-BQP85ZJj.mjs";
5
- import { n as dereferenceJsonSchema } from "../../jsonSchema-Cc4EtHRw.mjs";
6
- import { d as withCancellation } from "../../sensitiveFileUploadPaths-CSyJ3Ku8.mjs";
5
+ import { n as dereferenceJsonSchema } from "../../jsonSchema-BZoXGUCr.mjs";
6
+ import { p as withCancellation } from "../../sensitiveFileUploadPaths-CcbMAYCC.mjs";
7
7
 
8
8
  // src/utils/modifiers/FileToolModifier.node.ts
9
9
  /**
@@ -1,4 +1,4 @@
1
- import { Qa as ToolExecuteResponse, Xa as ToolExecuteParams, qa as Tool } from "../../customTool.types-DHxXBU6E.mjs";
1
+ import { Qa as ToolExecuteParams, Ya as Tool, eo as ToolExecuteResponse } from "../../customTool.types-BSbIG1OG.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  export declare class FileToolModifier {
4
4
  constructor(_client: ComposioClient);
@@ -1,3 +1,3 @@
1
- import { i as ssrfSafeFetchWhereSupported, n as isBlockedIp, r as ssrfSafeFetch, t as assertSafeFetchTarget } from "../ssrfGuard.node-CdIkwqVu.mjs";
1
+ import { i as ssrfSafeFetchWhereSupported, n as isBlockedIp, r as ssrfSafeFetch, t as assertSafeFetchTarget } from "../ssrfGuard.node-B749ae5Q.mjs";
2
2
 
3
3
  export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch, ssrfSafeFetchWhereSupported };
@@ -1,4 +1,4 @@
1
- import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-BSVMW915.mjs";
1
+ import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-BekZPeWY.mjs";
2
2
 
3
3
  // src/utils/ssrfGuard.workerd.ts
4
4
  /**
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22.22.3"
6
6
  },
7
- "version": "0.31.0",
7
+ "version": "0.32.0",
8
8
  "description": "",
9
9
  "main": "dist/index.mjs",
10
10
  "publishConfig": {
@@ -137,7 +137,7 @@
137
137
  "semver": "^7.8.6",
138
138
  "undici": "^7.30.2",
139
139
  "zod-to-json-schema": "^3.25.2",
140
- "@composio/json-schema-to-zod": "0.4.1"
140
+ "@composio/json-schema-to-zod": "0.4.2"
141
141
  },
142
142
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
143
143
  "repository": {
package/src/composio.ts CHANGED
@@ -31,7 +31,6 @@ import { checkForLatestVersionFromNPM } from './utils/version';
31
31
  import { OpenAIProvider } from './provider/OpenAIProvider';
32
32
  import { version } from '../package.json';
33
33
  import type { ComposioRequestHeaders } from './types/composio.types';
34
- import type { ComposioRequestOptions } from './types/requestOptions.types';
35
34
  import { Files } from '#files';
36
35
  import { getClientIdentity } from './utils/session';
37
36
  import { ToolkitVersionParam } from './types/tool.types';
@@ -460,19 +459,31 @@ export class Composio<
460
459
  *
461
460
  * @example
462
461
  * ```typescript
462
+ * import { Composio } from '@composio/core';
463
+ *
463
464
  * // Initialize with default configuration
464
465
  * const composio = new Composio();
466
+ * ```
467
+ *
468
+ * @example
469
+ * ```typescript
470
+ * import { Composio } from '@composio/core';
465
471
  *
466
472
  * // Initialize with custom API key and base URL
467
473
  * const composio = new Composio({
468
474
  * apiKey: 'your-api-key',
469
475
  * baseURL: 'https://api.composio.dev'
470
476
  * });
477
+ * ```
471
478
  *
472
- * // Initialize with custom provider
479
+ * @example
480
+ * ```typescript
481
+ * import { Composio, OpenAIProvider } from '@composio/core';
482
+ *
483
+ * // Initialize with an explicit provider
473
484
  * const composio = new Composio({
474
485
  * apiKey: 'your-api-key',
475
- * provider: new CustomProvider()
486
+ * provider: new OpenAIProvider()
476
487
  * });
477
488
  * ```
478
489
  */
@@ -626,7 +637,7 @@ export class Composio<
626
637
 
627
638
  // Check for the latest version of the Composio SDK from NPM.
628
639
  if (!this.config.disableVersionCheck) {
629
- checkForLatestVersionFromNPM(version);
640
+ void checkForLatestVersionFromNPM(version);
630
641
  }
631
642
  }
632
643
 
@@ -678,6 +689,8 @@ export class Composio<
678
689
  *
679
690
  * @example
680
691
  * ```typescript
692
+ * import { Composio } from '@composio/core';
693
+ *
681
694
  * // Create a base Composio instance
682
695
  * const composio = new Composio({
683
696
  * apiKey: 'your-api-key'
@@ -693,7 +706,7 @@ export class Composio<
693
706
  * });
694
707
  *
695
708
  * // Use the session for making API calls with the custom headers
696
- * await composioWithCustomHeaders.tools.list();
709
+ * await composioWithCustomHeaders.tools.getRawComposioTools({ toolkits: ['github'] });
697
710
  * ```
698
711
  */
699
712
  createSession(options?: { headers?: ComposioRequestHeaders }): Composio<TProvider> {
@@ -717,14 +730,20 @@ export class Composio<
717
730
  * @returns {Promise<void>} A promise that resolves when all pending telemetry has been sent.
718
731
  *
719
732
  * @example
720
- * ```typescript
733
+ * ```typescript nocheck="Cloudflare Worker handler; the checker has no Workers Env or ExecutionContext types"
734
+ * import { Composio } from '@composio/core';
735
+ *
721
736
  * // In a Cloudflare Worker, use ctx.waitUntil to ensure telemetry is flushed
722
737
  * export default {
723
738
  * async fetch(request: Request, env: Env, ctx: ExecutionContext) {
724
739
  * const composio = new Composio({ apiKey: env.COMPOSIO_API_KEY });
725
740
  *
726
741
  * // Do your work...
727
- * const result = await composio.tools.execute(...);
742
+ * const result = await composio.tools.execute('GITHUB_GET_REPOS', {
743
+ * userId: 'user_123',
744
+ * version: '20250909_00',
745
+ * arguments: { owner: 'composio' },
746
+ * });
728
747
  *
729
748
  * // Ensure telemetry flushes before worker terminates
730
749
  * ctx.waitUntil(composio.flush());
@@ -8,6 +8,7 @@
8
8
  * @module errors/ComposioError
9
9
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
10
10
  */
11
+ import { describeThrown } from '../utils/userCallback';
11
12
  import pc from 'picocolors';
12
13
  import { ZodError } from 'zod/v3';
13
14
  import { APIError } from '@composio/client';
@@ -183,7 +184,7 @@ export class ComposioError extends Error {
183
184
  ? sanitizeApiErrorText(rawCause.message)
184
185
  : rawCause instanceof Error
185
186
  ? rawCause.message
186
- : sanitizeApiErrorText(String(rawCause));
187
+ : sanitizeApiErrorText(describeThrown(rawCause));
187
188
  }
188
189
 
189
190
  // Add code if exists
@@ -424,7 +425,7 @@ export class ComposioError extends Error {
424
425
 
425
426
  if (error !== null && error !== undefined) {
426
427
  logger.error(pc.gray('Error details:'));
427
- logger.error(' ' + pc.white(String(error)));
428
+ logger.error(' ' + pc.white(describeThrown(error)));
428
429
  }
429
430
 
430
431
  logger.error(''); // Add a trailing empty line
package/src/index.ts CHANGED
@@ -54,6 +54,7 @@ export { RemoteFile } from './models/RemoteFile';
54
54
  export { createConnectionRequest } from './models/ConnectionRequest';
55
55
  export { ToolRouterSession } from './models/ToolRouterSession';
56
56
  export { Sessions } from './models/Sessions';
57
+ export { SessionWebhooks } from './models/SessionWebhooks';
57
58
  export { SessionConfigs } from './models/SessionConfigs';
58
59
  export * from './types/provider.types';
59
60
  export * from './types/customTool.types';
@@ -66,6 +67,24 @@ export * from './types/toolkit.types';
66
67
  export * from './types/triggers.types';
67
68
  export * from './types/webhookEvents.types';
68
69
  export * from './types/webhooks.types';
70
+ export { SessionWebhookEventTypes } from './types/sessionWebhooks.types';
71
+ export type {
72
+ ParseSessionWebhookParams,
73
+ SessionWebhookAfterExecuteEvent,
74
+ SessionWebhookAfterExecuteResponse,
75
+ SessionWebhookBeforeExecuteEvent,
76
+ SessionWebhookBeforeExecuteResponse,
77
+ SessionWebhookBlockResponse,
78
+ SessionWebhookEvent,
79
+ SessionWebhookEventType,
80
+ SessionWebhookHttpRequest,
81
+ SessionWebhookHttpRequestOverride,
82
+ SessionWebhookHttpResponse,
83
+ SessionWebhookHttpResponseOverride,
84
+ SessionWebhookMetadata,
85
+ SessionWebhookToolCall,
86
+ SessionWebhookToolResponse,
87
+ } from './types/sessionWebhooks.types';
69
88
  export * from './types/logs.types';
70
89
  export * from './types/usage.types';
71
90
  export * from './types/keyring.types';
@@ -9,9 +9,6 @@ import {
9
9
  ToolRouterToolsParam,
10
10
  ToolRouterConfigManageConnectionsSchema,
11
11
  ToolRouterCreateSessionConfigSchema,
12
- ToolRouterToolkitsParamSchema,
13
- ToolRouterToolkitsDisabledConfigSchema,
14
- ToolRouterToolkitsEnabledConfigSchema,
15
12
  ToolRouterUpdateSessionConfigSchema,
16
13
  ToolRouterUpdateManageConnectionsConfig,
17
14
  ToolRouterUpdateManageConnectionsSchema,
@@ -41,7 +38,7 @@ const requireApprovalParam = <T extends string>(
41
38
  requireApproval !== undefined ? { require_approval: requireApproval } : {};
42
39
 
43
40
  export const transformToolRouterToolsParams = (
44
- params?: Record<string, ToolRouterToolsParam | ToolRouterConfigTools> | undefined
41
+ params?: Record<string, ToolRouterToolsParam | ToolRouterConfigTools>
45
42
  ): Record<string, SessionToolsEntry> | undefined => {
46
43
  if (!params) {
47
44
  return undefined;
@@ -104,7 +101,7 @@ export const transformToolRouterTagsParams = (
104
101
  };
105
102
 
106
103
  export const transformToolRouterManageConnectionsParams = (
107
- params?: boolean | z.infer<typeof ToolRouterConfigManageConnectionsSchema>
104
+ params?: z.infer<typeof ToolRouterConfigManageConnectionsSchema>
108
105
  ): NonNullable<SessionCreateParams['manage_connections']> => {
109
106
  if (params === undefined) {
110
107
  // Default case when params is undefined
@@ -137,7 +134,7 @@ export const transformToolRouterManageConnectionsParams = (
137
134
 
138
135
  export const resolveToolRouterSandboxConfig = (
139
136
  config: Pick<ParsedCreateSessionConfig, 'sandbox' | 'workbench'>
140
- ): ParsedCreateSessionConfig['sandbox'] | ParsedCreateSessionConfig['workbench'] => {
137
+ ): ParsedCreateSessionConfig['sandbox'] => {
141
138
  if (config.sandbox !== undefined && config.workbench !== undefined) {
142
139
  throw new ValidationError(
143
140
  'Pass either sandbox or workbench, not both. workbench is a backwards-compatible alias for sandbox.'
@@ -186,7 +183,7 @@ export const resolveLocalToolsOptions = (
186
183
  };
187
184
 
188
185
  export const transformToolRouterSandboxParams = (
189
- params?: ParsedCreateSessionConfig['sandbox'] | ParsedCreateSessionConfig['workbench']
186
+ params?: ParsedCreateSessionConfig['sandbox']
190
187
  ): NonNullable<SessionCreateParams['workbench']> | undefined => {
191
188
  if (!params) {
192
189
  return undefined;
@@ -235,14 +232,40 @@ export type SessionPatchExperimentalBody = WithNull<
235
232
  'permissions' | 'link_url_overwrite' | 'fast_mode' | 'submit_feedback'
236
233
  >;
237
234
 
235
+ type GeneratedSessionHook = NonNullable<SessionCreateParams['hooks']>[number];
236
+
237
+ type SessionWebhookHandlerBody = {
238
+ type: 'webhook';
239
+ fallback_action: 'block' | 'continue';
240
+ timeout_ms?: number;
241
+ };
242
+
238
243
  /**
239
- * `hooks` as sent on create and update: `appliesTo` becomes `applies_to`.
240
- * Create and patch take the same hook shape.
244
+ * `hooks` as sent on create and update. Wider than the generated type by the
245
+ * `webhook` handler, which `@composio/client` does not declare until it picks
246
+ * up ComposioHQ/platform#15328.
241
247
  */
242
- export const transformToolRouterHooksParams = (
243
- hooks: ToolRouterHook[]
244
- ): NonNullable<SessionCreateParams['hooks']> =>
245
- hooks.map(({ appliesTo, ...hook }) => ({ ...hook, applies_to: appliesTo }));
248
+ type SessionHooksBody = Array<
249
+ Omit<GeneratedSessionHook, 'handler'> & {
250
+ handler: GeneratedSessionHook['handler'] | SessionWebhookHandlerBody;
251
+ }
252
+ >;
253
+
254
+ export const transformToolRouterHooksParams = (hooks: ToolRouterHook[]): SessionHooksBody =>
255
+ hooks.map(({ appliesTo, handler, ...hook }) => ({
256
+ ...hook,
257
+ applies_to: appliesTo,
258
+ handler:
259
+ handler.type === 'webhook'
260
+ ? {
261
+ type: handler.type,
262
+ fallback_action: handler.fallbackAction,
263
+ ...(handler.timeoutMs !== undefined && { timeout_ms: handler.timeoutMs }),
264
+ }
265
+ : handler,
266
+ }));
267
+
268
+ export type SessionCreateBody = Omit<SessionCreateParams, 'hooks'> & { hooks?: SessionHooksBody };
246
269
 
247
270
  /**
248
271
  * Request body of `session.update()`. Extends the generated `SessionPatchParams`
@@ -255,8 +278,9 @@ export type SessionPatchBody = Omit<
255
278
  SessionPatchParams,
256
279
  'toolkits' | 'tools' | 'tags' | 'auth_configs' | 'preload' | 'search' | 'execute'
257
280
  >,
258
- 'manage_connections' | 'multi_account' | 'experimental'
281
+ 'manage_connections' | 'multi_account' | 'experimental' | 'hooks'
259
282
  > & {
283
+ hooks?: SessionHooksBody | null;
260
284
  manage_connections?: SessionPatchManageConnectionsBody | null;
261
285
  multi_account?: SessionPatchMultiAccountBody | null;
262
286
  experimental?: SessionPatchExperimentalBody | null;
@@ -104,15 +104,19 @@ export class AuthConfigs {
104
104
  * @returns {Promise<CreateAuthConfigResponse>} Created auth config
105
105
  *
106
106
  * @example
107
+ * import { AuthConfigTypes } from '@composio/core';
108
+ *
107
109
  * // Use a specific Composio-managed app; omit managedAppId for the toolkit's default
108
110
  * const { composioManagedAuth } = await composio.toolkits.get('slack');
109
- * const slackAuthConfig = await authConfigs.create('slack', {
111
+ * const slackAuthConfig = await composio.authConfigs.create('slack', {
110
112
  * type: AuthConfigTypes.COMPOSIO_MANAGED,
111
113
  * managedAppId: composioManagedAuth?.find(app => !app.isDefault)?.managedAppId,
112
114
  * });
113
115
  *
114
116
  * @example
115
- * const authConfig = await authConfigs.create('my-toolkit', {
117
+ * import { AuthConfigTypes, AuthSchemeTypes } from '@composio/core';
118
+ *
119
+ * const authConfig = await composio.authConfigs.create('my-toolkit', {
116
120
  * type: AuthConfigTypes.CUSTOM,
117
121
  * name: 'My Custom Auth Config',
118
122
  * authScheme: AuthSchemeTypes.API_KEY,
@@ -232,11 +236,14 @@ export class AuthConfigs {
232
236
  * apiKey: 'new-api-key-value'
233
237
  * }
234
238
  * });
239
+ * ```
235
240
  *
241
+ * @example
242
+ * ```typescript
236
243
  * // Update a default auth config with new scopes
237
244
  * const updatedConfig = await composio.authConfigs.update('auth_abc123', {
238
245
  * type: 'default',
239
- * scopes: ['read:user', 'repo']
246
+ * scopes: 'read:user,repo'
240
247
  * });
241
248
  * ```
242
249
  */
@@ -171,6 +171,8 @@ export class ConnectedAccounts {
171
171
  *
172
172
  * @example
173
173
  * ```typescript
174
+ * import { AuthScheme } from '@composio/core';
175
+ *
174
176
  * // For OAuth2 authentication
175
177
  * const connectionRequest = await composio.connectedAccounts.initiate(
176
178
  * 'user_123',
@@ -183,17 +185,27 @@ export class ConnectedAccounts {
183
185
  * })
184
186
  * }
185
187
  * );
188
+ * ```
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * import { AuthScheme } from '@composio/core';
186
193
  *
187
194
  * // For API Key authentication
188
195
  * const connectionRequest = await composio.connectedAccounts.initiate(
189
196
  * 'user_123',
190
197
  * 'auth_config_123',
191
198
  * {
192
- * config: AuthScheme.ApiKey({
199
+ * config: AuthScheme.APIKey({
193
200
  * api_key: 'your_api_key'
194
201
  * })
195
202
  * }
196
203
  * );
204
+ * ```
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * import { AuthScheme } from '@composio/core';
197
209
  *
198
210
  * // For Basic authentication
199
211
  * const connectionRequest = await composio.connectedAccounts.initiate(
@@ -470,7 +482,10 @@ export class ConnectedAccounts {
470
482
  * ```typescript
471
483
  * // Wait for a connection to complete with default timeout
472
484
  * const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc');
485
+ * ```
473
486
  *
487
+ * @example
488
+ * ```typescript
474
489
  * // Wait with a custom timeout of 2 minutes
475
490
  * const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc', 120000);
476
491
  * ```
@@ -658,11 +673,16 @@ export class ConnectedAccounts {
658
673
  *
659
674
  * @example
660
675
  * ```typescript
661
- * // In your verifier route, after authenticating the user:
662
- * const { connectedAccountId, toolkitSlug } = await composio.connectedAccounts.completeAuth({
663
- * userId: 'user_123',
664
- * sessionUri, // the session URI from the verifier redirect
665
- * });
676
+ * // Your verifier route, after authenticating the user
677
+ * export async function GET(request: Request) {
678
+ * // The session URI arrives as the `session_uri` query parameter of the verifier redirect
679
+ * const sessionUri = new URL(request.url).searchParams.get('session_uri') ?? '';
680
+ * const { connectedAccountId, toolkitSlug } = await composio.connectedAccounts.completeAuth({
681
+ * userId: 'user_123',
682
+ * sessionUri,
683
+ * });
684
+ * return new Response(`Connected ${toolkitSlug}: ${connectedAccountId}`);
685
+ * }
666
686
  * ```
667
687
  */
668
688
  async completeAuth(
@@ -702,10 +722,9 @@ export class ConnectedAccounts {
702
722
  * enabled: true
703
723
  * });
704
724
  *
705
- * // Disable a connected account with a reason
725
+ * // Disable a connected account
706
726
  * const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
707
- * enabled: false,
708
- * reason: 'Token expired'
727
+ * enabled: false
709
728
  * });
710
729
  * ```
711
730
  */
@@ -729,7 +748,7 @@ export class ConnectedAccounts {
729
748
  * ```typescript
730
749
  * // Enable a previously disabled connected account
731
750
  * const enabledAccount = await composio.connectedAccounts.enable('conn_abc123');
732
- * console.log(enabledAccount.isDisabled); // false
751
+ * console.log(enabledAccount.success); // true
733
752
  * ```
734
753
  */
735
754
  async enable(
@@ -751,13 +770,7 @@ export class ConnectedAccounts {
751
770
  * ```typescript
752
771
  * // Disable a connected account
753
772
  * const disabledAccount = await composio.connectedAccounts.disable('conn_abc123');
754
- * console.log(disabledAccount.isDisabled); // true
755
- *
756
- * // You can also use updateStatus with a reason
757
- * // const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
758
- * // enabled: false,
759
- * // reason: 'No longer needed'
760
- * // });
773
+ * console.log(disabledAccount.success); // true
761
774
  * ```
762
775
  */
763
776
  async disable(
@@ -52,16 +52,6 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';
52
52
  /** Maximum allowed length for the final prefixed slug. */
53
53
  const MAX_SLUG_LENGTH = 60;
54
54
 
55
- type InputParamsSchema = {
56
- definitions: {
57
- input: {
58
- type: string;
59
- properties: Record<string, unknown>;
60
- required?: string[];
61
- };
62
- };
63
- };
64
-
65
55
  /**
66
56
  * Compute the final slug length for a tool given its context.
67
57
  * Returns the expected length of LOCAL_[TOOLKIT_]SLUG.
@@ -43,9 +43,10 @@ export class Keyring {
43
43
  * @returns {Promise<KeyringTransferKeysResponse>} The active key ID and every accepted public JWK, newest first
44
44
  *
45
45
  * @example
46
- * ```typescript
46
+ * ```typescript nocheck="Seals with the jose library, whose types the checker does not load"
47
47
  * import { CompactEncrypt, importJWK } from 'jose';
48
48
  *
49
+ * const secret = 'my-client-secret';
49
50
  * const { activeKid, keys } = await composio.keyring.listTransferKeys();
50
51
  * const jwk = keys.find(key => key.kid === activeKid)!;
51
52
  * const sealed = await new CompactEncrypt(new TextEncoder().encode(secret))