Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | /** |
| 2 | * Codegen: Python workbench helper source -> generated TS constant. |
| 3 | * |
| 4 | * The workbench helper is authored as real, ruff-lintable / pytest-testable |
| 5 | * Python under `src/workbench/python-helpers/`. The bundler (tsdown) and the |
| 6 | * tests (vitest) both consume a plain committed `.ts` constant, so we generate |
| 7 | * `src/workbench/python-helpers.generated.ts` from the `.py` source-of-truth. |
| 8 | * |
| 9 | * Run: pnpm --filter @composio/experimental run build:python-helpers |
| 10 | */ |
| 11 | |
| 12 | import { readFileSync, writeFileSync } from 'node:fs'; |
| 13 | import { dirname, join } from 'node:path'; |
| 14 | import { fileURLToPath } from 'node:url'; |
| 15 | import * as prettier from 'prettier'; |
| 16 | |
| 17 | const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url)); |
| 18 | const PACKAGE_DIR = join(SCRIPT_DIR, '..'); |
| 19 | const PY_SOURCE = join(PACKAGE_DIR, 'src/workbench/python-helpers/composio_helper.py'); |
| 20 | const OUTPUT = join(PACKAGE_DIR, 'src/workbench/python-helpers.generated.ts'); |
| 21 | |
| 22 | const pyText = readFileSync(PY_SOURCE, 'utf8'); |
| 23 | |
| 24 | const raw = |
| 25 | `// GENERATED by scripts/build-python-helpers.ts — do not edit; edit the .py source.\n` + |
| 26 | `// Source: src/workbench/python-helpers/composio_helper.py\n` + |
| 27 | `export const PYTHON_WORKBENCH_HELPER_SOURCE = ${JSON.stringify(pyText)};\n`; |
| 28 | |
| 29 | // Format with the repo's prettier config so the committed file is stable and the |
| 30 | // lint-staged hook / CI freshness check never see drift. |
| 31 | const prettierConfig = await prettier.resolveConfig(OUTPUT); |
| 32 | const generated = await prettier.format(raw, { ...prettierConfig, filepath: OUTPUT }); |
| 33 | |
| 34 | writeFileSync(OUTPUT, generated); |
| 35 | |
| 36 | // eslint-disable-next-line no-console |
| 37 | console.log(`Wrote ${OUTPUT} (${pyText.length} chars of Python source)`); |