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 | import { Effect, FileSystem, Option } from 'effect'; |
| 2 | import { CliError } from 'effect/cli'; |
| 3 | |
| 4 | import { readStdin } from 'src/effects/read-stdin'; |
| 5 | |
| 6 | /** |
| 7 | * Resolves an input flag such as `-d`: `-` or `@-` reads stdin to its end, `@path` reads the |
| 8 | * file, anything else is the value itself. No flag means no input; stdin is never read then. |
| 9 | */ |
| 10 | export const resolveExplicitTextInput = (input: Option.Option<string>) => |
| 11 | Effect.gen(function* () { |
| 12 | if (Option.isNone(input)) { |
| 13 | return undefined; |
| 14 | } |
| 15 | const value = input.value.trim(); |
| 16 | if (value === '-' || value === '@-') { |
| 17 | return yield* readStdin; |
| 18 | } |
| 19 | if (value.startsWith('@')) { |
| 20 | const filePath = value.slice(1).trim(); |
| 21 | if (!filePath) { |
| 22 | return yield* Effect.fail( |
| 23 | new CliError.InvalidValue({ |
| 24 | option: 'data', |
| 25 | value, |
| 26 | expected: 'a file path after "@"', |
| 27 | kind: 'flag', |
| 28 | }) |
| 29 | ); |
| 30 | } |
| 31 | const fs = yield* FileSystem.FileSystem; |
| 32 | return yield* fs.readFileString(filePath, 'utf-8'); |
| 33 | } |
| 34 | return value; |
| 35 | }); |