@composio/core 0.27.0 → 0.29.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 (64) hide show
  1. package/README.md +2 -0
  2. package/dist/{CustomTool-BYHB7sPs.mjs → CustomTool-Bd1KdWvo.mjs} +9 -8
  3. package/dist/{CustomTool-CqPoLUD6.d.mts → CustomTool-CMW-d2ZN.d.mts} +10 -9
  4. package/dist/{Telemetry-41JkqpZ7.mjs → Telemetry-D2PJwXKx.mjs} +1 -1
  5. package/dist/{cancellation-ZoRh6EJQ.mjs → cancellation-BoJjs34Y.mjs} +1 -1
  6. package/dist/{composio-BUa10iB3.d.mts → composio-D5UV5HXN.d.mts} +799 -100
  7. package/dist/{customTool.types-gX421uPT.d.mts → customTool.types-B9fs34dv.d.mts} +105 -60
  8. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +1 -1
  9. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +2 -2
  10. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +86 -3
  11. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +1 -1
  12. package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +1 -1
  13. package/dist/docs/reference/sdk-reference/typescript/session.mdx +51 -13
  14. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +6 -6
  15. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +4 -4
  16. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +5 -1
  17. package/dist/{errors-Cly0vXFh.mjs → errors-BK6Xc7Ia.mjs} +65 -1
  18. package/dist/experimental/index.d.mts +3 -3
  19. package/dist/experimental/index.mjs +1 -1
  20. package/dist/{fileUtils.node-DNLhLg0W.mjs → fileUtils.node-ILI1IjnZ.mjs} +4 -3
  21. package/dist/index.d.mts +46 -16
  22. package/dist/index.mjs +2973 -2778
  23. package/dist/models/Files.node.mjs +2 -2
  24. package/dist/sensitiveFileUploadPaths-BaEORC7-.mjs +588 -0
  25. package/dist/{types-DXxfzBX3.d.mts → types-CaP2SytR.d.mts} +2 -2
  26. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  27. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  28. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  29. package/dist/utils/modifiers/FileToolModifier.node.mjs +3 -3
  30. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  31. package/package.json +7 -6
  32. package/src/errors/ToolErrors.ts +73 -1
  33. package/src/experimental/index.ts +6 -1
  34. package/src/lib/toolRouterParams.ts +68 -33
  35. package/src/lib/toolRouterSessionDelete.ts +1 -10
  36. package/src/models/ConnectedAccounts.ts +3 -3
  37. package/src/models/ConnectionRequest.ts +38 -34
  38. package/src/models/CustomTool.ts +26 -31
  39. package/src/models/CustomToolkits.ts +116 -10
  40. package/src/models/Experimental.ts +1 -1
  41. package/src/models/MCP.ts +1 -2
  42. package/src/models/SessionConfigs.ts +11 -3
  43. package/src/models/SessionContext.ts +4 -4
  44. package/src/models/ToolRouter.ts +26 -17
  45. package/src/models/ToolRouterSession.ts +39 -24
  46. package/src/models/Tools.ts +60 -14
  47. package/src/models/Triggers.ts +12 -5
  48. package/src/models/inlineCustomToolsPayload.ts +3 -3
  49. package/src/models/proxyParamsTransform.ts +1 -1
  50. package/src/types/customTool.types.ts +62 -33
  51. package/src/types/customToolkits.types.ts +91 -11
  52. package/src/types/sessionConfigs.types.ts +21 -7
  53. package/src/types/toolRouter.types.ts +53 -24
  54. package/src/types/triggers.types.ts +14 -0
  55. package/src/utils/fileUtils.node.ts +5 -2
  56. package/src/utils/mime.ts +347 -1
  57. package/src/utils/rateLimit.ts +25 -0
  58. package/src/utils/transformers/connectedAccounts.ts +2 -7
  59. package/src/utils/transformers/customToolkits.ts +79 -10
  60. package/src/utils/transformers/sessionConfigs.ts +3 -3
  61. package/src/utils/transformers/toolRouterResponseTransform.ts +23 -75
  62. package/src/utils/transformers/toolkits.ts +7 -13
  63. package/src/utils/transformers/triggers.ts +28 -18
  64. 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
+ };
@@ -0,0 +1,25 @@
1
+ import { APIError } from '@composio/client';
2
+
3
+ /** Whether a client error is the API rejecting the request with a 429. */
4
+ export function isRateLimitResponse(error: unknown): error is APIError {
5
+ return error instanceof APIError && error.status === 429;
6
+ }
7
+
8
+ /**
9
+ * Seconds a 429 asks the caller to wait, from its `Retry-After` header (seconds or an HTTP date).
10
+ * Undefined when the header is missing or unreadable.
11
+ *
12
+ * @internal
13
+ */
14
+ export function getRetryAfterSeconds(error: APIError): number | undefined {
15
+ const value = error.headers?.get('retry-after')?.trim();
16
+ if (!value) {
17
+ return undefined;
18
+ }
19
+ const seconds = Number(value);
20
+ if (Number.isFinite(seconds)) {
21
+ return seconds >= 0 ? seconds : undefined;
22
+ }
23
+ const date = Date.parse(value);
24
+ return Number.isNaN(date) ? undefined : Math.max(0, (date - Date.now()) / 1000);
25
+ }
@@ -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,27 +54,72 @@ 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
+ mcp_url: params.mcpUrl,
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 => ({
46
118
  slug: params.slug,
47
119
  toolkit_config: {
48
120
  name: params.toolkitConfig.name,
49
- 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
- },
121
+ mcp_url: params.toolkitConfig.mcpUrl,
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,