@composio/core 0.16.0 → 0.18.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-BKhHv2hJ.d.mts} +1 -1
- package/dist/{CustomTool-l-j5HtEf.mjs → CustomTool-C4tv-GL1.mjs} +1 -1
- package/dist/FileToolModifier.utils.neutral-D_YkHwZP.mjs +188 -0
- package/dist/{Telemetry-DuGJSwUt.mjs → Telemetry-CBtSnWrm.mjs} +27 -11
- package/dist/cancellation-jUVItfHw.mjs +704 -0
- package/dist/{composio-DSs-1AhC.d.mts → composio-CldtZUyC.d.mts} +254 -247
- package/dist/{BaseProvider-D7p2OPEx.d.mts → customTool.types-DC5fPOOi.d.mts} +2954 -82
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
- package/dist/{errors-BcEUHZbq.mjs → errors-DyZt79fi.mjs} +3 -0
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BQ0fWge3.mjs → fileUtils.node-BwpUOF0s.mjs} +4 -4
- package/dist/index.d.mts +105 -7
- package/dist/index.mjs +94 -116
- package/dist/models/Files.node.mjs +2 -2
- package/dist/{sensitiveFileUploadPaths-BVEt0peg.mjs → sensitiveFileUploadPaths-B0w8dqpv.mjs} +23 -6
- package/dist/ssrfGuard.node-DlxO8uzr.mjs +307 -0
- package/dist/{types-B4k-qoOf.d.mts → types-BgsRW-XH.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 +57 -101
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +25 -6
- package/dist/utils/ssrfGuard.node.mjs +2 -152
- package/dist/utils/ssrfGuard.workerd.d.mts +13 -1
- package/dist/utils/ssrfGuard.workerd.mjs +13 -1
- package/package.json +8 -4
- package/src/errors/ToolErrors.ts +1 -0
- package/src/errors/ValidationErrors.ts +2 -0
- package/src/index.ts +6 -0
- package/src/models/RemoteFile.ts +7 -2
- package/src/models/ToolRouterSession.ts +36 -8
- package/src/models/ToolRouterSessionFileMount.ts +14 -8
- package/src/models/Tools.ts +102 -39
- package/src/provider/BaseProvider.ts +53 -1
- package/src/provider/OpenAIProvider.ts +43 -15
- package/src/services/telemetry/TelemetryService.ts +27 -12
- package/src/types/provider.types.ts +15 -0
- package/src/utils/fileUtils.node.ts +8 -2
- package/src/utils/jsonSchema.ts +505 -27
- package/src/utils/modifiers/FileToolModifier.node.ts +85 -181
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +199 -0
- package/src/utils/pinnedDispatcher.node.ts +118 -0
- package/src/utils/sensitiveFileUploadPaths.ts +36 -9
- package/src/utils/ssrfGuard.node.ts +100 -11
- package/src/utils/ssrfGuard.workerd.ts +16 -0
- package/dist/FileToolModifier.utils.neutral-B5rT711M.mjs +0 -72
- package/dist/cancellation-NVtGf3St.mjs +0 -364
- 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,
|
|
@@ -2,22 +2,43 @@ import logger from '../../utils/logger';
|
|
|
2
2
|
import { TelemetryMetricPayloadBody, TelemetryPayload } from './TelemetryService.types';
|
|
3
3
|
|
|
4
4
|
const TELEMETRY_URL = 'https://telemetry.composio.dev/v1';
|
|
5
|
+
const TELEMETRY_TIMEOUT_MS = 3_000;
|
|
5
6
|
|
|
6
7
|
export class TelemetryService {
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* POSTs a best-effort telemetry payload, bounding the request so a stalled
|
|
10
|
+
* endpoint cannot leave it pending indefinitely.
|
|
11
|
+
*
|
|
12
|
+
* A hand-rolled timer rather than AbortSignal.timeout so it can be cleared the
|
|
13
|
+
* moment the response lands: an uncleared timer is itself pending work, which on
|
|
14
|
+
* workerd pins the request context open for the full timeout on every successful
|
|
15
|
+
* send. Mirrors the bound applied to the npm version check.
|
|
11
16
|
*/
|
|
12
|
-
static async
|
|
17
|
+
private static async postWithTimeout(url: string, payload: unknown) {
|
|
18
|
+
const controller = new AbortController();
|
|
19
|
+
const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
|
|
13
20
|
try {
|
|
14
|
-
|
|
21
|
+
return await fetch(url, {
|
|
15
22
|
method: 'POST',
|
|
16
23
|
headers: {
|
|
17
24
|
'Content-Type': 'application/json',
|
|
18
25
|
},
|
|
19
26
|
body: JSON.stringify(payload),
|
|
27
|
+
signal: controller.signal,
|
|
20
28
|
});
|
|
29
|
+
} finally {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sends a metric to the Telemetry API.
|
|
36
|
+
* @param payload - The payload to send to the Telemetry API.
|
|
37
|
+
* @returns The response from the Telemetry API.
|
|
38
|
+
*/
|
|
39
|
+
static async sendMetric(payload: TelemetryMetricPayloadBody) {
|
|
40
|
+
try {
|
|
41
|
+
const result = await this.postWithTimeout(`${TELEMETRY_URL}/metrics/invocations`, payload);
|
|
21
42
|
return result;
|
|
22
43
|
} catch (error) {
|
|
23
44
|
// ignore error for now; telemetry failures should never affect SDK calls
|
|
@@ -32,13 +53,7 @@ export class TelemetryService {
|
|
|
32
53
|
*/
|
|
33
54
|
static async sendErrorLog(payload: TelemetryPayload) {
|
|
34
55
|
try {
|
|
35
|
-
const result = await
|
|
36
|
-
method: 'POST',
|
|
37
|
-
headers: {
|
|
38
|
-
'Content-Type': 'application/json',
|
|
39
|
-
},
|
|
40
|
-
body: JSON.stringify(payload),
|
|
41
|
-
});
|
|
56
|
+
const result = await this.postWithTimeout(`${TELEMETRY_URL}/errors`, payload);
|
|
42
57
|
return result;
|
|
43
58
|
} catch (error) {
|
|
44
59
|
// ignore error for now; telemetry failures should never affect SDK calls
|
|
@@ -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
|
}
|