Files
Alberto Schiabel 6e0a9db3c7 feat(docs): make coding agents reach for REST API v3.1 (#4079)
This PR:

- fixes
[UXE-233](https://linear.app/composio/issue/UXE-233/docs-should-explicitly-direct-agents-to-use-v31-apis)
- makes the agent-facing Markdown channels publish concrete REST v3.1
base URLs and endpoint tables while preserving the supported v3.0
reference tree
- centralizes `REST_VERSION_GUIDANCE`, `TOOL_VERSION_GUIDANCE`, and
raw-spec path matching in `lib/api-version-guidance.ts`
- renders `ApiBaseUrl` and `ApiEndpointsTable` in authored MDX and adds
an explicit version pointer to generated OpenAPI operation Markdown
- separates current and legacy REST references in `llms.txt`, excludes
v3.0 page bodies from `llms-full.txt`, and adds v3.1 selection guidance
to Context7
- validates serialized `ApiEndpointsTable` payloads with Zod before
generation while preserving forward-compatible fields
- addresses review feedback for the renamed authentication page,
SDK-reference pointer scope, generator validation behavior, and stale
OpenAPI tool-version descriptions

## Context

REST v3.0 is superseded but remains supported for existing integrations.
This PR changes what new agent-generated code discovers first; it does
not require existing v3.0 callers to migrate.

Authenticated read-only probes against the deployed API confirmed that
the affected v3 endpoints default to `00000000_00`, while their v3.1
counterparts default to `latest`. `POST /tools/scopes/required` is
available only on v3.1 and defaults to `latest`.

This PR does not move public URLs. A future `/reference/v3/` to
`/reference/v3.0/` migration remains separate because it has independent
compatibility and search-indexing risk.

## Verification

- `bun test tests/static/`
- `bun run build`
- `bun run test:integration`
- `bun run types:check`
- `bun run lint`

## Review follow-up

The version-default guidance is intentionally limited to the five
verified tool endpoints. v3.1 is a structural superset of v3, so this PR
does not claim route parity. Static coverage rejects broad non-tool
parity wording in both the shared guidance and Context7 rules.
2026-08-07 18:48:00 +05:30

63 lines
2.2 KiB
TypeScript

/**
* Shared API version detection logic.
* Centralizes the URL-based version detection used across components and proxy.
*/
export type ApiVersion = '3.1' | '3.0';
export type ReferenceApiVersion = ApiVersion | null;
/**
* REST base URL per API version. Single source of truth — the browser
* component (`components/api-base-url.tsx`), the markdown converter
* (`lib/source.ts`), and the version guidance constants
* (`lib/api-version-guidance.ts`) all read it from here rather than
* spelling the URL out again.
*/
export const API_BASE_URLS: Record<ApiVersion, string> = {
'3.1': 'https://backend.composio.dev/api/v3.1',
'3.0': 'https://backend.composio.dev/api/v3',
};
/**
* Detects the API version from a pathname.
* /reference/v3/ or /reference/v3 → '3.0', everything else → '3.1'
*/
export function detectApiVersion(pathname: string): ApiVersion {
return pathname.startsWith('/reference/v3/') || pathname === '/reference/v3'
? '3.0'
: '3.1';
}
/** True for reference pages that describe the REST API. */
export function isReferenceUrl(pathname: string): boolean {
return (
pathname !== '/reference/glossary' &&
pathname !== '/reference/sdk-reference' &&
!pathname.startsWith('/reference/sdk-reference/') &&
(pathname === '/reference' || pathname.startsWith('/reference/'))
);
}
/** The REST version described by a reference page, or null for SDK/glossary pages. */
export function detectReferenceApiVersion(pathname: string): ReferenceApiVersion {
return isReferenceUrl(pathname) ? detectApiVersion(pathname) : null;
}
const CURRENT_VERSION_URLS: Record<string, string> = {
'/reference/v3/authentication': '/reference/authenticating-to-composio',
};
/**
* The current-version URL for a legacy-tree page, so an agent reading a v3.0
* page can be pointed at the same operation on v3.1. Any other pathname is
* returned unchanged.
*/
export function toCurrentVersionUrl(pathname: string): string {
if (CURRENT_VERSION_URLS[pathname]) return CURRENT_VERSION_URLS[pathname];
if (pathname === '/reference/v3') return '/reference';
if (pathname.startsWith('/reference/v3/')) {
return `/reference/${pathname.slice('/reference/v3/'.length)}`;
}
return pathname;
}