lua-cli 2.3.2 → 2.4.1

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.
@@ -36,42 +36,47 @@ export async function promptSkillSelection(skills) {
36
36
  * @returns Confirmed or updated version
37
37
  */
38
38
  export async function promptVersionConfirmOrUpdate(currentVersion) {
39
- const { versionAction } = await inquirer.prompt([
39
+ console.log(`\nCurrent version: ${currentVersion}`);
40
+ const { newVersion } = await inquirer.prompt([
40
41
  {
41
- type: "list",
42
- name: "versionAction",
43
- message: `Current version is ${currentVersion}. What would you like to do?`,
44
- choices: [
45
- { name: `Keep current version (${currentVersion})`, value: "keep" },
46
- { name: "Update version", value: "update" }
47
- ]
42
+ type: "input",
43
+ name: "newVersion",
44
+ message: "Enter new version to push:",
45
+ default: incrementPatchVersion(currentVersion),
46
+ validate: (input) => {
47
+ if (!input || input.trim() === "") {
48
+ return "Version cannot be empty";
49
+ }
50
+ // Basic semver validation
51
+ const semverRegex = /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$/;
52
+ if (!semverRegex.test(input.trim())) {
53
+ return "Version must follow semver format (e.g., 1.0.0, 1.0.0-alpha.1)";
54
+ }
55
+ return true;
56
+ }
48
57
  }
49
58
  ]);
50
59
  clearPromptLines(2);
51
- if (versionAction === "update") {
52
- const { newVersion } = await inquirer.prompt([
53
- {
54
- type: "input",
55
- name: "newVersion",
56
- message: "Enter new version:",
57
- default: currentVersion,
58
- validate: (input) => {
59
- if (!input || input.trim() === "") {
60
- return "Version cannot be empty";
61
- }
62
- // Basic semver validation
63
- const semverRegex = /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$/;
64
- if (!semverRegex.test(input.trim())) {
65
- return "Version must follow semver format (e.g., 1.0.0, 1.0.0-alpha.1)";
66
- }
67
- return true;
68
- }
69
- }
70
- ]);
71
- clearPromptLines(2);
72
- return newVersion.trim();
60
+ return newVersion.trim();
61
+ }
62
+ /**
63
+ * Increments the patch version automatically (e.g., 1.0.0 → 1.0.1)
64
+ *
65
+ * @param version - Current version string
66
+ * @returns Incremented version
67
+ */
68
+ function incrementPatchVersion(version) {
69
+ const semverRegex = /^(\d+)\.(\d+)\.(\d+)(-[a-zA-Z0-9.-]+)?$/;
70
+ const match = version.match(semverRegex);
71
+ if (match) {
72
+ const major = match[1];
73
+ const minor = match[2];
74
+ const patch = parseInt(match[3]) + 1;
75
+ const prerelease = match[4] || '';
76
+ return `${major}.${minor}.${patch}${prerelease}`;
73
77
  }
74
- return currentVersion;
78
+ // If doesn't match semver, return as-is
79
+ return version;
75
80
  }
76
81
  /**
77
82
  * Reads the version from skill configuration.
@@ -271,10 +271,10 @@ export function createSandbox(options) {
271
271
  Infinity: Infinity,
272
272
  NaN: NaN,
273
273
  User: userService,
274
- Product: productService,
274
+ Products: productService,
275
275
  Data: dataService,
276
276
  Baskets: basketsService,
277
- Order: orderService,
277
+ Orders: orderService,
278
278
  // Environment variables function
279
279
  env: (key) => envVars[key]
280
280
  };
package/dist/web/app.js CHANGED
@@ -99,7 +99,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
99
99
  `:n+=_+`
100
100
  `}return p?t.push({type:"list-item",content:r.trim(),isComplete:!1}):h?t.push({type:"payment",content:o.trim(),isComplete:!1}):m?t.push({type:"actions",content:a.trim(),isComplete:!1}):g?t.push({type:"images",content:s.trim(),isComplete:!1}):b?t.push({type:"links",content:u.trim(),isComplete:!1}):y?t.push({type:"navigate",content:c.trim(),isComplete:!1}):k?t.push({type:"documents",content:d.trim(),isComplete:!1}):n.trim()&&t.push({type:"text",content:n.trim()}),t},kK=_K;oL=(0,Ze.memo)(function({message:e,onSelect:t,luaApiUrl:n,authToken:r,disablePreviewOnLinks:o=!1,onNavigate:a}){let s=(0,Ze.useCallback)(d=>{let p=d.match(/^#\s+(.+)$/m),h=d.match(/^##\s+(.+)$/m),m=p?p[1]:"",g=h?h[1]:"",b=`${m}. ${g}`;t&&t(b)},[t]),u=(0,Ze.useCallback)(d=>{if(!t)return;let p=xK(d).trim();t(p)},[t]),c=(0,Ze.useCallback)(()=>{if(e.type==="location")return(0,G.jsx)(TK,{message:e});if(e.mimeType?.startsWith("video"))return e.url?(0,G.jsx)(LK,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("image"))return e.url?(0,G.jsx)(SK,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("audio"))return(0,G.jsx)(gK,{message:e});if(e.type==="file"&&e.mimeType){let h=MK(new File([],"",{type:e.mimeType})).icon;return(0,G.jsx)("a",{"data-testid":"chat-file-message",href:e.url,target:"_blank",rel:"noopener noreferrer",className:"chat-file-message lua:mx-4 lua:sm:mx-5",children:(0,G.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-8",children:[(0,G.jsxs)("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:rounded-lg lua:bg-white lua:w-80",children:[(0,G.jsx)(h,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),(0,G.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:["File",(0,G.jsx)("span",{className:"lua:text-gray-500 lua:text-sm",children:e.mimeType})]})]}),e.content&&(0,G.jsx)("div",{className:"chat-file-content lua:bg-gray-100 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:(0,G.jsx)("div",{className:"lua:text-sm lua:text-gray-900",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let d=kK(e.content),p=nL(u);return(0,G.jsx)("div",{className:"chat-markdown-content lua:prose lua:prose-sm lua:max-w-none",children:(0,G.jsx)("div",{className:"lua:flex lua:flex-wrap lua:gap-4",children:(()=>{if(d.filter(h=>h.type==="list-item").length>1){let h=[],m=[];return d.forEach(g=>{g.type==="list-item"?m.push(g):(m.length>0&&(h.push(m),m=[]),h.push([g]))}),m.length>0&&h.push(m),h.map((g,b)=>g.length>1&&g[0].type==="list-item"?(0,G.jsx)(pK,{group:g,onCardClick:s,onListItemClick:u,onNavigate:a},b):g.map((y,k)=>{if(y.type==="list-item")return(0,G.jsx)(y9,{block:y,onCardClick:s,onListItemClick:u,onNavigate:a},k);if(y.type==="actions")return qT(y.content).length>0&&y.isComplete,null;if(y.type==="images"){let v=KT(y.content);if(v.length>0)return(0,G.jsx)(QT,{images:v},k)}if(y.type==="links"){let v=YT(y.content);return v.length>0&&y.isComplete?(0,G.jsx)(eL,{links:v,luaApiUrl:n||"",authToken:r||"",disablePreviewOnLinks:o},k):null}if(y.type==="navigate"){let v=XT(y.content);return v&&y.isComplete?(0,G.jsx)(tL,{text:v.text,url:v.url,onNavigate:a},k):null}if(y.type==="documents"){let v=WT(y.content);return(0,G.jsx)($T,{documents:v},k)}if(y.type==="payment"){let v=JT(y.content);return v?(0,G.jsx)("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:(0,G.jsx)(GT,{url:v})},k):null}return(0,G.jsx)("div",{className:"chat-markdown-block lua:w-full",children:(0,G.jsx)(I1,{components:p,children:y.content})},k)}))}return d.map((h,m)=>{if(h.type==="list-item")return(0,G.jsx)(y9,{block:h,onCardClick:s,onListItemClick:u,onNavigate:a},m);if(h.type==="actions")return qT(h.content).length>0&&h.isComplete,null;if(h.type==="images"){let g=KT(h.content);if(g.length>0)return(0,G.jsx)(QT,{images:g},m)}if(h.type==="navigate"){let g=XT(h.content);return g&&h.isComplete?(0,G.jsx)(tL,{text:g.text,url:g.url,onNavigate:a},m):null}if(h.type==="documents"){let g=WT(h.content);return(0,G.jsx)($T,{documents:g},m)}if(h.type==="links"){let g=YT(h.content);return g.length>0&&h.isComplete?(0,G.jsx)(eL,{links:g,luaApiUrl:n||"",authToken:r||"",disablePreviewOnLinks:o},m):null}if(h.type==="payment"){let g=JT(h.content);return g?(0,G.jsx)("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5 lua:mb-5",children:(0,G.jsx)(GT,{url:g})},m):null}return(0,G.jsx)("div",{className:"chat-markdown-block lua:w-full",children:(0,G.jsx)(I1,{components:p,children:h.content})},m)})})()})})},[e,s,u]);return(0,G.jsxs)("div",{className:`chat-message-container lua:flex lua:flex-col ${e.role==="user"?"lua:items-end":"lua:items-start"} lua:gap-1`,children:[(0,G.jsxs)("div",{className:`lua:flex ${e.role==="user"?"lua:justify-end":"lua:justify-start"} lua:items-start lua:gap-2 lua:w-full`,children:[!["file","image","video","tool","location"].includes(e.type||"")&&e.content!=="..."&&(0,G.jsx)("div",{className:`chat-message-bubble ${e.role==="user"?"chat-message-bubble-user lua:max-w-full md:lua:max-w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:py-3 lua:mx-4 lua:sm:mx-5 lua:whitespace-pre-wrap":"chat-message-bubble-agent lua:w-full lua:bg-white lua:text-gray-800 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:c()}),["file","image","video","location"].includes(e.type||"")&&c()]}),(0,G.jsx)("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:AK(e.createdAt)})]})}),iL=(0,Ze.createContext)(void 0),w9=(0,Ze.createContext)(void 0),aL=(0,Ze.createContext)(void 0),sL=(0,Ze.createContext)(void 0),lL=(0,Ze.createContext)(void 0);dL=e=>{let t="::: actions",n=e.indexOf(t);if(n===-1)return[];let r=e.indexOf(":::",n+t.length);return r===-1?[]:e.slice(n+t.length,r).trim().replace(/\\n/g,`
101
101
  `).split(`
102
- `).map(o=>o.trim()).filter(o=>o&&o.startsWith("-")).map(o=>({text:o.replace(/^-[\s]?/,"").trim(),onClick:o.replace(/^-[\s]?/,"").trim()}))},cce=(0,Ze.memo)(function({onSend:e,disabled:t=!1,onFilePaste:n}){let{inputMessage:r,setInputMessage:o}=IK(),[a,s]=(0,Ze.useState)(!1),u=(0,Ze.useRef)(null);(0,Ze.useEffect)(()=>{let p=()=>{s(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))};return p(),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}},[]),(0,Ze.useEffect)(()=>{let p=u.current;p&&(t||(p.style.height="auto",p.style.height=`${p.scrollHeight}px`))},[r]);let c=p=>{if(p.key==="Enter"){if(a||p.shiftKey||p.metaKey||p.ctrlKey)return;p.preventDefault(),e()}},d=(0,Ze.useCallback)(p=>{let{items:h}=p.clipboardData;if(!h||!n)return;let m=[];for(let g=0;g<h.length;g++){let b=h[g];if(b.kind==="file"){let y=b.getAsFile();y&&m.push(y)}}m.length>0&&(p.preventDefault(),n(m))},[n]);return(0,G.jsxs)("div",{className:"lua:flex lua:gap-3 lua:py-2 lua:px-3 lua:items-start",children:[(0,G.jsx)(of,{size:32,className:"lua:w-8 lua:h-8 lua:rounded-full lua:flex-shrink-0 lua:m-1"}),(0,G.jsx)("div",{className:"lua:flex-1 lua:flex",children:(0,G.jsx)("textarea",{ref:u,disabled:t,value:r,onChange:p=>o(p.target.value),onKeyDown:c,onPaste:d,placeholder:t?"This conversation's chat window has already been closed":"Reply to user",className:`lua:w-full lua:pl-0 lua:pr-4 lua:py-2 lua:resize-none lua:overflow-y-auto lua:border-none lua:focus:outline-none lua:focus:ring-0 lua:text-gray-700 lua:min-h-10 lua:max-h-48 lua:bg-white${t?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})})});var Ct,Je,x9,Me,Yn=A(()=>{"use strict";Ct={LUA_API:"https://api.heylua.ai",DEV_SERVER:"https://api.heylua.ai",LOCAL_DEV:""},Je={CHAT_GENERATE:e=>`${Ct.LUA_API}/chat/generate/${e}?channel=dev`,TOOLS_TEST:e=>`${Ct.LUA_API}/tools/test/${e}`,CHAT_HISTORY:e=>`${Ct.LUA_API}/chat/history/${e}`,AGENT_TYPES:`${Ct.LUA_API}/agents/self-serve/types`,CREATE_AGENT:`${Ct.LUA_API}/agents/self-serve/create`,AGENT_DETAILS:e=>`${Ct.LUA_API}/admin/agents/${e}`,SKILL_VERSIONS:(e,t)=>`${Ct.DEV_SERVER}/developer/skills/${e}/${t}/versions`,PERSONA_VERSIONS:e=>`${Ct.LUA_API}/developer/agents/${e}/persona/versions`,DEPLOY_PERSONA_VERSION:(e,t)=>`${Ct.LUA_API}/developer/agents/${e}/persona/version/${t}`,AGENT_RESOURCES:e=>`${Ct.LUA_API}/admin/agents/${e}/resources`,AGENT_RESOURCE:(e,t)=>`${Ct.LUA_API}/admin/agents/${e}/resources/${t}`,AGENT_SKILLS:e=>`${Ct.LUA_API}/developer/skills/${e}`,ACTIVATE_SKILL:(e,t)=>`${Ct.LUA_API}/developer/skills/${e}/${t}`,PUBLISH_SKILL_VERSION:(e,t,n)=>`${Ct.LUA_API}/developer/skills/${e}/${t}/${n}/publish`,PRODUCTION_LOGS:e=>`${Ct.LUA_API}/developer/agents/${e}/logs`,PRODUCTION_ENV:e=>`${Ct.LUA_API}/developer/agents/${e}/env`,AGENT_PRODUCTS:e=>`${Ct.LOCAL_DEV}/api/products`,AGENT_PRODUCT:(e,t)=>`${Ct.LOCAL_DEV}/api/products/${t}`,SEARCH_PRODUCTS:e=>`${Ct.LOCAL_DEV}/api/products/search`,AGENT_BASKETS:e=>`${Ct.LOCAL_DEV}/api/baskets`,AGENT_BASKET:(e,t)=>`${Ct.LOCAL_DEV}/api/baskets/${t}`,AGENT_ORDERS:e=>`${Ct.LOCAL_DEV}/api/orders`,AGENT_ORDER:(e,t)=>`${Ct.LOCAL_DEV}/api/orders/${t}`,CREATE_SKILL:e=>`${Ct.DEV_SERVER}/developer/skills/${e}`,DEVELOPER_LOGS:(e,t)=>`${Ct.DEV_SERVER}/developer/skills/${e}/${t}/logs`,USER_DATA:e=>`${Ct.DEV_SERVER}/developer/user/data/agent/${e}`,LOCAL_CHAT:`${Ct.LOCAL_DEV}/chat`,LOCAL_PERSONA:`${Ct.LOCAL_DEV}/persona`,LOCAL_TOOLS:`${Ct.LOCAL_DEV}/tools`,LOCAL_TOOLS_TEST:`${Ct.LOCAL_DEV}/tools/test`,LOCAL_ENV:`${Ct.LOCAL_DEV}/env`},x9=class{constructor(t=""){this.baseUrl=t}async getAllSkillOverrides(){try{let n=await(await fetch("/api/skills")).json();return n.success&&n.skills&&Array.isArray(n.skills)?n.skills.map(r=>({skillId:r.skillId,sandboxId:r.sandboxId||r.skillId})).filter(r=>r.skillId&&r.sandboxId):[]}catch(t){return console.error("Error getting skill overrides:",t),[]}}async sendChatMessage(t,n,r,o,a,s){try{let u=await this.getAllSkillOverrides(),c=u.length>0?u:[{skillId:r,sandboxId:o}],d={messages:[{type:"text",text:t}],navigate:!0,skillOverride:c,...s&&{personaOverride:s}},p=await fetch(Je.CHAT_GENERATE(n),{method:"POST",headers:{"Content-Type":"application/json",Authorization:a},body:JSON.stringify(d)});if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return{success:!0,text:(await p.json()).text||"No response received"}}catch(u){return console.error("Chat API error:",u),{success:!1,error:u instanceof Error?u.message:"Unknown error occurred"}}}async sendProductionChatMessage(t,n,r){try{let o={messages:[{type:"text",text:t}],navigate:!0,skillOverride:[]},a=await fetch(Je.CHAT_GENERATE(n),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify(o)});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,text:(await a.json()).text||"No response received"}}catch(o){return console.error("Production chat API error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async sendLocalChatMessage(t,n){try{let r=await fetch(Je.LOCAL_CHAT,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,persona:n})});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return await r.json()}catch(r){return console.error("Local chat API error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async loadPersona(){try{let t=await fetch(Je.LOCAL_PERSONA);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){return console.error("Load persona error:",t),{success:!1,error:t instanceof Error?t.message:"Failed to load persona"}}}async savePersona(t){try{let n=await fetch(Je.LOCAL_PERSONA,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({persona:t})});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Save persona error:",n),{success:!1,error:n instanceof Error?n.message:"Failed to save persona"}}}async loadTools(){try{let t=await fetch(Je.LOCAL_TOOLS);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){return console.error("Load tools error:",t),{success:!1,error:t instanceof Error?t.message:"Failed to load tools"}}}async testTool(t,n,r,o,a,s){try{let u={toolName:t,inputs:n,skillOverride:[{skillId:o,sandboxId:a}]},c=await fetch(Je.TOOLS_TEST(r),{method:"POST",headers:{"Content-Type":"application/json",Authorization:s},body:JSON.stringify(u)});if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);let d=await c.json();return{success:!0,result:d.result||d}}catch(u){return console.error("Tool test error:",u),{success:!1,error:u instanceof Error?u.message:"Unknown error occurred"}}}async getSkillVersions(t,n,r){try{let o=await fetch(Je.SKILL_VERSIONS(n,t),{method:"GET",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,versions:(await o.json()).versions||[]}}catch(o){return console.error("Error fetching skill versions:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getPersonaVersions(t,n){try{let r=await fetch(`${Ct.DEV_SERVER}/developer/agents/${t}/persona/versions`,{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"}});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return{success:!0,versions:(await r.json()).versions||[]}}catch(r){return console.error("Error fetching persona versions:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async getProductionPersonaVersions(t,n){try{let r=await fetch(Je.PERSONA_VERSIONS(t),{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"}});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return{success:!0,versions:(await r.json()).versions||[]}}catch(r){return console.error("Error fetching production persona versions:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async deployPersonaVersion(t,n,r){try{let o=await fetch(Je.DEPLOY_PERSONA_VERSION(t,r),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({})});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("Error deploying persona version:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createPersonaVersion(t,n,r){try{let o=await fetch(`${Ct.DEV_SERVER}/developer/agents/${t}/persona/version`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({persona:r})});if(!o.ok){let s=await o.text();throw new Error(`HTTP error! status: ${o.status}, message: ${s}`)}return{success:!0,data:await o.json()}}catch(o){return console.error("Error creating persona version:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createSkillVersion(t,n,r,o){try{let a=await fetch(`${Ct.DEV_SERVER}/developer/skills/${n}/${t}/version`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok){let u=await a.text();throw new Error(`HTTP error! status: ${a.status}, message: ${u}`)}return{success:!0,data:await a.json()}}catch(a){return console.error("Error creating skill version:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadEnvContent(){try{let t=await fetch(Je.LOCAL_ENV);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){return console.error("Load env error:",t),{success:!1,error:t instanceof Error?t.message:"Failed to load environment variables"}}}async saveEnvContent(t){try{let n=await fetch(Je.LOCAL_ENV,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Save env error:",n),{success:!1,error:n instanceof Error?n.message:"Failed to save environment variables"}}}async testLocalTool(t,n){try{let r=await fetch(Je.LOCAL_TOOLS_TEST,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({toolName:t,inputs:n})});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return await r.json()}catch(r){return console.error("Local tool test error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async loadChatHistory(t,n){try{console.log("ApiService: Loading chat history with API key:",t,"agentId:",n);let r=await fetch(Je.CHAT_HISTORY(n),{method:"GET",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Response status:",r.status),console.log("ApiService: Response headers:",r.headers),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Received data:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: Chat history load error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async clearChatHistory(t,n){try{console.log("ApiService: Clearing chat history with API key:",t,"agentId:",n);let r=await fetch(Je.CHAT_HISTORY(n),{method:"DELETE",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return{success:!0}}catch(r){return console.error("Clear chat history error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async clearSandboxLogs(t,n,r){try{console.log("ApiService: Clearing sandbox logs with API key:",t,"agentId:",n,"sandboxId:",r);let o=await fetch(Je.DEVELOPER_LOGS(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Clear logs response status:",o.status),!o.ok){let s=await o.text();throw console.error("ApiService: HTTP error response:",s),new Error(`HTTP error! status: ${o.status}`)}let a=await o.json();return console.log("ApiService: Clear logs response:",a),{success:!0,data:a}}catch(o){return console.error("ApiService: Clear sandbox logs error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async loadAllSandboxLogs(t,n,r=20){try{let o=await this.getAllSkillOverrides();if(o.length===0)return{success:!0,data:{logs:[]}};let a=o.map(async c=>{try{let d=await this.loadSandboxLogs(t,n,c.sandboxId,r);return d.success&&d.data&&d.data.logs?d.data.logs.map(p=>({...p,skillName:c.skillId,sandboxId:c.sandboxId})):[]}catch(d){return console.error(`Error loading logs for skill ${c.skillId}:`,d),[]}});return{success:!0,data:{logs:(await Promise.all(a)).flat().sort((c,d)=>new Date(d.timestamp).getTime()-new Date(c.timestamp).getTime()).slice(0,r)}}}catch(o){return console.error("Error loading all sandbox logs:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred",data:{logs:[]}}}}async loadSandboxLogs(t,n,r,o=20){try{console.log("ApiService: Loading sandbox logs with API key:",t,"agentId:",n,"sandboxId:",r);let a=await fetch(`${Je.DEVELOPER_LOGS(n,r)}?limit=${o}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Logs response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Received logs data:",s),{success:!0,data:s}}catch(a){return console.error("ApiService: Sandbox logs load error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadUserData(t,n){try{console.log("ApiService: Loading user data with API key:",t,"agentId:",n),console.log("ApiService: API key length:",t?.length),console.log("ApiService: API key starts with:",t?.substring(0,10));let r=await fetch(Je.USER_DATA(n),{method:"GET",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(console.log("ApiService: User data response status:",r.status),console.log("ApiService: Response headers:",Object.fromEntries(r.headers.entries())),!r.ok){let a=await r.text();if(console.error("ApiService: HTTP error response:",a),r.status===401){console.log("ApiService: Trying alternative authentication method...");let s=await fetch(Je.USER_DATA(n),{method:"GET",headers:{accept:"*/*",Authorization:t}});if(s.ok){let u=await s.json();return console.log("ApiService: Alternative auth successful:",u),{success:!0,data:u}}}throw new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Received user data:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: User data load error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async saveUserData(t,n,r){return this.updateUserData(t,n,r)}async getUserData(t,n){return this.loadUserData(t,n)}async updateUserData(t,n,r){try{console.log("ApiService: Updating user data with API key:",t,"agentId:",n,"data:",r);let o=await fetch(Je.USER_DATA(n),{method:"PUT",headers:{accept:"*/*",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(console.log("ApiService: Update user data response status:",o.status),!o.ok){let s=await o.text();throw console.error("ApiService: HTTP error response:",s),new Error(`HTTP error! status: ${o.status}`)}let a=await o.json();return console.log("ApiService: Updated user data response:",a),{success:!0,data:a}}catch(o){return console.error("ApiService: Update user data error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async loadResources(t,n){try{console.log("ApiService: Loading resources with API key:",t,"agentId:",n);let r=await fetch(Je.AGENT_RESOURCES(n),{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Resources response status:",r.status),!r.ok)throw new Error(`HTTP error! status: ${r.status}`);let o=await r.json();return console.log("ApiService: Resources data:",o),{success:!0,data:o||[]}}catch(r){return console.error("ApiService: Error loading resources:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async createResource(t,n,r){try{let o=await fetch(Je.AGENT_RESOURCES(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("Error creating resource:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateResource(t,n,r,o){try{let a=await fetch(Je.AGENT_RESOURCE(n,r),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return console.error("Error updating resource:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async deleteResource(t,n,r){try{let o=await fetch(Je.AGENT_RESOURCE(n,r),{method:"DELETE",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0}}catch(o){return console.error("Error deleting resource:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async clearUserData(t,n){try{console.log("ApiService: Clearing user data with API key:",t,"agentId:",n);let r=await fetch(Je.USER_DATA(n),{method:"DELETE",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Clear user data response status:",r.status),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Clear user data response:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: Clear user data error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async createSkill(t,n,r){try{let o=await fetch(Je.CREATE_SKILL(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({name:r.name,description:r.description||`A Lua skill for ${r.name}`,context:r.context||""})});if(!o.ok){let s=await o.text();return{success:!1,error:{message:`HTTP ${o.status}: ${s}`}}}return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:{message:o instanceof Error?o.message:"Unknown error"}}}}async getAgentTypes(t){try{let n=await fetch(Je.AGENT_TYPES,{method:"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Error fetching agent types:",n),[]}}async createAgent(t,n){try{let r=await fetch(Je.CREATE_AGENT,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(n)});return r.ok?{success:!0,data:await r.json()}:{success:!1,error:await r.json()}}catch(r){return{success:!1,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async getAgentDetails(t,n){try{let r=await fetch(Je.AGENT_DETAILS(n),{method:"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});return r.ok?{success:!0,data:await r.json()}:{success:!1,error:await r.json()}}catch(r){return{success:!1,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async getSkills(t,n){try{console.log("ApiService: Loading skills with API key:",t,"agentId:",n);let r=await fetch(Je.AGENT_SKILLS(n),{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Skills response status:",r.status),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Received skills data:",o),{success:!0,skills:o.skills||[]}}catch(r){return console.error("ApiService: Skills load error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async activateSkill(t,n,r,o){try{console.log(`ApiService: ${o?"Activating":"Deactivating"} skill:`,r,"for agent:",n);let a=await fetch(Je.ACTIVATE_SKILL(n,r),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({active:o})});if(console.log("ApiService: Activate skill response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Activate skill response:",s),{success:!0,data:s}}catch(a){return console.error("ApiService: Activate skill error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async publishSkillVersion(t,n,r,o){try{console.log("ApiService: Publishing skill version:",o,"for skill:",r,"agent:",n);let a=await fetch(Je.PUBLISH_SKILL_VERSION(n,r,o),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Publish skill version response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Publish skill version response:",s),{success:!0,data:s}}catch(a){return console.error("ApiService: Publish skill version error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadProductionLogs(t,n,r=1,o=100){try{console.log("ApiService: Loading production logs with API key:",t,"agentId:",n,"page:",r,"limit:",o);let a=await fetch(`${Je.PRODUCTION_LOGS(n)}?page=${r}&limit=${o}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Production logs response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Production logs response:",s),{success:!0,logs:s.logs||[],pagination:s.pagination}}catch(a){return console.error("ApiService: Production logs error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadProductionEnv(t,n){try{console.log("ApiService: Loading production env with API key:",t,"agentId:",n);let r=await fetch(Je.PRODUCTION_ENV(n),{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Production env response status:",r.status),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Production env response:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: Production env error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async updateProductionEnv(t,n,r){try{console.log("ApiService: Updating production env with API key:",t,"agentId:",n,"data:",r);let o=await fetch(Je.PRODUCTION_ENV(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(console.log("ApiService: Update production env response status:",o.status),!o.ok){let s=await o.text();throw console.error("ApiService: HTTP error response:",s),new Error(`HTTP error! status: ${o.status}`)}let a=await o.json();return console.log("ApiService: Update production env response:",a),{success:!0,data:a}}catch(o){return console.error("ApiService: Update production env error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getProducts(t,n,r=1,o=20){try{console.log("ApiService: Loading products with API key:",t,"agentId:",n);let a=await fetch(`${Je.AGENT_PRODUCTS(n)}?page=${r}&limit=${o}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return console.error("ApiService: Products load error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async createProduct(t,n,r){try{let o=await fetch(Je.AGENT_PRODUCTS(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Create product error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateProduct(t,n,r){try{let o=await fetch(Je.AGENT_PRODUCTS(n),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Update product error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async deleteProduct(t,n,r){try{let o=await fetch(Je.AGENT_PRODUCT(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Delete product error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async searchProducts(t,n,r){try{let o=await fetch(`${Je.SEARCH_PRODUCTS(n)}?searchQuery=${encodeURIComponent(r)}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Search products error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getBaskets(t,n,r){try{let o=r?`${Je.AGENT_BASKETS(n)}?status=${r}`:Je.AGENT_BASKETS(n),a=await fetch(o,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createBasket(t,n,r){try{let o=await fetch(Je.AGENT_BASKETS(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateBasket(t,n,r,o){try{let a=await fetch(Je.AGENT_BASKET(n,r),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async deleteBasket(t,n,r){try{let o=await fetch(Je.AGENT_BASKET(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getOrders(t,n,r){try{let o=r?`${Je.AGENT_ORDERS(n)}?status=${r}`:Je.AGENT_ORDERS(n),a=await fetch(o,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createOrder(t,n,r){try{let o=await fetch(Je.AGENT_ORDERS(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateOrderStatus(t,n,r,o){try{let a=await fetch(`${Je.AGENT_ORDER(n,r)}/status`,{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({status:o})});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async deleteOrder(t,n,r){try{let o=await fetch(Je.AGENT_ORDER(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}},Me=new x9});var Va,i5,b9=A(()=>{"use strict";o5();Va=Z(ke()),i5=({messages:e,isLoading:t,onActionClick:n,className:r="chat-messages",ariaLabel:o="Chat messages"})=>{let a=e.map(s=>({id:s.id,role:s.sender,content:s.text,type:"text",createdAt:s.timestamp.toISOString()}));return console.log("luaMessages",a),(0,Va.jsx)("div",{className:`${r} lua:relative lua:bg-gray-100`,role:"log","aria-live":"polite","aria-label":o,tabIndex:0,children:(0,Va.jsxs)("div",{className:"lua:bg-white lua:p-3 lua:rounded-lg lua:space-y-4 lua:flex lua:flex-col",children:[a.map(s=>{let u=dL(s.content);return(0,Va.jsxs)("div",{children:[(0,Va.jsx)(oL,{message:s,onSelect:n}),u.length>0&&(0,Va.jsx)(cL,{buttons:u,onClick:n})]},s.id)}),t&&(0,Va.jsx)(uL,{})]})})}});var $s,Pn,OK,_9,fL=A(()=>{"use strict";$s=Z(_e());o5();Yn();b9();Pn=Z(ke()),OK=({apiKey:e,agentId:t,skillId:n,sandboxId:r,persona:o,sharedChatMessages:a,onSharedSendMessage:s,onSharedClearHistory:u,isChatLoading:c,setIsChatLoading:d})=>{let{messages:p,setMessages:h}=z1(),[m,g]=(0,$s.useState)(""),b=(0,$s.useRef)(null),y=()=>{b.current?.scrollIntoView({behavior:"smooth"})};(0,$s.useEffect)(()=>{y()},[p]),(0,$s.useEffect)(()=>{if(a.length===0){let E={id:"welcome",role:"assistant",content:"\u{1F44B} Welcome! Start chatting to test your Lua skill. Your messages will be sent to the sandbox environment.",type:"text",createdAt:new Date().toISOString()};h([E])}},[a,h]);let k=E=>{v(E)},v=async E=>{if(!E.trim())return;let T={id:Date.now().toString(),text:E,sender:"user",timestamp:new Date};s(T),g(""),d(!0);try{let N=await Me.sendLocalChatMessage(E,o),R={id:(Date.now()+1).toString(),text:N.success?N.text||"No response received":`\u274C ${N.error||"Failed to send message"}`,sender:"assistant",timestamp:new Date};s(R)}catch(N){let R={id:(Date.now()+2).toString(),text:`\u274C Error: ${N instanceof Error?N.message:"Unknown error"}`,sender:"assistant",timestamp:new Date};s(R)}finally{d(!1)}};return(0,Pn.jsxs)("section",{className:"chat-container",role:"region","aria-label":"Chat interface",children:[(0,Pn.jsxs)("header",{className:"chat-header lua:bg-white lua:border-b",children:[(0,Pn.jsx)("div",{className:"chat-header-content",children:(0,Pn.jsxs)("div",{children:[(0,Pn.jsx)("h2",{children:"Chat to your Agent [Sandbox]"}),(0,Pn.jsx)("p",{className:"lua:text-gray-700",children:"Test your sandbox skill in real-time"})]})}),(0,Pn.jsx)("button",{className:"clear-chat-button",onClick:u,disabled:c,title:"Clear chat history","aria-label":"Clear chat history",children:"\u{1F5D1}\uFE0F"})]}),(0,Pn.jsx)(i5,{messages:a,isLoading:c,onActionClick:k,ariaLabel:"Chat messages"}),(0,Pn.jsx)("div",{ref:b}),(0,Pn.jsx)("div",{className:"chat-input-container",children:(0,Pn.jsxs)("form",{className:"chat-input-form",onSubmit:E=>{E.preventDefault(),v(m)},role:"form","aria-label":"Send message",children:[(0,Pn.jsx)("label",{htmlFor:"chat-input",className:"sr-only",children:"Type your message"}),(0,Pn.jsx)("input",{type:"text",id:"chat-input",name:"chatMessage",className:"chat-input",value:m,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&(E.preventDefault(),v(m))},placeholder:"Type your message...",disabled:c,autoComplete:"off","aria-describedby":"chat-input-help"}),(0,Pn.jsx)("div",{id:"chat-input-help",className:"sr-only",children:"Press Enter to send, Shift+Enter for new line"}),(0,Pn.jsx)("button",{type:"submit",className:"send-button",disabled:c||!m.trim(),"aria-label":c?"Sending message...":"Send message",children:c?"Sending...":"Send"})]})})]})},_9=e=>(0,Pn.jsx)(r5,{children:(0,Pn.jsx)(OK,{...e})})});var No,Oe,k9,S9=A(()=>{"use strict";No=Z(_e());sr();Yn();Oe=Z(ke()),k9=({persona:e,onSavePersona:t,apiKey:n,agentId:r})=>{let[o,a]=(0,No.useState)(e),[s,u]=(0,No.useState)(!1),[c,d]=(0,No.useState)([]),[p,h]=(0,No.useState)(!1),[m,g]=(0,No.useState)("current"),[b,y]=(0,No.useState)(null),[k,v]=(0,No.useState)(!1),[x,_]=(0,No.useState)(!1);(0,No.useEffect)(()=>{a(e)},[e]),(0,No.useEffect)(()=>{E()},[]);let E=async()=>{h(!0);try{let H=await Me.getPersonaVersions(r,n);if(H.success&&H.versions){let j=H.versions.sort(($,Y)=>Y.createdDate-$.createdDate);d(j)}else console.error("Failed to load persona versions:",H.error),d([])}catch(H){console.error("Error loading persona versions:",H),d([])}finally{h(!1)}},T=H=>{g(H),b&&y(null)},N=H=>{y(H)},R=()=>{y(null)},O=()=>{if(!o.trim()){alert("Please enter a persona before creating a version");return}_(!0)},F=async()=>{v(!0);try{let H=await Me.createPersonaVersion(r,n,o.trim());if(H.success)console.log("\u2705 Persona version created successfully:",H.data),await E(),g("versions"),alert("\u2705 Persona version created successfully! You can deploy it from the Production tab.");else throw new Error(H.error||"Failed to create persona version")}catch(H){console.error("\u274C Error creating persona version:",H),alert(`\u274C Failed to create persona version: ${H instanceof Error?H.message:"Unknown error"}`)}finally{v(!1),_(!1)}},z=()=>{_(!1)},V=async()=>{let H=o.trim();if(!H){alert("Persona cannot be empty");return}u(!0);try{await t(H)&&a(H)}finally{u(!1)}};return b?(0,Oe.jsxs)("div",{className:"lua:space-y-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2",children:[(0,Oe.jsx)(qe,{variant:"tertiary",size:"small",onClick:R,"aria-label":"Back to versions",children:"\u2190 Back"}),(0,Oe.jsxs)("h3",{className:"lua:text-lg lua:font-semibold lua:text-gray-900",children:["Persona v",b.version]}),b.isCurrent?(0,Oe.jsx)(Qr,{variant:"secondary",children:"Active (Deployed)"}):(0,Oe.jsx)(Qr,{children:"Available"})]}),(0,Oe.jsxs)(bt,{className:"lua:p-4 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:[(0,Oe.jsxs)("div",{className:"lua:grid lua:grid-cols-1 md:lua:grid-cols-3 lua:gap-4 lua:mb-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-500",children:"Created By"}),(0,Oe.jsx)("span",{className:"lua:text-sm lua:text-gray-900",children:b.createdBy})]}),(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-500",children:"Status"}),(0,Oe.jsx)("span",{className:"lua:text-sm lua:text-gray-900",children:b.isCurrent?"Active (Deployed)":"Available"})]}),(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-500",children:"Created Date"}),(0,Oe.jsx)("span",{className:"lua:text-sm lua:text-gray-900",children:new Date(b.createdDate).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"})})]})]}),(0,Oe.jsxs)("div",{children:[(0,Oe.jsx)("h4",{className:"lua:text-base lua:font-medium lua:text-gray-900 lua:mb-2",children:"Persona Content"}),(0,Oe.jsx)(bt,{className:"lua:p-3 lua:bg-gray-50 lua:border lua:border-gray-200 lua:text-sm lua:text-gray-900 lua:whitespace-pre-wrap",children:b.persona})]})]})]}):(0,Oe.jsxs)("div",{className:"lua:pb-24",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:justify-between lua:pb-2 lua:px-5 lua:py-4 lua:border-b lua:border-gray-200",children:[(0,Oe.jsx)("h3",{className:"lua:text-lg lua:font-semibold lua:text-gray-900",children:"Agent Persona"}),(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2",children:[(0,Oe.jsx)(qe,{variant:"primary",size:"small",onClick:O,disabled:k||!o.trim(),"aria-label":"Create new persona version",children:k?"Creating...":"Create Version"}),(0,Oe.jsx)(qe,{variant:"secondary",size:"small",onClick:V,disabled:s,"aria-label":"Save persona to YAML",children:s?"Saving\u2026":"Save"})]})]}),(0,Oe.jsxs)("div",{className:"lua:px-5 lua:py-4 lua:px-5 lua:py-4 lua:space-y-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2 ",children:[(0,Oe.jsx)(qe,{variant:m==="current"?"primary":"secondary",size:"small",onClick:()=>T("current"),children:"Current"}),(0,Oe.jsxs)(qe,{variant:m==="versions"?"primary":"secondary",size:"small",onClick:()=>T("versions"),children:["Versions (",c.length,")"]})]}),m==="current"?(0,Oe.jsx)("div",{children:(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-3",children:[(0,Oe.jsx)("h4",{className:"lua:text-base lua:font-medium lua:text-gray-900",children:"Edit Current Persona"}),(0,Oe.jsx)(au,{value:o,onChange:H=>a(H.target.value),placeholder:"Enter agent persona...",className:"lua:min-h-48"}),(0,Oe.jsxs)("div",{className:"lua:-mx-4 lua:px-4 lua:mt-3 lua:py-2 lua:bg-gray-50 lua:border-t lua:border-gray-200 lua:rounded-b-lg lua:text-sm lua:text-gray-700 lua:sticky lua:bottom-0",children:["This persona is stored in your ",(0,Oe.jsx)("code",{children:"lua.skill.yaml"})," file and used for local development."]})]})}):(0,Oe.jsx)(bt,{className:"lua:p-0 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:p?(0,Oe.jsx)("div",{className:"lua:p-6 lua:flex lua:items-center lua:justify-center",children:(0,Oe.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"lua:h-6 lua:opacity-60"})}):c.length>0?(0,Oe.jsx)("div",{className:"lua:divide-y lua:divide-gray-200",children:c.map((H,j)=>(0,Oe.jsxs)("button",{className:"lua:w-full lua:text-left lua:p-3 lua:flex lua:items-center lua:justify-between hover:lua:bg-gray-50",onClick:()=>N(H),children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2",children:[(0,Oe.jsxs)("span",{className:"lua:text-sm lua:font-medium lua:text-gray-900",children:["v",H.version]}),(0,Oe.jsx)(Qr,{variant:H.isCurrent?"secondary":"default",children:H.isCurrent?"Active":"Available"})]}),(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-600",children:new Date(H.createdDate).toLocaleDateString()})]}),(0,Oe.jsx)("span",{className:"lua:text-gray-400",children:"\u2192"})]},j))}):(0,Oe.jsxs)("div",{className:"lua:p-8 lua:text-center",children:[(0,Oe.jsx)("div",{className:"lua:text-3xl lua:mb-2",children:"\u{1F464}"}),(0,Oe.jsx)("div",{className:"lua:text-base lua:font-medium lua:text-gray-900",children:"No persona versions found"}),(0,Oe.jsx)("div",{className:"lua:text-sm lua:text-gray-600",children:"Persona versions will appear here when available"})]})}),x&&(0,Oe.jsx)("div",{className:"lua:fixed lua:inset-0 lua:bg-black/30 lua:flex lua:items-center lua:justify-center",children:(0,Oe.jsxs)("div",{className:"lua:bg-white lua:rounded-lg lua:shadow-lg lua:border lua:border-gray-200 lua:w-full lua:max-w-lg lua:p-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:justify-between lua:mb-2",children:[(0,Oe.jsx)("h3",{className:"lua:text-base lua:font-semibold lua:text-gray-900",children:"Create Persona Version"}),(0,Oe.jsx)(qe,{variant:"tertiary",size:"small",onClick:z,"aria-label":"Close",children:"\u2715"})]}),(0,Oe.jsxs)("div",{className:"lua:space-y-3",children:[(0,Oe.jsx)("p",{className:"lua:text-sm lua:text-gray-700",children:"This will create a new persona version that can be deployed to production."}),(0,Oe.jsxs)("p",{className:"lua:text-sm lua:text-gray-700",children:[(0,Oe.jsx)("strong",{children:"Note:"})," The version will be created but not automatically released. You can deploy it from the Production tab."]}),(0,Oe.jsxs)("div",{className:"lua:space-y-2",children:[(0,Oe.jsx)("h4",{className:"lua:text-sm lua:font-medium lua:text-gray-900",children:"Persona Content:"}),(0,Oe.jsxs)(bt,{className:"lua:p-3 lua:bg-gray-50 lua:border lua:border-gray-200 lua:text-sm lua:text-gray-900",children:[o.substring(0,300),o.length>300?"...":""]})]})]}),(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:justify-end lua:gap-2 lua:mt-4",children:[(0,Oe.jsx)(qe,{variant:"tertiary",onClick:z,disabled:k,children:"Cancel"}),(0,Oe.jsx)(qe,{variant:"primary",onClick:F,disabled:k,children:k?"Creating...":"Create Version"})]})]})})]})]})}});var Bn,Q,E9,N9=A(()=>{"use strict";Bn=Z(_e());Yn();Q=Z(ke()),E9=({apiKey:e,agentId:t,skillId:n,sandboxId:r})=>{let[o,a]=(0,Bn.useState)([]),[s,u]=(0,Bn.useState)(null),[c,d]=(0,Bn.useState)(null),[p,h]=(0,Bn.useState)([]),[m,g]=(0,Bn.useState)(!1),[b,y]=(0,Bn.useState)("current"),[k,v]=(0,Bn.useState)(!1),[x,_]=(0,Bn.useState)(!1),[E,T]=(0,Bn.useState)(""),[N,R]=(0,Bn.useState)({}),[O,F]=(0,Bn.useState)(null),[z,V]=(0,Bn.useState)(!0),[H,j]=(0,Bn.useState)(!1),[$,Y]=(0,Bn.useState)(null),[W,ae]=(0,Bn.useState)([]);(0,Bn.useEffect)(()=>{X(),q()},[]);let X=async()=>{V(!0),Y(null);try{console.log("Loading skills from /api/skills...");let J=await fetch("/api/skills");if(console.log("Skills API response status:",J.status),!J.ok)throw new Error(`HTTP ${J.status}: ${J.statusText}`);let le=await J.json();console.log("Skills API response data:",le),le.success&&le.skills&&Array.isArray(le.skills)?(console.log("Skills loaded successfully:",le.skills),a(le.skills),Y(null)):(console.error("Failed to load skills:",le.error),Y(le.error||"Failed to load skills - invalid data format"),a([]))}catch(J){console.error("Error loading skills:",J),Y(J instanceof Error?J.message:"Failed to load skills"),a([])}finally{V(!1)}},q=async()=>{try{let le=await(await fetch("/tools")).json();if(le.success&&le.tools){let oe=[];Array.isArray(le.tools)?oe=le.tools:typeof le.tools=="object"&&(oe=Object.entries(le.tools).map(([xe,Ge])=>({name:xe,...Ge}))),ae(oe)}else console.error("Failed to load tools:",le.error),ae([])}catch(J){console.error("Error loading tools:",J),ae([])}},M=J=>{let le={};J.inputSchema.properties&&Object.keys(J.inputSchema.properties).forEach(oe=>{let xe=J.inputSchema.properties[oe];le[oe]=ve(xe)}),R(le)},ve=J=>{if(J.type==="object"&&J.properties){let le={};return Object.keys(J.properties).forEach(oe=>{le[oe]=ve(J.properties[oe])}),le}else return J.type==="number"?0:J.type==="boolean"?!1:""},Ee=J=>{let le=W.find(oe=>oe.name===J);le&&(d(le),M(le),F(null))},I=async J=>{g(!0);try{let le=await Me.getSkillVersions(J.skillId,t,e);if(le.success&&le.versions){let oe=le.versions.sort((xe,Ge)=>new Date(Ge.createdDate||Ge.createdAt).getTime()-new Date(xe.createdDate||xe.createdAt).getTime());h(oe)}else console.error("Failed to load skill versions:",le.error),h([])}catch(le){console.error("Error loading skill versions:",le),h([])}finally{g(!1)}},ne=J=>{let le=o.find(oe=>oe.name===J);le&&(u(J),y("current"),I(le))},Fe=()=>{u(null),y("current"),h([]),d(null),F(null)},ye=J=>{y(J),c&&(d(null),F(null))},de=()=>{d(null),F(null)},ce=async()=>{if(!s)return;let J=o.find(oe=>oe.name===s);if(!J)return;p.some(oe=>oe.version===J.version)?(T(J.version),_(!0)):await he(J.version)},he=async J=>{if(!s)return;let le=o.find(oe=>oe.name===s);if(le){v(!0);try{let xe=await(await fetch("/tools")).json();if(!xe.success||!xe.tools)throw new Error("Failed to load current tools data");let Ge=[];Array.isArray(xe.tools)?Ge=xe.tools:typeof xe.tools=="object"&&(Ge=Object.entries(xe.tools).map(([Qt,pn])=>({name:Qt,description:pn.description||"",inputSchema:pn.inputSchema||{type:"object"},execute:pn.execute||""})));let vt=Ge.filter(Qt=>le.tools.includes(Qt.name)),Et={name:le.name,version:J,description:le.description,context:le.context,tools:vt};console.log("Creating version with data:",Et);let fn=await Me.createSkillVersion(le.skillId,t,e,Et);if(fn.success)console.log("\u2705 Version created successfully:",fn.data),await I(le),alert(`\u2705 Version ${J} created successfully!`);else throw new Error(fn.error||"Failed to create version")}catch(oe){console.error("\u274C Error creating version:",oe),alert(`\u274C Failed to create version: ${oe instanceof Error?oe.message:"Unknown error"}`)}finally{v(!1),_(!1)}}},Se=async()=>{if(!E.trim()){alert("Please enter a version number");return}if(p.some(le=>le.version===E.trim())){alert("This version already exists. Please enter a different version number.");return}await he(E.trim())},D=()=>{_(!1),T("")},re=(J,le,oe)=>{R(xe=>oe?{...xe,[J]:{...xe[J],[oe]:le}}:{...xe,[J]:le})},ue=async()=>{if(c){j(!0),F(null);try{let J=ge(N,c.inputSchema),le=await Me.testLocalTool(c.name,J);F(le)}catch(J){F({success:!1,error:J instanceof Error?J.message:"Unknown error occurred"})}finally{j(!1)}}},ge=(J,le)=>{let oe={};for(let[xe,Ge]of Object.entries(J))if(Ge&&typeof Ge=="object"&&!Array.isArray(Ge)){let vt=le.properties?.[xe];if(vt&&vt.type==="object"&&vt.properties){let Et=ge(Ge,vt);Object.keys(Et).length>0&&(oe[xe]=Et)}else oe[xe]=Ge}else{let vt=le.properties?.[xe];if((!le.required||!le.required.includes(xe))&&(Ge===""||Ge===null||Ge===void 0))continue;oe[xe]=Ge}return oe},se=(J,le,oe)=>{let xe=oe?N[J]?.[oe]||"":N[J]||"",Ge=oe?le.required?.includes(oe):c?.inputSchema.required?.includes(J);if(le.type==="object"&&le.properties)return(0,Q.jsxs)("div",{className:"nested-object",children:[(0,Q.jsx)("div",{className:"nested-object-label",children:J}),(0,Q.jsx)("div",{className:"nested-fields",children:Object.entries(le.properties).map(([vt,Et])=>(0,Q.jsxs)("div",{className:"nested-field",children:[(0,Q.jsxs)("label",{className:"nested-label",children:[vt,le.required?.includes(vt)&&(0,Q.jsx)("span",{className:"required",children:"*"})]}),se(J,Et,vt),Et.description&&(0,Q.jsx)("div",{className:"input-description",children:Et.description})]},vt))})]});switch(le.type){case"number":return(0,Q.jsx)("input",{type:"number",value:xe,onChange:vt=>re(J,parseFloat(vt.target.value)||0,oe),placeholder:le.description||`Enter ${oe||J}`,className:"tool-input",required:Ge});case"boolean":return(0,Q.jsx)("input",{type:"checkbox",checked:xe,onChange:vt=>re(J,vt.target.checked,oe),className:"tool-checkbox"});case"string":default:return(0,Q.jsx)("input",{type:"text",value:xe,onChange:vt=>re(J,vt.target.value,oe),placeholder:le.description||`Enter ${oe||J}`,className:"tool-input",required:Ge})}};if(z)return(0,Q.jsx)("div",{className:"skills-page",children:(0,Q.jsx)("div",{className:"skills-loading",children:(0,Q.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})});if(c)return(0,Q.jsx)("div",{className:"skills-page",children:(0,Q.jsxs)("div",{className:"tool-form",children:[(0,Q.jsxs)("div",{className:"tool-form-header",children:[(0,Q.jsx)("button",{className:"back-button",onClick:de,title:"Back to skill",children:"\u2190"}),(0,Q.jsx)("h3",{children:c.name})]}),(0,Q.jsxs)("div",{className:"tool-form-content",children:[(0,Q.jsx)("div",{className:"tool-info",children:(0,Q.jsx)("p",{children:c.description})}),(0,Q.jsxs)("div",{className:"tool-inputs",children:[(0,Q.jsx)("h4",{children:"Input Parameters"}),Object.keys(c.inputSchema.properties||{}).length>0?(0,Q.jsx)("div",{className:"input-fields",children:Object.entries(c.inputSchema.properties).map(([J,le])=>(0,Q.jsxs)("div",{className:"input-field",children:[(0,Q.jsxs)("label",{children:[J,c.inputSchema.required?.includes(J)&&(0,Q.jsx)("span",{className:"required",children:"*"})]}),se(J,le),le.description&&(0,Q.jsx)("div",{className:"input-description",children:le.description})]},J))}):(0,Q.jsx)("p",{className:"no-inputs",children:"This tool requires no input parameters."})]}),(0,Q.jsx)("div",{className:"tool-actions",children:(0,Q.jsx)("button",{onClick:ue,disabled:H,className:"test-button",children:H?"Testing...":"Test Tool"})}),O&&(0,Q.jsxs)("div",{className:"test-result",children:[(0,Q.jsx)("h4",{children:"Test Result"}),(0,Q.jsx)("div",{className:`result-content ${O.success?"success":"error"}`,children:O.success?(0,Q.jsxs)("div",{children:[(0,Q.jsx)("div",{className:"result-label",children:"\u2705 Success"}),(0,Q.jsx)("pre",{className:"result-data",children:JSON.stringify(O.result,null,2)})]}):(0,Q.jsxs)("div",{children:[(0,Q.jsx)("div",{className:"result-label",children:"\u274C Error"}),(0,Q.jsx)("div",{className:"result-error",children:O.error})]})})]})]})]})});if(s){let J=o.find(le=>le.name===s);return J?(0,Q.jsxs)("div",{className:"skills-page",children:[(0,Q.jsxs)("div",{className:"skills-header",children:[(0,Q.jsxs)("div",{className:"header-left",children:[(0,Q.jsx)("button",{className:"back-button",onClick:Fe,children:"\u2190"}),(0,Q.jsx)("h4",{children:J.name})]}),(0,Q.jsx)("button",{className:"create-version-button",onClick:ce,disabled:k,title:"Create new version",children:k?"Creating...":"Create Version"})]}),(0,Q.jsxs)("div",{className:"skill-tabs",children:[(0,Q.jsxs)("div",{className:"tabs-header",children:[(0,Q.jsx)("button",{className:`tab-button ${b==="current"?"active":""}`,onClick:()=>ye("current"),children:"Current"}),(0,Q.jsxs)("button",{className:`tab-button ${b==="versions"?"active":""}`,onClick:()=>ye("versions"),children:["Versions (",p.length,")"]})]}),(0,Q.jsx)("div",{className:"tab-content",children:b==="current"?(0,Q.jsxs)("div",{className:"current-skill-tab",children:[(0,Q.jsx)("div",{className:"skill-details",children:(0,Q.jsxs)("div",{className:"skill-info-section",children:[(0,Q.jsxs)("div",{className:"skill-meta",children:[(0,Q.jsxs)("span",{className:"skill-version",children:["v",J.version]}),(0,Q.jsxs)("span",{className:"skill-tools-count",children:[J.tools.length," tools"]})]}),J.description&&(0,Q.jsxs)("div",{className:"skill-description-section",children:[(0,Q.jsx)("h5",{children:"Description"}),(0,Q.jsx)("p",{children:J.description})]}),J.context&&(0,Q.jsxs)("div",{className:"skill-context-section",children:[(0,Q.jsx)("h5",{children:"Context"}),(0,Q.jsx)("p",{children:J.context})]})]})}),(0,Q.jsxs)("div",{className:"tools-section",children:[(0,Q.jsx)("div",{className:"tools-header",children:(0,Q.jsxs)("h5",{children:["Available Tools (",J.tools.length,")"]})}),J.tools&&J.tools.length>0?(0,Q.jsx)("div",{className:"tools-grid",children:J.tools.map((le,oe)=>(0,Q.jsxs)("div",{className:"tool-card",onClick:()=>Ee(le),children:[(0,Q.jsx)("div",{className:"tool-card-header",children:(0,Q.jsx)("h4",{children:le})}),(0,Q.jsx)("div",{className:"tool-card-body",children:(0,Q.jsx)("span",{className:"skill-badge",children:J.name})})]},oe))}):(0,Q.jsxs)("div",{className:"no-tools",children:[(0,Q.jsx)("div",{className:"no-tools-icon",children:"\u{1F527}"}),(0,Q.jsx)("div",{className:"no-tools-text",children:"No tools in this skill"}),(0,Q.jsx)("div",{className:"no-tools-subtext",children:"This skill doesn't have any tools defined"})]})]}),(0,Q.jsx)("div",{className:"skills-help",children:(0,Q.jsx)("p",{children:"This skill is compiled from your local code and updates automatically when you make changes. Use the tools above to test your skill's functionality."})})]}):(0,Q.jsx)("div",{className:"versions-skill-tab",children:m?(0,Q.jsx)("div",{className:"versions-loading",children:(0,Q.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})}):p.length>0?(0,Q.jsx)("div",{className:"versions-list",children:p.map((le,oe)=>(0,Q.jsxs)("div",{className:`version-item ${le.status}`,onClick:()=>{console.log("Selected version:",le.version)},children:[(0,Q.jsxs)("div",{className:"version-info",children:[(0,Q.jsxs)("div",{className:"version-header",children:[(0,Q.jsxs)("span",{className:"version-number",children:["v",le.version]}),(0,Q.jsx)("span",{className:`version-status ${le.status}`,children:le.status})]}),(0,Q.jsxs)("div",{className:"version-meta",children:[(0,Q.jsx)("span",{className:"version-date",children:new Date(le.createdDate||le.createdAt).toLocaleDateString()}),(0,Q.jsxs)("span",{className:"version-author",children:["by ",le.createdByEmail||le.createdBy]})]})]}),(0,Q.jsx)("div",{className:"version-arrow",children:"\u2192"})]},oe))}):(0,Q.jsxs)("div",{className:"no-versions",children:[(0,Q.jsx)("div",{className:"no-versions-icon",children:"\u{1F4E6}"}),(0,Q.jsx)("div",{className:"no-versions-text",children:"No versions found"}),(0,Q.jsx)("div",{className:"no-versions-subtext",children:"Create your first version to get started"})]})})})]}),x&&(0,Q.jsx)("div",{className:"version-modal-overlay",children:(0,Q.jsxs)("div",{className:"version-modal",children:[(0,Q.jsx)("div",{className:"version-modal-header",children:(0,Q.jsx)("h3",{children:"Create New Version"})}),(0,Q.jsxs)("div",{className:"version-modal-body",children:[(0,Q.jsxs)("p",{children:["Version ",(0,Q.jsx)("strong",{children:o.find(le=>le.name===s)?.version})," already exists."]}),(0,Q.jsx)("p",{children:"Please enter a new version number:"}),(0,Q.jsx)("input",{type:"text",value:E,onChange:le=>T(le.target.value),placeholder:"e.g., 1.0.1",className:"version-input",autoFocus:!0})]}),(0,Q.jsxs)("div",{className:"version-modal-actions",children:[(0,Q.jsx)("button",{className:"cancel-button",onClick:D,disabled:k,children:"Cancel"}),(0,Q.jsx)("button",{className:"create-button",onClick:Se,disabled:k||!E.trim(),children:k?"Creating...":"Create Version"})]})]})})]}):(0,Q.jsxs)("div",{className:"skills-page",children:[(0,Q.jsx)("div",{className:"skills-header",children:(0,Q.jsxs)("div",{className:"header-left",children:[(0,Q.jsx)("button",{className:"back-button",onClick:Fe,children:"\u2190"}),(0,Q.jsx)("h4",{children:"Skill Not Found"})]})}),(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u274C"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"Skill not found"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:"The selected skill could not be loaded"})]})]})}return(0,Q.jsxs)("div",{className:"skills-page",children:[(0,Q.jsxs)("div",{className:"skills-header",children:[(0,Q.jsx)("h3",{children:"Available Skills"}),(0,Q.jsx)("button",{className:"refresh-button",onClick:X,title:"Refresh skills",children:"\u21BB"})]}),(0,Q.jsx)("div",{className:"skills-content",children:$?(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u274C"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"Error loading skills"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:$}),(0,Q.jsx)("button",{className:"retry-button",onClick:X,style:{marginTop:"16px"},children:"Retry"})]}):o.length===0?(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u2699\uFE0F"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"No skills found"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:"Skills will appear here when available in your project"})]}):Array.isArray(o)&&o.length>0?(0,Q.jsx)("div",{className:"skills-list",children:o.map(J=>(0,Q.jsxs)("div",{className:"skill-item",onClick:()=>ne(J.name),children:[(0,Q.jsxs)("div",{className:"skill-info",children:[(0,Q.jsx)("div",{className:"skill-name",children:J.name}),(0,Q.jsx)("div",{className:"skill-description",children:J.description}),(0,Q.jsxs)("div",{className:"skill-stats",children:[(0,Q.jsxs)("span",{className:"skill-stat",children:["v",J.version]}),(0,Q.jsxs)("span",{className:"skill-stat",children:[J.tools.length," tools"]})]})]}),(0,Q.jsx)("div",{className:"skill-arrow",children:"\u2192"})]},J.name))}):(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u2699\uFE0F"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"No skills available"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:"No valid skills data received"})]})})]})}});var j1=A(()=>{});var sn,ze,U1,a5=A(()=>{"use strict";sn=Z(_e());Yn();j1();ze=Z(ke()),U1=({apiKey:e,agentId:t,isProduction:n=!1,onHeaderChange:r})=>{let[o,a]=(0,sn.useState)([]),[s,u]=(0,sn.useState)(!0),[c,d]=(0,sn.useState)(""),[p,h]=(0,sn.useState)([]),[m,g]=(0,sn.useState)(null),[b,y]=(0,sn.useState)(!1),[k,v]=(0,sn.useState)(!1),[x,_]=(0,sn.useState)({}),[E,T]=(0,sn.useState)(null),[N,R]=(0,sn.useState)(null),[O,F]=(0,sn.useState)(!1),[z,V]=(0,sn.useState)(!1),[H,j]=(0,sn.useState)(1),[$,Y]=(0,sn.useState)(1),[W,ae]=(0,sn.useState)(0);(0,sn.useEffect)(()=>{X()},[m,k,b,O,z,x]),(0,sn.useEffect)(()=>{q()},[e,t,H]);let X=()=>{if(!r)return;let D;m&&!b?D=(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("button",{className:"edit-button",onClick:I,disabled:z,title:"Edit product",children:"\u270F\uFE0F Edit"}),(0,ze.jsx)("button",{className:"delete-button",onClick:Fe,disabled:z,title:"Delete product",children:z?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):b||k?D=(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("button",{className:"cancel-button",onClick:ye,disabled:O,title:"Cancel",children:"\u2716 Cancel"}),(0,ze.jsx)("button",{className:"save-button",onClick:ne,disabled:O,title:k?"Create product":"Save changes",children:O?"\u27F3 Saving...":k?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):D=(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("button",{className:"create-button",onClick:Ee,title:"Create new product",children:"\u2795 Add Product"}),(0,ze.jsx)("button",{className:"refresh-button",onClick:q,disabled:s,title:"Refresh products",children:s?"\u27F3":"\u21BB"})]}),r({title:"",actions:D})};(0,sn.useEffect)(()=>{if(c.trim()){let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)}else h(o)},[o,c]),(0,sn.useEffect)(()=>{if(E||N){let D=setTimeout(()=>{T(null),R(null)},5e3);return()=>clearTimeout(D)}},[E,N]);let q=async()=>{u(!0);try{let D=await Me.getProducts(e,t,H,20);D.success&&D.data?(a(D.data.data||[]),Y(D.data.pagination?.totalPages||1),ae(D.data.pagination?.totalCount||0)):(console.error("Failed to load products:",D.error),a([]),T("Failed to load products"))}catch(D){console.error("Error loading products:",D),a([]),T("Failed to load products")}finally{u(!1)}},M=async()=>{if(!c.trim()){h(o);return}try{let D=await Me.searchProducts(e,t,c);D.success&&D.data?h(D.data.data||[]):T("Search failed")}catch(D){console.error("Search error:",D),T("Search failed")}},ve=D=>{g(D),_({...D}),y(!1)},Ee=()=>{g(null),_({id:"",name:"",description:"",price:""}),v(!0),y(!0)},I=()=>{y(!0)},ne=async()=>{if(!x.id||!x.id.toString().trim()){T("Product ID is required. Please fill in the ID field.");return}if(!x.name||!x.name.toString().trim()){T("Product name is required. Please fill in the name field.");return}F(!0);try{let D;k?D=await Me.createProduct(e,t,x):D=await Me.updateProduct(e,t,x),D.success?(R(k?"Product created successfully":"Product updated successfully"),y(!1),v(!1),g(D.data?.product||x),await q()):T(`Failed to ${k?"create":"update"} product: ${D.error||"Unknown error"}`)}catch(D){T(`Failed to ${k?"create":"update"} product: ${D.message||"Unknown error"}`)}finally{F(!1)}},Fe=async()=>{if(!(!m||!m.id)&&confirm(`Are you sure you want to delete "${m.name||m.id}"?`)){V(!0);try{(await Me.deleteProduct(e,t,m.id)).success?(R("Product deleted successfully"),g(null),await q()):T("Failed to delete product")}catch(D){console.error("Delete error:",D),T("Failed to delete product")}finally{V(!1)}}},ye=()=>{y(!1),v(!1),m?_({...m}):g(null)},de=()=>{g(null),y(!1),v(!1)},ce=(D,re)=>{_(ue=>({...ue,[D]:re}))},he=()=>{let D=["id","name","description","price"],re=new Set([...D,...Object.keys(x)]);return(0,ze.jsx)("div",{className:"product-form",children:(0,ze.jsxs)("div",{className:"form-fields",children:[Array.from(re).map(ue=>(0,ze.jsxs)("div",{className:"form-group",children:[(0,ze.jsx)("label",{htmlFor:`product-${ue}`,children:ue}),(0,ze.jsx)("input",{id:`product-${ue}`,type:ue==="price"?"number":"text",value:x[ue]||"",onChange:ge=>ce(ue,ge.target.value),placeholder:`Enter ${ue}...`,disabled:O,required:ue==="id"})]},ue)),(0,ze.jsxs)("div",{className:"form-group",children:[(0,ze.jsx)("label",{htmlFor:"add-field",children:"Add Custom Field"}),(0,ze.jsxs)("div",{className:"add-field-container",children:[(0,ze.jsx)("input",{id:"add-field-key",type:"text",placeholder:"Field name",onKeyPress:ue=>{if(ue.key==="Enter"){let ge=ue.target.value.trim();ge&&!x.hasOwnProperty(ge)&&(ce(ge,""),ue.target.value="")}}}),(0,ze.jsx)("span",{className:"field-hint",children:"Press Enter to add"})]})]})]})})},Se=()=>k?he():m?b?he():(0,ze.jsx)("div",{className:"product-info",children:Object.entries(m).map(([D,re])=>(0,ze.jsxs)("div",{className:"product-field",children:[(0,ze.jsx)("div",{className:"field-label",children:D}),(0,ze.jsx)("div",{className:"field-value",children:String(re)})]},D))}):null;return s&&o.length===0?(0,ze.jsx)("div",{className:"product-management",children:(0,ze.jsx)("div",{className:"loading-container",children:(0,ze.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})}):(0,ze.jsxs)("div",{className:"product-management",children:[E&&(0,ze.jsx)("div",{className:"error-message",children:E}),N&&(0,ze.jsx)("div",{className:"success-message",children:N}),(0,ze.jsx)("div",{className:"product-content",children:m||k?Se():(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("div",{className:"product-search",children:(0,ze.jsxs)("div",{className:"search-container",children:[(0,ze.jsx)("input",{type:"text",placeholder:"Search products...",value:c,onChange:D=>d(D.target.value),className:"search-input"}),(0,ze.jsx)("button",{className:"search-button",onClick:M,children:"\u{1F50D}"})]})}),(0,ze.jsx)("div",{className:"products-list",children:p.length>0?p.map(D=>(0,ze.jsxs)("div",{className:"product-item",onClick:()=>ve(D),children:[(0,ze.jsxs)("div",{className:"product-info",children:[(0,ze.jsx)("div",{className:"product-name",children:D.name||D.id}),(0,ze.jsx)("div",{className:"product-description",children:D.description||"No description"}),(0,ze.jsxs)("div",{className:"product-meta",children:["ID: ",D.id,D.price&&(0,ze.jsxs)("span",{children:[" \u2022 Price: ",D.price]})]})]}),(0,ze.jsx)("div",{className:"product-arrow",children:"\u2192"})]},D.id)):c?(0,ze.jsxs)("div",{className:"no-products",children:[(0,ze.jsx)("div",{className:"no-products-icon",children:"\u{1F50D}"}),(0,ze.jsx)("div",{className:"no-products-text",children:"No products found"}),(0,ze.jsx)("div",{className:"no-products-subtext",children:"Try a different search term"})]}):(0,ze.jsxs)("div",{className:"no-products",children:[(0,ze.jsx)("div",{className:"no-products-icon",children:"\u{1F4E6}"}),(0,ze.jsx)("div",{className:"no-products-text",children:"No products yet"}),(0,ze.jsx)("div",{className:"no-products-subtext",children:"Create your first product to get started"})]})}),$>1&&(0,ze.jsxs)("div",{className:"product-pagination",children:[(0,ze.jsxs)("div",{className:"pagination-info",children:["Page ",H," of ",$]}),(0,ze.jsxs)("div",{className:"pagination-controls",children:[(0,ze.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.max(1,D-1)),disabled:H<=1||s,children:"\u2190"}),(0,ze.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.min($,D+1)),disabled:H>=$||s,children:"\u2192"})]})]})]})})]})}});var ln,je,s5,P9=A(()=>{"use strict";ln=Z(_e());Yn();j1();je=Z(ke()),s5=({apiKey:e,agentId:t,isProduction:n=!1,onHeaderChange:r})=>{let[o,a]=(0,ln.useState)([]),[s,u]=(0,ln.useState)(!0),[c,d]=(0,ln.useState)(""),[p,h]=(0,ln.useState)([]),[m,g]=(0,ln.useState)(null),[b,y]=(0,ln.useState)(!1),[k,v]=(0,ln.useState)(!1),[x,_]=(0,ln.useState)({}),[E,T]=(0,ln.useState)(null),[N,R]=(0,ln.useState)(null),[O,F]=(0,ln.useState)(!1),[z,V]=(0,ln.useState)(!1),[H,j]=(0,ln.useState)(1),[$,Y]=(0,ln.useState)(1),[W,ae]=(0,ln.useState)(0);(0,ln.useEffect)(()=>{X()},[m,k,b,O,z,x]),(0,ln.useEffect)(()=>{q()},[e,t,H]);let X=()=>{if(!r)return;let D;m&&!b?D=(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("button",{className:"edit-button",onClick:I,disabled:z,title:"Edit basket",children:"\u270F\uFE0F Edit"}),(0,je.jsx)("button",{className:"delete-button",onClick:Fe,disabled:z,title:"Delete basket",children:z?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):b||k?D=(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("button",{className:"cancel-button",onClick:ye,disabled:O,title:"Cancel",children:"\u2716 Cancel"}),(0,je.jsx)("button",{className:"save-button",onClick:ne,disabled:O,title:k?"Create basket":"Save changes",children:O?"\u27F3 Saving...":k?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):D=(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("button",{className:"create-button",onClick:Ee,title:"Create new basket",children:"\u2795 Add Basket"}),(0,je.jsx)("button",{className:"refresh-button",onClick:q,disabled:s,title:"Refresh baskets",children:s?"\u27F3":"\u21BB"})]}),r({title:"",actions:D})};(0,ln.useEffect)(()=>{if(c.trim()){let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)}else h(o)},[o,c]),(0,ln.useEffect)(()=>{if(E||N){let D=setTimeout(()=>{T(null),R(null)},5e3);return()=>clearTimeout(D)}},[E,N]);let q=async()=>{u(!0);try{let D=await Me.getBaskets(e,t);D.success&&D.data?(a(D.data.data||D.data||[]),ae(Array.isArray(D.data)?D.data.length:D.data.data?.length||0)):(console.error("Failed to load baskets:",D.error),a([]),T("Failed to load baskets"))}catch(D){console.error("Error loading baskets:",D),a([]),T("Failed to load baskets")}finally{u(!1)}},M=async()=>{if(!c.trim()){h(o);return}let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)},ve=D=>{g(D),_({...D}),y(!1)},Ee=()=>{g(null),_({currency:"USD",metadata:{}}),v(!0),y(!0)},I=()=>{y(!0)},ne=async()=>{if(!x.currency||!x.currency.toString().trim()){T("Currency is required. Please fill in the currency field.");return}F(!0);try{let D;k?D=await Me.createBasket(e,t,x):D=await Me.updateBasket(e,t,m.id,x),D.success?(R(k?"Basket created successfully":"Basket updated successfully"),y(!1),v(!1),g(D.data||x),await q()):T(`Failed to ${k?"create":"update"} basket: ${D.error||"Unknown error"}`)}catch(D){console.error("\u274C Save error:",D),T(`Failed to ${k?"create":"update"} product: ${D.message||"Unknown error"}`)}finally{F(!1)}},Fe=async()=>{if(!(!m||!m.id)&&confirm("Are you sure you want to delete this basket?")){V(!0);try{(await Me.deleteBasket(e,t,m.id)).success?(R("Basket deleted successfully"),g(null),await q()):T("Failed to delete basket")}catch(D){console.error("Delete error:",D),T("Failed to delete basket")}finally{V(!1)}}},ye=()=>{y(!1),v(!1),m?_({...m}):g(null)},de=()=>{g(null),y(!1),v(!1)},ce=(D,re)=>{_(ue=>({...ue,[D]:re}))},he=()=>{let D=["currency","metadata"],re=new Set([...D,...Object.keys(x)]);return(0,je.jsx)("div",{className:"product-form",children:(0,je.jsxs)("div",{className:"form-fields",children:[Array.from(re).map(ue=>(0,je.jsxs)("div",{className:"form-group",children:[(0,je.jsx)("label",{htmlFor:`product-${ue}`,children:ue}),(0,je.jsx)("input",{id:`product-${ue}`,type:ue==="price"?"number":"text",value:x[ue]||"",onChange:ge=>ce(ue,ge.target.value),placeholder:`Enter ${ue}...`,disabled:O,required:ue==="id"})]},ue)),(0,je.jsxs)("div",{className:"form-group",children:[(0,je.jsx)("label",{htmlFor:"add-field",children:"Add Custom Field"}),(0,je.jsxs)("div",{className:"add-field-container",children:[(0,je.jsx)("input",{id:"add-field-key",type:"text",placeholder:"Field name",onKeyPress:ue=>{if(ue.key==="Enter"){let ge=ue.target.value.trim();ge&&!x.hasOwnProperty(ge)&&(ce(ge,""),ue.target.value="")}}}),(0,je.jsx)("span",{className:"field-hint",children:"Press Enter to add"})]})]})]})})},Se=()=>k?he():m?b?he():(0,je.jsx)("div",{className:"product-info",children:Object.entries(m).map(([D,re])=>(0,je.jsxs)("div",{className:"product-field",children:[(0,je.jsx)("div",{className:"field-label",children:D}),(0,je.jsx)("div",{className:"field-value",children:typeof re=="object"?JSON.stringify(re,null,2):String(re)})]},D))}):null;return s&&o.length===0?(0,je.jsx)("div",{className:"product-management",children:(0,je.jsx)("div",{className:"loading-container",children:(0,je.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})}):(0,je.jsxs)("div",{className:"product-management",children:[E&&(0,je.jsx)("div",{className:"error-message",children:E}),N&&(0,je.jsx)("div",{className:"success-message",children:N}),(0,je.jsx)("div",{className:"product-content",children:m||k?Se():(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("div",{className:"product-search",children:(0,je.jsxs)("div",{className:"search-container",children:[(0,je.jsx)("input",{type:"text",placeholder:"Search baskets...",value:c,onChange:D=>d(D.target.value),className:"search-input"}),(0,je.jsx)("button",{className:"search-button",onClick:M,children:"\u{1F50D}"})]})}),(0,je.jsx)("div",{className:"products-list",children:p.length>0?p.map(D=>(0,je.jsxs)("div",{className:"product-item",onClick:()=>ve(D),children:[(0,je.jsxs)("div",{className:"product-info",children:[(0,je.jsxs)("div",{className:"product-name",children:["Basket ",D.id.substring(0,8)]}),(0,je.jsxs)("div",{className:"product-description",children:[D.status||"active"," \u2022 ",D.currency||"USD"]}),(0,je.jsxs)("div",{className:"product-meta",children:["Items: ",D.itemCount||0,D.totalAmount&&(0,je.jsxs)("span",{children:[" \u2022 Total: ",D.totalAmount]})]})]}),(0,je.jsx)("div",{className:"product-arrow",children:"\u2192"})]},D.id)):c?(0,je.jsxs)("div",{className:"no-products",children:[(0,je.jsx)("div",{className:"no-products-icon",children:"\u{1F50D}"}),(0,je.jsx)("div",{className:"no-products-text",children:"No baskets found"}),(0,je.jsx)("div",{className:"no-products-subtext",children:"Try a different search term"})]}):(0,je.jsxs)("div",{className:"no-products",children:[(0,je.jsx)("div",{className:"no-products-icon",children:"\u{1F6D2}"}),(0,je.jsx)("div",{className:"no-products-text",children:"No baskets yet"}),(0,je.jsx)("div",{className:"no-products-subtext",children:"Create your first basket to get started"})]})}),$>1&&(0,je.jsxs)("div",{className:"product-pagination",children:[(0,je.jsxs)("div",{className:"pagination-info",children:["Page ",H," of ",$]}),(0,je.jsxs)("div",{className:"pagination-controls",children:[(0,je.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.max(1,D-1)),disabled:H<=1||s,children:"\u2190"}),(0,je.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.min($,D+1)),disabled:H>=$||s,children:"\u2192"})]})]})]})})]})}});var un,Ue,l5,R9=A(()=>{"use strict";un=Z(_e());Yn();j1();Ue=Z(ke()),l5=({apiKey:e,agentId:t,isOrderion:n=!1,onHeaderChange:r})=>{let[o,a]=(0,un.useState)([]),[s,u]=(0,un.useState)(!0),[c,d]=(0,un.useState)(""),[p,h]=(0,un.useState)([]),[m,g]=(0,un.useState)(null),[b,y]=(0,un.useState)(!1),[k,v]=(0,un.useState)(!1),[x,_]=(0,un.useState)({}),[E,T]=(0,un.useState)(null),[N,R]=(0,un.useState)(null),[O,F]=(0,un.useState)(!1),[z,V]=(0,un.useState)(!1),[H,j]=(0,un.useState)(1),[$,Y]=(0,un.useState)(1),[W,ae]=(0,un.useState)(0);(0,un.useEffect)(()=>{X()},[m,k,b,O,z,x]),(0,un.useEffect)(()=>{q()},[e,t,H]);let X=()=>{if(!r)return;let D;m&&!b?D=(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("button",{className:"edit-button",onClick:I,disabled:z,title:"Edit order",children:"\u270F\uFE0F Edit"}),(0,Ue.jsx)("button",{className:"delete-button",onClick:Fe,disabled:z,title:"Delete order",children:z?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):b||k?D=(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("button",{className:"cancel-button",onClick:ye,disabled:O,title:"Cancel",children:"\u2716 Cancel"}),(0,Ue.jsx)("button",{className:"save-button",onClick:ne,disabled:O,title:k?"Create order":"Save changes",children:O?"\u27F3 Saving...":k?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):D=(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("button",{className:"create-button",onClick:Ee,title:"Create new order",children:"\u2795 Add Order"}),(0,Ue.jsx)("button",{className:"refresh-button",onClick:q,disabled:s,title:"Refresh orders",children:s?"\u27F3":"\u21BB"})]}),r({title:"",actions:D})};(0,un.useEffect)(()=>{if(c.trim()){let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)}else h(o)},[o,c]),(0,un.useEffect)(()=>{if(E||N){let D=setTimeout(()=>{T(null),R(null)},5e3);return()=>clearTimeout(D)}},[E,N]);let q=async()=>{u(!0);try{let D=await Me.getOrders(e,t);D.success&&D.data?(a(D.data.data||[]),Y(D.data.pagination?.totalPages||1),ae(D.data.pagination?.totalCount||0)):(console.error("Failed to load orders:",D.error),a([]),T("Failed to load orders"))}catch(D){console.error("Error loading orders:",D),a([]),T("Failed to load orders")}finally{u(!1)}},M=async()=>{if(!c.trim()){h(o);return}try{let D=await Me.searchOrders(e,t,c);D.success&&D.data?h(D.data.data||[]):T("Search failed")}catch(D){console.error("Search error:",D),T("Search failed")}},ve=D=>{g(D),_({...D}),y(!1)},Ee=()=>{g(null),_({basketId:"",data:{}}),v(!0),y(!0)},I=()=>{y(!0)},ne=async()=>{if(!x.basketId||!x.basketId.toString().trim()){T("Basket ID is required. Please fill in the basket ID field.");return}F(!0);try{let D;k?D=await Me.createOrder(e,t,x):D=await Me.updateOrderStatus(e,t,m.id,x.status||"pending"),D.success?(console.log("\u2705 Save successful"),R(k?"Order created successfully":"Order updated successfully"),y(!1),v(!1),g(D.data?.order||x),await q()):(console.error("\u274C Save failed:",D.error),T(`Failed to ${k?"create":"update"} order: ${D.error||"Unknown error"}`))}catch(D){console.error("\u274C Save error:",D),T(`Failed to ${k?"create":"update"} order: ${D.message||"Unknown error"}`)}finally{F(!1)}},Fe=async()=>{if(!(!m||!m.id)&&confirm(`Are you sure you want to delete "${m.name||m.id}"?`)){V(!0);try{(await Me.deleteOrder(e,t,m.id)).success?(R("Order deleted successfully"),g(null),await q()):T("Failed to delete order")}catch(D){console.error("Delete error:",D),T("Failed to delete order")}finally{V(!1)}}},ye=()=>{y(!1),v(!1),m?_({...m}):g(null)},de=()=>{g(null),y(!1),v(!1)},ce=(D,re)=>{_(ue=>({...ue,[D]:re}))},he=()=>{let D=["basketId","status","data"],re=new Set([...D,...Object.keys(x)]);return(0,Ue.jsx)("div",{className:"order-form",children:(0,Ue.jsxs)("div",{className:"form-fields",children:[Array.from(re).map(ue=>(0,Ue.jsxs)("div",{className:"form-group",children:[(0,Ue.jsx)("label",{htmlFor:`order-${ue}`,children:ue}),(0,Ue.jsx)("input",{id:`order-${ue}`,type:ue==="price"?"number":"text",value:x[ue]||"",onChange:ge=>ce(ue,ge.target.value),placeholder:`Enter ${ue}...`,disabled:O,required:ue==="id"})]},ue)),(0,Ue.jsxs)("div",{className:"form-group",children:[(0,Ue.jsx)("label",{htmlFor:"add-field",children:"Add Custom Field"}),(0,Ue.jsxs)("div",{className:"add-field-container",children:[(0,Ue.jsx)("input",{id:"add-field-key",type:"text",placeholder:"Field name",onKeyPress:ue=>{if(ue.key==="Enter"){let ge=ue.target.value.trim();ge&&!x.hasOwnProperty(ge)&&(ce(ge,""),ue.target.value="")}}}),(0,Ue.jsx)("span",{className:"field-hint",children:"Press Enter to add"})]})]})]})})},Se=()=>k?he():m?b?he():(0,Ue.jsx)("div",{className:"order-info",children:Object.entries(m).map(([D,re])=>(0,Ue.jsxs)("div",{className:"order-field",children:[(0,Ue.jsx)("div",{className:"field-label",children:D}),(0,Ue.jsx)("div",{className:"field-value",children:String(re)})]},D))}):null;return s&&o.length===0?(0,Ue.jsx)("div",{className:"order-management",children:(0,Ue.jsx)("div",{className:"loading-container",children:(0,Ue.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})}):(0,Ue.jsxs)("div",{className:"order-management",children:[E&&(0,Ue.jsx)("div",{className:"error-message",children:E}),N&&(0,Ue.jsx)("div",{className:"success-message",children:N}),(0,Ue.jsx)("div",{className:"order-content",children:m||k?Se():(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("div",{className:"order-search",children:(0,Ue.jsxs)("div",{className:"search-container",children:[(0,Ue.jsx)("input",{type:"text",placeholder:"Search orders...",value:c,onChange:D=>d(D.target.value),className:"search-input"}),(0,Ue.jsx)("button",{className:"search-button",onClick:M,children:"\u{1F50D}"})]})}),(0,Ue.jsx)("div",{className:"orders-list",children:p.length>0?p.map(D=>(0,Ue.jsxs)("div",{className:"order-item",onClick:()=>ve(D),children:[(0,Ue.jsxs)("div",{className:"order-info",children:[(0,Ue.jsx)("div",{className:"order-name",children:D.name||D.id}),(0,Ue.jsx)("div",{className:"order-description",children:D.description||"No description"}),(0,Ue.jsxs)("div",{className:"order-meta",children:["ID: ",D.id,D.price&&(0,Ue.jsxs)("span",{children:[" \u2022 Price: ",D.price]})]})]}),(0,Ue.jsx)("div",{className:"order-arrow",children:"\u2192"})]},D.id)):c?(0,Ue.jsxs)("div",{className:"no-orders",children:[(0,Ue.jsx)("div",{className:"no-orders-icon",children:"\u{1F50D}"}),(0,Ue.jsx)("div",{className:"no-orders-text",children:"No orders found"}),(0,Ue.jsx)("div",{className:"no-orders-subtext",children:"Try a different search term"})]}):(0,Ue.jsxs)("div",{className:"no-orders",children:[(0,Ue.jsx)("div",{className:"no-orders-icon",children:"\u{1F4E6}"}),(0,Ue.jsx)("div",{className:"no-orders-text",children:"No orders yet"}),(0,Ue.jsx)("div",{className:"no-orders-subtext",children:"Create your first order to get started"})]})}),$>1&&(0,Ue.jsxs)("div",{className:"order-pagination",children:[(0,Ue.jsxs)("div",{className:"pagination-info",children:["Page ",H," of ",$]}),(0,Ue.jsxs)("div",{className:"pagination-controls",children:[(0,Ue.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.max(1,D-1)),disabled:H<=1||s,children:"\u2190"}),(0,Ue.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.min($,D+1)),disabled:H>=$||s,children:"\u2192"})]})]})]})})]})}});var pL=A(()=>{});var ur,Le,u5,T9=A(()=>{"use strict";ur=Z(_e());j1();pL();Le=Z(ke()),u5=({apiKey:e,agentId:t,isProduction:n=!1,onHeaderChange:r})=>{let[o,a]=(0,ur.useState)([]),[s,u]=(0,ur.useState)(!1),[c,d]=(0,ur.useState)(null),[p,h]=(0,ur.useState)(!1),[m,g]=(0,ur.useState)(!1),[b,y]=(0,ur.useState)({collection:"",data:"{}",searchText:""}),[k,v]=(0,ur.useState)(null),[x,_]=(0,ur.useState)(null),[E,T]=(0,ur.useState)(!1),[N,R]=(0,ur.useState)(!1),[O,F]=(0,ur.useState)(""),[z,V]=(0,ur.useState)(""),[H,j]=(0,ur.useState)(!1);(0,ur.useEffect)(()=>{$()},[c,m,p,E,N,b]);let $=()=>{if(!r)return;let ne;c&&!p?ne=(0,Le.jsxs)(Le.Fragment,{children:[(0,Le.jsx)("button",{className:"edit-button",onClick:W,disabled:N,title:"Edit entry",children:"\u270F\uFE0F Edit"}),(0,Le.jsx)("button",{className:"delete-button",onClick:handleDelete,disabled:N,title:"Delete entry",children:N?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):p||m?ne=(0,Le.jsxs)(Le.Fragment,{children:[(0,Le.jsx)("button",{className:"cancel-button",onClick:X,disabled:E,title:"Cancel",children:"\u2716 Cancel"}),(0,Le.jsx)("button",{className:"save-button",onClick:ae,disabled:E,title:m?"Create entry":"Save changes",children:E?"\u27F3 Saving...":m?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):ne=(0,Le.jsx)(Le.Fragment,{children:(0,Le.jsx)("button",{className:"create-button",onClick:Y,title:"Create new entry",children:"\u2795 Add Entry"})}),r({title:"",actions:ne})},Y=()=>{d(null),y({collection:"",data:`{
102
+ `).map(o=>o.trim()).filter(o=>o&&o.startsWith("-")).map(o=>({text:o.replace(/^-[\s]?/,"").trim(),onClick:o.replace(/^-[\s]?/,"").trim()}))},cce=(0,Ze.memo)(function({onSend:e,disabled:t=!1,onFilePaste:n}){let{inputMessage:r,setInputMessage:o}=IK(),[a,s]=(0,Ze.useState)(!1),u=(0,Ze.useRef)(null);(0,Ze.useEffect)(()=>{let p=()=>{s(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))};return p(),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}},[]),(0,Ze.useEffect)(()=>{let p=u.current;p&&(t||(p.style.height="auto",p.style.height=`${p.scrollHeight}px`))},[r]);let c=p=>{if(p.key==="Enter"){if(a||p.shiftKey||p.metaKey||p.ctrlKey)return;p.preventDefault(),e()}},d=(0,Ze.useCallback)(p=>{let{items:h}=p.clipboardData;if(!h||!n)return;let m=[];for(let g=0;g<h.length;g++){let b=h[g];if(b.kind==="file"){let y=b.getAsFile();y&&m.push(y)}}m.length>0&&(p.preventDefault(),n(m))},[n]);return(0,G.jsxs)("div",{className:"lua:flex lua:gap-3 lua:py-2 lua:px-3 lua:items-start",children:[(0,G.jsx)(of,{size:32,className:"lua:w-8 lua:h-8 lua:rounded-full lua:flex-shrink-0 lua:m-1"}),(0,G.jsx)("div",{className:"lua:flex-1 lua:flex",children:(0,G.jsx)("textarea",{ref:u,disabled:t,value:r,onChange:p=>o(p.target.value),onKeyDown:c,onPaste:d,placeholder:t?"This conversation's chat window has already been closed":"Reply to user",className:`lua:w-full lua:pl-0 lua:pr-4 lua:py-2 lua:resize-none lua:overflow-y-auto lua:border-none lua:focus:outline-none lua:focus:ring-0 lua:text-gray-700 lua:min-h-10 lua:max-h-48 lua:bg-white${t?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})})});var Ct,Je,x9,Me,Yn=A(()=>{"use strict";Ct={LUA_API:"https://api.heylua.ai",CHAT_API:"https://api.heylua.ai",DEV_SERVER:"https://api.heylua.ai",LOCAL_DEV:""},Je={CHAT_GENERATE:e=>`${Ct.CHAT_API}/chat/generate/${e}?channel=dev`,TOOLS_TEST:e=>`${Ct.LUA_API}/tools/test/${e}`,CHAT_HISTORY:e=>`${Ct.LUA_API}/chat/history/${e}`,AGENT_TYPES:`${Ct.LUA_API}/agents/self-serve/types`,CREATE_AGENT:`${Ct.LUA_API}/agents/self-serve/create`,AGENT_DETAILS:e=>`${Ct.LUA_API}/admin/agents/${e}`,SKILL_VERSIONS:(e,t)=>`${Ct.DEV_SERVER}/developer/skills/${e}/${t}/versions`,PERSONA_VERSIONS:e=>`${Ct.LUA_API}/developer/agents/${e}/persona/versions`,DEPLOY_PERSONA_VERSION:(e,t)=>`${Ct.LUA_API}/developer/agents/${e}/persona/version/${t}`,AGENT_RESOURCES:e=>`${Ct.LUA_API}/admin/agents/${e}/resources`,AGENT_RESOURCE:(e,t)=>`${Ct.LUA_API}/admin/agents/${e}/resources/${t}`,AGENT_SKILLS:e=>`${Ct.LUA_API}/developer/skills/${e}`,ACTIVATE_SKILL:(e,t)=>`${Ct.LUA_API}/developer/skills/${e}/${t}`,PUBLISH_SKILL_VERSION:(e,t,n)=>`${Ct.LUA_API}/developer/skills/${e}/${t}/${n}/publish`,PRODUCTION_LOGS:e=>`${Ct.LUA_API}/developer/agents/${e}/logs`,PRODUCTION_ENV:e=>`${Ct.LUA_API}/developer/agents/${e}/env`,AGENT_PRODUCTS:e=>`${Ct.LOCAL_DEV}/api/products`,AGENT_PRODUCT:(e,t)=>`${Ct.LOCAL_DEV}/api/products/${t}`,SEARCH_PRODUCTS:e=>`${Ct.LOCAL_DEV}/api/products/search`,AGENT_BASKETS:e=>`${Ct.LOCAL_DEV}/api/baskets`,AGENT_BASKET:(e,t)=>`${Ct.LOCAL_DEV}/api/baskets/${t}`,AGENT_ORDERS:e=>`${Ct.LOCAL_DEV}/api/orders`,AGENT_ORDER:(e,t)=>`${Ct.LOCAL_DEV}/api/orders/${t}`,CREATE_SKILL:e=>`${Ct.DEV_SERVER}/developer/skills/${e}`,DEVELOPER_LOGS:(e,t)=>`${Ct.DEV_SERVER}/developer/skills/${e}/${t}/logs`,USER_DATA:e=>`${Ct.DEV_SERVER}/developer/user/data/agent/${e}`,LOCAL_CHAT:`${Ct.LOCAL_DEV}/chat`,LOCAL_PERSONA:`${Ct.LOCAL_DEV}/persona`,LOCAL_TOOLS:`${Ct.LOCAL_DEV}/tools`,LOCAL_TOOLS_TEST:`${Ct.LOCAL_DEV}/tools/test`,LOCAL_ENV:`${Ct.LOCAL_DEV}/env`},x9=class{constructor(t=""){this.baseUrl=t}async getAllSkillOverrides(){try{let n=await(await fetch("/api/skills")).json();return n.success&&n.skills&&Array.isArray(n.skills)?n.skills.map(r=>({skillId:r.skillId,sandboxId:r.sandboxId||r.skillId})).filter(r=>r.skillId&&r.sandboxId):[]}catch(t){return console.error("Error getting skill overrides:",t),[]}}async sendChatMessage(t,n,r,o,a,s){try{let u=await this.getAllSkillOverrides(),c=u.length>0?u:[{skillId:r,sandboxId:o}],d={messages:[{type:"text",text:t}],navigate:!0,skillOverride:c,...s&&{personaOverride:s}},p=await fetch(Je.CHAT_GENERATE(n),{method:"POST",headers:{"Content-Type":"application/json",Authorization:a},body:JSON.stringify(d)});if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return{success:!0,text:(await p.json()).text||"No response received"}}catch(u){return console.error("Chat API error:",u),{success:!1,error:u instanceof Error?u.message:"Unknown error occurred"}}}async sendProductionChatMessage(t,n,r){try{let o={messages:[{type:"text",text:t}],navigate:!0,skillOverride:[]},a=await fetch(Je.CHAT_GENERATE(n),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify(o)});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,text:(await a.json()).text||"No response received"}}catch(o){return console.error("Production chat API error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async sendLocalChatMessage(t,n){try{let r=await fetch(Je.LOCAL_CHAT,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,persona:n})});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return await r.json()}catch(r){return console.error("Local chat API error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async loadPersona(){try{let t=await fetch(Je.LOCAL_PERSONA);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){return console.error("Load persona error:",t),{success:!1,error:t instanceof Error?t.message:"Failed to load persona"}}}async savePersona(t){try{let n=await fetch(Je.LOCAL_PERSONA,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({persona:t})});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Save persona error:",n),{success:!1,error:n instanceof Error?n.message:"Failed to save persona"}}}async loadTools(){try{let t=await fetch(Je.LOCAL_TOOLS);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){return console.error("Load tools error:",t),{success:!1,error:t instanceof Error?t.message:"Failed to load tools"}}}async testTool(t,n,r,o,a,s){try{let u={toolName:t,inputs:n,skillOverride:[{skillId:o,sandboxId:a}]},c=await fetch(Je.TOOLS_TEST(r),{method:"POST",headers:{"Content-Type":"application/json",Authorization:s},body:JSON.stringify(u)});if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);let d=await c.json();return{success:!0,result:d.result||d}}catch(u){return console.error("Tool test error:",u),{success:!1,error:u instanceof Error?u.message:"Unknown error occurred"}}}async getSkillVersions(t,n,r){try{let o=await fetch(Je.SKILL_VERSIONS(n,t),{method:"GET",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,versions:(await o.json()).versions||[]}}catch(o){return console.error("Error fetching skill versions:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getPersonaVersions(t,n){try{let r=await fetch(`${Ct.DEV_SERVER}/developer/agents/${t}/persona/versions`,{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"}});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return{success:!0,versions:(await r.json()).versions||[]}}catch(r){return console.error("Error fetching persona versions:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async getProductionPersonaVersions(t,n){try{let r=await fetch(Je.PERSONA_VERSIONS(t),{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"}});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return{success:!0,versions:(await r.json()).versions||[]}}catch(r){return console.error("Error fetching production persona versions:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async deployPersonaVersion(t,n,r){try{let o=await fetch(Je.DEPLOY_PERSONA_VERSION(t,r),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({})});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("Error deploying persona version:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createPersonaVersion(t,n,r){try{let o=await fetch(`${Ct.DEV_SERVER}/developer/agents/${t}/persona/version`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({persona:r})});if(!o.ok){let s=await o.text();throw new Error(`HTTP error! status: ${o.status}, message: ${s}`)}return{success:!0,data:await o.json()}}catch(o){return console.error("Error creating persona version:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createSkillVersion(t,n,r,o){try{let a=await fetch(`${Ct.DEV_SERVER}/developer/skills/${n}/${t}/version`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok){let u=await a.text();throw new Error(`HTTP error! status: ${a.status}, message: ${u}`)}return{success:!0,data:await a.json()}}catch(a){return console.error("Error creating skill version:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadEnvContent(){try{let t=await fetch(Je.LOCAL_ENV);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){return console.error("Load env error:",t),{success:!1,error:t instanceof Error?t.message:"Failed to load environment variables"}}}async saveEnvContent(t){try{let n=await fetch(Je.LOCAL_ENV,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Save env error:",n),{success:!1,error:n instanceof Error?n.message:"Failed to save environment variables"}}}async testLocalTool(t,n){try{let r=await fetch(Je.LOCAL_TOOLS_TEST,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({toolName:t,inputs:n})});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return await r.json()}catch(r){return console.error("Local tool test error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async loadChatHistory(t,n){try{console.log("ApiService: Loading chat history with API key:",t,"agentId:",n);let r=await fetch(Je.CHAT_HISTORY(n),{method:"GET",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Response status:",r.status),console.log("ApiService: Response headers:",r.headers),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Received data:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: Chat history load error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async clearChatHistory(t,n){try{console.log("ApiService: Clearing chat history with API key:",t,"agentId:",n);let r=await fetch(Je.CHAT_HISTORY(n),{method:"DELETE",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return{success:!0}}catch(r){return console.error("Clear chat history error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async clearSandboxLogs(t,n,r){try{console.log("ApiService: Clearing sandbox logs with API key:",t,"agentId:",n,"sandboxId:",r);let o=await fetch(Je.DEVELOPER_LOGS(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Clear logs response status:",o.status),!o.ok){let s=await o.text();throw console.error("ApiService: HTTP error response:",s),new Error(`HTTP error! status: ${o.status}`)}let a=await o.json();return console.log("ApiService: Clear logs response:",a),{success:!0,data:a}}catch(o){return console.error("ApiService: Clear sandbox logs error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async loadAllSandboxLogs(t,n,r=20){try{let o=await this.getAllSkillOverrides();if(o.length===0)return{success:!0,data:{logs:[]}};let a=o.map(async c=>{try{let d=await this.loadSandboxLogs(t,n,c.sandboxId,r);return d.success&&d.data&&d.data.logs?d.data.logs.map(p=>({...p,skillName:c.skillId,sandboxId:c.sandboxId})):[]}catch(d){return console.error(`Error loading logs for skill ${c.skillId}:`,d),[]}});return{success:!0,data:{logs:(await Promise.all(a)).flat().sort((c,d)=>new Date(d.timestamp).getTime()-new Date(c.timestamp).getTime()).slice(0,r)}}}catch(o){return console.error("Error loading all sandbox logs:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred",data:{logs:[]}}}}async loadSandboxLogs(t,n,r,o=20){try{console.log("ApiService: Loading sandbox logs with API key:",t,"agentId:",n,"sandboxId:",r);let a=await fetch(`${Je.DEVELOPER_LOGS(n,r)}?limit=${o}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Logs response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Received logs data:",s),{success:!0,data:s}}catch(a){return console.error("ApiService: Sandbox logs load error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadUserData(t,n){try{console.log("ApiService: Loading user data with API key:",t,"agentId:",n),console.log("ApiService: API key length:",t?.length),console.log("ApiService: API key starts with:",t?.substring(0,10));let r=await fetch(Je.USER_DATA(n),{method:"GET",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(console.log("ApiService: User data response status:",r.status),console.log("ApiService: Response headers:",Object.fromEntries(r.headers.entries())),!r.ok){let a=await r.text();if(console.error("ApiService: HTTP error response:",a),r.status===401){console.log("ApiService: Trying alternative authentication method...");let s=await fetch(Je.USER_DATA(n),{method:"GET",headers:{accept:"*/*",Authorization:t}});if(s.ok){let u=await s.json();return console.log("ApiService: Alternative auth successful:",u),{success:!0,data:u}}}throw new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Received user data:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: User data load error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async saveUserData(t,n,r){return this.updateUserData(t,n,r)}async getUserData(t,n){return this.loadUserData(t,n)}async updateUserData(t,n,r){try{console.log("ApiService: Updating user data with API key:",t,"agentId:",n,"data:",r);let o=await fetch(Je.USER_DATA(n),{method:"PUT",headers:{accept:"*/*",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(console.log("ApiService: Update user data response status:",o.status),!o.ok){let s=await o.text();throw console.error("ApiService: HTTP error response:",s),new Error(`HTTP error! status: ${o.status}`)}let a=await o.json();return console.log("ApiService: Updated user data response:",a),{success:!0,data:a}}catch(o){return console.error("ApiService: Update user data error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async loadResources(t,n){try{console.log("ApiService: Loading resources with API key:",t,"agentId:",n);let r=await fetch(Je.AGENT_RESOURCES(n),{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Resources response status:",r.status),!r.ok)throw new Error(`HTTP error! status: ${r.status}`);let o=await r.json();return console.log("ApiService: Resources data:",o),{success:!0,data:o||[]}}catch(r){return console.error("ApiService: Error loading resources:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async createResource(t,n,r){try{let o=await fetch(Je.AGENT_RESOURCES(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("Error creating resource:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateResource(t,n,r,o){try{let a=await fetch(Je.AGENT_RESOURCE(n,r),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return console.error("Error updating resource:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async deleteResource(t,n,r){try{let o=await fetch(Je.AGENT_RESOURCE(n,r),{method:"DELETE",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0}}catch(o){return console.error("Error deleting resource:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async clearUserData(t,n){try{console.log("ApiService: Clearing user data with API key:",t,"agentId:",n);let r=await fetch(Je.USER_DATA(n),{method:"DELETE",headers:{accept:"*/*",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Clear user data response status:",r.status),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Clear user data response:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: Clear user data error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async createSkill(t,n,r){try{let o=await fetch(Je.CREATE_SKILL(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({name:r.name,description:r.description||`A Lua skill for ${r.name}`,context:r.context||""})});if(!o.ok){let s=await o.text();return{success:!1,error:{message:`HTTP ${o.status}: ${s}`}}}return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:{message:o instanceof Error?o.message:"Unknown error"}}}}async getAgentTypes(t){try{let n=await fetch(Je.AGENT_TYPES,{method:"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Error fetching agent types:",n),[]}}async createAgent(t,n){try{let r=await fetch(Je.CREATE_AGENT,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(n)});return r.ok?{success:!0,data:await r.json()}:{success:!1,error:await r.json()}}catch(r){return{success:!1,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async getAgentDetails(t,n){try{let r=await fetch(Je.AGENT_DETAILS(n),{method:"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});return r.ok?{success:!0,data:await r.json()}:{success:!1,error:await r.json()}}catch(r){return{success:!1,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async getSkills(t,n){try{console.log("ApiService: Loading skills with API key:",t,"agentId:",n);let r=await fetch(Je.AGENT_SKILLS(n),{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Skills response status:",r.status),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Received skills data:",o),{success:!0,skills:o.skills||[]}}catch(r){return console.error("ApiService: Skills load error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async activateSkill(t,n,r,o){try{console.log(`ApiService: ${o?"Activating":"Deactivating"} skill:`,r,"for agent:",n);let a=await fetch(Je.ACTIVATE_SKILL(n,r),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({active:o})});if(console.log("ApiService: Activate skill response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Activate skill response:",s),{success:!0,data:s}}catch(a){return console.error("ApiService: Activate skill error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async publishSkillVersion(t,n,r,o){try{console.log("ApiService: Publishing skill version:",o,"for skill:",r,"agent:",n);let a=await fetch(Je.PUBLISH_SKILL_VERSION(n,r,o),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Publish skill version response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Publish skill version response:",s),{success:!0,data:s}}catch(a){return console.error("ApiService: Publish skill version error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadProductionLogs(t,n,r=1,o=100){try{console.log("ApiService: Loading production logs with API key:",t,"agentId:",n,"page:",r,"limit:",o);let a=await fetch(`${Je.PRODUCTION_LOGS(n)}?page=${r}&limit=${o}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Production logs response status:",a.status),!a.ok){let u=await a.text();throw console.error("ApiService: HTTP error response:",u),new Error(`HTTP error! status: ${a.status}`)}let s=await a.json();return console.log("ApiService: Production logs response:",s),{success:!0,logs:s.logs||[],pagination:s.pagination}}catch(a){return console.error("ApiService: Production logs error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async loadProductionEnv(t,n){try{console.log("ApiService: Loading production env with API key:",t,"agentId:",n);let r=await fetch(Je.PRODUCTION_ENV(n),{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(console.log("ApiService: Production env response status:",r.status),!r.ok){let a=await r.text();throw console.error("ApiService: HTTP error response:",a),new Error(`HTTP error! status: ${r.status}`)}let o=await r.json();return console.log("ApiService: Production env response:",o),{success:!0,data:o}}catch(r){return console.error("ApiService: Production env error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error occurred"}}}async updateProductionEnv(t,n,r){try{console.log("ApiService: Updating production env with API key:",t,"agentId:",n,"data:",r);let o=await fetch(Je.PRODUCTION_ENV(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(console.log("ApiService: Update production env response status:",o.status),!o.ok){let s=await o.text();throw console.error("ApiService: HTTP error response:",s),new Error(`HTTP error! status: ${o.status}`)}let a=await o.json();return console.log("ApiService: Update production env response:",a),{success:!0,data:a}}catch(o){return console.error("ApiService: Update production env error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getProducts(t,n,r=1,o=20){try{console.log("ApiService: Loading products with API key:",t,"agentId:",n);let a=await fetch(`${Je.AGENT_PRODUCTS(n)}?page=${r}&limit=${o}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return console.error("ApiService: Products load error:",a),{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async createProduct(t,n,r){try{let o=await fetch(Je.AGENT_PRODUCTS(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Create product error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateProduct(t,n,r){try{let o=await fetch(Je.AGENT_PRODUCTS(n),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Update product error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async deleteProduct(t,n,r){try{let o=await fetch(Je.AGENT_PRODUCT(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Delete product error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async searchProducts(t,n,r){try{let o=await fetch(`${Je.SEARCH_PRODUCTS(n)}?searchQuery=${encodeURIComponent(r)}`,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return console.error("ApiService: Search products error:",o),{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getBaskets(t,n,r){try{let o=r?`${Je.AGENT_BASKETS(n)}?status=${r}`:Je.AGENT_BASKETS(n),a=await fetch(o,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createBasket(t,n,r){try{let o=await fetch(Je.AGENT_BASKETS(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateBasket(t,n,r,o){try{let a=await fetch(Je.AGENT_BASKET(n,r),{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async deleteBasket(t,n,r){try{let o=await fetch(Je.AGENT_BASKET(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async getOrders(t,n,r){try{let o=r?`${Je.AGENT_ORDERS(n)}?status=${r}`:Je.AGENT_ORDERS(n),a=await fetch(o,{method:"GET",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async createOrder(t,n,r){try{let o=await fetch(Je.AGENT_ORDERS(n),{method:"POST",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}async updateOrderStatus(t,n,r,o){try{let a=await fetch(`${Je.AGENT_ORDER(n,r)}/status`,{method:"PUT",headers:{accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({status:o})});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return{success:!0,data:await a.json()}}catch(a){return{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}async deleteOrder(t,n,r){try{let o=await fetch(Je.AGENT_ORDER(n,r),{method:"DELETE",headers:{accept:"application/json",Authorization:`Bearer ${t}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return{success:!0,data:await o.json()}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}}},Me=new x9});var Va,i5,b9=A(()=>{"use strict";o5();Va=Z(ke()),i5=({messages:e,isLoading:t,onActionClick:n,className:r="chat-messages",ariaLabel:o="Chat messages"})=>{let a=e.map(s=>({id:s.id,role:s.sender,content:s.text,type:"text",createdAt:s.timestamp.toISOString()}));return console.log("luaMessages",a),(0,Va.jsx)("div",{className:`${r} lua:relative lua:bg-gray-100`,role:"log","aria-live":"polite","aria-label":o,tabIndex:0,children:(0,Va.jsxs)("div",{className:"lua:bg-white lua:p-3 lua:rounded-lg lua:space-y-4 lua:flex lua:flex-col",children:[a.map(s=>{let u=dL(s.content);return(0,Va.jsxs)("div",{children:[(0,Va.jsx)(oL,{message:s,onSelect:n}),u.length>0&&(0,Va.jsx)(cL,{buttons:u,onClick:n})]},s.id)}),t&&(0,Va.jsx)(uL,{})]})})}});var $s,Pn,OK,_9,fL=A(()=>{"use strict";$s=Z(_e());o5();Yn();b9();Pn=Z(ke()),OK=({apiKey:e,agentId:t,skillId:n,sandboxId:r,persona:o,sharedChatMessages:a,onSharedSendMessage:s,onSharedClearHistory:u,isChatLoading:c,setIsChatLoading:d})=>{let{messages:p,setMessages:h}=z1(),[m,g]=(0,$s.useState)(""),b=(0,$s.useRef)(null),y=()=>{b.current?.scrollIntoView({behavior:"smooth"})};(0,$s.useEffect)(()=>{y()},[p]),(0,$s.useEffect)(()=>{if(a.length===0){let E={id:"welcome",role:"assistant",content:"\u{1F44B} Welcome! Start chatting to test your Lua skill. Your messages will be sent to the sandbox environment.",type:"text",createdAt:new Date().toISOString()};h([E])}},[a,h]);let k=E=>{v(E)},v=async E=>{if(!E.trim())return;let T={id:Date.now().toString(),text:E,sender:"user",timestamp:new Date};s(T),g(""),d(!0);try{let N=await Me.sendLocalChatMessage(E,o),R={id:(Date.now()+1).toString(),text:N.success?N.text||"No response received":`\u274C ${N.error||"Failed to send message"}`,sender:"assistant",timestamp:new Date};s(R)}catch(N){let R={id:(Date.now()+2).toString(),text:`\u274C Error: ${N instanceof Error?N.message:"Unknown error"}`,sender:"assistant",timestamp:new Date};s(R)}finally{d(!1)}};return(0,Pn.jsxs)("section",{className:"chat-container",role:"region","aria-label":"Chat interface",children:[(0,Pn.jsxs)("header",{className:"chat-header lua:bg-white lua:border-b",children:[(0,Pn.jsx)("div",{className:"chat-header-content",children:(0,Pn.jsxs)("div",{children:[(0,Pn.jsx)("h2",{children:"Chat to your Agent [Sandbox]"}),(0,Pn.jsx)("p",{className:"lua:text-gray-700",children:"Test your sandbox skill in real-time"})]})}),(0,Pn.jsx)("button",{className:"clear-chat-button",onClick:u,disabled:c,title:"Clear chat history","aria-label":"Clear chat history",children:"\u{1F5D1}\uFE0F"})]}),(0,Pn.jsx)(i5,{messages:a,isLoading:c,onActionClick:k,ariaLabel:"Chat messages"}),(0,Pn.jsx)("div",{ref:b}),(0,Pn.jsx)("div",{className:"chat-input-container",children:(0,Pn.jsxs)("form",{className:"chat-input-form",onSubmit:E=>{E.preventDefault(),v(m)},role:"form","aria-label":"Send message",children:[(0,Pn.jsx)("label",{htmlFor:"chat-input",className:"sr-only",children:"Type your message"}),(0,Pn.jsx)("input",{type:"text",id:"chat-input",name:"chatMessage",className:"chat-input",value:m,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&(E.preventDefault(),v(m))},placeholder:"Type your message...",disabled:c,autoComplete:"off","aria-describedby":"chat-input-help"}),(0,Pn.jsx)("div",{id:"chat-input-help",className:"sr-only",children:"Press Enter to send, Shift+Enter for new line"}),(0,Pn.jsx)("button",{type:"submit",className:"send-button",disabled:c||!m.trim(),"aria-label":c?"Sending message...":"Send message",children:c?"Sending...":"Send"})]})})]})},_9=e=>(0,Pn.jsx)(r5,{children:(0,Pn.jsx)(OK,{...e})})});var No,Oe,k9,S9=A(()=>{"use strict";No=Z(_e());sr();Yn();Oe=Z(ke()),k9=({persona:e,onSavePersona:t,apiKey:n,agentId:r})=>{let[o,a]=(0,No.useState)(e),[s,u]=(0,No.useState)(!1),[c,d]=(0,No.useState)([]),[p,h]=(0,No.useState)(!1),[m,g]=(0,No.useState)("current"),[b,y]=(0,No.useState)(null),[k,v]=(0,No.useState)(!1),[x,_]=(0,No.useState)(!1);(0,No.useEffect)(()=>{a(e)},[e]),(0,No.useEffect)(()=>{E()},[]);let E=async()=>{h(!0);try{let H=await Me.getPersonaVersions(r,n);if(H.success&&H.versions){let j=H.versions.sort(($,Y)=>Y.createdDate-$.createdDate);d(j)}else console.error("Failed to load persona versions:",H.error),d([])}catch(H){console.error("Error loading persona versions:",H),d([])}finally{h(!1)}},T=H=>{g(H),b&&y(null)},N=H=>{y(H)},R=()=>{y(null)},O=()=>{if(!o.trim()){alert("Please enter a persona before creating a version");return}_(!0)},F=async()=>{v(!0);try{let H=await Me.createPersonaVersion(r,n,o.trim());if(H.success)console.log("\u2705 Persona version created successfully:",H.data),await E(),g("versions"),alert("\u2705 Persona version created successfully! You can deploy it from the Production tab.");else throw new Error(H.error||"Failed to create persona version")}catch(H){console.error("\u274C Error creating persona version:",H),alert(`\u274C Failed to create persona version: ${H instanceof Error?H.message:"Unknown error"}`)}finally{v(!1),_(!1)}},z=()=>{_(!1)},V=async()=>{let H=o.trim();if(!H){alert("Persona cannot be empty");return}u(!0);try{await t(H)&&a(H)}finally{u(!1)}};return b?(0,Oe.jsxs)("div",{className:"lua:space-y-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2",children:[(0,Oe.jsx)(qe,{variant:"tertiary",size:"small",onClick:R,"aria-label":"Back to versions",children:"\u2190 Back"}),(0,Oe.jsxs)("h3",{className:"lua:text-lg lua:font-semibold lua:text-gray-900",children:["Persona v",b.version]}),b.isCurrent?(0,Oe.jsx)(Qr,{variant:"secondary",children:"Active (Deployed)"}):(0,Oe.jsx)(Qr,{children:"Available"})]}),(0,Oe.jsxs)(bt,{className:"lua:p-4 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:[(0,Oe.jsxs)("div",{className:"lua:grid lua:grid-cols-1 md:lua:grid-cols-3 lua:gap-4 lua:mb-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-500",children:"Created By"}),(0,Oe.jsx)("span",{className:"lua:text-sm lua:text-gray-900",children:b.createdBy})]}),(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-500",children:"Status"}),(0,Oe.jsx)("span",{className:"lua:text-sm lua:text-gray-900",children:b.isCurrent?"Active (Deployed)":"Available"})]}),(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-500",children:"Created Date"}),(0,Oe.jsx)("span",{className:"lua:text-sm lua:text-gray-900",children:new Date(b.createdDate).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"})})]})]}),(0,Oe.jsxs)("div",{children:[(0,Oe.jsx)("h4",{className:"lua:text-base lua:font-medium lua:text-gray-900 lua:mb-2",children:"Persona Content"}),(0,Oe.jsx)(bt,{className:"lua:p-3 lua:bg-gray-50 lua:border lua:border-gray-200 lua:text-sm lua:text-gray-900 lua:whitespace-pre-wrap",children:b.persona})]})]})]}):(0,Oe.jsxs)("div",{className:"lua:pb-24",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:justify-between lua:pb-2 lua:px-5 lua:py-4 lua:border-b lua:border-gray-200",children:[(0,Oe.jsx)("h3",{className:"lua:text-lg lua:font-semibold lua:text-gray-900",children:"Agent Persona"}),(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2",children:[(0,Oe.jsx)(qe,{variant:"primary",size:"small",onClick:O,disabled:k||!o.trim(),"aria-label":"Create new persona version",children:k?"Creating...":"Create Version"}),(0,Oe.jsx)(qe,{variant:"secondary",size:"small",onClick:V,disabled:s,"aria-label":"Save persona to YAML",children:s?"Saving\u2026":"Save"})]})]}),(0,Oe.jsxs)("div",{className:"lua:px-5 lua:py-4 lua:px-5 lua:py-4 lua:space-y-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2 ",children:[(0,Oe.jsx)(qe,{variant:m==="current"?"primary":"secondary",size:"small",onClick:()=>T("current"),children:"Current"}),(0,Oe.jsxs)(qe,{variant:m==="versions"?"primary":"secondary",size:"small",onClick:()=>T("versions"),children:["Versions (",c.length,")"]})]}),m==="current"?(0,Oe.jsx)("div",{children:(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-3",children:[(0,Oe.jsx)("h4",{className:"lua:text-base lua:font-medium lua:text-gray-900",children:"Edit Current Persona"}),(0,Oe.jsx)(au,{value:o,onChange:H=>a(H.target.value),placeholder:"Enter agent persona...",className:"lua:min-h-48"}),(0,Oe.jsxs)("div",{className:"lua:-mx-4 lua:px-4 lua:mt-3 lua:py-2 lua:bg-gray-50 lua:border-t lua:border-gray-200 lua:rounded-b-lg lua:text-sm lua:text-gray-700 lua:sticky lua:bottom-0",children:["This persona is stored in your ",(0,Oe.jsx)("code",{children:"lua.skill.yaml"})," file and used for local development."]})]})}):(0,Oe.jsx)(bt,{className:"lua:p-0 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:p?(0,Oe.jsx)("div",{className:"lua:p-6 lua:flex lua:items-center lua:justify-center",children:(0,Oe.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"lua:h-6 lua:opacity-60"})}):c.length>0?(0,Oe.jsx)("div",{className:"lua:divide-y lua:divide-gray-200",children:c.map((H,j)=>(0,Oe.jsxs)("button",{className:"lua:w-full lua:text-left lua:p-3 lua:flex lua:items-center lua:justify-between hover:lua:bg-gray-50",onClick:()=>N(H),children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:flex-col lua:gap-1",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:gap-2",children:[(0,Oe.jsxs)("span",{className:"lua:text-sm lua:font-medium lua:text-gray-900",children:["v",H.version]}),(0,Oe.jsx)(Qr,{variant:H.isCurrent?"secondary":"default",children:H.isCurrent?"Active":"Available"})]}),(0,Oe.jsx)("span",{className:"lua:text-xs lua:text-gray-600",children:new Date(H.createdDate).toLocaleDateString()})]}),(0,Oe.jsx)("span",{className:"lua:text-gray-400",children:"\u2192"})]},j))}):(0,Oe.jsxs)("div",{className:"lua:p-8 lua:text-center",children:[(0,Oe.jsx)("div",{className:"lua:text-3xl lua:mb-2",children:"\u{1F464}"}),(0,Oe.jsx)("div",{className:"lua:text-base lua:font-medium lua:text-gray-900",children:"No persona versions found"}),(0,Oe.jsx)("div",{className:"lua:text-sm lua:text-gray-600",children:"Persona versions will appear here when available"})]})}),x&&(0,Oe.jsx)("div",{className:"lua:fixed lua:inset-0 lua:bg-black/30 lua:flex lua:items-center lua:justify-center",children:(0,Oe.jsxs)("div",{className:"lua:bg-white lua:rounded-lg lua:shadow-lg lua:border lua:border-gray-200 lua:w-full lua:max-w-lg lua:p-4",children:[(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:justify-between lua:mb-2",children:[(0,Oe.jsx)("h3",{className:"lua:text-base lua:font-semibold lua:text-gray-900",children:"Create Persona Version"}),(0,Oe.jsx)(qe,{variant:"tertiary",size:"small",onClick:z,"aria-label":"Close",children:"\u2715"})]}),(0,Oe.jsxs)("div",{className:"lua:space-y-3",children:[(0,Oe.jsx)("p",{className:"lua:text-sm lua:text-gray-700",children:"This will create a new persona version that can be deployed to production."}),(0,Oe.jsxs)("p",{className:"lua:text-sm lua:text-gray-700",children:[(0,Oe.jsx)("strong",{children:"Note:"})," The version will be created but not automatically released. You can deploy it from the Production tab."]}),(0,Oe.jsxs)("div",{className:"lua:space-y-2",children:[(0,Oe.jsx)("h4",{className:"lua:text-sm lua:font-medium lua:text-gray-900",children:"Persona Content:"}),(0,Oe.jsxs)(bt,{className:"lua:p-3 lua:bg-gray-50 lua:border lua:border-gray-200 lua:text-sm lua:text-gray-900",children:[o.substring(0,300),o.length>300?"...":""]})]})]}),(0,Oe.jsxs)("div",{className:"lua:flex lua:items-center lua:justify-end lua:gap-2 lua:mt-4",children:[(0,Oe.jsx)(qe,{variant:"tertiary",onClick:z,disabled:k,children:"Cancel"}),(0,Oe.jsx)(qe,{variant:"primary",onClick:F,disabled:k,children:k?"Creating...":"Create Version"})]})]})})]})]})}});var Bn,Q,E9,N9=A(()=>{"use strict";Bn=Z(_e());Yn();Q=Z(ke()),E9=({apiKey:e,agentId:t,skillId:n,sandboxId:r})=>{let[o,a]=(0,Bn.useState)([]),[s,u]=(0,Bn.useState)(null),[c,d]=(0,Bn.useState)(null),[p,h]=(0,Bn.useState)([]),[m,g]=(0,Bn.useState)(!1),[b,y]=(0,Bn.useState)("current"),[k,v]=(0,Bn.useState)(!1),[x,_]=(0,Bn.useState)(!1),[E,T]=(0,Bn.useState)(""),[N,R]=(0,Bn.useState)({}),[O,F]=(0,Bn.useState)(null),[z,V]=(0,Bn.useState)(!0),[H,j]=(0,Bn.useState)(!1),[$,Y]=(0,Bn.useState)(null),[W,ae]=(0,Bn.useState)([]);(0,Bn.useEffect)(()=>{X(),q()},[]);let X=async()=>{V(!0),Y(null);try{console.log("Loading skills from /api/skills...");let J=await fetch("/api/skills");if(console.log("Skills API response status:",J.status),!J.ok)throw new Error(`HTTP ${J.status}: ${J.statusText}`);let le=await J.json();console.log("Skills API response data:",le),le.success&&le.skills&&Array.isArray(le.skills)?(console.log("Skills loaded successfully:",le.skills),a(le.skills),Y(null)):(console.error("Failed to load skills:",le.error),Y(le.error||"Failed to load skills - invalid data format"),a([]))}catch(J){console.error("Error loading skills:",J),Y(J instanceof Error?J.message:"Failed to load skills"),a([])}finally{V(!1)}},q=async()=>{try{let le=await(await fetch("/tools")).json();if(le.success&&le.tools){let oe=[];Array.isArray(le.tools)?oe=le.tools:typeof le.tools=="object"&&(oe=Object.entries(le.tools).map(([xe,Ge])=>({name:xe,...Ge}))),ae(oe)}else console.error("Failed to load tools:",le.error),ae([])}catch(J){console.error("Error loading tools:",J),ae([])}},M=J=>{let le={};J.inputSchema.properties&&Object.keys(J.inputSchema.properties).forEach(oe=>{let xe=J.inputSchema.properties[oe];le[oe]=ve(xe)}),R(le)},ve=J=>{if(J.type==="object"&&J.properties){let le={};return Object.keys(J.properties).forEach(oe=>{le[oe]=ve(J.properties[oe])}),le}else return J.type==="number"?0:J.type==="boolean"?!1:""},Ee=J=>{let le=W.find(oe=>oe.name===J);le&&(d(le),M(le),F(null))},I=async J=>{g(!0);try{let le=await Me.getSkillVersions(J.skillId,t,e);if(le.success&&le.versions){let oe=le.versions.sort((xe,Ge)=>new Date(Ge.createdDate||Ge.createdAt).getTime()-new Date(xe.createdDate||xe.createdAt).getTime());h(oe)}else console.error("Failed to load skill versions:",le.error),h([])}catch(le){console.error("Error loading skill versions:",le),h([])}finally{g(!1)}},ne=J=>{let le=o.find(oe=>oe.name===J);le&&(u(J),y("current"),I(le))},Fe=()=>{u(null),y("current"),h([]),d(null),F(null)},ye=J=>{y(J),c&&(d(null),F(null))},de=()=>{d(null),F(null)},ce=async()=>{if(!s)return;let J=o.find(oe=>oe.name===s);if(!J)return;p.some(oe=>oe.version===J.version)?(T(J.version),_(!0)):await he(J.version)},he=async J=>{if(!s)return;let le=o.find(oe=>oe.name===s);if(le){v(!0);try{let xe=await(await fetch("/tools")).json();if(!xe.success||!xe.tools)throw new Error("Failed to load current tools data");let Ge=[];Array.isArray(xe.tools)?Ge=xe.tools:typeof xe.tools=="object"&&(Ge=Object.entries(xe.tools).map(([Qt,pn])=>({name:Qt,description:pn.description||"",inputSchema:pn.inputSchema||{type:"object"},execute:pn.execute||""})));let vt=Ge.filter(Qt=>le.tools.includes(Qt.name)),Et={name:le.name,version:J,description:le.description,context:le.context,tools:vt};console.log("Creating version with data:",Et);let fn=await Me.createSkillVersion(le.skillId,t,e,Et);if(fn.success)console.log("\u2705 Version created successfully:",fn.data),await I(le),alert(`\u2705 Version ${J} created successfully!`);else throw new Error(fn.error||"Failed to create version")}catch(oe){console.error("\u274C Error creating version:",oe),alert(`\u274C Failed to create version: ${oe instanceof Error?oe.message:"Unknown error"}`)}finally{v(!1),_(!1)}}},Se=async()=>{if(!E.trim()){alert("Please enter a version number");return}if(p.some(le=>le.version===E.trim())){alert("This version already exists. Please enter a different version number.");return}await he(E.trim())},D=()=>{_(!1),T("")},re=(J,le,oe)=>{R(xe=>oe?{...xe,[J]:{...xe[J],[oe]:le}}:{...xe,[J]:le})},ue=async()=>{if(c){j(!0),F(null);try{let J=ge(N,c.inputSchema),le=await Me.testLocalTool(c.name,J);F(le)}catch(J){F({success:!1,error:J instanceof Error?J.message:"Unknown error occurred"})}finally{j(!1)}}},ge=(J,le)=>{let oe={};for(let[xe,Ge]of Object.entries(J))if(Ge&&typeof Ge=="object"&&!Array.isArray(Ge)){let vt=le.properties?.[xe];if(vt&&vt.type==="object"&&vt.properties){let Et=ge(Ge,vt);Object.keys(Et).length>0&&(oe[xe]=Et)}else oe[xe]=Ge}else{let vt=le.properties?.[xe];if((!le.required||!le.required.includes(xe))&&(Ge===""||Ge===null||Ge===void 0))continue;oe[xe]=Ge}return oe},se=(J,le,oe)=>{let xe=oe?N[J]?.[oe]||"":N[J]||"",Ge=oe?le.required?.includes(oe):c?.inputSchema.required?.includes(J);if(le.type==="object"&&le.properties)return(0,Q.jsxs)("div",{className:"nested-object",children:[(0,Q.jsx)("div",{className:"nested-object-label",children:J}),(0,Q.jsx)("div",{className:"nested-fields",children:Object.entries(le.properties).map(([vt,Et])=>(0,Q.jsxs)("div",{className:"nested-field",children:[(0,Q.jsxs)("label",{className:"nested-label",children:[vt,le.required?.includes(vt)&&(0,Q.jsx)("span",{className:"required",children:"*"})]}),se(J,Et,vt),Et.description&&(0,Q.jsx)("div",{className:"input-description",children:Et.description})]},vt))})]});switch(le.type){case"number":return(0,Q.jsx)("input",{type:"number",value:xe,onChange:vt=>re(J,parseFloat(vt.target.value)||0,oe),placeholder:le.description||`Enter ${oe||J}`,className:"tool-input",required:Ge});case"boolean":return(0,Q.jsx)("input",{type:"checkbox",checked:xe,onChange:vt=>re(J,vt.target.checked,oe),className:"tool-checkbox"});case"string":default:return(0,Q.jsx)("input",{type:"text",value:xe,onChange:vt=>re(J,vt.target.value,oe),placeholder:le.description||`Enter ${oe||J}`,className:"tool-input",required:Ge})}};if(z)return(0,Q.jsx)("div",{className:"skills-page",children:(0,Q.jsx)("div",{className:"skills-loading",children:(0,Q.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})});if(c)return(0,Q.jsx)("div",{className:"skills-page",children:(0,Q.jsxs)("div",{className:"tool-form",children:[(0,Q.jsxs)("div",{className:"tool-form-header",children:[(0,Q.jsx)("button",{className:"back-button",onClick:de,title:"Back to skill",children:"\u2190"}),(0,Q.jsx)("h3",{children:c.name})]}),(0,Q.jsxs)("div",{className:"tool-form-content",children:[(0,Q.jsx)("div",{className:"tool-info",children:(0,Q.jsx)("p",{children:c.description})}),(0,Q.jsxs)("div",{className:"tool-inputs",children:[(0,Q.jsx)("h4",{children:"Input Parameters"}),Object.keys(c.inputSchema.properties||{}).length>0?(0,Q.jsx)("div",{className:"input-fields",children:Object.entries(c.inputSchema.properties).map(([J,le])=>(0,Q.jsxs)("div",{className:"input-field",children:[(0,Q.jsxs)("label",{children:[J,c.inputSchema.required?.includes(J)&&(0,Q.jsx)("span",{className:"required",children:"*"})]}),se(J,le),le.description&&(0,Q.jsx)("div",{className:"input-description",children:le.description})]},J))}):(0,Q.jsx)("p",{className:"no-inputs",children:"This tool requires no input parameters."})]}),(0,Q.jsx)("div",{className:"tool-actions",children:(0,Q.jsx)("button",{onClick:ue,disabled:H,className:"test-button",children:H?"Testing...":"Test Tool"})}),O&&(0,Q.jsxs)("div",{className:"test-result",children:[(0,Q.jsx)("h4",{children:"Test Result"}),(0,Q.jsx)("div",{className:`result-content ${O.success?"success":"error"}`,children:O.success?(0,Q.jsxs)("div",{children:[(0,Q.jsx)("div",{className:"result-label",children:"\u2705 Success"}),(0,Q.jsx)("pre",{className:"result-data",children:JSON.stringify(O.result,null,2)})]}):(0,Q.jsxs)("div",{children:[(0,Q.jsx)("div",{className:"result-label",children:"\u274C Error"}),(0,Q.jsx)("div",{className:"result-error",children:O.error})]})})]})]})]})});if(s){let J=o.find(le=>le.name===s);return J?(0,Q.jsxs)("div",{className:"skills-page",children:[(0,Q.jsxs)("div",{className:"skills-header",children:[(0,Q.jsxs)("div",{className:"header-left",children:[(0,Q.jsx)("button",{className:"back-button",onClick:Fe,children:"\u2190"}),(0,Q.jsx)("h4",{children:J.name})]}),(0,Q.jsx)("button",{className:"create-version-button",onClick:ce,disabled:k,title:"Create new version",children:k?"Creating...":"Create Version"})]}),(0,Q.jsxs)("div",{className:"skill-tabs",children:[(0,Q.jsxs)("div",{className:"tabs-header",children:[(0,Q.jsx)("button",{className:`tab-button ${b==="current"?"active":""}`,onClick:()=>ye("current"),children:"Current"}),(0,Q.jsxs)("button",{className:`tab-button ${b==="versions"?"active":""}`,onClick:()=>ye("versions"),children:["Versions (",p.length,")"]})]}),(0,Q.jsx)("div",{className:"tab-content",children:b==="current"?(0,Q.jsxs)("div",{className:"current-skill-tab",children:[(0,Q.jsx)("div",{className:"skill-details",children:(0,Q.jsxs)("div",{className:"skill-info-section",children:[(0,Q.jsxs)("div",{className:"skill-meta",children:[(0,Q.jsxs)("span",{className:"skill-version",children:["v",J.version]}),(0,Q.jsxs)("span",{className:"skill-tools-count",children:[J.tools.length," tools"]})]}),J.description&&(0,Q.jsxs)("div",{className:"skill-description-section",children:[(0,Q.jsx)("h5",{children:"Description"}),(0,Q.jsx)("p",{children:J.description})]}),J.context&&(0,Q.jsxs)("div",{className:"skill-context-section",children:[(0,Q.jsx)("h5",{children:"Context"}),(0,Q.jsx)("p",{children:J.context})]})]})}),(0,Q.jsxs)("div",{className:"tools-section",children:[(0,Q.jsx)("div",{className:"tools-header",children:(0,Q.jsxs)("h5",{children:["Available Tools (",J.tools.length,")"]})}),J.tools&&J.tools.length>0?(0,Q.jsx)("div",{className:"tools-grid",children:J.tools.map((le,oe)=>(0,Q.jsxs)("div",{className:"tool-card",onClick:()=>Ee(le),children:[(0,Q.jsx)("div",{className:"tool-card-header",children:(0,Q.jsx)("h4",{children:le})}),(0,Q.jsx)("div",{className:"tool-card-body",children:(0,Q.jsx)("span",{className:"skill-badge",children:J.name})})]},oe))}):(0,Q.jsxs)("div",{className:"no-tools",children:[(0,Q.jsx)("div",{className:"no-tools-icon",children:"\u{1F527}"}),(0,Q.jsx)("div",{className:"no-tools-text",children:"No tools in this skill"}),(0,Q.jsx)("div",{className:"no-tools-subtext",children:"This skill doesn't have any tools defined"})]})]}),(0,Q.jsx)("div",{className:"skills-help",children:(0,Q.jsx)("p",{children:"This skill is compiled from your local code and updates automatically when you make changes. Use the tools above to test your skill's functionality."})})]}):(0,Q.jsx)("div",{className:"versions-skill-tab",children:m?(0,Q.jsx)("div",{className:"versions-loading",children:(0,Q.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})}):p.length>0?(0,Q.jsx)("div",{className:"versions-list",children:p.map((le,oe)=>(0,Q.jsxs)("div",{className:`version-item ${le.status}`,onClick:()=>{console.log("Selected version:",le.version)},children:[(0,Q.jsxs)("div",{className:"version-info",children:[(0,Q.jsxs)("div",{className:"version-header",children:[(0,Q.jsxs)("span",{className:"version-number",children:["v",le.version]}),(0,Q.jsx)("span",{className:`version-status ${le.status}`,children:le.status})]}),(0,Q.jsxs)("div",{className:"version-meta",children:[(0,Q.jsx)("span",{className:"version-date",children:new Date(le.createdDate||le.createdAt).toLocaleDateString()}),(0,Q.jsxs)("span",{className:"version-author",children:["by ",le.createdByEmail||le.createdBy]})]})]}),(0,Q.jsx)("div",{className:"version-arrow",children:"\u2192"})]},oe))}):(0,Q.jsxs)("div",{className:"no-versions",children:[(0,Q.jsx)("div",{className:"no-versions-icon",children:"\u{1F4E6}"}),(0,Q.jsx)("div",{className:"no-versions-text",children:"No versions found"}),(0,Q.jsx)("div",{className:"no-versions-subtext",children:"Create your first version to get started"})]})})})]}),x&&(0,Q.jsx)("div",{className:"version-modal-overlay",children:(0,Q.jsxs)("div",{className:"version-modal",children:[(0,Q.jsx)("div",{className:"version-modal-header",children:(0,Q.jsx)("h3",{children:"Create New Version"})}),(0,Q.jsxs)("div",{className:"version-modal-body",children:[(0,Q.jsxs)("p",{children:["Version ",(0,Q.jsx)("strong",{children:o.find(le=>le.name===s)?.version})," already exists."]}),(0,Q.jsx)("p",{children:"Please enter a new version number:"}),(0,Q.jsx)("input",{type:"text",value:E,onChange:le=>T(le.target.value),placeholder:"e.g., 1.0.1",className:"version-input",autoFocus:!0})]}),(0,Q.jsxs)("div",{className:"version-modal-actions",children:[(0,Q.jsx)("button",{className:"cancel-button",onClick:D,disabled:k,children:"Cancel"}),(0,Q.jsx)("button",{className:"create-button",onClick:Se,disabled:k||!E.trim(),children:k?"Creating...":"Create Version"})]})]})})]}):(0,Q.jsxs)("div",{className:"skills-page",children:[(0,Q.jsx)("div",{className:"skills-header",children:(0,Q.jsxs)("div",{className:"header-left",children:[(0,Q.jsx)("button",{className:"back-button",onClick:Fe,children:"\u2190"}),(0,Q.jsx)("h4",{children:"Skill Not Found"})]})}),(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u274C"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"Skill not found"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:"The selected skill could not be loaded"})]})]})}return(0,Q.jsxs)("div",{className:"skills-page",children:[(0,Q.jsxs)("div",{className:"skills-header",children:[(0,Q.jsx)("h3",{children:"Available Skills"}),(0,Q.jsx)("button",{className:"refresh-button",onClick:X,title:"Refresh skills",children:"\u21BB"})]}),(0,Q.jsx)("div",{className:"skills-content",children:$?(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u274C"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"Error loading skills"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:$}),(0,Q.jsx)("button",{className:"retry-button",onClick:X,style:{marginTop:"16px"},children:"Retry"})]}):o.length===0?(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u2699\uFE0F"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"No skills found"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:"Skills will appear here when available in your project"})]}):Array.isArray(o)&&o.length>0?(0,Q.jsx)("div",{className:"skills-list",children:o.map(J=>(0,Q.jsxs)("div",{className:"skill-item",onClick:()=>ne(J.name),children:[(0,Q.jsxs)("div",{className:"skill-info",children:[(0,Q.jsx)("div",{className:"skill-name",children:J.name}),(0,Q.jsx)("div",{className:"skill-description",children:J.description}),(0,Q.jsxs)("div",{className:"skill-stats",children:[(0,Q.jsxs)("span",{className:"skill-stat",children:["v",J.version]}),(0,Q.jsxs)("span",{className:"skill-stat",children:[J.tools.length," tools"]})]})]}),(0,Q.jsx)("div",{className:"skill-arrow",children:"\u2192"})]},J.name))}):(0,Q.jsxs)("div",{className:"no-skills",children:[(0,Q.jsx)("div",{className:"no-skills-icon",children:"\u2699\uFE0F"}),(0,Q.jsx)("div",{className:"no-skills-text",children:"No skills available"}),(0,Q.jsx)("div",{className:"no-skills-subtext",children:"No valid skills data received"})]})})]})}});var j1=A(()=>{});var sn,ze,U1,a5=A(()=>{"use strict";sn=Z(_e());Yn();j1();ze=Z(ke()),U1=({apiKey:e,agentId:t,isProduction:n=!1,onHeaderChange:r})=>{let[o,a]=(0,sn.useState)([]),[s,u]=(0,sn.useState)(!0),[c,d]=(0,sn.useState)(""),[p,h]=(0,sn.useState)([]),[m,g]=(0,sn.useState)(null),[b,y]=(0,sn.useState)(!1),[k,v]=(0,sn.useState)(!1),[x,_]=(0,sn.useState)({}),[E,T]=(0,sn.useState)(null),[N,R]=(0,sn.useState)(null),[O,F]=(0,sn.useState)(!1),[z,V]=(0,sn.useState)(!1),[H,j]=(0,sn.useState)(1),[$,Y]=(0,sn.useState)(1),[W,ae]=(0,sn.useState)(0);(0,sn.useEffect)(()=>{X()},[m,k,b,O,z,x]),(0,sn.useEffect)(()=>{q()},[e,t,H]);let X=()=>{if(!r)return;let D;m&&!b?D=(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("button",{className:"edit-button",onClick:I,disabled:z,title:"Edit product",children:"\u270F\uFE0F Edit"}),(0,ze.jsx)("button",{className:"delete-button",onClick:Fe,disabled:z,title:"Delete product",children:z?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):b||k?D=(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("button",{className:"cancel-button",onClick:ye,disabled:O,title:"Cancel",children:"\u2716 Cancel"}),(0,ze.jsx)("button",{className:"save-button",onClick:ne,disabled:O,title:k?"Create product":"Save changes",children:O?"\u27F3 Saving...":k?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):D=(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("button",{className:"create-button",onClick:Ee,title:"Create new product",children:"\u2795 Add Product"}),(0,ze.jsx)("button",{className:"refresh-button",onClick:q,disabled:s,title:"Refresh products",children:s?"\u27F3":"\u21BB"})]}),r({title:"",actions:D})};(0,sn.useEffect)(()=>{if(c.trim()){let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)}else h(o)},[o,c]),(0,sn.useEffect)(()=>{if(E||N){let D=setTimeout(()=>{T(null),R(null)},5e3);return()=>clearTimeout(D)}},[E,N]);let q=async()=>{u(!0);try{let D=await Me.getProducts(e,t,H,20);D.success&&D.data?(a(D.data.data||[]),Y(D.data.pagination?.totalPages||1),ae(D.data.pagination?.totalCount||0)):(console.error("Failed to load products:",D.error),a([]),T("Failed to load products"))}catch(D){console.error("Error loading products:",D),a([]),T("Failed to load products")}finally{u(!1)}},M=async()=>{if(!c.trim()){h(o);return}try{let D=await Me.searchProducts(e,t,c);D.success&&D.data?h(D.data.data||[]):T("Search failed")}catch(D){console.error("Search error:",D),T("Search failed")}},ve=D=>{g(D),_({...D}),y(!1)},Ee=()=>{g(null),_({id:"",name:"",description:"",price:""}),v(!0),y(!0)},I=()=>{y(!0)},ne=async()=>{if(!x.id||!x.id.toString().trim()){T("Product ID is required. Please fill in the ID field.");return}if(!x.name||!x.name.toString().trim()){T("Product name is required. Please fill in the name field.");return}F(!0);try{let D;k?D=await Me.createProduct(e,t,x):D=await Me.updateProduct(e,t,x),D.success?(R(k?"Product created successfully":"Product updated successfully"),y(!1),v(!1),g(D.data?.product||x),await q()):T(`Failed to ${k?"create":"update"} product: ${D.error||"Unknown error"}`)}catch(D){T(`Failed to ${k?"create":"update"} product: ${D.message||"Unknown error"}`)}finally{F(!1)}},Fe=async()=>{if(!(!m||!m.id)&&confirm(`Are you sure you want to delete "${m.name||m.id}"?`)){V(!0);try{(await Me.deleteProduct(e,t,m.id)).success?(R("Product deleted successfully"),g(null),await q()):T("Failed to delete product")}catch(D){console.error("Delete error:",D),T("Failed to delete product")}finally{V(!1)}}},ye=()=>{y(!1),v(!1),m?_({...m}):g(null)},de=()=>{g(null),y(!1),v(!1)},ce=(D,re)=>{_(ue=>({...ue,[D]:re}))},he=()=>{let D=["id","name","description","price"],re=new Set([...D,...Object.keys(x)]);return(0,ze.jsx)("div",{className:"product-form",children:(0,ze.jsxs)("div",{className:"form-fields",children:[Array.from(re).map(ue=>(0,ze.jsxs)("div",{className:"form-group",children:[(0,ze.jsx)("label",{htmlFor:`product-${ue}`,children:ue}),(0,ze.jsx)("input",{id:`product-${ue}`,type:ue==="price"?"number":"text",value:x[ue]||"",onChange:ge=>ce(ue,ge.target.value),placeholder:`Enter ${ue}...`,disabled:O,required:ue==="id"})]},ue)),(0,ze.jsxs)("div",{className:"form-group",children:[(0,ze.jsx)("label",{htmlFor:"add-field",children:"Add Custom Field"}),(0,ze.jsxs)("div",{className:"add-field-container",children:[(0,ze.jsx)("input",{id:"add-field-key",type:"text",placeholder:"Field name",onKeyPress:ue=>{if(ue.key==="Enter"){let ge=ue.target.value.trim();ge&&!x.hasOwnProperty(ge)&&(ce(ge,""),ue.target.value="")}}}),(0,ze.jsx)("span",{className:"field-hint",children:"Press Enter to add"})]})]})]})})},Se=()=>k?he():m?b?he():(0,ze.jsx)("div",{className:"product-info",children:Object.entries(m).map(([D,re])=>(0,ze.jsxs)("div",{className:"product-field",children:[(0,ze.jsx)("div",{className:"field-label",children:D}),(0,ze.jsx)("div",{className:"field-value",children:String(re)})]},D))}):null;return s&&o.length===0?(0,ze.jsx)("div",{className:"product-management",children:(0,ze.jsx)("div",{className:"loading-container",children:(0,ze.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})}):(0,ze.jsxs)("div",{className:"product-management",children:[E&&(0,ze.jsx)("div",{className:"error-message",children:E}),N&&(0,ze.jsx)("div",{className:"success-message",children:N}),(0,ze.jsx)("div",{className:"product-content",children:m||k?Se():(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("div",{className:"product-search",children:(0,ze.jsxs)("div",{className:"search-container",children:[(0,ze.jsx)("input",{type:"text",placeholder:"Search products...",value:c,onChange:D=>d(D.target.value),className:"search-input"}),(0,ze.jsx)("button",{className:"search-button",onClick:M,children:"\u{1F50D}"})]})}),(0,ze.jsx)("div",{className:"products-list",children:p.length>0?p.map(D=>(0,ze.jsxs)("div",{className:"product-item",onClick:()=>ve(D),children:[(0,ze.jsxs)("div",{className:"product-info",children:[(0,ze.jsx)("div",{className:"product-name",children:D.name||D.id}),(0,ze.jsx)("div",{className:"product-description",children:D.description||"No description"}),(0,ze.jsxs)("div",{className:"product-meta",children:["ID: ",D.id,D.price&&(0,ze.jsxs)("span",{children:[" \u2022 Price: ",D.price]})]})]}),(0,ze.jsx)("div",{className:"product-arrow",children:"\u2192"})]},D.id)):c?(0,ze.jsxs)("div",{className:"no-products",children:[(0,ze.jsx)("div",{className:"no-products-icon",children:"\u{1F50D}"}),(0,ze.jsx)("div",{className:"no-products-text",children:"No products found"}),(0,ze.jsx)("div",{className:"no-products-subtext",children:"Try a different search term"})]}):(0,ze.jsxs)("div",{className:"no-products",children:[(0,ze.jsx)("div",{className:"no-products-icon",children:"\u{1F4E6}"}),(0,ze.jsx)("div",{className:"no-products-text",children:"No products yet"}),(0,ze.jsx)("div",{className:"no-products-subtext",children:"Create your first product to get started"})]})}),$>1&&(0,ze.jsxs)("div",{className:"product-pagination",children:[(0,ze.jsxs)("div",{className:"pagination-info",children:["Page ",H," of ",$]}),(0,ze.jsxs)("div",{className:"pagination-controls",children:[(0,ze.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.max(1,D-1)),disabled:H<=1||s,children:"\u2190"}),(0,ze.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.min($,D+1)),disabled:H>=$||s,children:"\u2192"})]})]})]})})]})}});var ln,je,s5,P9=A(()=>{"use strict";ln=Z(_e());Yn();j1();je=Z(ke()),s5=({apiKey:e,agentId:t,isProduction:n=!1,onHeaderChange:r})=>{let[o,a]=(0,ln.useState)([]),[s,u]=(0,ln.useState)(!0),[c,d]=(0,ln.useState)(""),[p,h]=(0,ln.useState)([]),[m,g]=(0,ln.useState)(null),[b,y]=(0,ln.useState)(!1),[k,v]=(0,ln.useState)(!1),[x,_]=(0,ln.useState)({}),[E,T]=(0,ln.useState)(null),[N,R]=(0,ln.useState)(null),[O,F]=(0,ln.useState)(!1),[z,V]=(0,ln.useState)(!1),[H,j]=(0,ln.useState)(1),[$,Y]=(0,ln.useState)(1),[W,ae]=(0,ln.useState)(0);(0,ln.useEffect)(()=>{X()},[m,k,b,O,z,x]),(0,ln.useEffect)(()=>{q()},[e,t,H]);let X=()=>{if(!r)return;let D;m&&!b?D=(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("button",{className:"edit-button",onClick:I,disabled:z,title:"Edit basket",children:"\u270F\uFE0F Edit"}),(0,je.jsx)("button",{className:"delete-button",onClick:Fe,disabled:z,title:"Delete basket",children:z?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):b||k?D=(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("button",{className:"cancel-button",onClick:ye,disabled:O,title:"Cancel",children:"\u2716 Cancel"}),(0,je.jsx)("button",{className:"save-button",onClick:ne,disabled:O,title:k?"Create basket":"Save changes",children:O?"\u27F3 Saving...":k?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):D=(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("button",{className:"create-button",onClick:Ee,title:"Create new basket",children:"\u2795 Add Basket"}),(0,je.jsx)("button",{className:"refresh-button",onClick:q,disabled:s,title:"Refresh baskets",children:s?"\u27F3":"\u21BB"})]}),r({title:"",actions:D})};(0,ln.useEffect)(()=>{if(c.trim()){let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)}else h(o)},[o,c]),(0,ln.useEffect)(()=>{if(E||N){let D=setTimeout(()=>{T(null),R(null)},5e3);return()=>clearTimeout(D)}},[E,N]);let q=async()=>{u(!0);try{let D=await Me.getBaskets(e,t);D.success&&D.data?(a(D.data.data||D.data||[]),ae(Array.isArray(D.data)?D.data.length:D.data.data?.length||0)):(console.error("Failed to load baskets:",D.error),a([]),T("Failed to load baskets"))}catch(D){console.error("Error loading baskets:",D),a([]),T("Failed to load baskets")}finally{u(!1)}},M=async()=>{if(!c.trim()){h(o);return}let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)},ve=D=>{g(D),_({...D}),y(!1)},Ee=()=>{g(null),_({currency:"USD",metadata:{}}),v(!0),y(!0)},I=()=>{y(!0)},ne=async()=>{if(!x.currency||!x.currency.toString().trim()){T("Currency is required. Please fill in the currency field.");return}F(!0);try{let D;k?D=await Me.createBasket(e,t,x):D=await Me.updateBasket(e,t,m.id,x),D.success?(R(k?"Basket created successfully":"Basket updated successfully"),y(!1),v(!1),g(D.data||x),await q()):T(`Failed to ${k?"create":"update"} basket: ${D.error||"Unknown error"}`)}catch(D){console.error("\u274C Save error:",D),T(`Failed to ${k?"create":"update"} product: ${D.message||"Unknown error"}`)}finally{F(!1)}},Fe=async()=>{if(!(!m||!m.id)&&confirm("Are you sure you want to delete this basket?")){V(!0);try{(await Me.deleteBasket(e,t,m.id)).success?(R("Basket deleted successfully"),g(null),await q()):T("Failed to delete basket")}catch(D){console.error("Delete error:",D),T("Failed to delete basket")}finally{V(!1)}}},ye=()=>{y(!1),v(!1),m?_({...m}):g(null)},de=()=>{g(null),y(!1),v(!1)},ce=(D,re)=>{_(ue=>({...ue,[D]:re}))},he=()=>{let D=["currency","metadata"],re=new Set([...D,...Object.keys(x)]);return(0,je.jsx)("div",{className:"product-form",children:(0,je.jsxs)("div",{className:"form-fields",children:[Array.from(re).map(ue=>(0,je.jsxs)("div",{className:"form-group",children:[(0,je.jsx)("label",{htmlFor:`product-${ue}`,children:ue}),(0,je.jsx)("input",{id:`product-${ue}`,type:ue==="price"?"number":"text",value:x[ue]||"",onChange:ge=>ce(ue,ge.target.value),placeholder:`Enter ${ue}...`,disabled:O,required:ue==="id"})]},ue)),(0,je.jsxs)("div",{className:"form-group",children:[(0,je.jsx)("label",{htmlFor:"add-field",children:"Add Custom Field"}),(0,je.jsxs)("div",{className:"add-field-container",children:[(0,je.jsx)("input",{id:"add-field-key",type:"text",placeholder:"Field name",onKeyPress:ue=>{if(ue.key==="Enter"){let ge=ue.target.value.trim();ge&&!x.hasOwnProperty(ge)&&(ce(ge,""),ue.target.value="")}}}),(0,je.jsx)("span",{className:"field-hint",children:"Press Enter to add"})]})]})]})})},Se=()=>k?he():m?b?he():(0,je.jsx)("div",{className:"product-info",children:Object.entries(m).map(([D,re])=>(0,je.jsxs)("div",{className:"product-field",children:[(0,je.jsx)("div",{className:"field-label",children:D}),(0,je.jsx)("div",{className:"field-value",children:typeof re=="object"?JSON.stringify(re,null,2):String(re)})]},D))}):null;return s&&o.length===0?(0,je.jsx)("div",{className:"product-management",children:(0,je.jsx)("div",{className:"loading-container",children:(0,je.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})}):(0,je.jsxs)("div",{className:"product-management",children:[E&&(0,je.jsx)("div",{className:"error-message",children:E}),N&&(0,je.jsx)("div",{className:"success-message",children:N}),(0,je.jsx)("div",{className:"product-content",children:m||k?Se():(0,je.jsxs)(je.Fragment,{children:[(0,je.jsx)("div",{className:"product-search",children:(0,je.jsxs)("div",{className:"search-container",children:[(0,je.jsx)("input",{type:"text",placeholder:"Search baskets...",value:c,onChange:D=>d(D.target.value),className:"search-input"}),(0,je.jsx)("button",{className:"search-button",onClick:M,children:"\u{1F50D}"})]})}),(0,je.jsx)("div",{className:"products-list",children:p.length>0?p.map(D=>(0,je.jsxs)("div",{className:"product-item",onClick:()=>ve(D),children:[(0,je.jsxs)("div",{className:"product-info",children:[(0,je.jsxs)("div",{className:"product-name",children:["Basket ",D.id.substring(0,8)]}),(0,je.jsxs)("div",{className:"product-description",children:[D.status||"active"," \u2022 ",D.currency||"USD"]}),(0,je.jsxs)("div",{className:"product-meta",children:["Items: ",D.itemCount||0,D.totalAmount&&(0,je.jsxs)("span",{children:[" \u2022 Total: ",D.totalAmount]})]})]}),(0,je.jsx)("div",{className:"product-arrow",children:"\u2192"})]},D.id)):c?(0,je.jsxs)("div",{className:"no-products",children:[(0,je.jsx)("div",{className:"no-products-icon",children:"\u{1F50D}"}),(0,je.jsx)("div",{className:"no-products-text",children:"No baskets found"}),(0,je.jsx)("div",{className:"no-products-subtext",children:"Try a different search term"})]}):(0,je.jsxs)("div",{className:"no-products",children:[(0,je.jsx)("div",{className:"no-products-icon",children:"\u{1F6D2}"}),(0,je.jsx)("div",{className:"no-products-text",children:"No baskets yet"}),(0,je.jsx)("div",{className:"no-products-subtext",children:"Create your first basket to get started"})]})}),$>1&&(0,je.jsxs)("div",{className:"product-pagination",children:[(0,je.jsxs)("div",{className:"pagination-info",children:["Page ",H," of ",$]}),(0,je.jsxs)("div",{className:"pagination-controls",children:[(0,je.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.max(1,D-1)),disabled:H<=1||s,children:"\u2190"}),(0,je.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.min($,D+1)),disabled:H>=$||s,children:"\u2192"})]})]})]})})]})}});var un,Ue,l5,R9=A(()=>{"use strict";un=Z(_e());Yn();j1();Ue=Z(ke()),l5=({apiKey:e,agentId:t,isOrderion:n=!1,onHeaderChange:r})=>{let[o,a]=(0,un.useState)([]),[s,u]=(0,un.useState)(!0),[c,d]=(0,un.useState)(""),[p,h]=(0,un.useState)([]),[m,g]=(0,un.useState)(null),[b,y]=(0,un.useState)(!1),[k,v]=(0,un.useState)(!1),[x,_]=(0,un.useState)({}),[E,T]=(0,un.useState)(null),[N,R]=(0,un.useState)(null),[O,F]=(0,un.useState)(!1),[z,V]=(0,un.useState)(!1),[H,j]=(0,un.useState)(1),[$,Y]=(0,un.useState)(1),[W,ae]=(0,un.useState)(0);(0,un.useEffect)(()=>{X()},[m,k,b,O,z,x]),(0,un.useEffect)(()=>{q()},[e,t,H]);let X=()=>{if(!r)return;let D;m&&!b?D=(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("button",{className:"edit-button",onClick:I,disabled:z,title:"Edit order",children:"\u270F\uFE0F Edit"}),(0,Ue.jsx)("button",{className:"delete-button",onClick:Fe,disabled:z,title:"Delete order",children:z?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):b||k?D=(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("button",{className:"cancel-button",onClick:ye,disabled:O,title:"Cancel",children:"\u2716 Cancel"}),(0,Ue.jsx)("button",{className:"save-button",onClick:ne,disabled:O,title:k?"Create order":"Save changes",children:O?"\u27F3 Saving...":k?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):D=(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("button",{className:"create-button",onClick:Ee,title:"Create new order",children:"\u2795 Add Order"}),(0,Ue.jsx)("button",{className:"refresh-button",onClick:q,disabled:s,title:"Refresh orders",children:s?"\u27F3":"\u21BB"})]}),r({title:"",actions:D})};(0,un.useEffect)(()=>{if(c.trim()){let D=o.filter(re=>Object.values(re).some(ue=>String(ue).toLowerCase().includes(c.toLowerCase())));h(D)}else h(o)},[o,c]),(0,un.useEffect)(()=>{if(E||N){let D=setTimeout(()=>{T(null),R(null)},5e3);return()=>clearTimeout(D)}},[E,N]);let q=async()=>{u(!0);try{let D=await Me.getOrders(e,t);D.success&&D.data?(a(D.data.data||[]),Y(D.data.pagination?.totalPages||1),ae(D.data.pagination?.totalCount||0)):(console.error("Failed to load orders:",D.error),a([]),T("Failed to load orders"))}catch(D){console.error("Error loading orders:",D),a([]),T("Failed to load orders")}finally{u(!1)}},M=async()=>{if(!c.trim()){h(o);return}try{let D=await Me.searchOrders(e,t,c);D.success&&D.data?h(D.data.data||[]):T("Search failed")}catch(D){console.error("Search error:",D),T("Search failed")}},ve=D=>{g(D),_({...D}),y(!1)},Ee=()=>{g(null),_({basketId:"",data:{}}),v(!0),y(!0)},I=()=>{y(!0)},ne=async()=>{if(!x.basketId||!x.basketId.toString().trim()){T("Basket ID is required. Please fill in the basket ID field.");return}F(!0);try{let D;k?D=await Me.createOrder(e,t,x):D=await Me.updateOrderStatus(e,t,m.id,x.status||"pending"),D.success?(console.log("\u2705 Save successful"),R(k?"Order created successfully":"Order updated successfully"),y(!1),v(!1),g(D.data?.order||x),await q()):(console.error("\u274C Save failed:",D.error),T(`Failed to ${k?"create":"update"} order: ${D.error||"Unknown error"}`))}catch(D){console.error("\u274C Save error:",D),T(`Failed to ${k?"create":"update"} order: ${D.message||"Unknown error"}`)}finally{F(!1)}},Fe=async()=>{if(!(!m||!m.id)&&confirm(`Are you sure you want to delete "${m.name||m.id}"?`)){V(!0);try{(await Me.deleteOrder(e,t,m.id)).success?(R("Order deleted successfully"),g(null),await q()):T("Failed to delete order")}catch(D){console.error("Delete error:",D),T("Failed to delete order")}finally{V(!1)}}},ye=()=>{y(!1),v(!1),m?_({...m}):g(null)},de=()=>{g(null),y(!1),v(!1)},ce=(D,re)=>{_(ue=>({...ue,[D]:re}))},he=()=>{let D=["basketId","status","data"],re=new Set([...D,...Object.keys(x)]);return(0,Ue.jsx)("div",{className:"order-form",children:(0,Ue.jsxs)("div",{className:"form-fields",children:[Array.from(re).map(ue=>(0,Ue.jsxs)("div",{className:"form-group",children:[(0,Ue.jsx)("label",{htmlFor:`order-${ue}`,children:ue}),(0,Ue.jsx)("input",{id:`order-${ue}`,type:ue==="price"?"number":"text",value:x[ue]||"",onChange:ge=>ce(ue,ge.target.value),placeholder:`Enter ${ue}...`,disabled:O,required:ue==="id"})]},ue)),(0,Ue.jsxs)("div",{className:"form-group",children:[(0,Ue.jsx)("label",{htmlFor:"add-field",children:"Add Custom Field"}),(0,Ue.jsxs)("div",{className:"add-field-container",children:[(0,Ue.jsx)("input",{id:"add-field-key",type:"text",placeholder:"Field name",onKeyPress:ue=>{if(ue.key==="Enter"){let ge=ue.target.value.trim();ge&&!x.hasOwnProperty(ge)&&(ce(ge,""),ue.target.value="")}}}),(0,Ue.jsx)("span",{className:"field-hint",children:"Press Enter to add"})]})]})]})})},Se=()=>k?he():m?b?he():(0,Ue.jsx)("div",{className:"order-info",children:Object.entries(m).map(([D,re])=>(0,Ue.jsxs)("div",{className:"order-field",children:[(0,Ue.jsx)("div",{className:"field-label",children:D}),(0,Ue.jsx)("div",{className:"field-value",children:String(re)})]},D))}):null;return s&&o.length===0?(0,Ue.jsx)("div",{className:"order-management",children:(0,Ue.jsx)("div",{className:"loading-container",children:(0,Ue.jsx)("img",{src:"https://admin.heylua.ai/images/logo.svg",alt:"Loading",className:"loading-logo"})})}):(0,Ue.jsxs)("div",{className:"order-management",children:[E&&(0,Ue.jsx)("div",{className:"error-message",children:E}),N&&(0,Ue.jsx)("div",{className:"success-message",children:N}),(0,Ue.jsx)("div",{className:"order-content",children:m||k?Se():(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("div",{className:"order-search",children:(0,Ue.jsxs)("div",{className:"search-container",children:[(0,Ue.jsx)("input",{type:"text",placeholder:"Search orders...",value:c,onChange:D=>d(D.target.value),className:"search-input"}),(0,Ue.jsx)("button",{className:"search-button",onClick:M,children:"\u{1F50D}"})]})}),(0,Ue.jsx)("div",{className:"orders-list",children:p.length>0?p.map(D=>(0,Ue.jsxs)("div",{className:"order-item",onClick:()=>ve(D),children:[(0,Ue.jsxs)("div",{className:"order-info",children:[(0,Ue.jsx)("div",{className:"order-name",children:D.name||D.id}),(0,Ue.jsx)("div",{className:"order-description",children:D.description||"No description"}),(0,Ue.jsxs)("div",{className:"order-meta",children:["ID: ",D.id,D.price&&(0,Ue.jsxs)("span",{children:[" \u2022 Price: ",D.price]})]})]}),(0,Ue.jsx)("div",{className:"order-arrow",children:"\u2192"})]},D.id)):c?(0,Ue.jsxs)("div",{className:"no-orders",children:[(0,Ue.jsx)("div",{className:"no-orders-icon",children:"\u{1F50D}"}),(0,Ue.jsx)("div",{className:"no-orders-text",children:"No orders found"}),(0,Ue.jsx)("div",{className:"no-orders-subtext",children:"Try a different search term"})]}):(0,Ue.jsxs)("div",{className:"no-orders",children:[(0,Ue.jsx)("div",{className:"no-orders-icon",children:"\u{1F4E6}"}),(0,Ue.jsx)("div",{className:"no-orders-text",children:"No orders yet"}),(0,Ue.jsx)("div",{className:"no-orders-subtext",children:"Create your first order to get started"})]})}),$>1&&(0,Ue.jsxs)("div",{className:"order-pagination",children:[(0,Ue.jsxs)("div",{className:"pagination-info",children:["Page ",H," of ",$]}),(0,Ue.jsxs)("div",{className:"pagination-controls",children:[(0,Ue.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.max(1,D-1)),disabled:H<=1||s,children:"\u2190"}),(0,Ue.jsx)("button",{className:"pagination-button",onClick:()=>j(D=>Math.min($,D+1)),disabled:H>=$||s,children:"\u2192"})]})]})]})})]})}});var pL=A(()=>{});var ur,Le,u5,T9=A(()=>{"use strict";ur=Z(_e());j1();pL();Le=Z(ke()),u5=({apiKey:e,agentId:t,isProduction:n=!1,onHeaderChange:r})=>{let[o,a]=(0,ur.useState)([]),[s,u]=(0,ur.useState)(!1),[c,d]=(0,ur.useState)(null),[p,h]=(0,ur.useState)(!1),[m,g]=(0,ur.useState)(!1),[b,y]=(0,ur.useState)({collection:"",data:"{}",searchText:""}),[k,v]=(0,ur.useState)(null),[x,_]=(0,ur.useState)(null),[E,T]=(0,ur.useState)(!1),[N,R]=(0,ur.useState)(!1),[O,F]=(0,ur.useState)(""),[z,V]=(0,ur.useState)(""),[H,j]=(0,ur.useState)(!1);(0,ur.useEffect)(()=>{$()},[c,m,p,E,N,b]);let $=()=>{if(!r)return;let ne;c&&!p?ne=(0,Le.jsxs)(Le.Fragment,{children:[(0,Le.jsx)("button",{className:"edit-button",onClick:W,disabled:N,title:"Edit entry",children:"\u270F\uFE0F Edit"}),(0,Le.jsx)("button",{className:"delete-button",onClick:handleDelete,disabled:N,title:"Delete entry",children:N?"\u27F3 Deleting...":"\u{1F5D1}\uFE0F Delete"})]}):p||m?ne=(0,Le.jsxs)(Le.Fragment,{children:[(0,Le.jsx)("button",{className:"cancel-button",onClick:X,disabled:E,title:"Cancel",children:"\u2716 Cancel"}),(0,Le.jsx)("button",{className:"save-button",onClick:ae,disabled:E,title:m?"Create entry":"Save changes",children:E?"\u27F3 Saving...":m?"\u{1F4BE} Create":"\u{1F4BE} Save"})]}):ne=(0,Le.jsx)(Le.Fragment,{children:(0,Le.jsx)("button",{className:"create-button",onClick:Y,title:"Create new entry",children:"\u2795 Add Entry"})}),r({title:"",actions:ne})},Y=()=>{d(null),y({collection:"",data:`{
103
103
  "title": "",
104
104
  "description": ""
105
105
  }`,searchText:""}),g(!0),h(!0)},W=()=>{h(!0)},ae=async()=>{if(!b.collection.trim()){v("Collection name is required. Please fill in the collection field.");return}try{JSON.parse(b.data)}catch{v("Invalid JSON format. Please check your data.");return}T(!0);try{let ne=JSON.parse(b.data);m?(console.log("Creating entry in collection:",b.collection,"data:",ne),_(`Entry created in "${b.collection}" collection`)):(console.log("Updating entry:",c?.id),_("Entry updated successfully")),h(!1),g(!1),d(null)}catch{v(`Failed to ${m?"create":"update"} entry`)}finally{T(!1)}},X=()=>{h(!1),g(!1),d(null)},q=async()=>{if(!z.trim()){v("Please enter a collection name to search");return}if(!O.trim()){v("Please enter a search query");return}j(!0),u(!0);try{console.log("Searching collection:",z,"query:",O),_(`Search completed for "${O}" in ${z}`),a([])}catch{v("Failed to search entries")}finally{j(!1),u(!1)}},M=ne=>{d(ne),y({collection:z,data:JSON.stringify(ne.data,null,2),searchText:ne.searchText||""}),h(!1)},ve=()=>(0,Le.jsx)("div",{className:"product-form",children:(0,Le.jsxs)("div",{className:"form-fields",children:[(0,Le.jsxs)("div",{className:"form-group",children:[(0,Le.jsx)("label",{htmlFor:"collection",children:"Collection Name *"}),(0,Le.jsx)("input",{id:"collection",type:"text",value:b.collection,onChange:ne=>y(Fe=>({...Fe,collection:ne.target.value})),placeholder:"e.g., movies, articles, customers",disabled:E||!m,className:m?"":"collection-input"}),(0,Le.jsx)("span",{className:"field-hint",children:m?"Enter a collection name (lowercase, no spaces)":"Collection cannot be changed"})]}),(0,Le.jsxs)("div",{className:"form-group",children:[(0,Le.jsx)("label",{htmlFor:"data",children:"Data (JSON) *"}),(0,Le.jsx)("textarea",{id:"data",value:b.data,onChange:ne=>y(Fe=>({...Fe,data:ne.target.value})),placeholder:`{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lua-cli",
3
- "version": "2.3.2",
3
+ "version": "2.4.1",
4
4
  "description": "Command-line interface for Lua AI platform - develop, test, and deploy LuaSkills with custom tools",
5
5
  "readmeFilename": "README.md",
6
6
  "main": "dist/api-exports.js",
@@ -2086,7 +2086,7 @@
2086
2086
  "inquirer": "^12.9.6",
2087
2087
  "js-yaml": "^4.1.0",
2088
2088
  "keytar": "^7.9.0",
2089
- "lua-cli": "^2.3.0-alpha.1",
2089
+ "lua-cli": "latest",
2090
2090
  "node-fetch": "^3.3.2",
2091
2091
  "open": "^10.1.0",
2092
2092
  "react": "^18.2.0",