@composio/core 0.18.1 → 1.0.0-beta.1

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 (69) hide show
  1. package/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-CM-roKk7.mjs} +1 -1
  2. package/dist/{CustomTool-VRfWzMix.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
  4. package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
  5. package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-DiQldIdC.mjs} +32 -17
  6. package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
  7. package/dist/{cancellation-P5YUlcfz.mjs → cancellation-BEpFk2S8.mjs} +7 -5
  8. package/dist/{composio-Cb3d1jFe.d.mts → composio-BVNJTVYa.d.mts} +2449 -118
  9. package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-CY5SXFfF.d.mts} +118 -5
  10. package/dist/{errors-Ue9wMrPK.mjs → errors-CvZjP9CH.mjs} +39 -4
  11. package/dist/experimental/index.d.mts +2 -2
  12. package/dist/experimental/index.mjs +1 -1
  13. package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-HQsywtTj.mjs} +8 -6
  14. package/dist/index.d.mts +292 -140
  15. package/dist/index.mjs +1914 -160
  16. package/dist/models/Files.node.d.mts +2 -3
  17. package/dist/models/Files.node.mjs +2 -2
  18. package/dist/models/Files.workerd.d.mts +2 -3
  19. package/dist/platform/node.d.mts +2 -3
  20. package/dist/platform/workerd.d.mts +2 -3
  21. package/dist/{sensitiveFileUploadPaths-QN7w4n8v.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
  22. package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-BK50mYTq.mjs} +94 -8
  23. package/dist/{types-CGdgK442.d.mts → types-CqGfjlZg.d.mts} +2 -2
  24. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
  25. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
  26. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
  27. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
  28. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
  29. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  30. package/dist/utils/ssrfGuard.node.d.mts +7 -7
  31. package/dist/utils/ssrfGuard.node.mjs +1 -1
  32. package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
  33. package/dist/utils/ssrfGuard.workerd.mjs +1 -1
  34. package/package.json +7 -7
  35. package/src/composio.ts +86 -2
  36. package/src/errors/ConnectedAccountsErrors.ts +47 -0
  37. package/src/index.ts +15 -0
  38. package/src/models/ConnectedAccounts.ts +118 -2
  39. package/src/models/CustomToolkits.ts +169 -0
  40. package/src/models/Experimental.ts +27 -0
  41. package/src/models/Keyring.ts +65 -0
  42. package/src/models/Logs.ts +101 -0
  43. package/src/models/ToolRouterSession.ts +51 -0
  44. package/src/models/Toolkits.ts +180 -0
  45. package/src/models/Tools.ts +3 -1
  46. package/src/models/Triggers.ts +2 -87
  47. package/src/models/Usage.ts +119 -0
  48. package/src/models/Webhooks.ts +520 -0
  49. package/src/types/authConfigs.types.ts +2 -0
  50. package/src/types/connectedAccounts.types.ts +54 -0
  51. package/src/types/customToolkits.types.ts +102 -0
  52. package/src/types/keyring.types.ts +32 -0
  53. package/src/types/logs.types.ts +108 -0
  54. package/src/types/toolRouter.types.ts +49 -1
  55. package/src/types/toolkit.types.ts +131 -0
  56. package/src/types/usage.types.ts +81 -0
  57. package/src/types/webhooks.types.ts +143 -0
  58. package/src/utils/constants.ts +1 -5
  59. package/src/utils/jsonSchema.ts +4 -1
  60. package/src/utils/logger.ts +39 -7
  61. package/src/utils/ssrfGuard.node.ts +98 -7
  62. package/src/utils/transformers/connectedAccounts.ts +37 -2
  63. package/src/utils/transformers/customToolkits.ts +98 -0
  64. package/src/utils/transformers/keyring.ts +24 -0
  65. package/src/utils/transformers/logs.ts +85 -0
  66. package/src/utils/transformers/toolkits.ts +100 -1
  67. package/src/utils/transformers/triggers.ts +2 -2
  68. package/src/utils/transformers/usage.ts +77 -0
  69. package/src/utils/transformers/webhooks.ts +139 -0
@@ -23,20 +23,52 @@ export const getLogLevel = (): LogLevel => {
23
23
  return envLevel && envLevel in LOG_LEVELS ? (envLevel as LogLevel) : 'info';
24
24
  };
