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 { Brand, Effect, Schema } from 'effect'; |
| 2 | import { JSONTransformSchema } from './utils/json-transform-schema'; |
| 3 | |
| 4 | /** |
| 5 | * The shape of a toolkit slug: a single, safe path segment (no `/`, `\`, or |
| 6 | * `..`), which prevents path traversal / arbitrary file write when a slug is |
| 7 | * interpolated into a filename and joined to the generator's output directory. |
| 8 | * See CWE-22. |
| 9 | * |
| 10 | * Shared so that every place that has to vouch for a slug — the schema below, |
| 11 | * the baked-catalog generator, and the test guarding its output — tightens |
| 12 | * together rather than drifting apart. |
| 13 | */ |
| 14 | export const TOOLKIT_SLUG_PATTERN = /^[a-z0-9_][a-z0-9_-]*$/; |
| 15 | |
| 16 | /** |
| 17 | * A toolkit slug used to derive generated source filenames. |
| 18 | */ |
| 19 | export const ToolkitSlug = Schema.Trim.check( |
| 20 | Schema.isNonEmpty(), |
| 21 | Schema.isPattern(TOOLKIT_SLUG_PATTERN, { |
| 22 | identifier: 'ToolkitSlug', |
| 23 | message: |
| 24 | 'Toolkit slug must contain only lowercase letters, digits, underscores, and hyphens (no path separators)', |
| 25 | }) |
| 26 | ); |
| 27 | |
| 28 | export const Toolkit = Schema.Struct({ |
| 29 | name: Schema.String, // "Gmail" |
| 30 | slug: ToolkitSlug, // "gmail" |
| 31 | // The API marks the auth fields optional; project custom toolkits may omit them. |
| 32 | auth_schemes: Schema.Array(Schema.String).pipe( |
| 33 | Schema.withDecodingDefaultType(Effect.succeed([])) |
| 34 | ), // [ "OAUTH2", "BEARER_TOKEN" ] |
| 35 | composio_managed_auth_schemes: Schema.Array(Schema.String).pipe( |
| 36 | Schema.withDecodingDefaultType(Effect.succeed([])) |
| 37 | ), // [ "OAUTH2" ] |
| 38 | is_local_toolkit: Schema.Boolean, |
| 39 | meta: Schema.Struct({ |
| 40 | description: Schema.String, |
| 41 | categories: Schema.Array(Schema.Unknown), |
| 42 | created_at: Schema.DateTimeUtcFromString, // "2024-05-03T11:44:32.061Z" |
| 43 | updated_at: Schema.DateTimeUtcFromString, // "2024-05-03T11:44:32.061Z" |
| 44 | available_versions: Schema.Array(Schema.String).pipe( |
| 45 | Schema.withDecodingDefaultType(Effect.succeed([])) |
| 46 | ), |
| 47 | tools_count: Schema.Int.pipe(Schema.withDecodingDefaultType(Effect.succeed(0))), |
| 48 | triggers_count: Schema.Int.pipe(Schema.withDecodingDefaultType(Effect.succeed(0))), |
| 49 | }), |
| 50 | no_auth: Schema.Boolean.pipe(Schema.withDecodingDefaultType(Effect.succeed(false))), |
| 51 | }).annotate({ identifier: 'Toolkit' }); |
| 52 | export type Toolkit = Schema.Schema.Type<typeof Toolkit>; |
| 53 | |
| 54 | export const Toolkits = Schema.Array(Toolkit); |
| 55 | export type Toolkits = Schema.Schema.Type<typeof Toolkits>; |
| 56 | |
| 57 | export const ToolkitsJSON = JSONTransformSchema(Toolkits); |
| 58 | export const toolkitsFromJSON = Schema.decodeEffect(ToolkitsJSON); |
| 59 | export const toolkitsToJSON = Schema.encodeEffect(ToolkitsJSON); |
| 60 | |
| 61 | export type ToolkitName = string & Brand.Brand<'ToolkitName'>; |
| 62 | export const ToolkitName = Brand.nominal<ToolkitName>(); |
| 63 | |
| 64 | /** |
| 65 | * Field definition for auth config creation / connected account initiation. |
| 66 | */ |
| 67 | export const AuthConfigField = Schema.Struct({ |
| 68 | name: Schema.String, |
| 69 | displayName: Schema.String, |
| 70 | description: Schema.String, |
| 71 | type: Schema.String, |
| 72 | required: Schema.Boolean, |
| 73 | default: Schema.NullOr(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed(null))), |
| 74 | }).annotate({ identifier: 'AuthConfigField' }); |
| 75 | export type AuthConfigField = Schema.Schema.Type<typeof AuthConfigField>; |
| 76 | |
| 77 | /** |
| 78 | * Auth config detail for a specific auth scheme (e.g. OAUTH2, API_KEY). |
| 79 | */ |
| 80 | export const AuthConfigDetail = Schema.Struct({ |
| 81 | mode: Schema.String, |
| 82 | name: Schema.String, |
| 83 | fields: Schema.Struct({ |
| 84 | auth_config_creation: Schema.Struct({ |
| 85 | required: Schema.Array(AuthConfigField), |
| 86 | optional: Schema.Array(AuthConfigField), |
| 87 | }), |
| 88 | connected_account_initiation: Schema.Struct({ |
| 89 | required: Schema.Array(AuthConfigField), |
| 90 | optional: Schema.Array(AuthConfigField), |
| 91 | }), |
| 92 | }), |
| 93 | }).annotate({ identifier: 'AuthConfigDetail' }); |
| 94 | export type AuthConfigDetail = Schema.Schema.Type<typeof AuthConfigDetail>; |
| 95 | |
| 96 | /** |
| 97 | * Detailed toolkit info from the retrieve endpoint, includes auth_config_details. |
| 98 | */ |
| 99 | export const ToolkitDetailed = Schema.Struct({ |
| 100 | name: Schema.String, |
| 101 | slug: ToolkitSlug, |
| 102 | is_local_toolkit: Schema.Boolean, |
| 103 | composio_managed_auth_schemes: Schema.Array(Schema.String).pipe( |
| 104 | Schema.withDecodingDefaultType(Effect.succeed([])) |
| 105 | ), |
| 106 | no_auth: Schema.Boolean.pipe(Schema.withDecodingDefaultType(Effect.succeed(false))), |
| 107 | meta: Schema.Struct({ |
| 108 | description: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed(''))), |
| 109 | categories: Schema.Array(Schema.Unknown).pipe( |
| 110 | Schema.withDecodingDefaultType(Effect.succeed([])) |
| 111 | ), |
| 112 | created_at: Schema.DateTimeUtcFromString, |
| 113 | updated_at: Schema.DateTimeUtcFromString, |
| 114 | available_versions: Schema.Array(Schema.String).pipe( |
| 115 | Schema.withDecodingDefaultType(Effect.succeed([])) |
| 116 | ), |
| 117 | tools_count: Schema.Int.pipe(Schema.withDecodingDefaultType(Effect.succeed(0))), |
| 118 | triggers_count: Schema.Int.pipe(Schema.withDecodingDefaultType(Effect.succeed(0))), |
| 119 | }), |
| 120 | auth_config_details: Schema.Array(AuthConfigDetail).pipe( |
| 121 | Schema.withDecodingDefaultType(Effect.succeed([])) |
| 122 | ), |
| 123 | }).annotate({ identifier: 'ToolkitDetailed' }); |
| 124 | export type ToolkitDetailed = Schema.Schema.Type<typeof ToolkitDetailed>; |
| 125 | |
| 126 | /** |
| 127 | * Search result for a single page of toolkits. |
| 128 | */ |
| 129 | export const ToolkitSearchResult = Schema.Struct({ |
| 130 | items: Toolkits, |
| 131 | total_items: Schema.Int, |
| 132 | total_pages: Schema.Int, |
| 133 | next_cursor: Schema.NullOr(Schema.String), |
| 134 | }).annotate({ identifier: 'ToolkitSearchResult' }); |
| 135 | export type ToolkitSearchResult = Schema.Schema.Type<typeof ToolkitSearchResult>; |