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 114 lines 4.49 KB
Raw
1 import { Effect, Schema, SchemaGetter } from 'effect';
2 import { OptionFromOptionalNullOr } from 'effect/Schema';
3 import { JSONTransformSchema } from './utils/json-transform-schema';
4
5 /**
6 * Where the CLI stores the Composio API key.
7 *
8 * - `"auto"` (default): plaintext `user_data.json`. Backwards-
9 * compatible with every prior CLI release — upgrading does not
10 * change where the key is stored, and no migration or keychain
11 * access is attempted. Lets users harden security explicitly by
12 * picking one of the keyring options below.
13 * - `"json"`: explicit opt-in to plaintext `user_data.json`. Pins
14 * the behavior so a future default change won't affect configs
15 * that set this value.
16 * - `"keychain-subprocess"`: store the API key in the OS credential
17 * store via `/usr/bin/security` (macOS) or `secret-tool` (Linux).
18 * Adds ~25ms to startup (memoized for the process). No macOS
19 * dialogs — `/usr/bin/security` is Apple-signed and trusted.
20 * Opt-in hardening for users who want the key out of plaintext.
21 * - `"keychain"` (experimental): direct Security.framework FFI
22 * (~1ms reads). Currently triggers a macOS keychain trust dialog
23 * on unsigned / ad-hoc signed binaries — avoid unless the
24 * composio binary is signed with a stable Developer ID
25 * certificate. Linux is identical to `"keychain-subprocess"`
26 * (there's no FFI backend for libsecret).
27 */
28 export const SecurityBackend = Schema.Literals(['auto', 'json', 'keychain-subprocess', 'keychain']);
29 export type SecurityBackend = Schema.Schema.Type<typeof SecurityBackend>;
30
31 export const ExperimentalFeatures = Schema.Record(Schema.String, Schema.Boolean);
32 export type ExperimentalFeatures = Schema.Schema.Type<typeof ExperimentalFeatures>;
33
34 export const DeveloperConfig = Schema.Struct({
35 enabled: Schema.Boolean.pipe(Schema.withDecodingDefaultType(Effect.succeed(true))),
36 destructiveActions: Schema.Boolean.pipe(Schema.withDecodingDefaultType(Effect.succeed(false))),
37 }).pipe(Schema.encodeKeys({ destructiveActions: 'destructive_actions' }));
38 export type DeveloperConfig = Schema.Schema.Type<typeof DeveloperConfig>;
39
40 const CliUserConfigStruct = Schema.Struct({
41 developer: DeveloperConfig.pipe(
42 Schema.withDecodingDefaultType(
43 Effect.succeed(
44 DeveloperConfig.make({
45 enabled: true,
46 destructiveActions: false,
47 })
48 )
49 )
50 ),
51 experimentalFeatures: ExperimentalFeatures.pipe(
52 Schema.withDecodingDefaultType(Effect.succeed({}))
53 ),
54 artifactDirectory: OptionFromOptionalNullOr(Schema.String, { onNoneEncoding: null }),
55 /**
56 * Where the CLI stores the Composio API key. See the
57 * `SecurityBackend` type above for semantics. Default: `"auto"`
58 * (plaintext `user_data.json`, same as every prior CLI release —
59 * no behavior change on upgrade).
60 */
61 security: SecurityBackend.pipe(
62 Schema.withDecodingDefaultType(Effect.succeed<SecurityBackend>('auto'))
63 ),
64 });
65
66 const CliUserConfigWithEncodedKeys = CliUserConfigStruct.pipe(
67 Schema.encodeKeys({
68 experimentalFeatures: 'experimental_features',
69 artifactDirectory: 'artifact_directory',
70 })
71 );
72
73 const unknownCliUserConfigFields = [Schema.Record(Schema.String, Schema.Unknown)] as const;
74
75 export const CliUserConfig = Schema.StructWithRest(
76 CliUserConfigWithEncodedKeys.from,
77 unknownCliUserConfigFields
78 ).pipe(
79 Schema.decodeTo(
80 Schema.StructWithRest(CliUserConfigWithEncodedKeys.to, unknownCliUserConfigFields),
81 {
82 decode: SchemaGetter.transform(
83 ({ developer, experimental_features, artifact_directory, security, ...rest }) => ({
84 ...rest,
85 developer,
86 experimentalFeatures: experimental_features,
87 artifactDirectory: artifact_directory,
88 security,
89 })
90 ),
91 encode: SchemaGetter.transform(
92 ({ developer, experimentalFeatures, artifactDirectory, security, ...rest }) => ({
93 ...rest,
94 developer,
95 experimental_features: experimentalFeatures,
96 artifact_directory: artifactDirectory,
97 security,
98 })
99 ),
100 }
101 ),
102 Schema.annotate({
103 identifier: 'CliUserConfig',
104 description: 'Named user configuration storage for the Composio CLI',
105 })
106 );
107
108 export type CliUserConfig = Schema.Schema.Type<typeof CliUserConfig>;
109
110 export const CliUserConfigJSON = JSONTransformSchema(CliUserConfig);
111 export const cliUserConfigFromJSON = Schema.decodeEffect(CliUserConfigJSON, {
112 onExcessProperty: 'ignore',
113 });
114 export const cliUserConfigToJSON = Schema.encodeEffect(CliUserConfigJSON);