@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.
- package/dist/{CustomTool-CKBCElpT.d.mts → CustomTool-CNJysHMK.d.mts} +1 -1
- package/dist/{CustomTool-B-_VjWpy.mjs → CustomTool-CnJxXr07.mjs} +1 -1
- package/dist/{cancellation-DV8CIi52.mjs → cancellation-BQibgpRG.mjs} +166 -34
- package/dist/{composio-C-418N1P.d.mts → composio-BFTtZj82.d.mts} +62 -80
- package/dist/{customTool.types-CK408sI-.d.mts → customTool.types-D57QrTns.d.mts} +309 -204
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +4 -4
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +2 -2
- package/dist/{errors-Dyiu3ifQ.mjs → errors-BN15NcCW.mjs} +34 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +66 -4
- package/dist/index.mjs +3321 -3103
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +13 -0
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/platform/workerd.mjs +3 -0
- package/dist/{types-D5A2wzBl.d.mts → types-DuVZKrXO.d.mts} +2 -0
- package/dist/{types-RpMRVn4D.d.mts → types-q8TwAngA.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +12 -9
- package/src/errors/ToolRouterErrors.ts +65 -0
- package/src/lib/toolRouterParams.ts +19 -13
- package/src/models/CustomToolkits.ts +1 -1
- package/src/models/MCP.ts +20 -1
- package/src/models/RemoteFile.ts +24 -5
- package/src/models/SessionContext.ts +24 -4
- package/src/models/ToolRouter.ts +6 -4
- package/src/models/ToolRouterSession.ts +95 -13
- package/src/models/Tools.ts +20 -36
- package/src/models/customToolExecution.ts +10 -0
- package/src/platform/node.ts +16 -0
- package/src/platform/types.ts +3 -0
- package/src/platform/workerd.ts +4 -0
- package/src/provider/BaseProvider.ts +2 -1
- package/src/types/tool.types.ts +5 -0
- package/src/types/toolRouter.types.ts +97 -26
- package/src/utils/jsonSchema.ts +191 -36
- package/src/utils/retries.ts +20 -0
- package/src/utils/safePath.ts +135 -54
- package/src/utils/session.ts +31 -2
- package/src/utils/transformers/toolRouterResponseTransform.ts +72 -27
- package/src/utils/transformers/usage.ts +1 -4
package/dist/platform/node.d.mts
CHANGED
package/dist/platform/node.mjs
CHANGED
|
@@ -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
|
|
|
@@ -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 {
|
|
2
|
-
import { n as ComposioConfig } from "./composio-
|
|
1
|
+
import { lr as BaseComposioProvider } from "./customTool.types-D57QrTns.mjs";
|
|
2
|
+
import { n as ComposioConfig } from "./composio-BFTtZj82.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 {
|
|
1
|
+
import { Aa as ToolExecuteResponse, Oa as ToolExecuteParams, Ta as Tool } from "../../customTool.types-D57QrTns.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 {
|
|
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-
|
|
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 {
|
|
1
|
+
import { Aa as ToolExecuteResponse, Oa as ToolExecuteParams, Ta as Tool } from "../../customTool.types-D57QrTns.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.
|
|
7
|
+
"version": "0.24.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
|
".": {
|
|
@@ -110,31 +111,33 @@
|
|
|
110
111
|
],
|
|
111
112
|
"license": "ISC",
|
|
112
113
|
"devDependencies": {
|
|
113
|
-
"@hono/node-server": "^2.1.
|
|
114
|
+
"@hono/node-server": "^2.1.4",
|
|
114
115
|
"@type-challenges/utils": "^0.1.1",
|
|
115
116
|
"@types/semver": "^7.8.0",
|
|
116
|
-
"
|
|
117
|
+
"ajv": "^8.20.0",
|
|
118
|
+
"fast-check": "^4.10.2",
|
|
119
|
+
"hono": "^4.13.13",
|
|
117
120
|
"tsdown": "^0.23.0",
|
|
118
121
|
"tsx": "^4.23.15",
|
|
119
122
|
"typedoc": "^0.28.20",
|
|
120
123
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
121
|
-
"vitest": "^5.0.
|
|
124
|
+
"vitest": "^5.0.3",
|
|
122
125
|
"zod": "^4.5.4"
|
|
123
126
|
},
|
|
124
127
|
"peerDependencies": {
|
|
125
128
|
"zod": ">=3.25.76 <5"
|
|
126
129
|
},
|
|
127
130
|
"dependencies": {
|
|
128
|
-
"@composio/client": "2.0.0-rc.
|
|
131
|
+
"@composio/client": "2.0.0-rc.14",
|
|
129
132
|
"@types/json-schema": "^7.0.15",
|
|
130
133
|
"is-fs-case-sensitive": "^2.0.0",
|
|
131
|
-
"openai": "^7.
|
|
134
|
+
"openai": "^7.31.0",
|
|
132
135
|
"picocolors": "^1.1.1",
|
|
133
136
|
"pusher-js": "^8.6.0",
|
|
134
137
|
"semver": "^7.8.5",
|
|
135
|
-
"undici": "^7.
|
|
138
|
+
"undici": "^7.30.0",
|
|
136
139
|
"zod-to-json-schema": "^3.25.2",
|
|
137
|
-
"@composio/json-schema-to-zod": "0.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
|
+
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
ToolRouterUpdateExperimentalConfig,
|
|
19
19
|
ToolRouterSandboxConfig,
|
|
20
20
|
ToolRouterInstant,
|
|
21
|
+
ToolRouterProxyExecute,
|
|
21
22
|
} from '../types/toolRouter.types';
|
|
22
23
|
import { ValidationError } from '../errors';
|
|
23
24
|
import { z } from 'zod';
|
|
@@ -195,27 +196,23 @@ export type SessionPatchBody = Omit<
|
|
|
195
196
|
SessionPatchParams,
|
|
196
197
|
'toolkits' | 'tools' | 'tags' | 'auth_configs' | 'preload' | 'search' | 'execute'
|
|
197
198
|
>,
|
|
198
|
-
'manage_connections' | 'multi_account' | 'experimental'
|
|
199
|
+
'manage_connections' | 'multi_account' | 'experimental'
|
|
199
200
|
> & {
|
|
200
201
|
manage_connections?: SessionPatchManageConnectionsBody | null;
|
|
201
202
|
multi_account?: SessionPatchMultiAccountBody | null;
|
|
202
203
|
experimental?: SessionPatchExperimentalBody | null;
|
|
203
204
|
expected_config_version?: number;
|
|
204
|
-
instant?: SessionInstantBody;
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
-
/**
|
|
208
|
-
export
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
export type SessionCreateBody = Omit<SessionCreateParams, 'premium_usage'> & {
|
|
215
|
-
instant?: SessionInstantBody;
|
|
216
|
-
};
|
|
207
|
+
/** `proxy_execute` as sent on create and update: a boolean becomes `{ enable }`. */
|
|
208
|
+
export const transformToolRouterProxyExecuteParams = (
|
|
209
|
+
config: ToolRouterProxyExecute
|
|
210
|
+
): NonNullable<SessionCreateParams['proxy_execute']> =>
|
|
211
|
+
typeof config === 'boolean' ? { enable: config } : config;
|
|
217
212
|
|
|
218
|
-
export const transformToolRouterInstantParams = (
|
|
213
|
+
export const transformToolRouterInstantParams = (
|
|
214
|
+
config: ToolRouterInstant
|
|
215
|
+
): NonNullable<SessionCreateParams['instant']> => {
|
|
219
216
|
if (config === false) return false;
|
|
220
217
|
return {
|
|
221
218
|
...(config.toolkits !== undefined && { toolkits: config.toolkits }),
|
|
@@ -223,6 +220,9 @@ export const transformToolRouterInstantParams = (config: ToolRouterInstant): Ses
|
|
|
223
220
|
...(config.returnInstantCharge !== undefined && {
|
|
224
221
|
return_instant_charge: config.returnInstantCharge,
|
|
225
222
|
}),
|
|
223
|
+
...(config.returnPricesInSearch !== undefined && {
|
|
224
|
+
return_prices_in_search: config.returnPricesInSearch,
|
|
225
|
+
}),
|
|
226
226
|
};
|
|
227
227
|
};
|
|
228
228
|
|
|
@@ -401,6 +401,12 @@ export const transformToolRouterUpdateParams = (
|
|
|
401
401
|
params.multi_account = ma;
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
|
+
if (config.proxyExecute !== undefined) {
|
|
405
|
+
params.proxy_execute =
|
|
406
|
+
config.proxyExecute === null
|
|
407
|
+
? null
|
|
408
|
+
: transformToolRouterProxyExecuteParams(config.proxyExecute);
|
|
409
|
+
}
|
|
404
410
|
if (config.preload !== undefined) {
|
|
405
411
|
params.preload = config.preload;
|
|
406
412
|
}
|
|
@@ -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);
|
package/src/models/MCP.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { McpUpdateResponse } from '@composio/client/resources.js';
|
|
|
24
24
|
import { McpRetrieveResponse } from '@composio/client/resources';
|
|
25
25
|
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
26
26
|
import { withCancellation } from '../utils/cancellation';
|
|
27
|
+
import logger from '../utils/logger';
|
|
27
28
|
|
|
28
29
|
function transformMCPItemResponse(response: McpUpdateResponse | McpRetrieveResponse): MCPItem {
|
|
29
30
|
return transform(response)
|
|
@@ -40,6 +41,19 @@ function transformMCPItemResponse(response: McpUpdateResponse | McpRetrieveRespo
|
|
|
40
41
|
toolkits: raw.toolkits,
|
|
41
42
|
}));
|
|
42
43
|
}
|
|
44
|
+
|
|
45
|
+
// `managed_auth_by_composio` is deprecated upstream, but dropping it would strip
|
|
46
|
+
// the connection-management tools from generated URLs. Keep sending it, silence
|
|
47
|
+
// the API client's notice (it names an internal call), and warn once per process
|
|
48
|
+
// in SDK terms instead.
|
|
49
|
+
const MANAGED_AUTH_DEPRECATION =
|
|
50
|
+
'[Deprecation] composio.mcp.generate() returns URLs that rely on the deprecated ' +
|
|
51
|
+
'include_composio_helper_actions query parameter, which the API will remove in a ' +
|
|
52
|
+
'future version. Switch to a session MCP endpoint: composio.create(userId, { mcp: true }) ' +
|
|
53
|
+
'exposes session.mcp.url with connection-management tools built in. ' +
|
|
54
|
+
'https://docs.composio.dev/docs/sessions-via-mcp';
|
|
55
|
+
let _managedAuthDeprecationWarned = false;
|
|
56
|
+
|
|
43
57
|
/**
|
|
44
58
|
* MCP (Model Control Protocol) class
|
|
45
59
|
* Handles MCP server operations.
|
|
@@ -465,8 +479,13 @@ export class MCP {
|
|
|
465
479
|
user_ids: [userId],
|
|
466
480
|
managed_auth_by_composio: options?.manuallyManageConnections ? false : true,
|
|
467
481
|
};
|
|
482
|
+
if (urlBody.managed_auth_by_composio && !_managedAuthDeprecationWarned) {
|
|
483
|
+
_managedAuthDeprecationWarned = true;
|
|
484
|
+
logger.warn(MANAGED_AUTH_DEPRECATION);
|
|
485
|
+
}
|
|
468
486
|
const urlResponse = await withCancellation(
|
|
469
|
-
() =>
|
|
487
|
+
() =>
|
|
488
|
+
this.client.withOptions({ logLevel: 'error' }).mcp.generate.url(urlBody, requestOptions),
|
|
470
489
|
requestOptions?.signal
|
|
471
490
|
);
|
|
472
491
|
|
package/src/models/RemoteFile.ts
CHANGED
|
@@ -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
|
|
200
|
-
|
|
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
|
-
|
|
210
|
-
|
|
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 {
|
|
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
|
-
() =>
|
|
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(
|
|
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(
|
|
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,
|
package/src/models/ToolRouter.ts
CHANGED
|
@@ -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,
|
|
@@ -52,13 +51,13 @@ import {
|
|
|
52
51
|
transformToolRouterToolkitsParams,
|
|
53
52
|
transformToolRouterMultiAccountParams,
|
|
54
53
|
transformToolRouterInstantParams,
|
|
54
|
+
transformToolRouterProxyExecuteParams,
|
|
55
55
|
resolveToolRouterSandboxConfig,
|
|
56
56
|
} from '../lib/toolRouterParams';
|
|
57
57
|
import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
|
|
58
58
|
import { buildMCPServerConfig } from '../lib/toolRouterMcp';
|
|
59
59
|
import { parseSessionConfigInput } from '../lib/sessionConfigConflict';
|
|
60
60
|
import { getSourceSessionConfig } from '../lib/toolRouterSourceSessionConfig';
|
|
61
|
-
import { transformSessionConfig } from '../utils/transformers/toolRouterResponseTransform';
|
|
62
61
|
import { ToolRouterSession } from './ToolRouterSession';
|
|
63
62
|
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
64
63
|
import { withCancellation } from '../utils/cancellation';
|
|
@@ -77,7 +76,7 @@ function getSessionMetadata(
|
|
|
77
76
|
session: SessionCreateResponse | SessionRetrieveResponse | SessionAttachResponse
|
|
78
77
|
) {
|
|
79
78
|
const metadata: ToolRouterSessionMetadata = {
|
|
80
|
-
config:
|
|
79
|
+
config: session.config,
|
|
81
80
|
preload: session.config.preload,
|
|
82
81
|
workbench: session.config.workbench,
|
|
83
82
|
configVersion: session.config_version,
|
|
@@ -269,7 +268,7 @@ export class ToolRouter<
|
|
|
269
268
|
])
|
|
270
269
|
);
|
|
271
270
|
|
|
272
|
-
const payload:
|
|
271
|
+
const payload: SessionCreateParams = {
|
|
273
272
|
user_id: userId,
|
|
274
273
|
auth_configs: routerConfig.authConfigs,
|
|
275
274
|
connected_accounts: connectedAccountsPayload,
|
|
@@ -284,6 +283,9 @@ export class ToolRouter<
|
|
|
284
283
|
),
|
|
285
284
|
workbench: sandboxPayload,
|
|
286
285
|
multi_account: multiAccountPayload,
|
|
286
|
+
...(routerConfig.proxyExecute !== undefined && {
|
|
287
|
+
proxy_execute: transformToolRouterProxyExecuteParams(routerConfig.proxyExecute),
|
|
288
|
+
}),
|
|
287
289
|
preload: routerConfig.preload,
|
|
288
290
|
...(isDirectToolsPreset && {
|
|
289
291
|
search: { enable: false },
|