Open History to see the last commit
1/**
2 * Connect-profile helpers + defaults for assembled provider OpenAPI docs.
3 */
4import type { ProviderConfig, ProviderConnect, SpecGrain } from './types.ts'
5
6/** Refuse assembly above this many classified generation endpoints. */
7export const MAX_SPEC_PATHS = 40
8
9export function bearerConnect(
10 serverUrl: string,
11 description?: string,
12): ProviderConnect {
13 return {
14 servers: [{ url: serverUrl, ...(description ? { description } : {}) }],
15 securitySchemes: {
16 bearerAuth: {
17 type: 'http',
18 scheme: 'bearer',
19 description: 'Provider API key as `Authorization: Bearer <key>`.',
20 },
21 },
22 security: [{ bearerAuth: [] }],
23 }
24}
25
26export function headerApiKeyConnect(
27 serverUrl: string,
28 headerName: string,
29 extra?: Pick<ProviderConnect, 'requiredHeaders' | 'siblingGet'>,
30): ProviderConnect {
31 return {
32 servers: [{ url: serverUrl }],
33 securitySchemes: {
34 apiKey: {
35 type: 'apiKey',
36 in: 'header',
37 name: headerName,
38 },
39 },
40 security: [{ apiKey: [] }],
41 ...extra,
42 }
43}
44
45export function resolveSpecGrain(
46 provider: ProviderConfig | undefined,
47): SpecGrain {
48 return provider?.specGrain ?? 'provider'
49}
50
51/**
52 * Declared connect profile only. Adapters without `connect` are not
53 * guessed from `modelsEndpoint` (that URL is often not the data plane).
54 */
55export function resolveConnect(
56 provider: ProviderConfig | undefined,
57): ProviderConnect | null {
58 return provider?.connect ?? null
59}