@composio/core 0.21.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 (59) hide show
  1. package/dist/{CustomTool-BHOYxLZX.d.mts → CustomTool-CnHdegDK.d.mts} +1 -1
  2. package/dist/{CustomTool-B-_VjWpy.mjs → CustomTool-CnJxXr07.mjs} +1 -1
  3. package/dist/{Telemetry-JRJJYS4I.mjs → Telemetry-41JkqpZ7.mjs} +3 -2
  4. package/dist/{cancellation-DV8CIi52.mjs → cancellation-BQibgpRG.mjs} +166 -34
  5. package/dist/{composio-BTZsFajb.d.mts → composio-Dq708dZS.d.mts} +81 -185
  6. package/dist/{customTool.types-D_w21L56.d.mts → customTool.types-B8lVpHOP.d.mts} +77 -59
  7. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +4 -4
  8. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
  9. package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -2
  10. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
  11. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +2 -2
  12. package/dist/{errors-Dyiu3ifQ.mjs → errors-BN15NcCW.mjs} +34 -2
  13. package/dist/experimental/index.d.mts +2 -2
  14. package/dist/experimental/index.mjs +1 -1
  15. package/dist/index.d.mts +46 -6
  16. package/dist/index.mjs +315 -363
  17. package/dist/models/Files.node.mjs +1 -1
  18. package/dist/platform/node.d.mts +1 -1
  19. package/dist/platform/node.mjs +13 -0
  20. package/dist/platform/workerd.d.mts +1 -1
  21. package/dist/platform/workerd.mjs +3 -0
  22. package/dist/{types-D5A2wzBl.d.mts → types-DuVZKrXO.d.mts} +2 -0
  23. package/dist/{types-CgRsUGqm.d.mts → types-eTw8Yw7Y.d.mts} +2 -2
  24. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  25. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  26. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  27. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  28. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  29. package/package.json +10 -7
  30. package/src/errors/ToolRouterErrors.ts +65 -0
  31. package/src/lib/toolRouterParams.ts +8 -10
  32. package/src/models/AuthConfigs.ts +0 -9
  33. package/src/models/ConnectionRequest.ts +21 -18
  34. package/src/models/CustomToolkits.ts +1 -1
  35. package/src/models/Logs.ts +2 -2
  36. package/src/models/RemoteFile.ts +24 -5
  37. package/src/models/SessionContext.ts +24 -4
  38. package/src/models/ToolRouter.ts +3 -3
  39. package/src/models/ToolRouterSession.ts +45 -13
  40. package/src/models/Tools.ts +21 -37
  41. package/src/models/Usage.ts +2 -1
  42. package/src/models/customToolExecution.ts +10 -0
  43. package/src/platform/node.ts +16 -0
  44. package/src/platform/types.ts +3 -0
  45. package/src/platform/workerd.ts +4 -0
  46. package/src/provider/BaseProvider.ts +2 -1
  47. package/src/provider/OpenAIProvider.ts +0 -283
  48. package/src/telemetry/Telemetry.ts +4 -2
  49. package/src/types/logs.types.ts +9 -1
  50. package/src/types/tool.types.ts +8 -3
  51. package/src/types/toolRouter.types.ts +27 -19
  52. package/src/types/usage.types.ts +2 -0
  53. package/src/utils/jsonSchema.ts +191 -36
  54. package/src/utils/retries.ts +20 -0
  55. package/src/utils/safePath.ts +135 -54
  56. package/src/utils/session.ts +31 -2
  57. package/src/utils/transformers/logs.ts +3 -2
  58. package/src/utils/transformers/toolRouterResponseTransform.ts +69 -12
  59. package/src/utils/transformers/usage.ts +1 -0
@@ -1,4 +1,4 @@
1
- import { t as telemetry } from "../Telemetry-JRJJYS4I.mjs";
1
+ import { t as telemetry } from "../Telemetry-41JkqpZ7.mjs";
2
2
  import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-DNLhLg0W.mjs";
3
3
 
4
4
  //#region src/models/Files.node.ts
@@ -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 { rr as BaseComposioProvider } from "./customTool.types-D_w21L56.mjs";
2
- import { n as ComposioConfig } from "./composio-BTZsFajb.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-CgRsUGqm.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-CgRsUGqm.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 { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-D_w21L56.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 { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-D_w21L56.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.21.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,9 +114,11 @@
113
114
  "@hono/node-server": "^2.1.1",
114
115
  "@type-challenges/utils": "^0.1.1",
115
116
  "@types/semver": "^7.8.0",
116
- "hono": "^4.13.7",
117
+ "ajv": "^8.20.0",
118
+ "fast-check": "^4.10.2",
119
+ "hono": "^4.13.8",
117
120
  "tsdown": "^0.23.0",
118
- "tsx": "^4.23.13",
121
+ "tsx": "^4.23.15",
119
122
  "typedoc": "^0.28.20",
