@composio/core 0.22.0 → 0.23.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 (48) hide show
  1. package/dist/{CustomTool-CKBCElpT.d.mts → CustomTool-CnHdegDK.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-Dq708dZS.d.mts} +2 -20
  5. package/dist/{customTool.types-CK408sI-.d.mts → customTool.types-B8lVpHOP.d.mts} +21 -64
  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 +45 -4
  15. package/dist/index.mjs +1589 -1448
  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-eTw8Yw7Y.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 +7 -4
  28. package/src/errors/ToolRouterErrors.ts +65 -0
  29. package/src/lib/toolRouterParams.ts +4 -14
  30. package/src/models/CustomToolkits.ts +1 -1
  31. package/src/models/RemoteFile.ts +24 -5
  32. package/src/models/SessionContext.ts +24 -4
  33. package/src/models/ToolRouter.ts +2 -4
  34. package/src/models/ToolRouterSession.ts +44 -13
  35. package/src/models/Tools.ts +20 -36
  36. package/src/models/customToolExecution.ts +10 -0
  37. package/src/platform/node.ts +16 -0
  38. package/src/platform/types.ts +3 -0
  39. package/src/platform/workerd.ts +4 -0
  40. package/src/provider/BaseProvider.ts +2 -1
  41. package/src/types/tool.types.ts +5 -0
  42. package/src/types/toolRouter.types.ts +10 -24
  43. package/src/utils/jsonSchema.ts +191 -36
  44. package/src/utils/retries.ts +20 -0
  45. package/src/utils/safePath.ts +135 -54
  46. package/src/utils/session.ts +31 -2
  47. package/src/utils/transformers/toolRouterResponseTransform.ts +64 -25
  48. package/src/utils/transformers/usage.ts +1 -4
@@ -1,4 +1,4 @@
1
- import { t as Platform } from "../types-D5A2wzBl.mjs";
1
+ import { t as Platform } from "../types-DuVZKrXO.mjs";
2
2
  //#region src/platform/node.d.ts
3
3
  /**
4
4
  * Node.js platform implementation.
@@ -71,6 +71,19 @@ const platform = {
71
71
  writeFileSync(filePath, content, encoding) {
72
72
  if (encoding && typeof content === "string") fs$1.writeFileSync(filePath, content, { encoding });
73
73
  else fs$1.writeFileSync(filePath, content);
74
+ },
75
+ writeFileExclusiveSync(filePath, content) {
76
+ const fd = fs$1.openSync(filePath, "wx");
77
+ try {
78
+ try {
79
+ fs$1.writeFileSync(fd, content);
80
+ } finally {
81
+ fs$1.closeSync(fd);
82
+ }
83
+ } catch (error) {
84
+ fs$1.rmSync(filePath, { force: true });
85
+ throw error;
86
+ }
74
87
  }
75
88
  };
76
89
 
@@ -1,4 +1,4 @@
1
- import { t as Platform } from "../types-D5A2wzBl.mjs";
1
+ import { t as Platform } from "../types-DuVZKrXO.mjs";
2
2
  //#region src/platform/workerd.d.ts
3
3
  /**
4
4
  * Cloudflare Workers / Edge runtime platform implementation.
@@ -64,6 +64,9 @@ const platform = {
64
64
  },
65
65
  writeFileSync(_filePath, _content, _encoding) {
66
66
  throw new Error("File system operations are not supported in this runtime environment (Cloudflare Workers/Edge). Use environment variables or external storage services instead.");
67
+ },
68
+ writeFileExclusiveSync(_filePath, _content) {
69
+ throw new Error("File system operations are not supported in this runtime environment.");
67
70
  }
68
71
  };
69
72
 
@@ -75,6 +75,8 @@ interface Platform {
75
75
  */
76
76
  writeFileSync(filePath: string, content: Uint8Array, encoding?: never): void;
77
77
  writeFileSync(filePath: string, content: string, encoding: Uint8ArrayEncoding): void;
