@composio/core 0.27.0 → 0.28.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-CqPoLUD6.d.mts → CustomTool-DyypijT6.d.mts} +2 -2
- package/dist/{Telemetry-41JkqpZ7.mjs → Telemetry-D2PJwXKx.mjs} +1 -1
- package/dist/{composio-BUa10iB3.d.mts → composio-CwHMpKXb.d.mts} +704 -26
- package/dist/{customTool.types-gX421uPT.d.mts → customTool.types-DoItUHkO.d.mts} +11 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +3 -3
- package/dist/experimental/index.d.mts +2 -2
- package/dist/{fileUtils.node-DNLhLg0W.mjs → fileUtils.node-ILI1IjnZ.mjs} +4 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2107 -1977
- package/dist/models/Files.node.mjs +2 -2
- package/dist/sensitiveFileUploadPaths-BaEORC7-.mjs +588 -0
- package/dist/{types-DXxfzBX3.d.mts → types-DWZWePfZ.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/package.json +7 -6
- package/src/lib/toolRouterParams.ts +28 -33
- package/src/lib/toolRouterSessionDelete.ts +1 -10
- package/src/models/ConnectedAccounts.ts +1 -1
- package/src/models/CustomTool.ts +1 -1
- package/src/models/CustomToolkits.ts +114 -8
- package/src/models/Experimental.ts +1 -1
- package/src/models/MCP.ts +1 -2
- package/src/models/SessionConfigs.ts +11 -3
- package/src/models/SessionContext.ts +4 -4
- package/src/models/ToolRouter.ts +2 -3
- package/src/models/ToolRouterSession.ts +17 -16
- package/src/models/Tools.ts +3 -3
- package/src/models/Triggers.ts +12 -5
- package/src/models/inlineCustomToolsPayload.ts +3 -3
- package/src/models/proxyParamsTransform.ts +1 -1
- package/src/types/customTool.types.ts +13 -5
- package/src/types/customToolkits.types.ts +89 -9
- package/src/types/sessionConfigs.types.ts +21 -7
- package/src/types/toolRouter.types.ts +14 -7
- package/src/types/triggers.types.ts +14 -0
- package/src/utils/fileUtils.node.ts +5 -2
- package/src/utils/mime.ts +347 -1
- package/src/utils/transformers/connectedAccounts.ts +2 -7
- package/src/utils/transformers/customToolkits.ts +78 -9
- package/src/utils/transformers/sessionConfigs.ts +3 -3
- package/src/utils/transformers/toolRouterResponseTransform.ts +23 -75
- package/src/utils/transformers/toolkits.ts +7 -13
- package/src/utils/transformers/triggers.ts +28 -18
- package/dist/sensitiveFileUploadPaths-BlLp-Yo2.mjs +0 -189
|
@@ -4,57 +4,28 @@
|
|
|
4
4
|
import type {
|
|
5
5
|
SessionExecuteResponse,
|
|
6
6
|
SessionProxyExecuteResponse,
|
|
7
|
-
} from '@composio/client/resources/tool-router/session
|
|
7
|
+
} from '@composio/client/resources/tool-router/session';
|
|
8
8
|
import z from 'zod/v3';
|
|
9
9
|
import { ComposioToolInputRequiredError } from '../../errors/ToolRouterErrors';
|
|
10
10
|
import { ValidationError } from '../../errors/ValidationErrors';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
import type {
|
|
12
|
+
ToolRouterBlockReason,
|
|
13
|
+
ToolRouterSessionExecuteResponse,
|
|
14
|
+
ToolRouterSessionProxyExecuteResponse,
|
|
15
15
|
} from '../../types/toolRouter.types';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* The `result_type` values of a call that ran. `input_required` and `blocked`
|
|
19
|
-
* are handled before this is read.
|
|
20
|
-
* so a shape drift there doesn't read as an unknown `result_type`.
|
|
19
|
+
* are handled before this is read.
|
|
21
20
|
*/
|
|
22
21
|
const ExecutedResponseSchema = z.object({
|
|
23
22
|
result_type: z.enum(['completed', 'failed']),
|
|
24
23
|
});
|
|
25
24
|
|
|
26
|
-
/**
|
|
27
|
-
const
|
|
28
|
-
result_type:
|
|
29
|
-
|
|
30
|
-
type: z.enum(['request_blocked', 'response_blocked']),
|
|
31
|
-
hook_id: z.string(),
|
|
32
|
-
}),
|
|
33
|
-
message: z.string(),
|
|
34
|
-
// Only session execute carries these; session proxy execute leaves them out.
|
|
35
|
-
log_id: z.string().optional(),
|
|
36
|
-
instant_charge: z.unknown().optional(),
|
|
37
|
-
hook_results: z.array(ToolRouterHookResultSchema).optional(),
|
|
38
|
-
});
|
|
39
|
-
type BlockedResponse = z.infer<typeof BlockedResponseSchema>;
|
|
40
|
-
|
|
41
|
-
const IsBlockedSchema = z.object({ result_type: z.literal('blocked') });
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Reads a `blocked` response, or returns `undefined` for any other
|
|
45
|
-
* `result_type`. A `blocked` response that does not match its schema is
|
|
46
|
-
* raised rather than read as a result.
|
|
47
|
-
*/
|
|
48
|
-
function parseBlockedResponse(raw: unknown, subject: string): BlockedResponse | undefined {
|
|
49
|
-
if (!IsBlockedSchema.safeParse(raw).success) return undefined;
|
|
50
|
-
const blocked = BlockedResponseSchema.safeParse(raw);
|
|
51
|
-
if (!blocked.success) {
|
|
52
|
-
throw new ValidationError(`${subject} returned a malformed blocked response`, {
|
|
53
|
-
cause: blocked.error,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return blocked.data;
|
|
57
|
-
}
|
|
25
|
+
/** The `reason` of a call a session hook blocked, in camelCase. */
|
|
26
|
+
const toBlockReason = (
|
|
27
|
+
reason: Extract<SessionExecuteResponse, { result_type: 'blocked' }>['reason']
|
|
28
|
+
): ToolRouterBlockReason => ({ type: reason.type, hookId: reason.hook_id });
|
|
58
29
|
|
|
59
30
|
/**
|
|
60
31
|
* Whether a session tool execution succeeded. `resultType` decides: a `failed`
|
|
@@ -251,25 +222,24 @@ export function transformSearchResponse(raw: RawSearchResponse) {
|
|
|
251
222
|
* Transforms a raw session execute API response to camelCase.
|
|
252
223
|
*
|
|
253
224
|
* @throws {ComposioToolInputRequiredError} If the tool asked for user input instead of running
|
|
254
|
-
* @throws {ValidationError} If the response carries no `result_type`, one this SDK does not know
|
|
225
|
+
* @throws {ValidationError} If the response carries no `result_type`, or one this SDK does not know
|
|
255
226
|
*/
|
|
256
227
|
export function transformExecuteResponse(
|
|
257
228
|
raw: SessionExecuteResponse,
|
|
258
229
|
toolSlug: string
|
|
259
230
|
): ToolRouterSessionExecuteResponse {
|
|
260
231
|
assertNotInputRequired(raw, `Tool ${toolSlug}`);
|
|
261
|
-
|
|
262
|
-
if (blocked) {
|
|
232
|
+
if (raw.result_type === 'blocked') {
|
|
263
233
|
// The agent reads `error`, so a blocked call reaches it as a failed call
|
|
264
234
|
// with the hook's message.
|
|
265
235
|
return {
|
|
266
236
|
data: {},
|
|
267
|
-
error:
|
|
268
|
-
logId:
|
|
237
|
+
error: raw.message,
|
|
238
|
+
logId: raw.log_id ?? '',
|
|
269
239
|
resultType: 'blocked',
|
|
270
|
-
blockReason:
|
|
271
|
-
...(
|
|
272
|
-
...(
|
|
240
|
+
blockReason: toBlockReason(raw.reason),
|
|
241
|
+
...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
|
|
242
|
+
...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
|
|
273
243
|
};
|
|
274
244
|
}
|
|
275
245
|
const executed = ExecutedResponseSchema.safeParse(raw);
|
|
@@ -279,29 +249,16 @@ export function transformExecuteResponse(
|
|
|
279
249
|
{ cause: executed.error }
|
|
280
250
|
);
|
|
281
251
|
}
|
|
282
|
-
const hookResults = CompletedHookResultsSchema.safeParse(raw);
|
|
283
|
-
if (!hookResults.success) {
|
|
284
|
-
throw new ValidationError(`Tool ${toolSlug} returned malformed hook results`, {
|
|
285
|
-
cause: hookResults.error,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
252
|
return {
|
|
289
253
|
data: raw.data,
|
|
290
254
|
error: raw.error,
|
|
291
255
|
logId: raw.log_id,
|
|
292
256
|
resultType: executed.data.result_type,
|
|
293
257
|
...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
|
|
294
|
-
...(
|
|
295
|
-
hookResults: hookResults.data.hook_results,
|
|
296
|
-
}),
|
|
258
|
+
...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
|
|
297
259
|
};
|
|
298
260
|
}
|
|
299
261
|
|
|
300
|
-
/** Hook results on a call that ran: session execute, or a proxied request that was sent. */
|
|
301
|
-
const CompletedHookResultsSchema = z.object({
|
|
302
|
-
hook_results: z.array(ToolRouterHookResultSchema).optional(),
|
|
303
|
-
});
|
|
304
|
-
|
|
305
262
|
/**
|
|
306
263
|
* Projects a session proxy execute response onto the SDK's shape: a request a
|
|
307
264
|
* session hook blocked comes back as `resultType: 'blocked'` with no HTTP
|
|
@@ -312,21 +269,14 @@ export function transformProxyExecuteResponse(
|
|
|
312
269
|
subject: string
|
|
313
270
|
): ToolRouterSessionProxyExecuteResponse {
|
|
314
271
|
assertNotInputRequired(raw, subject);
|
|
315
|
-
|
|
316
|
-
if (blocked) {
|
|
272
|
+
if (raw.result_type === 'blocked') {
|
|
317
273
|
return {
|
|
318
274
|
resultType: 'blocked',
|
|
319
|
-
blockReason:
|
|
320
|
-
message:
|
|
321
|
-
...(
|
|
275
|
+
blockReason: toBlockReason(raw.reason),
|
|
276
|
+
message: raw.message,
|
|
277
|
+
...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
|
|
322
278
|
};
|
|
323
279
|
}
|
|
324
|
-
const hookResults = CompletedHookResultsSchema.safeParse(raw);
|
|
325
|
-
if (!hookResults.success) {
|
|
326
|
-
throw new ValidationError(`${subject} returned malformed hook results`, {
|
|
327
|
-
cause: hookResults.error,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
280
|
return {
|
|
331
281
|
resultType: 'completed',
|
|
332
282
|
status: raw.status,
|
|
@@ -340,8 +290,6 @@ export function transformProxyExecuteResponse(
|
|
|
340
290
|
expiresAt: raw.binary_data.expires_at,
|
|
341
291
|
},
|
|
342
292
|
}),
|
|
343
|
-
...(
|
|
344
|
-
hookResults: hookResults.data.hook_results,
|
|
345
|
-
}),
|
|
293
|
+
...(raw.hook_results !== undefined && { hookResults: raw.hook_results }),
|
|
346
294
|
};
|
|
347
295
|
}
|
|
@@ -2,19 +2,13 @@ import {
|
|
|
2
2
|
ToolkitRetrieveResponse as RawToolkitRetrieveResponse,
|
|
3
3
|
ToolkitListResponse as RawToolkitListResponse,
|
|
4
4
|
ToolkitRetrieveCategoriesResponse as RawToolkitRetrieveCategoriesResponse,
|
|
5
|
-
type
|
|
5
|
+
type ToolkitRetrieveChangelogResponse as RawToolkitRetrieveChangelogResponse,
|
|
6
|
+
type ToolkitRetrieveMultiResponse as RawToolkitRetrieveMultiResponse,
|
|
7
|
+
type ToolkitRecommendScopesParams as RawToolkitRecommendScopesParams,
|
|
8
|
+
type ToolkitRecommendScopesResponse as RawToolkitRecommendScopesResponse,
|
|
9
|
+
type ToolkitRetrieveScopesGrantContextParams as RawToolkitRetrieveScopesGrantContextParams,
|
|
10
|
+
type ToolkitRetrieveScopesGrantContextResponse as RawToolkitRetrieveScopesGrantContextResponse,
|
|
6
11
|
} from '@composio/client/resources/toolkits';
|
|
7
|
-
|
|
8
|
-
// The `/toolkits/multi` and `/toolkits/changelog` response types are only
|
|
9
|
-
// reachable through the resource class namespace on the published subpath.
|
|
10
|
-
type RawToolkitRetrieveChangelogResponse = ClientToolkits.ToolkitRetrieveChangelogResponse;
|
|
11
|
-
type RawToolkitRetrieveMultiResponse = ClientToolkits.ToolkitRetrieveMultiResponse;
|
|
12
|
-
type RawToolkitRecommendScopesParams = ClientToolkits.ToolkitRecommendScopesParams;
|
|
13
|
-
type RawToolkitRecommendScopesResponse = ClientToolkits.ToolkitRecommendScopesResponse;
|
|
14
|
-
type RawToolkitRetrieveScopesGrantContextParams =
|
|
15
|
-
ClientToolkits.ToolkitRetrieveScopesGrantContextParams;
|
|
16
|
-
type RawToolkitRetrieveScopesGrantContextResponse =
|
|
17
|
-
ClientToolkits.ToolkitRetrieveScopesGrantContextResponse;
|
|
18
12
|
import {
|
|
19
13
|
ToolKitListResponse,
|
|
20
14
|
ToolKitListResponseSchema,
|
|
@@ -158,7 +152,7 @@ export const transformToolkitRetrieveResponse = (
|
|
|
158
152
|
name: category.name,
|
|
159
153
|
})),
|
|
160
154
|
availableVersions: response.meta.available_versions,
|
|
161
|
-
|
|
155
|
+
...(response.meta.app_url != null && { appUrl: response.meta.app_url }),
|
|
162
156
|
},
|
|
163
157
|
isLocalToolkit: response.is_local_toolkit,
|
|
164
158
|
composioManagedAuthSchemes: response.composio_managed_auth_schemes,
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
TriggersTypeRetrieveResponse as RawTriggersTypeRetrieveResponse,
|
|
3
3
|
TriggersTypeListResponse as RawTriggersTypeListResponse,
|
|
4
4
|
} from '@composio/client/resources/triggers-types';
|
|
5
|
-
import { TriggerInstanceListActiveResponse as RawTriggerInstanceListActiveResponse } from '@composio/client/resources/
|
|
5
|
+
import { TriggerInstanceListActiveResponse as RawTriggerInstanceListActiveResponse } from '@composio/client/resources/trigger-instances';
|
|
6
6
|
import {
|
|
7
7
|
IncomingTriggerPayload,
|
|
8
8
|
IncomingTriggerPayloadSchema,
|
|
@@ -48,25 +48,32 @@ export function transformIncomingTriggerPayload(response: TriggerData): Incoming
|
|
|
48
48
|
}));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function toTriggerType(
|
|
52
|
+
response: RawTriggersTypeRetrieveResponse | RawTriggersTypeListResponse['items'][number]
|
|
53
|
+
): TriggersTypeRetrieveResponse {
|
|
54
|
+
return {
|
|
55
|
+
slug: response.slug,
|
|
56
|
+
name: response.name,
|
|
57
|
+
description: response.description,
|
|
58
|
+
instructions: response.instructions,
|
|
59
|
+
toolkit: {
|
|
60
|
+
logo: response.toolkit.logo,
|
|
61
|
+
slug: response.toolkit.slug,
|
|
62
|
+
name: response.toolkit.name,
|
|
63
|
+
},
|
|
64
|
+
version: response.version,
|
|
65
|
+
payload: response.payload,
|
|
66
|
+
config: response.config,
|
|
67
|
+
type: response.type,
|
|
68
|
+
types: response.types,
|
|
69
|
+
requiresWebhookEndpointSetup: response.requires_webhook_endpoint_setup,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
51
73
|
export function transformTriggerTypeRetrieveResponse(
|
|
52
74
|
response: RawTriggersTypeRetrieveResponse
|
|
53
75
|
): TriggersTypeRetrieveResponse {
|
|
54
|
-
return transform(response)
|
|
55
|
-
.with(TriggerTypeSchema)
|
|
56
|
-
.using(response => ({
|
|
57
|
-
slug: response.slug,
|
|
58
|
-
name: response.name,
|
|
59
|
-
description: response.description,
|
|
60
|
-
instructions: response.instructions,
|
|
61
|
-
toolkit: {
|
|
62
|
-
logo: response.toolkit.logo,
|
|
63
|
-
slug: response.toolkit.slug,
|
|
64
|
-
name: response.toolkit.name,
|
|
65
|
-
},
|
|
66
|
-
version: response.version,
|
|
67
|
-
payload: response.payload,
|
|
68
|
-
config: response.config,
|
|
69
|
-
}));
|
|
76
|
+
return transform(response).with(TriggerTypeSchema).using(toTriggerType);
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
export function transformTriggerTypeListResponse(
|
|
@@ -75,7 +82,7 @@ export function transformTriggerTypeListResponse(
|
|
|
75
82
|
return transform(response)
|
|
76
83
|
.with(TriggersTypeListResponseSchema)
|
|
77
84
|
.using(response => ({
|
|
78
|
-
items: response.items,
|
|
85
|
+
items: response.items.map(toTriggerType),
|
|
79
86
|
nextCursor: response.next_cursor ?? null,
|
|
80
87
|
totalPages: response.total_pages,
|
|
81
88
|
}));
|
|
@@ -102,6 +109,9 @@ export function transformTriggerInstanceListActiveItem(
|
|
|
102
109
|
updatedAt: response.updated_at,
|
|
103
110
|
triggerData: response.trigger_data,
|
|
104
111
|
uuid: response.uuid,
|
|
112
|
+
type: response.type,
|
|
113
|
+
fallbackReason: response.fallback_reason,
|
|
114
|
+
pollingInterval: response.polling_interval,
|
|
105
115
|
}));
|
|
106
116
|
}
|
|
107
117
|
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { a as ComposioSensitiveFilePathBlockedError } from "./FileModifierErrors-CdGSABoq.mjs";
|
|
2
|
-
import { platform } from "#platform";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/uuid.ts
|
|
5
|
-
function getRandomUUID() {
|
|
6
|
-
return globalThis.crypto.randomUUID();
|
|
7
|
-
}
|
|
8
|
-
function getRandomShortId() {
|
|
9
|
-
return getRandomUUID().slice(0, 8).replace(/-/g, "");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/utils/buffer.ts
|
|
14
|
-
/**
|
|
15
|
-
* Convert ArrayBuffer to base64.
|
|
16
|
-
*/
|
|
17
|
-
function arrayBufferToBase64(buffer) {
|
|
18
|
-
const bytes = new Uint8Array(buffer);
|
|
19
|
-
let binary = "";
|
|
20
|
-
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
21
|
-
return btoa(binary);
|
|
22
|
-
}
|
|
23
|
-
const base64ToUint8Array = (base64) => {
|
|
24
|
-
const binary = atob(base64);
|
|
25
|
-
const bytes = new Uint8Array(binary.length);
|
|
26
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
27
|
-
return bytes;
|
|
28
|
-
};
|
|
29
|
-
const uint8ArrayToBase64 = (bytes) => {
|
|
30
|
-
let binary = "";
|
|
31
|
-
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
32
|
-
return btoa(binary);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/utils/readResponseBody.ts
|
|
37
|
-
/** Maximum size accepted for files fetched from user-supplied URLs (100 MiB). */
|
|
38
|
-
const MAX_URL_UPLOAD_SIZE_BYTES = 104857600;
|
|
39
|
-
const sizeLimitError = (actualSize, maxBytes) => /* @__PURE__ */ new Error(`File size (${actualSize} bytes) exceeds maximum allowed size (${maxBytes} bytes)`);
|
|
40
|
-
/**
|
|
41
|
-
* Read a fetch response without allowing an untrusted server to exhaust memory.
|
|
42
|
-
*
|
|
43
|
-
* `Content-Length` is checked as an early rejection, but the streamed byte
|
|
44
|
-
* count is authoritative because the header can be absent or dishonest.
|
|
45
|
-
*/
|
|
46
|
-
const readResponseBodyWithLimit = async (response, maxBytes = MAX_URL_UPLOAD_SIZE_BYTES) => {
|
|
47
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) throw new RangeError("maxBytes must be a non-negative safe integer");
|
|
48
|
-
const contentLength = response.headers.get("content-length")?.trim();
|
|
49
|
-
if (contentLength && /^\d+$/.test(contentLength)) {
|
|
50
|
-
const declaredSize = Number(contentLength);
|
|
51
|
-
if (!Number.isSafeInteger(declaredSize) || declaredSize > maxBytes) {
|
|
52
|
-
const error = sizeLimitError(declaredSize, maxBytes);
|
|
53
|
-
await response.body?.cancel(error).catch(() => void 0);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (!response.body) return /* @__PURE__ */ new Uint8Array();
|
|
58
|
-
const reader = response.body.getReader();
|
|
59
|
-
const chunks = [];
|
|
60
|
-
let totalBytes = 0;
|
|
61
|
-
try {
|
|
62
|
-
while (true) {
|
|
63
|
-
const { done, value } = await reader.read();
|
|
64
|
-
if (done) break;
|
|
65
|
-
if (!value || value.byteLength === 0) continue;
|
|
66
|
-
totalBytes += value.byteLength;
|
|
67
|
-
if (totalBytes > maxBytes) {
|
|
68
|
-
await reader.cancel(sizeLimitError(totalBytes, maxBytes));
|
|
69
|
-
throw sizeLimitError(totalBytes, maxBytes);
|
|
70
|
-
}
|
|
71
|
-
chunks.push(value);
|
|
72
|
-
}
|
|
73
|
-
} finally {
|
|
74
|
-
reader.releaseLock();
|
|
75
|
-
}
|
|
76
|
-
const body = new Uint8Array(totalBytes);
|
|
77
|
-
let offset = 0;
|
|
78
|
-
for (const chunk of chunks) {
|
|
79
|
-
body.set(chunk, offset);
|
|
80
|
-
offset += chunk.byteLength;
|
|
81
|
-
}
|
|
82
|
-
return body;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/utils/sensitiveFileUploadPaths.ts
|
|
87
|
-
/**
|
|
88
|
-
* Blocks accidental upload of local files from well-known secret/credential locations
|
|
89
|
-
* during auto file upload (and {@link getFileDataAfterUploadingToS3}).
|
|
90
|
-
*
|
|
91
|
-
* This is the single canonical guard shared by the core SDK and downstream
|
|
92
|
-
* packages (e.g. `@composio/cli`). Filesystem access goes through the `#platform`
|
|
93
|
-
* abstraction so this module stays free of static `node:*` imports and is safe to
|
|
94
|
-
* re-export from the package root (edge/workerd builds included).
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* Path segments (a single path component) that indicate a sensitive directory when
|
|
98
|
-
* they appear anywhere in a resolved local path. Matching follows the case sensitivity
|
|
99
|
-
* of the filesystem containing that path.
|
|
100
|
-
*/
|
|
101
|
-
const BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS = [
|
|
102
|
-
".ssh",
|
|
103
|
-
".aws",
|
|
104
|
-
".azure",
|
|
105
|
-
".gnupg",
|
|
106
|
-
".kube",
|
|
107
|
-
".docker",
|
|
108
|
-
".claude",
|
|
109
|
-
".password-store",
|
|
110
|
-
"keychains"
|
|
111
|
-
];
|
|
112
|
-
const SECRET_LIKE_BASENAME = /^(\.env(\.|$)|\.netrc$|\.pgpass$)/i;
|
|
113
|
-
/** Default SSH private key basenames (public keys like id_rsa.pub are allowed). */
|
|
114
|
-
const DEFAULT_PRIVATE_KEY_BASENAME = /^id_(rsa|ed25519|ecdsa|dsa|ecdsa_sk)(\.old)?$/i;
|
|
115
|
-
const splitSegments = (aPath) => aPath.split(/[/\\]+/).filter(Boolean);
|
|
116
|
-
/**
|
|
117
|
-
* Returns normalized path segments, resolving symlinks when the path exists.
|
|
118
|
-
*
|
|
119
|
-
* Both the written path and the symlink-resolved one are returned, because a
|
|
120
|
-
* denied segment can be hidden by a symlink in either direction:
|
|
121
|
-
*
|
|
122
|
-
* - `~/innocent-name` -> `~/nested/.aws/creds` hides `.aws` from the written
|
|
123
|
-
* path, so the denylist has to see the resolved one.
|
|
124
|
-
* - `~/.claude` -> `/state/claude` hides `.claude` from the *resolved* path,
|
|
125
|
-
* so the denylist also has to see the written one. Dotfile managers
|
|
126
|
-
* (chezmoi, stow, yadm) and containerised home directories produce exactly
|
|
127
|
-
* this layout.
|
|
128
|
-
*
|
|
129
|
-
* Matching only the resolved path silently turns the denylist off for the
|
|
130
|
-
* second case.
|
|
131
|
-
*/
|
|
132
|
-
function normalizePath(filePath) {
|
|
133
|
-
const absolute = platform.resolvePath(filePath);
|
|
134
|
-
let resolved = absolute;
|
|
135
|
-
try {
|
|
136
|
-
if (platform.existsSync(absolute)) resolved = platform.realpathSync(absolute);
|
|
137
|
-
} catch {}
|
|
138
|
-
return {
|
|
139
|
-
resolvedPath: resolved,
|
|
140
|
-
segments: splitSegments(resolved),
|
|
141
|
-
writtenSegments: splitSegments(absolute)
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* True if the path is under a built-in or extra deny segment, or the basename
|
|
146
|
-
* looks like an env / netrc / default SSH private key name.
|
|
147
|
-
*/
|
|
148
|
-
function isBlockedSensitiveFileUploadPath(filePath, additionalDenySegments) {
|
|
149
|
-
return getSensitiveFileUploadPathBlockReason(filePath, additionalDenySegments) != null;
|
|
150
|
-
}
|
|
151
|
-
function getSensitiveFileUploadPathBlockReason(filePath, additionalDenySegments) {
|
|
152
|
-
const { resolvedPath, segments, writtenSegments } = normalizePath(filePath);
|
|
153
|
-
const isCaseSensitive = platform.isFileSystemCaseSensitive?.(resolvedPath) ?? true;
|
|
154
|
-
const normalizeSegment = (segment) => isCaseSensitive ? segment : segment.toLowerCase();
|
|
155
|
-
const deny = new Set([...BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS, ...(additionalDenySegments ?? []).map((s) => s.trim()).filter(Boolean)].map(normalizeSegment));
|
|
156
|
-
for (const candidate of [segments, writtenSegments]) {
|
|
157
|
-
const segmentsForMatch = isCaseSensitive ? candidate : candidate.map(normalizeSegment);
|
|
158
|
-
for (let i = 0; i < candidate.length; i++) if (deny.has(segmentsForMatch[i])) return `path segment "${candidate[i]}" is in the sensitive file upload denylist`;
|
|
159
|
-
}
|
|
160
|
-
const basenames = [segments.at(-1), writtenSegments.at(-1)].filter((name) => !!name);
|
|
161
|
-
for (const basename of basenames) {
|
|
162
|
-
if (SECRET_LIKE_BASENAME.test(basename) || DEFAULT_PRIVATE_KEY_BASENAME.test(basename)) return `file name "${basename}" looks like a credential, env, or private key file`;
|
|
163
|
-
if (basename.toLowerCase() === "credentials") return "file name \"credentials\" is often used for cloud/API credential stores";
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Default remediation hint appended to the block message. Assumes an SDK caller
|
|
169
|
-
* that exposes `sensitiveFileUploadProtection`. Callers without such an opt-out
|
|
170
|
-
* (e.g. `@composio/cli`) should pass their own `remediation` so the message does
|
|
171
|
-
* not advertise an option the caller cannot honor.
|
|
172
|
-
*/
|
|
173
|
-
const DEFAULT_REMEDIATION = "To upload from this path anyway, set sensitiveFileUploadProtection: false on Composio (not recommended) or use a copy outside sensitive locations.";
|
|
174
|
-
/**
|
|
175
|
-
* @throws {ComposioSensitiveFilePathBlockedError} if the path is not allowed
|
|
176
|
-
*/
|
|
177
|
-
function assertSafeFileUploadPath(filePath, options) {
|
|
178
|
-
const reason = getSensitiveFileUploadPathBlockReason(filePath, options?.additionalDenySegments);
|
|
179
|
-
if (reason) {
|
|
180
|
-
const remediation = options?.remediation ?? DEFAULT_REMEDIATION;
|
|
181
|
-
throw new ComposioSensitiveFilePathBlockedError(`Refusing to upload: ${reason}. ${remediation}`, { meta: {
|
|
182
|
-
filePath,
|
|
183
|
-
reason
|
|
184
|
-
} });
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
//#endregion
|
|
189
|
-
export { readResponseBodyWithLimit as a, uint8ArrayToBase64 as c, MAX_URL_UPLOAD_SIZE_BYTES as i, getRandomShortId as l, assertSafeFileUploadPath as n, arrayBufferToBase64 as o, isBlockedSensitiveFileUploadPath as r, base64ToUint8Array as s, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS as t, getRandomUUID as u };
|