120
123
  "typescript": "npm:@typescript/typescript6@^6.0.2",
121
124
  "vitest": "^5.0.1",
@@ -125,16 +128,16 @@
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
- "openai": "^7.15.0",
134
+ "openai": "^7.21.0",
132
135
  "picocolors": "^1.1.1",
133
136
  "pusher-js": "^8.6.0",
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
+ }
@@ -17,7 +17,7 @@ import {
17
17
  ToolRouterUpdateManageConnectionsSchema,
18
18
  ToolRouterUpdateExperimentalConfig,
19
19
  ToolRouterSandboxConfig,
20
- ToolRouterPremiumUsage,
20
+ ToolRouterInstant,
21
21
  } from '../types/toolRouter.types';
22
22
  import { ValidationError } from '../errors';
23
23
  import { z } from 'zod';
@@ -203,17 +203,15 @@ export type SessionPatchBody = Omit<
203
203
  expected_config_version?: number;
204
204
  };
205
205
 
206
- export type SessionPremiumUsageBody = NonNullable<SessionPatchParams['premium_usage']>;
207
-
208
- export const transformToolRouterPremiumUsageParams = (
209
- config: ToolRouterPremiumUsage
210
- ): SessionPremiumUsageBody => {
206
+ export const transformToolRouterInstantParams = (
207
+ config: ToolRouterInstant
208
+ ): NonNullable<SessionCreateParams['instant']> => {
211
209
  if (config === false) return false;
212
210
  return {
213
211
  ...(config.toolkits !== undefined && { toolkits: config.toolkits }),
214
212
  ...(config.tools !== undefined && { tools: config.tools }),
215
- ...(config.returnPremiumCharge !== undefined && {
216
- return_premium_charge: config.returnPremiumCharge,
213
+ ...(config.returnInstantCharge !== undefined && {
214
+ return_instant_charge: config.returnInstantCharge,
217
215
  }),
218
216
  };
219
217
  };
@@ -354,8 +352,8 @@ export const transformToolRouterUpdateParams = (
354
352
  params.toolkits =
355
353
  config.toolkits === null ? null : transformToolRouterToolkitsParams(config.toolkits);
356
354
  }
357
- if (config.premiumUsage !== undefined) {
358
- params.premium_usage = transformToolRouterPremiumUsageParams(config.premiumUsage);
355
+ if (config.instant !== undefined) {
356
+ params.instant = transformToolRouterInstantParams(config.instant);
359
357
  }
360
358
  if (config.tools !== undefined) {
361
359
  params.tools = config.tools === null ? null : transformToolRouterToolsParams(config.tools);
@@ -45,15 +45,6 @@ export class AuthConfigs {
45
45
  telemetry.instrument(this, 'AuthConfigs');
46
46
  }
47
47
 
48
- /**
49
- * Protected getter for the client instance.
50
- * This is primarily used for testing purposes.
51
- * @protected
52
- */
53
- protected getClient(): ComposioClient {
54
- return this.client;
55
- }
56
-
57
48
  /**
58
49
  * Lists authentication configurations based on provided filter criteria.
59
50
  *
@@ -27,8 +27,7 @@ import { ConnectionRequest, ConnectionRequestState } from '../types/connectionRe
27
27
  * @param {string} connectedAccountId - The ID of the connected account
28
28
  * @param {ConnectedAccountStatus} [status] - Initial status of the connection
29
29
  * @param {string | null} [redirectUrl] - OAuth redirect URL if applicable
30
- * @returns {ConnectionRequestState & { waitForConnection: (timeout?: number) => Promise<ConnectedAccountRetrieveResponse> }}
31
- * Connection request object with state and methods
30
+ * @returns {ConnectionRequest} Connection request object with state and methods
32
31
  */
33
32
  export function createConnectionRequest(
34
33
  client: ComposioClient,
@@ -36,13 +35,22 @@ export function createConnectionRequest(
36
35
  status?: ConnectedAccountStatus,
37
36
  redirectUrl?: string | null
38
37
  ): ConnectionRequest {
39
- const state: ConnectionRequestState = {
38
+ // `waitForConnection` records each observed status on this same object, so
39
+ // `request.status` and `toJSON()` never disagree.
40
+ const request: ConnectionRequest = {
40
41
  id: connectedAccountId,
41
42
  status: status || ConnectedAccountStatuses.INITIATED,
42
43
  redirectUrl,
44
+ waitForConnection,
45
+ toJSON: (): ConnectionRequestState => ({
46
+ id: request.id,
47
+ status: request.status,
48
+ redirectUrl: request.redirectUrl,
49
+ }),
50
+ toString: () => JSON.stringify(request.toJSON(), null, 2),
43
51
  };
44
52
 
45
- telemetry.instrument(state, 'ConnectionRequest');
53
+ telemetry.instrument(request, 'ConnectionRequest');
46
54
 
47
55
  /**
48
56
  * Waits for the connection request to complete and become active.
@@ -87,7 +95,7 @@ export function createConnectionRequest(
87
95
  `Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ''}`,
88
96
  {
89
97
  meta: {
90
- connectedAccountId: state.id,
98
+ connectedAccountId: request.id,
91
99
  status: response.status,
92
100
  statusReason: response.status_reason,
93
101
  },
@@ -97,19 +105,19 @@ export function createConnectionRequest(
97
105
  };
98
106
 
99
107
  try {
100
- const response = await client.connectedAccounts.retrieve(state.id);
108
+ const response = await client.connectedAccounts.retrieve(request.id);
109
+ request.status = response.status;
101
110
  if (response.status === ConnectedAccountStatuses.ACTIVE) {
102
- state.status = ConnectedAccountStatuses.ACTIVE;
103
111
  return transformConnectedAccountResponse(response);
104
112
  }
105
113
  failIfTerminal(response);
106
114
  } catch (error) {
107
115
  if (error instanceof ComposioClient.NotFoundError) {
108
116
  throw new ComposioConnectedAccountNotFoundError(
109
- `Connected account with id ${state.id} not found`,
117
+ `Connected account with id ${request.id} not found`,
110
118
  {
111
119
  meta: {
112
- connectedAccountId: state.id,
120
+ connectedAccountId: request.id,
113
121
  },
114
122
  }
115
123
  );
@@ -123,9 +131,9 @@ export function createConnectionRequest(
123
131
 
124
132
  while (Date.now() - start < timeout) {
125
133
  try {
126
- const response = await client.connectedAccounts.retrieve(state.id);
134
+ const response = await client.connectedAccounts.retrieve(request.id);
127
135
 
128
- state.status = response.status;
136
+ request.status = response.status;
129
137
  if (response.status === ConnectedAccountStatuses.ACTIVE) {
130
138
  return transformConnectedAccountResponse(response);
131
139
  }
@@ -138,13 +146,8 @@ export function createConnectionRequest(
138
146
  }
139
147
  }
140
148
 
141
- throw new ConnectionRequestTimeoutError(`Connection request timed out for ${state.id}`);
149
+ throw new ConnectionRequestTimeoutError(`Connection request timed out for ${request.id}`);
142
150
  }
143
151
 
144
- return {
145
- ...state,
146
- waitForConnection,
147
- toJSON: () => ({ ...state }),
148
- toString: () => JSON.stringify(state, null, 2),
149
- };
152
+ return request;
150
153
  }
@@ -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);
@@ -46,7 +46,7 @@ export class Logs {
46
46
  * pagination.
47
47
  *
48
48
  * @param {LogSearchParams} [params] - Filters, `timeRange`, `limit` and `cursor`
49
- * @returns {Promise<LogSearchResponse>} Matching logs and the next cursor
49
+ * @returns {Promise<LogSearchResponse>} Matching logs and the next cursor. Charged calls include `metadata.instant_charge` as an exact USD string.
50
50
  * @throws {ValidationError} If the params fail validation
51
51
  *
52
52
  * @example
@@ -83,7 +83,7 @@ export class Logs {
83
83
  * source and raw `data`).
84
84
  *
85
85
  * @param {string} id - The log id
86
- * @returns {Promise<ToolExecutionLogDetail>} The log detail
86
+ * @returns {Promise<ToolExecutionLogDetail>} The log detail, with an optional exact USD charge in `metadata.instant_charge`
87
87
  *
88
88
  * @example
89
89
  * ```typescript
@@ -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,
@@ -50,7 +50,7 @@ import {
50
50
  transformToolRouterSandboxParams,
51
51
  transformToolRouterToolkitsParams,
52
52
  transformToolRouterMultiAccountParams,
53
- transformToolRouterPremiumUsageParams,
53
+ transformToolRouterInstantParams,
54
54
  resolveToolRouterSandboxConfig,
55
55
  } from '../lib/toolRouterParams';
56
56
  import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
@@ -272,8 +272,8 @@ export class ToolRouter<
272
272
  auth_configs: routerConfig.authConfigs,
273
273
  connected_accounts: connectedAccountsPayload,
274
274
  toolkits: transformToolRouterToolkitsParams(routerConfig.toolkits),
275
- ...(routerConfig.premiumUsage !== undefined && {
276
- premium_usage: transformToolRouterPremiumUsageParams(routerConfig.premiumUsage),
275
+ ...(routerConfig.instant !== undefined && {
276
+ instant: transformToolRouterInstantParams(routerConfig.instant),
277
277
  }),
278
278
  tools: transformToolRouterToolsParams(routerConfig.tools),
279
279
  tags: transformToolRouterTagsParams(routerConfig.tags),