@object-ui/plugin-ai 17.6.0 → 17.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("lucide-react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`lucide-react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginAI={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.lucide_react,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=Object.create,s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,u=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,f=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=l(t),a=0,o=i.length,u;a<o;a++)u=i[a],!d.call(e,u)&&u!==n&&s(e,u,{get:(e=>t[e]).bind(null,u),enumerable:!(r=c(t,u))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:o(u(e)),f(t||!e||!e.__esModule||!d.call(e,`default`)?s(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var p=({schema:e,onApply:t,onRefresh:o})=>{let{suggestions:s=[],showConfidence:c=!0,showReasoning:l=!1,autoFill:u=!1}=e,[d,f]=(0,n.useState)(s),[p,m]=(0,n.useState)(new Set),[h,g]=(0,n.useState)(!1),[_,v]=(0,n.useState)(!1),y=e=>{t?.(e),m(t=>new Set(t).add(e.fieldName))},b=()=>{d.forEach(e=>t?.(e)),m(new Set(d.map(e=>e.fieldName)))},x=e=>{f(t=>t.filter(t=>t.fieldName!==e))},S=()=>{v(!0),o&&o(),setTimeout(()=>v(!1),1e3)};if(h||d.length===0)return null;let C=d.filter(e=>!p.has(e.fieldName)),w=e=>e>=.8?`text-green-600`:e>=.5?`text-yellow-600`:`text-red-600`;return(0,a.jsxs)(r.Card,{className:`border-blue-200 bg-blue-50/30`,children:[(0,a.jsx)(r.CardHeader,{className:`pb-2`,children:(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(r.CardTitle,{className:`text-sm flex items-center gap-2`,children:[(0,a.jsx)(i.Sparkles,{className:`h-4 w-4 text-blue-500`}),`AI Suggestions`,(0,a.jsxs)(r.Badge,{variant:`secondary`,className:`text-xs`,children:[C.length,` suggestion`,C.length===1?``:`s`]})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:S,disabled:_,className:`h-7`,children:(0,a.jsx)(i.RefreshCw,{className:`h-3 w-3 ${_?`animate-spin`:``}`})}),C.length>1&&(0,a.jsx)(r.Button,{variant:`outline`,size:`sm`,onClick:b,className:`h-7 text-xs`,children:`Apply All`}),(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:()=>g(!0),className:`h-7`,children:(0,a.jsx)(i.X,{className:`h-3 w-3`})})]})]})}),(0,a.jsxs)(r.CardContent,{className:`space-y-2 pt-0`,children:[C.map(e=>(0,a.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-md bg-white border text-sm`,children:[(0,a.jsx)(i.Lightbulb,{className:`h-4 w-4 text-yellow-500 shrink-0`}),(0,a.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`span`,{className:`font-medium`,children:e.fieldName}),(0,a.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,a.jsx)(`span`,{className:`font-mono text-blue-600 truncate`,children:typeof e.value==`object`?JSON.stringify(e.value):String(e.value)})]}),c&&(0,a.jsxs)(`div`,{className:`text-xs ${w(e.confidence)}`,children:[Math.round(e.confidence*100),`% confidence`]}),l&&e.reasoning&&(0,a.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:e.reasoning})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-green-600 hover:text-green-700 hover:bg-green-50`,onClick:()=>y(e),children:(0,a.jsx)(i.Check,{className:`h-3.5 w-3.5`})}),(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>x(e.fieldName),children:(0,a.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})]},e.fieldName)),p.size>0&&(0,a.jsxs)(`div`,{className:`text-xs text-green-600 flex items-center gap-1 pt-1`,children:[(0,a.jsx)(i.Check,{className:`h-3 w-3`}),p.size,` suggestion`,p.size===1?``:`s`,` applied`]})]})]})},m=({schema:e,onSelect:t,onDismiss:n})=>{let{recommendations:o=[],showScores:s=!1,layout:c=`list`,loading:l=!1,emptyMessage:u=`No recommendations available`}=e,d=e=>{t?.(e)},f=e=>{n?.(e)};if(l)return(0,a.jsx)(r.Card,{children:(0,a.jsxs)(r.CardContent,{className:`p-8 text-center`,children:[(0,a.jsx)(i.Sparkles,{className:`h-8 w-8 text-blue-500 mx-auto mb-3 animate-pulse`}),(0,a.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Generating recommendations...`})]})});if(o.length===0)return(0,a.jsx)(r.Card,{children:(0,a.jsx)(r.CardContent,{className:`p-8 text-center text-muted-foreground`,children:u})});let p=e=>{if(!s)return null;let t=Math.round(e*100);return(0,a.jsxs)(r.Badge,{variant:e>=.7?`default`:e>=.4?`secondary`:`outline`,className:`text-xs`,children:[t,`%`]})};return(0,a.jsxs)(r.Card,{children:[(0,a.jsx)(r.CardHeader,{children:(0,a.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-sm`,children:[(0,a.jsx)(i.Sparkles,{className:`h-4 w-4 text-blue-500`}),`Recommendations`,(0,a.jsx)(r.Badge,{variant:`secondary`,className:`text-xs`,children:o.length})]})}),(0,a.jsx)(r.CardContent,{children:c===`grid`?(0,a.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:o.map(e=>(0,a.jsx)(r.Card,{className:`cursor-pointer hover:shadow-md transition-shadow`,onClick:()=>d(e),children:(0,a.jsxs)(r.CardContent,{className:`p-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-start justify-between mb-2`,children:[(0,a.jsx)(i.Star,{className:`h-4 w-4 text-yellow-500`}),p(e.score)]}),(0,a.jsx)(`h4`,{className:`font-medium text-sm mb-1`,children:e.title}),e.description&&(0,a.jsx)(`p`,{className:`text-xs text-muted-foreground line-clamp-3`,children:e.description}),e.category&&(0,a.jsx)(r.Badge,{variant:`outline`,className:`text-xs mt-2`,children:e.category}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1 mt-3`,children:[(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-green-600`,children:(0,a.jsx)(i.ThumbsUp,{className:`h-3 w-3`})}),(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-red-500`,children:(0,a.jsx)(i.ThumbsDown,{className:`h-3 w-3`})})]})]})},e.id))}):(0,a.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,a.jsxs)(`div`,{className:`flex items-start gap-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors cursor-pointer`,onClick:()=>d(e),children:[(0,a.jsx)(`div`,{className:`mt-1 shrink-0`,children:(0,a.jsx)(i.Star,{className:`h-4 w-4 text-yellow-500`})}),(0,a.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,a.jsx)(`span`,{className:`font-medium text-sm`,children:e.title}),e.category&&(0,a.jsx)(r.Badge,{variant:`outline`,className:`text-xs`,children:e.category}),p(e.score)]}),e.description&&(0,a.jsx)(`p`,{className:`text-xs text-muted-foreground line-clamp-2`,children:e.description})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e.action&&(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,children:(0,a.jsx)(i.ExternalLink,{className:`h-3.5 w-3.5`})}),(0,a.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-muted-foreground`,onClick:t=>{t.stopPropagation(),f(e)},children:(0,a.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})]},e.id))})})]})},h=({schema:e,onSubmit:t})=>{let{placeholder:o=`Ask a question about your data...`,result:s,suggestions:c=[],showHistory:l=!1,history:u=[],loading:d=!1}=e,[f,p]=(0,n.useState)(``),[m,h]=(0,n.useState)(s),[g,_]=(0,n.useState)(!1),v=g||d,y=e=>{let n=e||f;n.trim()&&(_(!0),t?.(n),t?_(!1):setTimeout(()=>{h({query:n,summary:`Results for: "${n}"`,confidence:.85,data:[],columns:[]}),_(!1)},1e3))},b=e=>{p(e),y(e)};return(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsx)(r.Card,{children:(0,a.jsxs)(r.CardContent,{className:`p-4`,children:[(0,a.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,a.jsxs)(`div`,{className:`relative flex-1`,children:[(0,a.jsx)(i.Search,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,a.jsx)(r.Input,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>e.key===`Enter`&&y(),placeholder:o,className:`pl-10 pr-20`,disabled:v}),(0,a.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2`,children:(0,a.jsx)(r.Button,{size:`sm`,onClick:()=>y(),disabled:v||!f.trim(),className:`h-7`,children:v?(0,a.jsx)(i.Loader2,{className:`h-3.5 w-3.5 animate-spin`}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i.Sparkles,{className:`h-3.5 w-3.5 mr-1`}),`Ask`]})})})]})}),c.length>0&&!m&&(0,a.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:c.map((e,t)=>(0,a.jsx)(`button`,{type:`button`,onClick:()=>b(e),className:`text-xs px-2.5 py-1 rounded-full border bg-muted/30 hover:bg-muted text-muted-foreground hover:text-foreground transition-colors`,disabled:v,children:e},t))})]})}),m&&(0,a.jsxs)(r.Card,{children:[(0,a.jsx)(r.CardHeader,{className:`pb-2`,children:(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(r.CardTitle,{className:`text-sm flex items-center gap-2`,children:[(0,a.jsx)(i.Table,{className:`h-4 w-4`}),`Results`]}),m.confidence!==void 0&&(0,a.jsxs)(r.Badge,{variant:m.confidence>=.7?`default`:`secondary`,className:`text-xs`,children:[Math.round(m.confidence*100),`% match`]})]})}),(0,a.jsxs)(r.CardContent,{children:[m.summary&&(0,a.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3`,children:m.summary}),m.data&&m.data.length>0&&m.columns&&(0,a.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,a.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,a.jsx)(`thead`,{className:`bg-muted`,children:(0,a.jsx)(`tr`,{children:m.columns.map((e,t)=>(0,a.jsx)(`th`,{className:`px-4 py-2 text-left font-medium`,children:e.label||e.name},t))})}),(0,a.jsx)(`tbody`,{children:m.data.map((e,t)=>(0,a.jsx)(`tr`,{className:`border-t`,children:m.columns.map((t,n)=>(0,a.jsx)(`td`,{className:`px-4 py-2`,children:String(e[t.name]??``)},n))},t))})]})}),(!m.data||m.data.length===0)&&(0,a.jsx)(`div`,{className:`text-center py-6 text-muted-foreground text-sm`,children:`No matching records found`})]})]}),l&&u.length>0&&(0,a.jsxs)(r.Card,{children:[(0,a.jsx)(r.CardHeader,{className:`pb-2`,children:(0,a.jsxs)(r.CardTitle,{className:`text-xs text-muted-foreground flex items-center gap-1`,children:[(0,a.jsx)(i.Clock,{className:`h-3 w-3`}),`Recent Queries`]})}),(0,a.jsx)(r.CardContent,{className:`space-y-1`,children:u.slice(0,5).map((e,t)=>(0,a.jsxs)(`button`,{type:`button`,onClick:()=>b(e.query),className:`w-full flex items-center gap-2 p-2 rounded-md text-sm text-left hover:bg-muted/50 transition-colors`,children:[(0,a.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,a.jsx)(`span`,{className:`truncate`,children:e.query}),(0,a.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 ml-auto`,children:new Date(e.timestamp).toLocaleDateString()})]},t))})]})]})};t.ComponentRegistry.register(`ai-form-assist`,p,{label:`AI Form Assist`,category:`AI`,inputs:[{name:`formId`,type:`string`,label:`Form ID`},{name:`objectName`,type:`string`,label:`Object Name`},{name:`fields`,type:`array`,label:`Fields to suggest`},{name:`suggestions`,type:`code`,label:`Suggestions Data`},{name:`autoFill`,type:`boolean`,label:`Auto Fill`,defaultValue:!1},{name:`showConfidence`,type:`boolean`,label:`Show Confidence`,defaultValue:!0},{name:`showReasoning`,type:`boolean`,label:`Show Reasoning`,defaultValue:!1}]}),t.ComponentRegistry.register(`ai-recommendations`,m,{label:`AI Recommendations`,category:`AI`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`recommendations`,type:`code`,label:`Recommendations Data`},{name:`maxResults`,type:`number`,label:`Max Results`,defaultValue:10},{name:`showScores`,type:`boolean`,label:`Show Scores`,defaultValue:!1},{name:`layout`,type:`enum`,label:`Layout`,enum:[{label:`List`,value:`list`},{label:`Grid`,value:`grid`},{label:`Carousel`,value:`carousel`}],defaultValue:`list`},{name:`emptyMessage`,type:`string`,label:`Empty Message`}]}),t.ComponentRegistry.register(`nl-query`,h,{label:`Natural Language Query`,category:`AI`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`placeholder`,type:`string`,label:`Placeholder Text`},{name:`suggestions`,type:`array`,label:`Example Queries`},{name:`showHistory`,type:`boolean`,label:`Show History`,defaultValue:!1}]}),e.AIFormAssist=p,e.AIRecommendations=m,e.NLQueryInput=h});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("lucide-react"),require("@object-ui/i18n"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`lucide-react`,`@object-ui/i18n`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginAI={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.lucide_react,e._object_ui_i18n,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=u(t),a=0,o=i.length,s;a<o;a++)s=i[a],!f.call(e,s)&&s!==n&&c(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=l(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:s(d(e)),p(t||!e||!e.__esModule||!f.call(e,`default`)?c(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var m=(0,a.createSafeTranslation)({"ai.nlQuery.placeholder":`Ask a question about your data…`,"ai.nlQuery.ask":`Ask`,"ai.nlQuery.results":`Results`,"ai.nlQuery.match":`{{percent}} match`,"ai.nlQuery.simulatedSummary":`Results for: {{query}}`,"ai.nlQuery.noResults":`No matching records found`,"ai.nlQuery.recentQueries":`Recent Queries`,"ai.formAssist.title":`AI Suggestions`,"ai.formAssist.suggestionCount":`{{count}} suggestions`,"ai.formAssist.suggestionCount_one":`{{count}} suggestion`,"ai.formAssist.suggestionCount_other":`{{count}} suggestions`,"ai.formAssist.applyAll":`Apply All`,"ai.formAssist.confidence":`{{percent}} confidence`,"ai.formAssist.appliedCount":`{{count}} suggestions applied`,"ai.formAssist.appliedCount_one":`{{count}} suggestion applied`,"ai.formAssist.appliedCount_other":`{{count}} suggestions applied`,"ai.recommendations.title":`Recommendations`,"ai.recommendations.generating":`Generating recommendations…`,"ai.recommendations.empty":`No recommendations available`},`ai.nlQuery.ask`);function h(e,t){return new Intl.NumberFormat(t,{style:`percent`,maximumFractionDigits:0}).format(e)}var g=({schema:e,onApply:t,onRefresh:s})=>{let{t:c}=m(),l=(0,a.useDisplayLocale)(),{suggestions:u=[],showConfidence:d=!0,showReasoning:f=!1}=e,[p,g]=(0,n.useState)(u),[_,v]=(0,n.useState)(new Set),[y,b]=(0,n.useState)(!1),[x,S]=(0,n.useState)(!1),C=e=>{t?.(e),v(t=>new Set(t).add(e.fieldName))},w=()=>{p.forEach(e=>t?.(e)),v(new Set(p.map(e=>e.fieldName)))},T=e=>{g(t=>t.filter(t=>t.fieldName!==e))},E=()=>{S(!0),s&&s(),setTimeout(()=>S(!1),1e3)};if(y||p.length===0)return null;let D=p.filter(e=>!_.has(e.fieldName)),O=e=>e>=.8?`text-green-600`:e>=.5?`text-yellow-600`:`text-red-600`;return(0,o.jsxs)(r.Card,{className:`border-blue-200 bg-blue-50/30`,children:[(0,o.jsx)(r.CardHeader,{className:`pb-2`,children:(0,o.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,o.jsxs)(r.CardTitle,{className:`text-sm flex items-center gap-2`,children:[(0,o.jsx)(i.Sparkles,{className:`h-4 w-4 text-blue-500`}),c(`ai.formAssist.title`),(0,o.jsx)(r.Badge,{variant:`secondary`,className:`text-xs`,children:c(`ai.formAssist.suggestionCount`,{count:D.length})})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:E,disabled:x,className:`h-7`,children:(0,o.jsx)(i.RefreshCw,{className:`h-3 w-3 ${x?`animate-spin`:``}`})}),D.length>1&&(0,o.jsx)(r.Button,{variant:`outline`,size:`sm`,onClick:w,className:`h-7 text-xs`,children:c(`ai.formAssist.applyAll`)}),(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:()=>b(!0),className:`h-7`,children:(0,o.jsx)(i.X,{className:`h-3 w-3`})})]})]})}),(0,o.jsxs)(r.CardContent,{className:`space-y-2 pt-0`,children:[D.map(e=>(0,o.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-md bg-white border text-sm`,children:[(0,o.jsx)(i.Lightbulb,{className:`h-4 w-4 text-yellow-500 shrink-0`}),(0,o.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,o.jsx)(`span`,{className:`font-medium`,children:e.fieldName}),(0,o.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,o.jsx)(`span`,{className:`font-mono text-blue-600 truncate`,children:typeof e.value==`object`?JSON.stringify(e.value):String(e.value)})]}),d&&(0,o.jsx)(`div`,{className:`text-xs ${O(e.confidence)}`,children:c(`ai.formAssist.confidence`,{percent:h(e.confidence,l)})}),f&&e.reasoning&&(0,o.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:e.reasoning})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-green-600 hover:text-green-700 hover:bg-green-50`,onClick:()=>C(e),children:(0,o.jsx)(i.Check,{className:`h-3.5 w-3.5`})}),(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>T(e.fieldName),children:(0,o.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})]},e.fieldName)),_.size>0&&(0,o.jsxs)(`div`,{className:`text-xs text-green-600 flex items-center gap-1 pt-1`,children:[(0,o.jsx)(i.Check,{className:`h-3 w-3`}),c(`ai.formAssist.appliedCount`,{count:_.size})]})]})]})},_=({schema:e,onSelect:t,onDismiss:n})=>{let{t:s}=m(),c=(0,a.useDisplayLocale)(),{recommendations:l=[],showScores:u=!1,layout:d=`list`,loading:f=!1,emptyMessage:p=s(`ai.recommendations.empty`)}=e,g=e=>{t?.(e)},_=e=>{n?.(e)};if(f)return(0,o.jsx)(r.Card,{children:(0,o.jsxs)(r.CardContent,{className:`p-8 text-center`,children:[(0,o.jsx)(i.Sparkles,{className:`h-8 w-8 text-blue-500 mx-auto mb-3 animate-pulse`}),(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s(`ai.recommendations.generating`)})]})});if(l.length===0)return(0,o.jsx)(r.Card,{children:(0,o.jsx)(r.CardContent,{className:`p-8 text-center text-muted-foreground`,children:p})});let v=e=>u?(0,o.jsx)(r.Badge,{variant:e>=.7?`default`:e>=.4?`secondary`:`outline`,className:`text-xs`,children:h(e,c)}):null;return(0,o.jsxs)(r.Card,{children:[(0,o.jsx)(r.CardHeader,{children:(0,o.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-sm`,children:[(0,o.jsx)(i.Sparkles,{className:`h-4 w-4 text-blue-500`}),s(`ai.recommendations.title`),(0,o.jsx)(r.Badge,{variant:`secondary`,className:`text-xs`,children:l.length})]})}),(0,o.jsx)(r.CardContent,{children:d===`grid`?(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:l.map(e=>(0,o.jsx)(r.Card,{className:`cursor-pointer hover:shadow-md transition-shadow`,onClick:()=>g(e),children:(0,o.jsxs)(r.CardContent,{className:`p-4`,children:[(0,o.jsxs)(`div`,{className:`flex items-start justify-between mb-2`,children:[(0,o.jsx)(i.Star,{className:`h-4 w-4 text-yellow-500`}),v(e.score)]}),(0,o.jsx)(`h4`,{className:`font-medium text-sm mb-1`,children:e.title}),e.description&&(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground line-clamp-3`,children:e.description}),e.category&&(0,o.jsx)(r.Badge,{variant:`outline`,className:`text-xs mt-2`,children:e.category}),(0,o.jsxs)(`div`,{className:`flex items-center gap-1 mt-3`,children:[(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-green-600`,children:(0,o.jsx)(i.ThumbsUp,{className:`h-3 w-3`})}),(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-red-500`,children:(0,o.jsx)(i.ThumbsDown,{className:`h-3 w-3`})})]})]})},e.id))}):(0,o.jsx)(`div`,{className:`space-y-2`,children:l.map(e=>(0,o.jsxs)(`div`,{className:`flex items-start gap-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors cursor-pointer`,onClick:()=>g(e),children:[(0,o.jsx)(`div`,{className:`mt-1 shrink-0`,children:(0,o.jsx)(i.Star,{className:`h-4 w-4 text-yellow-500`})}),(0,o.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,o.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,o.jsx)(`span`,{className:`font-medium text-sm`,children:e.title}),e.category&&(0,o.jsx)(r.Badge,{variant:`outline`,className:`text-xs`,children:e.category}),v(e.score)]}),e.description&&(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground line-clamp-2`,children:e.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e.action&&(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,children:(0,o.jsx)(i.ExternalLink,{className:`h-3.5 w-3.5`})}),(0,o.jsx)(r.Button,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-muted-foreground`,onClick:t=>{t.stopPropagation(),_(e)},children:(0,o.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})]},e.id))})})]})},v=({schema:e,onSubmit:t})=>{let{t:s}=m(),c=(0,a.useDisplayLocale)(),{placeholder:l=s(`ai.nlQuery.placeholder`),result:u,suggestions:d=[],showHistory:f=!1,history:p=[],loading:g=!1}=e,[_,v]=(0,n.useState)(``),[y,b]=(0,n.useState)(u),[x,S]=(0,n.useState)(!1),C=x||g,w=e=>{let n=e||_;n.trim()&&(S(!0),t?.(n),t?S(!1):setTimeout(()=>{b({query:n,summary:s(`ai.nlQuery.simulatedSummary`,{query:n}),confidence:.85,data:[],columns:[]}),S(!1)},1e3))},T=e=>{v(e),w(e)};return(0,o.jsxs)(`div`,{className:`space-y-4`,children:[(0,o.jsx)(r.Card,{children:(0,o.jsxs)(r.CardContent,{className:`p-4`,children:[(0,o.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,o.jsxs)(`div`,{className:`relative flex-1`,children:[(0,o.jsx)(i.Search,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,o.jsx)(r.Input,{value:_,onChange:e=>v(e.target.value),onKeyDown:e=>e.key===`Enter`&&w(),placeholder:l,className:`pl-10 pr-20`,disabled:C}),(0,o.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2`,children:(0,o.jsx)(r.Button,{size:`sm`,onClick:()=>w(),disabled:C||!_.trim(),className:`h-7`,children:C?(0,o.jsx)(i.Loader2,{className:`h-3.5 w-3.5 animate-spin`}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.Sparkles,{className:`h-3.5 w-3.5 mr-1`}),s(`ai.nlQuery.ask`)]})})})]})}),d.length>0&&!y&&(0,o.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:d.map((e,t)=>(0,o.jsx)(`button`,{type:`button`,onClick:()=>T(e),className:`text-xs px-2.5 py-1 rounded-full border bg-muted/30 hover:bg-muted text-muted-foreground hover:text-foreground transition-colors`,disabled:C,children:e},t))})]})}),y&&(0,o.jsxs)(r.Card,{children:[(0,o.jsx)(r.CardHeader,{className:`pb-2`,children:(0,o.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,o.jsxs)(r.CardTitle,{className:`text-sm flex items-center gap-2`,children:[(0,o.jsx)(i.Table,{className:`h-4 w-4`}),s(`ai.nlQuery.results`)]}),y.confidence!==void 0&&(0,o.jsx)(r.Badge,{variant:y.confidence>=.7?`default`:`secondary`,className:`text-xs`,children:s(`ai.nlQuery.match`,{percent:h(y.confidence,c)})})]})}),(0,o.jsxs)(r.CardContent,{children:[y.summary&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3`,children:y.summary}),y.data&&y.data.length>0&&y.columns&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:y.columns.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 text-left font-medium`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:y.data.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t`,children:y.columns.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2`,children:String(e[t.name]??``)},n))},t))})]})}),(!y.data||y.data.length===0)&&(0,o.jsx)(`div`,{className:`text-center py-6 text-muted-foreground text-sm`,children:s(`ai.nlQuery.noResults`)})]})]}),f&&p.length>0&&(0,o.jsxs)(r.Card,{children:[(0,o.jsx)(r.CardHeader,{className:`pb-2`,children:(0,o.jsxs)(r.CardTitle,{className:`text-xs text-muted-foreground flex items-center gap-1`,children:[(0,o.jsx)(i.Clock,{className:`h-3 w-3`}),s(`ai.nlQuery.recentQueries`)]})}),(0,o.jsx)(r.CardContent,{className:`space-y-1`,children:p.slice(0,5).map((e,t)=>(0,o.jsxs)(`button`,{type:`button`,onClick:()=>T(e.query),className:`w-full flex items-center gap-2 p-2 rounded-md text-sm text-left hover:bg-muted/50 transition-colors`,children:[(0,o.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,o.jsx)(`span`,{className:`truncate`,children:e.query}),(0,o.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 ml-auto`,children:new Date(e.timestamp).toLocaleDateString(c)})]},t))})]})]})};t.ComponentRegistry.register(`ai-form-assist`,g,{label:`AI Form Assist`,category:`AI`,inputs:[{name:`suggestions`,type:`code`},{name:`showConfidence`,type:`boolean`},{name:`showReasoning`,type:`boolean`}]}),t.ComponentRegistry.register(`ai-recommendations`,_,{label:`AI Recommendations`,category:`AI`,inputs:[{name:`recommendations`,type:`code`},{name:`showScores`,type:`boolean`},{name:`layout`,type:`enum`,enum:[{label:`List`,value:`list`},{label:`Grid`,value:`grid`}]},{name:`emptyMessage`,type:`string`}]}),t.ComponentRegistry.register(`nl-query`,v,{label:`Natural Language Query`,category:`AI`,inputs:[{name:`placeholder`,type:`string`},{name:`suggestions`,type:`array`},{name:`showHistory`,type:`boolean`}]}),e.AIFormAssist=g,e.AIRecommendations=_,e.NLQueryInput=v});
@@ -0,0 +1,51 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * Locale wiring for the three AI components — objectui#10232.
10
+ *
11
+ * The package used to have no `@object-ui/i18n` dependency at all: every string
12
+ * was hard-coded English and the `nl-query` history date was formatted in the
13
+ * MACHINE's locale. Wiring it as a whole — strings and display locale together —
14
+ * also puts the package inside the repo-wide machine-locale census
15
+ * (`packages/i18n/src/__tests__/machineLocaleCensus-9909.test.ts`), whose
16
+ * population is every package whose manifest names `@object-ui/i18n`.
17
+ *
18
+ * A module of its own, the shape `plugin-chatbot`'s `useAiApprovalsTranslation.ts`
19
+ * uses: the defaults map has to be importable by the test that compares it
20
+ * against the `en` pack, and exporting a non-component from a component file
21
+ * trips `react-refresh/only-export-components`. It is not exported from the
22
+ * package barrel, so it stays off the published API surface.
23
+ *
24
+ * English fallbacks for every key the components read. `createSafeTranslation`
25
+ * serves these when no `I18nProvider` is mounted, so a provider-less render
26
+ * shows English rather than raw keys. Every row is byte-identical to its `en`
27
+ * pack value — `aiComponents.i18n-10232.test.tsx` holds it there.
28
+ *
29
+ * The count rows are i18next count families (objectui#11445): the components
30
+ * pass `count`, and the provider-less path reads the `_one` / `_other` row for
31
+ * a numeric count, in the order i18next reads the `en` pack.
32
+ */
33
+ export declare const AI_DEFAULT_TRANSLATIONS: Record<string, string>;
34
+ /**
35
+ * Safe wrapper for `useObjectTranslation` that falls back to the map above when
36
+ * no `I18nProvider` is mounted — the factory form, because the components
37
+ * interpolate `{{count}}`, `{{percent}}` and `{{query}}`.
38
+ */
39
+ export declare const useAiTranslation: () => {
40
+ t: (key: string, options?: Record<string, unknown>) => string;
41
+ language: string;
42
+ } | {
43
+ t: import('i18next').TFunction<string, undefined>;
44
+ language: string;
45
+ };
46
+ /**
47
+ * A 0–1 score as a whole percentage in the DISPLAY locale (`useDisplayLocale()`),
48
+ * so `de` reads `85 %` rather than `85%` — the number face the
49
+ * `{{percent}}` holes above receive, already formatted.
50
+ */
51
+ export declare function formatPercent(score: number, locale: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-ai",
3
- "version": "17.6.0",
3
+ "version": "17.7.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
@@ -23,13 +23,11 @@
23
23
  "react-dom": "^18.0.0 || ^19.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "clsx": "^2.1.1",
27
- "lucide-react": "^1.31.0",
28
- "tailwind-merge": "^3.6.0",
29
- "@object-ui/components": "17.6.0",
30
- "@object-ui/core": "17.6.0",
31
- "@object-ui/react": "17.6.0",
32
- "@object-ui/types": "17.6.0"
26
+ "lucide-react": "^1.43.0",
27
+ "@object-ui/components": "17.7.0",
28
+ "@object-ui/core": "17.7.0",
29
+ "@object-ui/types": "17.7.0",
30
+ "@object-ui/i18n": "17.7.0"
33
31
  },
34
32
  "devDependencies": {
35
33
  "@types/node": "^26.2.0",
@@ -38,7 +36,8 @@
38
36
  "@vitejs/plugin-react": "^6.0.5",
39
37
  "vite": "^8.2.1",
40
38
  "vite-plugin-dts": "^5.0.3",
41
- "vitest": "^4.1.10"
39
+ "vitest": "^4.1.10",
40
+ "@object-ui/test-support": "17.4.0"
42
41
  },
43
42
  "description": "AI-driven UI plugin for Object UI — schema generation, conversational assistants and Vercel AI SDK integration",
44
43
  "keywords": [
@@ -71,9 +70,9 @@
71
70
  },
72
71
  "scripts": {
73
72
  "build": "vite build",
74
- "type-check": "tsc --noEmit",
73
+ "type-check": "tsc --noEmit && tsc -p tsconfig.test.json",
75
74
  "clean": "rm -rf dist",
76
- "test": "vitest run --passWithNoTests",
75
+ "test": "vitest run --root ../.. packages/plugin-ai/",
77
76
  "lint": "eslint ."
78
77
  }
79
78
  }