@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
ts 104 lines 4.32 KB
Raw
1 import { Config, Option, Schema } from 'effect';
2 import * as constants from 'src/constants';
3 import type { EnvBackend } from './backend';
4 import { flag, optionalLogLevel, optionalString } from './env';
5
6 const ENVIRONMENT = optionalString('COMPOSIO_ENVIRONMENT');
7
8 /** The explicit `name` value, else the `COMPOSIO_ENVIRONMENT`-derived default. */
9 const url = (name: string, prodDefault: string, stagingDefault: string) =>
10 Config.all({ explicit: optionalString(name), environment: ENVIRONMENT }).pipe(
11 Config.map(
12 ({ explicit, environment }) =>
13 explicit ?? (environment === 'staging' ? stagingDefault : prodDefault)
14 )
15 );
16
17 const BASE_URL = url('COMPOSIO_BASE_URL', constants.DEFAULT_BASE_URL, constants.STAGING_BASE_URL);
18 const WEB_URL = url('COMPOSIO_WEB_URL', constants.DEFAULT_WEB_URL, constants.STAGING_WEB_URL);
19
20 const BACKEND: Config.Config<EnvBackend> = Config.all({
21 baseURL: BASE_URL,
22 webURL: WEB_URL,
23 explicitBaseURL: optionalString('COMPOSIO_BASE_URL'),
24 explicitWebURL: optionalString('COMPOSIO_WEB_URL'),
25 environment: ENVIRONMENT,
26 }).pipe(
27 Config.map(({ baseURL, webURL, explicitBaseURL, explicitWebURL, environment }) => ({
28 baseURL,
29 webURL,
30 selectedBy:
31 explicitBaseURL !== undefined
32 ? Option.some('COMPOSIO_BASE_URL' as const)
33 : environment !== undefined
34 ? Option.some('COMPOSIO_ENVIRONMENT' as const)
35 : Option.none(),
36 webURLSet: explicitWebURL !== undefined,
37 }))
38 );
39
40 /**
41 * The `COMPOSIO_*` variables users set to configure the CLI, documented in the README.
42 *
43 * URL precedence (highest → lowest), applied by `resolveBackend` in `./backend.ts`:
44 * COMPOSIO_BASE_URL → COMPOSIO_ENVIRONMENT-derived → stored login's `base_url` → DEFAULT_BASE_URL
45 * COMPOSIO_WEB_URL → COMPOSIO_ENVIRONMENT-derived → stored login's `web_url` → DEFAULT_WEB_URL
46 *
47 * The stored login's URLs are the backend `composio login` recorded. They apply only while
48 * neither COMPOSIO_BASE_URL nor COMPOSIO_ENVIRONMENT is set, and only to the stored key: a key
49 * from COMPOSIO_USER_API_KEY uses the env-selected URLs.
50 */
51 export const APP_CONFIG = {
52 // The API key for the Composio API
53 USER_API_KEY: optionalString('COMPOSIO_USER_API_KEY'),
54
55 // The deployment environment ("production" | "staging"). Controls URL defaults.
56 ENVIRONMENT,
57
58 // The base URL for the Composio API the environment selects, before a stored login applies
59 BASE_URL,
60
61 // The base URL for the Composio web app the environment selects, before a stored login applies
62 WEB_URL,
63
64 // Both URLs above, with which variables set them; `resolveBackend` takes it
65 BACKEND,
66
67 // The cache directory for the Composio CLI
68 CACHE_DIR: optionalString('COMPOSIO_CACHE_DIR'),
69
70 // Override the root directory for CLI session artifacts
71 SESSION_DIR: optionalString('COMPOSIO_SESSION_DIR'),
72
73 // Override the directory added to PATH by `composio install`
74 BIN_DIR: optionalString('COMPOSIO_BIN_DIR'),
75
76 // The log level for the Composio CLI
77 LOG_LEVEL: optionalLogLevel('COMPOSIO_LOG_LEVEL'),
78
79 // The organization and project for multi-project auth (override file-based config)
80 ORG_ID: optionalString('COMPOSIO_ORG_ID'),
81 PROJECT_ID: optionalString('COMPOSIO_PROJECT_ID'),
82
83 // Override the Composio agents service URL
84 AGENTS_BASE_URL: optionalString('COMPOSIO_AGENTS_BASE_URL'),
85
86 // Sign forwarded trigger payloads with this secret
87 WEBHOOK_SECRET: optionalString('COMPOSIO_WEBHOOK_SECRET'),
88
89 // Internal context propagated between CLI processes
90 CLI_INVOCATION_ORIGIN: optionalString('COMPOSIO_CLI_INVOCATION_ORIGIN'),
91 CLI_PARENT_RUN_ID: optionalString('COMPOSIO_CLI_PARENT_RUN_ID'),
92 RUN_OUTPUT_DIR: optionalString('COMPOSIO_RUN_OUTPUT_DIR'),
93 // Staged file path -> name and MIME type, for the Files a `composio run` script passed to `execute()`
94 RUN_STAGED_FILES_FILE: optionalString('COMPOSIO_RUN_STAGED_FILES_FILE'),
95
96 // Disable connected account cache (defaults to true — cache is off by default)
97 DISABLE_CONNECTED_ACCOUNT_CACHE: flag('COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE', true),
98
99 // Every `COMPOSIO_TOOLKIT_VERSION_<TOOLKIT>=<version>` pin, keyed by `<TOOLKIT>` as written.
100 // `Config.Record` reads the whole `COMPOSIO_TOOLKIT_VERSION` subtree of the environment.
101 TOOLKIT_VERSIONS: Config.option(
102 Config.Record(Schema.String, Schema.String, ['COMPOSIO', 'TOOLKIT', 'VERSION'])
103 ),
104 };