@composio/core 0.22.0 → 0.24.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-CKBCElpT.d.mts → CustomTool-CNJysHMK.d.mts} +1 -1
  2. package/dist/{CustomTool-B-_VjWpy.mjs → CustomTool-CnJxXr07.mjs} +1 -1
  3. package/dist/{cancellation-DV8CIi52.mjs → cancellation-BQibgpRG.mjs} +166 -34
  4. package/dist/{composio-C-418N1P.d.mts → composio-BFTtZj82.d.mts} +62 -80
  5. package/dist/{customTool.types-CK408sI-.d.mts → customTool.types-D57QrTns.d.mts} +309 -204
  6. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +4 -4
  7. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
  8. package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -2
  9. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
  10. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +2 -2
  11. package/dist/{errors-Dyiu3ifQ.mjs → errors-BN15NcCW.mjs} +34 -2
  12. package/dist/experimental/index.d.mts +2 -2
  13. package/dist/experimental/index.mjs +1 -1
  14. package/dist/index.d.mts +66 -4
  15. package/dist/index.mjs +3321 -3103
  16. package/dist/platform/node.d.mts +1 -1
  17. package/dist/platform/node.mjs +13 -0
  18. package/dist/platform/workerd.d.mts +1 -1
  19. package/dist/platform/workerd.mjs +3 -0
  20. package/dist/{types-D5A2wzBl.d.mts → types-DuVZKrXO.d.mts} +2 -0
  21. package/dist/{types-RpMRVn4D.d.mts → types-q8TwAngA.d.mts} +2 -2
  22. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  23. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  24. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  25. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  26. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  27. package/package.json +12 -9
  28. package/src/errors/ToolRouterErrors.ts +65 -0
  29. package/src/lib/toolRouterParams.ts +19 -13
  30. package/src/models/CustomToolkits.ts +1 -1
  31. package/src/models/MCP.ts +20 -1
  32. package/src/models/RemoteFile.ts +24 -5
  33. package/src/models/SessionContext.ts +24 -4
  34. package/src/models/ToolRouter.ts +6 -4
  35. package/src/models/ToolRouterSession.ts +95 -13
  36. package/src/models/Tools.ts +20 -36
  37. package/src/models/customToolExecution.ts +10 -0
  38. package/src/platform/node.ts +16 -0
  39. package/src/platform/types.ts +3 -0
  40. package/src/platform/workerd.ts +4 -0
  41. package/src/provider/BaseProvider.ts +2 -1
  42. package/src/types/tool.types.ts +5 -0
  43. package/src/types/toolRouter.types.ts +97 -26
  44. package/src/utils/jsonSchema.ts +191 -36
  45. package/src/utils/retries.ts +20 -0
  46. package/src/utils/safePath.ts +135 -54
  47. package/src/utils/session.ts +31 -2
  48. package/src/utils/transformers/toolRouterResponseTransform.ts +72 -27
  49. package/src/utils/transformers/usage.ts +1 -4
@@ -4,8 +4,12 @@ import type { BaseComposioProvider } from '../provider/BaseProvider';
4
4
  import type { ComposioConfig } from '../composio';
5
5
  import type { ComposioRequestOptions } from '../types/requestOptions.types';
6
6
  import { withCancellation } from '../utils/cancellation';
7
+ import { withoutRetries } from '../utils/retries';
7
8
  import { ComposioRequestCancelledError } from '../errors/SDKErrors';
