@composio/core 0.16.0 → 0.17.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-Bk38kFp0.d.mts → CustomTool-Uip-fhPw.d.mts} +1 -1
- package/dist/{composio-DSs-1AhC.d.mts → composio-B27X6i6A.d.mts} +11 -10
- package/dist/{BaseProvider-D7p2OPEx.d.mts → customTool.types-B2Ava_j5.d.mts} +2874 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/{fileUtils.node-BQ0fWge3.mjs → fileUtils.node-B1Wn848p.mjs} +2 -2
- package/dist/index.d.mts +5 -6
- package/dist/index.mjs +34 -90
- package/dist/models/Files.node.mjs +1 -1
- package/dist/{types-B4k-qoOf.d.mts → types-DdZJuMm2.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 +1 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +11 -1
- package/dist/utils/ssrfGuard.node.mjs +11 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +13 -1
- package/dist/utils/ssrfGuard.workerd.mjs +13 -1
- package/package.json +2 -2
- package/src/models/RemoteFile.ts +7 -2
- package/src/models/ToolRouterSessionFileMount.ts +14 -8
- package/src/provider/BaseProvider.ts +53 -1
- package/src/provider/OpenAIProvider.ts +43 -15
- package/src/types/provider.types.ts +15 -0
- package/src/utils/fileUtils.node.ts +8 -2
- package/src/utils/ssrfGuard.node.ts +11 -0
- package/src/utils/ssrfGuard.workerd.ts +16 -0
- package/dist/customTool.types-cGHcIBX-.d.mts +0 -2859
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { ComposioGlobalExecuteToolFnNotSetError } from '../errors/ToolErrors';
|
|
2
2
|
import { ExecuteToolModifiers } from '../types/modifiers.types';
|
|
3
3
|
import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '../types/tool.types';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ExecuteToolFn,
|
|
6
|
+
ExecuteToolFnOptions,
|
|
7
|
+
GlobalExecuteToolFn,
|
|
8
|
+
ToolCallExecutionTarget,
|
|
9
|
+
} from '../types/provider.types';
|
|
5
10
|
import { McpUrlResponse, McpServerGetResponse } from '../types/mcp.types';
|
|
6
11
|
|
|
7
12
|
/**
|
|
@@ -60,6 +65,53 @@ abstract class BaseProvider<TMcpResponse> {
|
|
|
60
65
|
return this._globalExecuteToolFn(toolSlug, body, modifers);
|
|
61
66
|
}
|
|
62
67
|
|
|
68
|
+
/** Reject direct-only configuration when execution is bound to a session. */
|
|
69
|
+
protected assertToolCallExecutionOptions(
|
|
70
|
+
target: ToolCallExecutionTarget,
|
|
71
|
+
options?: ExecuteToolFnOptions,
|
|
72
|
+
modifiers?: ExecuteToolModifiers
|
|
73
|
+
): void {
|
|
74
|
+
if (typeof target !== 'string' && (options !== undefined || modifiers !== undefined)) {
|
|
75
|
+
throw new TypeError(
|
|
76
|
+
'Direct execution options and modifiers cannot be used with a Tool Router session'
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Execute normalized provider arguments against either the direct tools API or
|
|
83
|
+
* the Tool Router session that produced the model-visible tools.
|
|
84
|
+
*/
|
|
85
|
+
protected async executeToolForTarget(
|
|
86
|
+
target: ToolCallExecutionTarget,
|
|
87
|
+
toolSlug: string,
|
|
88
|
+
arguments_: Record<string, unknown>,
|
|
89
|
+
options?: ExecuteToolFnOptions,
|
|
90
|
+
modifiers?: ExecuteToolModifiers
|
|
91
|
+
): Promise<ToolExecuteResponse> {
|
|
92
|
+
this.assertToolCallExecutionOptions(target, options, modifiers);
|
|
93
|
+
|
|
94
|
+
if (typeof target === 'string') {
|
|
95
|
+
return this.executeTool(
|
|
96
|
+
toolSlug,
|
|
97
|
+
{
|
|
98
|
+
arguments: arguments_,
|
|
99
|
+
connectedAccountId: options?.connectedAccountId,
|
|
100
|
+
customAuthParams: options?.customAuthParams,
|
|
101
|
+
customConnectionData: options?.customConnectionData,
|
|
102
|
+
userId: target,
|
|
103
|
+
},
|
|
104
|
+
modifiers
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const result = await target.execute(toolSlug, arguments_);
|
|
109
|
+
return {
|
|
110
|
+
...result,
|
|
111
|
+
successful: result.error === null,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
63
115
|
/**
|
|
64
116
|
* @public
|
|
65
117
|
* @deprecated: Will be removed in a future version, once the `experimental.mcp` flag is stabilized. Use `wrapMcpServers` instead.
|
|
@@ -10,10 +10,14 @@
|
|
|
10
10
|
import { OpenAI } from 'openai';
|
|
11
11
|
import { Stream } from 'openai/streaming';
|
|
12
12
|
import { BaseNonAgenticProvider } from './BaseProvider';
|
|
13
|
-
import { Tool
|
|
13
|
+
import { Tool } from '../types/tool.types';
|
|
14
14
|
import logger from '../utils/logger';
|
|
15
15
|
import { ExecuteToolModifiers } from '../types/modifiers.types';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
ExecuteToolFnOptions,
|
|
18
|
+
ToolCallExecutionTarget,
|
|
19
|
+
ToolCallSession,
|
|
20
|
+
} from '../types/provider.types';
|
|
17
21
|
import { McpUrlResponse, McpServerGetResponse } from '../types/mcp.types';
|
|
18
22
|
import { normalizeToolArguments } from '../utils/toolArguments';
|
|
19
23
|
import { deduplicateJsonSchemaRequiredArrays } from '../utils/jsonSchema';
|
|
@@ -153,7 +157,7 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
153
157
|
* This method processes a tool call from OpenAI's chat completion API,
|
|
154
158
|
* executes the corresponding Composio tool, and returns the result.
|
|
155
159
|
*
|
|
156
|
-
* @param {string}
|
|
160
|
+
* @param {string | ToolCallSession} executionTarget - A user ID for direct tools or the session that produced session tools
|
|
157
161
|
* @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool call from OpenAI
|
|
158
162
|
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
159
163
|
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
@@ -179,22 +183,32 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
179
183
|
* console.log(JSON.parse(result));
|
|
180
184
|
* ```
|
|
181
185
|
*/
|
|
186
|
+
async executeToolCall(
|
|
187
|
+
session: ToolCallSession,
|
|
188
|
+
tool: OpenAI.ChatCompletionMessageFunctionToolCall
|
|
189
|
+
): Promise<string>;
|
|
182
190
|
async executeToolCall(
|
|
183
191
|
userId: string,
|
|
184
192
|
tool: OpenAI.ChatCompletionMessageFunctionToolCall,
|
|
185
193
|
options?: ExecuteToolFnOptions,
|
|
186
194
|
modifiers?: ExecuteToolModifiers
|
|
195
|
+
): Promise<string>;
|
|
196
|
+
async executeToolCall(
|
|
197
|
+
executionTarget: ToolCallExecutionTarget,
|
|
198
|
+
tool: OpenAI.ChatCompletionMessageFunctionToolCall,
|
|
199
|
+
options?: ExecuteToolFnOptions,
|
|
200
|
+
modifiers?: ExecuteToolModifiers
|
|
187
201
|
): Promise<string> {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
// OpenAI always serializes tool arguments as a JSON string; normalize tolerates
|
|
203
|
+
// empty / object-shaped payloads too (issue #2406).
|
|
204
|
+
const arguments_ = normalizeToolArguments(tool.function.arguments, tool.function.name);
|
|
205
|
+
const result = await this.executeToolForTarget(
|
|
206
|
+
executionTarget,
|
|
207
|
+
tool.function.name,
|
|
208
|
+
arguments_,
|
|
209
|
+
options,
|
|
210
|
+
modifiers
|
|
211
|
+
);
|
|
198
212
|
return JSON.stringify(result);
|
|
199
213
|
}
|
|
200
214
|
|
|
@@ -204,7 +218,7 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
204
218
|
* This method processes tool calls from an OpenAI chat completion response,
|
|
205
219
|
* executes each tool call, and returns the results.
|
|
206
220
|
*
|
|
207
|
-
* @param {string}
|
|
221
|
+
* @param {string | ToolCallSession} executionTarget - A user ID for direct tools or the session that produced session tools
|
|
208
222
|
* @param {OpenAI.ChatCompletion} chatCompletion - The chat completion response from OpenAI
|
|
209
223
|
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
210
224
|
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
@@ -240,12 +254,23 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
240
254
|
* console.log(results); // Array of tool execution results
|
|
241
255
|
* ```
|
|
242
256
|
*/
|
|
257
|
+
async handleToolCalls(
|
|
258
|
+
session: ToolCallSession,
|
|
259
|
+
chatCompletion: OpenAI.ChatCompletion
|
|
260
|
+
): Promise<OpenAI.ChatCompletionToolMessageParam[]>;
|
|
243
261
|
async handleToolCalls(
|
|
244
262
|
userId: string,
|
|
245
263
|
chatCompletion: OpenAI.ChatCompletion,
|
|
246
264
|
options?: ExecuteToolFnOptions,
|
|
247
265
|
modifiers?: ExecuteToolModifiers
|
|
266
|
+
): Promise<OpenAI.ChatCompletionToolMessageParam[]>;
|
|
267
|
+
async handleToolCalls(
|
|
268
|
+
executionTarget: ToolCallExecutionTarget,
|
|
269
|
+
chatCompletion: OpenAI.ChatCompletion,
|
|
270
|
+
options?: ExecuteToolFnOptions,
|
|
271
|
+
modifiers?: ExecuteToolModifiers
|
|
248
272
|
): Promise<OpenAI.ChatCompletionToolMessageParam[]> {
|
|
273
|
+
this.assertToolCallExecutionOptions(executionTarget, options, modifiers);
|
|
249
274
|
const outputs: OpenAI.ChatCompletionToolMessageParam[] = [];
|
|
250
275
|
// Only the first choice is actionable: its tool results feed back into a
|
|
251
276
|
// single assistant turn. With n > 1, iterating every choice would run each
|
|
@@ -259,7 +284,10 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
259
284
|
if (toolCall.type !== 'function') {
|
|
260
285
|
continue;
|
|
261
286
|
}
|
|
262
|
-
const toolResult =
|
|
287
|
+
const toolResult =
|
|
288
|
+
typeof executionTarget === 'string'
|
|
289
|
+
? await this.executeToolCall(executionTarget, toolCall, options, modifiers)
|
|
290
|
+
: await this.executeToolCall(executionTarget, toolCall);
|
|
263
291
|
outputs.push({
|
|
264
292
|
role: 'tool',
|
|
265
293
|
tool_call_id: toolCall.id,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ToolListParams,
|
|
9
9
|
} from './tool.types';
|
|
10
10
|
import { CustomConnectionData } from './connectedAccountAuthStates.types';
|
|
11
|
+
import type { ToolRouterSessionExecuteResponse } from './toolRouter.types';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Base provider implementation, which needs to be implemented by the extended class.
|
|
@@ -25,6 +26,20 @@ export type ExecuteToolFnOptions = {
|
|
|
25
26
|
customConnectionData?: CustomConnectionData;
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Minimal public contract required to execute model tool calls through a Tool Router session.
|
|
31
|
+
* {@link ToolRouterSession} satisfies this interface.
|
|
32
|
+
*/
|
|
33
|
+
export interface ToolCallSession {
|
|
34
|
+
execute(
|
|
35
|
+
toolSlug: string,
|
|
36
|
+
arguments_?: Record<string, unknown>
|
|
37
|
+
): Promise<ToolRouterSessionExecuteResponse>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Direct user execution or execution bound to a Tool Router session. */
|
|
41
|
+
export type ToolCallExecutionTarget = string | ToolCallSession;
|
|
42
|
+
|
|
28
43
|
/**
|
|
29
44
|
* This type is used to infer the wrapped tool type from the provider.
|
|
30
45
|
* It checks if the provider has a method `_wrapTool` and infers the return type.
|
|
@@ -246,7 +246,10 @@ const uploadFileToS3 = async (
|
|
|
246
246
|
// `InvalidArgumentError: invalid content-length header`, which surfaces as
|
|
247
247
|
// `TypeError: fetch failed` and breaks every `file_uploadable` connector tool
|
|
248
248
|
// on Node 22+.
|
|
249
|
-
|
|
249
|
+
// SSRF guard: `new_presigned_url` comes from the API response, which the SDK
|
|
250
|
+
// treats as untrusted — a response naming an internal address would otherwise
|
|
251
|
+
// have the file's bytes PUT to it. See ssrfGuard.node.ts.
|
|
252
|
+
const uploadResponse = await ssrfSafeFetch(signedURL, {
|
|
250
253
|
method: 'PUT',
|
|
251
254
|
body: uploadBuffer,
|
|
252
255
|
signal,
|
|
@@ -348,7 +351,10 @@ export const downloadFileFromS3 = async ({
|
|
|
348
351
|
fileDownloadDir?: string;
|
|
349
352
|
signal?: AbortSignal;
|
|
350
353
|
}): Promise<FileDownloadData> => {
|
|
351
|
-
|
|
354
|
+
// SSRF guard: `s3Url` is a field of the tool-execution response, so it is no
|
|
355
|
+
// more trusted than a user-supplied URL — and the bytes it returns are
|
|
356
|
+
// written to disk. See ssrfGuard.node.ts.
|
|
357
|
+
const response = await ssrfSafeFetch(s3Url, { signal });
|
|
352
358
|
if (!response.ok) {
|
|
353
359
|
throw new Error(`Failed to download file: ${response.statusText}`);
|
|
354
360
|
}
|
|
@@ -204,3 +204,14 @@ export const ssrfSafeFetch = async (
|
|
|
204
204
|
{ url: rawUrl }
|
|
205
205
|
);
|
|
206
206
|
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* {@link ssrfSafeFetch} for call sites that must keep working on every runtime.
|
|
210
|
+
*
|
|
211
|
+
* `ssrfSafeFetch` fails closed in edge runtimes, which is right for a URL the
|
|
212
|
+
* caller chose to upload — the alternative is fetching it unvalidated — but not
|
|
213
|
+
* for Tool Router session file transfers, where refusing would remove a working
|
|
214
|
+
* feature from Workers rather than close a hole reachable there. On Node this
|
|
215
|
+
* is the full guard; only the edge build differs.
|
|
216
|
+
*/
|
|
217
|
+
export const ssrfSafeFetchWhereSupported = ssrfSafeFetch;
|
|
@@ -17,3 +17,19 @@ export const ssrfSafeFetch = async (rawUrl: string): Promise<Response> => {
|
|
|
17
17
|
}
|
|
18
18
|
);
|
|
19
19
|
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Unguarded `fetch`, for the call sites that must keep working here.
|
|
23
|
+
*
|
|
24
|
+
* Failing closed is the right default for a URL the caller chose to upload, but
|
|
25
|
+
* applying it to Tool Router session file transfers would take a working
|
|
26
|
+
* feature away from Workers instead of closing a hole reachable there. The
|
|
27
|
+
* guard exists to stop a URL from reaching private address space the SDK's host
|
|
28
|
+
* can see; an edge worker has no such vantage point — it cannot resolve DNS to
|
|
29
|
+
* check, and its `fetch` does not originate inside the caller's network. The
|
|
30
|
+
* Node build applies the full guard.
|
|
31
|
+
*/
|
|
32
|
+
export const ssrfSafeFetchWhereSupported = async (
|
|
33
|
+
rawUrl: string,
|
|
34
|
+
init: RequestInit = {}
|
|
35
|
+
): Promise<Response> => fetch(rawUrl, init);
|