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, 04:45 UTC
| 1 | // Entry point of the `generation-runtime` companion module: everything in the |
| 2 | // CLI that needs the TypeScript compiler, bundled into `dist/generation-runtime.mjs` |
| 3 | // next to the executable rather than into the executable itself. The compiler is |
| 4 | // ~3.7MB of minified JavaScript that every invocation used to parse at startup |
| 5 | // (about 74ms on the pinned toolchain) even though only `composio generate` and |
| 6 | // `composio run` call it. See `RUN_COMPANION_MODULE_BASENAMES`. |
| 7 | // |
| 8 | // The CLI loads this file with `loadInstalledCompanionModule('generation-runtime')`. |
| 9 | // Because the bundle carries its own copy of `effect`, nothing Effect-shaped may |
| 10 | // cross the boundary: a fiber cannot run primitives built by another copy of the |
| 11 | // runtime. So this module exposes plain functions and promises, runs the Effect |
| 12 | // pipelines on its own runtime, and reports failures as values that |
| 13 | // `rehydrateGenerationError` turns back into the CLI's error classes. Results |
| 14 | // stay object references (same process), no serialization happens. |
| 15 | import * as BunPath from '@effect/platform-bun/BunPath'; |
| 16 | import type * as Path from 'effect/Path'; |
| 17 | import { Effect, Result } from 'effect'; |
| 18 | import type { ToolkitIndex } from 'src/generation/create-toolkit-index'; |
| 19 | import type { GenerationError } from 'src/generation/errors'; |
| 20 | import { generatePythonSources } from 'src/generation/python/generate'; |
| 21 | import type { SourceFile } from 'src/generation/types'; |
| 22 | import { generateTypeScriptSources } from 'src/generation/typescript/generate'; |
| 23 | import { transpileTypeScriptSources } from 'src/generation/typescript/transpile'; |
| 24 | |
| 25 | export { BANNER } from 'src/generation/constants'; |
| 26 | export { createToolkitIndex } from 'src/generation/create-toolkit-index'; |
| 27 | export type { ToolkitIndex } from 'src/generation/create-toolkit-index'; |
| 28 | export { |
| 29 | extractInlineExecuteToolSlugs, |
| 30 | wrapFileSourceForRun, |
| 31 | wrapInlineCodeForRun, |
| 32 | } from 'src/commands/run-source-transforms'; |
| 33 | |
| 34 | /** Outcome of a generation step, as a value the CLI's own runtime can consume. */ |
| 35 | export type GenerationOutcome<A> = |
| 36 | | { readonly _tag: 'Success'; readonly value: A } |
| 37 | | { readonly _tag: 'Failure'; readonly error: GenerationError }; |
| 38 | |
| 39 | // Failures become `GenerationOutcome`; a defect (an unexpected throw inside the |
| 40 | // pipeline) still rejects the promise, so the CLI treats it as a defect too. |
| 41 | const runOutcome = <A, E extends GenerationError>( |
| 42 | effect: Effect.Effect<A, E, Path.Path> |
| 43 | ): Promise<GenerationOutcome<A>> => |
| 44 | Effect.runPromise( |
| 45 | effect.pipe( |
| 46 | Effect.provide(BunPath.layer), |
| 47 | Effect.result, |
| 48 | Effect.map((result): GenerationOutcome<A> => |
| 49 | Result.isSuccess(result) |
| 50 | ? { _tag: 'Success', value: result.success } |
| 51 | : { _tag: 'Failure', error: result.failure } |
| 52 | ) |
| 53 | ) |
| 54 | ); |
| 55 | |
| 56 | export type GenerateTypeScriptSourcesParams = Parameters<typeof generateTypeScriptSources>[0]; |
| 57 | export type TranspileTypeScriptSourcesParams = Parameters<typeof transpileTypeScriptSources>[0]; |
| 58 | export type GeneratePythonSourcesParams = Parameters<typeof generatePythonSources>[0]; |
| 59 | |
| 60 | export const generateTypeScriptSourceFiles = ( |
| 61 | params: GenerateTypeScriptSourcesParams, |
| 62 | index: ToolkitIndex |
| 63 | ): Promise<GenerationOutcome<Array<SourceFile>>> => |
| 64 | runOutcome(generateTypeScriptSources(params)(index)); |
| 65 | |
| 66 | export const transpileTypeScriptSourceFiles = ( |
| 67 | params: TranspileTypeScriptSourcesParams |
| 68 | ): Promise<GenerationOutcome<void>> => runOutcome(transpileTypeScriptSources(params)); |
| 69 | |
| 70 | export const generatePythonSourceFiles = ( |
| 71 | params: GeneratePythonSourcesParams, |
| 72 | index: ToolkitIndex |
| 73 | ): Promise<GenerationOutcome<Array<SourceFile>>> => |
| 74 | runOutcome(generatePythonSources(params)(index)); |