8
- import { ComposioSessionConfigConflictError } from '../errors/ToolRouterErrors';
9
+ import {
10
+ ComposioSessionConfigConflictError,
11
+ ComposioToolInputRequiredError,
12
+ } from '../errors/ToolRouterErrors';
9
13
  import {
10
14
  ToolRouterMCPServerConfig,
11
15
  SessionExperimental,
@@ -17,6 +21,7 @@ import {
17
21
  ToolRouterSessionExecuteResponseSchema,
18
22
  ToolRouterSessionProxyExecuteResponse,
19
23
  ToolRouterSessionExecuteOptions,
24
+ ToolRouterSessionMetaToolSlug,
20
25
  ToolRouterSessionConfig,
21
26
  ToolRouterSessionMetadata,
22
27
  ToolRouterSessionPreloadConfig,
@@ -33,9 +38,9 @@ import {
33
38
  type ToolRouterSessionDeleteResponse,
34
39
  } from '../types/toolRouter.types';
35
40
  import {
41
+ assertNotInputRequired,
36
42
  transformSearchResponse,
37
43
  transformExecuteResponse,
38
- transformSessionConfig,
39
44
  } from '../utils/transformers/toolRouterResponseTransform';
40
45
  import { SessionMetaToolOptions } from '../types/modifiers.types';
41
46
  import { ConnectionRequest } from '../types/connectionRequest.types';
@@ -67,6 +72,7 @@ import type {
67
72
  import { ToolSchema, type Tool, type ToolExecuteResponse } from '../types/tool.types';
68
73
  import type { SessionProxyExecuteParams } from '../types/toolRouter.types';
69
74
  import type {
75
+ SessionExecuteMetaParams,
70
76
  SessionExecuteParams,
71
77
  SessionLinkParams,
72
78
  SessionPatchParams,
@@ -679,6 +685,7 @@ export class ToolRouterSession<
679
685
  * @param options - Optional execution options
680
686
  * @param options.account - Account identifier for direct app tool execution. Accepted on every project: in multi-account sessions it picks the account; on single-account projects it must match one of the session's active connections for the toolkit. Helper/meta tools either ignore this top-level field or define their own account-selection fields.
681
687
  * @returns The tool execution result
688
+ * @throws {ComposioToolInputRequiredError} If the tool needs input from the user (for example an approval) before it can run
682
689
  */
683
690
  async execute(
684
691
  toolSlug: string,
@@ -704,6 +711,7 @@ export class ToolRouterSession<
704
711
  data: result.data,
705
712
  error: result.error,
706
713
  logId: '',
714
+ resultType: result.successful ? 'completed' : 'failed',
707
715
  };
708
716
  }
709
717
  assertUnambiguousCustomToolSlug(this.customToolsMap, toolSlug);
@@ -724,10 +732,64 @@ export class ToolRouterSession<
724
732
  }
725
733
 
726
734
  const response = await withCancellation(
727
- () => this.client.toolRouter.session.execute(this.sessionId, executeParams, requestOptions),
735
+ () =>
736
+ this.client.toolRouter.session.execute(
737
+ this.sessionId,
738
+ executeParams,
739
+ withoutRetries(requestOptions)
740
+ ),
728
741
  requestOptions?.signal
729
742
  );
730
- const transformed = transformExecuteResponse(response);
743
+ const transformed = transformExecuteResponse(response, toolSlug);
744
+ return ToolRouterSessionExecuteResponseSchema.parse(transformed);
745
+ }
746
+
747
+ /**
748
+ * Execute a Composio meta tool (`COMPOSIO_*`) within the session.
749
+ *
750
+ * `session.execute()` also runs meta tools. This method only accepts meta
751
+ * tool slugs, so a typo is a type error instead of a failed request. The call
752
+ * is sent to the Composio backend as is: custom tools named in a
753
+ * `COMPOSIO_MULTI_EXECUTE_TOOL` call are not run in-process here.
754
+ *
755
+ * @param slug - The meta tool slug to execute
756
+ * @param arguments_ - Optional meta tool arguments
757
+ * @returns The tool execution result, in the same shape as `session.execute()`
758
+ * @throws {ComposioToolInputRequiredError} If the tool needs input from the user (for example an approval) before it can run
759
+ *
760
+ * @example
761
+ * ```typescript
762
+ * const { data, resultType } = await session.executeMeta('COMPOSIO_SEARCH_TOOLS', {
763
+ * queries: [{ use_case: 'send an email' }],
764
+ * });
765
+ * ```
766
+ */
767
+ async executeMeta(
768
+ slug: ToolRouterSessionMetaToolSlug,
769
+ arguments_?: Record<string, unknown>,
770
+ requestOptions?: ComposioRequestOptions
771
+ ): Promise<ToolRouterSessionExecuteResponse> {
772
+ const executeMetaParams: SessionExecuteMetaParams = {
773
+ slug,
774
+ arguments: arguments_ ?? {},
775
+ };
776
+ const experimental = inlineCustomToolsExperimental<SessionExecuteMetaParams.Experimental>(
777
+ this.inlineCustomToolsPayload
778
+ );
779
+ if (experimental) {
780
+ executeMetaParams.experimental = experimental;
781
+ }
782
+
783
+ const response = await withCancellation(
784
+ () =>
785
+ this.client.toolRouter.session.executeMeta(
786
+ this.sessionId,
787
+ executeMetaParams,
788
+ withoutRetries(requestOptions)
789
+ ),
790
+ requestOptions?.signal
791
+ );
792
+ const transformed = transformExecuteResponse(response, slug);
731
793
  return ToolRouterSessionExecuteResponseSchema.parse(transformed);
732
794
  }
733
795
 
@@ -737,6 +799,7 @@ export class ToolRouterSession<
737
799
  *
738
800
  * @param params - Proxy request parameters (toolkit, endpoint, method, body, headers/query params)
739
801
  * @returns The proxied API response with status, data, headers
802
+ * @throws {ComposioToolInputRequiredError} If the call needs input from the user before it can run
740
803
  */
741
804
  async proxyExecute(
742
805
  params: SessionProxyExecuteParams,
@@ -750,10 +813,18 @@ export class ToolRouterSession<
750
813
  const clientParams = transformProxyParams(validated.data);
751
814
  const response = await withCancellation(
752
815
  () =>
753
- this.client.toolRouter.session.proxyExecute(this.sessionId, clientParams, requestOptions),
816
+ this.client.toolRouter.session.proxyExecute(
817
+ this.sessionId,
818
+ clientParams,
819
+ withoutRetries(requestOptions)
820
+ ),
754
821
  requestOptions?.signal
755
822
  );
756
823
 
824
+ assertNotInputRequired(
825
+ response,
826
+ `${validated.data.method} proxy call for toolkit ${validated.data.toolkit}`
827
+ );
757
828
  return {
758
829
  status: response.status,
759
830
  data: response.data,
@@ -856,7 +927,7 @@ export class ToolRouterSession<
856
927
  }
857
928
 
858
929
  this.configVersion = response.config_version;
859
- this.config = transformSessionConfig(response.config);
930
+ this.config = response.config;
860
931
  this.preload = response.config.preload;
861
932
  this.sandbox = response.config.workbench;
862
933
  this.warnings = response.warnings ?? [];
@@ -913,7 +984,7 @@ export class ToolRouterSession<
913
984
  version: item.version,
914
985
  createdAt: item.created_at,
915
986
  isCurrent: item.is_current,
916
- config: transformSessionConfig(item.config),
987
+ config: item.config,
917
988
  })),
