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, 03:37 UTC
| 1 | /** |
| 2 | * Shared API version detection logic. |
| 3 | * Centralizes the URL-based version detection used across components and proxy. |
| 4 | */ |
| 5 | |
| 6 | export type ApiVersion = '3.1' | '3.0'; |
| 7 | export type ReferenceApiVersion = ApiVersion | null; |
| 8 | |
| 9 | /** |
| 10 | * REST base URL per API version. Single source of truth — the browser |
| 11 | * component (`components/api-base-url.tsx`), the markdown converter |
| 12 | * (`lib/source.ts`), and the version guidance constants |
| 13 | * (`lib/api-version-guidance.ts`) all read it from here rather than |
| 14 | * spelling the URL out again. |
| 15 | */ |
| 16 | export const API_BASE_URLS: Record<ApiVersion, string> = { |
| 17 | '3.1': 'https://backend.composio.dev/api/v3.1', |
| 18 | '3.0': 'https://backend.composio.dev/api/v3', |
| 19 | }; |
| 20 | |
| 21 | /** |
| 22 | * Detects the API version from a pathname. |
| 23 | * /reference/v3/ or /reference/v3 → '3.0', everything else → '3.1' |
| 24 | */ |
| 25 | export function detectApiVersion(pathname: string): ApiVersion { |
| 26 | return pathname.startsWith('/reference/v3/') || pathname === '/reference/v3' |
| 27 | ? '3.0' |
| 28 | : '3.1'; |
| 29 | } |
| 30 | |
| 31 | /** True for reference pages that describe the REST API. */ |
| 32 | export function isReferenceUrl(pathname: string): boolean { |
| 33 | return ( |
| 34 | pathname !== '/reference/glossary' && |
| 35 | pathname !== '/reference/sdk-reference' && |
| 36 | !pathname.startsWith('/reference/sdk-reference/') && |
| 37 | (pathname === '/reference' || pathname.startsWith('/reference/')) |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | /** The REST version described by a reference page, or null for SDK/glossary pages. */ |
| 42 | export function detectReferenceApiVersion(pathname: string): ReferenceApiVersion { |
| 43 | return isReferenceUrl(pathname) ? detectApiVersion(pathname) : null; |
| 44 | } |
| 45 | |
| 46 | const CURRENT_VERSION_URLS: Record<string, string> = { |
| 47 | '/reference/v3/authentication': '/reference/authenticating-to-composio', |
| 48 | }; |
| 49 | |
| 50 | /** |
| 51 | * The current-version URL for a legacy-tree page, so an agent reading a v3.0 |
| 52 | * page can be pointed at the same operation on v3.1. Any other pathname is |
| 53 | * returned unchanged. |
| 54 | */ |
| 55 | export function toCurrentVersionUrl(pathname: string): string { |
| 56 | if (CURRENT_VERSION_URLS[pathname]) return CURRENT_VERSION_URLS[pathname]; |
| 57 | if (pathname === '/reference/v3') return '/reference'; |
| 58 | if (pathname.startsWith('/reference/v3/')) { |
| 59 | return `/reference/${pathname.slice('/reference/v3/'.length)}`; |
| 60 | } |
| 61 | return pathname; |
| 62 | } |