@composio/core 0.26.0 → 0.28.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 (49) hide show
  1. package/dist/{CustomTool-DfP4ldQl.d.mts → CustomTool-DyypijT6.d.mts} +2 -2
  2. package/dist/{Telemetry-41JkqpZ7.mjs → Telemetry-D2PJwXKx.mjs} +1 -1
  3. package/dist/{composio-BMDH-1Qj.d.mts → composio-CwHMpKXb.d.mts} +748 -70
  4. package/dist/{customTool.types-BoOELgJF.d.mts → customTool.types-DoItUHkO.d.mts} +780 -23
  5. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +3 -3
  6. package/dist/docs/reference/sdk-reference/typescript/session.mdx +5 -4
  7. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +5 -1
  8. package/dist/experimental/index.d.mts +2 -2
  9. package/dist/{fileUtils.node-DNLhLg0W.mjs → fileUtils.node-ILI1IjnZ.mjs} +4 -3
  10. package/dist/index.d.mts +10 -10
  11. package/dist/index.mjs +420 -158
  12. package/dist/models/Files.node.mjs +2 -2
  13. package/dist/sensitiveFileUploadPaths-BaEORC7-.mjs +588 -0
  14. package/dist/{types-DHNV_T_z.d.mts → types-DWZWePfZ.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/modifiers/FileToolModifier.node.d.mts +1 -1
  18. package/dist/utils/modifiers/FileToolModifier.node.mjs +1 -1
  19. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  20. package/package.json +7 -6
  21. package/src/lib/toolRouterParams.ts +33 -15
  22. package/src/lib/toolRouterSessionDelete.ts +1 -10
  23. package/src/models/ConnectedAccounts.ts +1 -1
  24. package/src/models/CustomTool.ts +1 -1
  25. package/src/models/CustomToolkits.ts +114 -8
  26. package/src/models/Experimental.ts +1 -1
  27. package/src/models/MCP.ts +1 -2
  28. package/src/models/SessionConfigs.ts +11 -3
  29. package/src/models/SessionContext.ts +6 -21
  30. package/src/models/ToolRouter.ts +5 -1
  31. package/src/models/ToolRouterSession.ts +21 -35
  32. package/src/models/Tools.ts +3 -3
  33. package/src/models/Triggers.ts +12 -5
  34. package/src/models/inlineCustomToolsPayload.ts +3 -3
  35. package/src/models/proxyParamsTransform.ts +1 -1
  36. package/src/types/customTool.types.ts +13 -5
  37. package/src/types/customToolkits.types.ts +89 -9
  38. package/src/types/sessionConfigs.types.ts +21 -7
  39. package/src/types/toolRouter.types.ts +169 -17
  40. package/src/types/triggers.types.ts +14 -0
  41. package/src/utils/fileUtils.node.ts +5 -2
  42. package/src/utils/mime.ts +347 -1
  43. package/src/utils/transformers/connectedAccounts.ts +2 -7
  44. package/src/utils/transformers/customToolkits.ts +78 -9
  45. package/src/utils/transformers/sessionConfigs.ts +3 -3
  46. package/src/utils/transformers/toolRouterResponseTransform.ts +71 -5
  47. package/src/utils/transformers/toolkits.ts +7 -13
  48. package/src/utils/transformers/triggers.ts +28 -18
  49. package/dist/sensitiveFileUploadPaths-BlLp-Yo2.mjs +0 -189
package/src/utils/mime.ts CHANGED
@@ -7,6 +7,7 @@ export function getExtensionFromMimeType(mimeType: string): string {
7
7
  'text/plain': 'txt',
8
8
  'text/html': 'html',
9
9
  'text/css': 'css',
10
+ 'text/csv': 'csv',
10
11
  'text/javascript': 'js',
11
12
  'application/json': 'json',
12
13
  'application/xml': 'xml',
@@ -42,7 +43,8 @@ export function getExtensionFromMimeType(mimeType: string): string {
42
43
 
43
44
  const cleanMimeType = mimeType.split(';')[0].toLowerCase().trim();
44
45
 
45
- if (mimeToExt[cleanMimeType]) {
46
+ // An own property only: `constructor` or `__proto__` must not reach Object.prototype.
47
+ if (Object.hasOwn(mimeToExt, cleanMimeType)) {
46
48
  return mimeToExt[cleanMimeType];
47
49
  }
48
50
 
@@ -73,3 +75,347 @@ export function getExtensionFromMimeType(mimeType: string): string {
73
75
 
74
76
  return 'bin';
75
77
  }
78
+
79
+ // A local file has no Content-Type of its own, so its MIME type is inferred from
80
+ // its name's extension, as the Python SDK does (`composio.utils.mimetypes.guess`).
81
+ // Tools validate the `mimetype` of an uploaded file (Canva's design import rejects
82
+ // `application/octet-stream`, issue #4984), so the generic type is a last resort.
83
+ export const DEFAULT_MIME_TYPE = 'application/octet-stream';
84
+
85
+ // Extension (lowercase, no leading dot) -> MIME type. Each value is what the
86
+ // `mime` package returns, which the CLI's `composio execute` uses for the same
87
+ // files. The Python SDK mirrors this table in `composio/utils/mimetypes.py`;
88
+ // keep the two identical.
89
+ export const MIME_TYPES_BY_EXTENSION: Readonly<Record<string, string>> = {
90
+ '3g2': 'video/3gpp2',
91
+ '3gp': 'video/3gpp',
92
+ '3gpp': 'video/3gpp',
93
+ '7z': 'application/x-7z-compressed',
94
+ aab: 'application/x-authorware-bin',
95
+ aac: 'audio/aac',
96
+ aam: 'application/x-authorware-map',
97
+ aas: 'application/x-authorware-seg',
98
+ adts: 'audio/aac',
99
+ ai: 'application/postscript',
100
+ aif: 'audio/x-aiff',
101
+ aifc: 'audio/x-aiff',
102
+ aiff: 'audio/x-aiff',
103
+ arc: 'application/x-freearc',
104
+ arj: 'application/x-arj',
105
+ asf: 'video/x-ms-asf',
106
+ asm: 'text/x-asm',
107
+ asx: 'video/x-ms-asf',
108
+ au: 'audio/basic',
109
+ avi: 'video/x-msvideo',
110
+ avif: 'image/avif',
111
+ bat: 'application/x-msdownload',
112
+ bcpio: 'application/x-bcpio',
113
+ bmp: 'image/bmp',
114
+ book: 'application/vnd.framemaker',
115
+ boz: 'application/x-bzip2',
116
+ bz: 'application/x-bzip',
117
+ bz2: 'application/x-bzip2',
118
+ c: 'text/x-c',
119
+ cat: 'application/vnd.ms-pki.seccat',
120
+ cc: 'text/x-c',
121
+ cco: 'application/x-cocoa',
122
+ cdf: 'application/x-netcdf',
123
+ cer: 'application/pkix-cert',
124
+ chat: 'application/x-chat',
125
+ class: 'application/java-vm',
126
+ com: 'application/x-msdownload',
127
+ conf: 'text/plain',
128
+ cpio: 'application/x-cpio',
129
+ cpp: 'text/x-c',
130
+ cpt: 'application/mac-compactpro',
131
+ crl: 'application/pkix-crl',
132
+ crt: 'application/x-x509-ca-cert',
133
+ csh: 'application/x-csh',
134
+ css: 'text/css',
135
+ csv: 'text/csv',
136
+ cxx: 'text/x-c',
137
+ dcr: 'application/x-director',
138
+ def: 'text/plain',
139
+ der: 'application/x-x509-ca-cert',
140
+ dir: 'application/x-director',
141
+ doc: 'application/msword',
142
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
143
+ dot: 'application/msword',
144
+ dp: 'application/vnd.osgi.dp',
145
+ dvi: 'application/x-dvi',
146
+ dwf: 'model/vnd.dwf',
147
+ dwg: 'image/vnd.dwg',
148
+ dxf: 'image/vnd.dxf',
149
+ dxr: 'application/x-director',
150
+ eml: 'message/rfc822',
151
+ eot: 'application/vnd.ms-fontobject',
152
+ eps: 'application/postscript',
153
+ epub: 'application/epub+zip',
154
+ etx: 'text/x-setext',
155
+ evy: 'application/x-envoy',
156
+ f: 'text/x-fortran',
157
+ f77: 'text/x-fortran',
158
+ f90: 'text/x-fortran',
159
+ fdf: 'application/fdf',
160
+ flac: 'audio/x-flac',
161
+ fli: 'video/x-fli',
162
+ flo: 'application/vnd.micrografx.flo',
163
+ flx: 'text/vnd.fmi.flexstor',
164
+ for: 'text/x-fortran',
165
+ fpx: 'image/vnd.fpx',
166
+ g3: 'image/g3fax',
167
+ gif: 'image/gif',
168
+ gtar: 'application/x-gtar',
169
+ gz: 'application/gzip',
170
+ h: 'text/x-c',
171
+ hdf: 'application/x-hdf',
172
+ heic: 'image/heic',
173
+ heif: 'image/heif',
174
+ hh: 'text/x-c',
175
+ hlp: 'application/winhlp',
176
+ hpgl: 'application/vnd.hp-hpgl',
177
+ hqx: 'application/mac-binhex40',
178
+ htc: 'text/x-component',
179
+ htm: 'text/html',
180
+ html: 'text/html',
181
+ ice: 'x-conference/x-cooltalk',
182
+ ico: 'image/vnd.microsoft.icon',
183
+ ics: 'text/calendar',
184
+ ief: 'image/ief',
185
+ iges: 'model/iges',
186
+ igs: 'model/iges',
187
+ jam: 'application/vnd.jam',
188
+ java: 'text/x-java-source',
189
+ jfif: 'image/pjpeg',
190
+ jpe: 'image/jpeg',
191
+ jpeg: 'image/jpeg',
192
+ jpg: 'image/jpeg',
193
+ js: 'text/javascript',
194
+ json: 'application/json',
195
+ kar: 'audio/midi',
196
+ key: 'application/vnd.apple.keynote',
197
+ latex: 'application/x-latex',
198
+ lha: 'application/x-lzh-compressed',
199
+ list: 'text/plain',
200
+ log: 'text/plain',
201
+ lzh: 'application/x-lzh-compressed',
202
+ m1v: 'video/mpeg',
203
+ m2a: 'audio/mpeg',
204
+ m2v: 'video/mpeg',
205
+ m3u: 'audio/x-mpegurl',
206
+ m3u8: 'application/vnd.apple.mpegurl',
207
+ m4a: 'audio/mp4',
208
+ man: 'text/troff',
209
+ map: 'application/json',
210
+ mcd: 'application/vnd.mcd',
211
+ md: 'text/markdown',
212
+ me: 'text/troff',
213
+ mht: 'message/rfc822',
214
+ mhtml: 'message/rfc822',
215
+ mid: 'audio/midi',
216
+ midi: 'audio/midi',
217
+ mif: 'application/vnd.mif',
218
+ mime: 'message/rfc822',
219
+ mjs: 'text/javascript',
220
+ mka: 'audio/x-matroska',
221
+ mkv: 'video/x-matroska',
222
+ mov: 'video/quicktime',
223
+ movie: 'video/x-sgi-movie',
224
+ mp2: 'audio/mpeg',
225
+ mp3: 'audio/mpeg',
226
+ mp4: 'video/mp4',
227
+ mpc: 'application/vnd.mophun.certificate',
228
+ mpe: 'video/mpeg',
229
+ mpeg: 'video/mpeg',
230
+ mpg: 'video/mpeg',
231
+ mpga: 'audio/mpeg',
232
+ mpp: 'application/dash-patch+xml',
233
+ mpt: 'application/vnd.ms-project',
234
+ mrc: 'application/marc',
235
+ ms: 'text/troff',
236
+ nc: 'application/x-netcdf',
237
+ nsc: 'application/x-conference',
238
+ numbers: 'application/vnd.apple.numbers',
239
+ obj: 'model/obj',
240
+ oda: 'application/oda',
241
+ odg: 'application/vnd.oasis.opendocument.graphics',
242
+ odp: 'application/vnd.oasis.opendocument.presentation',
243
+ ods: 'application/vnd.oasis.opendocument.spreadsheet',
244
+ odt: 'application/vnd.oasis.opendocument.text',
245
+ ogg: 'audio/ogg',
246
+ opus: 'audio/ogg',
247
+ otf: 'font/otf',
248
+ p: 'text/x-pascal',
249
+ p10: 'application/pkcs10',
250
+ p12: 'application/x-pkcs12',
251
+ p7c: 'application/pkcs7-mime',
252
+ p7m: 'application/pkcs7-mime',
253
+ p7r: 'application/x-pkcs7-certreqresp',
254
+ p7s: 'application/pkcs7-signature',
255
+ pages: 'application/vnd.apple.pages',
256
+ pas: 'text/x-pascal',
257
+ pbm: 'image/x-portable-bitmap',
258
+ pcl: 'application/vnd.hp-pcl',
259
+ pct: 'image/x-pict',
260
+ pcx: 'image/vnd.zbrush.pcx',
261
+ pdb: 'application/vnd.palm',
262
+ pdf: 'application/pdf',
263
+ pfx: 'application/x-pkcs12',
264
+ pgm: 'image/x-portable-graymap',
265
+ pic: 'image/x-pict',
266
+ pl: 'application/x-perl',
267
+ pm: 'application/x-perl',
268
+ png: 'image/png',
269
+ pnm: 'image/x-portable-anymap',
270
+ pot: 'application/vnd.ms-powerpoint',
271
+ ppm: 'image/x-portable-pixmap',
272
+ pps: 'application/vnd.ms-powerpoint',
273
+ ppt: 'application/vnd.ms-powerpoint',
274
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
275
+ pre: 'application/vnd.lotus-freelance',
276
+ ps: 'application/postscript',
277
+ psd: 'image/vnd.adobe.photoshop',
278
+ pyo: 'model/vnd.pytha.pyox',
279
+ qt: 'video/quicktime',
280
+ ra: 'audio/x-pn-realaudio',
281
+ ram: 'audio/x-pn-realaudio',
282
+ rar: 'application/vnd.rar',
283
+ ras: 'image/x-cmu-raster',
284
+ rdf: 'application/rdf+xml',
285
+ rgb: 'image/x-rgb',
286
+ rm: 'application/vnd.rn-realmedia',
287
+ rmi: 'audio/midi',
288
+ rmp: 'audio/x-pn-realaudio-plugin',
289
+ rng: 'application/xml',
290
+ roff: 'text/troff',
291
+ rpm: 'application/x-redhat-package-manager',
292
+ rtf: 'application/rtf',
293
+ rtx: 'text/richtext',
294
+ s: 'text/x-asm',
295
+ s3m: 'audio/s3m',
296
+ scm: 'application/vnd.lotus-screencam',
297
+ sdp: 'application/sdp',
298
+ sea: 'application/x-sea',
299
+ sgm: 'text/sgml',
300
+ sgml: 'text/sgml',
301
+ sh: 'application/x-sh',
302
+ shar: 'application/x-shar',
303
+ shtml: 'text/html',
304
+ sid: 'image/x-mrsid-image',
305
+ sit: 'application/x-stuffit',
306
+ skd: 'application/vnd.koan',
307
+ skm: 'application/vnd.koan',
308
+ skp: 'application/vnd.koan',
309
+ skt: 'application/vnd.koan',
310
+ smi: 'application/smil+xml',
311
+ smil: 'application/smil+xml',
312
+ snd: 'audio/basic',
313
+ spc: 'application/x-pkcs7-certificates',
314
+ spl: 'application/x-futuresplash',
315
+ src: 'application/x-wais-source',
316
+ step: 'model/step',
317
+ stl: 'model/stl',
318
+ stp: 'model/step',
319
+ sv4cpio: 'application/x-sv4cpio',
320
+ sv4crc: 'application/x-sv4crc',
321
+ svg: 'image/svg+xml',
322
+ swf: 'application/x-shockwave-flash',
323
+ t: 'text/troff',
324
+ tar: 'application/x-tar',
325
+ tcl: 'application/x-tcl',
326
+ tex: 'application/x-tex',
327
+ texi: 'application/x-texinfo',
328
+ texinfo: 'application/x-texinfo',
329
+ text: 'text/plain',
330
+ tif: 'image/tiff',
331
+ tiff: 'image/tiff',
332
+ tr: 'text/troff',
333
+ ts: 'video/mp2t',
334
+ tsv: 'text/tab-separated-values',
335
+ txt: 'text/plain',
336
+ uri: 'text/uri-list',
337
+ uris: 'text/uri-list',
338
+ ustar: 'application/x-ustar',
339
+ uu: 'text/x-uuencode',
340
+ vcd: 'application/x-cdlink',
341
+ vcf: 'text/x-vcard',
342
+ vcs: 'text/x-vcalendar',
343
+ viv: 'video/vnd.vivo',
344
+ vox: 'application/x-authorware-bin',
345
+ vrml: 'model/vrml',
346
+ vsd: 'application/vnd.visio',
347
+ vst: 'application/vnd.visio',
348
+ vsw: 'application/vnd.visio',
349
+ wasm: 'application/wasm',
350
+ wav: 'audio/wav',
351
+ wbmp: 'image/vnd.wap.wbmp',
352
+ webm: 'video/webm',
353
+ webmanifest: 'application/manifest+json',
354
+ webp: 'image/webp',
355
+ wmf: 'image/wmf',
356
+ wml: 'text/vnd.wap.wml',
357
+ wmlc: 'application/vnd.wap.wmlc',
358
+ wmls: 'text/vnd.wap.wmlscript',
359
+ wmlsc: 'application/vnd.wap.wmlscriptc',
360
+ woff: 'font/woff',
361
+ woff2: 'font/woff2',
362
+ wpd: 'application/vnd.wordperfect',
363
+ wri: 'application/x-mswrite',
364
+ wrl: 'model/vrml',
365
+ wsc: 'message/vnd.wfa.wsc',
366
+ wsdl: 'application/wsdl+xml',
367
+ xbm: 'image/x-xbitmap',
368
+ xif: 'image/vnd.xiff',
369
+ xla: 'application/vnd.ms-excel',
370
+ xlc: 'application/vnd.ms-excel',
371
+ xlm: 'application/vnd.ms-excel',
372
+ xls: 'application/vnd.ms-excel',
373
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
374
+ xlt: 'application/vnd.ms-excel',
375
+ xlw: 'application/vnd.ms-excel',
376
+ xm: 'audio/xm',
377
+ xml: 'application/xml',
378
+ xpm: 'image/x-xpixmap',
379
+ xsl: 'application/xml',
380
+ xul: 'application/vnd.mozilla.xul+xml',
381
+ xwd: 'image/x-xwindowdump',
382
+ xyz: 'chemical/x-xyz',
383
+ yaml: 'text/yaml',
384
+ yml: 'text/yaml',
385
+ zip: 'application/zip',
386
+ // Not known to the `mime` package; values from Python's standard `mimetypes`,
387
+ // except `tgz`.
388
+ '3gpp2': 'audio/3gpp2',
389
+ ass: 'audio/aac',
390
+ h5: 'application/x-hdf5',
391
+ ksh: 'text/plain',
392
+ loas: 'audio/aac',
393
+ mpa: 'video/mpeg',
394
+ nws: 'message/rfc822',
395
+ ppa: 'application/vnd.ms-powerpoint',
396
+ pwz: 'application/vnd.ms-powerpoint',
397
+ py: 'text/x-python',
398
+ pyc: 'application/x-python-code',
399
+ tgz: 'application/gzip',
400
+ wiz: 'application/msword',
401
+ xlb: 'application/vnd.ms-excel',
402
+ xpdl: 'application/xml',
403
+ };
404
+
405
+ /**
406
+ * The MIME type of a file, from its name's extension; `application/octet-stream`
407
+ * when the extension is missing or unknown. Accepts a bare name or a path.
408
+ *
409
+ * @example getMimeTypeFromFileName('/tmp/deck.pptx') // 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
410
+ */
411
+ export const getMimeTypeFromFileName = (fileName: string): string => {
412
+ const baseName = fileName.split(/[\\/]/).pop() ?? '';
413
+ const dot = baseName.lastIndexOf('.');
414
+ // A leading dot is a hidden file's name (`.env`), not an extension.
415
+ if (dot <= 0) return DEFAULT_MIME_TYPE;
416
+ const extension = baseName.slice(dot + 1).toLowerCase();
417
+ // An own property only: `report.constructor` must not reach Object.prototype.
418
+ return Object.hasOwn(MIME_TYPES_BY_EXTENSION, extension)
419
+ ? MIME_TYPES_BY_EXTENSION[extension]
420
+ : DEFAULT_MIME_TYPE;
421
+ };
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  ConnectedAccountListResponse as RawConnectedAccountListResponse,
3
3
  ConnectedAccountRetrieveResponse as RawConnectedAccountRetrieveResponse,
4
- type ConnectedAccounts as ClientConnectedAccounts,
4
+ type ConnectedAccountCompleteAuthResponse as RawConnectedAccountCompleteAuthResponse,
5
+ type ConnectedAccountRevokeResponse as RawConnectedAccountRevokeResponse,
5
6
  } from '@composio/client/resources/connected-accounts';
6
7
  import {
7
8
  ConnectedAccountListResponse,
@@ -13,12 +14,6 @@ import {
13
14
  ConnectedAccountCompleteAuthResponse,
14
15
  ConnectedAccountCompleteAuthResponseSchema,
15
16
  } from '../../types/connectedAccounts.types';
16
-
17
- // The revoke and complete-auth response types are only reachable through the
18
- // resource class namespace on the published subpath.
19
- type RawConnectedAccountRevokeResponse = ClientConnectedAccounts.ConnectedAccountRevokeResponse;
20
- type RawConnectedAccountCompleteAuthResponse =
21
- ClientConnectedAccounts.ConnectedAccountCompleteAuthResponse;
22
17
  import { ConnectionDataSchema } from '../../types/connectedAccountAuthStates.types';
23
18
  import logger from '../logger';
24
19
  import { transform } from '../transform';
@@ -1,24 +1,48 @@
1
1
  import type {
2
+ CustomCreateToolkitParams as RawCustomCreateToolkitParams,
3
+ CustomCreateToolkitResponse as RawCustomCreateToolkitResponse,
2
4
  CustomDeleteToolkitResponse as RawCustomDeleteToolkitResponse,
3
5
  CustomSyncParams as RawCustomSyncParams,
4
6
  CustomSyncResponse as RawCustomSyncResponse,
7
+ CustomUpdateToolkitsParams as RawCustomUpdateToolkitsParams,
8
+ CustomUpdateToolkitsResponse as RawCustomUpdateToolkitsResponse,
5
9
  CustomUpsertParams as RawCustomUpsertParams,
6
10
  CustomUpsertResponse as RawCustomUpsertResponse,
7
11
  } from '@composio/client/resources/custom';
8
12
  import {
13
+ CustomToolkitApiKeyField,
9
14
  CustomToolkitAuthScheme,
15
+ CustomToolkitCreateParams,
16
+ CustomToolkitCreateResponse,
17
+ CustomToolkitCreateResponseSchema,
10
18
  CustomToolkitDeleteResponse,
11
19
  CustomToolkitDeleteResponseSchema,
20
+ CustomToolkitLogoFile,
12
21
  CustomToolkitSyncParams,
13
22
  CustomToolkitSyncResponse,
14
23
  CustomToolkitSyncResponseSchema,
24
+ CustomToolkitUpdateParams,
25
+ CustomToolkitUpdateResponse,
26
+ CustomToolkitUpdateResponseSchema,
15
27
  CustomToolkitUpsertParams,
16
28
  CustomToolkitUpsertResponse,
17
29
  CustomToolkitUpsertResponseSchema,
18
30
  } from '../../types/customToolkits.types';
19
31
  import { transform } from '../transform';
20
32
 
21
- type RawCustomToolkitAuthScheme = RawCustomUpsertParams['toolkit_config']['auth_schemes'][number];
33
+ type RawCustomToolkitAuthScheme = RawCustomCreateToolkitParams['auth_schemes'][number];
34
+ type RawCustomToolkitLogoFile = NonNullable<RawCustomCreateToolkitParams['logo_file']>;
35
+
36
+ const transformCustomToolkitLogoFile = (
37
+ logoFile: CustomToolkitLogoFile | undefined
38
+ ): RawCustomToolkitLogoFile | undefined =>
39
+ logoFile && { content: logoFile.content, mime_type: logoFile.mimeType };
40
+
41
+ const transformCustomToolkitApiKeyField = (apiKeyField: CustomToolkitApiKeyField | undefined) =>
42
+ apiKeyField && {
43
+ display_name: apiKeyField.displayName,
44
+ description: apiKeyField.description,
45
+ };
22
46
 
23
47
  const transformCustomToolkitAuthScheme = (
24
48
  scheme: CustomToolkitAuthScheme
@@ -30,16 +54,64 @@ const transformCustomToolkitAuthScheme = (
30
54
  return {
31
55
  mode: 'API_KEY',
32
56
  headers: scheme.headers,
33
- api_key_field: scheme.apiKeyField && {
34
- display_name: scheme.apiKeyField.displayName,
35
- description: scheme.apiKeyField.description,
36
- },
57
+ api_key_field: transformCustomToolkitApiKeyField(scheme.apiKeyField),
58
+ ...(scheme.additionalFields && {
59
+ additional_fields: {
60
+ generic_id: {
61
+ display_name: scheme.additionalFields.genericId.displayName,
62
+ description: scheme.additionalFields.genericId.description,
63
+ },
64
+ },
65
+ }),
37
66
  };
38
67
  case 'DCR_OAUTH':
39
68
  return { mode: 'DCR_OAUTH', discovery_url: scheme.discoveryUrl };
40
69
  }
41
70
  };
42
71
 
72
+ export const transformCustomToolkitCreateParams = (
73
+ params: CustomToolkitCreateParams
74
+ ): RawCustomCreateToolkitParams => ({
75
+ name: params.name,
76
+ app_url: params.appUrl,
77
+ logo_file: transformCustomToolkitLogoFile(params.logoFile),
78
+ auth_schemes: params.authSchemes.map(transformCustomToolkitAuthScheme),
79
+ user_id: params.userId,
80
+ callback_url: params.callbackUrl,
81
+ });
82
+
83
+ export const transformCustomToolkitCreateResponse = (
84
+ response: RawCustomCreateToolkitResponse
85
+ ): CustomToolkitCreateResponse => {
86
+ return transform(response)
87
+ .with(CustomToolkitCreateResponseSchema)
88
+ .using(response => ({
89
+ slug: response.slug,
90
+ connectLink: response.connect_link && {
91
+ redirectUrl: response.connect_link.redirect_url,
92
+ expiresAt: response.connect_link.expires_at,
93
+ connectedAccountId: response.connect_link.connected_account_id,
94
+ },
95
+ }));
96
+ };
97
+
98
+ export const transformCustomToolkitUpdateParams = (
99
+ params: CustomToolkitUpdateParams
100
+ ): RawCustomUpdateToolkitsParams => ({
101
+ name: params.name,
102
+ logo_file: transformCustomToolkitLogoFile(params.logoFile),
103
+ api_key_field: transformCustomToolkitApiKeyField(params.apiKeyField),
104
+ user_id: params.userId,
105
+ });
106
+
107
+ export const transformCustomToolkitUpdateResponse = (
108
+ response: RawCustomUpdateToolkitsResponse
109
+ ): CustomToolkitUpdateResponse => {
110
+ return transform(response)
111
+ .with(CustomToolkitUpdateResponseSchema)
112
+ .using(response => ({ success: response.success }));
113
+ };
114
+
43
115
  export const transformCustomToolkitUpsertParams = (
44
116
  params: CustomToolkitUpsertParams
45
117
  ): RawCustomUpsertParams => ({
@@ -47,10 +119,7 @@ export const transformCustomToolkitUpsertParams = (
47
119
  toolkit_config: {
48
120
  name: params.toolkitConfig.name,
49
121
  app_url: params.toolkitConfig.appUrl,
50
- logo_file: params.toolkitConfig.logoFile && {
51
- content: params.toolkitConfig.logoFile.content,
52
- mime_type: params.toolkitConfig.logoFile.mimeType,
53
- },
122
+ logo_file: transformCustomToolkitLogoFile(params.toolkitConfig.logoFile),
54
123
  auth_schemes: params.toolkitConfig.authSchemes.map(transformCustomToolkitAuthScheme),
55
124
  },
56
125
  });
@@ -13,7 +13,7 @@ import {
13
13
  import { transform } from '../transform';
14
14
 
15
15
  export const transformSessionConfigSummary = (
16
- response: RawSessionConfigListResponse.Item
16
+ response: RawSessionConfigListResponse['items'][number]
17
17
  ): SessionConfigSummary => {
18
18
  return transform(response)
19
19
  .with(SessionConfigSummarySchema)
@@ -45,8 +45,8 @@ export const transformSessionConfig = (response: RawSessionConfig): SessionConfi
45
45
  name: response.name,
46
46
  description: response.description,
47
47
  archived: response.archived,
48
- // The policy has no snake_case keys: copy it as-is so toolkit slugs
49
- // and tag names survive.
48
+ // The policy keeps the backend's wire shape: copy it as-is so toolkit
49
+ // slugs and tag names survive.
50
50
  config: response.config,
51
51
  createdAt: response.created_at,
52
52
  updatedAt: response.updated_at,
@@ -4,14 +4,28 @@
4
4
  import type {
5
5
  SessionExecuteResponse,
6
6
  SessionProxyExecuteResponse,
7
- } from '@composio/client/resources/tool-router/session/session.mjs';
7
+ } from '@composio/client/resources/tool-router/session';
8
8
  import z from 'zod/v3';
9
9
  import { ComposioToolInputRequiredError } from '../../errors/ToolRouterErrors';
10
10
  import { ValidationError } from '../../errors/ValidationErrors';
11
- import type { ToolRouterSessionExecuteResponse } from '../../types/toolRouter.types';
11
+ import type {
12
+ ToolRouterBlockReason,
13
+ ToolRouterSessionExecuteResponse,
14
+ ToolRouterSessionProxyExecuteResponse,
15
+ } from '../../types/toolRouter.types';
16
+
17
+ /**
18
+ * The `result_type` values of a call that ran. `input_required` and `blocked`
19
+ * are handled before this is read.
20
+ */
21
+ const ExecutedResponseSchema = z.object({
22
+ result_type: z.enum(['completed', 'failed']),
23
+ });
12
24
 
13
- /** The `result_type` values of a call that ran. `input_required` is raised before this is read. */
14
- const ExecutedResponseSchema = z.object({ result_type: z.enum(['completed', 'failed']) });
25
+ /** The `reason` of a call a session hook blocked, in camelCase. */
26
+ const toBlockReason = (
27
+ reason: Extract<SessionExecuteResponse, { result_type: 'blocked' }>['reason']
28
+ ): ToolRouterBlockReason => ({ type: reason.type, hookId: reason.hook_id });
15
29
 
16
30
  /**
17
31
  * Whether a session tool execution succeeded. `resultType` decides: a `failed`
@@ -210,8 +224,24 @@ export function transformSearchResponse(raw: RawSearchResponse) {
210
224
  * @throws {ComposioToolInputRequiredError} If the tool asked for user input instead of running
211
225
  * @throws {ValidationError} If the response carries no `result_type`, or one this SDK does not know
212
226
  */
213
- export function transformExecuteResponse(raw: SessionExecuteResponse, toolSlug: string) {
227
+ export function transformExecuteResponse(
228
+ raw: SessionExecuteResponse,
229
+ toolSlug: string
230
+ ): ToolRouterSessionExecuteResponse {
214
231
  assertNotInputRequired(raw, `Tool ${toolSlug}`);
232
+ if (raw.result_type === 'blocked') {
233
+ // The agent reads `error`, so a blocked call reaches it as a failed call
234
+ // with the hook's message.
235
+ return {
236
+ data: {},
237
+ error: raw.message,
238
+ logId: raw.log_id ?? '',
239
+ resultType: 'blocked',
240
+ blockReason: toBlockReason(raw.reason),
241
+ ...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
242
+ ...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
243
+ };
244
+ }
215
245
  const executed = ExecutedResponseSchema.safeParse(raw);
216
246
  if (!executed.success) {
217
247
  throw new ValidationError(
@@ -225,5 +255,41 @@ export function transformExecuteResponse(raw: SessionExecuteResponse, toolSlug:
225
255
  logId: raw.log_id,
226
256
  resultType: executed.data.result_type,
227
257
  ...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
258
+ ...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
259
+ };
260
+ }
261
+
262
+ /**
263
+ * Projects a session proxy execute response onto the SDK's shape: a request a
264
+ * session hook blocked comes back as `resultType: 'blocked'` with no HTTP
265
+ * response.
266
+ */
267
+ export function transformProxyExecuteResponse(
268
+ raw: SessionProxyExecuteResponse,
269
+ subject: string
270
+ ): ToolRouterSessionProxyExecuteResponse {
271
+ assertNotInputRequired(raw, subject);
272
+ if (raw.result_type === 'blocked') {
273
+ return {
274
+ resultType: 'blocked',
275
+ blockReason: toBlockReason(raw.reason),
276
+ message: raw.message,
277
+ ...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
278
+ };
279
+ }
280
+ return {
281
+ resultType: 'completed',
282
+ status: raw.status,
283
+ data: raw.data,
284
+ headers: raw.headers,
285
+ ...(raw.binary_data && {
286
+ binaryData: {
287
+ contentType: raw.binary_data.content_type,
288
+ size: raw.binary_data.size,
289
+ url: raw.binary_data.url,
290
+ expiresAt: raw.binary_data.expires_at,
291
+ },
292
+ }),
293
+ ...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
228
294
  };
229
295
  }
@@ -2,19 +2,13 @@ import {
2
2
  ToolkitRetrieveResponse as RawToolkitRetrieveResponse,
3
3
  ToolkitListResponse as RawToolkitListResponse,
4
4
  ToolkitRetrieveCategoriesResponse as RawToolkitRetrieveCategoriesResponse,
5
- type Toolkits as ClientToolkits,
5
+ type ToolkitRetrieveChangelogResponse as RawToolkitRetrieveChangelogResponse,
6
+ type ToolkitRetrieveMultiResponse as RawToolkitRetrieveMultiResponse,
7
+ type ToolkitRecommendScopesParams as RawToolkitRecommendScopesParams,
8
+ type ToolkitRecommendScopesResponse as RawToolkitRecommendScopesResponse,
9
+ type ToolkitRetrieveScopesGrantContextParams as RawToolkitRetrieveScopesGrantContextParams,
10
+ type ToolkitRetrieveScopesGrantContextResponse as RawToolkitRetrieveScopesGrantContextResponse,
6
11
  } from '@composio/client/resources/toolkits';
7
-
8
- // The `/toolkits/multi` and `/toolkits/changelog` response types are only
9
- // reachable through the resource class namespace on the published subpath.
10
- type RawToolkitRetrieveChangelogResponse = ClientToolkits.ToolkitRetrieveChangelogResponse;
11
- type RawToolkitRetrieveMultiResponse = ClientToolkits.ToolkitRetrieveMultiResponse;
12
- type RawToolkitRecommendScopesParams = ClientToolkits.ToolkitRecommendScopesParams;
13
- type RawToolkitRecommendScopesResponse = ClientToolkits.ToolkitRecommendScopesResponse;
14
- type RawToolkitRetrieveScopesGrantContextParams =
15
- ClientToolkits.ToolkitRetrieveScopesGrantContextParams;
16
- type RawToolkitRetrieveScopesGrantContextResponse =
17
- ClientToolkits.ToolkitRetrieveScopesGrantContextResponse;
18
12
  import {
19
13
  ToolKitListResponse,
20
14
  ToolKitListResponseSchema,
@@ -158,7 +152,7 @@ export const transformToolkitRetrieveResponse = (
158
152
  name: category.name,
159
153
  })),
160
154
  availableVersions: response.meta.available_versions,
161
- // appUrl: response.meta.app_url, @TODO Update the client type to include this
155
+ ...(response.meta.app_url != null && { appUrl: response.meta.app_url }),
162
156
  },
163
157
  isLocalToolkit: response.is_local_toolkit,
164
158
  composioManagedAuthSchemes: response.composio_managed_auth_schemes,