UNPKG

@websolutespa/payload-plugin-bowl-llm

Version:

LLM plugin for Bowl PayloadCms plugin

62 lines (61 loc) 2.18 kB
'use client'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { SelectInput, useConfig, useField } from '@payloadcms/ui'; import * as React from 'react'; export const LlmTool = ({ path })=>{ const { value, setValue } = useField({ path }); const [options, setOptions] = React.useState([]); const { config } = useConfig(); const { routes: { api: apiRoute } = {} } = config; React.useEffect(()=>{ const fetchOptions = async ()=>{ try { const response = await fetch(`${apiRoute}/llm/tools`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, referrer: '' }); if (response.ok) { const tools = await response.json(); const options = tools.map((tool)=>({ label: tool.id, value: tool.value })).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); } }; fetchOptions(); }, []); return /*#__PURE__*/ _jsxs("div", { className: "field-type select", children: [ /*#__PURE__*/ _jsx("label", { className: "field-label", htmlFor: `field-${path}`.replace(/\./g, '__'), children: "LLM functionName" }), /*#__PURE__*/ _jsx(SelectInput, { path: path, name: path, options: options, value: value, onChange: (option)=>Array.isArray(option) ? null : setValue(option.value) }) ] }); }; //# sourceMappingURL=LlmTool.js.map