78
+ /** Writes a new file, failing if its path already exists. A failed write removes the file. */
79
+ writeFileExclusiveSync(filePath: string, content: Uint8Array): void;
78
80
  /**
79
81
  * Indicates whether this platform supports file system operations.
80
82
  * Edge runtimes like Cloudflare Workers return false.
@@ -1,5 +1,5 @@
1
- import { ar as BaseComposioProvider } from "./customTool.types-CK408sI-.mjs";
2
- import { n as ComposioConfig } from "./composio-C-418N1P.mjs";
1
+ import { rr as BaseComposioProvider } from "./customTool.types-B8lVpHOP.mjs";
2
+ import { n as ComposioConfig } from "./composio-Dq708dZS.mjs";
3
3
  //#region src/utils/config-defaults/types.d.ts
4
4
  /**
5
5
  * Configuration defaults for Composio.
@@ -1,4 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-RpMRVn4D.mjs";
1
+ import { t as ConfigDefaults } from "../../types-eTw8Yw7Y.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.node.d.ts
3
3
  export declare const CONFIG_DEFAULTS: ConfigDefaults;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-RpMRVn4D.mjs";
1
+ import { t as ConfigDefaults } from "../../types-eTw8Yw7Y.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.workerd.d.ts
3
3
  export declare const CONFIG_DEFAULTS: ConfigDefaults;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { Ea as ToolExecuteResponse, wa as ToolExecuteParams, xa as Tool } from "../../customTool.types-CK408sI-.mjs";
1
+ import { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-B8lVpHOP.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.node.d.ts
4
4
  export declare class FileToolModifier {
@@ -1,8 +1,8 @@
1
1
  import { i as logger } from "../../SsrfErrors-DiQldIdC.mjs";
2
- import { g as ComposioRequestCancelledError } from "../../errors-Dyiu3ifQ.mjs";
2
+ import { _ as ComposioRequestCancelledError } from "../../errors-BN15NcCW.mjs";
3
3
  import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-CdGSABoq.mjs";
4
4
  import { a as isEmptyFileValue, c as transformProperties, i as getSchemaVariants, l as walkFileUploadableLeaves, o as isPlainObject, r as findSchemaVariantWithFileProperty, t as DELETE_VALUE } from "../../FileToolModifier.utils.neutral-DWFpnsj2.mjs";
5
- import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-DV8CIi52.mjs";
5
+ import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-BQibgpRG.mjs";
6
6
  import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-DNLhLg0W.mjs";
7
7
 
8
8
  //#region src/utils/modifiers/FileToolModifier.node.ts
@@ -1,4 +1,4 @@
1
- import { Ea as ToolExecuteResponse, wa as ToolExecuteParams, xa as Tool } from "../../customTool.types-CK408sI-.mjs";
1
+ import { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-B8lVpHOP.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.workerd.d.ts
4
4
  export declare class FileToolModifier {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22.22.3"
6
6
  },
7
- "version": "0.22.0",
7
+ "version": "0.23.0",
8
8
  "description": "",
9
9
  "main": "dist/index.mjs",
10
10
  "publishConfig": {
@@ -40,7 +40,8 @@
40
40
  "edge-light": "./dist/utils/ssrfGuard.workerd.mjs",
41
41
  "node": "./dist/utils/ssrfGuard.node.mjs",
42
42
  "default": "./dist/utils/ssrfGuard.node.mjs"
43
- }
43
+ },
44
+ "#client_identity": "./package.json"
44
45
  },
45
46
  "exports": {
46
47
  ".": {
@@ -113,6 +114,8 @@
113
114
  "@hono/node-server": "^2.1.1",
114
115
  "@type-challenges/utils": "^0.1.1",
115
116
  "@types/semver": "^7.8.0",
117
+ "ajv": "^8.20.0",
118
+ "fast-check": "^4.10.2",
116
119
  "hono": "^4.13.8",
117
120
  "tsdown": "^0.23.0",
118
121
  "tsx": "^4.23.15",
@@ -125,7 +128,7 @@
125
128
  "zod": ">=3.25.76 <5"
126
129
  },
127
130
  "dependencies": {
128
- "@composio/client": "2.0.0-rc.8",
131
+ "@composio/client": "2.0.0-rc.11",
129
132
  "@types/json-schema": "^7.0.15",
130
133
  "is-fs-case-sensitive": "^2.0.0",
131
134
  "openai": "^7.21.0",
@@ -134,7 +137,7 @@
134
137
  "semver": "^7.8.5",
135
138
  "undici": "^7.29.1",
136
139
  "zod-to-json-schema": "^3.25.2",
137
- "@composio/json-schema-to-zod": "0.3.3"
140
+ "@composio/json-schema-to-zod": "0.3.4"
138
141
  },
139
142
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
140
143
  "repository": {
@@ -3,8 +3,21 @@ import { ComposioError, ComposioErrorOptions } from './ComposioError';
3
3
  export const ToolRouterErrorCodes = {
4
4
  MCP_DESTINATION_REJECTED: 'MCP_DESTINATION_REJECTED',
5
5
  SESSION_CONFIG_CONFLICT: 'SESSION_CONFIG_CONFLICT',
6
+ TOOL_INPUT_REQUIRED: 'TOOL_INPUT_REQUIRED',
6
7
  };
7
8
 
9
+ /** One question a tool asks the user before it can run. */
10
+ export interface ToolRouterInputRequest {
11
+ /** Kind of input requested. */
12
+ type: 'elicitation';
13
+ /** How the client collects the input. */
14
+ mode: 'form';
15
+ /** Message to show the user. */
16
+ message: string;
17
+ /** JSON Schema for the answer: a flat object with string, number, boolean or enum fields. */
18
+ requestedSchema: Record<string, unknown>;
19
+ }
20
+
8
21
  /**
9
22
  * Thrown when a session's hosted MCP endpoint is not a destination the SDK
10
23
  * will hand the session credential to. The SDK only attaches its credential
@@ -59,3 +72,55 @@ export class ComposioSessionConfigConflictError extends ComposioError {
59
72
  this.name = 'ComposioSessionConfigConflictError';
60
73
  }
61
74
  }
75
+
76
+ /**
77
+ * Thrown when a session tool execution or proxied call did not run because it
78
+ * needs input from the user first, for example an approval. The API answers
79
+ * such a call with `result_type: "input_required"` instead of a result.
80
+ *
81
+ * `inputRequests` holds the questions, keyed by the ID the answers must
82
+ * reuse. `requestState` is the opaque `request_state` the API returned; when
83
+ * present it must be sent back unchanged together with the answers. The SDK
84
+ * does not submit answers yet, so nothing was executed and the call is not
85
+ * retried.
86
+ */
87
+ export class ComposioToolInputRequiredError extends ComposioError {
88
+ /** Questions for the user, keyed by the ID the answers must reuse. */
89
+ public readonly inputRequests: Record<string, ToolRouterInputRequest>;
90
+ /**
91
+ * Opaque `request_state` from the API, to be sent back unchanged with the answers.
92
+ *
93
+ * It is continuation state, so it is kept out of logs: the property is
94
+ * non-enumerable. Read it as `error.requestState`; `console.error(error)`,
95
+ * `util.inspect(error)`, `JSON.stringify(error)` and object spread leave it out.
96
+ */
97
+ declare public readonly requestState?: string;
98
+
99
+ constructor(
100
+ subject: string,
101
+ details: { inputRequests: Record<string, ToolRouterInputRequest>; requestState?: string },
102
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
103
+ ) {
104
+ const count = Object.keys(details.inputRequests).length;
105
+ super(
106
+ `${subject} requires user input before it can run (${count} input request${count === 1 ? '' : 's'}) and was not executed. ` +
107
+ 'The questions are on `inputRequests` and the opaque `request_state` to send back with the answers is on `requestState`.',
108
+ {
109
+ ...options,
110
+ code: ToolRouterErrorCodes.TOOL_INPUT_REQUIRED,
111
+ possibleFixes: options.possibleFixes ?? [
112
+ 'Collect the answers described by `inputRequests`, then call the session execute endpoint again with `input_responses` and the unchanged `request_state`',
113
+ 'Remove the tool, its toolkit or its tags from the `require_approval` lists of the session configuration if no approval is intended',
114
+ ],
115
+ }
116
+ );
117
+ this.name = 'ComposioToolInputRequiredError';
118
+ this.inputRequests = details.inputRequests;
119
+ Object.defineProperty(this, 'requestState', {
120
+ value: details.requestState,
121
+ enumerable: false,
122
+ writable: false,
123
+ configurable: true,
124
+ });
125
+ }
126
+ }
@@ -195,27 +195,17 @@ export type SessionPatchBody = Omit<
195
195
  SessionPatchParams,
