@composio/core 0.13.1 → 0.14.1
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/README.md +62 -247
- package/dist/BaseProvider-Dc5yKZhk.d.mts +29394 -0
- package/dist/{CustomTool-DLf7JeKt.d.mts → CustomTool-4nVuwLzO.d.mts} +1 -2
- package/dist/{CustomTool-D9qwyMrv.mjs → CustomTool-l-j5HtEf.mjs} +17 -15
- package/dist/FileModifierErrors-B8V8_3VE.mjs +97 -0
- package/dist/{FileModifierErrors-3fSwIWoa.mjs → SsrfErrors-DNJt57GL.mjs} +24 -85
- package/dist/{Telemetry-DhGI_J4G.mjs → Telemetry-CF0rNHu2.mjs} +40 -8
- package/dist/{jsonSchema-CFKdONpP.mjs → cancellation-BbJ-UQ__.mjs} +64 -19
- package/dist/{composio-BHSQwOUz.d.mts → composio-ChU3eD9F.d.mts} +1083 -1061
- package/dist/{customTool.types-9yFqPjdw.d.mts → customTool.types-CX2-LbfI.d.mts} +634 -601
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -22
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +2 -0
- package/dist/{errors-DSIlYfl5.mjs → errors-BcEUHZbq.mjs} +75 -74
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BiO1JQsJ.mjs → fileUtils.node-DOkW4PBg.mjs} +36 -70
- package/dist/index.d.mts +2446 -1563
- package/dist/index.mjs +1415 -1381
- package/dist/models/Files.node.d.mts +2 -11
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +0 -1
- package/dist/platform/node.d.mts +1 -2
- package/dist/platform/node.mjs +3 -0
- package/dist/platform/workerd.d.mts +1 -2
- package/dist/platform/workerd.mjs +30 -3
- package/dist/sensitiveFileUploadPaths-C43dHP7S.mjs +164 -0
- package/dist/{types-BJLCRj9q.d.mts → types-D5N60gUD.d.mts} +2 -3
- package/dist/{types-DdoCRzLj.d.mts → types-DY1r-kN9.d.mts} +9 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -2
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -2
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -2
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -2
- package/dist/utils/ssrfGuard.node.d.mts +22 -0
- package/dist/utils/ssrfGuard.node.mjs +152 -0
- package/dist/utils/ssrfGuard.workerd.d.mts +9 -0
- package/dist/utils/ssrfGuard.workerd.mjs +17 -0
- package/package.json +20 -15
- package/src/errors/SsrfErrors.ts +48 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +10 -0
- package/src/models/CustomTool.ts +1 -3
- package/src/models/ToolRouterSession.ts +38 -16
- package/src/models/ToolRouterSessionFileMount.ts +7 -3
- package/src/models/Tools.ts +32 -2
- package/src/models/Triggers.ts +16 -76
- package/src/platform/node.ts +4 -0
- package/src/platform/types.ts +10 -0
- package/src/platform/workerd.ts +36 -3
- package/src/provider/OpenAIProvider.ts +19 -14
- package/src/telemetry/Telemetry.ts +9 -6
- package/src/telemetry/redact.ts +40 -0
- package/src/types/tool.types.ts +36 -32
- package/src/utils/fileUtils.node.ts +29 -6
- package/src/utils/jsonSchema.ts +58 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +2 -1
- package/src/utils/readResponseBody.ts +63 -0
- package/src/utils/sdk.ts +5 -4
- package/src/utils/{sensitiveFileUploadPaths.node.ts → sensitiveFileUploadPaths.ts} +29 -13
- package/src/utils/ssrfGuard.node.ts +202 -0
- package/src/utils/ssrfGuard.workerd.ts +19 -0
- package/src/utils/toolkitVersion.ts +21 -2
- package/dist/BaseProvider-Brb3o86-.d.mts +0 -29425
- package/dist/CustomTool-NpHpqdnU.d.mts +0 -74
- package/dist/buffer-PcbMMsgm.mjs +0 -33
- package/dist/composio-DfPD7BAi.d.mts +0 -5666
- package/dist/customTool.types-D-6YqFdW.d.mts +0 -2826
- package/dist/types-CCh8qvui.d.mts +0 -12
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
2
|
+
|
|
3
|
+
export const SsrfErrorCodes = {
|
|
4
|
+
BLOCKED_INTERNAL_URL: 'BLOCKED_INTERNAL_URL',
|
|
5
|
+
} as const;
|
|
6
|
+
|
|
7
|
+
export interface ComposioBlockedInternalUrlErrorOptions extends Omit<ComposioErrorOptions, 'code'> {
|
|
8
|
+
/** The user-supplied URL that was refused. */
|
|
9
|
+
url?: string;
|
|
10
|
+
/** The resolved address that tripped the guard, when known. */
|
|
11
|
+
resolvedIp?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Thrown when a URL file input resolves to a private, loopback, link-local, or
|
|
16
|
+
* otherwise internal address, or points at a non-http(s) scheme. Guards against
|
|
17
|
+
* turning URL-based file uploads (including Tool Router session files and
|
|
18
|
+
* automatic upload during tool execution) into a server-side request forgery
|
|
19
|
+
* (SSRF) probe of internal infrastructure such as cloud metadata endpoints
|
|
20
|
+
* (`169.254.169.254`).
|
|
21
|
+
*/
|
|
22
|
+
export class ComposioBlockedInternalUrlError extends ComposioError {
|
|
23
|
+
constructor(
|
|
24
|
+
message: string = 'Refusing to fetch an internal or non-public URL',
|
|
25
|
+
options: ComposioBlockedInternalUrlErrorOptions = {}
|
|
26
|
+
) {
|
|
27
|
+
const { url, resolvedIp, meta: optionsMeta, ...rest } = options;
|
|
28
|
+
|
|
29
|
+
const meta: Record<string, unknown> = {
|
|
30
|
+
...optionsMeta,
|
|
31
|
+
...(url && { url }),
|
|
32
|
+
...(resolvedIp && { resolvedIp }),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
super(message, {
|
|
36
|
+
...rest,
|
|
37
|
+
code: SsrfErrorCodes.BLOCKED_INTERNAL_URL,
|
|
38
|
+
meta: Object.keys(meta).length > 0 ? meta : undefined,
|
|
39
|
+
possibleFixes: options.possibleFixes ?? [
|
|
40
|
+
'Use a publicly reachable http(s) URL',
|
|
41
|
+
'Do not point file inputs at localhost, link-local, or private-network hosts',
|
|
42
|
+
'If the source is internal, download it yourself and pass a File/Blob instead of a URL',
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.name = 'ComposioBlockedInternalUrlError';
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/errors/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { BaseNonAgenticProvider, BaseAgenticProvider } from './provider/BaseProv
|
|
|
6
6
|
export type { BaseComposioProvider } from './provider/BaseProvider';
|
|
7
7
|
export {
|
|
8
8
|
dereferenceJsonSchema,
|
|
9
|
+
deduplicateJsonSchemaRequiredArrays,
|
|
9
10
|
jsonSchemaToZodSchema,
|
|
10
11
|
removeNonRequiredProperties,
|
|
11
12
|
} from './utils/jsonSchema';
|
|
@@ -16,6 +17,15 @@ export type {
|
|
|
16
17
|
} from './utils/jsonSchema';
|
|
17
18
|
export { getExtensionFromMimeType } from './utils/mime';
|
|
18
19
|
export { normalizeToolArguments } from './utils/toolArguments';
|
|
20
|
+
// Sensitive-file-upload denylist guard. This is the single canonical
|
|
21
|
+
// implementation; downstream packages (e.g. `@composio/cli`) import it here so
|
|
22
|
+
// every local-file upload path enforces the same denylist. Safe in the edge
|
|
23
|
+
// bundle: the module routes filesystem access through `#platform`.
|
|
24
|
+
export {
|
|
25
|
+
assertSafeFileUploadPath,
|
|
26
|
+
isBlockedSensitiveFileUploadPath,
|
|
27
|
+
BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS,
|
|
28
|
+
} from './utils/sensitiveFileUploadPaths';
|
|
19
29
|
export {
|
|
20
30
|
sanitizeSchemaPropertyKeys,
|
|
21
31
|
restoreOriginalKeys,
|
package/src/models/CustomTool.ts
CHANGED
|
@@ -483,9 +483,7 @@ export function buildCustomToolsMapFromResponse(
|
|
|
483
483
|
tools: CustomTool[],
|
|
484
484
|
toolkits: CustomToolkit[] | undefined,
|
|
485
485
|
experimental:
|
|
486
|
-
|
|
|
487
|
-
| SessionRetrieveResponse['experimental']
|
|
488
|
-
| undefined
|
|
486
|
+
SessionCreateResponse['experimental'] | SessionRetrieveResponse['experimental'] | undefined
|
|
489
487
|
): CustomToolsMap {
|
|
490
488
|
const byFinalSlug = new Map<string, CustomToolsMapEntry>();
|
|
491
489
|
const byOriginalSlug = new Map<string, CustomToolsMapEntry>();
|
|
@@ -766,11 +766,23 @@ export class ToolRouterSession<
|
|
|
766
766
|
);
|
|
767
767
|
}
|
|
768
768
|
|
|
769
|
-
const [localResults,
|
|
769
|
+
const [localResults, remoteOutcome] = await Promise.all([
|
|
770
770
|
Promise.all(localPromises),
|
|
771
|
-
remotePromise
|
|
771
|
+
remotePromise
|
|
772
|
+
? remotePromise.then(result => ({ result })).catch(error => ({ error }))
|
|
773
|
+
: undefined,
|
|
772
774
|
]);
|
|
773
775
|
|
|
776
|
+
const remoteTransportFailed = !!remoteOutcome && 'error' in remoteOutcome;
|
|
777
|
+
const remoteTransportError = remoteTransportFailed ? remoteOutcome.error : null;
|
|
778
|
+
const remoteErrorMessage = remoteTransportFailed
|
|
779
|
+
? (remoteTransportError instanceof Error
|
|
780
|
+
? remoteTransportError.message
|
|
781
|
+
: String(remoteTransportError)) || 'Remote tool execution failed'
|
|
782
|
+
: null;
|
|
783
|
+
const remoteResult =
|
|
784
|
+
remoteOutcome && 'result' in remoteOutcome ? remoteOutcome.result : undefined;
|
|
785
|
+
|
|
774
786
|
// If only local tools, return the single/first result unwrapped
|
|
775
787
|
if (remoteIndices.length === 0 && localResults.length === 1) {
|
|
776
788
|
return localResults[0].result;
|
|
@@ -784,9 +796,15 @@ export class ToolRouterSession<
|
|
|
784
796
|
? remoteResult.data
|
|
785
797
|
: {}
|
|
786
798
|
) as Record<string, unknown>;
|
|
787
|
-
const remoteResults =
|
|
788
|
-
|
|
789
|
-
|
|
799
|
+
const remoteResults = remoteErrorMessage
|
|
800
|
+
? remoteIndices.map(index => ({
|
|
801
|
+
response: { successful: false, data: {}, error: remoteErrorMessage },
|
|
802
|
+
tool_slug: parsed[index].tool_slug,
|
|
803
|
+
error: remoteErrorMessage,
|
|
804
|
+
}))
|
|
805
|
+
: ((Array.isArray(remoteData.results) ? remoteData.results : []) as Array<
|
|
806
|
+
Record<string, unknown>
|
|
807
|
+
>);
|
|
790
808
|
|
|
791
809
|
// Build local result entries matching backend format
|
|
792
810
|
const localEntries = localResults.map(({ index, result }) => ({
|
|
@@ -796,20 +814,22 @@ export class ToolRouterSession<
|
|
|
796
814
|
...(result.error ? { error: result.error } : {}),
|
|
797
815
|
},
|
|
798
816
|
tool_slug: parsed[index].tool_slug,
|
|
817
|
+
index,
|
|
799
818
|
...(result.error ? { error: result.error } : {}),
|
|
800
819
|
}));
|
|
801
820
|
|
|
802
|
-
//
|
|
821
|
+
// Restore original request order, then re-index sequentially so there are no collisions.
|
|
803
822
|
const merged: Array<Record<string, unknown>> = [
|
|
804
|
-
...(
|
|
805
|
-
...localEntries,
|
|
806
|
-
];
|
|
807
|
-
const allResults = merged.map(
|
|
808
|
-
(entry, i): Record<string, unknown> => ({
|
|
823
|
+
...remoteResults.map((entry, remotePosition) => ({
|
|
809
824
|
...entry,
|
|
810
|
-
index:
|
|
811
|
-
})
|
|
812
|
-
|
|
825
|
+
index: remoteIndices[remotePosition] ?? remotePosition,
|
|
826
|
+
})),
|
|
827
|
+
...localEntries,
|
|
828
|
+
].sort((a, b) => Number(a.index) - Number(b.index));
|
|
829
|
+
const allResults = merged.map((entry, i): Record<string, unknown> => ({
|
|
830
|
+
...entry,
|
|
831
|
+
index: i,
|
|
832
|
+
}));
|
|
813
833
|
const failedCount = allResults.filter(r => r.error).length;
|
|
814
834
|
const mergedData: Record<string, unknown> = {
|
|
815
835
|
...remoteData,
|
|
@@ -817,13 +837,15 @@ export class ToolRouterSession<
|
|
|
817
837
|
};
|
|
818
838
|
if (
|
|
819
839
|
localEntries.length > 0 &&
|
|
820
|
-
|
|
840
|
+
(remoteErrorMessage ||
|
|
841
|
+
['total_count', 'success_count', 'error_count'].some(key => key in remoteData))
|
|
821
842
|
) {
|
|
822
843
|
mergedData.total_count = allResults.length;
|
|
823
844
|
mergedData.success_count = allResults.length - failedCount;
|
|
824
845
|
mergedData.error_count = failedCount;
|
|
825
846
|
}
|
|
826
|
-
const remoteError =
|
|
847
|
+
const remoteError =
|
|
848
|
+
remoteErrorMessage ?? (typeof remoteResult?.error === 'string' ? remoteResult.error : null);
|
|
827
849
|
const hasAnyError = localResults.some(r => r.result.error) || !!remoteError;
|
|
828
850
|
|
|
829
851
|
return {
|
|
@@ -18,7 +18,9 @@ import {
|
|
|
18
18
|
import { RemoteFile } from './RemoteFile';
|
|
19
19
|
import { ValidationError } from '../errors';
|
|
20
20
|
import { platform } from '#platform';
|
|
21
|
+
import { ssrfSafeFetch } from '#ssrf_guard';
|
|
21
22
|
import { getExtensionFromMimeType } from '../utils/mime';
|
|
23
|
+
import { readResponseBodyWithLimit } from '../utils/readResponseBody';
|
|
22
24
|
import { getRandomShortId } from '../utils/uuid';
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -110,11 +112,11 @@ export class ToolRouterSessionFilesMount {
|
|
|
110
112
|
): Promise<{ fileToUpload: File; remotePath: string; mimetype: string }> {
|
|
111
113
|
if (typeof input === 'string') {
|
|
112
114
|
if (input.startsWith('http://') || input.startsWith('https://')) {
|
|
113
|
-
const response = await
|
|
115
|
+
const response = await ssrfSafeFetch(input);
|
|
114
116
|
if (!response.ok) {
|
|
115
117
|
throw new Error(`Failed to fetch file from URL: ${response.statusText}`);
|
|
116
118
|
}
|
|
117
|
-
const
|
|
119
|
+
const content = await readResponseBodyWithLimit(response);
|
|
118
120
|
const rawContentType = response.headers.get('content-type') || 'application/octet-stream';
|
|
119
121
|
const mimeType = rawContentType.split(';')[0].trim();
|
|
120
122
|
const url = new URL(input);
|
|
@@ -125,7 +127,7 @@ export class ToolRouterSessionFilesMount {
|
|
|
125
127
|
const extension = getExtensionFromMimeType(mimeType);
|
|
126
128
|
filename = `${getRandomShortId()}.${extension}`;
|
|
127
129
|
}
|
|
128
|
-
const file = new File([
|
|
130
|
+
const file = new File([content as BlobPart], filename, { type: mimeType });
|
|
129
131
|
return {
|
|
130
132
|
fileToUpload: file,
|
|
131
133
|
remotePath: options.remotePath ?? filename,
|
|
@@ -178,6 +180,8 @@ export class ToolRouterSessionFilesMount {
|
|
|
178
180
|
*
|
|
179
181
|
* Accepts a file path (local or URL), a native File object, or a raw buffer.
|
|
180
182
|
* The file is stored in the virtual filesystem associated with the tool router session.
|
|
183
|
+
* URL inputs require a Node.js or Bun runtime so the destination can be DNS-validated;
|
|
184
|
+
* edge runtimes must fetch the file themselves and pass a File or ArrayBuffer.
|
|
181
185
|
*
|
|
182
186
|
* @param input - File path (string), native File, or raw buffer (ArrayBuffer | Uint8Array).
|
|
183
187
|
* @param options - Optional configuration. When passing a buffer, remotePath is required.
|
package/src/models/Tools.ts
CHANGED
|
@@ -114,6 +114,11 @@ export class Tools<
|
|
|
114
114
|
*/
|
|
115
115
|
private readonly warnedAutoUploadDisabledForTool = new Set<string>();
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Lazily-built sibling client with retries disabled; see `clientWithoutRetries`.
|
|
119
|
+
*/
|
|
120
|
+
private clientWithoutRetriesCache?: ComposioClient;
|
|
121
|
+
|
|
117
122
|
constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
|
|
118
123
|
if (!client) {
|
|
119
124
|
throw new Error('ComposioClient is required');
|
|
@@ -146,6 +151,27 @@ export class Tools<
|
|
|
146
151
|
telemetry.instrument(this, 'Tools');
|
|
147
152
|
}
|
|
148
153
|
|
|
154
|
+
/**
|
|
155
|
+
* A cached sibling client that never retries requests, mirroring Python's
|
|
156
|
+
* `client.without_retries`.
|
|
157
|
+
*
|
|
158
|
+
* Used for non-idempotent writes (`tools.execute` / `tools.proxy`), where a
|
|
159
|
+
* silent retry after a read timeout can duplicate a side effect (e.g. send an
|
|
160
|
+
* email twice). Reads keep the default retry behaviour, and so do other writes
|
|
161
|
+
* (`toolRouter.session.execute`, auth-config and connected-account mutations):
|
|
162
|
+
* the durable fix there is backend-honoured idempotency keys, tracked
|
|
163
|
+
* separately.
|
|
164
|
+
*
|
|
165
|
+
* Cached rather than rebuilt per call because `withOptions` constructs a fresh
|
|
166
|
+
* client; its options never change, so one per `Tools` instance suffices.
|
|
167
|
+
*/
|
|
168
|
+
private get clientWithoutRetries(): ComposioClient {
|
|
169
|
+
if (!this.clientWithoutRetriesCache) {
|
|
170
|
+
this.clientWithoutRetriesCache = this.client.withOptions({ maxRetries: 0 });
|
|
171
|
+
}
|
|
172
|
+
return this.clientWithoutRetriesCache;
|
|
173
|
+
}
|
|
174
|
+
|
|
149
175
|
/**
|
|
150
176
|
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
151
177
|
*
|
|
@@ -919,7 +945,9 @@ export class Tools<
|
|
|
919
945
|
text: body.text,
|
|
920
946
|
};
|
|
921
947
|
const result = await withCancellation(
|
|
922
|
-
|
|
948
|
+
// Disable retries: tool execution is a non-idempotent write, and a
|
|
949
|
+
// silent retry after a read timeout can duplicate the side effect.
|
|
950
|
+
() => this.clientWithoutRetries.tools.execute(tool.slug, executeBody, requestOptions),
|
|
923
951
|
requestOptions?.signal
|
|
924
952
|
);
|
|
925
953
|
// transform the response to the ToolExecuteResponse format
|
|
@@ -1253,7 +1281,9 @@ export class Tools<
|
|
|
1253
1281
|
custom_connection_data: toolProxyParams.data.customConnectionData,
|
|
1254
1282
|
} as ComposioToolProxyParams;
|
|
1255
1283
|
return withCancellation(
|
|
1256
|
-
|
|
1284
|
+
// Disable retries: a proxied call is a non-idempotent write, and a silent
|
|
1285
|
+
// retry after a read timeout can duplicate the side effect.
|
|
1286
|
+
() => this.clientWithoutRetries.tools.proxy(proxyBody, requestOptions),
|
|
1257
1287
|
requestOptions?.signal
|
|
1258
1288
|
);
|
|
1259
1289
|
}
|
package/src/models/Triggers.ts
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
} from '../types/triggers.types';
|
|
41
41
|
import logger from '../utils/logger';
|
|
42
42
|
import { telemetry } from '../telemetry/Telemetry';
|
|
43
|
-
import {
|
|
43
|
+
import { ValidationError } from '../errors';
|
|
44
44
|
import { PusherService } from '../services/pusher/Pusher';
|
|
45
45
|
import {
|
|
46
46
|
ComposioTriggerTypeNotFoundError,
|
|
@@ -328,6 +328,10 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
328
328
|
body?: TriggerInstanceUpsertParams,
|
|
329
329
|
requestOptions?: ComposioRequestOptions
|
|
330
330
|
): Promise<TriggerInstanceUpsertResponse> {
|
|
331
|
+
if (!userId?.trim()) {
|
|
332
|
+
throw new ValidationError(`A non-empty userId is required to create a trigger`);
|
|
333
|
+
}
|
|
334
|
+
|
|
331
335
|
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body ?? {});
|
|
332
336
|
|
|
333
337
|
if (!parsedBody.success) {
|
|
@@ -336,14 +340,12 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
336
340
|
});
|
|
337
341
|
}
|
|
338
342
|
|
|
339
|
-
//
|
|
340
|
-
|
|
341
|
-
let toolkitSlug: string;
|
|
343
|
+
// Validate the trigger slug up-front so callers get a clear client-side
|
|
344
|
+
// `ComposioTriggerTypeNotFoundError`. The Python SDK mirrors this behavior.
|
|
342
345
|
try {
|
|
343
|
-
|
|
344
|
-
toolkitSlug = triggerType.toolkit.slug;
|
|
346
|
+
await this.getType(slug, requestOptions);
|
|
345
347
|
} catch (error) {
|
|
346
|
-
//
|
|
348
|
+
// The trigger types endpoint returns 400 (not 404) for an unknown slug.
|
|
347
349
|
if (error instanceof APIError && (error.status === 400 || error.status === 404)) {
|
|
348
350
|
throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {
|
|
349
351
|
cause: error,
|
|
@@ -353,79 +355,17 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
353
355
|
`Visit the toolkit page to see the available triggers`,
|
|
354
356
|
],
|
|
355
357
|
});
|
|
356
|
-
} else {
|
|
357
|
-
throw error;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// Attempt to get connected account ID
|
|
362
|
-
let connectedAccountId: string | undefined = body?.connectedAccountId;
|
|
363
|
-
|
|
364
|
-
try {
|
|
365
|
-
const connectedAccountListParams = {
|
|
366
|
-
user_ids: [userId],
|
|
367
|
-
toolkit_slugs: [toolkitSlug],
|
|
368
|
-
};
|
|
369
|
-
const { items: connectedAccounts } = await withCancellation(
|
|
370
|
-
() => this.client.connectedAccounts.list(connectedAccountListParams, requestOptions),
|
|
371
|
-
requestOptions?.signal
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
if (connectedAccounts.length === 0) {
|
|
375
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
376
|
-
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
377
|
-
{
|
|
378
|
-
cause: new Error(`No connected account found for user ${userId}`),
|
|
379
|
-
possibleFixes: [`Create a new connected account for user ${userId}`],
|
|
380
|
-
}
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const accountExists = connectedAccounts.some(acc => acc.id === connectedAccountId);
|
|
385
|
-
// if the connected account id is provided and it does not exist, throw an error
|
|
386
|
-
if (connectedAccountId && !accountExists) {
|
|
387
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
388
|
-
`Connected account ID ${connectedAccountId} not found for user ${userId}`,
|
|
389
|
-
{
|
|
390
|
-
cause: new Error(
|
|
391
|
-
`Connected account ID ${connectedAccountId} not found for user ${userId}`
|
|
392
|
-
),
|
|
393
|
-
possibleFixes: [
|
|
394
|
-
`Create a new connected account for user ${userId}`,
|
|
395
|
-
`Verify the connected account ID`,
|
|
396
|
-
],
|
|
397
|
-
}
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// if the connected account id is not provided, use the first connected account
|
|
402
|
-
if (!connectedAccountId) {
|
|
403
|
-
connectedAccountId = connectedAccounts[0].id;
|
|
404
|
-
logger.warn(
|
|
405
|
-
`[Warn] Multiple connected accounts found for user ${userId}, using the first one. Pass connectedAccountId to select a specific account.`
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
} catch (error) {
|
|
409
|
-
if (error instanceof APIError && [400, 404].includes(error.status)) {
|
|
410
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
411
|
-
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
412
|
-
{
|
|
413
|
-
cause: error,
|
|
414
|
-
possibleFixes: [`Create a new connected account for user ${userId}`],
|
|
415
|
-
}
|
|
416
|
-
);
|
|
417
358
|
}
|
|
418
359
|
throw error;
|
|
419
360
|
}
|
|
420
361
|
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
-
//
|
|
424
|
-
//
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
connected_account_id: connectedAccountId,
|
|
362
|
+
// Pass `user_id` straight through: when `connected_account_id` is omitted the
|
|
363
|
+
// backend resolves the first active connection for this user and the
|
|
364
|
+
// trigger's toolkit, mirroring tool execution. When 2FA is enabled and
|
|
365
|
+
// `connected_account_id` is pinned, the backend validates that `user_id`
|
|
366
|
+
// owns it.
|
|
367
|
+
const upsertParams: ClientTriggerInstanceUpsertParams = {
|
|
368
|
+
connected_account_id: parsedBody.data.connectedAccountId,
|
|
429
369
|
trigger_config: parsedBody.data.triggerConfig,
|
|
430
370
|
toolkit_versions: this.toolkitVersions,
|
|
431
371
|
user_id: userId,
|
package/src/platform/node.ts
CHANGED
package/src/platform/types.ts
CHANGED
|
@@ -42,6 +42,16 @@ export interface Platform {
|
|
|
42
42
|
*/
|
|
43
43
|
existsSync(filePath: string): boolean;
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Resolves symlinks in a path, returning the canonical absolute path. On Node
|
|
47
|
+
* this is `fs.realpathSync`; on edge runtimes without a filesystem it returns
|
|
48
|
+
* the input path unchanged (best-effort). Used to prevent a symlink from
|
|
49
|
+
* smuggling an upload past the sensitive-path denylist.
|
|
50
|
+
* @param filePath - The path to canonicalize.
|
|
51
|
+
* @returns The resolved path, or the input path if it cannot be resolved.
|
|
52
|
+
*/
|
|
53
|
+
realpathSync(filePath: string): string;
|
|
54
|
+
|
|
45
55
|
/**
|
|
46
56
|
* Creates a directory at the given path, including parent directories if needed.
|
|
47
57
|
* @param dirPath - The directory path to create.
|
package/src/platform/workerd.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import type { Platform, Uint8ArrayEncoding } from './types';
|
|
2
2
|
|
|
3
|
+
const SLASH_CHAR_CODE = 47; // '/'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Trailing-slash trim without a regex. The equivalent pattern backtracks
|
|
7
|
+
* quadratically on long runs of slashes (CodeQL js/polynomial-redos), so this
|
|
8
|
+
* walks the string from the end instead. Returns the input unchanged when
|
|
9
|
+
* there is nothing to trim, so the common case allocates nothing.
|
|
10
|
+
*/
|
|
11
|
+
const trimTrailingSlashes = (value: string): string => {
|
|
12
|
+
let end = value.length;
|
|
13
|
+
while (end > 0 && value.charCodeAt(end - 1) === SLASH_CHAR_CODE) end--;
|
|
14
|
+
return end === value.length ? value : value.slice(0, end);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Leading-and-trailing slash trim without a regex, matching the semantics of
|
|
19
|
+
* the previous leading/trailing slash-trim replace for every input, including
|
|
20
|
+
* a string that is entirely slashes.
|
|
21
|
+
*/
|
|
22
|
+
const trimSurroundingSlashes = (value: string): string => {
|
|
23
|
+
let start = 0;
|
|
24
|
+
let end = value.length;
|
|
25
|
+
while (start < end && value.charCodeAt(start) === SLASH_CHAR_CODE) start++;
|
|
26
|
+
while (end > start && value.charCodeAt(end - 1) === SLASH_CHAR_CODE) end--;
|
|
27
|
+
return start === 0 && end === value.length ? value : value.slice(start, end);
|
|
28
|
+
};
|
|
29
|
+
|
|
3
30
|
/**
|
|
4
31
|
* Cloudflare Workers / Edge runtime platform implementation.
|
|
5
32
|
* Provides stub implementations for file system operations that are unavailable in edge runtimes.
|
|
@@ -18,9 +45,9 @@ export const platform: Platform = {
|
|
|
18
45
|
return paths
|
|
19
46
|
.map((segment, index) => {
|
|
20
47
|
if (index === 0) {
|
|
21
|
-
return segment
|
|
48
|
+
return trimTrailingSlashes(segment);
|
|
22
49
|
}
|
|
23
|
-
return segment
|
|
50
|
+
return trimSurroundingSlashes(segment);
|
|
24
51
|
})
|
|
25
52
|
.filter(Boolean)
|
|
26
53
|
.join('/');
|
|
@@ -40,7 +67,7 @@ export const platform: Platform = {
|
|
|
40
67
|
|
|
41
68
|
basename(filePath: string): string {
|
|
42
69
|
// Simple basename extraction without Node.js path module
|
|
43
|
-
const segments = filePath
|
|
70
|
+
const segments = trimTrailingSlashes(filePath).split('/');
|
|
44
71
|
return segments[segments.length - 1] || '';
|
|
45
72
|
},
|
|
46
73
|
|
|
@@ -49,6 +76,12 @@ export const platform: Platform = {
|
|
|
49
76
|
return false;
|
|
50
77
|
},
|
|
51
78
|
|
|
79
|
+
realpathSync(filePath: string): string {
|
|
80
|
+
// No filesystem in edge runtimes: cannot resolve symlinks, so return the
|
|
81
|
+
// input unchanged. Local-path uploads don't happen on workerd anyway.
|
|
82
|
+
return filePath;
|
|
83
|
+
},
|
|
84
|
+
|
|
52
85
|
mkdirSync(_dirPath: string): void {
|
|
53
86
|
// No-op in edge runtimes - directories cannot be created
|
|
54
87
|
},
|
|
@@ -16,6 +16,7 @@ import { ExecuteToolModifiers } from '../types/modifiers.types';
|
|
|
16
16
|
import { ExecuteToolFnOptions } from '../types/provider.types';
|
|
17
17
|
import { McpUrlResponse, McpServerGetResponse } from '../types/mcp.types';
|
|
18
18
|
import { normalizeToolArguments } from '../utils/toolArguments';
|
|
19
|
+
import { deduplicateJsonSchemaRequiredArrays } from '../utils/jsonSchema';
|
|
19
20
|
|
|
20
21
|
export type OpenAiTool = OpenAI.ChatCompletionTool;
|
|
21
22
|
export type OpenAiToolCollection = Array<OpenAiTool>;
|
|
@@ -96,7 +97,7 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
96
97
|
const formattedSchema: OpenAI.FunctionDefinition = {
|
|
97
98
|
name: tool.slug,
|
|
98
99
|
description: tool.description,
|
|
99
|
-
parameters: tool.inputParameters,
|
|
100
|
+
parameters: deduplicateJsonSchemaRequiredArrays(tool.inputParameters),
|
|
100
101
|
};
|
|
101
102
|
return {
|
|
102
103
|
type: 'function',
|
|
@@ -246,20 +247,24 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
246
247
|
modifiers?: ExecuteToolModifiers
|
|
247
248
|
): Promise<OpenAI.ChatCompletionToolMessageParam[]> {
|
|
248
249
|
const outputs: OpenAI.ChatCompletionToolMessageParam[] = [];
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
content: toolResult,
|
|
261
|
-
});
|
|
250
|
+
// Only the first choice is actionable: its tool results feed back into a
|
|
251
|
+
// single assistant turn. With n > 1, iterating every choice would run each
|
|
252
|
+
// tool call once per choice and orphan the tool_call_ids belonging to the
|
|
253
|
+
// alternative completions.
|
|
254
|
+
const [choice] = chatCompletion.choices;
|
|
255
|
+
// A single assistant message can carry several tool calls (parallel tool
|
|
256
|
+
// calls, on by default). Each one needs its own tool result, otherwise the
|
|
257
|
+
// next request fails since some tool_call_ids go unanswered.
|
|
258
|
+
for (const toolCall of choice?.message.tool_calls ?? []) {
|
|
259
|
+
if (toolCall.type !== 'function') {
|
|
260
|
+
continue;
|
|
262
261
|
}
|
|
262
|
+
const toolResult = await this.executeToolCall(userId, toolCall, options, modifiers);
|
|
263
|
+
outputs.push({
|
|
264
|
+
role: 'tool',
|
|
265
|
+
tool_call_id: toolCall.id,
|
|
266
|
+
content: toolResult,
|
|
267
|
+
});
|
|
263
268
|
}
|
|
264
269
|
return outputs;
|
|
265
270
|
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from '../services/telemetry/TelemetryService.types';
|
|
19
19
|
import { TelemetryService } from '../services/telemetry/TelemetryService';
|
|
20
20
|
import logger from '../utils/logger';
|
|
21
|
+
import { redactSensitiveText } from './redact';
|
|
21
22
|
/**
|
|
22
23
|
* The Telemetry class is used to log the telemetry for any given instance which extends InstrumentedInstance.
|
|
23
24
|
*
|
|
@@ -207,28 +208,30 @@ export class TelemetryTransport {
|
|
|
207
208
|
},
|
|
208
209
|
source: this.telemetrySource,
|
|
209
210
|
};
|
|
211
|
+
// Redact secrets (URLs with tokens, Authorization headers, API keys, etc.)
|
|
212
|
+
// from free-form error text before it is transported off-process.
|
|
210
213
|
// client error, this is likely handled by the API itseld
|
|
211
214
|
if (error instanceof ComposioClientError) {
|
|
212
215
|
telemetryPayload.error = {
|
|
213
216
|
errorId: error.errorId,
|
|
214
217
|
name: error.name,
|
|
215
|
-
message: error.message,
|
|
216
|
-
stack: error.stack,
|
|
218
|
+
message: redactSensitiveText(error.message),
|
|
219
|
+
stack: redactSensitiveText(error.stack),
|
|
217
220
|
};
|
|
218
221
|
} else if (error instanceof ComposioError) {
|
|
219
222
|
telemetryPayload.error = {
|
|
220
223
|
errorId: error.errorId,
|
|
221
224
|
name: error.name,
|
|
222
225
|
code: error.code,
|
|
223
|
-
message: error.message,
|
|
224
|
-
stack: error.stack,
|
|
226
|
+
message: redactSensitiveText(error.message),
|
|
227
|
+
stack: redactSensitiveText(error.stack),
|
|
225
228
|
};
|
|
226
229
|
} else if (error instanceof Error) {
|
|
227
230
|
telemetryPayload.error = {
|
|
228
231
|
errorId: error.errorId,
|
|
229
232
|
name: error.name ?? 'Unknown error',
|
|
230
|
-
message: error.message,
|
|
231
|
-
stack: error.stack,
|
|
233
|
+
message: redactSensitiveText(error.message),
|
|
234
|
+
stack: redactSensitiveText(error.stack),
|
|
232
235
|
};
|
|
233
236
|
}
|
|
234
237
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort redaction of secrets from free-form error text before it is sent
|
|
3
|
+
* to the telemetry endpoint.
|
|
4
|
+
*
|
|
5
|
+
* Error `message` and `stack` fields routinely interpolate URLs (with
|
|
6
|
+
* query-string tokens / presigned signatures), `Authorization` headers, API
|
|
7
|
+
* keys, and connected-account identifiers. None of that should leave the
|
|
8
|
+
* process. Structured telemetry fields never carry raw secrets, so only the two
|
|
9
|
+
* free-form strings are passed through here.
|
|
10
|
+
*
|
|
11
|
+
* This is defence-in-depth, not a proof: it targets the shapes we have seen
|
|
12
|
+
* leak. When in doubt it over-redacts rather than under-redacts.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const REDACTED = '[REDACTED]';
|
|
16
|
+
|
|
17
|
+
const REDACTION_RULES: ReadonlyArray<readonly [RegExp, string]> = [
|
|
18
|
+
// URL query strings — tokens, presigned signatures, one-time codes.
|
|
19
|
+
[/(\bhttps?:\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`],
|
|
20
|
+
// Authorization scheme + credential: `Bearer <token>`, `Basic <token>`.
|
|
21
|
+
[/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
|
|
22
|
+
// Secret-ish `key: value` / `key=value` / `key: "value"` / `key: 'value'` pairs.
|
|
23
|
+
[
|
|
24
|
+
/\b(authorization|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd)\b(\s*[:=]+\s*)(["']?)([^\s"',}&]+)\3/gi,
|
|
25
|
+
`$1$2$3${REDACTED}$3`,
|
|
26
|
+
],
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Redact common secret shapes from a free-form string. Returns the input
|
|
31
|
+
* unchanged when it is empty or `undefined`.
|
|
32
|
+
*/
|
|
33
|
+
export const redactSensitiveText = (input: string | undefined): string | undefined => {
|
|
34
|
+
if (!input) return input;
|
|
35
|
+
let output = input;
|
|
36
|
+
for (const [pattern, replacement] of REDACTION_RULES) {
|
|
37
|
+
output = output.replace(pattern, replacement);
|
|
38
|
+
}
|
|
39
|
+
return output;
|
|
40
|
+
};
|