@composio/core 0.32.0 → 0.33.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 (30) hide show
  1. package/dist/{CustomTool-CBx9kzea.d.mts → CustomTool-C2kvAvzk.d.mts} +1 -1
  2. package/dist/{Telemetry-BWKZmDxM.mjs → Telemetry-CcCuFVUb.mjs} +1 -1
  3. package/dist/{composio-CPf6NHnB.d.mts → composio-BqE615oV.d.mts} +126 -95
  4. package/dist/{customTool.types-BSbIG1OG.d.mts → customTool.types-DnyEZmlx.d.mts} +312 -58
  5. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +52 -8
  6. package/dist/experimental/index.d.mts +2 -2
  7. package/dist/{fileUtils.node-BJUYMEph.mjs → fileUtils.node-DPMtE0ER.mjs} +1 -65
  8. package/dist/index.d.mts +5 -238
  9. package/dist/index.mjs +52 -23
  10. package/dist/jsonSchema-CDHLYm7d.d.mts +237 -0
  11. package/dist/{jsonSchema-BZoXGUCr.mjs → jsonSchema-CfZwBS13.mjs} +5 -1
  12. package/dist/models/Files.node.mjs +3 -3
  13. package/dist/{sensitiveFileUploadPaths-CcbMAYCC.mjs → sensitiveFileUploadPaths-6NcnFSyX.mjs} +61 -70
  14. package/dist/{types-ns3Q_WrP.d.mts → types-Cwr_Makk.d.mts} +2 -2
  15. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  16. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  17. package/dist/utils/json-schema.d.mts +2 -1
  18. package/dist/utils/json-schema.mjs +2 -1
  19. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  20. package/dist/utils/modifiers/FileToolModifier.node.mjs +3 -3
  21. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  22. package/package.json +6 -6
  23. package/src/models/ConnectedAccounts.ts +71 -11
  24. package/src/types/connectedAccounts.types.ts +59 -1
  25. package/src/types/toolRouter.types.ts +2 -1
  26. package/src/utils/fileUtils.node.ts +1 -83
  27. package/src/utils/json-schema.ts +6 -0
  28. package/src/utils/jsonSchema.ts +17 -4
  29. package/src/utils/mime.ts +25 -385
  30. package/src/utils/mimeTables.generated.ts +356 -0
@@ -1,9 +1,9 @@
1
1
  import { l as logger } from "../../SsrfErrors-BekZPeWY.mjs";
2
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";
3
+ import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-DPMtE0ER.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-BZoXGUCr.mjs";
6
- import { p as withCancellation } from "../../sensitiveFileUploadPaths-CcbMAYCC.mjs";
5
+ import { n as dereferenceJsonSchema } from "../../jsonSchema-CfZwBS13.mjs";
6
+ import { p as withCancellation } from "../../sensitiveFileUploadPaths-6NcnFSyX.mjs";
7
7
 
8
8
  // src/utils/modifiers/FileToolModifier.node.ts
9
9
  /**
@@ -1,4 +1,4 @@
1
- import { Qa as ToolExecuteParams, Ya as Tool, eo as ToolExecuteResponse } from "../../customTool.types-BSbIG1OG.mjs";
1
+ import { Za as Tool, eo as ToolExecuteParams, no as ToolExecuteResponse } from "../../customTool.types-DnyEZmlx.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  export declare class FileToolModifier {
4
4
  constructor(_client: ComposioClient);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22.22.3"
6
6
  },
7
- "version": "0.32.0",
7
+ "version": "0.33.0",
8
8
  "description": "",
9
9
  "main": "dist/index.mjs",
10
10
  "publishConfig": {
@@ -111,11 +111,11 @@
111
111
  ],
112
112
  "license": "ISC",
113
113
  "devDependencies": {
114
- "@hono/node-server": "^2.1.8",
114
+ "@hono/node-server": "^2.1.11",
115
115
  "@types/semver": "^7.8.0",
116
116
  "ajv": "^8.20.0",
117
- "fast-check": "^4.10.2",
118
- "hono": "^4.13.18",
117
+ "fast-check": "^4.11.0",
118
+ "hono": "^4.13.23",
119
119
  "mime": "^4.1.2",
120
120
  "tsdown": "^0.23.7",
121
121
  "tsx": "^4.23.15",
@@ -131,13 +131,13 @@
131
131
  "@composio/client": "2.1.36",
132
132
  "@types/json-schema": "^7.0.15",
133
133
  "is-fs-case-sensitive": "^2.0.0",
134
- "openai": "^7.55.0",
134
+ "openai": "^7.65.0",
135
135
  "picocolors": "^1.1.1",
136
136
  "pusher-js": "^8.6.0",
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.2"
140
+ "@composio/json-schema-to-zod": "0.4.3"
141
141
  },
142
142
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
143
143
  "repository": {
@@ -5,6 +5,7 @@
5
5
  * @date 2025-05-05
6
6
  * @module ConnectedAccounts
7
7
  */
