nowaikit 4.16.0 → 4.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="https://raw.githubusercontent.com/aartiq/servicenow-mcp/main/docs/assets/banner.png" alt="NowAIKit ServiceNow MCP Server" width="100%"/>
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/nowaikit?style=flat-square&color=00D4AA&label=npm)](https://www.npmjs.com/package/nowaikit)
6
- [![Tools](https://img.shields.io/badge/450%2B%20tools-all%20modules-0F4C81?style=flat-square)](docs/TOOLS.md)
6
+ [![Tools](https://img.shields.io/badge/500%2B%20tools-all%20modules-0F4C81?style=flat-square)](docs/TOOLS.md)
7
7
  [![MCP](https://img.shields.io/badge/MCP-Model%20Context%20Protocol-0F4C81?style=flat-square)](https://modelcontextprotocol.io)
8
8
  [![License: Source Available](https://img.shields.io/badge/license-Source%20Available-f59e0b?style=flat-square)](LICENSE)
9
9
 
@@ -11,7 +11,9 @@
11
11
 
12
12
  **Connect Claude, ChatGPT, Gemini, Cursor, Copilot, or any AI, to ServiceNow.**
13
13
 
14
- 450+ tools across ITSM, ITOM, CMDB, HRSD, CSM, Flow Designer, scripting & portal. Read, build, query and automate any instance in plain English.
14
+ 500+ tools across ITSM, ITOM, CMDB, HRSD, CSM, Flow Designer, scripting & portal. Read, build, query and automate any instance in plain English.
15
+
16
+ 500+ does not mean a heavy context. Your AI does not load every tool. It finds the right one on demand with `search_tools`, you can expose a role package instead of the full set, and clients that load tools only when needed pull just what a task requires, so token cost stays low.
15
17
 
16
18
  New in 4.4 to 4.7: **impact analysis** to see what depends on a table, field, or script before you change it (`list_table_config`, `find_field_references`, `find_script_references`), **Local Sync** to pull widgets and scripts to local files, edit, and push them back, and **`aggregate_report`** for server-side reports (count plus averages, no 1,000-row truncation) with chart-ready output for Copilot and Teams.
17
19
 
@@ -91,7 +93,7 @@ No instance? Grab a free Personal Developer Instance at **[developer.servicenow.
91
93
 
92
94
  | | |
93
95
  |---|---|
94
- | [Installation](docs/INSTALLATION.md) · [Client setup](docs/CLIENT_SETUP.md) | [All 450+ tools](docs/TOOLS.md) · [Tool packages](docs/TOOL_PACKAGES.md) |
96
+ | [Installation](docs/INSTALLATION.md) · [Client setup](docs/CLIENT_SETUP.md) | [All 500+ tools](docs/TOOLS.md) · [Tool packages](docs/TOOL_PACKAGES.md) |
95
97
  | [Multi-instance](docs/MULTI_INSTANCE.md) · [OAuth](docs/SERVICENOW_OAUTH_SETUP.md) | [Scripting](docs/SCRIPTING.md) · [ATF](docs/ATF.md) · [Reporting](docs/REPORTING.md) |
96
98
  | [Skills & branded reports](docs/SKILLS_AND_REPORTS.md) | [Use your own Claude/Codex subscription](docs/SKILLS_AND_REPORTS.md#using-your-own-claude-code-or-codex-subscription) |
97
99
 
@@ -48,7 +48,7 @@ ${qu(d==="oauth")}`:c}const Iu=typeof window<"u"&&window.api!==void 0;function q
48
48
  Use "query_records" with correct table: incident, change_request, problem, task, sys_user, cmdb_ci.
49
49
  Query syntax: active=true, priority=1, ORDERBYDESCsys_created_on, nameLIKEtext.
50
50
  IMPORTANT: Do NOT add assigned_to filter unless user explicitly says "my" or "assigned to me". Query ALL matching records by default.`:void 0,T=D=>D.replace(/sk-ant-[a-zA-Z0-9_-]+/g,"sk-ant-***").replace(/sk-[a-zA-Z0-9_-]{20,}/g,"sk-***").replace(/AIza[a-zA-Z0-9_-]+/g,"AIza***").replace(/gsk_[a-zA-Z0-9_-]+/g,"gsk_***").replace(/sk-or-[a-zA-Z0-9_-]+/g,"sk-or-***").replace(/key=[^&\s]+/g,"key=***");try{if(d==="anthropic"){const D=v==null?void 0:v.map(N=>({name:N.name,description:N.description,input_schema:N.inputSchema||{type:"object",properties:{}}})),W={model:u,max_tokens:4096,messages:h};q&&(W.system=q),D&&D.length>0&&(W.tools=D);const Z=await fetch("/api/ai/anthropic/v1/messages",{method:"POST",headers:{"Content-Type":"application/json","x-api-key":c,"anthropic-version":"2023-06-01","X-NowAIKit-Proxy":"1"},body:JSON.stringify(W)});if(!Z.ok){const N=T(`API error ${Z.status}: ${await Z.text()}`);return k(d,u,(v==null?void 0:v.length)||0,!1,Date.now()-b,void 0,N),{error:N}}const j=await Z.json(),M=j.usage,m=M?{inputTokens:M.input_tokens||0,outputTokens:M.output_tokens||0}:void 0;return k(d,u,(v==null?void 0:v.length)||0,!0,Date.now()-b,m),{content:j.content,stop_reason:j.stop_reason,usage:m}}else if(d==="google"){const W={contents:h.map(F=>{const X=[];if(typeof F.content=="string")X.push({text:F.content});else if(Array.isArray(F.content))for(const ae of F.content)ae.type==="text"?X.push({text:ae.text}):ae.type==="tool_use"?X.push({functionCall:{name:ae.name,args:ae.input}}):ae.type==="tool_result"&&X.push({functionResponse:{name:"tool",response:{content:ae.content}}});return{role:F.role==="assistant"?"model":"user",parts:X}})};q&&(W.systemInstruction={parts:[{text:q}]}),v&&v.length>0&&(W.tools=[{functionDeclarations:v.map(F=>({name:F.name,description:F.description,parameters:F.inputSchema||{type:"object",properties:{}}}))}]);const Z=`/api/ai/google/v1beta/models/${u}:generateContent?key=${c}`,j=`https://generativelanguage.googleapis.com/v1beta/models/${u}:generateContent?key=${c}`;let M;try{if(M=await fetch(Z,{method:"POST",headers:{"Content-Type":"application/json","X-NowAIKit-Proxy":"1"},body:JSON.stringify(W)}),M.status===404)throw new Error("proxy_not_available")}catch{M=await fetch(j,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(W)})}if(!M.ok){const F=T(`Google AI error ${M.status}: ${await M.text()}`);return k(d,u,(v==null?void 0:v.length)||0,!1,Date.now()-b,void 0,F),{error:F}}const m=await M.json(),N=((fe=(V=(B=m.candidates)==null?void 0:B[0])==null?void 0:V.content)==null?void 0:fe.parts)??[],ee=[];for(const F of N)F.text&&ee.push({type:"text",text:F.text}),F.functionCall&&ee.push({type:"tool_use",id:`toolu_${Date.now()}`,name:F.functionCall.name,input:F.functionCall.args});const w=m.usageMetadata,G=w?{inputTokens:w.promptTokenCount||0,outputTokens:w.candidatesTokenCount||0}:void 0;return k(d,u,(v==null?void 0:v.length)||0,!0,Date.now()-b,G),{content:ee,stop_reason:ee.some(F=>F.type==="tool_use")?"tool_use":"end_turn",usage:G}}else{const W={openai:"/api/ai/openai/v1/chat/completions",groq:"/api/ai/groq/openai/v1/chat/completions",openrouter:"/api/ai/openrouter/api/v1/chat/completions",ollama:"/api/ai/ollama/v1/chat/completions",lmstudio:"/api/ai/lmstudio/v1/chat/completions"}[d];if(!W)return{error:`Unknown provider: ${d}`};const Z=[];q&&Z.push({role:"system",content:q});for(const ae of h)if(typeof ae.content=="string")Z.push({role:ae.role,content:ae.content});else if(Array.isArray(ae.content)){const he=ae.content,ke=he.filter(le=>le.type==="text").map(le=>le.text).join(`
51
- `),Le=he.filter(le=>le.type==="tool_use"),Ee=he.filter(le=>le.type==="tool_result");if(Le.length>0)Z.push({role:"assistant",content:ke||null,tool_calls:Le.map(le=>({id:le.id,type:"function",function:{name:le.name,arguments:JSON.stringify(le.input)}}))});else if(Ee.length>0)for(const le of Ee)Z.push({role:"tool",tool_call_id:le.tool_use_id,content:typeof le.content=="string"?le.content:JSON.stringify(le.content)});else ke&&Z.push({role:ae.role,content:ke})}const j={model:u,messages:Z},M=v==null?void 0:v.map(ae=>({type:"function",function:{name:ae.name,description:ae.description,parameters:ae.inputSchema||{type:"object",properties:{}}}}));M&&M.length>0&&(j.tools=M);const m={"Content-Type":"application/json","X-NowAIKit-Proxy":"1"};c&&(m.Authorization=`Bearer ${c}`);const N=await fetch(W,{method:"POST",headers:m,body:JSON.stringify(j)});if(!N.ok){const ae=T(`API error ${N.status}: ${await N.text()}`);return k(d,u,(v==null?void 0:v.length)||0,!1,Date.now()-b,void 0,ae),{error:ae}}const ee=await N.json(),w=(K=(ne=ee.choices)==null?void 0:ne[0])==null?void 0:K.message,G=[];if(w!=null&&w.content&&G.push({type:"text",text:w.content}),w!=null&&w.tool_calls)for(const ae of w.tool_calls){let he={};try{he=JSON.parse(ae.function.arguments)}catch{}G.push({type:"tool_use",id:ae.id,name:ae.function.name,input:he})}const F=ee.usage,X=F?{inputTokens:F.prompt_tokens||0,outputTokens:F.completion_tokens||0}:void 0;return k(d,u,(v==null?void 0:v.length)||0,!0,Date.now()-b,X),{content:G,stop_reason:G.some(ae=>ae.type==="tool_use")?"tool_use":"end_turn",usage:X}}}catch(D){const W=D instanceof TypeError&&String(D.message).includes("Failed to fetch")?'AI proxy not available. Run "npm run serve" or "npm run dev:web" for browser AI chat, or use the desktop app.':D instanceof Error?D.message:"Request failed";return k(d,u,(v==null?void 0:v.length)||0,!1,Date.now()-b,void 0,W),{error:W}}}},It=Iu?window.api:Nu,Pu=[{value:"full",label:"Full — all 450+ tools"},{value:"service_desk",label:"Service Desk"},{value:"change_coordinator",label:"Change Coordinator"},{value:"platform_developer",label:"Platform Developer"},{value:"system_administrator",label:"System Administrator"},{value:"itom_engineer",label:"ITOM Engineer"}],br=["welcome","url","auth","creds","test","role","clients","done"],Mu=[{value:"",label:"— Select —"},{value:"prod",label:"Production"},{value:"staging",label:"Staging"},{value:"uat",label:"UAT"},{value:"test",label:"Test"},{value:"dev",label:"Development"},{value:"demo",label:"Demo"}];function Du({onComplete:l,onClose:d,existingGroups:c=[]}){const[u,h]=z.useState("welcome"),[v,C]=z.useState(""),[b,k]=z.useState({instanceUrl:"",instanceName:"default",group:"Default",environment:"",authMethod:"basic",authMode:"service-account",username:"",password:"",clientId:"",clientSecret:"",toolPackage:"full",writeEnabled:!1}),[q,T]=z.useState("idle"),[B,V]=z.useState(""),[fe,ne]=z.useState(""),K=()=>{const w=br.indexOf(u);w<br.length-1&&h(br[w+1])},D=()=>{const w=br.indexOf(u);w>0&&h(br[w-1])},W=(w,G)=>k(F=>({...F,[w]:G}));function Z(){return It}async function j(){T("testing");try{const w=Z(),G={name:b.instanceName,instanceUrl:b.instanceUrl,authMethod:b.authMethod,username:b.username,password:b.password,clientId:b.clientId,clientSecret:b.clientSecret,toolPackage:b.toolPackage,writeEnabled:b.writeEnabled,group:b.group||"Default",environment:b.environment||void 0};if(w){const F=await w.testInstance(G);F.success?(T("ok"),V("Connection successful")):(T("fail"),V(F.error??"Connection failed"))}else try{const F=await fetch(`${b.instanceUrl}/api/now/table/sys_properties?sysparm_limit=1`,{headers:b.username?{Authorization:"Basic "+btoa(`${b.username}:${b.password}`)}:{}});F.ok?(T("ok"),V("Connection successful")):(T("fail"),V(`HTTP ${F.status} — check credentials`))}catch{T("fail"),V("Could not reach instance — check URL and CORS settings")}}catch(w){T("fail"),V(w instanceof Error?w.message:"Connection failed")}}async function M(){const w=Z();if(w){const G={name:b.instanceName,instanceUrl:b.instanceUrl,authMethod:b.authMethod,username:b.username,password:b.password,clientId:b.clientId,clientSecret:b.clientSecret,toolPackage:b.toolPackage,writeEnabled:b.writeEnabled,group:b.group||"Default",environment:b.environment||void 0},F=await w.addInstance(G);if(!F.success){ne(F.error??"Failed to save config");return}}K()}const m={container:{display:"flex",alignItems:"center",justifyContent:"center",height:"100vh",padding:24},card:{background:"var(--surface)",border:"1px solid var(--border)",borderRadius:12,padding:40,width:"100%",maxWidth:520,position:"relative"},title:{fontSize:"1.4rem",fontWeight:700,marginBottom:8},sub:{color:"var(--text2)",marginBottom:28,fontSize:"0.9rem"},label:{display:"block",fontSize:"0.8rem",color:"var(--dim)",marginBottom:6,textTransform:"uppercase",letterSpacing:"0.05em"},input:{width:"100%",background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",padding:"10px 12px",fontSize:"0.9rem",marginBottom:16},btn:{background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,padding:"10px 20px",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},btnGhost:{background:"transparent",color:"var(--text2)",border:"1px solid var(--border)",borderRadius:6,padding:"10px 20px",fontSize:"0.9rem",cursor:"pointer"},row:{display:"flex",gap:12,justifyContent:"flex-end",marginTop:24},progress:{display:"flex",gap:6,marginBottom:28}},N=br.indexOf(u),ee=br.length-2;return s.jsx("div",{style:m.container,children:s.jsxs("div",{style:m.card,children:[d&&u!=="done"&&s.jsx("button",{onClick:d,style:{position:"absolute",top:12,right:12,background:"transparent",border:"none",color:"var(--dim)",fontSize:"1.2rem",cursor:"pointer",padding:"4px 8px",borderRadius:4,zIndex:10},title:"Close",children:"✕"}),u!=="welcome"&&u!=="done"&&s.jsx("div",{style:m.progress,children:Array.from({length:ee}).map((w,G)=>s.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:G<N?"var(--accent)":"var(--border)"}},G))}),u==="welcome"&&s.jsxs(s.Fragment,{children:[s.jsxs("h1",{style:m.title,children:["Welcome to ",s.jsx("span",{style:{background:"linear-gradient(135deg, #00D4AA 0%, #0F4C81 100%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent"},children:"NowAIKit"})]}),s.jsx("p",{style:m.sub,children:"Connect Any AI to ServiceNow. Instantly."}),s.jsxs("div",{style:{display:"flex",gap:12},children:[s.jsx("button",{style:m.btn,onClick:K,children:"Get Started →"}),d&&s.jsx("button",{style:m.btnGhost,onClick:d,children:"Cancel"})]})]}),u==="url"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"ServiceNow Instance"}),s.jsx("label",{style:m.label,children:"Instance URL"}),s.jsxs("div",{style:{display:"flex",alignItems:"center",marginBottom:16},children:[s.jsx("span",{style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRight:"none",borderRadius:"6px 0 0 6px",padding:"10px 10px",fontSize:"0.9rem",color:"var(--dim)",whiteSpace:"nowrap"},children:"https://"}),s.jsx("input",{style:{...m.input,marginBottom:0,borderRadius:0,flex:1},value:b.instanceUrl.replace(/^https?:\/\//,"").replace(/\.service-now\.com$/,""),onChange:w=>{const G=w.target.value.replace(/[^a-zA-Z0-9-]/g,"");W("instanceUrl",`https://${G}.service-now.com`)},placeholder:"yourcompany"}),s.jsx("span",{style:{background:"var(--surface2)",border:"1px solid var(--border)",borderLeft:"none",borderRadius:"0 6px 6px 0",padding:"10px 10px",fontSize:"0.9rem",color:"var(--dim)",whiteSpace:"nowrap"},children:".service-now.com"})]}),s.jsx("label",{style:m.label,children:"Short name (e.g. prod, dev)"}),s.jsx("input",{style:m.input,value:b.instanceName,onChange:w=>W("instanceName",w.target.value),placeholder:"default"}),s.jsx("label",{style:m.label,children:"Group / Customer"}),c.length>0?s.jsxs("div",{style:{marginBottom:16},children:[s.jsxs("select",{style:{...m.input,cursor:"pointer",marginBottom:8},value:b.group===v&&v?"__new__":b.group,onChange:w=>{w.target.value==="__new__"?(C(""),W("group","")):(W("group",w.target.value),C(""))},children:[c.map(w=>s.jsx("option",{value:w,children:w},w)),s.jsx("option",{value:"__new__",children:"+ Add new group…"})]}),(b.group===""||!c.includes(b.group)&&b.group!=="Default")&&s.jsx("input",{style:m.input,value:v,onChange:w=>{C(w.target.value),W("group",w.target.value)},placeholder:"e.g. Acme Corp, Internal, Customer A"})]}):s.jsx("input",{style:m.input,value:b.group,onChange:w=>W("group",w.target.value),placeholder:"e.g. Acme Corp, Default"}),s.jsx("label",{style:m.label,children:"Environment"}),s.jsx("select",{style:{...m.input,cursor:"pointer"},value:b.environment,onChange:w=>W("environment",w.target.value),children:Mu.map(w=>s.jsx("option",{value:w.value,children:w.label},w.value))}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,disabled:!b.instanceUrl.startsWith("https://"),children:"Next →"})]})]}),u==="auth"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Authentication"}),s.jsx("label",{style:m.label,children:"Method"}),["basic","oauth"].map(w=>s.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10,cursor:"pointer"},children:[s.jsx("input",{type:"radio",checked:b.authMethod===w,onChange:()=>W("authMethod",w)}),s.jsx("span",{style:{fontSize:"0.9rem"},children:w==="basic"?"Basic Auth (username + password)":"OAuth 2.0 (recommended for production)"})]},w)),s.jsx("br",{}),s.jsx("label",{style:m.label,children:"Execution Context"}),[["service-account","Service account — shared credentials (default)"],["per-user","Per-user — each user runs in their own ServiceNow context (enterprise)"],["impersonation","Impersonation — service account + user ACL context"]].map(([w,G])=>s.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,marginBottom:10,cursor:"pointer"},children:[s.jsx("input",{type:"radio",style:{marginTop:3},checked:b.authMode===w,onChange:()=>W("authMode",w)}),s.jsx("span",{style:{fontSize:"0.875rem",color:"var(--text2)"},children:G})]},w)),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="creds"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Credentials"}),b.authMethod==="oauth"&&s.jsxs(s.Fragment,{children:[s.jsx("label",{style:m.label,children:"OAuth Client ID"}),s.jsx("input",{style:m.input,value:b.clientId,onChange:w=>W("clientId",w.target.value)}),s.jsx("label",{style:m.label,children:"OAuth Client Secret"}),s.jsx("input",{style:m.input,type:"password",value:b.clientSecret,onChange:w=>W("clientSecret",w.target.value)})]}),s.jsx("label",{style:m.label,children:b.authMethod==="oauth"?"Service Account Username":"Username"}),s.jsx("input",{style:m.input,value:b.username,onChange:w=>W("username",w.target.value)}),s.jsx("label",{style:m.label,children:"Password"}),s.jsx("input",{style:m.input,type:"password",value:b.password,onChange:w=>W("password",w.target.value)}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="test"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Test Connection"}),s.jsx("p",{style:m.sub,children:"Verify nowaikit can reach your ServiceNow instance."}),q==="idle"&&s.jsx("button",{style:m.btn,onClick:j,children:"Test Connection"}),q==="testing"&&s.jsx("p",{style:{color:"var(--dim)"},children:"Testing…"}),q==="ok"&&s.jsxs("p",{style:{color:"var(--green)",marginBottom:16},children:["✓ ",B]}),q==="fail"&&s.jsxs("p",{style:{color:"var(--red)",marginBottom:16},children:["✗ ",B]}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),(q==="ok"||q==="fail")&&s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="role"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Tool Package & Permissions"}),s.jsx("label",{style:m.label,children:"Tool Package"}),s.jsx("select",{style:{...m.input,cursor:"pointer"},value:b.toolPackage,onChange:w=>W("toolPackage",w.target.value),children:Pu.map(w=>s.jsx("option",{value:w.value,children:w.label},w.value))}),s.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[s.jsx("input",{type:"checkbox",checked:b.writeEnabled,onChange:w=>W("writeEnabled",w.target.checked)}),s.jsx("span",{style:{fontSize:"0.9rem"},children:"Enable write operations (create/update/delete)"})]}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="clients"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Install into AI Client"}),s.jsx("p",{style:m.sub,children:"nowaikit will write the config automatically. You can also do this later from the Instances page."}),s.jsxs("p",{style:{color:"var(--text2)",fontSize:"0.875rem",marginBottom:20},children:["Click ",s.jsx("strong",{children:"Install"})," to detect installed clients and write their configs, or ",s.jsx("strong",{children:"Skip"})," to configure manually later."]}),fe&&s.jsxs("p",{style:{color:"var(--red)",fontSize:"0.875rem",marginBottom:8},children:["✗ ",fe]}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:M,children:"Skip for now"}),s.jsx("button",{style:m.btn,onClick:M,children:"Install & Finish →"})]})]}),u==="done"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:{...m.title,color:"var(--green)"},children:"✓ Setup Complete!"}),s.jsxs("p",{style:m.sub,children:["nowaikit is connected to ",s.jsx("strong",{children:b.instanceUrl})," as ",s.jsx("strong",{children:b.instanceName}),"."]}),s.jsxs("p",{style:{color:"var(--text2)",fontSize:"0.875rem",marginBottom:24},children:["Open your AI client (Claude Desktop, Cursor, etc.) and start using ServiceNow tools. Try: ",s.jsx("em",{children:'"List my 5 most recent open incidents"'})]}),s.jsx("button",{style:m.btn,onClick:l,children:"Open Dashboard →"})]})]})})}const zu={full:"450+",service_desk:"47",change_coordinator:"32",platform_developer:"51",system_administrator:"38",itom_engineer:"29"};function ap(){return It}function Xn({label:l,value:d,sub:c,subTitle:u,accent:h,valueColor:v}){return s.jsxs("div",{className:"card",style:{padding:"20px 22px",flex:1,minWidth:0,overflow:"hidden"},children:[s.jsx("div",{style:{fontSize:"0.68rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:8,whiteSpace:"nowrap"},children:l}),s.jsx("div",{style:{fontSize:"1.75rem",fontWeight:700,color:v??(h?"var(--accent)":"var(--text)"),lineHeight:1,marginBottom:c?6:0},children:d}),c&&s.jsx("div",{title:u??c,style:{fontSize:"0.78rem",color:"var(--text2)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:u?"help":"default"},children:c})]})}async function Bu(l,d,c){const u=await fetch("/api/report/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdown:l,title:d,format:c})});if(!u.ok)throw new Error(`Report generation failed: ${u.status}`);const h=await u.blob(),v=URL.createObjectURL(h),C=document.createElement("a");C.href=v,C.download=`${d.replace(/[^a-zA-Z0-9_-]/g,"_")||"report"}.${c}`,document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(v)}function Fu(){const[l,d]=z.useState(""),[c,u]=z.useState(""),[h,v]=z.useState("pdf"),[C,b]=z.useState(!1),[k,q]=z.useState("");async function T(){if(!c.trim()){q("Paste some markdown content first");return}b(!0),q("Generating…");try{await Bu(c,l||"NowAIKit Report",h),q(`${h.toUpperCase()} downloaded`)}catch(V){q(`Error: ${V instanceof Error?V.message:"unknown"}`)}finally{b(!1)}}const B=V=>({padding:"5px 14px",borderRadius:5,fontSize:"0.8rem",fontWeight:600,cursor:"pointer",background:V?"var(--accent)":"var(--surface2)",color:V?"#fff":"var(--text2)",border:V?"none":"1px solid var(--border)",transition:"all .15s"});return s.jsxs("div",{className:"card",style:{marginBottom:28,overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:8},children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),s.jsx("polyline",{points:"14 2 14 8 20 8"}),s.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),s.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),s.jsx("polyline",{points:"10 9 9 9 8 9"})]}),s.jsx("span",{style:{fontSize:"0.7rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Generate Report"})]}),s.jsxs("div",{style:{padding:"14px 16px",display:"flex",flexDirection:"column",gap:10},children:[s.jsx("input",{value:l,onChange:V=>d(V.target.value),placeholder:"Report title (optional)",style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",padding:"8px 12px",fontSize:"0.85rem",outline:"none"}}),s.jsx("textarea",{value:c,onChange:V=>u(V.target.value),placeholder:"Paste markdown content here (analysis results, capability output, etc.)",rows:5,style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",padding:"8px 12px",fontSize:"0.82rem",resize:"vertical",outline:"none",minHeight:80,lineHeight:1.5}}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[s.jsx("span",{style:{fontSize:"0.78rem",color:"var(--dim)"},children:"Format:"}),s.jsx("button",{onClick:()=>v("pdf"),style:B(h==="pdf"),children:"PDF"}),s.jsx("button",{onClick:()=>v("pptx"),style:B(h==="pptx"),children:"PPTX"}),s.jsx("div",{style:{flex:1}}),s.jsx("button",{onClick:T,disabled:C||!c.trim(),className:"btn-primary",style:{padding:"8px 18px",fontSize:"0.82rem",borderRadius:6,opacity:C||!c.trim()?.5:1},children:C?"Generating…":"Generate & Download"})]}),k&&s.jsx("div",{style:{fontSize:"0.78rem",color:k.startsWith("Error")?"var(--red)":"var(--text2)"},children:k})]})]})}function Ou({serverOnline:l,serverUrl:d,onRefresh:c}){const[u,h]=z.useState(!1),[v,C]=z.useState("");async function b(){const T=ap();if(!T){C("Desktop app required to manage the server");return}h(!0),C(l?"Stopping…":"Starting…");try{if(l)await T.stopServer(),C("Server stopped");else{const B=await T.startServer();B.success?C("Server started"):C(B.error??"Start failed")}setTimeout(c,1500)}catch(B){C(`Error: ${B instanceof Error?B.message:"unknown"}`)}finally{h(!1)}}async function k(){const T=ap();if(T){h(!0),C("Restarting…");try{await T.stopServer();const B=await T.startServer();C(B.success?"Server restarted":B.error??"Restart failed"),setTimeout(c,1500)}catch(B){C(`Error: ${B instanceof Error?B.message:"unknown"}`)}finally{h(!1)}}}const q=T=>s.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:`var(--${T})`,marginRight:6,flexShrink:0,boxShadow:T==="green"?"0 0 6px var(--green)":"none"}});return s.jsxs("div",{className:"card",style:{marginBottom:28,overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",flex:1,minWidth:200},children:[q(l?"green":"dim"),s.jsx("span",{style:{fontWeight:600,fontSize:"0.88rem"},children:"Server"}),s.jsx("span",{style:{marginLeft:8,fontSize:"0.78rem",color:l?"var(--green)":"var(--dim)"},children:l?"Online · MCP Server (stdio)":"Offline"})]}),s.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[s.jsx("button",{onClick:b,disabled:u,style:{background:l?"rgba(248,113,113,0.12)":"var(--accent)",border:l?"1px solid rgba(248,113,113,0.3)":"none",color:l?"var(--red)":"#fff",borderRadius:6,padding:"6px 14px",fontSize:"0.82rem",fontWeight:600,cursor:"pointer",opacity:u?.6:1},children:u?"…":l?"■ Stop":"▶ Start"}),l&&s.jsx("button",{onClick:k,disabled:u,style:{background:"rgba(34,197,94,0.12)",border:"1px solid rgba(34,197,94,0.3)",color:"var(--green)",borderRadius:6,padding:"6px 14px",fontSize:"0.82rem",fontWeight:600,cursor:"pointer",opacity:u?.6:1},children:"↻ Restart"})]})]}),v&&s.jsx("div",{style:{padding:"8px 16px",fontSize:"0.78rem",color:"var(--text2)",background:"var(--surface2)",borderBottom:"1px solid var(--border)"},children:v}),!l&&!u&&!v&&s.jsxs("div",{style:{padding:"12px 16px",fontSize:"0.82rem",color:"var(--text2)"},children:[s.jsx("strong",{style:{color:"var(--yellow)"},children:"Server is offline."})," ","Click ",s.jsx("strong",{children:"▶ Start"})," above to launch the server, or run ",s.jsx("code",{style:{background:"var(--surface2)",padding:"1px 6px",borderRadius:4},children:"nowaikit server"})," in a terminal."]})]})}function Wu({instances:l,serverOnline:d,appVersion:c,serverUrl:u,onRefresh:h,onNavigate:v}){const C=l.find(b=>b.active);return s.jsxs("div",{children:[s.jsxs("div",{className:"page-header",children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"}),s.jsx("polyline",{points:"9 22 9 12 15 12 15 22"})]}),"Dashboard"]}),s.jsx("button",{className:"btn-ghost",onClick:h,style:{padding:"6px 14px",fontSize:"0.8rem"},children:"↻ Refresh"})]}),s.jsxs("div",{style:{display:"flex",gap:14,marginBottom:28,flexWrap:"wrap"},children:[s.jsx(Xn,{label:"Active Instance",value:(C==null?void 0:C.name)??"—",sub:C==null?void 0:C.url,subTitle:C==null?void 0:C.url,accent:!0}),s.jsx(Xn,{label:"Tools",value:C?zu[C.toolPackage]??"—":"—",sub:C?C.toolPackage.replace(/_/g," ")+" package":"no instance"}),s.jsx(Xn,{label:"Instances",value:l.length,sub:"configured"}),s.jsx(Xn,{label:"Server",value:d?"Online":"Offline",sub:void 0,valueColor:d?"var(--green)":"var(--dim)"})]}),s.jsx(Ou,{serverOnline:d,serverUrl:u,onRefresh:h}),s.jsxs("div",{style:{display:"flex",gap:12,marginBottom:28,flexWrap:"wrap"},children:[s.jsxs("button",{className:"btn-primary",onClick:()=>v("chat"),style:{display:"flex",alignItems:"center",gap:8},children:[s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),"Start Chat"]}),s.jsxs("button",{className:"btn-ghost",onClick:()=>v("tools"),style:{display:"flex",alignItems:"center",gap:8},children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2",ry:"2"}),s.jsx("path",{d:"M16 21V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v16"})]}),"Browse Tools"]}),s.jsxs("button",{className:"btn-ghost",onClick:()=>v("instances"),style:{display:"flex",alignItems:"center",gap:8},children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),s.jsx("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]}),"Manage Instances"]})]}),s.jsx(Fu,{}),s.jsxs("div",{className:"card",style:{overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[s.jsx("span",{style:{fontSize:"0.7rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Configured Instances"}),s.jsx("button",{onClick:()=>v("instances"),style:{background:"none",border:"none",color:"var(--accent)",fontSize:"0.78rem",cursor:"pointer"},children:"Manage →"})]}),l.length===0?s.jsxs("div",{style:{padding:"32px 16px",textAlign:"center",color:"var(--dim)",fontSize:"0.875rem"},children:["No instances configured."," ",s.jsx("button",{onClick:()=>v("instances"),style:{background:"none",border:"none",color:"var(--accent)",cursor:"pointer",fontSize:"0.875rem"},children:"Add one →"})]}):l.map((b,k)=>s.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"13px 16px",borderBottom:k<l.length-1?"1px solid var(--border)":"none",gap:12,minWidth:0},children:[s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsxs("div",{style:{fontWeight:600,marginBottom:3,display:"flex",alignItems:"center",gap:8},children:[s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.name}),b.active&&s.jsx("span",{className:"badge-green",style:{flexShrink:0},children:"active"})]}),s.jsx("div",{title:b.url,style:{fontSize:"0.8rem",color:"var(--text2)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"help",maxWidth:"100%"},children:b.url})]}),s.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",fontSize:"0.75rem",color:"var(--dim)",flexShrink:0},children:[s.jsx("span",{className:"badge-dim",children:b.toolPackage.replace(/_/g," ")}),s.jsx("span",{children:"·"}),s.jsx("span",{children:b.authMethod}),s.jsx("span",{children:"·"}),s.jsx("span",{style:{color:b.writeEnabled?"var(--yellow)":"var(--dim)"},children:b.writeEnabled?"read/write":"read-only"})]})]},b.name))]})]})}const Uu={prod:{bg:"rgba(232,70,106,0.15)",fg:"#F06A82"},staging:{bg:"rgba(245,158,11,0.15)",fg:"#FF8A55"},test:{bg:"rgba(59,130,246,0.15)",fg:"#60a5fa"},dev:{bg:"rgba(16,185,129,0.15)",fg:"#34d399"},uat:{bg:"rgba(15,76,129,0.15)",fg:"#3A6FA1"}};function lp(l){return Uu[l.toLowerCase()]??{bg:"var(--surface2)",fg:"var(--dim)"}}function Gu({instances:l,onRemove:d,onSetDefault:c,onTest:u,onAddInstance:h}){const[v,C]=z.useState({}),[b,k]=z.useState(new Set),[q,T]=z.useState(""),B=z.useMemo(()=>{const j=new Map;for(const M of l){const m=M.group||"Default";j.has(m)||j.set(m,[]),j.get(m).push(M)}return Array.from(j.entries()).map(([M,m])=>({name:M,instances:m.sort((N,ee)=>{const w=["prod","staging","uat","test","dev"],G=w.indexOf(N.environment.toLowerCase()),F=w.indexOf(ee.environment.toLowerCase());return(G===-1?99:G)-(F===-1?99:F)}),hasActive:m.some(N=>N.active)})).sort((M,m)=>M.hasActive!==m.hasActive?M.hasActive?-1:1:M.name.localeCompare(m.name))},[l]);z.useMemo(()=>{if(b.size===0&&B.length>0){const j=new Set,M=B.find(m=>m.hasActive);M?j.add(M.name):j.add(B[0].name),k(j)}},[B]);const V=z.useMemo(()=>{if(!q.trim())return B;const j=q.toLowerCase();return B.map(M=>({...M,instances:M.instances.filter(m=>m.name.toLowerCase().includes(j)||m.url.toLowerCase().includes(j)||m.group.toLowerCase().includes(j)||m.environment.toLowerCase().includes(j))})).filter(M=>M.instances.length>0)},[B,q]);function fe(j){k(M=>{const m=new Set(M);return m.has(j)?m.delete(j):m.add(j),m})}function ne(){k(new Set(B.map(j=>j.name)))}function K(){k(new Set)}async function D(j){C(m=>({...m,[j]:"testing"}));const M=await u(j);C(m=>({...m,[j]:M}))}const W=B.length,Z=l.length;return s.jsxs("div",{children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:20,flexWrap:"wrap",gap:12},children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),s.jsx("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]}),"Instances"]}),s.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--dim)",marginTop:2},children:[W," ",W===1?"group":"groups"," · ",Z," ",Z===1?"instance":"instances"]})]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsx("button",{className:"btn-ghost",onClick:ne,style:{fontSize:"0.78rem",padding:"6px 12px"},children:"Expand All"}),s.jsx("button",{className:"btn-ghost",onClick:K,style:{fontSize:"0.78rem",padding:"6px 12px"},children:"Collapse All"}),s.jsx("button",{className:"btn-primary",onClick:h,style:{fontSize:"0.85rem"},children:"+ Add Instance"})]})]}),s.jsx("input",{className:"input",type:"text",value:q,onChange:j=>T(j.target.value),placeholder:`Search ${Z} instances by name, URL, group, or environment…`,style:{marginBottom:16,fontSize:"0.85rem"}}),V.length===0&&s.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--dim)"},children:l.length===0?s.jsxs(s.Fragment,{children:[s.jsx("div",{style:{fontSize:"1.5rem",marginBottom:12},children:"🔗"}),s.jsx("p",{children:"No instances configured yet."}),s.jsxs("p",{style:{fontSize:"0.85rem",marginTop:8,color:"var(--text2)"},children:["Run ",s.jsx("code",{style:{background:"var(--surface2)",padding:"1px 6px",borderRadius:3},children:"nowaikit setup"})," or click ",s.jsx("strong",{children:"Add Instance"}),"."]})]}):s.jsxs("p",{children:['No instances match "',q,'"']})}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:V.map(j=>{const M=b.has(j.name),m=j.instances.reduce((N,ee)=>{const w=ee.environment||"other";return N[w]=(N[w]||0)+1,N},{});return s.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[s.jsxs("button",{onClick:()=>fe(j.name),style:{width:"100%",display:"flex",alignItems:"center",gap:14,padding:"14px 20px",background:"transparent",border:"none",cursor:"pointer",textAlign:"left",transition:"background .15s"},children:[s.jsx("span",{style:{fontSize:"1.1rem",width:24,textAlign:"center",flexShrink:0},children:j.hasActive?"🟢":"⬡"}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{fontWeight:600,fontSize:"0.95rem",color:"var(--text)"},children:j.name}),s.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text2)",marginTop:2,display:"flex",gap:8,flexWrap:"wrap"},children:[s.jsxs("span",{children:[j.instances.length," ",j.instances.length===1?"instance":"instances"]}),Object.entries(m).map(([N,ee])=>{const w=lp(N);return s.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"0 6px",borderRadius:8,fontSize:"0.68rem",fontWeight:500,background:w.bg,color:w.fg},children:[ee," ",N]},N)})]})]}),j.hasActive&&s.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,padding:"3px 10px",borderRadius:12,fontSize:"0.72rem",fontWeight:500,background:"rgba(34,197,94,0.12)",color:"var(--green)"},children:[s.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"var(--green)"}}),"Active"]}),s.jsx("span",{style:{fontSize:"0.7rem",color:"var(--dim)",transition:"transform .2s",transform:M?"rotate(180deg)":"rotate(0deg)"},children:"▼"})]}),M&&s.jsx("div",{style:{borderTop:"1px solid var(--border)"},children:j.instances.map(N=>{const ee=v[N.name],w=lp(N.environment);return s.jsxs("div",{style:{padding:"12px 20px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:14,transition:"background .1s"},children:[s.jsx("div",{style:{width:56,flexShrink:0,textAlign:"center",padding:"4px 0",borderRadius:6,fontSize:"0.72rem",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em",background:w.bg,color:w.fg},children:N.environment||"—"}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:2},children:[s.jsx("span",{style:{fontWeight:600,fontSize:"0.88rem"},children:N.name}),N.active&&s.jsx("span",{style:{background:"#14532d",color:"#86efac",padding:"1px 8px",borderRadius:12,fontSize:"0.68rem",fontWeight:600},children:"ACTIVE"})]}),s.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text2)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.url}),s.jsxs("div",{style:{fontSize:"0.72rem",color:"var(--dim)",marginTop:2},children:[N.authMethod," · ",N.toolPackage.replace(/_/g," ")," · ",N.writeEnabled?"read/write":"read-only"]})]}),s.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[!N.active&&s.jsx("button",{className:"btn-ghost",onClick:()=>c(N.name),style:{fontSize:"0.78rem",padding:"5px 12px"},children:"Set Active"}),s.jsx("button",{className:"btn-ghost",onClick:()=>D(N.name),disabled:ee==="testing",style:{fontSize:"0.78rem",padding:"5px 12px"},children:ee==="testing"?"…":"Test"}),s.jsx("button",{onClick:()=>{confirm(`Remove instance "${N.name}"?`)&&d(N.name)},style:{background:"transparent",border:"1px solid rgba(239,68,68,0.3)",borderRadius:6,color:"var(--red)",padding:"5px 12px",cursor:"pointer",fontSize:"0.78rem",opacity:.7,transition:"opacity .15s"},children:"✕"})]}),ee&&ee!=="testing"&&s.jsxs("div",{style:{position:"absolute",bottom:4,left:90,fontSize:"0.72rem",color:ee.ok?"var(--green)":"var(--red)"},children:[ee.ok?"✓":"✗"," ",ee.message]})]},N.name)})})]},j.name)})})]})}const hp=[{id:"all",label:"All"},{id:"incident",label:"Incidents"},{id:"problem",label:"Problems"},{id:"change",label:"Change"},{id:"task",label:"Tasks"},{id:"cmdb",label:"CMDB"},{id:"user",label:"Users"},{id:"knowledge",label:"Knowledge"},{id:"catalog",label:"Catalog"},{id:"script",label:"Scripts"},{id:"event",label:"Events"}],_p=[{id:"all",label:"All Tiers",color:"var(--dim)"},{id:"read",label:"Read",color:"var(--green)"},{id:"write",label:"Write",color:"var(--yellow)"},{id:"scripting",label:"Scripting",color:"#c084fc"},{id:"agentic",label:"Agentic",color:"var(--red)"}];function Xo(l){const d=(l||"").toLowerCase();return d.includes("[scripting]")||d.includes("scripting")?"scripting":d.includes("[agentic]")||d.includes("agentic playbook")?"agentic":d.includes("[write]")||d.includes("write_enabled")||d.includes("requires write")?"write":"read"}function Hu(l){const d=_p.find(c=>c.id===l);return s.jsx("span",{style:{fontSize:"0.65rem",padding:"2px 6px",borderRadius:10,border:`1px solid ${d.color}`,color:d.color,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em"},children:d.label})}function Jo(l){const d=l.toLowerCase();for(const c of hp.slice(1))if(d.includes(c.id))return c.id;return"other"}function $u({tool:l,onClose:d}){var fe,ne;const c=((fe=l.inputSchema)==null?void 0:fe.properties)??{},u=((ne=l.inputSchema)==null?void 0:ne.required)??[],[h,v]=z.useState({}),[C,b]=z.useState(""),[k,q]=z.useState(!1),[T,B]=z.useState("");async function V(){var D;q(!0),b(""),B("");const K=It;if(!K){B("Desktop app required"),q(!1);return}try{const W={};for(const[j,M]of Object.entries(h)){if(!M&&!u.includes(j))continue;const m=(D=c[j])==null?void 0:D.type;m==="number"||m==="integer"?W[j]=Number(M):m==="boolean"?W[j]=M==="true":W[j]=M}const Z=await K.executeTool(l.name,W);Z.success?b(typeof Z.result=="string"?Z.result:JSON.stringify(Z.result,null,2)):B(Z.error??"Tool execution failed")}catch(W){B(W instanceof Error?W.message:"Error")}q(!1)}return s.jsxs("div",{style:{position:"fixed",top:0,right:0,bottom:0,width:420,background:"var(--surface)",borderLeft:"1px solid var(--border2)",boxShadow:"var(--shadow)",zIndex:100,display:"flex",flexDirection:"column"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 20px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[s.jsx("code",{style:{color:"var(--accent)",fontWeight:700,fontSize:"0.95rem"},children:l.name}),s.jsx("button",{onClick:d,style:{background:"none",border:"none",color:"var(--dim)",fontSize:"1.2rem",padding:4},children:"✕"})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px 20px"},children:[l.description&&s.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text2)",marginBottom:20,lineHeight:1.6},children:l.description}),Object.entries(c).map(([K,D])=>s.jsxs("div",{style:{marginBottom:14},children:[s.jsxs("label",{style:{display:"block",fontSize:"0.78rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:5},children:[K,u.includes(K)&&s.jsx("span",{style:{color:"var(--red)",marginLeft:3},children:"*"})]}),D.description&&s.jsx("div",{style:{fontSize:"0.76rem",color:"var(--text2)",marginBottom:5},children:D.description}),D.enum?s.jsxs("select",{value:h[K]??"",onChange:W=>v(Z=>({...Z,[K]:W.target.value})),style:{width:"100%",background:"var(--surface2)",border:"1px solid var(--border2)",borderRadius:6,color:"var(--text)",padding:"8px 10px",fontSize:"0.85rem"},children:[s.jsx("option",{value:"",children:"— select —"}),D.enum.map(W=>s.jsx("option",{value:W,children:W},W))]}):s.jsx("input",{className:"input",type:D.type==="number"||D.type==="integer"?"number":"text",value:h[K]??"",onChange:W=>v(Z=>({...Z,[K]:W.target.value})),placeholder:D.type==="boolean"?"true / false":D.type??""})]},K)),Object.keys(c).length===0&&s.jsx("div",{style:{color:"var(--dim)",fontSize:"0.85rem"},children:"No parameters required."})]}),s.jsxs("div",{style:{padding:"14px 20px",borderTop:"1px solid var(--border)",flexShrink:0},children:[s.jsx("button",{className:"btn-primary",onClick:V,disabled:k,style:{width:"100%",padding:10,opacity:k?.6:1},children:k?"Running…":"Run Tool"}),T&&s.jsxs("div",{style:{color:"var(--red)",fontSize:"0.8rem",marginTop:10},children:["✗ ",T]}),C&&s.jsx("pre",{className:"result-box",style:{marginTop:12,maxHeight:260},children:C})]})]})}function Vu({activeToolPackage:l,serverOnline:d,serverUrl:c,onRestart:u}){const[h,v]=z.useState([]),[C,b]=z.useState(!0),[k,q]=z.useState("all"),[T,B]=z.useState("all"),[V,fe]=z.useState(""),[ne,K]=z.useState(null),[D,W]=z.useState(!1);z.useEffect(()=>{const j=It;if(!j){b(!1);return}j.listTools().then(M=>v(M??[])).catch(()=>{}).finally(()=>b(!1))},[]);const Z=h.filter(j=>!(k!=="all"&&Jo(j.name)!==k||T!=="all"&&Xo(j.description)!==T||V&&!j.name.toLowerCase().includes(V.toLowerCase())&&!(j.description??"").toLowerCase().includes(V.toLowerCase())));return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100vh - 56px)"},children:[s.jsxs("div",{className:"page-header",style:{marginBottom:16},children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2",ry:"2"}),s.jsx("path",{d:"M16 21V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v16"})]}),"Tools"]}),!C&&s.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--dim)",marginTop:2},children:[Z.length," of ",h.length," tools · ",l.replace(/_/g," ")," package"]})]}),s.jsx("input",{className:"input",placeholder:"Search tools…",value:V,onChange:j=>fe(j.target.value),style:{width:220}})]}),s.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:10},children:hp.map(j=>{const M=j.id==="all"?h.length:h.filter(m=>Jo(m.name)===j.id).length;return M===0&&j.id!=="all"?null:s.jsxs("button",{onClick:()=>q(j.id),style:{padding:"5px 12px",borderRadius:20,fontSize:"0.8rem",border:"1px solid",borderColor:k===j.id?"var(--accent)":"var(--border2)",background:k===j.id?"var(--accent-bg)":"transparent",color:k===j.id?"var(--accent)":"var(--text2)",fontWeight:k===j.id?600:400,transition:"all .15s"},children:[j.label," ",s.jsx("span",{style:{opacity:.7,marginLeft:2},children:M})]},j.id)})}),s.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:20,alignItems:"center"},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--dim)",marginRight:4},children:"Tier:"}),_p.map(j=>{const M=j.id==="all"?h.length:h.filter(m=>Xo(m.description)===j.id).length;return s.jsxs("button",{onClick:()=>B(j.id),style:{padding:"4px 10px",borderRadius:16,fontSize:"0.75rem",border:"1px solid",borderColor:T===j.id?j.color:"var(--border2)",background:T===j.id?`${j.color}15`:"transparent",color:T===j.id?j.color:"var(--text2)",fontWeight:T===j.id?600:400,transition:"all .15s"},children:[j.label," ",s.jsx("span",{style:{opacity:.7,marginLeft:2},children:M})]},j.id)})]}),!d&&!C&&s.jsxs("div",{style:{background:"rgba(251,191,36,0.1)",border:"1px solid rgba(251,191,36,0.25)",borderRadius:8,padding:"10px 16px",marginBottom:16,fontSize:"0.85rem",color:"var(--yellow)",display:"flex",alignItems:"center",gap:10},children:[s.jsx("span",{children:"⚠"}),s.jsxs("span",{style:{flex:1},children:["HTTP server offline — ",s.jsx("strong",{children:"Run"})," will fail."]}),s.jsx("button",{disabled:D,onClick:async()=>{const j=It;j&&(W(!0),await j.startServer(),W(!1),u==null||u())},style:{background:"rgba(251,191,36,0.2)",border:"1px solid rgba(251,191,36,0.4)",color:"var(--yellow)",borderRadius:6,padding:"4px 12px",fontSize:"0.8rem",cursor:"pointer",flexShrink:0,opacity:D?.6:1},children:D?"Starting…":"Start Server"})]}),C?s.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--dim)",gap:10},children:[s.jsx("span",{className:"spinner"})," Loading tools…"]}):Z.length===0?s.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--dim)"},children:h.length===0?"No tools loaded — ensure HTTP server is running":"No tools match the filter"}):s.jsx("div",{style:{flex:1,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(auto-fill,minmax(260px,1fr))",gap:10,alignContent:"start"},children:Z.map(j=>s.jsxs("button",{onClick:()=>K((ne==null?void 0:ne.name)===j.name?null:j),style:{background:(ne==null?void 0:ne.name)===j.name?"var(--accent-bg)":"var(--surface)",border:`1px solid ${(ne==null?void 0:ne.name)===j.name?"var(--accent)":"var(--border)"}`,borderRadius:"var(--radius)",padding:"14px 16px",textAlign:"left",cursor:"pointer",transition:"all .15s"},children:[s.jsx("div",{style:{fontFamily:"monospace",fontSize:"0.82rem",color:"var(--accent)",fontWeight:600,marginBottom:5},children:j.name}),s.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text2)",lineHeight:1.4,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:j.description||"No description"}),s.jsxs("div",{style:{marginTop:8,display:"flex",gap:6,alignItems:"center"},children:[s.jsx("span",{className:"badge-dim",children:Jo(j.name)}),Hu(Xo(j.description))]})]},j.name))}),ne&&s.jsx($u,{tool:ne,serverUrl:c,onClose:()=>K(null)})]})}const Ku=[15,25,50,100];function Yu(){return It}function Qu(){const[l,d]=z.useState([]),[c,u]=z.useState(!0),[h,v]=z.useState(""),[C,b]=z.useState(null),[k,q]=z.useState(0),[T,B]=z.useState(25);function V(){u(!0),b(null),q(0);const m=Yu();if(!m){u(!1);return}m.getAuditLogs(2e3).then(N=>{d(N??[])}).catch(()=>{}).finally(()=>u(!1))}z.useEffect(()=>{V()},[]);const fe=l.filter(m=>{if(!h)return!0;const N=h.toLowerCase();return(m.tool??"").toLowerCase().includes(N)||(m.instance??"").toLowerCase().includes(N)||(m.provider??"").toLowerCase().includes(N)||(m.model??"").toLowerCase().includes(N)||(m.error??"").toLowerCase().includes(N)||(m.event??"").toLowerCase().includes(N)||(m.user??"").toLowerCase().includes(N)}),ne=Math.ceil(fe.length/T),K=fe.slice(k*T,(k+1)*T);function D(m){if(!m)return"—";try{const N=new Date(m);return N.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})+" "+N.toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return m}}function W(m){return m.success===!0?s.jsx("span",{className:"badge-green",children:"ok"}):m.success===!1?s.jsx("span",{className:"badge-red",children:"error"}):s.jsx("span",{className:"badge-dim",children:"—"})}function Z(){const m=["Time","Event","Tool","Instance","User","Provider","Model","Status","Duration (ms)","Input Tokens","Output Tokens","Error"],N=fe.map(X=>[X.ts??"",X.event??"",X.tool||X.resource||X.prompt||"",X.instance??"",X.user??"",X.provider??"",X.model??"",X.success===!0?"ok":X.success===!1?"error":"",X.durationMs!=null?String(X.durationMs):"",X.inputTokens!=null?String(X.inputTokens):"",X.outputTokens!=null?String(X.outputTokens):"",X.error??""]),ee=[m,...N].map(X=>X.map(ae=>`"${String(ae).replace(/"/g,'""')}"`).join(",")).join(`
51
+ `),Le=he.filter(le=>le.type==="tool_use"),Ee=he.filter(le=>le.type==="tool_result");if(Le.length>0)Z.push({role:"assistant",content:ke||null,tool_calls:Le.map(le=>({id:le.id,type:"function",function:{name:le.name,arguments:JSON.stringify(le.input)}}))});else if(Ee.length>0)for(const le of Ee)Z.push({role:"tool",tool_call_id:le.tool_use_id,content:typeof le.content=="string"?le.content:JSON.stringify(le.content)});else ke&&Z.push({role:ae.role,content:ke})}const j={model:u,messages:Z},M=v==null?void 0:v.map(ae=>({type:"function",function:{name:ae.name,description:ae.description,parameters:ae.inputSchema||{type:"object",properties:{}}}}));M&&M.length>0&&(j.tools=M);const m={"Content-Type":"application/json","X-NowAIKit-Proxy":"1"};c&&(m.Authorization=`Bearer ${c}`);const N=await fetch(W,{method:"POST",headers:m,body:JSON.stringify(j)});if(!N.ok){const ae=T(`API error ${N.status}: ${await N.text()}`);return k(d,u,(v==null?void 0:v.length)||0,!1,Date.now()-b,void 0,ae),{error:ae}}const ee=await N.json(),w=(K=(ne=ee.choices)==null?void 0:ne[0])==null?void 0:K.message,G=[];if(w!=null&&w.content&&G.push({type:"text",text:w.content}),w!=null&&w.tool_calls)for(const ae of w.tool_calls){let he={};try{he=JSON.parse(ae.function.arguments)}catch{}G.push({type:"tool_use",id:ae.id,name:ae.function.name,input:he})}const F=ee.usage,X=F?{inputTokens:F.prompt_tokens||0,outputTokens:F.completion_tokens||0}:void 0;return k(d,u,(v==null?void 0:v.length)||0,!0,Date.now()-b,X),{content:G,stop_reason:G.some(ae=>ae.type==="tool_use")?"tool_use":"end_turn",usage:X}}}catch(D){const W=D instanceof TypeError&&String(D.message).includes("Failed to fetch")?'AI proxy not available. Run "npm run serve" or "npm run dev:web" for browser AI chat, or use the desktop app.':D instanceof Error?D.message:"Request failed";return k(d,u,(v==null?void 0:v.length)||0,!1,Date.now()-b,void 0,W),{error:W}}}},It=Iu?window.api:Nu,Pu=[{value:"full",label:"Full — all 500+ tools"},{value:"service_desk",label:"Service Desk"},{value:"change_coordinator",label:"Change Coordinator"},{value:"platform_developer",label:"Platform Developer"},{value:"system_administrator",label:"System Administrator"},{value:"itom_engineer",label:"ITOM Engineer"}],br=["welcome","url","auth","creds","test","role","clients","done"],Mu=[{value:"",label:"— Select —"},{value:"prod",label:"Production"},{value:"staging",label:"Staging"},{value:"uat",label:"UAT"},{value:"test",label:"Test"},{value:"dev",label:"Development"},{value:"demo",label:"Demo"}];function Du({onComplete:l,onClose:d,existingGroups:c=[]}){const[u,h]=z.useState("welcome"),[v,C]=z.useState(""),[b,k]=z.useState({instanceUrl:"",instanceName:"default",group:"Default",environment:"",authMethod:"basic",authMode:"service-account",username:"",password:"",clientId:"",clientSecret:"",toolPackage:"full",writeEnabled:!1}),[q,T]=z.useState("idle"),[B,V]=z.useState(""),[fe,ne]=z.useState(""),K=()=>{const w=br.indexOf(u);w<br.length-1&&h(br[w+1])},D=()=>{const w=br.indexOf(u);w>0&&h(br[w-1])},W=(w,G)=>k(F=>({...F,[w]:G}));function Z(){return It}async function j(){T("testing");try{const w=Z(),G={name:b.instanceName,instanceUrl:b.instanceUrl,authMethod:b.authMethod,username:b.username,password:b.password,clientId:b.clientId,clientSecret:b.clientSecret,toolPackage:b.toolPackage,writeEnabled:b.writeEnabled,group:b.group||"Default",environment:b.environment||void 0};if(w){const F=await w.testInstance(G);F.success?(T("ok"),V("Connection successful")):(T("fail"),V(F.error??"Connection failed"))}else try{const F=await fetch(`${b.instanceUrl}/api/now/table/sys_properties?sysparm_limit=1`,{headers:b.username?{Authorization:"Basic "+btoa(`${b.username}:${b.password}`)}:{}});F.ok?(T("ok"),V("Connection successful")):(T("fail"),V(`HTTP ${F.status} — check credentials`))}catch{T("fail"),V("Could not reach instance — check URL and CORS settings")}}catch(w){T("fail"),V(w instanceof Error?w.message:"Connection failed")}}async function M(){const w=Z();if(w){const G={name:b.instanceName,instanceUrl:b.instanceUrl,authMethod:b.authMethod,username:b.username,password:b.password,clientId:b.clientId,clientSecret:b.clientSecret,toolPackage:b.toolPackage,writeEnabled:b.writeEnabled,group:b.group||"Default",environment:b.environment||void 0},F=await w.addInstance(G);if(!F.success){ne(F.error??"Failed to save config");return}}K()}const m={container:{display:"flex",alignItems:"center",justifyContent:"center",height:"100vh",padding:24},card:{background:"var(--surface)",border:"1px solid var(--border)",borderRadius:12,padding:40,width:"100%",maxWidth:520,position:"relative"},title:{fontSize:"1.4rem",fontWeight:700,marginBottom:8},sub:{color:"var(--text2)",marginBottom:28,fontSize:"0.9rem"},label:{display:"block",fontSize:"0.8rem",color:"var(--dim)",marginBottom:6,textTransform:"uppercase",letterSpacing:"0.05em"},input:{width:"100%",background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",padding:"10px 12px",fontSize:"0.9rem",marginBottom:16},btn:{background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,padding:"10px 20px",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},btnGhost:{background:"transparent",color:"var(--text2)",border:"1px solid var(--border)",borderRadius:6,padding:"10px 20px",fontSize:"0.9rem",cursor:"pointer"},row:{display:"flex",gap:12,justifyContent:"flex-end",marginTop:24},progress:{display:"flex",gap:6,marginBottom:28}},N=br.indexOf(u),ee=br.length-2;return s.jsx("div",{style:m.container,children:s.jsxs("div",{style:m.card,children:[d&&u!=="done"&&s.jsx("button",{onClick:d,style:{position:"absolute",top:12,right:12,background:"transparent",border:"none",color:"var(--dim)",fontSize:"1.2rem",cursor:"pointer",padding:"4px 8px",borderRadius:4,zIndex:10},title:"Close",children:"✕"}),u!=="welcome"&&u!=="done"&&s.jsx("div",{style:m.progress,children:Array.from({length:ee}).map((w,G)=>s.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:G<N?"var(--accent)":"var(--border)"}},G))}),u==="welcome"&&s.jsxs(s.Fragment,{children:[s.jsxs("h1",{style:m.title,children:["Welcome to ",s.jsx("span",{style:{background:"linear-gradient(135deg, #00D4AA 0%, #0F4C81 100%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent"},children:"NowAIKit"})]}),s.jsx("p",{style:m.sub,children:"Connect Any AI to ServiceNow. Instantly."}),s.jsxs("div",{style:{display:"flex",gap:12},children:[s.jsx("button",{style:m.btn,onClick:K,children:"Get Started →"}),d&&s.jsx("button",{style:m.btnGhost,onClick:d,children:"Cancel"})]})]}),u==="url"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"ServiceNow Instance"}),s.jsx("label",{style:m.label,children:"Instance URL"}),s.jsxs("div",{style:{display:"flex",alignItems:"center",marginBottom:16},children:[s.jsx("span",{style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRight:"none",borderRadius:"6px 0 0 6px",padding:"10px 10px",fontSize:"0.9rem",color:"var(--dim)",whiteSpace:"nowrap"},children:"https://"}),s.jsx("input",{style:{...m.input,marginBottom:0,borderRadius:0,flex:1},value:b.instanceUrl.replace(/^https?:\/\//,"").replace(/\.service-now\.com$/,""),onChange:w=>{const G=w.target.value.replace(/[^a-zA-Z0-9-]/g,"");W("instanceUrl",`https://${G}.service-now.com`)},placeholder:"yourcompany"}),s.jsx("span",{style:{background:"var(--surface2)",border:"1px solid var(--border)",borderLeft:"none",borderRadius:"0 6px 6px 0",padding:"10px 10px",fontSize:"0.9rem",color:"var(--dim)",whiteSpace:"nowrap"},children:".service-now.com"})]}),s.jsx("label",{style:m.label,children:"Short name (e.g. prod, dev)"}),s.jsx("input",{style:m.input,value:b.instanceName,onChange:w=>W("instanceName",w.target.value),placeholder:"default"}),s.jsx("label",{style:m.label,children:"Group / Customer"}),c.length>0?s.jsxs("div",{style:{marginBottom:16},children:[s.jsxs("select",{style:{...m.input,cursor:"pointer",marginBottom:8},value:b.group===v&&v?"__new__":b.group,onChange:w=>{w.target.value==="__new__"?(C(""),W("group","")):(W("group",w.target.value),C(""))},children:[c.map(w=>s.jsx("option",{value:w,children:w},w)),s.jsx("option",{value:"__new__",children:"+ Add new group…"})]}),(b.group===""||!c.includes(b.group)&&b.group!=="Default")&&s.jsx("input",{style:m.input,value:v,onChange:w=>{C(w.target.value),W("group",w.target.value)},placeholder:"e.g. Acme Corp, Internal, Customer A"})]}):s.jsx("input",{style:m.input,value:b.group,onChange:w=>W("group",w.target.value),placeholder:"e.g. Acme Corp, Default"}),s.jsx("label",{style:m.label,children:"Environment"}),s.jsx("select",{style:{...m.input,cursor:"pointer"},value:b.environment,onChange:w=>W("environment",w.target.value),children:Mu.map(w=>s.jsx("option",{value:w.value,children:w.label},w.value))}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,disabled:!b.instanceUrl.startsWith("https://"),children:"Next →"})]})]}),u==="auth"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Authentication"}),s.jsx("label",{style:m.label,children:"Method"}),["basic","oauth"].map(w=>s.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10,cursor:"pointer"},children:[s.jsx("input",{type:"radio",checked:b.authMethod===w,onChange:()=>W("authMethod",w)}),s.jsx("span",{style:{fontSize:"0.9rem"},children:w==="basic"?"Basic Auth (username + password)":"OAuth 2.0 (recommended for production)"})]},w)),s.jsx("br",{}),s.jsx("label",{style:m.label,children:"Execution Context"}),[["service-account","Service account — shared credentials (default)"],["per-user","Per-user — each user runs in their own ServiceNow context (enterprise)"],["impersonation","Impersonation — service account + user ACL context"]].map(([w,G])=>s.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,marginBottom:10,cursor:"pointer"},children:[s.jsx("input",{type:"radio",style:{marginTop:3},checked:b.authMode===w,onChange:()=>W("authMode",w)}),s.jsx("span",{style:{fontSize:"0.875rem",color:"var(--text2)"},children:G})]},w)),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="creds"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Credentials"}),b.authMethod==="oauth"&&s.jsxs(s.Fragment,{children:[s.jsx("label",{style:m.label,children:"OAuth Client ID"}),s.jsx("input",{style:m.input,value:b.clientId,onChange:w=>W("clientId",w.target.value)}),s.jsx("label",{style:m.label,children:"OAuth Client Secret"}),s.jsx("input",{style:m.input,type:"password",value:b.clientSecret,onChange:w=>W("clientSecret",w.target.value)})]}),s.jsx("label",{style:m.label,children:b.authMethod==="oauth"?"Service Account Username":"Username"}),s.jsx("input",{style:m.input,value:b.username,onChange:w=>W("username",w.target.value)}),s.jsx("label",{style:m.label,children:"Password"}),s.jsx("input",{style:m.input,type:"password",value:b.password,onChange:w=>W("password",w.target.value)}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="test"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Test Connection"}),s.jsx("p",{style:m.sub,children:"Verify nowaikit can reach your ServiceNow instance."}),q==="idle"&&s.jsx("button",{style:m.btn,onClick:j,children:"Test Connection"}),q==="testing"&&s.jsx("p",{style:{color:"var(--dim)"},children:"Testing…"}),q==="ok"&&s.jsxs("p",{style:{color:"var(--green)",marginBottom:16},children:["✓ ",B]}),q==="fail"&&s.jsxs("p",{style:{color:"var(--red)",marginBottom:16},children:["✗ ",B]}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),(q==="ok"||q==="fail")&&s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="role"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Tool Package & Permissions"}),s.jsx("label",{style:m.label,children:"Tool Package"}),s.jsx("select",{style:{...m.input,cursor:"pointer"},value:b.toolPackage,onChange:w=>W("toolPackage",w.target.value),children:Pu.map(w=>s.jsx("option",{value:w.value,children:w.label},w.value))}),s.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[s.jsx("input",{type:"checkbox",checked:b.writeEnabled,onChange:w=>W("writeEnabled",w.target.checked)}),s.jsx("span",{style:{fontSize:"0.9rem"},children:"Enable write operations (create/update/delete)"})]}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:D,children:"← Back"}),s.jsx("button",{style:m.btn,onClick:K,children:"Next →"})]})]}),u==="clients"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:m.title,children:"Install into AI Client"}),s.jsx("p",{style:m.sub,children:"nowaikit will write the config automatically. You can also do this later from the Instances page."}),s.jsxs("p",{style:{color:"var(--text2)",fontSize:"0.875rem",marginBottom:20},children:["Click ",s.jsx("strong",{children:"Install"})," to detect installed clients and write their configs, or ",s.jsx("strong",{children:"Skip"})," to configure manually later."]}),fe&&s.jsxs("p",{style:{color:"var(--red)",fontSize:"0.875rem",marginBottom:8},children:["✗ ",fe]}),s.jsxs("div",{style:m.row,children:[s.jsx("button",{style:m.btnGhost,onClick:M,children:"Skip for now"}),s.jsx("button",{style:m.btn,onClick:M,children:"Install & Finish →"})]})]}),u==="done"&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{style:{...m.title,color:"var(--green)"},children:"✓ Setup Complete!"}),s.jsxs("p",{style:m.sub,children:["nowaikit is connected to ",s.jsx("strong",{children:b.instanceUrl})," as ",s.jsx("strong",{children:b.instanceName}),"."]}),s.jsxs("p",{style:{color:"var(--text2)",fontSize:"0.875rem",marginBottom:24},children:["Open your AI client (Claude Desktop, Cursor, etc.) and start using ServiceNow tools. Try: ",s.jsx("em",{children:'"List my 5 most recent open incidents"'})]}),s.jsx("button",{style:m.btn,onClick:l,children:"Open Dashboard →"})]})]})})}const zu={full:"500+",service_desk:"47",change_coordinator:"32",platform_developer:"51",system_administrator:"38",itom_engineer:"29"};function ap(){return It}function Xn({label:l,value:d,sub:c,subTitle:u,accent:h,valueColor:v}){return s.jsxs("div",{className:"card",style:{padding:"20px 22px",flex:1,minWidth:0,overflow:"hidden"},children:[s.jsx("div",{style:{fontSize:"0.68rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.07em",marginBottom:8,whiteSpace:"nowrap"},children:l}),s.jsx("div",{style:{fontSize:"1.75rem",fontWeight:700,color:v??(h?"var(--accent)":"var(--text)"),lineHeight:1,marginBottom:c?6:0},children:d}),c&&s.jsx("div",{title:u??c,style:{fontSize:"0.78rem",color:"var(--text2)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:u?"help":"default"},children:c})]})}async function Bu(l,d,c){const u=await fetch("/api/report/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdown:l,title:d,format:c})});if(!u.ok)throw new Error(`Report generation failed: ${u.status}`);const h=await u.blob(),v=URL.createObjectURL(h),C=document.createElement("a");C.href=v,C.download=`${d.replace(/[^a-zA-Z0-9_-]/g,"_")||"report"}.${c}`,document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(v)}function Fu(){const[l,d]=z.useState(""),[c,u]=z.useState(""),[h,v]=z.useState("pdf"),[C,b]=z.useState(!1),[k,q]=z.useState("");async function T(){if(!c.trim()){q("Paste some markdown content first");return}b(!0),q("Generating…");try{await Bu(c,l||"NowAIKit Report",h),q(`${h.toUpperCase()} downloaded`)}catch(V){q(`Error: ${V instanceof Error?V.message:"unknown"}`)}finally{b(!1)}}const B=V=>({padding:"5px 14px",borderRadius:5,fontSize:"0.8rem",fontWeight:600,cursor:"pointer",background:V?"var(--accent)":"var(--surface2)",color:V?"#fff":"var(--text2)",border:V?"none":"1px solid var(--border)",transition:"all .15s"});return s.jsxs("div",{className:"card",style:{marginBottom:28,overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:8},children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),s.jsx("polyline",{points:"14 2 14 8 20 8"}),s.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),s.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),s.jsx("polyline",{points:"10 9 9 9 8 9"})]}),s.jsx("span",{style:{fontSize:"0.7rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Generate Report"})]}),s.jsxs("div",{style:{padding:"14px 16px",display:"flex",flexDirection:"column",gap:10},children:[s.jsx("input",{value:l,onChange:V=>d(V.target.value),placeholder:"Report title (optional)",style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",padding:"8px 12px",fontSize:"0.85rem",outline:"none"}}),s.jsx("textarea",{value:c,onChange:V=>u(V.target.value),placeholder:"Paste markdown content here (analysis results, capability output, etc.)",rows:5,style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",padding:"8px 12px",fontSize:"0.82rem",resize:"vertical",outline:"none",minHeight:80,lineHeight:1.5}}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[s.jsx("span",{style:{fontSize:"0.78rem",color:"var(--dim)"},children:"Format:"}),s.jsx("button",{onClick:()=>v("pdf"),style:B(h==="pdf"),children:"PDF"}),s.jsx("button",{onClick:()=>v("pptx"),style:B(h==="pptx"),children:"PPTX"}),s.jsx("div",{style:{flex:1}}),s.jsx("button",{onClick:T,disabled:C||!c.trim(),className:"btn-primary",style:{padding:"8px 18px",fontSize:"0.82rem",borderRadius:6,opacity:C||!c.trim()?.5:1},children:C?"Generating…":"Generate & Download"})]}),k&&s.jsx("div",{style:{fontSize:"0.78rem",color:k.startsWith("Error")?"var(--red)":"var(--text2)"},children:k})]})]})}function Ou({serverOnline:l,serverUrl:d,onRefresh:c}){const[u,h]=z.useState(!1),[v,C]=z.useState("");async function b(){const T=ap();if(!T){C("Desktop app required to manage the server");return}h(!0),C(l?"Stopping…":"Starting…");try{if(l)await T.stopServer(),C("Server stopped");else{const B=await T.startServer();B.success?C("Server started"):C(B.error??"Start failed")}setTimeout(c,1500)}catch(B){C(`Error: ${B instanceof Error?B.message:"unknown"}`)}finally{h(!1)}}async function k(){const T=ap();if(T){h(!0),C("Restarting…");try{await T.stopServer();const B=await T.startServer();C(B.success?"Server restarted":B.error??"Restart failed"),setTimeout(c,1500)}catch(B){C(`Error: ${B instanceof Error?B.message:"unknown"}`)}finally{h(!1)}}}const q=T=>s.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:`var(--${T})`,marginRight:6,flexShrink:0,boxShadow:T==="green"?"0 0 6px var(--green)":"none"}});return s.jsxs("div",{className:"card",style:{marginBottom:28,overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",flex:1,minWidth:200},children:[q(l?"green":"dim"),s.jsx("span",{style:{fontWeight:600,fontSize:"0.88rem"},children:"Server"}),s.jsx("span",{style:{marginLeft:8,fontSize:"0.78rem",color:l?"var(--green)":"var(--dim)"},children:l?"Online · MCP Server (stdio)":"Offline"})]}),s.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[s.jsx("button",{onClick:b,disabled:u,style:{background:l?"rgba(248,113,113,0.12)":"var(--accent)",border:l?"1px solid rgba(248,113,113,0.3)":"none",color:l?"var(--red)":"#fff",borderRadius:6,padding:"6px 14px",fontSize:"0.82rem",fontWeight:600,cursor:"pointer",opacity:u?.6:1},children:u?"…":l?"■ Stop":"▶ Start"}),l&&s.jsx("button",{onClick:k,disabled:u,style:{background:"rgba(34,197,94,0.12)",border:"1px solid rgba(34,197,94,0.3)",color:"var(--green)",borderRadius:6,padding:"6px 14px",fontSize:"0.82rem",fontWeight:600,cursor:"pointer",opacity:u?.6:1},children:"↻ Restart"})]})]}),v&&s.jsx("div",{style:{padding:"8px 16px",fontSize:"0.78rem",color:"var(--text2)",background:"var(--surface2)",borderBottom:"1px solid var(--border)"},children:v}),!l&&!u&&!v&&s.jsxs("div",{style:{padding:"12px 16px",fontSize:"0.82rem",color:"var(--text2)"},children:[s.jsx("strong",{style:{color:"var(--yellow)"},children:"Server is offline."})," ","Click ",s.jsx("strong",{children:"▶ Start"})," above to launch the server, or run ",s.jsx("code",{style:{background:"var(--surface2)",padding:"1px 6px",borderRadius:4},children:"nowaikit server"})," in a terminal."]})]})}function Wu({instances:l,serverOnline:d,appVersion:c,serverUrl:u,onRefresh:h,onNavigate:v}){const C=l.find(b=>b.active);return s.jsxs("div",{children:[s.jsxs("div",{className:"page-header",children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"}),s.jsx("polyline",{points:"9 22 9 12 15 12 15 22"})]}),"Dashboard"]}),s.jsx("button",{className:"btn-ghost",onClick:h,style:{padding:"6px 14px",fontSize:"0.8rem"},children:"↻ Refresh"})]}),s.jsxs("div",{style:{display:"flex",gap:14,marginBottom:28,flexWrap:"wrap"},children:[s.jsx(Xn,{label:"Active Instance",value:(C==null?void 0:C.name)??"—",sub:C==null?void 0:C.url,subTitle:C==null?void 0:C.url,accent:!0}),s.jsx(Xn,{label:"Tools",value:C?zu[C.toolPackage]??"—":"—",sub:C?C.toolPackage.replace(/_/g," ")+" package":"no instance"}),s.jsx(Xn,{label:"Instances",value:l.length,sub:"configured"}),s.jsx(Xn,{label:"Server",value:d?"Online":"Offline",sub:void 0,valueColor:d?"var(--green)":"var(--dim)"})]}),s.jsx(Ou,{serverOnline:d,serverUrl:u,onRefresh:h}),s.jsxs("div",{style:{display:"flex",gap:12,marginBottom:28,flexWrap:"wrap"},children:[s.jsxs("button",{className:"btn-primary",onClick:()=>v("chat"),style:{display:"flex",alignItems:"center",gap:8},children:[s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),"Start Chat"]}),s.jsxs("button",{className:"btn-ghost",onClick:()=>v("tools"),style:{display:"flex",alignItems:"center",gap:8},children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2",ry:"2"}),s.jsx("path",{d:"M16 21V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v16"})]}),"Browse Tools"]}),s.jsxs("button",{className:"btn-ghost",onClick:()=>v("instances"),style:{display:"flex",alignItems:"center",gap:8},children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),s.jsx("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]}),"Manage Instances"]})]}),s.jsx(Fu,{}),s.jsxs("div",{className:"card",style:{overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[s.jsx("span",{style:{fontSize:"0.7rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Configured Instances"}),s.jsx("button",{onClick:()=>v("instances"),style:{background:"none",border:"none",color:"var(--accent)",fontSize:"0.78rem",cursor:"pointer"},children:"Manage →"})]}),l.length===0?s.jsxs("div",{style:{padding:"32px 16px",textAlign:"center",color:"var(--dim)",fontSize:"0.875rem"},children:["No instances configured."," ",s.jsx("button",{onClick:()=>v("instances"),style:{background:"none",border:"none",color:"var(--accent)",cursor:"pointer",fontSize:"0.875rem"},children:"Add one →"})]}):l.map((b,k)=>s.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"13px 16px",borderBottom:k<l.length-1?"1px solid var(--border)":"none",gap:12,minWidth:0},children:[s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsxs("div",{style:{fontWeight:600,marginBottom:3,display:"flex",alignItems:"center",gap:8},children:[s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.name}),b.active&&s.jsx("span",{className:"badge-green",style:{flexShrink:0},children:"active"})]}),s.jsx("div",{title:b.url,style:{fontSize:"0.8rem",color:"var(--text2)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"help",maxWidth:"100%"},children:b.url})]}),s.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",fontSize:"0.75rem",color:"var(--dim)",flexShrink:0},children:[s.jsx("span",{className:"badge-dim",children:b.toolPackage.replace(/_/g," ")}),s.jsx("span",{children:"·"}),s.jsx("span",{children:b.authMethod}),s.jsx("span",{children:"·"}),s.jsx("span",{style:{color:b.writeEnabled?"var(--yellow)":"var(--dim)"},children:b.writeEnabled?"read/write":"read-only"})]})]},b.name))]})]})}const Uu={prod:{bg:"rgba(232,70,106,0.15)",fg:"#F06A82"},staging:{bg:"rgba(245,158,11,0.15)",fg:"#FF8A55"},test:{bg:"rgba(59,130,246,0.15)",fg:"#60a5fa"},dev:{bg:"rgba(16,185,129,0.15)",fg:"#34d399"},uat:{bg:"rgba(15,76,129,0.15)",fg:"#3A6FA1"}};function lp(l){return Uu[l.toLowerCase()]??{bg:"var(--surface2)",fg:"var(--dim)"}}function Gu({instances:l,onRemove:d,onSetDefault:c,onTest:u,onAddInstance:h}){const[v,C]=z.useState({}),[b,k]=z.useState(new Set),[q,T]=z.useState(""),B=z.useMemo(()=>{const j=new Map;for(const M of l){const m=M.group||"Default";j.has(m)||j.set(m,[]),j.get(m).push(M)}return Array.from(j.entries()).map(([M,m])=>({name:M,instances:m.sort((N,ee)=>{const w=["prod","staging","uat","test","dev"],G=w.indexOf(N.environment.toLowerCase()),F=w.indexOf(ee.environment.toLowerCase());return(G===-1?99:G)-(F===-1?99:F)}),hasActive:m.some(N=>N.active)})).sort((M,m)=>M.hasActive!==m.hasActive?M.hasActive?-1:1:M.name.localeCompare(m.name))},[l]);z.useMemo(()=>{if(b.size===0&&B.length>0){const j=new Set,M=B.find(m=>m.hasActive);M?j.add(M.name):j.add(B[0].name),k(j)}},[B]);const V=z.useMemo(()=>{if(!q.trim())return B;const j=q.toLowerCase();return B.map(M=>({...M,instances:M.instances.filter(m=>m.name.toLowerCase().includes(j)||m.url.toLowerCase().includes(j)||m.group.toLowerCase().includes(j)||m.environment.toLowerCase().includes(j))})).filter(M=>M.instances.length>0)},[B,q]);function fe(j){k(M=>{const m=new Set(M);return m.has(j)?m.delete(j):m.add(j),m})}function ne(){k(new Set(B.map(j=>j.name)))}function K(){k(new Set)}async function D(j){C(m=>({...m,[j]:"testing"}));const M=await u(j);C(m=>({...m,[j]:M}))}const W=B.length,Z=l.length;return s.jsxs("div",{children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:20,flexWrap:"wrap",gap:12},children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),s.jsx("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),s.jsx("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]}),"Instances"]}),s.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--dim)",marginTop:2},children:[W," ",W===1?"group":"groups"," · ",Z," ",Z===1?"instance":"instances"]})]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsx("button",{className:"btn-ghost",onClick:ne,style:{fontSize:"0.78rem",padding:"6px 12px"},children:"Expand All"}),s.jsx("button",{className:"btn-ghost",onClick:K,style:{fontSize:"0.78rem",padding:"6px 12px"},children:"Collapse All"}),s.jsx("button",{className:"btn-primary",onClick:h,style:{fontSize:"0.85rem"},children:"+ Add Instance"})]})]}),s.jsx("input",{className:"input",type:"text",value:q,onChange:j=>T(j.target.value),placeholder:`Search ${Z} instances by name, URL, group, or environment…`,style:{marginBottom:16,fontSize:"0.85rem"}}),V.length===0&&s.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--dim)"},children:l.length===0?s.jsxs(s.Fragment,{children:[s.jsx("div",{style:{fontSize:"1.5rem",marginBottom:12},children:"🔗"}),s.jsx("p",{children:"No instances configured yet."}),s.jsxs("p",{style:{fontSize:"0.85rem",marginTop:8,color:"var(--text2)"},children:["Run ",s.jsx("code",{style:{background:"var(--surface2)",padding:"1px 6px",borderRadius:3},children:"nowaikit setup"})," or click ",s.jsx("strong",{children:"Add Instance"}),"."]})]}):s.jsxs("p",{children:['No instances match "',q,'"']})}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:V.map(j=>{const M=b.has(j.name),m=j.instances.reduce((N,ee)=>{const w=ee.environment||"other";return N[w]=(N[w]||0)+1,N},{});return s.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[s.jsxs("button",{onClick:()=>fe(j.name),style:{width:"100%",display:"flex",alignItems:"center",gap:14,padding:"14px 20px",background:"transparent",border:"none",cursor:"pointer",textAlign:"left",transition:"background .15s"},children:[s.jsx("span",{style:{fontSize:"1.1rem",width:24,textAlign:"center",flexShrink:0},children:j.hasActive?"🟢":"⬡"}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{fontWeight:600,fontSize:"0.95rem",color:"var(--text)"},children:j.name}),s.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text2)",marginTop:2,display:"flex",gap:8,flexWrap:"wrap"},children:[s.jsxs("span",{children:[j.instances.length," ",j.instances.length===1?"instance":"instances"]}),Object.entries(m).map(([N,ee])=>{const w=lp(N);return s.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"0 6px",borderRadius:8,fontSize:"0.68rem",fontWeight:500,background:w.bg,color:w.fg},children:[ee," ",N]},N)})]})]}),j.hasActive&&s.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,padding:"3px 10px",borderRadius:12,fontSize:"0.72rem",fontWeight:500,background:"rgba(34,197,94,0.12)",color:"var(--green)"},children:[s.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"var(--green)"}}),"Active"]}),s.jsx("span",{style:{fontSize:"0.7rem",color:"var(--dim)",transition:"transform .2s",transform:M?"rotate(180deg)":"rotate(0deg)"},children:"▼"})]}),M&&s.jsx("div",{style:{borderTop:"1px solid var(--border)"},children:j.instances.map(N=>{const ee=v[N.name],w=lp(N.environment);return s.jsxs("div",{style:{padding:"12px 20px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:14,transition:"background .1s"},children:[s.jsx("div",{style:{width:56,flexShrink:0,textAlign:"center",padding:"4px 0",borderRadius:6,fontSize:"0.72rem",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em",background:w.bg,color:w.fg},children:N.environment||"—"}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:2},children:[s.jsx("span",{style:{fontWeight:600,fontSize:"0.88rem"},children:N.name}),N.active&&s.jsx("span",{style:{background:"#14532d",color:"#86efac",padding:"1px 8px",borderRadius:12,fontSize:"0.68rem",fontWeight:600},children:"ACTIVE"})]}),s.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text2)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.url}),s.jsxs("div",{style:{fontSize:"0.72rem",color:"var(--dim)",marginTop:2},children:[N.authMethod," · ",N.toolPackage.replace(/_/g," ")," · ",N.writeEnabled?"read/write":"read-only"]})]}),s.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[!N.active&&s.jsx("button",{className:"btn-ghost",onClick:()=>c(N.name),style:{fontSize:"0.78rem",padding:"5px 12px"},children:"Set Active"}),s.jsx("button",{className:"btn-ghost",onClick:()=>D(N.name),disabled:ee==="testing",style:{fontSize:"0.78rem",padding:"5px 12px"},children:ee==="testing"?"…":"Test"}),s.jsx("button",{onClick:()=>{confirm(`Remove instance "${N.name}"?`)&&d(N.name)},style:{background:"transparent",border:"1px solid rgba(239,68,68,0.3)",borderRadius:6,color:"var(--red)",padding:"5px 12px",cursor:"pointer",fontSize:"0.78rem",opacity:.7,transition:"opacity .15s"},children:"✕"})]}),ee&&ee!=="testing"&&s.jsxs("div",{style:{position:"absolute",bottom:4,left:90,fontSize:"0.72rem",color:ee.ok?"var(--green)":"var(--red)"},children:[ee.ok?"✓":"✗"," ",ee.message]})]},N.name)})})]},j.name)})})]})}const hp=[{id:"all",label:"All"},{id:"incident",label:"Incidents"},{id:"problem",label:"Problems"},{id:"change",label:"Change"},{id:"task",label:"Tasks"},{id:"cmdb",label:"CMDB"},{id:"user",label:"Users"},{id:"knowledge",label:"Knowledge"},{id:"catalog",label:"Catalog"},{id:"script",label:"Scripts"},{id:"event",label:"Events"}],_p=[{id:"all",label:"All Tiers",color:"var(--dim)"},{id:"read",label:"Read",color:"var(--green)"},{id:"write",label:"Write",color:"var(--yellow)"},{id:"scripting",label:"Scripting",color:"#c084fc"},{id:"agentic",label:"Agentic",color:"var(--red)"}];function Xo(l){const d=(l||"").toLowerCase();return d.includes("[scripting]")||d.includes("scripting")?"scripting":d.includes("[agentic]")||d.includes("agentic playbook")?"agentic":d.includes("[write]")||d.includes("write_enabled")||d.includes("requires write")?"write":"read"}function Hu(l){const d=_p.find(c=>c.id===l);return s.jsx("span",{style:{fontSize:"0.65rem",padding:"2px 6px",borderRadius:10,border:`1px solid ${d.color}`,color:d.color,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em"},children:d.label})}function Jo(l){const d=l.toLowerCase();for(const c of hp.slice(1))if(d.includes(c.id))return c.id;return"other"}function $u({tool:l,onClose:d}){var fe,ne;const c=((fe=l.inputSchema)==null?void 0:fe.properties)??{},u=((ne=l.inputSchema)==null?void 0:ne.required)??[],[h,v]=z.useState({}),[C,b]=z.useState(""),[k,q]=z.useState(!1),[T,B]=z.useState("");async function V(){var D;q(!0),b(""),B("");const K=It;if(!K){B("Desktop app required"),q(!1);return}try{const W={};for(const[j,M]of Object.entries(h)){if(!M&&!u.includes(j))continue;const m=(D=c[j])==null?void 0:D.type;m==="number"||m==="integer"?W[j]=Number(M):m==="boolean"?W[j]=M==="true":W[j]=M}const Z=await K.executeTool(l.name,W);Z.success?b(typeof Z.result=="string"?Z.result:JSON.stringify(Z.result,null,2)):B(Z.error??"Tool execution failed")}catch(W){B(W instanceof Error?W.message:"Error")}q(!1)}return s.jsxs("div",{style:{position:"fixed",top:0,right:0,bottom:0,width:420,background:"var(--surface)",borderLeft:"1px solid var(--border2)",boxShadow:"var(--shadow)",zIndex:100,display:"flex",flexDirection:"column"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 20px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[s.jsx("code",{style:{color:"var(--accent)",fontWeight:700,fontSize:"0.95rem"},children:l.name}),s.jsx("button",{onClick:d,style:{background:"none",border:"none",color:"var(--dim)",fontSize:"1.2rem",padding:4},children:"✕"})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px 20px"},children:[l.description&&s.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text2)",marginBottom:20,lineHeight:1.6},children:l.description}),Object.entries(c).map(([K,D])=>s.jsxs("div",{style:{marginBottom:14},children:[s.jsxs("label",{style:{display:"block",fontSize:"0.78rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:5},children:[K,u.includes(K)&&s.jsx("span",{style:{color:"var(--red)",marginLeft:3},children:"*"})]}),D.description&&s.jsx("div",{style:{fontSize:"0.76rem",color:"var(--text2)",marginBottom:5},children:D.description}),D.enum?s.jsxs("select",{value:h[K]??"",onChange:W=>v(Z=>({...Z,[K]:W.target.value})),style:{width:"100%",background:"var(--surface2)",border:"1px solid var(--border2)",borderRadius:6,color:"var(--text)",padding:"8px 10px",fontSize:"0.85rem"},children:[s.jsx("option",{value:"",children:"— select —"}),D.enum.map(W=>s.jsx("option",{value:W,children:W},W))]}):s.jsx("input",{className:"input",type:D.type==="number"||D.type==="integer"?"number":"text",value:h[K]??"",onChange:W=>v(Z=>({...Z,[K]:W.target.value})),placeholder:D.type==="boolean"?"true / false":D.type??""})]},K)),Object.keys(c).length===0&&s.jsx("div",{style:{color:"var(--dim)",fontSize:"0.85rem"},children:"No parameters required."})]}),s.jsxs("div",{style:{padding:"14px 20px",borderTop:"1px solid var(--border)",flexShrink:0},children:[s.jsx("button",{className:"btn-primary",onClick:V,disabled:k,style:{width:"100%",padding:10,opacity:k?.6:1},children:k?"Running…":"Run Tool"}),T&&s.jsxs("div",{style:{color:"var(--red)",fontSize:"0.8rem",marginTop:10},children:["✗ ",T]}),C&&s.jsx("pre",{className:"result-box",style:{marginTop:12,maxHeight:260},children:C})]})]})}function Vu({activeToolPackage:l,serverOnline:d,serverUrl:c,onRestart:u}){const[h,v]=z.useState([]),[C,b]=z.useState(!0),[k,q]=z.useState("all"),[T,B]=z.useState("all"),[V,fe]=z.useState(""),[ne,K]=z.useState(null),[D,W]=z.useState(!1);z.useEffect(()=>{const j=It;if(!j){b(!1);return}j.listTools().then(M=>v(M??[])).catch(()=>{}).finally(()=>b(!1))},[]);const Z=h.filter(j=>!(k!=="all"&&Jo(j.name)!==k||T!=="all"&&Xo(j.description)!==T||V&&!j.name.toLowerCase().includes(V.toLowerCase())&&!(j.description??"").toLowerCase().includes(V.toLowerCase())));return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100vh - 56px)"},children:[s.jsxs("div",{className:"page-header",style:{marginBottom:16},children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2",ry:"2"}),s.jsx("path",{d:"M16 21V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v16"})]}),"Tools"]}),!C&&s.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--dim)",marginTop:2},children:[Z.length," of ",h.length," tools · ",l.replace(/_/g," ")," package"]})]}),s.jsx("input",{className:"input",placeholder:"Search tools…",value:V,onChange:j=>fe(j.target.value),style:{width:220}})]}),s.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:10},children:hp.map(j=>{const M=j.id==="all"?h.length:h.filter(m=>Jo(m.name)===j.id).length;return M===0&&j.id!=="all"?null:s.jsxs("button",{onClick:()=>q(j.id),style:{padding:"5px 12px",borderRadius:20,fontSize:"0.8rem",border:"1px solid",borderColor:k===j.id?"var(--accent)":"var(--border2)",background:k===j.id?"var(--accent-bg)":"transparent",color:k===j.id?"var(--accent)":"var(--text2)",fontWeight:k===j.id?600:400,transition:"all .15s"},children:[j.label," ",s.jsx("span",{style:{opacity:.7,marginLeft:2},children:M})]},j.id)})}),s.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:20,alignItems:"center"},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--dim)",marginRight:4},children:"Tier:"}),_p.map(j=>{const M=j.id==="all"?h.length:h.filter(m=>Xo(m.description)===j.id).length;return s.jsxs("button",{onClick:()=>B(j.id),style:{padding:"4px 10px",borderRadius:16,fontSize:"0.75rem",border:"1px solid",borderColor:T===j.id?j.color:"var(--border2)",background:T===j.id?`${j.color}15`:"transparent",color:T===j.id?j.color:"var(--text2)",fontWeight:T===j.id?600:400,transition:"all .15s"},children:[j.label," ",s.jsx("span",{style:{opacity:.7,marginLeft:2},children:M})]},j.id)})]}),!d&&!C&&s.jsxs("div",{style:{background:"rgba(251,191,36,0.1)",border:"1px solid rgba(251,191,36,0.25)",borderRadius:8,padding:"10px 16px",marginBottom:16,fontSize:"0.85rem",color:"var(--yellow)",display:"flex",alignItems:"center",gap:10},children:[s.jsx("span",{children:"⚠"}),s.jsxs("span",{style:{flex:1},children:["HTTP server offline — ",s.jsx("strong",{children:"Run"})," will fail."]}),s.jsx("button",{disabled:D,onClick:async()=>{const j=It;j&&(W(!0),await j.startServer(),W(!1),u==null||u())},style:{background:"rgba(251,191,36,0.2)",border:"1px solid rgba(251,191,36,0.4)",color:"var(--yellow)",borderRadius:6,padding:"4px 12px",fontSize:"0.8rem",cursor:"pointer",flexShrink:0,opacity:D?.6:1},children:D?"Starting…":"Start Server"})]}),C?s.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--dim)",gap:10},children:[s.jsx("span",{className:"spinner"})," Loading tools…"]}):Z.length===0?s.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--dim)"},children:h.length===0?"No tools loaded — ensure HTTP server is running":"No tools match the filter"}):s.jsx("div",{style:{flex:1,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(auto-fill,minmax(260px,1fr))",gap:10,alignContent:"start"},children:Z.map(j=>s.jsxs("button",{onClick:()=>K((ne==null?void 0:ne.name)===j.name?null:j),style:{background:(ne==null?void 0:ne.name)===j.name?"var(--accent-bg)":"var(--surface)",border:`1px solid ${(ne==null?void 0:ne.name)===j.name?"var(--accent)":"var(--border)"}`,borderRadius:"var(--radius)",padding:"14px 16px",textAlign:"left",cursor:"pointer",transition:"all .15s"},children:[s.jsx("div",{style:{fontFamily:"monospace",fontSize:"0.82rem",color:"var(--accent)",fontWeight:600,marginBottom:5},children:j.name}),s.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text2)",lineHeight:1.4,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:j.description||"No description"}),s.jsxs("div",{style:{marginTop:8,display:"flex",gap:6,alignItems:"center"},children:[s.jsx("span",{className:"badge-dim",children:Jo(j.name)}),Hu(Xo(j.description))]})]},j.name))}),ne&&s.jsx($u,{tool:ne,serverUrl:c,onClose:()=>K(null)})]})}const Ku=[15,25,50,100];function Yu(){return It}function Qu(){const[l,d]=z.useState([]),[c,u]=z.useState(!0),[h,v]=z.useState(""),[C,b]=z.useState(null),[k,q]=z.useState(0),[T,B]=z.useState(25);function V(){u(!0),b(null),q(0);const m=Yu();if(!m){u(!1);return}m.getAuditLogs(2e3).then(N=>{d(N??[])}).catch(()=>{}).finally(()=>u(!1))}z.useEffect(()=>{V()},[]);const fe=l.filter(m=>{if(!h)return!0;const N=h.toLowerCase();return(m.tool??"").toLowerCase().includes(N)||(m.instance??"").toLowerCase().includes(N)||(m.provider??"").toLowerCase().includes(N)||(m.model??"").toLowerCase().includes(N)||(m.error??"").toLowerCase().includes(N)||(m.event??"").toLowerCase().includes(N)||(m.user??"").toLowerCase().includes(N)}),ne=Math.ceil(fe.length/T),K=fe.slice(k*T,(k+1)*T);function D(m){if(!m)return"—";try{const N=new Date(m);return N.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})+" "+N.toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return m}}function W(m){return m.success===!0?s.jsx("span",{className:"badge-green",children:"ok"}):m.success===!1?s.jsx("span",{className:"badge-red",children:"error"}):s.jsx("span",{className:"badge-dim",children:"—"})}function Z(){const m=["Time","Event","Tool","Instance","User","Provider","Model","Status","Duration (ms)","Input Tokens","Output Tokens","Error"],N=fe.map(X=>[X.ts??"",X.event??"",X.tool||X.resource||X.prompt||"",X.instance??"",X.user??"",X.provider??"",X.model??"",X.success===!0?"ok":X.success===!1?"error":"",X.durationMs!=null?String(X.durationMs):"",X.inputTokens!=null?String(X.inputTokens):"",X.outputTokens!=null?String(X.outputTokens):"",X.error??""]),ee=[m,...N].map(X=>X.map(ae=>`"${String(ae).replace(/"/g,'""')}"`).join(",")).join(`
52
52
  `),w=new Blob([ee],{type:"text/csv"}),G=URL.createObjectURL(w),F=document.createElement("a");F.href=G,F.download=`nowaikit-audit-${new Date().toISOString().slice(0,10)}.csv`,F.click(),URL.revokeObjectURL(G)}const j={padding:"8px 12px",fontSize:"0.72rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.06em",textAlign:"left",borderBottom:"1px solid var(--border)",fontWeight:600},M={padding:"10px 12px",fontSize:"0.82rem",borderBottom:"1px solid var(--border)",verticalAlign:"middle"};return s.jsxs("div",{children:[s.jsxs("div",{className:"page-header",children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),s.jsx("polyline",{points:"14 2 14 8 20 8"}),s.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),s.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]}),"Audit Log"]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsx("input",{className:"input",placeholder:"Filter by tool, instance, provider, model…",value:h,onChange:m=>{v(m.target.value),q(0)},style:{width:280}}),s.jsx("button",{className:"btn-ghost",onClick:Z,disabled:fe.length===0,style:{padding:"6px 14px",fontSize:"0.8rem"},title:"Export filtered logs as CSV",children:"Export CSV"}),s.jsx("button",{className:"btn-ghost",onClick:V,style:{padding:"6px 14px",fontSize:"0.8rem"},children:"↻"})]})]}),s.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--dim)",marginBottom:14},children:["Log: ",s.jsx("code",{style:{color:"var(--text2)"},children:"~/.config/nowaikit/audit.jsonl"}),!c&&s.jsxs("span",{style:{marginLeft:12},children:["Showing ",K.length," of ",fe.length," entries",fe.length!==l.length&&` (${l.length} total)`]})]}),c?s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:200,color:"var(--dim)",gap:10},children:[s.jsx("span",{className:"spinner"})," Loading logs…"]}):l.length===0?s.jsxs("div",{className:"card",style:{padding:32,textAlign:"center",color:"var(--dim)"},children:[s.jsx("div",{style:{marginBottom:8},children:"No audit log entries found."}),s.jsx("div",{style:{fontSize:"0.8rem"},children:"Logs appear after tools are called or chat messages are sent."})]}):s.jsxs("div",{className:"card",style:{overflow:"auto"},children:[s.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:1e3},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:j,children:"Time"}),s.jsx("th",{style:j,children:"Event"}),s.jsx("th",{style:j,children:"Tool"}),s.jsx("th",{style:j,children:"Instance"}),s.jsx("th",{style:j,children:"User"}),s.jsx("th",{style:j,children:"Provider"}),s.jsx("th",{style:j,children:"Model"}),s.jsx("th",{style:j,children:"Status"}),s.jsx("th",{style:j,children:"Tokens"}),s.jsx("th",{style:j,children:"Duration"}),s.jsx("th",{style:j,children:"Error"})]})}),s.jsx("tbody",{children:K.map((m,N)=>s.jsxs("tr",{onClick:()=>b(C===m?null:m),style:{cursor:"pointer",background:C===m?"var(--surface2)":"transparent",transition:"background .1s"},children:[s.jsx("td",{style:{...M,color:"var(--text2)",fontFamily:"monospace",fontSize:"0.78rem",whiteSpace:"nowrap"},children:D(m.ts)}),s.jsx("td",{style:{...M,fontSize:"0.75rem",color:"var(--dim)"},children:m.event??"—"}),s.jsx("td",{style:{...M,fontFamily:"monospace",color:"var(--accent)",fontWeight:500},children:m.tool||m.resource||m.prompt||"—"}),s.jsx("td",{style:{...M,fontSize:"0.8rem",color:"var(--text2)"},children:m.instance??"—"}),s.jsx("td",{style:{...M,fontSize:"0.8rem",color:"var(--text2)"},children:m.user??"—"}),s.jsx("td",{style:{...M,fontSize:"0.8rem",color:"var(--text2)"},children:m.provider??"—"}),s.jsx("td",{style:{...M,fontFamily:"monospace",fontSize:"0.75rem",color:"var(--text2)",maxWidth:150,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.model??"—"}),s.jsx("td",{style:M,children:W(m)}),s.jsx("td",{style:{...M,fontFamily:"monospace",fontSize:"0.75rem",color:"var(--text2)",whiteSpace:"nowrap"},children:m.inputTokens!=null||m.outputTokens!=null?`${m.inputTokens??0}→${m.outputTokens??0}`:"—"}),s.jsx("td",{style:{...M,color:"var(--text2)"},children:m.durationMs!=null?`${m.durationMs}ms`:"—"}),s.jsx("td",{style:{...M,color:"var(--red)",fontSize:"0.75rem",maxWidth:200,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.error??""})]},k*T+N))})]}),fe.length>0&&s.jsxs("div",{style:{padding:"12px 16px",display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid var(--border)",flexWrap:"wrap",gap:8},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:"0.78rem",color:"var(--text2)"},children:[s.jsx("span",{children:"Rows:"}),s.jsx("select",{value:T,onChange:m=>{B(Number(m.target.value)),q(0)},style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",padding:"3px 6px",fontSize:"0.78rem"},children:Ku.map(m=>s.jsx("option",{value:m,children:m},m))})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[s.jsx("button",{className:"btn-ghost",onClick:()=>q(0),disabled:k===0,style:{padding:"4px 8px",fontSize:"0.75rem"},children:"« First"}),s.jsx("button",{className:"btn-ghost",onClick:()=>q(m=>Math.max(0,m-1)),disabled:k===0,style:{padding:"4px 8px",fontSize:"0.75rem"},children:"‹ Prev"}),(()=>{const m=[],N=Math.max(0,k-2),ee=Math.min(ne-1,k+2);N>0&&m.push(0),N>1&&m.push(-1);for(let w=N;w<=ee;w++)m.push(w);return ee<ne-2&&m.push(-2),ee<ne-1&&m.push(ne-1),m.map((w,G)=>w<0?s.jsx("span",{style:{padding:"0 4px",color:"var(--dim)",fontSize:"0.75rem"},children:"…"},`e${G}`):s.jsx("button",{className:"btn-ghost",onClick:()=>q(w),style:{padding:"4px 8px",fontSize:"0.75rem",minWidth:28,background:w===k?"var(--accent)":"transparent",color:w===k?"#fff":"var(--text2)",borderRadius:4,fontWeight:w===k?600:400},children:w+1},w))})(),s.jsx("button",{className:"btn-ghost",onClick:()=>q(m=>Math.min(ne-1,m+1)),disabled:k>=ne-1,style:{padding:"4px 8px",fontSize:"0.75rem"},children:"Next ›"}),s.jsx("button",{className:"btn-ghost",onClick:()=>q(ne-1),disabled:k>=ne-1,style:{padding:"4px 8px",fontSize:"0.75rem"},children:"Last »"})]}),s.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--dim)"},children:[k*T+1,"–",Math.min((k+1)*T,fe.length)," of ",fe.length]})]}),C&&s.jsxs("div",{style:{padding:"14px 16px",borderTop:"2px solid var(--border2)",background:"var(--surface2)"},children:[s.jsx("div",{style:{fontSize:"0.72rem",color:"var(--dim)",marginBottom:6,textTransform:"uppercase",letterSpacing:"0.06em"},children:"Entry Detail"}),s.jsx("pre",{style:{fontSize:"0.78rem",overflowX:"auto",color:"var(--text)",lineHeight:1.5},children:JSON.stringify(C,null,2)})]})]})]})}function Xu({size:l=16,color:d="currentColor",style:c}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:l,fill:d,viewBox:"0 0 16 16",style:c,children:s.jsx("path",{d:"m3.127 10.604 3.135-1.76.053-.153-.053-.085H6.11l-.525-.032-1.791-.048-1.554-.065-1.505-.08-.38-.081L0 7.832l.036-.234.32-.214.455.04 1.009.069 1.513.105 1.097.064 1.626.17h.259l.036-.105-.089-.065-.068-.064-1.566-1.062-1.695-1.121-.887-.646-.48-.327-.243-.306-.104-.67.435-.48.585.04.15.04.593.456 1.267.981 1.654 1.218.242.202.097-.068.012-.049-.109-.181-.9-1.626-.96-1.655-.428-.686-.113-.411a2 2 0 0 1-.068-.484l.496-.674L4.446 0l.662.089.279.242.411.94.666 1.48 1.033 2.014.302.597.162.553.06.17h.105v-.097l.085-1.134.157-1.392.154-1.792.052-.504.25-.605.497-.327.387.186.319.456-.045.294-.19 1.23-.37 1.93-.243 1.29h.142l.161-.16.654-.868 1.097-1.372.484-.545.565-.601.363-.287h.686l.505.751-.226.775-.707.895-.585.759-.839 1.13-.524.904.048.072.125-.012 1.897-.403 1.024-.186 1.223-.21.553.258.06.263-.218.536-1.307.323-1.533.307-2.284.54-.028.02.032.04 1.029.098.44.024h1.077l2.005.15.525.346.315.424-.053.323-.807.411-3.631-.863-.872-.218h-.12v.073l.726.71 1.331 1.202 1.667 1.55.084.383-.214.302-.226-.032-1.464-1.101-.565-.497-1.28-1.077h-.084v.113l.295.432 1.557 2.34.08.718-.112.234-.404.141-.444-.08-.911-1.28-.94-1.44-.759-1.291-.093.053-.448 4.821-.21.246-.484.186-.403-.307-.214-.496.214-.98.258-1.28.21-1.016.19-1.263.112-.42-.008-.028-.092.012-.953 1.307-1.448 1.957-1.146 1.227-.274.109-.477-.247.045-.44.266-.39 1.586-2.018.956-1.25.617-.723-.004-.105h-.036l-4.212 2.736-.75.096-.324-.302.04-.496.154-.162 1.267-.871z"})})}function Ju({size:l=16,color:d="currentColor",style:c}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:l,fill:d,viewBox:"0 0 16 16",style:c,children:s.jsx("path",{d:"M14.949 6.547a3.94 3.94 0 0 0-.348-3.273 4.11 4.11 0 0 0-4.4-1.934A4.1 4.1 0 0 0 8.423.2 4.15 4.15 0 0 0 6.305.086a4.1 4.1 0 0 0-1.891.948 4.04 4.04 0 0 0-1.158 1.753 4.1 4.1 0 0 0-1.563.679A4 4 0 0 0 .554 4.72a3.99 3.99 0 0 0 .502 4.731 3.94 3.94 0 0 0 .346 3.274 4.11 4.11 0 0 0 4.402 1.933c.382.425.852.764 1.377.995.526.231 1.095.35 1.67.346 1.78.002 3.358-1.132 3.901-2.804a4.1 4.1 0 0 0 1.563-.68 4 4 0 0 0 1.14-1.253 3.99 3.99 0 0 0-.506-4.716m-6.097 8.406a3.05 3.05 0 0 1-1.945-.694l.096-.054 3.23-1.838a.53.53 0 0 0 .265-.455v-4.49l1.366.778q.02.011.025.035v3.722c-.003 1.653-1.361 2.992-3.037 2.996m-6.53-2.75a2.95 2.95 0 0 1-.36-2.01l.095.057L5.29 12.09a.53.53 0 0 0 .527 0l3.949-2.246v1.555a.05.05 0 0 1-.022.041L6.473 13.3c-1.454.826-3.311.335-4.15-1.098m-.85-6.94A3.02 3.02 0 0 1 3.07 3.949v3.785a.51.51 0 0 0 .262.451l3.93 2.237-1.366.779a.05.05 0 0 1-.048 0L2.585 9.342a2.98 2.98 0 0 1-1.113-4.094zm11.216 2.571L8.747 5.576l1.362-.776a.05.05 0 0 1 .048 0l3.265 1.86a3 3 0 0 1 1.173 1.207 2.96 2.96 0 0 1-.27 3.2 3.05 3.05 0 0 1-1.36.997V8.279a.52.52 0 0 0-.276-.445m1.36-2.015-.097-.057-3.226-1.855a.53.53 0 0 0-.53 0L6.249 6.153V4.598a.04.04 0 0 1 .019-.04L9.533 2.7a3.07 3.07 0 0 1 3.257.139c.474.325.843.778 1.066 1.303.223.526.289 1.103.191 1.664zM5.503 8.575 4.139 7.8a.05.05 0 0 1-.026-.037V4.049c0-.57.166-1.127.476-1.607s.752-.864 1.275-1.105a3.08 3.08 0 0 1 3.234.41l-.096.054-3.23 1.838a.53.53 0 0 0-.265.455zm.742-1.577 1.758-1 1.762 1v2l-1.755 1-1.762-1z"})})}function Zu({size:l=16,color:d="currentColor",style:c}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:l,fill:d,viewBox:"0 0 28 28",style:c,children:s.jsx("path",{d:"M14 28C14 26.0633 13.6267 24.2433 12.88 22.54C12.1567 20.8367 11.165 19.355 9.905 18.095C8.645 16.835 7.16333 15.8433 5.46 15.12C3.75667 14.3733 1.93667 14 0 14C1.93667 14 3.75667 13.6383 5.46 12.915C7.16333 12.1683 8.645 11.165 9.905 9.905C11.165 8.645 12.1567 7.16333 12.88 5.46C13.6267 3.75667 14 1.93667 14 0C14 1.93667 14.3617 3.75667 15.085 5.46C15.8317 7.16333 16.835 8.645 18.095 9.905C19.355 11.165 20.8367 12.1683 22.54 12.915C24.2433 13.6383 26.0633 14 28 14C26.0633 14 24.2433 14.3733 22.54 15.12C20.8367 15.8433 19.355 16.835 18.095 18.095C16.835 19.355 15.8317 20.8367 15.085 22.54C14.3617 24.2433 14 26.0633 14 28Z"})})}function ey({size:l=16,color:d="currentColor",style:c}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:l,fill:d,viewBox:"0 0 24 24",style:c,children:s.jsx("path",{d:"M3 3v18h18V3zm11.72 13.37c-.41.38-.82.66-1.33.87l-.21.09c-.83.3-1.82.21-2.63-.1-.45-.21-.82-.46-1.19-.8.33-.41.66-.75 1.07-1.07l.27.21c.5.35 1 .47 1.61.41.62-.12 1.12-.4 1.52-.9.37-.61.41-1.09.41-1.8V10.4c0-.72-.15-1.18-.6-1.74-.61-.49-1.17-.74-1.96-.7-.66.11-1.19.42-1.59.95-.33.53-.48 1.07-.37 1.69.2.68.45 1.25 1.07 1.61.52.27.98.32 1.56.33h.25c.2.02.4.02.61.03V14c-1.49.06-2.65.06-3.84-.97a4.22 4.22 0 0 1-1.23-2.8c.04-.88.35-1.6.86-2.32l.15-.23c1.43-1.51 3.7-1.61 5.31-.31l.17.14c.58.52.96 1.25 1.08 2.01 0 .16.01.33.01.49v3.6c0 1.05-.3 1.95-1.02 2.74Z"})})}function ty({size:l=16,color:d="currentColor",style:c}){return s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:l,fill:"none",stroke:d,viewBox:"0 0 512 512",style:c,children:[s.jsx("path",{d:"M3 248.945C18 248.945 76 236 106 219C136 202 136 202 198 158C276.497 102.293 332 120.945 423 120.945",strokeWidth:"90",strokeLinecap:"round"}),s.jsx("path",{d:"M511 121.5L357.25 210.268L357.25 32.7324L511 121.5Z",fill:d,stroke:"none"}),s.jsx("path",{d:"M0 249C15 249 73 261.945 103 278.945C133 295.945 133 295.945 195 339.945C273.497 395.652 329 377 420 377",strokeWidth:"90",strokeLinecap:"round"}),s.jsx("path",{d:"M508 376.445L354.25 287.678L354.25 465.213L508 376.445Z",fill:d,stroke:"none"})]})}function ry({size:l=16,color:d="currentColor",style:c}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:l,fill:d,viewBox:"0 0 24 24",style:c,children:s.jsx("path",{d:"M12 2C8.5 2 6 4.5 6 7.5c0 1.5.6 2.8 1.5 3.8-.3.5-.5 1.1-.5 1.7v5c0 1.7 1.3 3 3 3h4c1.7 0 3-1.3 3-3v-5c0-.6-.2-1.2-.5-1.7.9-1 1.5-2.3 1.5-3.8C18 4.5 15.5 2 12 2zm-2 8.5c-.6 0-1-.7-1-1.5s.4-1.5 1-1.5 1 .7 1 1.5-.4 1.5-1 1.5zm4 0c-.6 0-1-.7-1-1.5s.4-1.5 1-1.5 1 .7 1 1.5-.4 1.5-1 1.5zm-4.5 3.5c0-.3.2-.5.5-.5h4c.3 0 .5.2.5.5s-.2.5-.5.5h-4c-.3 0-.5-.2-.5-.5z"})})}function iy({size:l=16,color:d="currentColor",style:c}){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:l,fill:d,viewBox:"0 0 24 24",style:c,children:s.jsx("path",{d:"M4 3h16c1.1 0 2 .9 2 2v10c0 1.1-.9 2-2 2h-6l-4 4v-4H4c-1.1 0-2-.9-2-2V5c0-1.1.9-2 2-2zm1 3v2h2V6H5zm0 3v2h2V9H5zm0 3v2h2v-2H5zm4-6v8h6V6H9zm7 0v2h2V6h-2zm0 3v2h2V9h-2z"})})}const vp={anthropic:Xu,openai:Ju,google:Zu,groq:ey,openrouter:ty,ollama:ry,lmstudio:iy};function ny(l){const d=new Map;for(const u of l)if(u.role==="user"&&Array.isArray(u.content))for(const h of u.content)h.type==="tool_result"&&d.set(h.tool_use_id,h);const c=[];for(const u of l)if(u.role==="user"&&typeof u.content=="string")c.push({kind:"user",text:u.content});else if(u.role==="assistant"&&Array.isArray(u.content))for(const h of u.content)h.type==="text"&&c.push({kind:"assistant",parts:[h]}),h.type==="tool_use"&&c.push({kind:"tool",tu:h,result:d.get(h.id)});return c}function sy(l){const d=/```[\w]*\n?([\s\S]*?)```/g,c=[];let u=0,h=0,v;for(;(v=d.exec(l))!==null;)v.index>u&&c.push(cp(l.slice(u,v.index),h++)),c.push(s.jsx("pre",{style:{background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,padding:"10px 14px",overflowX:"auto",fontSize:"0.8rem",margin:"8px 0"},children:s.jsx("code",{children:v[1].trim()})},h++)),u=v.index+v[0].length;return u<l.length&&c.push(cp(l.slice(u),h++)),c}function cp(l,d){const c=l.split(/(`[^`\n]+`|\*\*[^*]+\*\*)/g);return s.jsx("span",{style:{whiteSpace:"pre-wrap"},children:c.map((u,h)=>u.startsWith("`")&&u.endsWith("`")?s.jsx("code",{style:{background:"var(--surface3)",padding:"1px 5px",borderRadius:4,fontSize:"0.82em"},children:u.slice(1,-1)},h):u.startsWith("**")&&u.endsWith("**")?s.jsx("strong",{children:u.slice(2,-2)},h):u)},d)}async function oy(l,d){const c=await fetch("/api/report/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdown:l,title:"NowAIKit Chat Export",format:d})});if(!c.ok)throw new Error(`Report generation failed: ${c.status}`);const u=await c.blob(),h=URL.createObjectURL(u),v=document.createElement("a");v.href=h,v.download=`chat-export-${Date.now()}.${d}`,document.body.appendChild(v),v.click(),document.body.removeChild(v),URL.revokeObjectURL(h)}function ay(l){return l.length>500&&/^#{1,3}\s/m.test(l)}function ly({text:l}){const[d,c]=z.useState(null);async function u(v){c(v);try{await oy(l,v)}catch{}finally{c(null)}}const h={background:"var(--surface)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text2)",padding:"2px 8px",fontSize:"0.7rem",fontWeight:600,cursor:"pointer",transition:"all .15s"};return s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[s.jsx("span",{style:{fontSize:"0.68rem",color:"var(--dim)"},children:"Export:"}),s.jsx("button",{onClick:()=>u("pdf"),disabled:d!==null,style:{...h,opacity:d?.5:1},children:d==="pdf"?"…":"PDF"}),s.jsx("button",{onClick:()=>u("pptx"),disabled:d!==null,style:{...h,opacity:d?.5:1},children:d==="pptx"?"…":"PPTX"})]})}function cy({tu:l,result:d}){const[c,u]=z.useState(!1),h=d&&!d.is_error;return s.jsxs("div",{style:{background:"#1a1f35",border:"1px solid #2e3a5f",borderRadius:8,fontSize:"0.78rem",overflow:"hidden",fontFamily:"monospace"},children:[s.jsxs("button",{onClick:()=>u(v=>!v),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 10px",background:"transparent",border:"none",color:"#93c5fd",cursor:"pointer",textAlign:"left"},children:[s.jsx("span",{style:{fontSize:"0.7rem",opacity:.7},children:c?"▼":"▶"}),s.jsx("span",{style:{fontWeight:600},children:l.name}),d&&s.jsx("span",{className:h?"badge-green":"badge-red",style:{marginLeft:"auto"},children:h?"ok":"error"}),!d&&s.jsx("span",{className:"badge-dim",style:{marginLeft:"auto"},children:"running…"})]}),c&&s.jsxs("div",{style:{padding:"8px 10px",borderTop:"1px solid #2e3a5f"},children:[s.jsx("div",{style:{color:"var(--dim)",fontSize:"0.68rem",marginBottom:3,letterSpacing:"0.05em"},children:"INPUT"}),s.jsx("pre",{style:{fontSize:"0.74rem",overflowX:"auto",color:"#a5f3fc",marginBottom:d?8:0},children:JSON.stringify(l.input,null,2)}),d&&s.jsxs(s.Fragment,{children:[s.jsx("div",{style:{color:"var(--dim)",fontSize:"0.68rem",marginBottom:3,letterSpacing:"0.05em"},children:d.is_error?"ERROR":"OUTPUT"}),s.jsx("pre",{style:{fontSize:"0.74rem",overflowX:"auto",color:d.is_error?"var(--red)":"#a5f3fc"},children:d.content})]})]})]})}const ra=new Set(["ollama","lmstudio"]),pp=[{id:"anthropic",label:"Claude"},{id:"openai",label:"ChatGPT"},{id:"google",label:"Gemini"},{id:"groq",label:"Groq"},{id:"openrouter",label:"OpenRouter"},{id:"ollama",label:"Ollama"},{id:"lmstudio",label:"LM Studio"}],dp={anthropic:[{value:"claude-opus-5",label:"Claude Opus 5"},{value:"claude-fable-5",label:"Claude Fable 5"},{value:"claude-sonnet-5",label:"Claude Sonnet 5"},{value:"claude-haiku-4-5-20251001",label:"Claude Haiku 4.5"}],openai:[{value:"gpt-5.6-sol",label:"GPT-5.6 Sol"},{value:"gpt-5.6-terra",label:"GPT-5.6 Terra"},{value:"gpt-5.6-luna",label:"GPT-5.6 Luna"},{value:"gpt-5.5",label:"GPT-5.5"}],google:[{value:"gemini-3.1-pro-preview",label:"Gemini 3.1 Pro"},{value:"gemini-3-pro-preview",label:"Gemini 3 Pro"},{value:"gemini-3-flash-preview",label:"Gemini 3 Flash"},{value:"gemini-2.5-flash",label:"Gemini 2.5 Flash"},{value:"gemini-2.5-pro",label:"Gemini 2.5 Pro"}],groq:[{value:"meta-llama/llama-4-maverick-17b-128e-instruct",label:"Llama 4 Maverick"},{value:"meta-llama/llama-4-scout-17b-16e-instruct",label:"Llama 4 Scout"},{value:"llama-3.3-70b-versatile",label:"Llama 3.3 70B"},{value:"llama-3.1-8b-instant",label:"Llama 3.1 8B"}],openrouter:[{value:"openai/o1-pro",label:"OpenAI o1 Pro"},{value:"xai/grok-4",label:"Grok 4 (xAI)"},{value:"anthropic/claude-sonnet-5",label:"Claude Sonnet 5"},{value:"google/gemini-3-flash-preview",label:"Gemini 3 Flash"},{value:"deepseek/deepseek-r1:free",label:"DeepSeek R1 (free)"},{value:"meta-llama/llama-4-maverick-17b-128e-instruct",label:"Llama 4 Maverick"},{value:"meta-llama/llama-3.3-70b-instruct",label:"Llama 3.3 70B"},{value:"google/gemma-2-9b-it:free",label:"Gemma 2 9B (free)"}],ollama:[{value:"llama3.3:latest",label:"Llama 3.3 70B"},{value:"llama3.2:latest",label:"Llama 3.2 3B"},{value:"qwen3:latest",label:"Qwen 3"},{value:"deepseek-r1:latest",label:"DeepSeek R1"},{value:"gemma3:latest",label:"Gemma 3"},{value:"phi4:latest",label:"Phi-4"},{value:"mistral:latest",label:"Mistral"},{value:"granite3.3:latest",label:"Granite 3.3"}],lmstudio:[{value:"llama-3.3-70b",label:"Llama 3.3 70B"},{value:"qwen3-8b",label:"Qwen 3 8B"},{value:"deepseek-r1-distill",label:"DeepSeek R1 Distill"},{value:"gemma-3-9b",label:"Gemma 3 9B"},{value:"phi-4",label:"Phi-4"},{value:"mistral-7b",label:"Mistral 7B"}]},py=["Show me my 5 most recent open incidents","List all critical change requests scheduled for this week","Find all CIs with no owner assigned","What problems have been open for more than 30 days?"],up=128,dy=new Set(["query_records","get_record","get_table_schema","get_user","get_group","get_incident","create_incident","update_incident","resolve_incident","get_change_request","list_change_requests","create_change_request","update_change_request","get_task","list_my_tasks","update_task","get_problem","create_problem","update_problem","search_knowledge","get_knowledge_article","add_work_note","add_comment","search_cmdb_ci","get_cmdb_ci","list_users","list_groups","natural_language_search"]),yp={incident:["incident","resolve_incident","close_incident","add_work_note","add_comment"],incidents:["incident","query_records"],change:["change_request","change"],changes:["change_request","query_records"],problem:["problem"],problems:["problem","query_records"],task:["task"],tasks:["task","query_records"],user:["user","get_user"],users:["user","list_users","query_records"],group:["group"],groups:["group","list_groups"],knowledge:["knowledge"],kb:["knowledge"],ci:["cmdb","ci"],cmdb:["cmdb","ci"],server:["cmdb","ci_server"],catalog:["catalog"],flow:["flow"],report:["report","aggregate","trend"],sla:["sla"],approval:["approval"],hr:["hr_"],security:["security"],vulnerability:["vulnerab"],asset:["asset"],license:["license"],portal:["portal"],widget:["widget"],script:["script","business_rule"],acl:["acl"],notification:["notification","email"],atf:["atf"],test:["atf","test"]};function mp(l){return l.endsWith("ies")?l.slice(0,-3)+"y":l.endsWith("ses")||l.endsWith("xes")||l.endsWith("zes")||l.endsWith("es")?l.slice(0,-2):l.endsWith("s")&&!l.endsWith("ss")?l.slice(0,-1):l.endsWith("ing")&&l.length>5?l.slice(0,-3):l.endsWith("ed")&&l.length>4?l.slice(0,-2):l}function uy(l,d){if(l.length<=up)return l;const u=d.toLowerCase().split(/\s+/).filter(b=>b.length>2),h=[...new Set([...u,...u.map(mp)])],v=[];for(const b of u){const k=yp[b]||yp[mp(b)];k&&v.push(...k)}const C=l.map(b=>{let k=0;const q=b.name.toLowerCase(),T=(b.description||"").toLowerCase();dy.has(b.name)&&(k+=5);for(const B of h)q.includes(B)&&(k+=3),T.includes(B)&&(k+=1);for(const B of v)q.includes(B)&&(k+=4);return(q.startsWith("list_")||q.startsWith("get_")||q.startsWith("search_"))&&(k+=1),{tool:b,score:k}});return C.sort((b,k)=>k.score-b.score),C.slice(0,up).map(b=>b.tool)}const yy=8;async function my(l,d,c,u,h,v,C){if(!d&&!ra.has(l))return{error:"No API key configured. Go to Settings to add one."};const b=It;let k=[...u];try{for(let q=0;q<yy;q++){const T=k.map(D=>({role:D.role,content:D.content})),B=await b.sendChat({provider:l,apiKey:d,model:c,messages:T,tools:h.length>0?h:void 0,baseUrl:C});if(B.error)return{error:B.error};const fe=(B.content??[]).map(D=>D.type==="tool_use"?{type:"tool_use",id:D.id??`toolu_${Date.now()}`,name:D.name??"",input:D.input??{}}:{type:"text",text:D.text??""});k=[...k,{role:"assistant",content:fe}],v(k);const ne=fe.filter(D=>D.type==="tool_use");if(ne.length===0||B.stop_reason!=="tool_use")return{messages:k};const K=[];for(const D of ne)try{const W=await b.executeTool(D.name,D.input),Z=W.success?typeof W.result=="string"?W.result:JSON.stringify(W.result,null,2):`Error: ${W.error??"Tool execution failed"}`;K.push({type:"tool_result",tool_use_id:D.id,content:Z,is_error:!W.success})}catch(W){K.push({type:"tool_result",tool_use_id:D.id,content:`Error: ${W instanceof Error?W.message:"Unknown error"}`,is_error:!0})}k=[...k,{role:"user",content:K}],v(k)}return{messages:k,error:"Tool execution limit reached. The AI made too many consecutive tool calls."}}catch(q){return{error:q instanceof Error?q.message:"Request failed"}}}const Fi="nowaikit_chat_history";function fy(l,d){try{const c=JSON.parse(localStorage.getItem(Fi)||"{}");c[l]=d,localStorage.setItem(Fi,JSON.stringify(c))}catch{}}function fp(l){try{return JSON.parse(localStorage.getItem(Fi)||"{}")[l]||[]}catch{return[]}}function gy(l){try{const d=JSON.parse(localStorage.getItem(Fi)||"{}");delete d[l],localStorage.setItem(Fi,JSON.stringify(d))}catch{}}function hy({settings:l,serverUrl:d,instances:c}){var ge;const[u,h]=z.useState(l.activeProvider||"anthropic"),[v,C]=z.useState(l.model||"claude-sonnet-5"),[b,k]=z.useState(()=>fp(l.activeProvider||"anthropic")),[q,T]=z.useState(""),[B,V]=z.useState(!1),[fe,ne]=z.useState(""),[K,D]=z.useState([]),[W,Z]=z.useState(!1),[j,M]=z.useState(""),[m,N]=z.useState(0),ee=z.useRef(null),w=z.useRef(null),G=z.useRef(null),F=z.useRef(u);z.useEffect(()=>{F.current===u&&fy(u,b)},[b,u]),z.useEffect(()=>{const I=dp[u],Y=I[0].value;I.find($=>$.value===v)||C(Y),k(fp(u)),ne(""),F.current=u},[u]),z.useEffect(()=>{var I;(I=ee.current)==null||I.scrollIntoView({behavior:"smooth"})},[b,B]),z.useEffect(()=>{It.listTools().then(Y=>D(Y??[])).catch(()=>{})},[]),z.useEffect(()=>{if(!W)return;const I=Y=>{var $,ve;!(($=G.current)!=null&&$.contains(Y.target))&&!((ve=w.current)!=null&&ve.contains(Y.target))&&Z(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[W]);const X=l.providers[u],ae=ra.has(u),he=ae||!!(X!=null&&X.apiKey),ke=c.find(I=>I.active),Le=ny(b),Ee=j?K.filter(I=>{var Y;return I.name.toLowerCase().includes(j.toLowerCase())||((Y=I.description)==null?void 0:Y.toLowerCase().includes(j.toLowerCase()))}):K,le=Ee.slice(0,10);function U(I){const Y=I.target.value;T(Y);const $=Y.match(/(?:^|\s)\/([\w_]*)$/);$?(M($[1]),N(0),Z(!0)):Z(!1)}function se(I){var $;const Y=q.replace(/(?:^|\s)\/([\w_]*)$/,ve=>`${ve.startsWith(" ")?" ":""}/${I.name} `);T(Y),Z(!1),($=w.current)==null||$.focus()}async function H(I){const Y=(I??q).trim();if(!Y||B)return;T(""),ne(""),Z(!1);const $=Y.replace(/\/([\w_]+)/g,(_e,E)=>K.find(me=>me.name===E)?`(use tool: ${E})`:_e),ve=[...b,{role:"user",content:Y}];k(ve),V(!0);try{const _e=uy(K,Y),E=await my(u,(X==null?void 0:X.apiKey)??"",v,ve,_e,oe=>k(oe),X==null?void 0:X.baseUrl);if(V(!1),E.error){ne(E.error);return}E.messages&&k(E.messages)}catch(_e){V(!1),ne(_e instanceof Error?_e.message:"Chat request failed")}}function g(I){if(W&&le.length>0){if(I.key==="ArrowDown"){I.preventDefault(),N(Y=>Math.min(Y+1,le.length-1));return}if(I.key==="ArrowUp"){I.preventDefault(),N(Y=>Math.max(Y-1,0));return}if(I.key==="Tab"||I.key==="Enter"&&W){I.preventDefault(),le[m]&&se(le[m]);return}if(I.key==="Escape"){Z(!1);return}}I.key==="Enter"&&!I.shiftKey&&(I.preventDefault(),H())}const A={background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",padding:"6px 10px",fontSize:"0.8rem"};return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100vh - 56px)",maxWidth:900,margin:"0 auto"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16,gap:12,flexWrap:"wrap"},children:[s.jsxs("div",{style:{minWidth:0},children:[s.jsxs("h2",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[s.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),"AI Chat"]}),ke&&s.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Instance: ",ke.name," · ",ke.url]})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,flexWrap:"wrap"},children:[s.jsx("div",{style:{display:"flex",border:"1px solid var(--border)",borderRadius:6,overflow:"hidden"},children:pp.map(I=>{var $;const Y=ra.has(I.id)||!!(($=l.providers[I.id])!=null&&$.apiKey);return s.jsxs("button",{onClick:()=>h(I.id),style:{padding:"5px 12px",border:"none",fontSize:"0.78rem",cursor:"pointer",background:u===I.id?"var(--accent)":"transparent",color:u===I.id?"#fff":Y?"var(--text2)":"var(--dim)",fontWeight:u===I.id?600:400,transition:"all .15s",display:"flex",alignItems:"center",gap:5},children:[sa.createElement(vp[I.id]??(()=>null),{size:14,color:u===I.id?"#fff":"currentColor"})," ",I.label,Y&&u!==I.id&&s.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--green)"}})]},I.id)})}),s.jsx("select",{value:v,onChange:I=>C(I.target.value),style:A,children:dp[u].map(I=>s.jsx("option",{value:I.value,children:I.label},I.value))}),b.length>0&&s.jsx(s.Fragment,{children:s.jsx("button",{className:"btn-ghost",onClick:()=>{gy(u),k([]),ne("")},style:{padding:"6px 14px",fontSize:"0.8rem"},children:"New Chat"})})]})]}),!he&&!ae&&s.jsxs("div",{style:{background:"rgba(251,191,36,0.1)",border:"1px solid rgba(251,191,36,0.3)",borderRadius:8,padding:"12px 16px",marginBottom:16,fontSize:"0.875rem",color:"var(--yellow)"},children:["No API key for ",s.jsx("strong",{children:(ge=pp.find(I=>I.id===u))==null?void 0:ge.label}),". Go to ",s.jsx("strong",{children:"Settings → AI Providers"})," to add your key."]}),s.jsxs("div",{style:{flex:1,overflowY:"auto",marginBottom:16,display:"flex",flexDirection:"column",gap:4},children:[Le.length===0&&s.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:24,color:"var(--dim)"},children:[s.jsxs("div",{style:{textAlign:"center"},children:[s.jsx("div",{style:{fontSize:"1.8rem",marginBottom:8},children:"🔗"}),s.jsx("div",{style:{fontSize:"0.95rem",color:"var(--text2)",fontWeight:500},children:"Ask anything about your ServiceNow instance"}),s.jsxs("div",{style:{fontSize:"0.8rem",marginTop:4},children:["Type ",s.jsx("code",{style:{background:"var(--surface2)",padding:"1px 5px",borderRadius:3},children:"/"})," to browse & run tools · Shift+Enter for new line"]})]}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,width:"100%",maxWidth:560},children:py.map(I=>s.jsx("button",{onClick:()=>H(I),style:{background:"var(--surface)",border:"1px solid var(--border)",borderRadius:8,color:"var(--text2)",padding:"10px 14px",textAlign:"left",fontSize:"0.85rem",cursor:"pointer",transition:"all .15s"},children:I},I))})]}),Le.map((I,Y)=>{if(I.kind==="user")return s.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:6},children:s.jsx("div",{style:{background:"var(--accent)",color:"#fff",borderRadius:8,padding:"10px 12px",maxWidth:"88%",fontSize:"0.85rem",lineHeight:1.5},children:I.text})},Y);if(I.kind==="assistant"){const $=I.parts[0].text;return s.jsx("div",{style:{display:"flex",justifyContent:"flex-start",marginBottom:6},children:s.jsxs("div",{style:{background:"var(--surface2)",borderRadius:8,padding:"10px 12px",maxWidth:"88%",fontSize:"0.85rem",lineHeight:1.5},children:[sy($),ay($)&&s.jsx(ly,{text:$})]})},Y)}return I.kind==="tool"?s.jsx("div",{style:{maxWidth:"95%",marginBottom:4},children:s.jsx(cy,{tu:I.tu,result:I.result})},Y):null}),B&&s.jsx("div",{style:{display:"flex",justifyContent:"flex-start",marginBottom:4},children:s.jsx("div",{style:{background:"var(--surface)",border:"1px solid var(--border)",borderRadius:"3px 14px 14px 14px",padding:"12px 16px"},children:s.jsx("div",{style:{display:"flex",gap:5,alignItems:"center"},children:[0,1,2].map(I=>s.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:"var(--dim)",animation:`bounce .9s ease-in-out ${I*.2}s infinite alternate`}},I))})})}),fe&&s.jsx("div",{style:{background:"rgba(248,113,113,0.1)",border:"1px solid rgba(248,113,113,0.3)",borderRadius:8,padding:"10px 14px",color:"var(--red)",fontSize:"0.85rem"},children:fe}),s.jsx("div",{ref:ee})]}),W&&le.length>0&&s.jsx("div",{ref:G,style:{position:"relative",marginBottom:4},children:s.jsxs("div",{style:{position:"absolute",bottom:"100%",left:0,right:0,background:"var(--surface)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.4)",zIndex:50,maxHeight:280,overflowY:"auto"},children:[s.jsx("div",{style:{padding:"8px 12px 6px",fontSize:"0.7rem",color:"var(--dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Tools — Tab or Enter to select · Esc to close"}),le.map((I,Y)=>s.jsxs("button",{onMouseDown:$=>{$.preventDefault(),se(I)},style:{display:"flex",alignItems:"baseline",gap:10,width:"100%",padding:"8px 12px",background:Y===m?"var(--accent-bg)":"transparent",border:"none",cursor:"pointer",textAlign:"left",transition:"background .1s",borderBottom:Y<le.length-1?"1px solid var(--border)":"none"},children:[s.jsxs("code",{style:{color:"var(--accent)",fontWeight:600,fontSize:"0.8rem",flexShrink:0},children:["/",I.name]}),s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text2)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.description})]},I.name)),K.length>10&&s.jsxs("div",{style:{padding:"6px 12px",fontSize:"0.72rem",color:"var(--dim)",borderTop:"1px solid var(--border)"},children:[Ee.length," tools · type to filter"]})]})}),s.jsxs("div",{style:{display:"flex",gap:10,alignItems:"flex-end",paddingBottom:4},children:[s.jsx("textarea",{ref:w,value:q,onChange:U,onKeyDown:g,placeholder:"Ask anything… or type / to browse tools (Enter to send)",rows:1,disabled:B||!he,style:{flex:1,background:"var(--surface2)",border:"1px solid var(--border)",borderRadius:10,color:"var(--text)",padding:"11px 14px",fontSize:"0.9rem",resize:"none",outline:"none",transition:"border-color .15s, box-shadow .15s",minHeight:46,maxHeight:160,lineHeight:1.5,...q?{borderColor:"var(--accent)",boxShadow:"0 0 0 3px var(--accent-bg)"}:{}}}),s.jsx("button",{onClick:()=>H(),disabled:B||!q.trim()||!he,className:"btn-primary",style:{padding:"11px 20px",borderRadius:10,flexShrink:0,opacity:B||!q.trim()||!he?.45:1},children:B?s.jsx("span",{className:"spinner",style:{width:16,height:16,borderWidth:2}}):"Send"})]}),s.jsx("style",{children:`
53
53
  @keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-5px); } }
54
54
  textarea:focus { border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--accent-bg) !important; }
@@ -49,7 +49,7 @@ export function buildAgentCard() {
49
49
  }
50
50
  return {
51
51
  name: 'NowAIKit',
52
- description: 'The most comprehensive ServiceNow AI toolkit — 400+ tools covering ITSM, CMDB, HRSD, CSM, SecOps, GRC, DevOps, and more.',
52
+ description: 'The most comprehensive ServiceNow AI toolkit: 500+ tools covering ITSM, CMDB, HRSD, CSM, SecOps, GRC, DevOps, and more.',
53
53
  url: baseUrl,
54
54
  version: VERSION,
55
55
  capabilities: {
@@ -1 +1 @@
1
- {"version":3,"file":"agent-card.js","sourceRoot":"","sources":["../../src/a2a/agent-card.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,qDAAqD;AACrD,MAAM,UAAU,GAA0E;IACxF,QAAQ,EAAE,EAAE,IAAI,EAAE,qBAAqB,E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C,CAAC,CAAE,CAAC;AACjC,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC"}
@@ -1,3 +1,17 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ /**
3
+ * nowaikit CLI entry point.
4
+ *
5
+ * Commands:
6
+ * nowaikit setup [--add] — interactive setup wizard
7
+ * nowaikit web — start the web dashboard in your browser
8
+ * nowaikit auth login — per-user OAuth login
9
+ * nowaikit auth logout — remove stored token
10
+ * nowaikit auth whoami — show current authenticated user
11
+ * nowaikit instances list — list configured instances
12
+ * nowaikit instances remove <name> — remove an instance
13
+ * nowaikit capabilities — list all 26 Apex capabilities
14
+ * nowaikit run <capability> — run a capability in direct mode (BYOK)
15
+ */
16
+ import './suppress-warnings.js';
3
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AACH,OAAO,wBAAwB,CAAC"}
package/dist/cli/index.js CHANGED
@@ -13,6 +13,7 @@
13
13
  * nowaikit capabilities — list all 26 Apex capabilities
14
14
  * nowaikit run <capability> — run a capability in direct mode (BYOK)
15
15
  */
16
+ import './suppress-warnings.js'; // must be first: installs the warning filter before ora/cli-spinners load
16
17
  import { Command } from 'commander';
17
18
  import chalk from 'chalk';
18
19
  import { execSync, spawn } from 'child_process';
@@ -87,7 +88,9 @@ async function checkForUpdate() {
87
88
  async function installUpdate(version) {
88
89
  const { spawnSync } = await import('node:child_process');
89
90
  console.log(dim(` Installing nowaikit@${version} ...`));
90
- const r = spawnSync('npm', ['install', '-g', `nowaikit@${version}`], { stdio: 'inherit' });
91
+ // shell:true on Windows so `npm` resolves to npm.cmd (a bare spawn can't find the .cmd and the
92
+ // self-update silently "fails"). POSIX doesn't need a shell.
93
+ const r = spawnSync('npm', ['install', '-g', `nowaikit@${version}`], { stdio: 'inherit', shell: process.platform === 'win32' });
91
94
  if (r.status === 0) {
92
95
  console.log(success(` ✓ Updated to ${version}`));
93
96
  return true;
@@ -137,7 +140,7 @@ async function maybePromptUpdate(latest) {
137
140
  }
138
141
  // Re-run the original command on the freshly installed version so it just works.
139
142
  const { spawnSync } = await import('node:child_process');
140
- const re = spawnSync('nowaikit', argv, { stdio: 'inherit', env: { ...process.env, NOWAIKIT_NO_UPDATE_CHECK: '1' } });
143
+ const re = spawnSync('nowaikit', argv, { stdio: 'inherit', shell: process.platform === 'win32', env: { ...process.env, NOWAIKIT_NO_UPDATE_CHECK: '1' } });
141
144
  if (re.error) {
142
145
  console.log(dim(` Run your command again to use ${latest}.`));
143
146
  process.exit(0);