UNPKG

@tanstack/ai

Version:

Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.

28 lines (22 loc) 892 B
/** * Provider ids are open slugs, not a closed catalog. `@tanstack/ai` does not * list adapters. Any matching string is a valid id and becomes `x-byok-<id>`. */ export type ProviderId = string /** `[a-z][a-z0-9-]{0,63}` — lowercase, no underscores, max 64 chars. */ export const BYOK_PROVIDER_ID_PATTERN = /^[a-z][a-z0-9-]{0,63}$/ export const BYOK_HEADER_PREFIX = 'x-byok-' export function isProviderId(value: unknown): value is ProviderId { return typeof value === 'string' && BYOK_PROVIDER_ID_PATTERN.test(value) } export function resolveProviderId( provider: string | { readonly id: string }, ): string { return typeof provider === 'string' ? provider : provider.id } export function byokHeaderName(provider: string): string { if (!isProviderId(provider)) { throw new Error(`Invalid BYOK provider id: ${provider}`) } return `${BYOK_HEADER_PREFIX}${provider}` }