8
+ import { z } from 'zod/v3';
8
9
  import ComposioClient, { BadRequestError, ConflictError } from '@composio/client';
9
10
  import type { APIPromise } from '@composio/client';
10
11
  import {
@@ -34,6 +35,8 @@ import {
34
35
  ConnectedAccountCompleteAuthParams,
35
36
  ConnectedAccountCompleteAuthParamsSchema,
36
37
  ConnectedAccountCompleteAuthResponse,
38
+ PatchConnectedAccountParams,
39
+ PatchConnectedAccountParamsSchema,
37
40
  UpdateConnectedAccountAclParams,
38
41
  UpdateConnectedAccountParams,
39
42
  UpdateConnectedAccountParamsSchema,
@@ -67,6 +70,13 @@ import { ComposioRequestOptions } from '../types/requestOptions.types';
67
70
  import { withCancellation } from '../utils/cancellation';
68
71
  import { ComposioRequestCancelledError } from '../errors/SDKErrors';
69
72
 
73
+ const UpdateRequestSchema = z.union([
74
+ PatchConnectedAccountParamsSchema.transform(body => ({ endpoint: 'patch', body }) as const),
75
+ UpdateConnectedAccountParamsSchema.strict().transform(
76
+ body => ({ endpoint: 'status', body }) as const
77
+ ),
78
+ ]);
79
+
70
80
  // One-time-per-process guard so long-running services don't spam the deprecation
71
81
  // warning on every initiate() call.
72
82
  let _legacyInitiateWarningEmitted = false;
@@ -821,34 +831,84 @@ export class ConnectedAccounts {
821
831
  }
822
832
 
823
833
  /**
824
- * Enable or disable a connected account. Accepts `{ enabled: boolean }`.
834
+ * Update a connected account's alias, credentials, or both in one request.
835
+ * The response contains the account ID, status, and success flag.
825
836
  *
826
- * Use `updateAcl()` for ACL writes on SHARED connections.
837
+ * Pass `alias`, `connection`, or both. Set `alias` to an empty string to
838
+ * clear it. To update credentials, put the fields you want to change in
839
+ * `connection.state.val`. Set a field to `null` to remove it. Omitted fields
840
+ * keep their current values.
827
841
  *
828
- * @param {string} nanoid - The unique identifier of the connected account
829
- * @param {UpdateConnectedAccountParams} params - The update parameters
830
- * @returns {Promise<ConnectedAccountUpdateStatusResponse>} The update response
842
+ * Use `enable()` or `disable()` to change the account's status. The deprecated
843
+ * `update(id, { enabled })` overload accepts only `enabled` and logs a warning.
844
+ * The SDK throws `ValidationError` before sending a request if the input is
845
+ * empty or contains unsupported fields.
846
+ *
847
+ * Use `updateAcl()` to change access to a shared connected account.
848
+ *
849
+ * @param {string} nanoid - The connected account ID.
850
+ * @param {PatchConnectedAccountParams} params - The alias or credential fields to update.
851
+ * @returns {Promise<ConnectedAccountPatchResponse>}
831
852
  *
832
853
  * @example
833
854
  * ```typescript
834
- * // Disable an account
835
- * await composio.connectedAccounts.update('ca_abc123', { enabled: false });
855
+ * // Set an alias.
856
+ * await composio.connectedAccounts.update('ca_abc123', { alias: 'work-gmail' });
857
+ *
858
+ * // Clear the alias.
859
+ * await composio.connectedAccounts.update('ca_abc123', { alias: '' });
860
+ *
861
+ * // Replace the stored bearer token.
862
+ * await composio.connectedAccounts.update('ca_abc123', {
863
+ * connection: {
864
+ * state: {
865
+ * authScheme: 'BEARER_TOKEN',
866
+ * val: { token: 'new-access-token' },
867
+ * },
868
+ * },
869
+ * });
836
870
  * ```
837
871
  */
838
872
  async update(
839
873
  nanoid: string,
840
- params: UpdateConnectedAccountParams,
874
+ params: PatchConnectedAccountParams,
841
875
  requestOptions?: ComposioRequestOptions
842
- ): Promise<ConnectedAccountUpdateStatusResponse> {
843
- const parsedParams = UpdateConnectedAccountParamsSchema.safeParse(params);
876
+ ): Promise<ConnectedAccountPatchResponse>;
877
+ /**
878
+ * @deprecated Use `enable()` or `disable()` instead.
879
+ */
880
+ async update(
881
+ nanoid: string,
882
+ params: UpdateConnectedAccountParams & { alias?: never; connection?: never },
883
+ requestOptions?: ComposioRequestOptions
884
+ ): Promise<ConnectedAccountUpdateStatusResponse>;
885
+ async update(
886
+ nanoid: string,
887
+ params:
888
+ | PatchConnectedAccountParams
889
+ | (UpdateConnectedAccountParams & { alias?: never; connection?: never }),
890
+ requestOptions?: ComposioRequestOptions
891
+ ): Promise<ConnectedAccountPatchResponse | ConnectedAccountUpdateStatusResponse> {
892
+ const parsedParams = UpdateRequestSchema.safeParse(params);
844
893
  if (!parsedParams.success) {
845
894
  throw new ValidationError('Failed to parse connected account update params', {
846
895
  cause: parsedParams.error,
847
896
  });
848
897
  }
849
898
 
899
+ const request = parsedParams.data;
900
+ if (request.endpoint === 'status') {
901
+ logger.warn(
902
+ 'connectedAccounts.update({ enabled }) is deprecated; use connectedAccounts.enable() or connectedAccounts.disable() instead.'
903
+ );
904
+ return withCancellation(
905
+ () => this.client.connectedAccounts.updateStatus(nanoid, request.body, requestOptions),
906
+ requestOptions?.signal
907
+ );
908
+ }
909
+
850
910
  return withCancellation(
851
- () => this.client.connectedAccounts.updateStatus(nanoid, parsedParams.data, requestOptions),
911
+ () => this.client.connectedAccounts.patch(nanoid, request.body, requestOptions),
852
912
  requestOptions?.signal
853
913
  );
854
914
  }
@@ -364,13 +364,71 @@ export const ConnectedAccountRefreshOptionsSchema = z.object({
364
364
  });
365
365
  export type ConnectedAccountRefreshOptions = z.infer<typeof ConnectedAccountRefreshOptionsSchema>;
366
366
 
367
- // Use the Stainless-generated type as the source of truth for update params.
368
367
  export type { ConnectedAccountUpdateStatusParams as UpdateConnectedAccountParams } from '@composio/client/resources/connected-accounts';
369
368
 
370
369
  export const UpdateConnectedAccountParamsSchema = z.object({
371
370
  enabled: z.boolean(),
372
371
  });
373
372
 
373
+ /**
374
+ * Params for `composio.connectedAccounts.update()`: a new `alias` (an empty
375
+ * string clears it), new credential fields in `connection`, or both. At
376
+ * least one of the two is required.
377
+ *
378
+ * Use `enable()` or `disable()` to change whether the account is active.
379
+ */
380
+ export type PatchConnectedAccountParams = z.infer<typeof PatchConnectedAccountParamsSchema> & {
381
+ enabled?: never;
382
+ };
383
+
384
+ const credentialField = z.string().nullable().optional();
385
+
386
+ export const PatchConnectedAccountParamsSchema = z
387
+ .object({
388
+ alias: z.string().optional(),
389
+ connection: z
390
+ .object({
391
+ state: z
392
+ .object({
393
+ authScheme: z.enum([
394
+ 'BEARER_TOKEN',
395
+ 'API_KEY',
396
+ 'BASIC',
397
+ 'BASIC_WITH_JWT',
398
+ 'GOOGLE_SERVICE_ACCOUNT',
399
+ 'SERVICE_ACCOUNT',
400
+ ]),
401
+ val: z
402
+ .object({
403
+ token: credentialField,
404
+ generic_api_key: credentialField,
405
+ api_key: credentialField,
406
+ bearer_token: credentialField,
407
+ basic_encoded: credentialField,
408
+ generic_token: credentialField,
409
+ api_key_prefix: credentialField,
410
+ generic_secret: credentialField,
411
+ generic_id: credentialField,
412
+ user_agent: credentialField,
413
+ username: credentialField,
414
+ password: credentialField,
415
+ credentials_json: credentialField,
416
+ application_id: credentialField,
417
+ installation_id: credentialField,
418
+ private_key: credentialField,
419
+ })
420
+ .strict(),
421
+ })
422
+ .strict(),
423
+ })
424
+ .strict()
425
+ .optional(),
426
+ })
427
+ .strict()
428
+ .refine(params => params.alias !== undefined || params.connection !== undefined, {
429
+ message: 'At least one of alias or connection must be provided',
430
+ });
431
+
374
432
  /**
375
433
  * Params for `composio.connectedAccounts.updateAcl()`. Mirrors the inner
376
434
  * shape of the wire's `acl_config_for_shared` block — the SDK adds the
@@ -1123,9 +1123,10 @@ export const ToolRouterUpdateManageConnectionsSchema = z
1123
1123
  .object({
1124
1124
  enable: z
1125
1125
  .boolean()
1126
+ .nullable()
1126
1127
  .optional()
1127
1128
  .describe(
1128
- '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'
1129
+ 'Whether to expose connection management tools in the session. Pass null to restore the default (true).'
1129
1130
  ),
1130
1131
  callbackUrl: z
1131
1132
  .string()
@@ -12,7 +12,7 @@ import { assertSafeFileUploadPath } from './sensitiveFileUploadPaths';
12
12
  import { assertPathInsideUploadDirs } from './uploadDirAllowlist.node';
13
13
  import { ssrfSafeFetch } from './ssrfGuard.node';
14
14
  import { readResponseBodyWithLimit } from './readResponseBody';
15
- import { getMimeTypeFromFileName } from './mime';
15
+ import { getExtensionFromMimeType, getMimeTypeFromFileName } from './mime';
16
16
 
17
17
  /**
18
18
  * Options for {@link getFileDataAfterUploadingToS3} (S3 presigned upload from local path, URL, or File).
@@ -62,88 +62,6 @@ export const isHttpUrl = (value: string): boolean => {
62
62
  }
63
63
  };
64
64
 
65
- // Helper function to get file extension from MIME type
66
- const getExtensionFromMimeType = (mimeType: string): string => {
67
- const mimeToExt: Record<string, string> = {
68
- 'text/plain': 'txt',
69
- 'text/html': 'html',
70
- 'text/css': 'css',
71
- 'text/csv': 'csv',
72
- 'text/javascript': 'js',
73
- 'application/json': 'json',
74
- 'application/xml': 'xml',
75
- 'application/pdf': 'pdf',
76
- 'application/zip': 'zip',
77
- 'application/x-zip-compressed': 'zip',
78
- 'application/gzip': 'gz',
79
- 'application/x-tar': 'tar',
80
- 'application/msword': 'doc',
81
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
82
- 'application/vnd.ms-excel': 'xls',
83
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
84
- 'application/vnd.ms-powerpoint': 'ppt',
85
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx',
86
- 'image/jpeg': 'jpg',
87
- 'image/jpg': 'jpg',
88
- 'image/png': 'png',
89
- 'image/gif': 'gif',
90
- 'image/svg+xml': 'svg',
91
- 'image/webp': 'webp',
92
- 'image/bmp': 'bmp',
93
- 'image/tiff': 'tiff',
94
- 'audio/mpeg': 'mp3',
95
- 'audio/wav': 'wav',
96
- 'audio/ogg': 'ogg',
97
- 'video/mp4': 'mp4',
98
- 'video/mpeg': 'mpeg',
99
- 'video/quicktime': 'mov',
100
- 'video/x-msvideo': 'avi',
101
- 'video/webm': 'webm',
102
- };
103
-
104
- // Clean the MIME type by removing parameters (e.g., "text/plain; charset=utf-8" -> "text/plain")
105
- const cleanMimeType = mimeType.split(';')[0].toLowerCase().trim();
106
-
107
- // Try exact match first
108
- // An own property only: `constructor` or `__proto__` must not reach Object.prototype.
109
- if (Object.hasOwn(mimeToExt, cleanMimeType)) {
110
- return mimeToExt[cleanMimeType];
111
- }
112
-
113
- // Try to extract from the MIME type (e.g., "image/png" -> "png")
114
- const parts = cleanMimeType.split('/');
115
- if (parts.length === 2) {
116
- const subtype = parts[1].toLowerCase();
117
- const cleanSubtype = subtype; // Already cleaned above
118
-
119
- // Handle structured MIME types with + (e.g., "application/vnd.api+json" -> "json")
120
- if (cleanSubtype.includes('+')) {
121
- const plusParts = cleanSubtype.split('+');
122
- const prefix = plusParts[0];
123
- const suffix = plusParts[plusParts.length - 1]; // Get the part after the last +
124
-
125
- // For specific formats, prefer the prefix (e.g., "atom+xml" -> "atom")
126
- const knownPrefixes = ['svg', 'atom', 'rss'];
127
- if (knownPrefixes.includes(prefix)) {
128
- return prefix;
129
- }
130
-
131
- // For common structured suffixes, use the suffix (e.g., "vnd.api+json" -> "json")
132
- const structuredSuffixes = ['json', 'xml', 'yaml', 'zip', 'gzip'];
133
- if (structuredSuffixes.includes(suffix)) {
134
- return suffix;
135
- }
136
-
137
- // Default to the suffix for other structured types
138
- return suffix;
139
- }
140
-
141
- return cleanSubtype || 'txt';
142
- }
143
-
144
- return 'txt'; // Default fallback
145
- };
146
-
147
65
  // Helper function to generate a filename with timestamp and random ID
148
66
  const generateTimestampedFilename = (extension: string, prefix?: string): string => {
149
67
  const basePrefix = prefix || 'file_ts';
@@ -1 +1,7 @@
1
1
  export { jsonSchemaToZodShape } from '@composio/json-schema-to-zod';
2
+ export {
3
+ dereferenceJsonSchema,
4
+ type DereferenceJsonSchemaOptions,
5
+ type UnresolvedRefReason,
6
+ type UnresolvedRefStrategy,
7
+ } from './jsonSchema';
@@ -6,6 +6,11 @@ import { isPlainObject } from './modifiers/FileToolModifier.utils.neutral';
6
6
 
7
7
  const MAX_REF_CHAIN_DEPTH = 100;
8
8
  const MAX_NODE_DEPTH = 512;
9
+ // Bounds the nodes one `dereferenceJsonSchema` call visits. Inlining copies a
10
+ // target once per `$ref` to it, so `$defs` whose entries each reference the next
11
+ // one twice expand exponentially while staying under both depth caps. The
12
+ // largest recorded Composio schemas visit about 2,600 nodes.
13
+ const MAX_DEREFERENCED_NODES = 100_000;
9
14
  // Bounds on one null-acceptance check; past either, null is not proven accepted.
10
15
  const MAX_NULL_CHECK_DEPTH = 64;
11
16
  const MAX_NULL_CHECK_NODES = 2_000;
@@ -66,9 +71,9 @@ const UNRESOLVED_REF_DESCRIPTION =
66
71
  * API-provided tool definition that emits `$ref` without a `$defs`
67
72
  * block — see https://github.com/ComposioHQ/composio/issues/3307).
68
73
  *
69
- * Safety caps (`MAX_REF_CHAIN_DEPTH`, `MAX_NODE_DEPTH`) still throw in both
70
- * modes; cycle handling (already permissive via `CYCLE_BREAK_SENTINEL`) is
71
- * unaffected.
74
+ * Safety caps (`MAX_REF_CHAIN_DEPTH`, `MAX_NODE_DEPTH`,
75
+ * `MAX_DEREFERENCED_NODES`) still throw in both modes; cycle handling (already
76
+ * permissive via `CYCLE_BREAK_SENTINEL`) is unaffected.
72
77
  */
73
78
  export type UnresolvedRefStrategy = 'throw' | 'sentinel';
74
79
 
@@ -174,7 +179,8 @@ const throwResolutionError = (
174
179
  * `$defs`; see https://github.com/ComposioHQ/composio/issues/3307).
175
180
  *
176
181
  * @throws {JsonSchemaRefResolutionError} on malformed pointers, missing
177
- * targets (strict mode only), or chains past the depth cap (both modes).
182
+ * targets (strict mode only), or chains past the depth cap or an expansion
183
+ * past the node cap (both modes).
178
184
  */
179
185
  export function dereferenceJsonSchema<T = unknown>(
180
186
  schema: T,
@@ -187,6 +193,7 @@ export function dereferenceJsonSchema<T = unknown>(
187
193
 
188
194
  const root = schema as Record<string, unknown>;
189
195
  const visiting = new WeakSet<object>();
196
+ let visited = 0;
190
197
 
191
198
  // POLLUTING_KEYS filter prevents an attacker-shaped $defs entry from altering
192
199
  // the cloned node's prototype.
@@ -215,6 +222,12 @@ export function dereferenceJsonSchema<T = unknown>(
215
222
  { possibleFixes: REF_RESOLUTION_FIXES }
216
223
  );
217
224
  }
225
+ if (++visited > MAX_DEREFERENCED_NODES) {
226
+ throw new JsonSchemaRefResolutionError(
227
+ `JSON Schema $ref expansion exceeded node cap (${MAX_DEREFERENCED_NODES})`,
228
+ { possibleFixes: REF_RESOLUTION_FIXES }
229
+ );
230
+ }
218
231
  if (Array.isArray(node)) {
219
232
  if (visiting.has(node)) return { ...CYCLE_BREAK_SENTINEL };
220
233
  visiting.add(node);