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C5C,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,mBAAmB,CAAC,CAY9B","sourcesContent":["import type { OAuthCredential } from \"../auth/types.ts\";\nimport type { Model, ThinkingLevelMap } from \"../types.ts\";\n\nexport const DEFAULT_RADIUS_GATEWAY = \"https://radius.pi.dev\";\n\nexport type RadiusGatewayModel = {\n\tid: string;\n\tname: string;\n\treasoning: boolean;\n\tthinkingLevelMap?: ThinkingLevelMap;\n\tinput: (\"text\" | \"image\")[];\n\tcost: Model<\"pi-messages\">[\"cost\"];\n\tcontextWindow: number;\n\tmaxTokens: number;\n};\n\nexport type RadiusGatewayConfig = {\n\tbaseUrl: string;\n\tmodels: RadiusGatewayModel[];\n};\n\nexport type RadiusOAuthCredential = OAuthCredential & {\n\tgatewayConfig?: RadiusGatewayConfig;\n};\n\nfunction isRadiusGatewayModel(value: unknown): value is RadiusGatewayModel {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return false;\n\tconst model = value as Partial<RadiusGatewayModel>;\n\treturn (\n\t\ttypeof model.id === \"string\" &&\n\t\ttypeof model.name === \"string\" &&\n\t\ttypeof model.reasoning === \"boolean\" &&\n\t\tArray.isArray(model.input) &&\n\t\ttypeof model.cost === \"object\" &&\n\t\tmodel.cost !== null &&\n\t\t!Array.isArray(model.cost) &&\n\t\ttypeof model.contextWindow === \"number\" &&\n\t\ttypeof model.maxTokens === \"number\"\n\t);\n}\n\nfunction sanitizeRadiusGatewayConfig(config: unknown): RadiusGatewayConfig | undefined {\n\tif (typeof config !== \"object\" || config === null || Array.isArray(config)) return undefined;\n\tconst { baseUrl, models } = config as Partial<RadiusGatewayConfig>;\n\tif (typeof baseUrl !== \"string\" || !Array.isArray(models)) return undefined;\n\treturn {\n\t\tbaseUrl,\n\t\tmodels: models.filter(isRadiusGatewayModel).map((model) => ({ ...model })),\n\t};\n}\n\nexport function normalizeRadiusGatewayUrl(value: string): string {\n\tconst withScheme = /^https?:\\/\\//iu.test(value) ? value : `https://${value}`;\n\treturn withScheme.replace(/\\/+$/u, \"\");\n}\n\nexport function getRadiusCredentialConfig(credential: OAuthCredential | undefined): RadiusGatewayConfig | undefined {\n\treturn sanitizeRadiusGatewayConfig((credential as RadiusOAuthCredential | undefined)?.gatewayConfig);\n}\n\nexport function getRadiusModelsFromConfig(providerId: string, config: RadiusGatewayConfig): Model<\"pi-messages\">[] {\n\treturn config.models.map((model) => ({\n\t\t...model,\n\t\tapi: \"pi-messages\",\n\t\tprovider: providerId,\n\t\tbaseUrl: config.baseUrl,\n\t}));\n}\n\nexport function getRadiusModels(providerId: string, credential: OAuthCredential | undefined): Model<\"pi-messages\">[] {\n\tconst config = getRadiusCredentialConfig(credential);\n\treturn config ? getRadiusModelsFromConfig(providerId, config) : [];\n}\n\nfunction truncateHttpBody(body: string): string {\n\tconst trimmed = body.trim();\n\treturn trimmed.length > 512 ? `${trimmed.slice(0, 512)}…` : trimmed;\n}\n\nexport async function loadRadiusGatewayConfig(\n\tgateway: string,\n\tapiKey?: string,\n\tsignal?: AbortSignal,\n): Promise<RadiusGatewayConfig> {\n\tconst headers: Record<string, string> = { accept: \"application/json\" };\n\tif (apiKey) headers.authorization = `Bearer ${apiKey}`;\n\tconst response = await fetch(new URL(\"/v1/config\", gateway), { headers, signal });\n\tif (!response.ok) {\n\t\tthrow new Error(\n\t\t\t`Could not load Radius config from ${gateway}: ${response.status}: ${truncateHttpBody(await response.text())}`,\n\t\t);\n\t}\n\tconst config = sanitizeRadiusGatewayConfig(await response.json());\n\tif (!config) throw new Error(`Invalid Radius config from ${gateway}`);\n\treturn config;\n}\n"]}