@composio/core 0.12.0 → 0.13.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-BBnsv9kS.d.mts → BaseProvider-Brb3o86-.d.mts} +80 -80
- package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
- package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-DLf7JeKt.d.mts} +1 -1
- package/dist/CustomTool-NpHpqdnU.d.mts +74 -0
- package/dist/{composio-CHnEggnv.d.mts → composio-BHSQwOUz.d.mts} +503 -319
- package/dist/composio-DfPD7BAi.d.mts +5666 -0
- package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-9yFqPjdw.d.mts} +448 -76
- package/dist/customTool.types-D-6YqFdW.d.mts +2826 -0
- package/dist/docs/error-consistency.md +97 -0
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
- package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +252 -0
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +155 -0
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
- package/dist/{errors-D5f4pfvI.mjs → errors-DSIlYfl5.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +36 -6
- package/dist/index.mjs +455 -123
- package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
- package/dist/{types-CaI5Z4PA.d.mts → types-BJLCRj9q.d.mts} +2 -2
- package/dist/types-CCh8qvui.d.mts +12 -0
- 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 +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/docs/error-consistency.md +97 -0
- package/package.json +4 -3
- package/src/composio.ts +509 -0
- package/src/errors/AuthConfigErrors.ts +23 -0
- package/src/errors/ComposioError.ts +408 -0
- package/src/errors/ConnectedAccountsErrors.ts +158 -0
- package/src/errors/ConnectionRequestErrors.ts +32 -0
- package/src/errors/FileModifierErrors.ts +100 -0
- package/src/errors/PusherErrors.ts +28 -0
- package/src/errors/RemoteFileErrors.ts +62 -0
- package/src/errors/SDKErrors.ts +92 -0
- package/src/errors/ToolErrors.ts +244 -0
- package/src/errors/ToolkitErrors.ts +39 -0
- package/src/errors/TriggerErrors.ts +120 -0
- package/src/errors/ValidationErrors.ts +99 -0
- package/src/errors/index.ts +41 -0
- package/src/experimental/index.ts +28 -0
- package/src/index.ts +64 -0
- package/src/lib/toolRouterConstants.ts +1 -0
- package/src/lib/toolRouterParams.ts +306 -0
- package/src/lib/toolRouterSessionDelete.ts +30 -0
- package/src/models/AuthConfigs.ts +398 -0
- package/src/models/AuthScheme.ts +206 -0
- package/src/models/ConnectedAccounts.ts +735 -0
- package/src/models/ConnectionRequest.ts +150 -0
- package/src/models/CustomTool.ts +676 -0
- package/src/models/Experimental.ts +202 -0
- package/src/models/Files.node.ts +93 -0
- package/src/models/Files.workerd.ts +49 -0
- package/src/models/MCP.ts +478 -0
- package/src/models/RemoteFile.ts +172 -0
- package/src/models/SessionContext.ts +147 -0
- package/src/models/Sessions.ts +21 -0
- package/src/models/ToolRouter.ts +406 -0
- package/src/models/ToolRouterSession.ts +839 -0
- package/src/models/ToolRouterSessionFileMount.ts +389 -0
- package/src/models/Toolkits.ts +412 -0
- package/src/models/Tools.ts +1260 -0
- package/src/models/Triggers.ts +1381 -0
- package/src/models/customToolExecution.ts +118 -0
- package/src/models/inlineCustomToolsPayload.ts +17 -0
- package/src/models/proxyParamsTransform.ts +26 -0
- package/src/provider/BaseProvider.ts +138 -0
- package/src/provider/ComposioProvider.ts +29 -0
- package/src/provider/OpenAIProvider.ts +547 -0
- package/src/services/internal/InternalService.ts +50 -0
- package/src/services/internal/InternalService.types.ts +14 -0
- package/src/services/pusher/Pusher.ts +230 -0
- package/src/services/telemetry/TelemetryService.ts +48 -0
- package/src/services/telemetry/TelemetryService.types.ts +67 -0
- package/src/telemetry/BatchProcessor.ts +77 -0
- package/src/telemetry/README.md +123 -0
- package/src/telemetry/Telemetry.ts +356 -0
- package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
- package/src/types/authConfigs.types.ts +174 -0
- package/src/types/composio.types.ts +1 -0
- package/src/types/connectedAccountAuthStates.types.ts +852 -0
- package/src/types/connectedAccounts.types.ts +395 -0
- package/src/types/connectionRequest.types.ts +16 -0
- package/src/types/customTool.types.ts +261 -0
- package/src/types/files.types.ts +15 -0
- package/src/types/mcp.experimental.types.ts +163 -0
- package/src/types/mcp.types.ts +362 -0
- package/src/types/modifiers.types.ts +663 -0
- package/src/types/org.types.ts +0 -0
- package/src/types/provider.types.ts +41 -0
- package/src/types/pusher.types.ts +18 -0
- package/src/types/requestOptions.types.ts +62 -0
- package/src/types/telemetry.types.ts +89 -0
- package/src/types/tool.types.ts +408 -0
- package/src/types/toolRouter.types.ts +774 -0
- package/src/types/toolkit.types.ts +130 -0
- package/src/types/triggers.types.ts +401 -0
- package/src/types/webhookEvents.types.ts +219 -0
- package/src/utils/buffer.ts +30 -0
- package/src/utils/cancellation.ts +22 -0
- package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
- package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
- package/src/utils/config-defaults/index.ts +1 -0
- package/src/utils/config-defaults/types.ts +14 -0
- package/src/utils/constants.ts +22 -0
- package/src/utils/crypto.ts +34 -0
- package/src/utils/env.ts +34 -0
- package/src/utils/fileDirs.ts +81 -0
- package/src/utils/fileUtils.node.ts +458 -0
- package/src/utils/json-schema.ts +1 -0
- package/src/utils/jsonSchema.ts +355 -0
- package/src/utils/logger.ts +99 -0
- package/src/utils/mime.ts +75 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
- package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
- package/src/utils/pagination.ts +73 -0
- package/src/utils/pusher.ts +286 -0
- package/src/utils/schemaPropertyKeys.ts +433 -0
- package/src/utils/sdk.ts +110 -0
- package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
- package/src/utils/session.ts +114 -0
- package/src/utils/toolArguments.ts +73 -0
- package/src/utils/toolkitVersion.ts +26 -0
- package/src/utils/transform.ts +42 -0
- package/src/utils/transformers/authConfigs.ts +107 -0
- package/src/utils/transformers/connectedAccounts.ts +119 -0
- package/src/utils/transformers/mcp.ts +164 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
- package/src/utils/transformers/toolkits.ts +100 -0
- package/src/utils/transformers/triggers.ts +118 -0
- package/src/utils/uploadDirAllowlist.node.ts +178 -0
- package/src/utils/uuid.ts +7 -0
- package/src/utils/version.ts +58 -0
- package/src/utils/zodSchema.ts +90 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
// Extend the Error interface to include errorId
|
|
2
|
+
declare global {
|
|
3
|
+
interface Error {
|
|
4
|
+
errorId?: string;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
import { ComposioError as ComposioClientError } from '@composio/client';
|
|
9
|
+
import { TELEMETRY_EVENTS, TelemetryMetadata } from '../types/telemetry.types';
|
|
10
|
+
import { getEnvVariable } from '../utils/env';
|
|
11
|
+
import { BatchProcessor } from './BatchProcessor';
|
|
12
|
+
import { ComposioError } from '../errors/ComposioError';
|
|
13
|
+
import { getRandomUUID } from '../utils/uuid';
|
|
14
|
+
import {
|
|
15
|
+
TelemetryMetricPayloadBody,
|
|
16
|
+
TelemetryMetricSource,
|
|
17
|
+
TelemetryPayload,
|
|
18
|
+
} from '../services/telemetry/TelemetryService.types';
|
|
19
|
+
import { TelemetryService } from '../services/telemetry/TelemetryService';
|
|
20
|
+
import logger from '../utils/logger';
|
|
21
|
+
/**
|
|
22
|
+
* The Telemetry class is used to log the telemetry for any given instance which extends InstrumentedInstance.
|
|
23
|
+
*
|
|
24
|
+
* This class is used to instrument the telemetry for the given instance and send the telemetry to the server.
|
|
25
|
+
* This class is also used to create a global error handler for the given instance.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* const telemetry = new Telemetry({...});
|
|
30
|
+
* const composio = new Composio({...})
|
|
31
|
+
*
|
|
32
|
+
* telemetry.instrument(composio);
|
|
33
|
+
* telemetry.instrument(composio.tools);
|
|
34
|
+
* telemetry.instrument(composio.toolkits);
|
|
35
|
+
* telemetry.instrument(composio.triggers);
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
export class TelemetryTransport {
|
|
39
|
+
private telemetryMetadata!: TelemetryMetadata;
|
|
40
|
+
private isTelemetryDisabled: boolean = true;
|
|
41
|
+
private telemetrySource!: TelemetryMetricSource;
|
|
42
|
+
private readonly telemetrySourceName = 'typescript-sdk';
|
|
43
|
+
private readonly telemetryServiceName = 'sdk';
|
|
44
|
+
private readonly telemetryLanguage = 'typescript';
|
|
45
|
+
private exitHandlersRegistered = false;
|
|
46
|
+
private pendingImmediateTelemetry: Set<Promise<void>> = new Set();
|
|
47
|
+
|
|
48
|
+
private batchProcessor = new BatchProcessor(200, 10, async (data: TelemetryMetricPayloadBody) => {
|
|
49
|
+
logger.debug('Sending batch of telemetry metrics', data);
|
|
50
|
+
await TelemetryService.sendMetric(data as TelemetryPayload[]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
setup(metadata: TelemetryMetadata) {
|
|
54
|
+
this.telemetryMetadata = metadata;
|
|
55
|
+
this.isTelemetryDisabled = false;
|
|
56
|
+
this.telemetrySource = {
|
|
57
|
+
host: this.telemetryMetadata?.host ?? this.telemetrySourceName,
|
|
58
|
+
service: this.telemetryServiceName,
|
|
59
|
+
language: this.telemetryLanguage,
|
|
60
|
+
version: this.telemetryMetadata?.version,
|
|
61
|
+
platform: this.telemetryMetadata?.isBrowser ? 'browser' : 'node',
|
|
62
|
+
environment: getEnvVariable('NODE_ENV', 'production') as TelemetryMetricSource['environment'],
|
|
63
|
+
};
|
|
64
|
+
// Register exit handlers to automatically flush telemetry before process exit
|
|
65
|
+
this.registerExitHandlers();
|
|
66
|
+
|
|
67
|
+
// send telemetry event for SDK initialization without blocking setup
|
|
68
|
+
this.deferTelemetry(() =>
|
|
69
|
+
this.sendMetric([
|
|
70
|
+
{
|
|
71
|
+
functionName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
72
|
+
durationMs: 0,
|
|
73
|
+
timestamp: Date.now() / 1000,
|
|
74
|
+
props: {},
|
|
75
|
+
source: this.telemetrySource,
|
|
76
|
+
metadata: {
|
|
77
|
+
provider: this.telemetryMetadata?.provider ?? 'openai',
|
|
78
|
+
},
|
|
79
|
+
error: undefined,
|
|
80
|
+
},
|
|
81
|
+
])
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Instrument the telemetry for the given instance.
|
|
87
|
+
*
|
|
88
|
+
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
89
|
+
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
90
|
+
* @param instance - any instance that extends InstrumentedInstance
|
|
91
|
+
* @param fileName - the file name of the instance
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
instrument<T extends object>(instance: T, fileName?: string) {
|
|
95
|
+
const proto = Object.getPrototypeOf(instance);
|
|
96
|
+
const methodNames = Object.getOwnPropertyNames(proto).filter(key => {
|
|
97
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
98
|
+
return (
|
|
99
|
+
key !== 'constructor' &&
|
|
100
|
+
descriptor &&
|
|
101
|
+
typeof descriptor.value === 'function' &&
|
|
102
|
+
descriptor.value.constructor.name === 'AsyncFunction'
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
// prioritize the explicitly passed class name, then fall back to constructor name, then 'unknown'
|
|
106
|
+
const instrumentedClassName = fileName ?? instance.constructor?.name ?? 'unknown';
|
|
107
|
+
|
|
108
|
+
for (const name of methodNames) {
|
|
109
|
+
const originalMethod = (instance as unknown as Record<string, Function>)[name] as (
|
|
110
|
+
...args: unknown[]
|
|
111
|
+
) => Promise<unknown>;
|
|
112
|
+
|
|
113
|
+
(instance as unknown as Record<string, Function>)[name] = async (...args: unknown[]) => {
|
|
114
|
+
// Check telemetry status once at the start to ensure consistent behavior
|
|
115
|
+
const telemetryEnabled = this.shouldSendTelemetry();
|
|
116
|
+
const startTime = telemetryEnabled ? Date.now() : undefined;
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const result = await originalMethod.apply(instance, args);
|
|
120
|
+
|
|
121
|
+
// Only collect telemetry if setup() has been called (telemetry is enabled)
|
|
122
|
+
if (telemetryEnabled && startTime !== undefined) {
|
|
123
|
+
const durationMs = Date.now() - startTime;
|
|
124
|
+
const telemetryPayload: TelemetryPayload = {
|
|
125
|
+
functionName: `${instrumentedClassName}.${name}`,
|
|
126
|
+
durationMs,
|
|
127
|
+
timestamp: startTime / 1000,
|
|
128
|
+
props: {
|
|
129
|
+
fileName: instrumentedClassName,
|
|
130
|
+
method: name,
|
|
131
|
+
},
|
|
132
|
+
metadata: {
|
|
133
|
+
provider: this.telemetryMetadata?.provider ?? 'openai',
|
|
134
|
+
},
|
|
135
|
+
error: undefined,
|
|
136
|
+
source: this.telemetrySource,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
this.batchProcessor.pushItem(telemetryPayload);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return result;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (error instanceof Error) {
|
|
145
|
+
if (!error.errorId) {
|
|
146
|
+
error.errorId = getRandomUUID();
|
|
147
|
+
// Only send error telemetry if telemetry is enabled
|
|
148
|
+
if (telemetryEnabled && startTime !== undefined) {
|
|
149
|
+
const durationMs = Date.now() - startTime;
|
|
150
|
+
this.prepareAndSendErrorTelemetry(
|
|
151
|
+
error,
|
|
152
|
+
instrumentedClassName,
|
|
153
|
+
name,
|
|
154
|
+
startTime,
|
|
155
|
+
durationMs
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return instance;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Check if the telemetry should be sent.
|
|
170
|
+
* @returns true if the telemetry should be sent, false otherwise
|
|
171
|
+
*/
|
|
172
|
+
private shouldSendTelemetry() {
|
|
173
|
+
const telemetryDisabledEnvironments = ['test', 'ci'];
|
|
174
|
+
const nodeEnv = (getEnvVariable('NODE_ENV', 'development') || '').toLowerCase();
|
|
175
|
+
const isDisabledEnvironment = telemetryDisabledEnvironments.includes(nodeEnv);
|
|
176
|
+
const isTelemetryDisabledByEnv = getEnvVariable('TELEMETRY_DISABLED', 'false') === 'true';
|
|
177
|
+
|
|
178
|
+
return !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDisabledEnvironment;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Prepare and send the error telemetry.
|
|
183
|
+
*
|
|
184
|
+
* @param {unknown} error - The error to send.
|
|
185
|
+
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
186
|
+
* @param {string} name - The name of the method that threw the error.
|
|
187
|
+
* @param {number} startTime - The start time of the method invocation in milliseconds.
|
|
188
|
+
* @param {number} durationMs - The duration of the method invocation in milliseconds.
|
|
189
|
+
*/
|
|
190
|
+
private prepareAndSendErrorTelemetry(
|
|
191
|
+
error: unknown,
|
|
192
|
+
instrumentedClassName: string,
|
|
193
|
+
name: string,
|
|
194
|
+
startTime: number,
|
|
195
|
+
durationMs: number
|
|
196
|
+
) {
|
|
197
|
+
const telemetryPayload: TelemetryPayload = {
|
|
198
|
+
functionName: `${instrumentedClassName}.${name}`,
|
|
199
|
+
durationMs,
|
|
200
|
+
timestamp: startTime / 1000,
|
|
201
|
+
props: {
|
|
202
|
+
fileName: instrumentedClassName,
|
|
203
|
+
method: name,
|
|
204
|
+
},
|
|
205
|
+
metadata: {
|
|
206
|
+
provider: this.telemetryMetadata?.provider ?? 'openai',
|
|
207
|
+
},
|
|
208
|
+
source: this.telemetrySource,
|
|
209
|
+
};
|
|
210
|
+
// client error, this is likely handled by the API itseld
|
|
211
|
+
if (error instanceof ComposioClientError) {
|
|
212
|
+
telemetryPayload.error = {
|
|
213
|
+
errorId: error.errorId,
|
|
214
|
+
name: error.name,
|
|
215
|
+
message: error.message,
|
|
216
|
+
stack: error.stack,
|
|
217
|
+
};
|
|
218
|
+
} else if (error instanceof ComposioError) {
|
|
219
|
+
telemetryPayload.error = {
|
|
220
|
+
errorId: error.errorId,
|
|
221
|
+
name: error.name,
|
|
222
|
+
code: error.code,
|
|
223
|
+
message: error.message,
|
|
224
|
+
stack: error.stack,
|
|
225
|
+
};
|
|
226
|
+
} else if (error instanceof Error) {
|
|
227
|
+
telemetryPayload.error = {
|
|
228
|
+
errorId: error.errorId,
|
|
229
|
+
name: error.name ?? 'Unknown error',
|
|
230
|
+
message: error.message,
|
|
231
|
+
stack: error.stack,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this.deferTelemetry(() => this.sendErrorTelemetry(telemetryPayload));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private deferTelemetry(callback: () => Promise<void>): void {
|
|
239
|
+
const pending = new Promise<void>(resolve => {
|
|
240
|
+
const run = () => {
|
|
241
|
+
Promise.resolve()
|
|
242
|
+
.then(callback)
|
|
243
|
+
.catch(error => {
|
|
244
|
+
logger.debug('Error sending deferred telemetry', error);
|
|
245
|
+
})
|
|
246
|
+
.finally(resolve);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
if (typeof queueMicrotask === 'function') {
|
|
250
|
+
queueMicrotask(run);
|
|
251
|
+
} else {
|
|
252
|
+
setTimeout(run, 0);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
this.pendingImmediateTelemetry.add(pending);
|
|
257
|
+
pending.finally(() => {
|
|
258
|
+
this.pendingImmediateTelemetry.delete(pending);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private async flushImmediateTelemetry(): Promise<void> {
|
|
263
|
+
while (this.pendingImmediateTelemetry.size > 0) {
|
|
264
|
+
await Promise.all(Array.from(this.pendingImmediateTelemetry));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Send the telemetry payload to the server.
|
|
270
|
+
* @param payload - the telemetry payload to send
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
async sendMetric(payload: TelemetryMetricPayloadBody) {
|
|
274
|
+
if (!this.shouldSendTelemetry()) {
|
|
275
|
+
logger.debug('Telemetry is disabled, skipping metric telemetry', payload);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
logger.debug('SDK Metric', payload);
|
|
280
|
+
await TelemetryService.sendMetric(payload);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
logger.error('Error sending metric telemetry', error);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// @TODO: check if this will send the error telemetry to the server
|
|
286
|
+
async sendErrorTelemetry(payload: TelemetryPayload) {
|
|
287
|
+
if (!this.shouldSendTelemetry()) {
|
|
288
|
+
logger.debug('Telemetry is disabled, skipping metric telemetry', payload);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
logger.debug('SDK Error Telemetry', payload);
|
|
293
|
+
await TelemetryService.sendErrorLog(payload);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
logger.error('Error sending error telemetry', error);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Flush any pending telemetry and wait for it to complete.
|
|
301
|
+
* This is automatically called on process exit in Node.js environments.
|
|
302
|
+
*/
|
|
303
|
+
async flush(): Promise<void> {
|
|
304
|
+
await this.batchProcessor.flush();
|
|
305
|
+
await this.flushImmediateTelemetry();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Register process exit handlers to automatically flush telemetry.
|
|
310
|
+
* Only registers handlers in Node.js environments (not in browsers).
|
|
311
|
+
*/
|
|
312
|
+
private registerExitHandlers(): void {
|
|
313
|
+
// Only register once and only in Node.js environments
|
|
314
|
+
if (this.exitHandlersRegistered || typeof process === 'undefined' || !process.on) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
this.exitHandlersRegistered = true;
|
|
319
|
+
|
|
320
|
+
const flushSync = () => {
|
|
321
|
+
// Use a flag to track if we're already flushing to prevent double-flush
|
|
322
|
+
this.flush().catch(error => {
|
|
323
|
+
logger.debug('Error flushing telemetry on exit', error);
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// beforeExit is emitted when Node.js empties its event loop and has nothing else to schedule
|
|
328
|
+
// This is the best place to flush async operations
|
|
329
|
+
process.on('beforeExit', () => {
|
|
330
|
+
flushSync();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// Handle SIGINT (Ctrl+C) and SIGTERM (kill command)
|
|
334
|
+
// Store handler references so they can be properly removed
|
|
335
|
+
const createSignalHandler = (signal: NodeJS.Signals) => {
|
|
336
|
+
const handler = () => {
|
|
337
|
+
logger.debug(`Received ${signal}, flushing telemetry...`);
|
|
338
|
+
this.flush()
|
|
339
|
+
.catch(error => {
|
|
340
|
+
logger.debug('Error flushing telemetry on signal', error);
|
|
341
|
+
})
|
|
342
|
+
.finally(() => {
|
|
343
|
+
// Remove the handler before re-emitting to prevent infinite loop
|
|
344
|
+
process.removeListener(signal, handler);
|
|
345
|
+
process.kill(process.pid, signal);
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
return handler;
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
process.on('SIGINT', createSignalHandler('SIGINT'));
|
|
352
|
+
process.on('SIGTERM', createSignalHandler('SIGTERM'));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export const telemetry = new TelemetryTransport();
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import z from 'zod/v3';
|
|
2
|
+
import { DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID } from '../utils/constants';
|
|
3
|
+
|
|
4
|
+
export const ToolRouterSessionFilesMountListOptionsSchema = z.object({
|
|
5
|
+
path: z.string().optional(),
|
|
6
|
+
mountId: z.string().default(DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID),
|
|
7
|
+
/** Pagination cursor from the previous response nextCursor field */
|
|
8
|
+
cursor: z.string().optional(),
|
|
9
|
+
/** Maximum number of files to return per page (1-500) */
|
|
10
|
+
limit: z.number().min(1).max(500).optional(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export type ToolRouterSessionFilesMountListOptions = z.input<
|
|
14
|
+
typeof ToolRouterSessionFilesMountListOptionsSchema
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
const FileListItemSchema = z.object({
|
|
18
|
+
last_modified: z.string(),
|
|
19
|
+
mount_relative_path: z.string(),
|
|
20
|
+
sandbox_mount_prefix: z.string(),
|
|
21
|
+
size: z.number(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const FileListResponseSchema = z
|
|
25
|
+
.object({
|
|
26
|
+
items: z.array(FileListItemSchema),
|
|
27
|
+
next_cursor: z.string().optional(),
|
|
28
|
+
})
|
|
29
|
+
.transform(data => ({
|
|
30
|
+
items: data.items.map(item => ({
|
|
31
|
+
lastModified: item.last_modified,
|
|
32
|
+
mountRelativePath: item.mount_relative_path,
|
|
33
|
+
sandboxMountPrefix: item.sandbox_mount_prefix,
|
|
34
|
+
size: item.size,
|
|
35
|
+
})),
|
|
36
|
+
nextCursor: data.next_cursor,
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
export type FileListResponse = z.infer<typeof FileListResponseSchema>;
|
|
40
|
+
|
|
41
|
+
export const ToolRouterSessionFilesMountUploadOptionsSchema = z.object({
|
|
42
|
+
/** Remote path/filename on the mount. When passing a buffer, either mimetype or remotePath is required. */
|
|
43
|
+
remotePath: z.string().optional(),
|
|
44
|
+
mountId: z.string().default(DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID),
|
|
45
|
+
/** MIME type. When passing a buffer, either mimetype or remotePath is required. Ignored when passing File (uses file.type). */
|
|
46
|
+
mimetype: z.string().optional(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export type ToolRouterSessionFilesMountUploadOptions = z.input<
|
|
50
|
+
typeof ToolRouterSessionFilesMountUploadOptionsSchema
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
export const ToolRouterSessionFilesMountDownloadOptionsSchema = z.object({
|
|
54
|
+
mountId: z.string().default(DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export type ToolRouterSessionFilesMountDownloadOptions = z.input<
|
|
58
|
+
typeof ToolRouterSessionFilesMountDownloadOptionsSchema
|
|
59
|
+
>;
|
|
60
|
+
|
|
61
|
+
export const ToolRouterSessionFilesMountDeleteOptionsSchema = z.object({
|
|
62
|
+
mountId: z.string().default(DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export type ToolRouterSessionFilesMountDeleteOptions = z.input<
|
|
66
|
+
typeof ToolRouterSessionFilesMountDeleteOptionsSchema
|
|
67
|
+
>;
|
|
68
|
+
|
|
69
|
+
export const RemoteFileDataSchema = z
|
|
70
|
+
.object({
|
|
71
|
+
expires_at: z.string(),
|
|
72
|
+
mount_relative_path: z.string(),
|
|
73
|
+
sandbox_mount_prefix: z.string(),
|
|
74
|
+
download_url: z.string(),
|
|
75
|
+
})
|
|
76
|
+
.transform(data => ({
|
|
77
|
+
expiresAt: data.expires_at,
|
|
78
|
+
mountRelativePath: data.mount_relative_path,
|
|
79
|
+
sandboxMountPrefix: data.sandbox_mount_prefix,
|
|
80
|
+
downloadUrl: data.download_url,
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
/** Parsed shape from API response. Use with `new RemoteFile(data)`. */
|
|
84
|
+
export type RemoteFileData = z.infer<typeof RemoteFileDataSchema>;
|
|
85
|
+
|
|
86
|
+
export const FileDeleteResponseSchema = z
|
|
87
|
+
.object({
|
|
88
|
+
mount_relative_path: z.string(),
|
|
89
|
+
sandbox_mount_prefix: z.string(),
|
|
90
|
+
})
|
|
91
|
+
.transform(data => ({
|
|
92
|
+
mountRelativePath: data.mount_relative_path,
|
|
93
|
+
sandboxMountPrefix: data.sandbox_mount_prefix,
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
export type FileDeleteResponse = z.infer<typeof FileDeleteResponseSchema>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
|
|
3
|
+
export const AuthConfigTypes = {
|
|
4
|
+
CUSTOM: 'use_custom_auth',
|
|
5
|
+
COMPOSIO_MANAGED: 'use_composio_managed_auth',
|
|
6
|
+
} as const;
|
|
7
|
+
export type AuthConfigType = (typeof AuthConfigTypes)[keyof typeof AuthConfigTypes];
|
|
8
|
+
|
|
9
|
+
export const AuthSchemeTypes = {
|
|
10
|
+
OAUTH1: 'OAUTH1',
|
|
11
|
+
OAUTH2: 'OAUTH2',
|
|
12
|
+
API_KEY: 'API_KEY',
|
|
13
|
+
BASIC: 'BASIC',
|
|
14
|
+
BEARER_TOKEN: 'BEARER_TOKEN',
|
|
15
|
+
BILLCOM_AUTH: 'BILLCOM_AUTH',
|
|
16
|
+
GOOGLE_SERVICE_ACCOUNT: 'GOOGLE_SERVICE_ACCOUNT',
|
|
17
|
+
NO_AUTH: 'NO_AUTH',
|
|
18
|
+
BASIC_WITH_JWT: 'BASIC_WITH_JWT',
|
|
19
|
+
CALCOM_AUTH: 'CALCOM_AUTH',
|
|
20
|
+
SERVICE_ACCOUNT: 'SERVICE_ACCOUNT',
|
|
21
|
+
SAML: 'SAML',
|
|
22
|
+
DCR_OAUTH: 'DCR_OAUTH',
|
|
23
|
+
S2S_OAUTH2: 'S2S_OAUTH2',
|
|
24
|
+
} as const;
|
|
25
|
+
export type AuthSchemeType = (typeof AuthSchemeTypes)[keyof typeof AuthSchemeTypes];
|
|
26
|
+
|
|
27
|
+
export const AuthConfigCreationToolAccessConfigSchema = z.object({
|
|
28
|
+
toolsForConnectedAccountCreation: z.array(z.string()).optional(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const AuthConfigToolAccessConfigSchema = z.object({
|
|
32
|
+
toolsAvailableForExecution: z.array(z.string()).optional(),
|
|
33
|
+
toolsForConnectedAccountCreation: z.array(z.string()).optional(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const AuthSchemeEnum = z.enum([
|
|
37
|
+
'OAUTH2',
|
|
38
|
+
'OAUTH1',
|
|
39
|
+
'API_KEY',
|
|
40
|
+
'BASIC',
|
|
41
|
+
'BILLCOM_AUTH',
|
|
42
|
+
'BEARER_TOKEN',
|
|
43
|
+
'GOOGLE_SERVICE_ACCOUNT',
|
|
44
|
+
'NO_AUTH',
|
|
45
|
+
'BASIC_WITH_JWT',
|
|
46
|
+
'CALCOM_AUTH',
|
|
47
|
+
'SERVICE_ACCOUNT',
|
|
48
|
+
'SAML',
|
|
49
|
+
'DCR_OAUTH',
|
|
50
|
+
'S2S_OAUTH2',
|
|
51
|
+
]);
|
|
52
|
+
export const CreateCustomAuthConfigParamsSchema = z.object({
|
|
53
|
+
type: z.literal('use_custom_auth'),
|
|
54
|
+
name: z.string().optional(),
|
|
55
|
+
credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
|
|
56
|
+
authScheme: AuthSchemeEnum,
|
|
57
|
+
proxyConfig: z
|
|
58
|
+
.object({
|
|
59
|
+
proxyUrl: z.string(),
|
|
60
|
+
proxyAuthKey: z.string().optional(),
|
|
61
|
+
})
|
|
62
|
+
.optional(),
|
|
63
|
+
toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional(),
|
|
64
|
+
isEnabledForToolRouter: z.boolean().optional(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const CreateComposioManagedAuthConfigParamsSchema = z.object({
|
|
68
|
+
type: z.literal('use_composio_managed_auth'),
|
|
69
|
+
name: z.string().optional(),
|
|
70
|
+
credentials: z
|
|
71
|
+
.object({
|
|
72
|
+
scopes: z.union([z.string(), z.array(z.string())]).optional(),
|
|
73
|
+
user_scopes: z.union([z.string(), z.array(z.string())]).optional(),
|
|
74
|
+
})
|
|
75
|
+
.passthrough()
|
|
76
|
+
.optional(),
|
|
77
|
+
toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional(),
|
|
78
|
+
isEnabledForToolRouter: z.boolean().optional(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Discriminated union of all possible auth config types.
|
|
83
|
+
*/
|
|
84
|
+
export const CreateAuthConfigParamsSchema = z.discriminatedUnion('type', [
|
|
85
|
+
CreateCustomAuthConfigParamsSchema,
|
|
86
|
+
CreateComposioManagedAuthConfigParamsSchema,
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
export type CreateAuthConfigParams = z.infer<typeof CreateAuthConfigParamsSchema>;
|
|
90
|
+
|
|
91
|
+
export const CreateAuthConfigResponseSchema = z.object({
|
|
92
|
+
id: z.string(),
|
|
93
|
+
authScheme: z.string(),
|
|
94
|
+
isComposioManaged: z.boolean(),
|
|
95
|
+
toolkit: z.string(),
|
|
96
|
+
});
|
|
97
|
+
export type CreateAuthConfigResponse = z.infer<typeof CreateAuthConfigResponseSchema>;
|
|
98
|
+
|
|
99
|
+
export const AuthConfigRetrieveResponseSchema = z.object({
|
|
100
|
+
id: z.string(),
|
|
101
|
+
name: z.string(),
|
|
102
|
+
toolkit: z.object({
|
|
103
|
+
logo: z.string(),
|
|
104
|
+
slug: z.string(),
|
|
105
|
+
}),
|
|
106
|
+
noOfConnections: z.number(),
|
|
107
|
+
status: z.enum(['ENABLED', 'DISABLED']),
|
|
108
|
+
authScheme: AuthSchemeEnum.optional(),
|
|
109
|
+
credentials: z.record(z.string(), z.unknown()).optional(),
|
|
110
|
+
expectedInputFields: z.array(z.unknown()).optional(),
|
|
111
|
+
isEnabledForToolRouter: z.boolean().optional(),
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated - use tool access config to determine the tools that the user can perform on the auth config.
|
|
114
|
+
*/
|
|
115
|
+
restrictToFollowingTools: z.array(z.string()).optional(),
|
|
116
|
+
isComposioManaged: z.boolean().optional(),
|
|
117
|
+
createdBy: z.string().optional(),
|
|
118
|
+
createdAt: z.string().optional(),
|
|
119
|
+
lastUpdatedAt: z.string().optional(),
|
|
120
|
+
toolAccessConfig: AuthConfigToolAccessConfigSchema.optional(),
|
|
121
|
+
});
|
|
122
|
+
export type AuthConfigRetrieveResponse = z.infer<typeof AuthConfigRetrieveResponseSchema>;
|
|
123
|
+
|
|
124
|
+
export const AuthConfigListParamsSchema = z.object({
|
|
125
|
+
cursor: z.string().optional(),
|
|
126
|
+
isComposioManaged: z.boolean().optional(),
|
|
127
|
+
limit: z.number().optional(),
|
|
128
|
+
search: z.string().optional(),
|
|
129
|
+
showDisabled: z.boolean().optional(),
|
|
130
|
+
toolkit: z.string().optional(),
|
|
131
|
+
});
|
|
132
|
+
export type AuthConfigListParams = z.infer<typeof AuthConfigListParamsSchema>;
|
|
133
|
+
|
|
134
|
+
export const AuthConfigListResponseSchema = z.object({
|
|
135
|
+
items: z.array(AuthConfigRetrieveResponseSchema),
|
|
136
|
+
nextCursor: z.string().nullable(),
|
|
137
|
+
totalPages: z.number(),
|
|
138
|
+
});
|
|
139
|
+
export type AuthConfigListResponse = z.infer<typeof AuthConfigListResponseSchema>;
|
|
140
|
+
|
|
141
|
+
export const AuthCustomConfigUpdateParamsSchema = z.object({
|
|
142
|
+
type: z.literal('custom'),
|
|
143
|
+
credentials: z
|
|
144
|
+
.object({
|
|
145
|
+
scopes: z.union([z.string(), z.array(z.string())]).optional(),
|
|
146
|
+
user_scopes: z.union([z.string(), z.array(z.string())]).optional(),
|
|
147
|
+
})
|
|
148
|
+
.passthrough()
|
|
149
|
+
.optional(),
|
|
150
|
+
isEnabledForToolRouter: z.boolean().optional(),
|
|
151
|
+
/**
|
|
152
|
+
* @deprecated - use tool access config to determine the tools that the user can perform on the auth config.
|
|
153
|
+
*/
|
|
154
|
+
restrictToFollowingTools: z.array(z.string()).optional(),
|
|
155
|
+
toolAccessConfig: AuthConfigToolAccessConfigSchema.optional(),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
export const AuthDefaultConfigUpdateParamsSchema = z.object({
|
|
159
|
+
type: z.literal('default'),
|
|
160
|
+
scopes: z.string().optional(),
|
|
161
|
+
isEnabledForToolRouter: z.boolean().optional(),
|
|
162
|
+
/**
|
|
163
|
+
* @deprecated - use tool access config to determine the tools that the user can perform on the auth config.
|
|
164
|
+
*/
|
|
165
|
+
restrictToFollowingTools: z.array(z.string()).optional(),
|
|
166
|
+
toolAccessConfig: AuthConfigToolAccessConfigSchema.optional(),
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export const AuthConfigUpdateParamsSchema = z.discriminatedUnion('type', [
|
|
170
|
+
AuthCustomConfigUpdateParamsSchema,
|
|
171
|
+
AuthDefaultConfigUpdateParamsSchema,
|
|
172
|
+
]);
|
|
173
|
+
|
|
174
|
+
export type AuthConfigUpdateParams = z.infer<typeof AuthConfigUpdateParamsSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ComposioRequestHeaders = Record<string, string>;
|