import { randomUUID } from 'crypto';

// Caching this at the top level because Promptfoo will call this for every test run
// the only way to make sure that this changes only on a per-run basis is by leveraging
// the fact that this module gets cached when it is first imported.
const CACHED_RUN_ID = `run_${randomUUID()}`;

export function runId(varName: string) {
  if (varName === 'runId') {
    return {
      output: CACHED_RUN_ID,
    };
  }

  return {
    error: 'Invalid variable name. Must use "runId"',
  };
}

export default runId;
