UNPKG

@websolutespa/payload-plugin-bowl-llm

Version:

LLM plugin for Bowl PayloadCms plugin

74 lines (73 loc) 2.72 kB
'use client'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { SelectInput, useField, useFormFields } from '@payloadcms/ui'; import * as React from 'react'; export const LlmProvider = ({ path })=>{ const appKey = useFormFields(([fields])=>fields['settings.credentials.appKey']); const apiKey = useFormFields(([fields])=>fields['settings.credentials.apiKey']); const { value, setValue } = useField({ path }); const [options, setOptions] = React.useState([]); const appKeyValue = appKey?.initialValue; const apiKeyValue = apiKey?.initialValue; React.useEffect(()=>{ const fetchOptions = async ()=>{ try { const response = await fetch((process.env.PAYLOAD_PUBLIC_BASE_PATH || '') + '/api/llm/providers?locale=it', { method: 'POST', headers: { 'Content-Type': 'application/json' }, referrer: '', body: JSON.stringify({ appKey: appKeyValue, apiKey: apiKeyValue }) }); if (response.ok) { const providers = await response.json(); const options = providers.map((provider)=>({ label: provider.value, value: provider.id })).sort((a, b)=>a.label.localeCompare(b.label)); setOptions(options); } else { setOptions([ { label: (await response.json()).message, value: '' } ]); } } catch (error) { console.error('Error fetching data:', error); } }; if (appKeyValue && apiKeyValue) { fetchOptions(); } }, [ appKeyValue, apiKeyValue ]); return /*#__PURE__*/ _jsxs("div", { className: "field-type select", children: [ /*#__PURE__*/ _jsx("label", { className: "field-label", htmlFor: `field-${path}`.replace(/\./g, '__'), children: "Provider" }), /*#__PURE__*/ _jsx(SelectInput, { path: path, name: path, options: options, value: value, hasMany: false, onChange: (option)=>Array.isArray(option) ? null : setValue(option.value) }) ] }); }; //# sourceMappingURL=LlmProvider.js.map