25
25
 
26
+ /**
27
+ * Destination for SDK log output. Each method receives the already
28
+ * formatted and redacted message as its single argument. `console` satisfies
29
+ * this interface, and so do most structured loggers (pino, winston, ...).
30
+ */
31
+ export interface ComposioLogger {
32
+ error: (...args: unknown[]) => void;
33
+ warn: (...args: unknown[]) => void;
34
+ info: (...args: unknown[]) => void;
35
+ debug: (...args: unknown[]) => void;
36
+ }
37
+
26
38
  interface LoggerOptions {
27
39
  level?: LogLevel;
28
40
  includeTimestamp?: boolean;
41
+ /** Where formatted output is written. Defaults to `console`. */
42
+ sink?: ComposioLogger;
43
+ }
44
+
45
+ export interface LoggerConfigureOptions {
46
+ level?: LogLevel;
47
+ sink?: ComposioLogger;
29
48
  }
30
49
 
31
50
  export class Logger {
32
- private readonly level: LogLevel;
51
+ private level: LogLevel;
33
52
  private readonly includeTimestamp: boolean;
34
- private readonly console: Console;
53
+ private sink: ComposioLogger;
35
54
 
36
55
  constructor(options: LoggerOptions = {}) {
37
56
  this.level = options.level ?? getLogLevel();
38
57
  this.includeTimestamp = options.includeTimestamp ?? true;
39
- this.console = console;
58
+ this.sink = options.sink ?? console;
59
+ }
60
+
61
+ /**
62
+ * Reconfigure the level and/or sink in place. Omitted fields are left
63
+ * unchanged, so `configure({ level: 'debug' })` keeps the current sink.
64
+ */
65
+ configure(options: LoggerConfigureOptions): void {
66
+ if (options.level !== undefined) this.level = options.level;
67
+ if (options.sink !== undefined) this.sink = options.sink;
68
+ }
69
+
70
+ getLevel(): LogLevel {
71
+ return this.level;
40
72
  }
41
73
 
42
74
  private formatMessage(args: unknown[]): string {
@@ -71,25 +103,25 @@ export class Logger {
71
103
 
72
104
  error(...args: unknown[]): void {
73
105
  if (this.shouldLog('error')) {
74
- this.console.error(this.formatMessage(args));
106
+ this.sink.error(this.formatMessage(args));
75
107
  }
76
108
  }
77
109
 
78
110
  warn(...args: unknown[]): void {
79
111
  if (this.shouldLog('warn')) {
80
- this.console.warn(this.formatMessage(args));
112
+ this.sink.warn(this.formatMessage(args));
81
113
  }
82
114
  }
83
115
 
84
116
  info(...args: unknown[]): void {
85
117
  if (this.shouldLog('info')) {
86
- this.console.info(this.formatMessage(args));
118
+ this.sink.info(this.formatMessage(args));
87
119
  }
88
120
  }
89
121
 
90
122
  debug(...args: unknown[]): void {
91
123
  if (this.shouldLog('debug')) {
92
- this.console.debug(this.formatMessage(args));
124
+ this.sink.debug(this.formatMessage(args));
93
125
  }
94
126
  }
95
127
  }
@@ -40,6 +40,74 @@ import {
40
40
 
41
41
  const MAX_REDIRECTS = 5;
42
42
 
43
+ /**
44
+ * The Fetch standard's "redirect status" set. A 3xx outside it is not a
45
+ * redirect to follow even when it carries a `location` — `304 Not Modified`
46
+ * and `305 Use Proxy` most of all, and following those would replay the
47
+ * request against a target the caller never asked for. The Python guard
48
+ * follows the same set (`_REDIRECT_STATUS_CODES`).
49
+ */
50
+ const REDIRECT_STATUS_CODES = new Set([301, 302, 303, 307, 308]);
51
+
52
+ /**
53
+ * Headers that describe a request body, so they have to go when the body does:
54
+ * the Fetch standard's "request-body-header name" set, plus the two the Python
55
+ * guard also drops because `requests` recomputes them from the body it sends.
56
+ */
57
+ const BODY_HEADERS = [
58
+ 'content-encoding',
59
+ 'content-language',
60
+ 'content-length',
61
+ 'content-location',
62
+ 'content-type',
63
+ 'transfer-encoding',
64
+ ];
65
+
66
+ /**
67
+ * The method the hop after a redirect uses, or `null` to replay as-is. A
68
+ * returned method also means the request body goes.
69
+ *
70
+ * These are the Fetch standard's redirect rules, which following redirects by
71
+ * hand (`redirect: 'manual'`) means `fetch` never applies for us: `303` points
72
+ * at a result URL that has no use for the original body, so every method loses
73
+ * it and everything but `HEAD` becomes a `GET`; `301`/`302` do the same to a
74
+ * `POST` only; `307`/`308` replay both. Without this, a `303` answering an
75
+ * upload would PUT the payload again at a URL that expects a GET. The Python
76
+ * guard applies the same rules in `safe_request`.
77
+ */
78
+ const redirectRewrite = (status: number, method: string): string | null => {
79
+ if (status === 303) return method === 'HEAD' ? 'HEAD' : 'GET';
80
+ if ((status === 301 || status === 302) && method === 'POST') return 'GET';
81
+ return null;
82
+ };
83
+
84
+ /**
85
+ * Headers that carry a credential for the origin the request was addressed
86
+ * to, so they must not follow a redirect to a different origin. The Fetch
87
+ * standard strips `Authorization` on a cross-origin redirect; `Cookie` and
88
+ * `Proxy-Authorization` go with it the way `requests` and curl drop them on a
89
+ * host change. `redirect: 'manual'` means `fetch` never applies that rule for
90
+ * us either. The Python guard drops the same three (`_CREDENTIAL_HEADERS`).
91
+ */
92
+ const CREDENTIAL_HEADERS = ['authorization', 'cookie', 'proxy-authorization'];
93
+
94
+ const applyRedirectSemantics = (
95
+ init: RequestInit,
96
+ status: number,
97
+ fromUrl: string,
98
+ toUrl: string
99
+ ): RequestInit => {
100
+ const method = redirectRewrite(status, (init.method ?? 'GET').toUpperCase());
101
+ const crossOrigin = new URL(fromUrl).origin !== new URL(toUrl).origin;
102
+ if (method === null && !crossOrigin) return init;
103
+
104
+ const headers = new Headers(init.headers);
105
+ if (method !== null) for (const name of BODY_HEADERS) headers.delete(name);
106
+ if (crossOrigin) for (const name of CREDENTIAL_HEADERS) headers.delete(name);
107
+ if (method === null) return { ...init, headers };
108
+ return { ...init, method, body: undefined, headers };
109
+ };
110
+
43
111
  /**
44
112
  * Whether the runtime would route `url` through an env proxy the SDK cannot
45
113
  * see into. Bun honors proxy environment variables automatically. Node's
@@ -77,6 +145,7 @@ const IPV4_BLOCKED_CIDRS: ReadonlyArray<readonly [string, number]> = [
77
145
  ['172.16.0.0', 12], // private
78
146
  ['192.0.0.0', 24], // IETF protocol assignments
79
147
  ['192.0.2.0', 24], // TEST-NET-1
148
+ ['192.88.99.0', 24], // 6to4 relay anycast (deprecated, RFC 7526)
80
149
  ['192.168.0.0', 16], // private
81
150
  ['198.18.0.0', 15], // benchmarking
82
151
  ['198.51.100.0', 24], // TEST-NET-2
@@ -146,8 +215,20 @@ const isBlockedIpv6 = (ip: string): boolean => {
146
215
  return isBlockedIpv4Long((((h[6] << 16) >>> 0) | h[7]) >>> 0);
147
216
  }
148
217
 
218
+ // Transition and tunnel ranges. Each one either carries an arbitrary IPv4
219
+ // address in its low bits or is reserved, so a public-looking literal here
220
+ // can still name internal space: `2002:7f00:1::` is 6to4 for `127.0.0.1`.
221
+ // Blocking the whole range rather than decoding it matches the Python guard,
222
+ // where `ipaddress.is_global` already rejects all of them.
223
+ if (h[0] === 0x2001 && (h[1] & 0xfe00) === 0) return true; // IETF protocol assignments 2001::/23 (incl. Teredo)
224
+ if (h[0] === 0x2001 && h[1] === 0x0db8) return true; // documentation 2001:db8::/32
225
+ if (h[0] === 0x2002) return true; // 6to4 2002::/16
226
+ if (h[0] === 0x0064 && h[1] === 0xff9b && h[2] === 0x0001) return true; // local-use NAT64 64:ff9b:1::/48
227
+ if (h[0] === 0x0100 && h[1] === 0 && h[2] === 0 && h[3] === 0) return true; // discard-only 100::/64
228
+
149
229
  if ((h[0] & 0xfe00) === 0xfc00) return true; // unique local fc00::/7
150
230
  if ((h[0] & 0xffc0) === 0xfe80) return true; // link-local fe80::/10
231
+ if ((h[0] & 0xffc0) === 0xfec0) return true; // site-local fec0::/10 (deprecated)
151
232
  if ((h[0] & 0xff00) === 0xff00) return true; // multicast ff00::/8
152
233
 
153
234
  return false;
@@ -221,7 +302,8 @@ export const assertSafeFetchTarget = async (rawUrl: string): Promise<string[]> =
221
302
  * connects to the address it validated, and re-validates and re-pins every
222
303
  * redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
223
304
  * Intermediate redirect bodies are cancelled; non-redirect responses are
224
- * returned unchanged.
305
+ * returned unchanged. Each hop carries the method, body, and credential headers
306
+ * the Fetch standard says it should — see {@link applyRedirectSemantics}.
225
307
  *
226
308
  * A hop whose effective dispatcher is a configured route (caller-supplied
227
309
  * `init.dispatcher`, non-stock global dispatcher, env-proxy mode) is *not*
@@ -233,6 +315,9 @@ export const ssrfSafeFetch = async (
233
315
  maxRedirects: number = MAX_REDIRECTS
234
316
  ): Promise<Response> => {
235
317
  let currentUrl = rawUrl;
318
+ // Rebound per hop: a redirect can drop the method and body (see
319
+ // `applyRedirectSemantics`), and the following hops must send what is left.
320
+ let currentInit = init;
236
321
 
237
322
  for (let hop = 0; hop <= maxRedirects; hop++) {
238
323
  const addresses = await assertSafeFetchTarget(currentUrl);
@@ -241,7 +326,7 @@ export const ssrfSafeFetch = async (
241
326
  // Pinning replaces the connect target; through a configured route that
242
327
  // would dial the validated origin instead of the route's next hop (the
243
328
  // proxy), so those hops keep the pre-flight check only.
244
- const callerDispatcher = (init as RequestInit & { dispatcher?: unknown }).dispatcher;
329
+ const callerDispatcher = (currentInit as RequestInit & { dispatcher?: unknown }).dispatcher;
245
330
  const respectConfiguredRoute =
246
331
  callerDispatcher !== undefined ||
247
332
  envProxyApplies(new URL(currentUrl), isBun) ||
@@ -253,14 +338,18 @@ export const ssrfSafeFetch = async (
253
338
  let response: Response;
254
339
  try {
255
340
  if (isBun && !respectConfiguredRoute) {
256
- response = await pinnedHttpFetch(currentUrl, { ...init, redirect: 'manual' }, addresses);
341
+ response = await pinnedHttpFetch(
342
+ currentUrl,
343
+ { ...currentInit, redirect: 'manual' },
344
+ addresses
345
+ );
257
346
  } else {
258
347
  // `dispatcher` is a Node-only extension to `RequestInit`.
259
348
  response = await fetch(
260
349
  currentUrl,
261
350
  (dispatcher === undefined
262
- ? { ...init, redirect: 'manual' }
263
- : { ...init, redirect: 'manual', dispatcher }) as RequestInit
351
+ ? { ...currentInit, redirect: 'manual' }
352
+ : { ...currentInit, redirect: 'manual', dispatcher }) as RequestInit
264
353
  );
265
354
  }
266
355
  } catch (error) {
@@ -277,7 +366,7 @@ export const ssrfSafeFetch = async (
277
366
  }
278
367
 
279
368
  const isRedirect =
280
- response.status >= 300 && response.status < 400 && response.headers.has('location');
369
+ REDIRECT_STATUS_CODES.has(response.status) && response.headers.has('location');
281
370
  if (!isRedirect) {
282
371
  return response;
283
372
  }
@@ -286,7 +375,9 @@ export const ssrfSafeFetch = async (
286
375
  // than leaving it to the garbage collector (mirrors `readResponseBodyWithLimit`).
287
376
  await response.body?.cancel().catch(() => undefined);
288
377
 
289
- currentUrl = new URL(response.headers.get('location')!, currentUrl).toString();
378
+ const nextUrl = new URL(response.headers.get('location')!, currentUrl).toString();
379
+ currentInit = applyRedirectSemantics(currentInit, response.status, currentUrl, nextUrl);
380
+ currentUrl = nextUrl;
290
381
  }
291
382
 
292
383
  throw new ComposioBlockedInternalUrlError(
@@ -1,20 +1,30 @@
1
1
  import {
2
2
  ConnectedAccountListResponse as RawConnectedAccountListResponse,
3
3
  ConnectedAccountRetrieveResponse as RawConnectedAccountRetrieveResponse,
4
+ type ConnectedAccounts as ClientConnectedAccounts,
4
5
  } from '@composio/client/resources/connected-accounts';
5
6
  import {
6
7
  ConnectedAccountListResponse,
7
8
  ConnectedAccountListResponseSchema,
8
9
  ConnectedAccountRetrieveResponse,
9
10
  ConnectedAccountRetrieveResponseSchema,
11
+ ConnectedAccountRevokeResponse,
12
+ ConnectedAccountRevokeResponseSchema,
13
+ ConnectedAccountCompleteAuthResponse,
14
+ ConnectedAccountCompleteAuthResponseSchema,
10
15
  } 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;
11
22
  import { ConnectionDataSchema } from '../../types/connectedAccountAuthStates.types';
12
23
  import logger from '../logger';
13
24
  import { transform } from '../transform';
14
25
 
15
26
  type RawConnectedAccountResponseWithLabels = (
16
- | RawConnectedAccountRetrieveResponse
17
- | RawConnectedAccountListResponse['items'][0]
27
+ RawConnectedAccountRetrieveResponse | RawConnectedAccountListResponse['items'][0]
18
28
  ) & {
19
29
  word_id?: string | null;
20
30
  alias?: string | null;
@@ -117,3 +127,28 @@ export function transformConnectedAccountListResponse(
117
127
  totalPages: response.total_pages,
118
128
  }));
119
129
  }
130
+
131
+ export const transformConnectedAccountRevokeResponse = (
132
+ response: RawConnectedAccountRevokeResponse
133
+ ): ConnectedAccountRevokeResponse => {
134
+ return transform(response)
135
+ .with(ConnectedAccountRevokeResponseSchema)
136
+ .using(response => ({
137
+ revokedTokens: response.revoked_tokens,
138
+ connectedAccount: {
139
+ id: response.connected_account.id,
140
+ status: response.connected_account.status,
141
+ },
142
+ }));
143
+ };
144
+
145
+ export const transformConnectedAccountCompleteAuthResponse = (
146
+ response: RawConnectedAccountCompleteAuthResponse
147
+ ): ConnectedAccountCompleteAuthResponse => {
148
+ return transform(response)
149
+ .with(ConnectedAccountCompleteAuthResponseSchema)
150
+ .using(response => ({
151
+ connectedAccountId: response.connected_account_id,
152
+ toolkitSlug: response.toolkit_slug,
153
+ }));
154
+ };
@@ -0,0 +1,98 @@
1
+ import type {
2
+ CustomDeleteToolkitResponse as RawCustomDeleteToolkitResponse,
3
+ CustomSyncParams as RawCustomSyncParams,
4
+ CustomSyncResponse as RawCustomSyncResponse,
5
+ CustomUpsertParams as RawCustomUpsertParams,
6
+ CustomUpsertResponse as RawCustomUpsertResponse,
7
+ } from '@composio/client/resources/custom';
8
+ import {
9
+ CustomToolkitAuthScheme,
10
+ CustomToolkitDeleteResponse,
11
+ CustomToolkitDeleteResponseSchema,
12
+ CustomToolkitSyncParams,
13
+ CustomToolkitSyncResponse,
14
+ CustomToolkitSyncResponseSchema,
15
+ CustomToolkitUpsertParams,
16
+ CustomToolkitUpsertResponse,
17
+ CustomToolkitUpsertResponseSchema,
18
+ } from '../../types/customToolkits.types';
19
+ import { transform } from '../transform';
20
+
21
+ type RawCustomToolkitAuthScheme = RawCustomUpsertParams['toolkit_config']['auth_schemes'][number];
22
+
23
+ const transformCustomToolkitAuthScheme = (
24
+ scheme: CustomToolkitAuthScheme
25
+ ): RawCustomToolkitAuthScheme => {
26
+ switch (scheme.mode) {
27
+ case 'NO_AUTH':
28
+ return { mode: 'NO_AUTH' };
29
+ case 'API_KEY':
30
+ return {
31
+ mode: 'API_KEY',
32
+ headers: scheme.headers,
33
+ api_key_field: scheme.apiKeyField && {
34
+ display_name: scheme.apiKeyField.displayName,
35
+ description: scheme.apiKeyField.description,
36
+ },
37
+ };
38
+ case 'DCR_OAUTH':
39
+ return { mode: 'DCR_OAUTH', discovery_url: scheme.discoveryUrl };
40
+ }
41
+ };
42
+
43
+ export const transformCustomToolkitUpsertParams = (
44
+ params: CustomToolkitUpsertParams
45
+ ): RawCustomUpsertParams => ({
46
+ slug: params.slug,
47
+ toolkit_config: {
48
+ 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
+ },
54
+ auth_schemes: params.toolkitConfig.authSchemes.map(transformCustomToolkitAuthScheme),
55
+ },
56
+ });
57
+
58
+ export const transformCustomToolkitUpsertResponse = (
59
+ response: RawCustomUpsertResponse
60
+ ): CustomToolkitUpsertResponse => {
61
+ return transform(response)
62
+ .with(CustomToolkitUpsertResponseSchema)
63
+ .using(response => ({ slug: response.slug }));
64
+ };
65
+
66
+ export const transformCustomToolkitSyncParams = (
67
+ slug: string,
68
+ params: CustomToolkitSyncParams
69
+ ): RawCustomSyncParams => ({
70
+ slug,
71
+ connected_account_id: params.connectedAccountId,
72
+ });
73
+
74
+ export const transformCustomToolkitSyncResponse = (
75
+ response: RawCustomSyncResponse
76
+ ): CustomToolkitSyncResponse => {
77
+ return transform(response)
78
+ .with(CustomToolkitSyncResponseSchema)
79
+ .using(response => ({
80
+ slug: response.slug,
81
+ version: response.version,
82
+ syncedCount: response.synced_count,
83
+ }));
84
+ };
85
+
86
+ export const transformCustomToolkitDeleteResponse = (
87
+ response: RawCustomDeleteToolkitResponse
88
+ ): CustomToolkitDeleteResponse => {
89
+ return transform(response)
90
+ .with(CustomToolkitDeleteResponseSchema)
91
+ .using(response => ({
92
+ slug: response.slug,
93
+ deleted: response.deleted,
94
+ revokeJobIds: response.revoke_job_ids,
95
+ authConfigsDeleted: response.auth_configs_deleted,
96
+ connectedAccountsDeleted: response.connected_accounts_deleted,
97
+ }));
98
+ };
@@ -0,0 +1,24 @@
1
+ import type { KeyringListTransferKeysResponse as RawKeyringListTransferKeysResponse } from '@composio/client/resources/keyring';
2
+ import {
3
+ KeyringTransferKeysResponse,
4
+ KeyringTransferKeysResponseSchema,
5
+ } from '../../types/keyring.types';
6
+ import { transform } from '../transform';
7
+
8
+ export const transformKeyringTransferKeysResponse = (
9
+ response: RawKeyringListTransferKeysResponse
10
+ ): KeyringTransferKeysResponse => {
11
+ return transform(response)
12
+ .with(KeyringTransferKeysResponseSchema)
13
+ .using(response => ({
14
+ activeKid: response.active_kid,
15
+ keys: response.keys.map(key => ({
16
+ kty: key.kty,
17
+ n: key.n,
18
+ e: key.e,
19
+ alg: key.alg,
20
+ use: key.use,
21
+ kid: key.kid,
22
+ })),
23
+ }));
24
+ };
@@ -0,0 +1,85 @@
1
+ import type {
2
+ LogCreateToolExecutionParams as RawLogSearchParams,
3
+ LogCreateToolExecutionResponse as RawLogSearchResponse,
4
+ LogRetrieveToolExecutionResponse as RawToolExecutionLogDetail,
5
+ } from '@composio/client/resources/logs';
6
+ import {
7
+ LogSearchParams,
8
+ LogSearchResponse,
9
+ LogSearchResponseSchema,
10
+ ToolExecutionLog,
11
+ ToolExecutionLogDetail,
12
+ ToolExecutionLogDetailSchema,
13
+ ToolExecutionLogSchema,
14
+ } from '../../types/logs.types';
15
+ import { transform } from '../transform';
16
+
17
+ export const transformLogSearchParams = (params: LogSearchParams): RawLogSearchParams => ({
18
+ limit: params.limit,
19
+ cursor: params.cursor,
20
+ filters: params.filters,
21
+ time_range: params.timeRange,
22
+ });
23
+
24
+ export const transformToolExecutionLog = (
25
+ response: RawLogSearchResponse['logs'][number]
26
+ ): ToolExecutionLog => {
27
+ return transform(response)
28
+ .with(ToolExecutionLogSchema)
29
+ .using(response => ({
30
+ id: response.id,
31
+ timestamp: response.timestamp,
32
+ type: response.type,
33
+ status: response.status,
34
+ level: response.level,
35
+ message: response.message,
36
+ metadata: response.metadata,
37
+ metrics: response.metrics,
38
+ parent: response.parent
39
+ ? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
40
+ : null,
41
+ }));
42
+ };
43
+
44
+ export const transformLogSearchResponse = (response: RawLogSearchResponse): LogSearchResponse => {
45
+ return transform(response)
46
+ .with(LogSearchResponseSchema)
47
+ .using(response => ({
48
+ logs: response.logs.map(transformToolExecutionLog),
49
+ nextCursor: response.next_cursor,
50
+ }));
51
+ };
52
+
53
+ export const transformToolExecutionLogDetail = (
54
+ response: RawToolExecutionLogDetail
55
+ ): ToolExecutionLogDetail => {
56
+ return transform(response)
57
+ .with(ToolExecutionLogDetailSchema)
58
+ .using(response => ({
59
+ id: response.id,
60
+ timestamp: response.timestamp,
61
+ type: response.type,
62
+ status: response.status,
63
+ level: response.level,
64
+ message: response.message,
65
+ metadata: response.metadata,
66
+ metrics: response.metrics,
67
+ parent: response.parent
68
+ ? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
69
+ : null,
70
+ timings: response.timings
71
+ ? { startTime: response.timings.start_time, endTime: response.timings.end_time }
72
+ : undefined,
73
+ context: {
74
+ sessionId: response.context.session_id,
75
+ traceId: response.context.trace_id,
76
+ requestId: response.context.request_id,
77
+ },
78
+ source: {
79
+ host: response.source.host,
80
+ framework: response.source.framework,
81
+ language: response.source.language,
82
+ },
83
+ data: response.data,
84
+ }));
85
+ };
@@ -2,7 +2,19 @@ import {
2
2
  ToolkitRetrieveResponse as RawToolkitRetrieveResponse,
3
3
  ToolkitListResponse as RawToolkitListResponse,
4
4
  ToolkitRetrieveCategoriesResponse as RawToolkitRetrieveCategoriesResponse,
5
+ type Toolkits as ClientToolkits,
5
6
  } 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;
6
18
  import {
7
19
  ToolKitListResponse,
8
20
  ToolKitListResponseSchema,
@@ -10,11 +22,23 @@ import {
10
22
  ToolkitRetrieveResponseSchema,
11
23
  ToolkitRetrieveCategoriesResponse,
12
24
  ToolkitRetrieveCategoriesResponseSchema,
25
+ ToolkitChangelogResponse,
26
+ ToolkitChangelogResponseSchema,
27
+ ToolkitRecommendScopesParams,
28
+ ToolkitRecommendScopesResponse,
29
+ ToolkitRecommendScopesResponseSchema,
30
+ ToolkitListGrantContextsParams,
31
+ ToolkitListGrantContextsResponse,
32
+ ToolkitListGrantContextsResponseSchema,
13
33
  } from '../../types/toolkit.types';
14
34
  import { transform } from '../transform';
15
35
 
36
+ /**
37
+ * `GET /toolkits` and `POST /toolkits/multi` return the same item shape; the
38
+ * generated client only names them differently per operation.
39
+ */
16
40
  export const transformToolkitListResponse = (
17
- response: RawToolkitListResponse
41
+ response: RawToolkitListResponse | RawToolkitRetrieveMultiResponse
18
42
  ): ToolKitListResponse => {
19
43
  return transform(response)
20
44
  .with(ToolKitListResponseSchema)
@@ -84,6 +108,24 @@ export const transformToolkitRetrieveResponse = (
84
108
  }));
85
109
  };
86
110
 
111
+ export const transformToolkitChangelogResponse = (
112
+ response: RawToolkitRetrieveChangelogResponse
113
+ ): ToolkitChangelogResponse => {
114
+ return transform(response)
115
+ .with(ToolkitChangelogResponseSchema)
116
+ .using(response => ({
117
+ items: response.items.map(item => ({
118
+ slug: item.slug,
119
+ name: item.name,
120
+ displayName: item.display_name,
121
+ versions: item.versions.map(version => ({
122
+ version: version.version,
123
+ changelog: version.changelog,
124
+ })),
125
+ })),
126
+ }));
127
+ };
128
+
87
129
  export const transformToolkitRetrieveCategoriesResponse = (
88
130
  response: RawToolkitRetrieveCategoriesResponse
89
131
  ): ToolkitRetrieveCategoriesResponse => {
@@ -98,3 +140,60 @@ export const transformToolkitRetrieveCategoriesResponse = (
98
140
  totalPages: response.total_pages,
99
141
  }));
