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 { telemetry, withCommandTelemetry } from 'src/analytics/command-input'; |
| 2 | import { withCommandMeta } from 'src/invocation/command-identity'; |
| 3 | import { Argument, Command, Flag } from 'effect/cli'; |
| 4 | import { runProxy } from './proxy.handler'; |
| 5 | |
| 6 | const endpoint = Argument.String('url').pipe( |
| 7 | Argument.withDescription('Absolute or relative API endpoint to call through proxy execute.') |
| 8 | ); |
| 9 | |
| 10 | const toolkit = Flag.String('toolkit').pipe( |
| 11 | Flag.withAlias('t'), |
| 12 | Flag.withDescription('Toolkit slug whose connected account should be used') |
| 13 | ); |
| 14 | |
| 15 | const account = Flag.String('account').pipe( |
| 16 | Flag.withDescription( |
| 17 | 'Connected account selector. Matches alias, word_id, or connected account id for the toolkit.' |
| 18 | ), |
| 19 | Flag.optional |
| 20 | ); |
| 21 | |
| 22 | const method = Flag.String('method').pipe( |
| 23 | Flag.withAlias('X'), |
| 24 | Flag.withDefault('GET'), |
| 25 | Flag.withDescription('HTTP method, curl-style (GET, POST, PUT, DELETE, PATCH)') |
| 26 | ); |
| 27 | |
| 28 | const headers = Flag.String('header').pipe( |
| 29 | Flag.withAlias('H'), |
| 30 | Flag.withDescription('Header in "Name: value" format. Repeat for multiple headers.'), |
| 31 | Flag.atLeast(0) |
| 32 | ); |
| 33 | |
| 34 | const data = Flag.String('data').pipe( |
| 35 | Flag.withAlias('d'), |
| 36 | Flag.withDescription('Request body as raw text, JSON, @file, or - for stdin'), |
| 37 | Flag.optional |
| 38 | ); |
| 39 | |
| 40 | const skipConnectionCheck = Flag.Boolean('skip-connection-check').pipe( |
| 41 | Flag.withDefault(false), |
| 42 | Flag.withDescription( |
| 43 | 'Skip the short-lived connected-account fail-fast check if you just connected an account' |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | const proxyCmdBase = Command.make( |
| 48 | 'proxy', |
| 49 | { |
| 50 | endpoint, |
| 51 | toolkit, |
| 52 | account, |
| 53 | method, |
| 54 | headers, |
| 55 | data, |
| 56 | skipConnectionCheck, |
| 57 | }, |
| 58 | runProxy |
| 59 | ).pipe( |
| 60 | Command.withDescription( |
| 61 | 'curl-like access to any toolkit API through Composio using your connected account.\nComposio handles authentication — just provide the full URL and toolkit.' |
| 62 | ), |
| 63 | Command.withShortDescription( |
| 64 | 'curl-like access to any toolkit API through Composio using your connected account.' |
| 65 | ), |
| 66 | Command.withExamples([ |
| 67 | { |
| 68 | command: |
| 69 | 'composio proxy https://gmail.googleapis.com/gmail/v1/users/me/profile --toolkit gmail --account work', |
| 70 | }, |
| 71 | { |
| 72 | command: |
| 73 | 'composio proxy https://gmail.googleapis.com/gmail/v1/users/me/drafts --toolkit gmail \\\n -X POST -H \'content-type: application/json\' -d \'{"message":{"raw":"..."}}\'', |
| 74 | }, |
| 75 | ]), |
| 76 | withCommandMeta({ requiresLogin: true }) |
| 77 | ); |
| 78 | |
| 79 | export const proxyCmd = withCommandTelemetry(proxyCmdBase, input => |
| 80 | telemetry.fields({ |
| 81 | toolkit: telemetry.value(input.toolkit), |
| 82 | method: telemetry.value(input.method), |
| 83 | has_endpoint: telemetry.value(true), |
| 84 | has_data: telemetry.flag('--data', telemetry.present(input.data)), |
| 85 | header_count: { |
| 86 | value: input.headers?.length ?? 0, |
| 87 | flags: input.headers?.length ? ['--header'] : [], |
| 88 | }, |
| 89 | skip_connection_check: telemetry.flag('--skip-connection-check', input.skipConnectionCheck), |
| 90 | }) |
| 91 | ); |