@websolutespa/payload-plugin-bowl-llm
Version:
LLM plugin for Bowl PayloadCms plugin
188 lines (187 loc) • 7.04 kB
JavaScript
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { marked } from 'marked';
import React, { useMemo } from 'react';
import { isChunkText } from '../../api/types';
export const LlmChunk = ({ item })=>{
switch(item.type){
case 'string':
case 'text':
{
const text = (isChunkText(item) ? item.text : item.content) || '';
return /*#__PURE__*/ _jsx(LlmChunkText, {
text: text
});
}
case 'file':
{
const title = item.url.split('/').pop();
return item.url ? /*#__PURE__*/ _jsx("div", {
className: "llm__row",
children: /*#__PURE__*/ _jsx("div", {
className: "llm__col --end-xs-12 --xs-10 --sm-9 --md-8 --lg-7 --xl-6",
children: /*#__PURE__*/ _jsxs("a", {
href: item.url,
download: title,
target: "_blank",
rel: "noreferrer",
children: [
/*#__PURE__*/ _jsx("svg", {
xmlns: "http://www.w3.org/2000/svg",
width: "12",
height: "12",
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round",
className: "lucide lucide-paperclip-icon lucide-paperclip",
children: /*#__PURE__*/ _jsx("path", {
d: "m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"
})
}),
/*#__PURE__*/ _jsx("span", {
children: title
})
]
})
})
}) : /*#__PURE__*/ _jsx("code", {
children: JSON.stringify(item)
});
}
case 'image':
{
return item.url ? /*#__PURE__*/ _jsx("div", {
className: "llm__row",
children: /*#__PURE__*/ _jsx("div", {
className: "llm__col --end-xs-12 --xs-10 --sm-9 --md-8 --lg-7 --xl-6",
children: /*#__PURE__*/ _jsx("img", {
src: item.url,
alt: ""
})
})
}) : /*#__PURE__*/ _jsx("code", {
children: JSON.stringify(item)
});
}
case 'image_url':
{
return item.image_url ? /*#__PURE__*/ _jsx("div", {
className: "llm__row",
children: /*#__PURE__*/ _jsx("div", {
className: "llm__col --end-xs-12 --xs-10 --sm-9 --md-8 --lg-7 --xl-6",
children: /*#__PURE__*/ _jsx("img", {
src: item.image_url.url,
alt: ""
})
})
}) : /*#__PURE__*/ _jsx("code", {
children: JSON.stringify(item)
});
}
default:
return /*#__PURE__*/ _jsx(LlmChunkCard, {
item: item
});
}
};
export function LlmChunkText({ text }) {
const html = useMemo(()=>{
if (!text) {
console.error('LlmChunkText.error', text);
return '';
}
return marked.parse(text);
}, [
text
]);
return /*#__PURE__*/ _jsx("p", {
className: "llm__text",
dangerouslySetInnerHTML: {
__html: html
}
});
}
const USE_CARD = true;
export function LlmChunkCard({ item }) {
const knownKeys = [
'type',
'id',
'title',
'abstract',
'description',
'image',
'place',
'date',
'time',
'url'
];
const keys = useMemo(()=>{
const keys = Object.keys(item);
return keys.sort((a, b)=>{
return knownKeys.indexOf(a) - knownKeys.indexOf(b);
});
}, []);
return USE_CARD ? /*#__PURE__*/ _jsx("div", {
className: "llm__card",
children: keys.map((key)=>{
const value = String(item[key]);
if (!value) {
return undefined;
}
switch(key){
case 'type':
case 'id':
case 'place':
case 'date':
case 'time':
return /*#__PURE__*/ _jsx("span", {
className: `llm__card-${key} llm__pill`,
title: key,
children: value
}, key);
case 'image':
return /*#__PURE__*/ _jsx("div", {
className: `llm__card-${key}`,
title: key,
children: /*#__PURE__*/ _jsx("a", {
href: value,
target: "_blank",
rel: "noreferrer",
children: /*#__PURE__*/ _jsx("img", {
src: value
})
})
}, key);
case 'url':
case 'link':
case 'href':
return /*#__PURE__*/ _jsx("div", {
className: `llm__card-${key}`,
title: key,
children: /*#__PURE__*/ _jsx("a", {
className: "llm__pill",
href: value,
target: "_blank",
title: value,
rel: "noreferrer",
children: value
})
}, key);
default:
return /*#__PURE__*/ _jsx("div", {
className: `llm__card-${key}`,
title: key,
dangerouslySetInnerHTML: {
__html: value
}
}, key);
}
})
}) : /*#__PURE__*/ _jsx("code", {
children: JSON.stringify(item, null, 2)
});
}
//# sourceMappingURL=LlmChunk.js.map