196
196
  'toolkits' | 'tools' | 'tags' | 'auth_configs' | 'preload' | 'search' | 'execute'
197
197
  >,
198
- 'manage_connections' | 'multi_account' | 'experimental' | 'premium_usage'
198
+ 'manage_connections' | 'multi_account' | 'experimental'
199
199
  > & {
200
200
  manage_connections?: SessionPatchManageConnectionsBody | null;
201
201
  multi_account?: SessionPatchMultiAccountBody | null;
202
202
  experimental?: SessionPatchExperimentalBody | null;
203
203
  expected_config_version?: number;
204
- instant?: SessionInstantBody;
205
204
  };
206
205
 
207
- /** SDK-owned wire contract until the generated client adopts the Instant names. */
208
- export type SessionInstantBody =
209
- | false
210
- | (Omit<Exclude<ToolRouterInstant, false>, 'returnInstantCharge'> & {
211
- return_instant_charge?: boolean;
212
- });
213
-
214
- export type SessionCreateBody = Omit<SessionCreateParams, 'premium_usage'> & {
215
- instant?: SessionInstantBody;
216
- };
217
-
218
- export const transformToolRouterInstantParams = (config: ToolRouterInstant): SessionInstantBody => {
206
+ export const transformToolRouterInstantParams = (
207
+ config: ToolRouterInstant
208
+ ): NonNullable<SessionCreateParams['instant']> => {
219
209
  if (config === false) return false;
220
210
  return {
221
211
  ...(config.toolkits !== undefined && { toolkits: config.toolkits }),
@@ -161,7 +161,7 @@ export class CustomToolkits {
161
161
  requestOptions?: ComposioRequestOptions
162
162
  ): Promise<CustomToolkitDeleteResponse> {
163
163
  const result = await withCancellation(
164
- () => this.client.custom.deleteToolkit(slug, requestOptions),
164
+ () => this.client.custom.deleteToolkit(slug, {}, requestOptions),
165
165
  requestOptions?.signal
166
166
  );
167
167
  return transformCustomToolkitDeleteResponse(result);
@@ -1,6 +1,9 @@
1
1
  import { platform } from '#platform';
2
2
  import { ssrfSafeFetchWhereSupported } from '#ssrf_guard';
3
3
  import { COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME } from '../utils/constants';
4
+ import { z } from 'zod';
5
+
6
+ const existingFileError = z.object({ code: z.literal('EEXIST') });
4
7
 
5
8
  function getParentDir(filePath: string): string {
6
9
  const lastSep = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
@@ -14,7 +17,7 @@ import {
14
17
  ValidationError,
15
18
  } from '../errors';
16
19
  import { readResponseBodyWithLimit } from '../utils/readResponseBody';
17
- import { safeBasename, untrustedBasename } from '../utils/safePath';
20
+ import { numberedBasename, safeBasename, untrustedBasename } from '../utils/safePath';
18
21
 
19
22
  /**
20
23
  * Represents a file stored in a tool router session's file mount.
@@ -173,6 +176,7 @@ export class RemoteFile {
173
176
  * Requires a Node.js runtime with file system support (not available in Cloudflare Workers/Edge).
174
177
  *
175
178
  * @param path - Local path to save the file. If omitted, saves to the Composio temp directory using the filename from the mount path.
179
+ * An existing default destination gets a copy number before its extension.
176
180
  * @returns The absolute path where the file was saved
177
181
  * @throws Error if file system is not supported or the save fails
178
182
  * @throws ValidationError if `path` is omitted and the mount path yields no usable filename
@@ -196,8 +200,8 @@ export class RemoteFile {
196
200
  // `"."` or `"foo/.."` would otherwise make `savePath` its own directory or
197
201
  // the parent, and fail with a raw `EISDIR` only after `mkdirSync` had run.
198
202
  const defaultDir = platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
199
- const savePath =
200
- path ?? platform.joinPath(defaultDir, safeBasename(this.mountRelativePath, 'mount path'));
203
+ const defaultName = path == null ? safeBasename(this.mountRelativePath, 'mount path') : '';
204
+ const savePath = path ?? platform.joinPath(defaultDir, defaultName);
201
205
 
202
206
  const content = await this.buffer();
203
207
 
@@ -206,7 +210,22 @@ export class RemoteFile {
206
210
  platform.mkdirSync(dir);
207
211
  }
208
212
 
209
- platform.writeFileSync(savePath, content);
210
- return savePath;
213
+ if (path != null) {
214
+ platform.writeFileSync(savePath, content);
215
+ return savePath;
216
+ }
217
+
218
+ // Server names can equal a digest-tagged name literally. Reserve a new
219
+ // destination atomically so either save order keeps both downloads.
220
+ for (let copy = 0; ; copy++) {
221
+ const destination =
222
+ copy === 0 ? savePath : platform.joinPath(defaultDir, numberedBasename(defaultName, copy));
223
+ try {
224
+ platform.writeFileExclusiveSync(destination, content);
225
+ return destination;
226
+ } catch (error) {
227
+ if (!existingFileError.safeParse(error).success) throw error;
228
+ }
229
+ }
211
230
  }
212
231
  }
@@ -23,10 +23,14 @@ import {
23
23
  findCustomTool,
24
24
  executeCustomTool,
25
25
  } from './customToolExecution';
26
- import { transformExecuteResponse } from '../utils/transformers/toolRouterResponseTransform';
26
+ import {
27
+ assertNotInputRequired,
28
+ transformExecuteResponse,
29
+ } from '../utils/transformers/toolRouterResponseTransform';
27
30
  import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session/session.mjs';
28
31
  import { inlineCustomToolsExperimental } from './inlineCustomToolsPayload';
29
32
  import { withCancellation } from '../utils/cancellation';
33
+ import { withoutRetries } from '../utils/retries';
30
34
 
31
35
  /**
32
36
  * Concrete implementation of SessionContext.
@@ -84,6 +88,7 @@ export class SessionContextImpl implements SessionContext {
84
88
  data: result.data,
85
89
  error: result.error,
86
90
  logId: '',
91
+ resultType: result.successful ? 'completed' : 'failed',
87
92
  });
88
93
  }
89
94
  assertUnambiguousCustomToolSlug(this.customToolsMap, toolSlug);
@@ -100,10 +105,17 @@ export class SessionContextImpl implements SessionContext {
100
105
  }
101
106
 
102
107
  const response = await withCancellation(
103
- () => this.client.toolRouter.session.execute(this.sessionId, executeParams, requestOptions),
108
+ () =>
109
+ this.client.toolRouter.session.execute(
110
+ this.sessionId,
111
+ executeParams,
112
+ withoutRetries(requestOptions)
113
+ ),
104
114
  requestOptions?.signal
105
115
  );
106
- return ToolRouterSessionExecuteResponseSchema.parse(transformExecuteResponse(response));
116
+ return ToolRouterSessionExecuteResponseSchema.parse(
117
+ transformExecuteResponse(response, toolSlug)
118
+ );
107
119
  }
108
120
 
109
121
  /**
@@ -124,10 +136,18 @@ export class SessionContextImpl implements SessionContext {
124
136
  const clientParams = transformProxyParams(validated.data);
125
137
  const response = await withCancellation(
126
138
  () =>
127
- this.client.toolRouter.session.proxyExecute(this.sessionId, clientParams, requestOptions),
139
+ this.client.toolRouter.session.proxyExecute(
140
+ this.sessionId,
141
+ clientParams,
142
+ withoutRetries(requestOptions)
143
+ ),
128
144
  requestOptions?.signal
129
145
  );
130
146
 
147
+ assertNotInputRequired(
148
+ response,
149
+ `${validated.data.method} proxy call for toolkit ${validated.data.toolkit}`
150
+ );
131
151
  return {
132
152
  status: response.status,
133
153
  data: response.data,
@@ -44,7 +44,6 @@ import type {
44
44
  InlineCustomToolsWirePayload,
45
45
  } from '../types/customTool.types';
46
46
  import {
47
- type SessionCreateBody,
48
47
  transformToolRouterTagsParams,
49
48
  transformToolRouterToolsParams,
50
49
  transformToolRouterManageConnectionsParams,
@@ -58,7 +57,6 @@ import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
58
57
  import { buildMCPServerConfig } from '../lib/toolRouterMcp';
59
58
  import { parseSessionConfigInput } from '../lib/sessionConfigConflict';
60
59
  import { getSourceSessionConfig } from '../lib/toolRouterSourceSessionConfig';
61
- import { transformSessionConfig } from '../utils/transformers/toolRouterResponseTransform';
62
60
  import { ToolRouterSession } from './ToolRouterSession';
63
61
  import { ComposioRequestOptions } from '../types/requestOptions.types';
64
62
  import { withCancellation } from '../utils/cancellation';
@@ -77,7 +75,7 @@ function getSessionMetadata(
77
75
  session: SessionCreateResponse | SessionRetrieveResponse | SessionAttachResponse
78
76
  ) {
79
77
  const metadata: ToolRouterSessionMetadata = {
80
- config: transformSessionConfig(session.config),
78
+ config: session.config,
81
79
  preload: session.config.preload,
82
80
  workbench: session.config.workbench,
83
81
  configVersion: session.config_version,
@@ -269,7 +267,7 @@ export class ToolRouter<
269
267
  ])
270
268
  );
271
269
 
272
- const payload: SessionCreateBody = {
270
+ const payload: SessionCreateParams = {
273
271
  user_id: userId,
274
272
  auth_configs: routerConfig.authConfigs,
275
273
  connected_accounts: connectedAccountsPayload,
@@ -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,
@@ -33,9 +37,9 @@ import {
33
37
  type ToolRouterSessionDeleteResponse,
34
38
  } from '../types/toolRouter.types';
35
39
  import {
40
+ assertNotInputRequired,
36
41
  transformSearchResponse,
37
42
  transformExecuteResponse,
38
- transformSessionConfig,
39
43
  } from '../utils/transformers/toolRouterResponseTransform';
40
44
  import { SessionMetaToolOptions } from '../types/modifiers.types';
41
45
  import { ConnectionRequest } from '../types/connectionRequest.types';
@@ -679,6 +683,7 @@ export class ToolRouterSession<
679
683
  * @param options - Optional execution options
680
684
  * @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
685
  * @returns The tool execution result
686
+ * @throws {ComposioToolInputRequiredError} If the tool needs input from the user (for example an approval) before it can run
682
687
  */
683
688
  async execute(
684
689
  toolSlug: string,
@@ -704,6 +709,7 @@ export class ToolRouterSession<
704
709
  data: result.data,
705
710
  error: result.error,
706
711
  logId: '',
712
+ resultType: result.successful ? 'completed' : 'failed',
707
713
  };
708
714
  }
709
715
  assertUnambiguousCustomToolSlug(this.customToolsMap, toolSlug);
@@ -724,10 +730,15 @@ export class ToolRouterSession<
724
730
  }
725
731
 
726
732
  const response = await withCancellation(
727
- () => this.client.toolRouter.session.execute(this.sessionId, executeParams, requestOptions),
733
+ () =>
734
+ this.client.toolRouter.session.execute(
735
+ this.sessionId,
736
+ executeParams,
737
+ withoutRetries(requestOptions)
738
+ ),
728
739
  requestOptions?.signal
729
740
  );
730
- const transformed = transformExecuteResponse(response);
741
+ const transformed = transformExecuteResponse(response, toolSlug);
731
742
  return ToolRouterSessionExecuteResponseSchema.parse(transformed);
732
743
  }
733
744
 
@@ -737,6 +748,7 @@ export class ToolRouterSession<
737
748
  *
738
749
  * @param params - Proxy request parameters (toolkit, endpoint, method, body, headers/query params)
739
750
  * @returns The proxied API response with status, data, headers
751
+ * @throws {ComposioToolInputRequiredError} If the call needs input from the user before it can run
740
752
  */
741
753
  async proxyExecute(
742
754
  params: SessionProxyExecuteParams,
@@ -750,10 +762,18 @@ export class ToolRouterSession<
750
762
  const clientParams = transformProxyParams(validated.data);
751
763
  const response = await withCancellation(
752
764
  () =>
753
- this.client.toolRouter.session.proxyExecute(this.sessionId, clientParams, requestOptions),
765
+ this.client.toolRouter.session.proxyExecute(
766
+ this.sessionId,
767
+ clientParams,
768
+ withoutRetries(requestOptions)
769
+ ),
754
770
  requestOptions?.signal
755
771
  );
756
772
 
773
+ assertNotInputRequired(
774
+ response,
775
+ `${validated.data.method} proxy call for toolkit ${validated.data.toolkit}`
776
+ );
757
777
  return {
758
778
  status: response.status,
759
779
  data: response.data,
@@ -856,7 +876,7 @@ export class ToolRouterSession<
856
876
  }
857
877
 
858
878
  this.configVersion = response.config_version;
859
- this.config = transformSessionConfig(response.config);
879
+ this.config = response.config;
860
880
  this.preload = response.config.preload;
861
881
  this.sandbox = response.config.workbench;
862
882
  this.warnings = response.warnings ?? [];
@@ -913,7 +933,7 @@ export class ToolRouterSession<
913
933
  version: item.version,
914
934
  createdAt: item.created_at,
915
935
  isCurrent: item.is_current,
916
- config: transformSessionConfig(item.config),
936
+ config: item.config,
917
937
  })),