100
142
  };
143
+
144
+ export const transformToolkitRecommendScopesParams = (
145
+ params: ToolkitRecommendScopesParams
146
+ ): RawToolkitRecommendScopesParams => ({
147
+ tools: params.tools,
148
+ auth_scheme: params.authScheme,
149
+ toolkit_version: params.toolkitVersion,
150
+ grant_context: params.grantContext,
151
+ include: params.include,
152
+ exclude: params.exclude,
153
+ available_scopes: params.availableScopes,
154
+ });
155
+
156
+ export const transformToolkitRecommendScopesResponse = (
157
+ response: RawToolkitRecommendScopesResponse
158
+ ): ToolkitRecommendScopesResponse => {
159
+ return transform(response)
160
+ .with(ToolkitRecommendScopesResponseSchema)
161
+ .using(response => ({
162
+ authScheme: response.auth_scheme,
163
+ toolkitVersion: response.toolkit_version,
164
+ grantContext: response.grant_context,
165
+ scopes: {
166
+ leastPrivilege: response.scopes.least_privilege,
167
+ fewest: response.scopes.fewest,
168
+ conditional: response.scopes.conditional.map(condition => ({
169
+ scope: condition.scope,
170
+ when: condition.when,
171
+ for: condition.for,
172
+ })),
173
+ },
174
+ }));
175
+ };
176
+
177
+ export const transformToolkitListGrantContextsParams = (
178
+ params: ToolkitListGrantContextsParams
179
+ ): RawToolkitRetrieveScopesGrantContextParams => ({
180
+ auth_scheme: params.authScheme,
181
+ toolkit_version: params.toolkitVersion,
182
+ });
183
+
184
+ export const transformToolkitListGrantContextsResponse = (
185
+ response: RawToolkitRetrieveScopesGrantContextResponse
186
+ ): ToolkitListGrantContextsResponse => {
187
+ return transform(response)
188
+ .with(ToolkitListGrantContextsResponseSchema)
189
+ .using(response => ({
190
+ authScheme: response.auth_scheme,
191
+ toolkitVersion: response.toolkit_version,
192
+ grantContextDimensions: response.grant_context_dimensions.map(dimension => ({
193
+ dimension: dimension.dimension,
194
+ description: dimension.description,
195
+ values: dimension.values,
196
+ })),
197
+ defaultGrantContext: response.default_grant_context,
198
+ }));
199
+ };
@@ -96,8 +96,8 @@ export function transformTriggerInstanceListActiveItem(
96
96
  id: response.id,
97
97
  connectedAccountId: response.connected_account_id,
98
98
  disabledAt: response.disabled_at,
99
- state: response.state,
100
- triggerConfig: response.trigger_config,
99
+ state: response.state ?? {},
100
+ triggerConfig: response.trigger_config ?? {},
101
101
  triggerName: response.trigger_name,
102
102
  updatedAt: response.updated_at,
103
103
  triggerData: response.trigger_data,