import type { ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow'; import { normalizeBaseUrl, toModelOptions, type TeamorouterModel } from './teamorouter'; /** Dropdown content for the model field, read live from `GET /v1/models`. */ export function modelLoader(kind: 'chat' | 'image' | 'all') { return async function (this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('teamorouterApi'); const response = (await this.helpers.httpRequestWithAuthentication.call(this, 'teamorouterApi', { method: 'GET', baseURL: normalizeBaseUrl(credentials.baseUrl as string), url: '/models', json: true, })) as { data?: TeamorouterModel[] } | TeamorouterModel[]; const models = Array.isArray(response) ? response : response?.data ?? []; return toModelOptions(models, kind); }; }