import { Effect } from "effect"; import type * as Cause from "effect/Cause"; import type { ExecutionEngine } from "@executor/execution"; export const withExecutionUsageTracking = ( organizationId: string, engine: ExecutionEngine, trackUsage: (organizationId: string) => void, ): ExecutionEngine => ({ execute: (code, options) => engine .execute(code, options) .pipe(Effect.tap(() => Effect.sync(() => trackUsage(organizationId)))), executeWithPause: (code) => engine .executeWithPause(code) .pipe(Effect.tap(() => Effect.sync(() => trackUsage(organizationId)))), // resume doesn't count as usage resume: (executionId, response) => engine.resume(executionId, response), getDescription: engine.getDescription, });