Aimobile / assets /AiPersonalityForge-DXnPiFSx.js
admin08077's picture
Upload 395 files
634008a verified
import{r as p,j as e}from"./react-B-lWpQRQ.js";import{u as A,U as E,aC as T,aK as F,T as R,M as U,L as D,aL as L}from"./index-DyMS-nC-.js";import{u as M,f as $}from"./promptUtils-DniUlv0T.js";import"./@google-xfXoiafW.js";import{e as H}from"./fileUtils-DLahR3l0.js";import"./@braintree-DY5JYOZd.js";import"./react-dom-CU2yWD-Y.js";import"./scheduler-DYLXRpC5.js";import"./idb-Dob3nYDb.js";import"./axe-core-CA05Kxsw.js";import"./marked-CesSW9Du.js";import"./@mermaid-js-Ce0__7Tp.js";import"./langium-B_PGe6V2.js";import"./vscode-jsonrpc-2tvYB2ki.js";import"./chevrotain-D5DQZOif.js";import"./@chevrotain-DMYZVohV.js";import"./lodash-es-CKTcnrxn.js";import"./chevrotain-allstar-eFSt8-qu.js";import"./vscode-languageserver-types-NoPvPymt.js";import"./vscode-languageserver-textdocument-CKBVUiR3.js";import"./vscode-uri-CoxP0whD.js";const J={persona:"You are a helpful assistant.",rules:[],outputFormat:"markdown",exampleIO:[]},ce=()=>{const[l,x]=M(),[m,u]=p.useState(null),{addNotification:f}=A(),j=p.useRef(null),[h,y]=p.useState(""),[N,g]=p.useState([]),[b,v]=p.useState(!1),s=l.find(t=>t.id===m);p.useEffect(()=>{!m&&l.length>0&&u(l[0].id)},[l,m]);const i=(t,r)=>{if(!s)return;const o={...s,[t]:r};x(l.map(a=>a.id===m?o:a))},I=()=>{const t=Date.now().toString(),r={...J,id:t,name:"Untitled Personality"};x([...l,r]),u(t)},k=t=>{window.confirm("Are you sure you want to delete this personality?")&&(x(l.filter(r=>r.id!==t)),m===t&&u(l.length>1?l[0].id:null))},w=async()=>{if(!h.trim()||!s||b)return;const t=$(s),r=[...N,{role:"user",content:h}];g(r),y(""),v(!0);try{const o=L(h,t,.7);let a="";g(n=>[...n,{role:"model",content:""}]);for await(const n of o)a+=n,g(c=>c[c.length-1].role==="model"?[...c.slice(0,-1),{role:"model",content:a}]:c)}catch(o){const a=o instanceof Error?o.message:"An error occurred";g(n=>[...n,{role:"model",content:`**Error:** ${a}`}])}finally{v(!1)}},C=()=>{s&&(H(s,`${s.name.replace(/\s+/g,"_")}.json`),f("Personality exported!","success"))},S=t=>{var a;const r=(a=t.target.files)==null?void 0:a[0];if(!r)return;const o=new FileReader;o.onload=n=>{var c;try{const d=JSON.parse((c=n.target)==null?void 0:c.result);d.id&&d.name&&d.persona?(x(P=>[...P.filter(O=>O.id!==d.id),d]),u(d.id),f("Personality imported!","success")):f("Invalid personality file.","error")}catch{f("Failed to parse JSON file.","error")}},o.readAsText(r)};return e.jsxs("div",{className:"h-full flex text-text-primary",children:[e.jsxs("aside",{className:"w-64 bg-surface border-r border-border flex flex-col",children:[e.jsx("div",{className:"p-4 border-b border-border",children:e.jsx("h2",{className:"text-lg font-bold",children:"Personalities"})}),e.jsx("div",{className:"flex-grow overflow-y-auto",children:l.map(t=>e.jsxs("div",{onClick:()=>u(t.id),className:`group flex justify-between items-center p-3 text-sm cursor-pointer ${m===t.id?"bg-primary/10 text-primary":"hover:bg-gray-100 dark:hover:bg-slate-700"}`,children:[e.jsx("span",{className:"truncate",children:t.name}),e.jsx("button",{onClick:r=>{r.stopPropagation(),k(t.id)},className:"opacity-0 group-hover:opacity-100 text-text-secondary hover:text-red-500",children:e.jsx(E,{})})]},t.id))}),e.jsxs("div",{className:"p-4 border-t border-border space-y-2",children:[e.jsxs("button",{onClick:I,className:"btn-primary w-full py-2 text-sm flex items-center justify-center gap-2",children:[e.jsx(T,{})," New"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>{var t;return(t=j.current)==null?void 0:t.click()},className:"flex-1 py-2 text-sm bg-gray-100 dark:bg-slate-700 rounded-md flex items-center justify-center gap-2",children:[e.jsx(F,{})," Import"]}),e.jsxs("button",{onClick:C,className:"flex-1 py-2 text-sm bg-gray-100 dark:bg-slate-700 rounded-md flex items-center justify-center gap-2",children:[e.jsx(R,{})," Export"]}),e.jsx("input",{type:"file",ref:j,onChange:S,accept:".json",className:"hidden"})]})]})]}),s?e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-px bg-border",children:[e.jsxs("div",{className:"bg-background p-4 flex flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{children:[e.jsx("label",{className:"font-bold",children:"Name"}),e.jsx("input",{type:"text",value:s.name,onChange:t=>i("name",t.target.value),className:"w-full mt-1 p-2 bg-surface border rounded"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"font-bold",children:"Persona"}),e.jsx("textarea",{value:s.persona,onChange:t=>i("persona",t.target.value),className:"w-full mt-1 p-2 bg-surface border rounded h-24"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"font-bold",children:"Rules (one per line)"}),e.jsx("textarea",{value:s.rules.join(`
`),onChange:t=>i("rules",t.target.value.split(`
`)),className:"w-full mt-1 p-2 bg-surface border rounded h-32"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"font-bold",children:"Output Format"}),e.jsxs("select",{value:s.outputFormat,onChange:t=>i("outputFormat",t.target.value),className:"w-full mt-1 p-2 bg-surface border rounded",children:[e.jsx("option",{children:"markdown"}),e.jsx("option",{children:"json"}),e.jsx("option",{children:"text"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold mb-2",children:"Examples"}),s.exampleIO.map((t,r)=>e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2 p-2 border rounded bg-surface",children:[e.jsx("textarea",{placeholder:"User Input",value:t.input,onChange:o=>i("exampleIO",s.exampleIO.map((a,n)=>n===r?{...a,input:o.target.value}:a)),className:"h-20 p-1 bg-background border rounded"}),e.jsx("textarea",{placeholder:"Model Output",value:t.output,onChange:o=>i("exampleIO",s.exampleIO.map((a,n)=>n===r?{...a,output:o.target.value}:a)),className:"h-20 p-1 bg-background border rounded"})]},r)),e.jsx("button",{onClick:()=>i("exampleIO",[...s.exampleIO,{input:"",output:""}]),className:"text-sm text-primary",children:"+ Add Example"})]})]}),e.jsxs("div",{className:"bg-background p-4 flex flex-col",children:[e.jsx("h2",{className:"text-lg font-bold mb-2 border-b pb-2",children:"Live Testbed"}),e.jsxs("div",{className:"flex-grow overflow-y-auto space-y-4 pr-2",children:[N.map((t,r)=>e.jsxs("div",{className:`p-3 rounded-lg ${t.role==="user"?"bg-primary/10":"bg-surface"}`,children:[e.jsx("strong",{className:"capitalize",children:t.role}),e.jsx(U,{content:t.content})]},r)),b&&e.jsx("div",{className:"flex justify-center",children:e.jsx(D,{})})]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx("input",{value:h,onChange:t=>y(t.target.value),onKeyDown:t=>t.key==="Enter"&&w(),className:"flex-grow p-2 bg-surface border rounded",placeholder:"Test your AI..."}),e.jsx("button",{onClick:w,disabled:b,className:"btn-primary px-4",children:"Send"})]})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-text-secondary",children:"Select or create a personality to begin."})]})};export{ce as AiPersonalityForge};
//# sourceMappingURL=AiPersonalityForge-DXnPiFSx.js.map