918
989
  nextCursor: response.next_cursor ?? null,
919
990
  totalPages: response.total_pages,
@@ -1038,6 +1109,12 @@ export class ToolRouterSession<
1038
1109
 
1039
1110
  const remoteTransportFailed = !!remoteOutcome && 'error' in remoteOutcome;
1040
1111
  const remoteTransportError = remoteTransportFailed ? remoteOutcome.error : null;
1112
+ // An input request is not a per-tool failure: rethrow it so the caller gets
1113
+ // `inputRequests` and `requestState`.
1114
+ // Accepted: local tools in this batch already ran and their results are discarded.
1115
+ if (remoteTransportError instanceof ComposioToolInputRequiredError) {
1116
+ throw remoteTransportError;
1117
+ }
1041
1118
  const remoteErrorMessage = remoteTransportFailed
1042
1119
  ? (remoteTransportError instanceof Error
1043
1120
  ? remoteTransportError.message
@@ -1109,16 +1186,21 @@ export class ToolRouterSession<
1109
1186
  }
1110
1187
  const remoteError =
1111
1188
  remoteErrorMessage ?? (typeof remoteResult?.error === 'string' ? remoteResult.error : null);
1112
- const hasAnyError = localResults.some(r => r.result.error) || !!remoteError;
1189
+ // A failed execution can carry no error text, so success is read from each
1190
+ // result's own verdict and not from the absence of an error message.
1191
+ const hasAnyFailure =
1192
+ localResults.some(r => !r.result.successful) ||
1193
+ remoteResult?.successful === false ||
1194
+ !!remoteError;
1113
1195
 
