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 108 lines 3.2 KB
Raw
1 import { Schema, SchemaGetter } from 'effect';
2 import { JSONTransformSchema } from './utils/json-transform-schema';
3 import { OptionFromOptionalNullOr } from 'effect/Schema';
4
5 const userDataFields = {
6 /**
7 * API key for the Composio API server.
8 */
9 apiKey: OptionFromOptionalNullOr(Schema.String, { onNoneEncoding: null }),
10
11 /**
12 * Base URL for the Composio API server (backend).
13 */
14 baseURL: OptionFromOptionalNullOr(Schema.String, { onNoneEncoding: null }),
15
16 /**
17 * Base URL for the Composio web app (frontend).
18 */
19 webURL: OptionFromOptionalNullOr(Schema.String, { onNoneEncoding: null }),
20
21 /**
22 * Organization ID for the current user.
23 */
24 orgId: OptionFromOptionalNullOr(Schema.String, { onNoneEncoding: null }),
25
26 /**
27 * Legacy global project ID retained for backward-compatible reads.
28 * New CLI versions no longer persist this field.
29 */
30 projectId: OptionFromOptionalNullOr(Schema.String, { onNoneEncoding: null }),
31
32 /**
33 * Optional global test user identifier used by CLI/e2e flows.
34 */
35 testUserId: OptionFromOptionalNullOr(Schema.String, { onNoneEncoding: null }),
36 };
37
38 const userDataKeyMapping = {
39 apiKey: 'api_key',
40 baseURL: 'base_url',
41 webURL: 'web_url',
42 orgId: 'org_id',
43 projectId: 'project_id',
44 testUserId: 'test_user_id',
45 } as const;
46
47 const UserDataStruct = Schema.Struct(userDataFields);
48 const UserDataWithEncodedKeys = UserDataStruct.pipe(Schema.encodeKeys(userDataKeyMapping));
49 const unknownUserDataFields = [Schema.Record(Schema.String, Schema.Unknown)] as const;
50
51 export const UserData = Schema.StructWithRest(
52 UserDataWithEncodedKeys.from,
53 unknownUserDataFields
54 ).pipe(
55 Schema.decodeTo(Schema.StructWithRest(UserDataWithEncodedKeys.to, unknownUserDataFields), {
56 decode: SchemaGetter.transform(
57 ({ api_key, base_url, web_url, org_id, project_id, test_user_id, ...rest }) => ({
58 ...rest,
59 apiKey: api_key,
60 baseURL: base_url,
61 webURL: web_url,
62 orgId: org_id,
63 projectId: project_id,
64 testUserId: test_user_id,
65 })
66 ),
67 encode: SchemaGetter.transform(
68 ({ apiKey, baseURL, webURL, orgId, projectId, testUserId, ...rest }) => ({
69 ...rest,
70 api_key: apiKey,
71 base_url: baseURL,
72 web_url: webURL,
73 org_id: orgId,
74 project_id: projectId,
75 test_user_id: testUserId,
76 })
77 ),
78 }),
79 Schema.annotate({
80 identifier: 'UserData',
81 description: 'User data storage for the Composio CLI',
82 })
83 );
84
85 export type UserData = Schema.Schema.Type<typeof UserData>;
86
87 export const UserDataWithDefaults = Schema.Struct({
88 ...userDataFields,
89
90 baseURL: Schema.String,
91 webURL: Schema.String,
92
93 // orgId and legacy projectId remain as Option<string> — they may not be set.
94 }).pipe(
95 Schema.encodeKeys(userDataKeyMapping),
96 Schema.annotate({
97 identifier: 'UserDataWithDefaults',
98 description: 'User data storage for the Composio CLI with defaults',
99 })
100 );
101
102 export type UserDataWithDefaults = Schema.Schema.Type<typeof UserDataWithDefaults>;
103
104 export const UserDataJSON = JSONTransformSchema(UserData);
105 export const userDataFromJSON = Schema.decodeEffect(UserDataJSON, {
106 onExcessProperty: 'ignore',
107 });
108 export const userDataToJSON = Schema.encodeEffect(UserDataJSON);