918
938
  nextCursor: response.next_cursor ?? null,
919
939
  totalPages: response.total_pages,
@@ -1038,6 +1058,12 @@ export class ToolRouterSession<
1038
1058
 
1039
1059
  const remoteTransportFailed = !!remoteOutcome && 'error' in remoteOutcome;
1040
1060
  const remoteTransportError = remoteTransportFailed ? remoteOutcome.error : null;
1061
+ // An input request is not a per-tool failure: rethrow it so the caller gets
1062
+ // `inputRequests` and `requestState`.
1063
+ // Accepted: local tools in this batch already ran and their results are discarded.
1064
+ if (remoteTransportError instanceof ComposioToolInputRequiredError) {
1065
+ throw remoteTransportError;
1066
+ }
1041
1067
  const remoteErrorMessage = remoteTransportFailed
1042
1068
  ? (remoteTransportError instanceof Error
1043
1069
  ? remoteTransportError.message
@@ -1109,16 +1135,21 @@ export class ToolRouterSession<
1109
1135
  }
1110
1136
  const remoteError =
1111
1137
  remoteErrorMessage ?? (typeof remoteResult?.error === 'string' ? remoteResult.error : null);
1112
- const hasAnyError = localResults.some(r => r.result.error) || !!remoteError;
1138
+ // A failed execution can carry no error text, so success is read from each
1139
+ // result's own verdict and not from the absence of an error message.
1140
+ const hasAnyFailure =
1141
+ localResults.some(r => !r.result.successful) ||
1142
+ remoteResult?.successful === false ||
1143
+ !!remoteError;
1113
1144
 
1114
1145
  return {
1115
1146
  data: mergedData,
1116
- error: hasAnyError
1117
- ? remoteError && failedCount === 0
1118
- ? remoteError
1119
- : `${failedCount} out of ${allResults.length} tools failed`
1147
+ error: hasAnyFailure
1148
+ ? failedCount > 0
1149
+ ? `${failedCount} out of ${allResults.length} tools failed`
1150
+ : remoteError
1120
1151
  : null,
1121
- successful: !hasAnyError,
1152
+ successful: !hasAnyFailure,
1122
1153
  ...(remoteResult?.instantCharge !== undefined && {
1123
1154
  instantCharge: remoteResult.instantCharge,
1124
1155
  }),