okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-split-int (a3024ed10) into f-split-qa1: qa2's s3237-s3238 kept, my 21 strings renumbered s3260-s32808667a3dbf

main
922 B18 linesraw
1/**
2 * The address an app is given depends on who builds the final request URL.
3 *
4 * OpenAI-style clients (Chat Completions, Responses) are given the base that ends in /v1 and add /chat/completions or /responses.
5 * Anthropic-style clients (Claude Code, the Anthropic SDKs) add /v1/messages themselves, so they are given the server root. With
6 * the /v1 base they post /v1/v1/messages.
7 */
8export type ConnectProtocol = 'openai' | 'responses' | 'anthropic';
9
10/** The server root: the base address without its trailing /v1. */
11export function serverRoot(baseUrl: string): string {
12  return String(baseUrl ?? '').trim().replace(/\/+$/, '').replace(/\/v1$/i, '');
13}
14
15/** The address to type into an app that speaks this protocol. */
16export function appBaseUrl(baseUrl: string, protocol: ConnectProtocol): string {
17  return protocol === 'anthropic' ? serverRoot(baseUrl) : String(baseUrl ?? '').trim().replace(/\/+$/, '');
18}