Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 36 lines 907 Bytes
Raw
1 import { Effect } from 'effect';
2
3 /**
4 * Metrics from API calls.
5 */
6 export type Metrics = {
7 readonly byteSize: number;
8 readonly requests: number;
9 };
10
11 /**
12 * Formats byte size into a human-readable string.
13 * @param bytes - Number of bytes to format
14 * @returns A string like "1.23 KB" or "456 B"
15 */
16 const formatBytes = (bytes: number): string => {
17 if (bytes < 1024) {
18 return `${bytes} B`;
19 }
20 const kb = bytes / 1024;
21 if (kb < 1024) {
22 return `${kb.toFixed(2)} KB`;
23 }
24 const mb = kb / 1024;
25 return `${mb.toFixed(2)} MB`;
26 };
27
28 /**
29 * Logs API metrics (request count and total bytes downloaded) at debug level.
30 * @param metrics - The metrics to log
31 * @returns An Effect that logs the metrics
32 */
33 export const logMetrics = (metrics: Metrics): Effect.Effect<void> =>
34 Effect.logDebug(
35 `API metrics: ${metrics.requests} request(s), ${formatBytes(metrics.byteSize)} downloaded`
36 );