1114
1196
  return {
1115
1197
  data: mergedData,
1116
- error: hasAnyError
1117
- ? remoteError && failedCount === 0
1118
- ? remoteError
1119
- : `${failedCount} out of ${allResults.length} tools failed`
1198
+ error: hasAnyFailure
1199
+ ? failedCount > 0
1200
+ ? `${failedCount} out of ${allResults.length} tools failed`
1201
+ : remoteError
1120
1202
  : null,
1121
- successful: !hasAnyError,
1203
+ successful: !hasAnyFailure,
1122
1204
  ...(remoteResult?.instantCharge !== undefined && {
1123
1205
  instantCharge: remoteResult.instantCharge,
1124
1206
  }),
@@ -62,7 +62,11 @@ import {
62
62
  import { dereferenceJsonSchema } from '../utils/jsonSchema';
63
63
  import { ComposioRequestOptions } from '../types/requestOptions.types';
64
64
  import { withCancellation } from '../utils/cancellation';
65
- import { transformExecuteResponse } from '../utils/transformers/toolRouterResponseTransform';
65
+ import { withoutRetries } from '../utils/retries';
66
+ import {
67
+ isExecutionSuccessful,
68
+ transformExecuteResponse,
69
+ } from '../utils/transformers/toolRouterResponseTransform';
66
70
  import { ComposioRequestCancelledError } from '../errors/SDKErrors';
67
71
 
68
72
  const TOOL_ROUTER_SESSION_TOOLS_PAGE_LIMIT = 500;
@@ -120,11 +124,6 @@ export class Tools<
120
124
  */
121
125
  private readonly warnedAutoUploadDisabledForTool = new Set<string>();
122
126
 
123
- /**
124
- * Lazily-built sibling client with retries disabled; see `clientWithoutRetries`.
125
- */
126
- private clientWithoutRetriesCache?: ComposioClient;
127
-
128
127
  constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
129
128
  if (!client) {
130
129
  throw new Error('ComposioClient is required');
@@ -157,27 +156,6 @@ export class Tools<
157
156
  telemetry.instrument(this, 'Tools');
158
157
  }
159
158
 
160
- /**
161
- * A cached sibling client that never retries requests, mirroring Python's
162
- * `client.without_retries`.
163
- *
164
- * Used for non-idempotent writes (`tools.execute` / `tools.proxy`), where a
165
- * silent retry after a read timeout can duplicate a side effect (e.g. send an
166
- * email twice). Reads keep the default retry behaviour, and so do other writes
167
- * (`toolRouter.session.execute`, auth-config and connected-account mutations):
168
- * the durable fix there is backend-honoured idempotency keys, tracked
169
- * separately.
170
- *
171
- * Cached rather than rebuilt per call because `withOptions` constructs a fresh
172
- * client; its options never change, so one per `Tools` instance suffices.
173
- */
174
- private get clientWithoutRetries(): ComposioClient {
175
- if (!this.clientWithoutRetriesCache) {
176
- this.clientWithoutRetriesCache = this.client.withOptions({ maxRetries: 0 });
177
- }
178
- return this.clientWithoutRetriesCache;
179
- }
180
-
181
159
  /**
182
160
  * Transforms tool data from snake_case API format to camelCase for internal SDK use.
183
161
  *
@@ -1022,9 +1000,7 @@ export class Tools<
1022
1000
  text: body.text,
1023
1001
  };
1024
1002
  const result = await withCancellation(
1025
- // Disable retries: tool execution is a non-idempotent write, and a
1026
- // silent retry after a read timeout can duplicate the side effect.
1027
- () => this.clientWithoutRetries.tools.execute(tool.slug, executeBody, requestOptions),
1003
+ () => this.client.tools.execute(tool.slug, executeBody, withoutRetries(requestOptions)),
1028
1004
  requestOptions?.signal
1029
1005
  );
1030
1006
  // transform the response to the ToolExecuteResponse format
@@ -1254,15 +1230,23 @@ export class Tools<
1254
1230
  }
1255
1231
 
1256
1232
  const response = await withCancellation(
1257
- () => this.client.toolRouter.session.execute(body.sessionId, executePayload, requestOptions),
1233
+ () =>
1234
+ this.client.toolRouter.session.execute(
1235
+ body.sessionId,
1236
+ executePayload,
1237
+ withoutRetries(requestOptions)
1238
+ ),
1258
1239
  requestOptions?.signal
1259
1240
  );
1260
1241
 
1261
- const { data, error, logId, instantCharge } = transformExecuteResponse(response);
1242
+ const { data, error, logId, resultType, instantCharge } = transformExecuteResponse(
1243
+ response,
1244
+ toolSlug
1245
+ );
1262
1246
  let result: ToolExecuteResponse = {
1263
1247
  data,
1264
1248
  error,
1265
- successful: !error,
1249
+ successful: isExecutionSuccessful({ resultType }),
1266
1250
  logId,
1267
1251
  ...(instantCharge !== undefined && { instantCharge }),
1268
1252
  };
@@ -1352,6 +1336,7 @@ export class Tools<
1352
1336
  * @param {string} body.endpoint - Path relative to the toolkit's base URL, or an absolute URL
1353
1337
  * @param {'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'} body.method - HTTP method
1354
1338
  * @param {string} [body.connectedAccountId] - The connected account to authenticate as
1339
+ * @param {string} [body.userId] - The user the connected account belongs to. Projects with 2FA enabled check it against the connected account and may require it
1355
1340
  * @param {unknown} [body.body] - JSON request body
1356
1341
  * @param {Array<{ in: 'query' | 'header'; name: string; value: string | number }>} [body.parameters] - Extra query parameters or headers
1357
1342
  * @returns {Promise<ToolProxyResponse>} The upstream status, headers, and parsed body
@@ -1399,6 +1384,7 @@ export class Tools<
1399
1384
  method: toolProxyParams.data.method,
1400
1385
  body: toolProxyParams.data.body,
1401
1386
  connected_account_id: toolProxyParams.data.connectedAccountId,
1387
+ user_id: toolProxyParams.data.userId,
1402
1388
  parameters: parameters,
1403
1389
  /**
1404
1390
  * @deprecated The `customConnectionData` proxy param is deprecated and will be
@@ -1409,9 +1395,7 @@ export class Tools<
1409
1395
  custom_connection_data: toolProxyParams.data.customConnectionData,
1410
1396
  } as ComposioToolProxyParams;
1411
1397
  return withCancellation(
1412
- // Disable retries: a proxied call is a non-idempotent write, and a silent
1413
- // retry after a read timeout can duplicate the side effect.
1414
- () => this.clientWithoutRetries.tools.proxy(proxyBody, requestOptions),
1398
+ () => this.client.tools.proxy(proxyBody, withoutRetries(requestOptions)),
1415
1399
  requestOptions?.signal
1416
1400
  );
1417
1401
  }
@@ -10,6 +10,7 @@ import type {
10
10
  import type { ToolExecuteResponse } from '../types/tool.types';
11
11
  import { ValidationError } from '../errors';
12
12
  import { ComposioRequestCancelledError, isRequestAbortError } from '../errors/SDKErrors';
13
+ import { ComposioToolInputRequiredError } from '../errors/ToolRouterErrors';
13
14
 
14
15
  /**
15
16
  * Find a custom tool entry by slug.
@@ -59,6 +60,9 @@ export function assertUnambiguousCustomToolSlug(
59
60
  * and wraps the result into the standard response format.
60
61
  *
61
62
  * Callers provide a pre-built SessionContext (which may include sibling routing).
63
+ *
64
+ * @throws {ComposioToolInputRequiredError} If a call the tool made through the
65
+ * session context needs user input before it can run
62
66
  */
63
67
  export async function executeCustomTool(
64
68
  entry: CustomToolsMapEntry,
@@ -103,6 +107,12 @@ export async function executeCustomTool(
103
107
  if (err instanceof ComposioRequestCancelledError) {
104
108
  throw err;
105
109
  }
110
+ // `ctx.execute()` / `ctx.proxyExecute()` asked for user input: nothing ran.
111
+ // Flattening it into a failed result would drop the questions and the
112
+ // request state the caller needs to answer them.
113
+ if (err instanceof ComposioToolInputRequiredError) {
114
+ throw err;
115
+ }
106
116
  if (options?.signal?.aborted && isRequestAbortError(err)) {
107
117
  throw new ComposioRequestCancelledError(undefined, {
108
118
  cause: err instanceof Error ? err : undefined,
@@ -108,4 +108,20 @@ export const platform = {
108
108
  fs.writeFileSync(filePath, content);
109
109
  }
110
110
  },
111
+
112
+ writeFileExclusiveSync(filePath: string, content: Uint8Array): void {
113
+ const fd = fs.openSync(filePath, 'wx');
114
+ try {
115
+ try {
116
+ fs.writeFileSync(fd, content);
117
+ } finally {
118
+ fs.closeSync(fd);
119
+ }
120
+ } catch (error) {
121
+ // The path was created here, so a failed write or close must not leave
122
+ // a partial file that a retry would treat as an existing download.
123
+ fs.rmSync(filePath, { force: true });
124
+ throw error;
125
+ }
126
+ },
111
127
  } as Platform;
@@ -85,6 +85,9 @@ export interface Platform {
85
85
  writeFileSync(filePath: string, content: Uint8Array, encoding?: never): void;
86
86
  writeFileSync(filePath: string, content: string, encoding: Uint8ArrayEncoding): void;
87
87
 
88
+ /** Writes a new file, failing if its path already exists. A failed write removes the file. */
89
+ writeFileExclusiveSync(filePath: string, content: Uint8Array): void;
90
+
88
91
  /**
89
92
  * Indicates whether this platform supports file system operations.
90
93
  * Edge runtimes like Cloudflare Workers return false.
@@ -108,4 +108,8 @@ export const platform: Platform = {
108
108
  'Use environment variables or external storage services instead.'
109
109
  );
110
110
  },
111
+
112
+ writeFileExclusiveSync(_filePath: string, _content: Uint8Array): never {
113
+ throw new Error('File system operations are not supported in this runtime environment.');
114
+ },
111
115
  };
@@ -8,6 +8,7 @@ import {
8
8
  ToolCallExecutionTarget,
9
9
  } from '../types/provider.types';
10
10
  import { McpUrlResponse, McpServerGetResponse } from '../types/mcp.types';
11
+ import { isExecutionSuccessful } from '../utils/transformers/toolRouterResponseTransform';
11
12
 
12
13
  /**
13
14
  * @internal
@@ -108,7 +109,7 @@ abstract class BaseProvider<TMcpResponse> {
108
109
  const result = await target.execute(toolSlug, arguments_);
109
110
  return {
110
111
  ...result,
111
- successful: result.error === null,
112
+ successful: isExecutionSuccessful(result),
112
113
  };
113
114
  }
114
115
 
@@ -426,6 +426,11 @@ export const ToolProxyParamsSchema = z.object({
426
426
  )
427
427
  .optional(),
428
428
  connectedAccountId: z.string().optional(),
429
+ /**
430
+ * The user the connected account belongs to. Projects with 2FA enabled check it
431
+ * against the connected account, and require it for orgs created on or after
432
+ */
433
+ userId: z.string().optional(),
429
434
  /**
430
435
  * @deprecated
431
436
  */
@@ -8,6 +8,7 @@ import { ConnectedAccountExperimentalSchema } from './connectedAccounts.types';
8
8
  import type {
9
9
  SessionConfigHistoryResponse,
10
10
  SessionCreateResponse,
11
+ SessionExecuteMetaParams,
11
12
  } from '@composio/client/resources/tool-router/session/session.mjs';
12
13
  import type {
13
14
  CustomTool,
@@ -131,6 +132,12 @@ export const ToolRouterInstantSchema = z.union([
131
132
  * usage on a Session set to `false`.
132
133
  */
133
134
  returnInstantCharge: z.boolean().optional(),
135
+ /**
136
+ * Experimental. Show each Instant tool's price in Session search
137
+ * results, under `toolkitConnectionStatuses[].instantAccount.prices`.
138
+ * Controls visibility only.
139
+ */
140
+ returnPricesInSearch: z.boolean().optional(),
134
141
  })
135
142
  .strict(),
136
143
  ]);
@@ -149,7 +156,16 @@ export const ToolRouterManageConnectionsConfigSchema = z.object({
149
156
 
150
157
  // Tags
151
158
  export const ToolRouterTagsParamSchema = z
152
- .array(z.enum(['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint']))
159
+ .array(
160
+ z.enum([
161
+ 'readOnlyHint',
162
+ 'createHint',
163
+ 'updateHint',
164
+ 'destructiveHint',
165
+ 'idempotentHint',
166
+ 'openWorldHint',
167
+ ])
168
+ )
153
169
  .describe('The tags to filter the tools by');
154
170
  export const ToolRouterTagsEnableDisableSchema = z
155
171
  .object({
@@ -233,6 +249,33 @@ export const ToolRouterConfigToolsSchema = z
233
249
  });
234
250
  export type ToolRouterConfigTools = z.infer<typeof ToolRouterConfigToolsSchema>;
235
251
 
252
+ /**
253
+ * Proxy execute settings for a session. `enable: true` exposes the
254
+ * `COMPOSIO_PROXY_EXECUTE` meta tool and `enable: false` also turns off the
255
+ * sandbox `proxy_execute()` helper. Leaving the block out keeps the meta tool
256
+ * off while `sandbox.enableProxyExecution` controls the helper.
257
+ */
258
+ export const ToolRouterProxyExecuteConfigSchema = z
259
+ .object({
260
+ enable: z
261
+ .boolean()
262
+ .describe(
263
+ 'true exposes the COMPOSIO_PROXY_EXECUTE meta tool. false also turns off the sandbox proxy_execute() helper.'
264
+ ),
265
+ })
266
+ .strict();
267
+ export type ToolRouterProxyExecuteConfig = z.infer<typeof ToolRouterProxyExecuteConfigSchema>;
268
+
269
+ /**
270
+ * `proxyExecute` as accepted by `sessions.create()` and `session.update()`:
271
+ * a boolean is shorthand for `{ enable: boolean }`.
272
+ */
273
+ export const ToolRouterProxyExecuteSchema = z.union([
274
+ z.boolean(),
275
+ ToolRouterProxyExecuteConfigSchema,
276
+ ]);
277
+ export type ToolRouterProxyExecute = z.infer<typeof ToolRouterProxyExecuteSchema>;
278
+
236
279
  const ToolRouterCreateSessionConfigBaseSchema = z
237
280
  .object({
238
281
  sessionPreset: z
@@ -319,6 +362,10 @@ const ToolRouterCreateSessionConfigBaseSchema = z
319
362
  .optional()
320
363
  .describe('Multi-account configuration for this session'),
321
364
 
365
+ proxyExecute: ToolRouterProxyExecuteSchema.optional().describe(
366
+ 'Proxy execute configuration for this session; a boolean is shorthand for `{ enable }`. Rejected by the API when enable is false and sandbox.enableProxyExecution is true.'
367
+ ),
368
+
322
369
  preload: z
323
370
  .object({
324
371
  tools: z
@@ -440,6 +487,8 @@ export const ToolRouterCreateSessionConfigSchema = z
440
487
  * @param {boolean} [multiAccount.enable] - When true, enables multi-account mode. Falls back to org/project-level config when not set.
441
488
  * @param {number} [multiAccount.maxAccountsPerToolkit] - Max connected accounts per toolkit (2-10, default 5)
442
489
  * @param {boolean} [multiAccount.requireExplicitSelection] - When true, require explicit account selection when multiple accounts are connected
490
+ * @param {boolean | object} [proxyExecute] - Proxy execute configuration for this session. A boolean is shorthand for `{ enable }`.
491
+ * @param {boolean} proxyExecute.enable - `true` exposes the `COMPOSIO_PROXY_EXECUTE` meta tool. `false` also turns off the sandbox `proxy_execute()` helper.
443
492
  * @param {object} [preload] - Tools to preload into session.tools() and the MCP tool list
444
493
  * @param {string[] | 'all'} [preload.tools] - Tool slugs to preload, or "all" to preload every app tool allowed by the session filters. "all" requires a positive filter such as toolkits, tools, or tags; the backend validates and caps the final tool set.
445
494
  * @param {object} [experimental] - Experimental features configuration. Not stable; may change or be removed.
@@ -609,7 +658,24 @@ const ToolRouterSessionSearchToolkitConnectionStatusSchema = z.object({
609
658
  connectionDetails: z.record(z.string(), z.unknown()).optional(),
610
659
  currentUserInfo: z.record(z.string(), z.unknown()).optional(),
611
660
  /** Present when the toolkit runs on a Composio Instant account; only these tools run on it. */
612
- instantAccount: z.object({ allowedToolSlugs: z.array(z.string()) }).optional(),
661
+ instantAccount: z
662
+ .object({
663
+ allowedToolSlugs: z.array(z.string()),
664
+ /**
665
+ * Price of each tool, keyed by tool slug. Present only when the Session
666
+ * sets `instant.returnPricesInSearch`.
667
+ */
668
+ prices: z
669
+ .record(
670
+ z.string(),
671
+ z.object({
672
+ description: z.string().optional(),
673
+ discount: z.string().nullable().optional(),
674
+ })
675
+ )
676
+ .optional(),
677
+ })
678
+ .optional(),
613
679
  });
614
680
 
615
681
  export const ToolRouterSessionSearchResponseSchema = z.object({
@@ -630,6 +696,12 @@ export const ToolRouterSessionExecuteResponseSchema = z.object({
630
696
  data: z.record(z.string(), z.unknown()),
631
697
  error: z.string().nullable(),
632
698
  logId: z.string(),
699
+ /**
700
+ * Whether the tool ran and succeeded (`completed`) or ran and failed
701
+ * (`failed`). A failed execution can carry a `null` or empty `error`, so
702
+ * read this rather than `error` to tell the two apart.
703
+ */
704
+ resultType: z.enum(['completed', 'failed']),
633
705
  /** Actual Instant usage charge when the Session opts into returning it. */
634
706
  instantCharge: z.unknown().optional(),
635
707
  });
@@ -703,34 +775,31 @@ export interface ToolRouterSessionExecuteOptions {
703
775
  account?: string;
704
776
  }
705
777
 
778
+ /**
779
+ * Slug of a Composio meta tool (`COMPOSIO_*`) that `session.executeMeta()` can
780
+ * run, for example `COMPOSIO_SEARCH_TOOLS`.
781
+ */
782
+ export type ToolRouterSessionMetaToolSlug = SessionExecuteMetaParams['slug'];
783
+
784
+ export type ToolRouterSessionExecuteMetaFn = (
785
+ slug: ToolRouterSessionMetaToolSlug,
786
+ arguments_?: Record<string, unknown>,
787
+ requestOptions?: ComposioRequestOptions
788
+ ) => Promise<ToolRouterSessionExecuteResponse>;
789
+
706
790
  export type ToolRouterSessionPreloadConfig = SessionCreateResponse.Config.Preload;
707
791
 
708
792
  export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Workbench;
709
793
 
710
794
  export type ToolRouterSessionWarning = SessionCreateResponse.Warning;
711
795
 
712
- const ToolRouterInstantResponseFilterSchema = z.union([
713
- z.object({ enabled: z.array(z.string()) }),
714
- z.object({ disabled: z.array(z.string()) }),
715
- ]);
716
-
717
- /** Instant policy in the server's Session config (wire field casing). */
718
- export const ToolRouterInstantResponseSchema = z.object({
719
- toolkits: ToolRouterInstantResponseFilterSchema.optional(),
720
- tools: z.record(z.string(), ToolRouterInstantResponseFilterSchema).optional(),
721
- return_instant_charge: z.boolean(),
722
- });
723
- export type ToolRouterInstantResponse = z.infer<typeof ToolRouterInstantResponseSchema>;
724
-
725
796
  /**
726
797
  * Server-side session configuration as returned by the API: toolkit/tool
727
798
  * allowlists, tags, auth configs, connected accounts, manage_connections,
728
- * preload, sandbox (`workbench`), search, execute and Instant settings.
729
- * The generated client still declares the old policy name.
799
+ * preload, sandbox (`workbench`), search, execute, proxy execute and Instant
800
+ * settings.
730
801
  */
731
- export type ToolRouterSessionConfig = Omit<SessionCreateResponse.Config, 'premium_usage'> & {
732
- instant?: false | ToolRouterInstantResponse;
733
- };
802
+ export type ToolRouterSessionConfig = SessionCreateResponse.Config;
734
803
 
735
804
  export interface ToolRouterSessionMetadata {
736
805
  /** Present on every session built from an API response; the constructor synthesises a minimal config when absent. */
@@ -936,6 +1005,11 @@ export const ToolRouterUpdateSessionConfigSchema = z
936
1005
  .nullable()
937
1006
  .optional()
938
1007
  .describe('`null` removes the session override; the mode then resolves to disabled'),
1008
+ proxyExecute: ToolRouterProxyExecuteSchema.nullable()
1009
+ .optional()
1010
+ .describe(
1011
+ 'Replaces the proxy execute block; a boolean is shorthand for `{ enable }` and `null` removes it'
1012
+ ),
939
1013
  preload: z
940
1014
  .object({
941
1015
  tools: z.union([z.array(z.string()), z.literal('all')]).optional(),
@@ -1046,12 +1120,7 @@ export type ToolRouterSessionListConfigHistoryOptions = z.infer<
1046
1120
  * The session configuration at one version, as stored by the API. This is
1047
1121
  * the wire shape (snake_case), with the Instant policy under `instant`.
1048
1122
  */
1049
- export type ToolRouterSessionConfigHistoryConfig = Omit<
1050
- SessionConfigHistoryResponse.Item.Config,
1051
- 'premium_usage'
1052
- > & {
1053
- instant?: false | ToolRouterInstantResponse;
1054
- };
1123
+ export type ToolRouterSessionConfigHistoryConfig = SessionConfigHistoryResponse.Item.Config;
1055
1124
 
1056
1125
  export type ToolRouterSessionConfigHistoryItem = {
1057
1126
  /** The config version this entry represents. */
@@ -1151,6 +1220,8 @@ export interface Session<
1151
1220
  search: ToolRouterSessionSearchFn;
1152
1221
  /** Execute a tool within the session */
1153
1222
  execute: ToolRouterSessionExecuteFn;
1223
+ /** Execute a Composio meta tool (`COMPOSIO_*`) within the session */
1224
+ executeMeta: ToolRouterSessionExecuteMetaFn;
1154
1225
  /** Update the session configuration. Mutates this session in-place and resolves to the updated `config`. */
1155
1226
  update: ToolRouterSessionUpdateFn;
1156
1227
  /** Delete the session. Deleted sessions are no longer retrievable or executable. */