Skip to content

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

1.6 KB
Raw Blame
/**
 * Codegen: Python workbench helper source -> generated TS constant.
 *
 * The workbench helper is authored as real, ruff-lintable / pytest-testable
 * Python under `src/workbench/python-helpers/`. The bundler (tsdown) and the
 * tests (vitest) both consume a plain committed `.ts` constant, so we generate
 * `src/workbench/python-helpers.generated.ts` from the `.py` source-of-truth.
 *
 * Run: pnpm --filter @composio/experimental run build:python-helpers
 */

import { readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import * as prettier from 'prettier';

const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
const PACKAGE_DIR = join(SCRIPT_DIR, '..');
const PY_SOURCE = join(PACKAGE_DIR, 'src/workbench/python-helpers/composio_helper.py');
const OUTPUT = join(PACKAGE_DIR, 'src/workbench/python-helpers.generated.ts');

const pyText = readFileSync(PY_SOURCE, 'utf8');

const raw =
  `// GENERATED by scripts/build-python-helpers.ts — do not edit; edit the .py source.\n` +
  `// Source: src/workbench/python-helpers/composio_helper.py\n` +
  `export const PYTHON_WORKBENCH_HELPER_SOURCE = ${JSON.stringify(pyText)};\n`;

// Format with the repo's prettier config so the committed file is stable and the
// lint-staged hook / CI freshness check never see drift.
const prettierConfig = await prettier.resolveConfig(OUTPUT);
const generated = await prettier.format(raw, { ...prettierConfig, filepath: OUTPUT });

writeFileSync(OUTPUT, generated);

// eslint-disable-next-line no-console
console.log(`Wrote ${OUTPUT} (${pyText.length} chars of Python source)`);