@composio/core 0.5.5 → 0.6.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/BaseProvider-QPPZprGx.d.mts +26875 -0
- package/dist/BaseProvider-dBg5sg9H.d.cts +26875 -0
- package/dist/FileToolModifier.utils.neutral-BN_L8usp.mjs +78 -0
- package/dist/FileToolModifier.utils.neutral-Bcl7LVf4.cjs +102 -0
- package/dist/Telemetry-Bn5VseVi.mjs +331 -0
- package/dist/Telemetry-DErMJqj0.cjs +337 -0
- package/dist/buffer-BFpVRahf.mjs +382 -0
- package/dist/buffer-CYf1Z6Sd.cjs +478 -0
- package/dist/composio-h_UeXpQT.d.cts +6325 -0
- package/dist/composio-ivOweCw4.d.mts +6325 -0
- package/dist/fileUtils.node-DLp53qm1.cjs +232 -0
- package/dist/fileUtils.node-MOEGtpnI.mjs +219 -0
- package/dist/index.cjs +273 -417
- package/dist/index.d.cts +6 -33161
- package/dist/index.d.mts +6 -33161
- package/dist/index.mjs +182 -325
- package/dist/models/Files.node.cjs +6 -4
- package/dist/models/Files.node.d.cts +1 -1
- package/dist/models/Files.node.d.mts +1 -1
- package/dist/models/Files.node.mjs +4 -2
- package/dist/models/Files.workerd.cjs +1 -1
- package/dist/models/Files.workerd.mjs +1 -1
- package/dist/platform/node.cjs +6 -3
- package/dist/platform/node.d.cts +1 -1
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +6 -3
- package/dist/platform/workerd.d.cts +1 -1
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/{types-BaUqjuX3.d.mts → types-BF2OQZRP.d.cts} +8 -5
- package/dist/types-BXCpxUsu.d.cts +13 -0
- package/dist/{types-BrsW5suw.d.cts → types-Cvt_yFsu.d.mts} +8 -5
- package/dist/types-anOdQ7KW.d.mts +13 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.cjs +10 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.cts +7 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +8 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.mjs +9 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.cjs +10 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.cts +7 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +8 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +9 -0
- package/dist/utils/modifiers/FileToolModifier.node.cjs +172 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.cts +21 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +21 -0
- package/dist/utils/modifiers/FileToolModifier.node.mjs +173 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.cjs +27 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.d.cts +20 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +20 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +27 -0
- package/package.json +25 -1
- package/src/platform/index.ts +1 -1
- package/src/platform/node.ts +17 -9
- package/src/platform/types.ts +9 -5
- package/src/platform/workerd.ts +7 -3
- package/dist/fileUtils-2bnnG7dq.cjs +0 -979
- package/dist/fileUtils-Dbn-fnh5.mjs +0 -900
- /package/dist/{chunk-0j-ceAHr.mjs → chunk-Dx2NuYGI.mjs} +0 -0
- /package/dist/{files.types-B7P5A1Z5.d.mts → files.types-BDqIUdfP.d.mts} +0 -0
- /package/dist/{files.types-D-RzIOHq.d.cts → files.types-nK6eTNnc.d.cts} +0 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CQwRTUmo.cjs');
|
|
2
|
+
const require_buffer = require('./buffer-CYf1Z6Sd.cjs');
|
|
3
|
+
let _composio_client = require("@composio/client");
|
|
4
|
+
|
|
5
|
+
//#region src/types/telemetry.types.ts
|
|
6
|
+
const TELEMETRY_EVENTS = {
|
|
7
|
+
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
8
|
+
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
9
|
+
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
10
|
+
CLI_INVOKED: "CLI_INVOKED"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/telemetry/BatchProcessor.ts
|
|
15
|
+
var BatchProcessor = class {
|
|
16
|
+
batch = [];
|
|
17
|
+
time;
|
|
18
|
+
batchSize;
|
|
19
|
+
processBatchCallback;
|
|
20
|
+
timer = null;
|
|
21
|
+
pendingBatches = /* @__PURE__ */ new Set();
|
|
22
|
+
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
23
|
+
this.batch = [];
|
|
24
|
+
this.time = time;
|
|
25
|
+
this.batchSize = batchSize;
|
|
26
|
+
this.processBatchCallback = processBatchCallback;
|
|
27
|
+
}
|
|
28
|
+
pushItem(item) {
|
|
29
|
+
this.batch.push(item);
|
|
30
|
+
if (this.batch.length >= this.batchSize) this.processBatch();
|
|
31
|
+
else if (!this.timer) this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
32
|
+
}
|
|
33
|
+
processBatch() {
|
|
34
|
+
if (this.batch.length > 0) {
|
|
35
|
+
const batchToProcess = this.batch;
|
|
36
|
+
this.batch = [];
|
|
37
|
+
const pending = this.processBatchCallback(batchToProcess).catch(() => {}).finally(() => {
|
|
38
|
+
this.pendingBatches.delete(pending);
|
|
39
|
+
});
|
|
40
|
+
this.pendingBatches.add(pending);
|
|
41
|
+
}
|
|
42
|
+
if (this.timer) {
|
|
43
|
+
clearTimeout(this.timer);
|
|
44
|
+
this.timer = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Flush any pending batches and wait for all of them to complete.
|
|
49
|
+
* Useful for ensuring telemetry is sent before process exit.
|
|
50
|
+
*/
|
|
51
|
+
async flush() {
|
|
52
|
+
this.processBatch();
|
|
53
|
+
if (this.pendingBatches.size > 0) await Promise.all(this.pendingBatches);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/services/telemetry/TelemetryService.ts
|
|
59
|
+
const TELEMETRY_URL = "https://telemetry.composio.dev/v1";
|
|
60
|
+
var TelemetryService = class {
|
|
61
|
+
/**
|
|
62
|
+
* Sends a metric to the Telemetry API.
|
|
63
|
+
* @param payload - The payload to send to the Telemetry API.
|
|
64
|
+
* @returns The response from the Telemetry API.
|
|
65
|
+
*/
|
|
66
|
+
static async sendMetric(payload) {
|
|
67
|
+
try {
|
|
68
|
+
return await fetch(`${TELEMETRY_URL}/metrics/invocations`, {
|
|
69
|
+
method: "POST",
|
|
70
|
+
headers: { "Content-Type": "application/json" },
|
|
71
|
+
body: JSON.stringify(payload)
|
|
72
|
+
});
|
|
73
|
+
} catch (error) {
|
|
74
|
+
require_buffer.logger_default.debug("Error sending metric telemetry", error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Sends an error log to the Telemetry API.
|
|
79
|
+
* @param payload - The payload to send to the Telemetry API.
|
|
80
|
+
* @returns The response from the Telemetry API.
|
|
81
|
+
*/
|
|
82
|
+
static async sendErrorLog(payload) {
|
|
83
|
+
try {
|
|
84
|
+
return await fetch(`${TELEMETRY_URL}/errors`, {
|
|
85
|
+
method: "POST",
|
|
86
|
+
headers: { "Content-Type": "application/json" },
|
|
87
|
+
body: JSON.stringify(payload)
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
require_buffer.logger_default.debug("Error sending error telemetry", error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/telemetry/Telemetry.ts
|
|
97
|
+
/**
|
|
98
|
+
* The Telemetry class is used to log the telemetry for any given instance which extends InstrumentedInstance.
|
|
99
|
+
*
|
|
100
|
+
* This class is used to instrument the telemetry for the given instance and send the telemetry to the server.
|
|
101
|
+
* This class is also used to create a global error handler for the given instance.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
*
|
|
105
|
+
* const telemetry = new Telemetry({...});
|
|
106
|
+
* const composio = new Composio({...})
|
|
107
|
+
*
|
|
108
|
+
* telemetry.instrument(composio);
|
|
109
|
+
* telemetry.instrument(composio.tools);
|
|
110
|
+
* telemetry.instrument(composio.toolkits);
|
|
111
|
+
* telemetry.instrument(composio.triggers);
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
var TelemetryTransport = class {
|
|
115
|
+
telemetryMetadata;
|
|
116
|
+
isTelemetryDisabled = true;
|
|
117
|
+
telemetrySource;
|
|
118
|
+
telemetrySourceName = "typescript-sdk";
|
|
119
|
+
telemetryServiceName = "sdk";
|
|
120
|
+
telemetryLanguage = "typescript";
|
|
121
|
+
exitHandlersRegistered = false;
|
|
122
|
+
batchProcessor = new BatchProcessor(200, 10, async (data) => {
|
|
123
|
+
require_buffer.logger_default.debug("Sending batch of telemetry metrics", data);
|
|
124
|
+
await TelemetryService.sendMetric(data);
|
|
125
|
+
});
|
|
126
|
+
setup(metadata) {
|
|
127
|
+
this.telemetryMetadata = metadata;
|
|
128
|
+
this.isTelemetryDisabled = false;
|
|
129
|
+
this.telemetrySource = {
|
|
130
|
+
host: this.telemetryMetadata?.host ?? this.telemetrySourceName,
|
|
131
|
+
service: this.telemetryServiceName,
|
|
132
|
+
language: this.telemetryLanguage,
|
|
133
|
+
version: this.telemetryMetadata?.version,
|
|
134
|
+
platform: this.telemetryMetadata?.isBrowser ? "browser" : "node",
|
|
135
|
+
environment: require_buffer.getEnvVariable("NODE_ENV", "production")
|
|
136
|
+
};
|
|
137
|
+
this.registerExitHandlers();
|
|
138
|
+
this.sendMetric([{
|
|
139
|
+
functionName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
140
|
+
durationMs: 0,
|
|
141
|
+
timestamp: Date.now() / 1e3,
|
|
142
|
+
props: {},
|
|
143
|
+
source: this.telemetrySource,
|
|
144
|
+
metadata: { provider: this.telemetryMetadata?.provider ?? "openai" },
|
|
145
|
+
error: void 0
|
|
146
|
+
}]);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Instrument the telemetry for the given instance.
|
|
150
|
+
*
|
|
151
|
+
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
152
|
+
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
153
|
+
* @param instance - any instance that extends InstrumentedInstance
|
|
154
|
+
* @param fileName - the file name of the instance
|
|
155
|
+
* @returns
|
|
156
|
+
*/
|
|
157
|
+
instrument(instance, fileName) {
|
|
158
|
+
const proto = Object.getPrototypeOf(instance);
|
|
159
|
+
const methodNames = Object.getOwnPropertyNames(proto).filter((key) => {
|
|
160
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
161
|
+
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
162
|
+
});
|
|
163
|
+
const instrumentedClassName = fileName ?? instance.constructor?.name ?? "unknown";
|
|
164
|
+
for (const name of methodNames) {
|
|
165
|
+
const originalMethod = instance[name];
|
|
166
|
+
instance[name] = async (...args) => {
|
|
167
|
+
const telemetryEnabled = this.shouldSendTelemetry();
|
|
168
|
+
const startTime = telemetryEnabled ? Date.now() : void 0;
|
|
169
|
+
try {
|
|
170
|
+
const result = await originalMethod.apply(instance, args);
|
|
171
|
+
if (telemetryEnabled && startTime !== void 0) {
|
|
172
|
+
const durationMs = Date.now() - startTime;
|
|
173
|
+
const telemetryPayload = {
|
|
174
|
+
functionName: `${instrumentedClassName}.${name}`,
|
|
175
|
+
durationMs,
|
|
176
|
+
timestamp: startTime / 1e3,
|
|
177
|
+
props: {
|
|
178
|
+
fileName: instrumentedClassName,
|
|
179
|
+
method: name,
|
|
180
|
+
params: args
|
|
181
|
+
},
|
|
182
|
+
metadata: { provider: this.telemetryMetadata?.provider ?? "openai" },
|
|
183
|
+
error: void 0,
|
|
184
|
+
source: this.telemetrySource
|
|
185
|
+
};
|
|
186
|
+
this.batchProcessor.pushItem(telemetryPayload);
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (error instanceof Error) {
|
|
191
|
+
if (!error.errorId) {
|
|
192
|
+
error.errorId = require_buffer.getRandomUUID();
|
|
193
|
+
if (telemetryEnabled && startTime !== void 0) {
|
|
194
|
+
const durationMs = Date.now() - startTime;
|
|
195
|
+
await this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args, startTime, durationMs);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return instance;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Check if the telemetry should be sent.
|
|
207
|
+
* @returns true if the telemetry should be sent, false otherwise
|
|
208
|
+
*/
|
|
209
|
+
shouldSendTelemetry() {
|
|
210
|
+
const telemetryDisabledEnvironments = ["test", "ci"];
|
|
211
|
+
const nodeEnv = (require_buffer.getEnvVariable("NODE_ENV", "development") || "").toLowerCase();
|
|
212
|
+
const isDisabledEnvironment = telemetryDisabledEnvironments.includes(nodeEnv);
|
|
213
|
+
const isTelemetryDisabledByEnv = require_buffer.getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
214
|
+
return !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDisabledEnvironment;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Prepare and send the error telemetry.
|
|
218
|
+
*
|
|
219
|
+
* @TODO This currently blocks the thread and sends the telemetry to the server.
|
|
220
|
+
*
|
|
221
|
+
* @param {unknown} error - The error to send.
|
|
222
|
+
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
223
|
+
* @param {string} name - The name of the method that threw the error.
|
|
224
|
+
* @param {unknown[]} args - The arguments passed to the method.
|
|
225
|
+
* @param {number} startTime - The start time of the method invocation in milliseconds.
|
|
226
|
+
* @param {number} durationMs - The duration of the method invocation in milliseconds.
|
|
227
|
+
*/
|
|
228
|
+
async prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args, startTime, durationMs) {
|
|
229
|
+
const telemetryPayload = {
|
|
230
|
+
functionName: `${instrumentedClassName}.${name}`,
|
|
231
|
+
durationMs,
|
|
232
|
+
timestamp: startTime / 1e3,
|
|
233
|
+
props: {
|
|
234
|
+
fileName: instrumentedClassName,
|
|
235
|
+
method: name,
|
|
236
|
+
params: args
|
|
237
|
+
},
|
|
238
|
+
metadata: { provider: this.telemetryMetadata?.provider ?? "openai" },
|
|
239
|
+
source: this.telemetrySource
|
|
240
|
+
};
|
|
241
|
+
if (error instanceof _composio_client.ComposioError) telemetryPayload.error = {
|
|
242
|
+
errorId: error.errorId,
|
|
243
|
+
name: error.name,
|
|
244
|
+
message: error.message,
|
|
245
|
+
stack: error.stack
|
|
246
|
+
};
|
|
247
|
+
else if (error instanceof require_buffer.ComposioError) telemetryPayload.error = {
|
|
248
|
+
errorId: error.errorId,
|
|
249
|
+
name: error.name,
|
|
250
|
+
code: error.code,
|
|
251
|
+
message: error.message,
|
|
252
|
+
stack: error.stack
|
|
253
|
+
};
|
|
254
|
+
else if (error instanceof Error) telemetryPayload.error = {
|
|
255
|
+
errorId: error.errorId,
|
|
256
|
+
name: error.name ?? "Unknown error",
|
|
257
|
+
message: error.message,
|
|
258
|
+
stack: error.stack
|
|
259
|
+
};
|
|
260
|
+
await this.sendErrorTelemetry(telemetryPayload);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Send the telemetry payload to the server.
|
|
264
|
+
* @param payload - the telemetry payload to send
|
|
265
|
+
* @returns
|
|
266
|
+
*/
|
|
267
|
+
async sendMetric(payload) {
|
|
268
|
+
if (!this.shouldSendTelemetry()) {
|
|
269
|
+
require_buffer.logger_default.debug("Telemetry is disabled, skipping metric telemetry", payload);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
require_buffer.logger_default.debug("SDK Metric", payload);
|
|
274
|
+
await TelemetryService.sendMetric(payload);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
require_buffer.logger_default.error("Error sending metric telemetry", error);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async sendErrorTelemetry(payload) {
|
|
280
|
+
if (!this.shouldSendTelemetry()) {
|
|
281
|
+
require_buffer.logger_default.debug("Telemetry is disabled, skipping metric telemetry", payload);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
require_buffer.logger_default.debug("SDK Error Telemetry", payload);
|
|
286
|
+
await TelemetryService.sendErrorLog(payload);
|
|
287
|
+
} catch (error) {
|
|
288
|
+
require_buffer.logger_default.error("Error sending error telemetry", error);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Flush any pending telemetry and wait for it to complete.
|
|
293
|
+
* This is automatically called on process exit in Node.js environments.
|
|
294
|
+
*/
|
|
295
|
+
async flush() {
|
|
296
|
+
await this.batchProcessor.flush();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Register process exit handlers to automatically flush telemetry.
|
|
300
|
+
* Only registers handlers in Node.js environments (not in browsers).
|
|
301
|
+
*/
|
|
302
|
+
registerExitHandlers() {
|
|
303
|
+
if (this.exitHandlersRegistered || typeof process === "undefined" || !process.on) return;
|
|
304
|
+
this.exitHandlersRegistered = true;
|
|
305
|
+
const flushSync = () => {
|
|
306
|
+
this.flush().catch((error) => {
|
|
307
|
+
require_buffer.logger_default.debug("Error flushing telemetry on exit", error);
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
process.on("beforeExit", () => {
|
|
311
|
+
flushSync();
|
|
312
|
+
});
|
|
313
|
+
const createSignalHandler = (signal) => {
|
|
314
|
+
const handler = () => {
|
|
315
|
+
require_buffer.logger_default.debug(`Received ${signal}, flushing telemetry...`);
|
|
316
|
+
this.flush().catch((error) => {
|
|
317
|
+
require_buffer.logger_default.debug("Error flushing telemetry on signal", error);
|
|
318
|
+
}).finally(() => {
|
|
319
|
+
process.removeListener(signal, handler);
|
|
320
|
+
process.kill(process.pid, signal);
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
return handler;
|
|
324
|
+
};
|
|
325
|
+
process.on("SIGINT", createSignalHandler("SIGINT"));
|
|
326
|
+
process.on("SIGTERM", createSignalHandler("SIGTERM"));
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const telemetry = new TelemetryTransport();
|
|
330
|
+
|
|
331
|
+
//#endregion
|
|
332
|
+
Object.defineProperty(exports, 'telemetry', {
|
|
333
|
+
enumerable: true,
|
|
334
|
+
get: function () {
|
|
335
|
+
return telemetry;
|
|
336
|
+
}
|
|
337
|
+
});
|