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

next
ts 43 lines 1.61 KB
Raw
1 import { Effect } from 'effect';
2 import { rehydrateGenerationError, type GenerationError } from 'src/generation/errors';
3 import { loadInstalledCompanionModule } from 'src/services/run-companion-modules';
4 import type { GenerationOutcome } from 'src/services/generation-runtime';
5
6 // Type-only reference: it leaves no import behind, so the compiler stays out of
7 // the executable. The module itself is loaded from disk on first use.
8 export type GenerationRuntime = typeof import('src/services/generation-runtime');
9
10 /**
11 * The `generation-runtime` companion module (TypeScript compiler, generation
12 * pipeline, `composio run` source rewrites), loaded on demand. See
13 * `src/services/generation-runtime.ts` for why its API is Effect-free.
14 */
15 export const loadGenerationRuntime = loadInstalledCompanionModule<GenerationRuntime>(
16 'generation-runtime',
17 [
18 'BANNER',
19 'createToolkitIndex',
20 'extractInlineExecuteToolSlugs',
21 'wrapFileSourceForRun',
22 'wrapInlineCodeForRun',
23 'generateTypeScriptSourceFiles',
24 'transpileTypeScriptSourceFiles',
25 'generatePythonSourceFiles',
26 ]
27 );
28
29 /**
30 * Lifts a companion-module outcome into the CLI's runtime: successes succeed,
31 * failures fail with the CLI's own instance of the error, and a rejected promise
32 * (a defect inside the pipeline) stays a defect.
33 */
34 export const generationOutcome = <A>(
35 run: () => Promise<GenerationOutcome<A>>
36 ): Effect.Effect<A, GenerationError> =>
37 Effect.promise(run).pipe(
38 Effect.flatMap(outcome =>
39 outcome._tag === 'Success'
40 ? Effect.succeed(outcome.value)
41 : Effect.fail(rehydrateGenerationError(outcome.error))
42 )
43 );