Open History to see the last commit
1/**
2 * Connect-profile helpers + defaults for assembled provider OpenAPI docs.
3 */
4import type {
5 ProviderConfig,
6 ProviderConnect,
7 RequiredHeader,
8 SpecGrain,
9} from './types.ts'
10
11/**
12 * Queue documents narrowed with `?activity=`: FAL `video` was 653 models
13 * and `image` 638 (2026-11-04), each inlined as its own schema. The
14 * unnarrowed queue document is uncapped because it inlines none.
15 */
16export const MAX_QUEUE_SPEC_PATHS = 1024
17
18export function bearerConnect(
19 serverUrl: string,
20 description?: string,
21): ProviderConnect {
22 return {
23 servers: [{ url: serverUrl, ...(description ? { description } : {}) }],
24 securitySchemes: {
25 bearerAuth: {
26 type: 'http',
27 scheme: 'bearer',
28 description: 'Provider API key as `Authorization: Bearer <key>`.',
29 },
30 },
31 security: [{ bearerAuth: [] }],
32 }
33}
34
35export function headerApiKeyConnect(
36 serverUrl: string,
37 headerName: string,
38 extra?: Pick<ProviderConnect, 'requiredHeaders' | 'siblingGet'>,
39): ProviderConnect {
40 return {
41 servers: [{ url: serverUrl }],
42 securitySchemes: {
43 apiKey: {
44 type: 'apiKey',
45 in: 'header',
46 name: headerName,
47 },
48 },
49 security: [{ apiKey: [] }],
50 ...extra,
51 }
52}
53
54/** OpenAPI header parameters. A constant becomes `schema.const`; a client-supplied header does not. */
55export function requiredHeaderParameters(
56 headers: Array<RequiredHeader> | undefined,
57): Array<Record<string, unknown>> {
58 if (!headers) return []
59 return headers.map((header) =>
60 'value' in header
61 ? {
62 name: header.name,
63 in: 'header',
64 required: true,
65 schema: { type: 'string', const: header.value },
66 }
67 : {
68 name: header.name,
69 in: 'header',
70 required: true,
71 description: header.description,
72 schema: { type: 'string' },
73 },
74 )
75}
76
77export function resolveSpecGrain(
78 provider: ProviderConfig | undefined,
79): SpecGrain {
80 return provider?.specGrain ?? 'provider'
81}
82
83/**
84 * Declared connect profile only. Adapters without `connect` are not
85 * guessed from `modelsEndpoint` (that URL is often not the data plane).
86 */
87export function resolveConnect(
88 provider: ProviderConfig | undefined,
89): ProviderConnect | null {
90 return provider?.connect ?? null
91}