@composio/core 1.0.0-beta.0 → 1.0.0-beta.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/dist/{CustomTool-l-j5HtEf.mjs → CustomTool-CM-roKk7.mjs} +16 -6
- package/dist/{CustomTool-CwpeQhz2.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
- package/dist/{FileModifierErrors-B8V8_3VE.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-DNJt57GL.mjs → SsrfErrors-DiQldIdC.mjs} +154 -19
- package/dist/{Telemetry-DK1uAWnD.mjs → Telemetry-JRJJYS4I.mjs} +28 -44
- package/dist/cancellation-BEpFk2S8.mjs +706 -0
- package/dist/{composio-XjF7EMEe.d.mts → composio-BVNJTVYa.d.mts} +2450 -119
- package/dist/{customTool.types-DpJbYY5m.d.mts → customTool.types-CY5SXFfF.d.mts} +143 -28
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +4 -3
- package/dist/{errors-BcEUHZbq.mjs → errors-CvZjP9CH.mjs} +42 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BwpUOF0s.mjs → fileUtils.node-HQsywtTj.mjs} +11 -9
- package/dist/index.d.mts +393 -142
- package/dist/index.mjs +1945 -171
- package/dist/models/Files.node.d.mts +2 -3
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +2 -3
- package/dist/platform/node.d.mts +2 -3
- package/dist/platform/workerd.d.mts +2 -3
- package/dist/{sensitiveFileUploadPaths-B0w8dqpv.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
- package/dist/{ssrfGuard.node-DlxO8uzr.mjs → ssrfGuard.node-BK50mYTq.mjs} +187 -24
- package/dist/{types-C9kJAurw.d.mts → types-CqGfjlZg.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +7 -7
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +25 -7
- package/src/composio.ts +86 -2
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/ToolErrors.ts +1 -0
- package/src/errors/ValidationErrors.ts +2 -0
- package/src/index.ts +21 -0
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomTool.ts +41 -6
- package/src/models/CustomToolkits.ts +169 -0
- package/src/models/Experimental.ts +27 -0
- package/src/models/Keyring.ts +65 -0
- package/src/models/Logs.ts +101 -0
- package/src/models/RemoteFile.ts +54 -36
- package/src/models/ToolRouterSession.ts +60 -4
- package/src/models/Toolkits.ts +180 -0
- package/src/models/Tools.ts +3 -1
- package/src/models/Triggers.ts +17 -87
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/telemetry/TelemetryService.ts +27 -12
- package/src/telemetry/redact.ts +133 -6
- package/src/types/authConfigs.types.ts +2 -0
- package/src/types/connectedAccounts.types.ts +54 -0
- package/src/types/customToolkits.types.ts +102 -0
- package/src/types/keyring.types.ts +32 -0
- package/src/types/logs.types.ts +108 -0
- package/src/types/toolRouter.types.ts +49 -1
- package/src/types/toolkit.types.ts +131 -0
- package/src/types/usage.types.ts +81 -0
- package/src/types/webhooks.types.ts +143 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/fileUtils.node.ts +10 -2
- package/src/utils/jsonSchema.ts +509 -28
- package/src/utils/logger.ts +45 -13
- package/src/utils/pinnedDispatcher.node.ts +109 -13
- package/src/utils/sdk.ts +1 -1
- package/src/utils/ssrfGuard.node.ts +124 -21
- package/src/utils/ssrfGuard.workerd.ts +5 -1
- package/src/utils/transformers/connectedAccounts.ts +37 -2
- package/src/utils/transformers/customToolkits.ts +98 -0
- package/src/utils/transformers/keyring.ts +24 -0
- package/src/utils/transformers/logs.ts +85 -0
- package/src/utils/transformers/toolkits.ts +100 -1
- package/src/utils/transformers/triggers.ts +2 -2
- package/src/utils/transformers/usage.ts +77 -0
- package/src/utils/transformers/webhooks.ts +139 -0
- package/dist/cancellation-C-qy8rcj.mjs +0 -364
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ValidationError } from "./errors-
|
|
1
|
+
import { _ as ValidationError } from "./errors-CvZjP9CH.mjs";
|
|
2
2
|
import { z as z$1 } from "zod/v3";
|
|
3
3
|
import * as z4 from "zod/v4";
|
|
4
4
|
import * as zodToJsonSchema from "zod-to-json-schema";
|
|
@@ -375,26 +375,32 @@ function buildCustomToolsMapFromResponse(tools, toolkits, experimental) {
|
|
|
375
375
|
};
|
|
376
376
|
for (const handle of tools) registerHandle(handle, handle.extendsToolkit);
|
|
377
377
|
if (toolkits) for (const tk of toolkits) for (const handle of tk.tools) registerHandle(handle, tk.slug);
|
|
378
|
-
const findHandle = (originalSlug, toolkit) => {
|
|
378
|
+
const findHandle = (finalSlug, originalSlug, toolkit) => {
|
|
379
379
|
const originalSlugKey = originalSlug.toUpperCase();
|
|
380
380
|
const qualifiedMatch = handlesByQualifiedOriginalSlug.get(qualifiedOriginalSlugKey(toolkit, originalSlugKey));
|
|
381
381
|
if (qualifiedMatch) return qualifiedMatch;
|
|
382
382
|
const bareMatches = handlesByOriginalSlug.get(originalSlugKey) ?? [];
|
|
383
|
-
|
|
383
|
+
if (bareMatches.length === 0) return void 0;
|
|
384
|
+
if (toolkit === void 0 && bareMatches.length === 1) return bareMatches[0];
|
|
385
|
+
const registered = [...new Set(bareMatches.map((m) => (m.toolkit ?? "custom").toUpperCase()))].sort();
|
|
386
|
+
throw new ValidationError(`Cannot map custom tool "${finalSlug}": original slug "${originalSlug}" for toolkit "${toolkit ?? "custom"}" has no exact local match. Registered for toolkits: ${registered.join(", ")}.`);
|
|
384
387
|
};
|
|
385
388
|
const addEntry = (finalSlug, originalSlug, toolkit) => {
|
|
386
389
|
const resolvedToolkit = toolkit ?? void 0;
|
|
387
|
-
const match = findHandle(originalSlug, resolvedToolkit);
|
|
390
|
+
const match = findHandle(finalSlug, originalSlug, resolvedToolkit);
|
|
388
391
|
if (!match) return;
|
|
389
392
|
const finalSlugKey = finalSlug.toUpperCase();
|
|
390
393
|
if (byFinalSlug.has(finalSlugKey)) throw new ValidationError(`Custom tool slug collision: "${finalSlug}" is already registered.`);
|
|
394
|
+
const entryToolkit = resolvedToolkit ?? match.toolkit;
|
|
395
|
+
const qualifiedKey = qualifiedOriginalSlugKey(entryToolkit, originalSlug);
|
|
396
|
+
if (byToolkitAndOriginalSlug.has(qualifiedKey)) throw new ValidationError(`Custom tool slug collision: original slug "${match.handle.slug}" is already registered for toolkit "${entryToolkit ?? "custom"}".`);
|
|
391
397
|
const entry = {
|
|
392
398
|
handle: match.handle,
|
|
393
399
|
finalSlug,
|
|
394
|
-
toolkit:
|
|
400
|
+
toolkit: entryToolkit
|
|
395
401
|
};
|
|
396
402
|
byFinalSlug.set(finalSlugKey, entry);
|
|
397
|
-
byToolkitAndOriginalSlug.set(
|
|
403
|
+
byToolkitAndOriginalSlug.set(qualifiedKey, entry);
|
|
398
404
|
addOriginalSlugAlias({
|
|
399
405
|
byOriginalSlug,
|
|
400
406
|
ambiguousOriginalSlugs,
|
|
@@ -404,6 +410,10 @@ function buildCustomToolsMapFromResponse(tools, toolkits, experimental) {
|
|
|
404
410
|
};
|
|
405
411
|
if (experimental?.custom_tools) for (const ct of experimental.custom_tools) addEntry(ct.slug, ct.original_slug, ct.extends_toolkit);
|
|
406
412
|
if (experimental?.custom_toolkits) for (const ctk of experimental.custom_toolkits) for (const ct of ctk.tools) addEntry(ct.slug, ct.original_slug, ctk.slug);
|
|
413
|
+
for (const [originalSlugKey, matches] of handlesByOriginalSlug) if (matches.length > 1) {
|
|
414
|
+
byOriginalSlug.delete(originalSlugKey);
|
|
415
|
+
ambiguousOriginalSlugs.add(originalSlugKey);
|
|
416
|
+
}
|
|
407
417
|
return {
|
|
408
418
|
byFinalSlug,
|
|
409
419
|
byOriginalSlug,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-
|
|
1
|
+
import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-CY5SXFfF.mjs";
|
|
2
2
|
import { SessionCreateResponse } from "@composio/client/resources/tool-router/session/session.mjs";
|
|
3
3
|
//#region src/models/CustomTool.d.ts
|
|
4
4
|
/**
|
|
@@ -19,8 +19,10 @@ const transformSchema = (property) => {
|
|
|
19
19
|
if (property.anyOf) newProperty.anyOf = property.anyOf.map(transformSchema);
|
|
20
20
|
if (property.oneOf) newProperty.oneOf = property.oneOf.map(transformSchema);
|
|
21
21
|
if (property.allOf) newProperty.allOf = property.allOf.map(transformSchema);
|
|
22
|
-
if (property.items)
|
|
23
|
-
|
|
22
|
+
if (property.items) {
|
|
23
|
+
if (Array.isArray(property.items)) newProperty.items = property.items.map(transformSchema);
|
|
24
|
+
else newProperty.items = transformSchema(property.items);
|
|
25
|
+
}
|
|
24
26
|
return newProperty;
|
|
25
27
|
};
|
|
26
28
|
/**
|
|
@@ -55,6 +55,125 @@ const COMPOSIO_LOG_LEVEL = getEnvVariable("COMPOSIO_LOG_LEVEL");
|
|
|
55
55
|
const IS_DEVELOPMENT_OR_CI = getEnvVariable("DEVELOPMENT") || getEnvVariable("CI") || false;
|
|
56
56
|
const DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID = "files";
|
|
57
57
|
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/telemetry/redact.ts
|
|
60
|
+
/**
|
|
61
|
+
* Best-effort redaction of secrets from free-form error text before it is sent
|
|
62
|
+
* to the telemetry endpoint.
|
|
63
|
+
*
|
|
64
|
+
* Error `message` and `stack` fields routinely interpolate URLs (with
|
|
65
|
+
* query-string tokens / presigned signatures), `Authorization` headers, API
|
|
66
|
+
* keys, and connected-account identifiers. None of that should leave the
|
|
67
|
+
* process. Structured telemetry fields never carry raw secrets, so only the two
|
|
68
|
+
* free-form strings are passed through here.
|
|
69
|
+
*
|
|
70
|
+
* This is defence-in-depth, not a proof: it targets the shapes we have seen
|
|
71
|
+
* leak. When in doubt it over-redacts rather than under-redacts.
|
|
72
|
+
*/
|
|
73
|
+
const REDACTED = "[REDACTED]";
|
|
74
|
+
const SECRET_KEY_PATTERN = String.raw`authorization|auth|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd`;
|
|
75
|
+
const SECRET_KEY_WITH_PREFIX_PATTERN = String.raw`(?:[A-Za-z0-9]+_)*(?:${SECRET_KEY_PATTERN})`;
|
|
76
|
+
const QUOTED_SECRET_KEY_PREFIX = String.raw`(["'])(${SECRET_KEY_WITH_PREFIX_PATTERN})\1(\s*[:=]+\s*)`;
|
|
77
|
+
const BARE_SECRET_KEY_PREFIX = String.raw`(?<![A-Za-z0-9"'])(${SECRET_KEY_PATTERN})\b(\s*[:=]+\s*)`;
|
|
78
|
+
const ESCAPED_SECRET_KEY_PREFIX = String.raw`(?<![A-Za-z0-9])(${SECRET_KEY_PATTERN})\b((?:\\["'])?\s*[:=]+\s*)`;
|
|
79
|
+
const SECRET_PAIR_PREFIX = String.raw`(?<![A-Za-z0-9])(${SECRET_KEY_PATTERN})\b(["']?\s*[:=]+\s*)`;
|
|
80
|
+
const BARE_KEY_DOUBLE_QUOTED_VALUE = new RegExp(String.raw`${BARE_SECRET_KEY_PREFIX}"((?:\\.|[^"\\\r\n])*)"`, "gi");
|
|
81
|
+
const BARE_KEY_SINGLE_QUOTED_VALUE = new RegExp(String.raw`${BARE_SECRET_KEY_PREFIX}'((?:\\.|[^'\\\r\n])*)'`, "gi");
|
|
82
|
+
const BARE_KEY_ESCAPED_DOUBLE_QUOTED_VALUE = new RegExp(String.raw`${ESCAPED_SECRET_KEY_PREFIX}\\"((?:\\.|[^"\\\r\n])*)\\"`, "gi");
|
|
83
|
+
const BARE_KEY_ESCAPED_SINGLE_QUOTED_VALUE = new RegExp(String.raw`${ESCAPED_SECRET_KEY_PREFIX}\\'((?:\\.|[^'\\\r\n])*)\\'`, "gi");
|
|
84
|
+
const SECRET_PAIR_UNQUOTED = new RegExp(String.raw`${SECRET_PAIR_PREFIX}(?!\\["'])([^\s"',}&]+)`, "gi");
|
|
85
|
+
const CONTAINS_QUOTED_FIELD = /(?:^|[,{\s])(["'])[^"'\\\r\n]+\1\s*[:=]\s*$/;
|
|
86
|
+
const REDACTION_RULES = [
|
|
87
|
+
[/(\bhttps?:\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`],
|
|
88
|
+
[/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
|
|
89
|
+
[new RegExp(String.raw`${QUOTED_SECRET_KEY_PREFIX}"(?:\\.|[^"\\\r\n])*"`, "gi"), `$1$2$1$3"${REDACTED}"`],
|
|
90
|
+
[new RegExp(String.raw`${QUOTED_SECRET_KEY_PREFIX}'(?:\\.|[^'\\\r\n])*'`, "gi"), `$1$2$1$3'${REDACTED}'`]
|
|
91
|
+
];
|
|
92
|
+
const isWordCharacter = (character) => /[\p{L}\p{N}_]/u.test(character);
|
|
93
|
+
const activeQuotesAt = (input, offsets) => {
|
|
94
|
+
const activeQuotes = /* @__PURE__ */ new Map();
|
|
95
|
+
let quote;
|
|
96
|
+
let escaped = false;
|
|
97
|
+
let lastOffset = -1;
|
|
98
|
+
for (const offset of offsets) lastOffset = Math.max(lastOffset, offset);
|
|
99
|
+
for (let position = 0; position < input.length; position += 1) {
|
|
100
|
+
const character = input[position];
|
|
101
|
+
if (offsets.has(position)) {
|
|
102
|
+
activeQuotes.set(position, quote);
|
|
103
|
+
if (position === lastOffset) break;
|
|
104
|
+
}
|
|
105
|
+
if (character === "\n" || character === "\r") {
|
|
106
|
+
quote = void 0;
|
|
107
|
+
escaped = false;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const previous = position > 0 && !["\n", "\r"].includes(input[position - 1]) ? input[position - 1] : "";
|
|
111
|
+
const following = input[position + 1] ?? "";
|
|
112
|
+
if (!quote) {
|
|
113
|
+
if (character === "\"" || character === "'" && !isWordCharacter(previous)) quote = character;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (escaped) escaped = false;
|
|
117
|
+
else if (character === "\\") escaped = true;
|
|
118
|
+
else if (character === quote) {
|
|
119
|
+
if (quote === "'" && isWordCharacter(previous) && isWordCharacter(following)) continue;
|
|
120
|
+
quote = void 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return activeQuotes;
|
|
124
|
+
};
|
|
125
|
+
const completesQuotedFieldAt = (input, index, quote) => {
|
|
126
|
+
let escaped = false;
|
|
127
|
+
for (let position = index; position < input.length; position += 1) {
|
|
128
|
+
const character = input[position];
|
|
129
|
+
if (character === "\n" || character === "\r") return false;
|
|
130
|
+
if (escaped) {
|
|
131
|
+
escaped = false;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (character === "\\") {
|
|
135
|
+
escaped = true;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (character !== quote) continue;
|
|
139
|
+
let separator = position + 1;
|
|
140
|
+
while (separator < input.length && /\s/.test(input[separator])) separator += 1;
|
|
141
|
+
return input[separator] === ":" || input[separator] === "=";
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
};
|
|
145
|
+
const redactBareQuotedValue = (input, pattern, quote) => {
|
|
146
|
+
pattern.lastIndex = 0;
|
|
147
|
+
const matches = Array.from(input.matchAll(pattern));
|
|
148
|
+
if (matches.length === 0) return input;
|
|
149
|
+
const activeQuotes = activeQuotesAt(input, new Set(matches.map((match) => match.index)));
|
|
150
|
+
const parts = [];
|
|
151
|
+
let cursor = 0;
|
|
152
|
+
for (const match of matches) {
|
|
153
|
+
const offset = match.index;
|
|
154
|
+
parts.push(input.slice(cursor, offset));
|
|
155
|
+
if (activeQuotes.get(offset) === quote && (completesQuotedFieldAt(input, offset + match[0].length, quote) || CONTAINS_QUOTED_FIELD.test(match[3]))) parts.push(match[0]);
|
|
156
|
+
else parts.push(`${match[1]}${match[2]}${quote}${REDACTED}${quote}`);
|
|
157
|
+
cursor = offset + match[0].length;
|
|
158
|
+
}
|
|
159
|
+
parts.push(input.slice(cursor));
|
|
160
|
+
return parts.join("");
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Redact common secret shapes from a free-form string. Returns the input
|
|
164
|
+
* unchanged when it is empty or `undefined`.
|
|
165
|
+
*/
|
|
166
|
+
const redactSensitiveText = (input) => {
|
|
167
|
+
if (!input) return input;
|
|
168
|
+
let output = input;
|
|
169
|
+
for (const [pattern, replacement] of REDACTION_RULES) output = output.replace(pattern, replacement);
|
|
170
|
+
output = output.replace(BARE_KEY_ESCAPED_DOUBLE_QUOTED_VALUE, `$1$2\\"${REDACTED}\\"`);
|
|
171
|
+
output = output.replace(BARE_KEY_ESCAPED_SINGLE_QUOTED_VALUE, `$1$2\\'${REDACTED}\\'`);
|
|
172
|
+
output = redactBareQuotedValue(output, BARE_KEY_DOUBLE_QUOTED_VALUE, "\"");
|
|
173
|
+
output = redactBareQuotedValue(output, BARE_KEY_SINGLE_QUOTED_VALUE, "'");
|
|
174
|
+
return output.replace(SECRET_PAIR_UNQUOTED, `$1$2${REDACTED}`);
|
|
175
|
+
};
|
|
176
|
+
|
|
58
177
|
//#endregion
|
|
59
178
|
//#region src/utils/logger.ts
|
|
60
179
|
const LOG_LEVELS = {
|
|
@@ -76,39 +195,53 @@ const getLogLevel = () => {
|
|
|
76
195
|
var Logger = class {
|
|
77
196
|
level;
|
|
78
197
|
includeTimestamp;
|
|
79
|
-
|
|
198
|
+
sink;
|
|
80
199
|
constructor(options = {}) {
|
|
81
200
|
this.level = options.level ?? getLogLevel();
|
|
82
201
|
this.includeTimestamp = options.includeTimestamp ?? true;
|
|
83
|
-
this.
|
|
202
|
+
this.sink = options.sink ?? console;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Reconfigure the level and/or sink in place. Omitted fields are left
|
|
206
|
+
* unchanged, so `configure({ level: 'debug' })` keeps the current sink.
|
|
207
|
+
*/
|
|
208
|
+
configure(options) {
|
|
209
|
+
if (options.level !== void 0) this.level = options.level;
|
|
210
|
+
if (options.sink !== void 0) this.sink = options.sink;
|
|
211
|
+
}
|
|
212
|
+
getLevel() {
|
|
213
|
+
return this.level;
|
|
84
214
|
}
|
|
85
215
|
formatMessage(args) {
|
|
86
216
|
const formattedArgs = args.map((arg, index) => {
|
|
87
217
|
if (typeof arg === "object") return JSON.stringify(arg);
|
|
88
218
|
else {
|
|
89
|
-
if (index === 0)
|
|
90
|
-
|
|
219
|
+
if (index === 0) {
|
|
220
|
+
if (args.length > 1) return pc.yellow(`${arg}`);
|
|
221
|
+
else return String(arg);
|
|
222
|
+
}
|
|
91
223
|
return String(arg);
|
|
92
224
|
}
|
|
93
225
|
}).join("\n");
|
|
94
|
-
|
|
226
|
+
const redactedArgs = redactSensitiveText(formattedArgs) ?? formattedArgs;
|
|
227
|
+
if (!this.includeTimestamp) return redactedArgs;
|
|
95
228
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
96
|
-
return `${pc.gray(timestamp)} - ${
|
|
229
|
+
return `${pc.gray(timestamp)} - ${redactedArgs}`;
|
|
97
230
|
}
|
|
98
231
|
shouldLog(level) {
|
|
99
232
|
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
100
233
|
}
|
|
101
234
|
error(...args) {
|
|
102
|
-
if (this.shouldLog("error")) this.
|
|
235
|
+
if (this.shouldLog("error")) this.sink.error(this.formatMessage(args));
|
|
103
236
|
}
|
|
104
237
|
warn(...args) {
|
|
105
|
-
if (this.shouldLog("warn")) this.
|
|
238
|
+
if (this.shouldLog("warn")) this.sink.warn(this.formatMessage(args));
|
|
106
239
|
}
|
|
107
240
|
info(...args) {
|
|
108
|
-
if (this.shouldLog("info")) this.
|
|
241
|
+
if (this.shouldLog("info")) this.sink.info(this.formatMessage(args));
|
|
109
242
|
}
|
|
110
243
|
debug(...args) {
|
|
111
|
-
if (this.shouldLog("debug")) this.
|
|
244
|
+
if (this.shouldLog("debug")) this.sink.debug(this.formatMessage(args));
|
|
112
245
|
}
|
|
113
246
|
};
|
|
114
247
|
const logger = new Logger();
|
|
@@ -200,14 +333,16 @@ var ComposioError$1 = class ComposioError$1 extends Error {
|
|
|
200
333
|
if (statusCode !== void 0) data.statusCode = statusCode;
|
|
201
334
|
if (meta) data.meta = meta;
|
|
202
335
|
if (possibleFixes) data.possibleFixes = possibleFixes;
|
|
203
|
-
if (includeStack && stack)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
336
|
+
if (includeStack && stack) {
|
|
337
|
+
if (stack.includes("Caused by:")) {
|
|
338
|
+
const [currentStack, causeStack] = stack.split("Caused by:");
|
|
339
|
+
data.stack = [
|
|
340
|
+
...currentStack.split("\n").slice(1),
|
|
341
|
+
"Caused by:",
|
|
342
|
+
...causeStack.split("\n")
|
|
343
|
+
];
|
|
344
|
+
} else data.stack = stack.split("\n").slice(1);
|
|
345
|
+
}
|
|
211
346
|
return data;
|
|
212
347
|
}
|
|
213
348
|
/**
|
|
@@ -381,4 +516,4 @@ var ComposioBlockedInternalUrlError = class extends ComposioError$1 {
|
|
|
381
516
|
};
|
|
382
517
|
|
|
383
518
|
//#endregion
|
|
384
|
-
export {
|
|
519
|
+
export { redactSensitiveText as a, DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID as c, USER_DATA_FILE_NAME as d, constants_exports as f, logger as i, IS_DEVELOPMENT_OR_CI as l, getEnvsWithPrefix as m, SsrfErrorCodes as n, COMPOSIO_DIR as o, getEnvVariable as p, ComposioError$1 as r, DEFAULT_BASE_URL as s, ComposioBlockedInternalUrlError as t, TEMP_FILES_DIRECTORY_NAME as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as logger, p as getEnvVariable, r as ComposioError$1 } from "./SsrfErrors-
|
|
2
|
-
import {
|
|
1
|
+
import { a as redactSensitiveText, i as logger, p as getEnvVariable, r as ComposioError$1 } from "./SsrfErrors-DiQldIdC.mjs";
|
|
2
|
+
import { u as getRandomUUID } from "./sensitiveFileUploadPaths-BlLp-Yo2.mjs";
|
|
3
3
|
import { ComposioError } from "@composio/client";
|
|
4
4
|
|
|
5
5
|
//#region src/types/telemetry.types.ts
|
|
@@ -64,7 +64,31 @@ var BatchProcessor = class {
|
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region src/services/telemetry/TelemetryService.ts
|
|
66
66
|
const TELEMETRY_URL = "https://telemetry.composio.dev/v1";
|
|
67
|
+
const TELEMETRY_TIMEOUT_MS = 3e3;
|
|
67
68
|
var TelemetryService = class {
|
|
69
|
+
/**
|
|
70
|
+
* POSTs a best-effort telemetry payload, bounding the request so a stalled
|
|
71
|
+
* endpoint cannot leave it pending indefinitely.
|
|
72
|
+
*
|
|
73
|
+
* A hand-rolled timer rather than AbortSignal.timeout so it can be cleared the
|
|
74
|
+
* moment the response lands: an uncleared timer is itself pending work, which on
|
|
75
|
+
* workerd pins the request context open for the full timeout on every successful
|
|
76
|
+
* send. Mirrors the bound applied to the npm version check.
|
|
77
|
+
*/
|
|
78
|
+
static async postWithTimeout(url, payload) {
|
|
79
|
+
const controller = new AbortController();
|
|
80
|
+
const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
|
|
81
|
+
try {
|
|
82
|
+
return await fetch(url, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: { "Content-Type": "application/json" },
|
|
85
|
+
body: JSON.stringify(payload),
|
|
86
|
+
signal: controller.signal
|
|
87
|
+
});
|
|
88
|
+
} finally {
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
68
92
|
/**
|
|
69
93
|
* Sends a metric to the Telemetry API.
|
|
70
94
|
* @param payload - The payload to send to the Telemetry API.
|
|
@@ -72,11 +96,7 @@ var TelemetryService = class {
|
|
|
72
96
|
*/
|
|
73
97
|
static async sendMetric(payload) {
|
|
74
98
|
try {
|
|
75
|
-
return await
|
|
76
|
-
method: "POST",
|
|
77
|
-
headers: { "Content-Type": "application/json" },
|
|
78
|
-
body: JSON.stringify(payload)
|
|
79
|
-
});
|
|
99
|
+
return await this.postWithTimeout(`${TELEMETRY_URL}/metrics/invocations`, payload);
|
|
80
100
|
} catch (error) {
|
|
81
101
|
logger.debug("Error sending metric telemetry", error);
|
|
82
102
|
}
|
|
@@ -88,49 +108,13 @@ var TelemetryService = class {
|
|
|
88
108
|
*/
|
|
89
109
|
static async sendErrorLog(payload) {
|
|
90
110
|
try {
|
|
91
|
-
return await
|
|
92
|
-
method: "POST",
|
|
93
|
-
headers: { "Content-Type": "application/json" },
|
|
94
|
-
body: JSON.stringify(payload)
|
|
95
|
-
});
|
|
111
|
+
return await this.postWithTimeout(`${TELEMETRY_URL}/errors`, payload);
|
|
96
112
|
} catch (error) {
|
|
97
113
|
logger.debug("Error sending error telemetry", error);
|
|
98
114
|
}
|
|
99
115
|
}
|
|
100
116
|
};
|
|
101
117
|
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/telemetry/redact.ts
|
|
104
|
-
/**
|
|
105
|
-
* Best-effort redaction of secrets from free-form error text before it is sent
|
|
106
|
-
* to the telemetry endpoint.
|
|
107
|
-
*
|
|
108
|
-
* Error `message` and `stack` fields routinely interpolate URLs (with
|
|
109
|
-
* query-string tokens / presigned signatures), `Authorization` headers, API
|
|
110
|
-
* keys, and connected-account identifiers. None of that should leave the
|
|
111
|
-
* process. Structured telemetry fields never carry raw secrets, so only the two
|
|
112
|
-
* free-form strings are passed through here.
|
|
113
|
-
*
|
|
114
|
-
* This is defence-in-depth, not a proof: it targets the shapes we have seen
|
|
115
|
-
* leak. When in doubt it over-redacts rather than under-redacts.
|
|
116
|
-
*/
|
|
117
|
-
const REDACTED = "[REDACTED]";
|
|
118
|
-
const REDACTION_RULES = [
|
|
119
|
-
[/(\bhttps?:\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`],
|
|
120
|
-
[/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
|
|
121
|
-
[/(?<![A-Za-z0-9])(authorization|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd)\b(["']?\s*[:=]+\s*)(["']?)([^\s"',}&]+)\3/gi, `$1$2$3${REDACTED}$3`]
|
|
122
|
-
];
|
|
123
|
-
/**
|
|
124
|
-
* Redact common secret shapes from a free-form string. Returns the input
|
|
125
|
-
* unchanged when it is empty or `undefined`.
|
|
126
|
-
*/
|
|
127
|
-
const redactSensitiveText = (input) => {
|
|
128
|
-
if (!input) return input;
|
|
129
|
-
let output = input;
|
|
130
|
-
for (const [pattern, replacement] of REDACTION_RULES) output = output.replace(pattern, replacement);
|
|
131
|
-
return output;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
118
|
//#endregion
|
|
135
119
|
//#region src/telemetry/Telemetry.ts
|
|
136
120
|
/**
|