@casys/mcp-erpnext 2.2.0 → 2.2.2
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/mcp-erpnext.mjs +1109 -256
- package/package.json +1 -1
- package/ui-dist/chart-viewer/index.html +10 -10
- package/ui-dist/doclist-viewer/index.html +10 -10
- package/ui-dist/funnel-viewer/index.html +10 -10
- package/ui-dist/invoice-viewer/index.html +11 -11
- package/ui-dist/kanban-viewer/index.html +10 -10
- package/ui-dist/kpi-viewer/index.html +10 -10
- package/ui-dist/stock-viewer/index.html +11 -11
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Stock Viewer - mcp-erpnext</title>
|
|
7
|
+
<script type="module" crossorigin>(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const u of document.querySelectorAll('link[rel="modulepreload"]'))a(u);new MutationObserver(u=>{for(const f of u)if(f.type==="childList")for(const d of f.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&a(d)}).observe(document,{childList:!0,subtree:!0});function i(u){const f={};return u.integrity&&(f.integrity=u.integrity),u.referrerPolicy&&(f.referrerPolicy=u.referrerPolicy),u.crossOrigin==="use-credentials"?f.credentials="include":u.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function a(u){if(u.ep)return;u.ep=!0;const f=i(u);fetch(u.href,f)}})();var Xl={exports:{}},go={},ea={exports:{}},se={};/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react.production.min.js
|
|
10
10
|
*
|
|
@@ -119,10 +119,10 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
119
119
|
- omitted: host decides border`)});C({method:k("ui/request-display-mode"),params:C({mode:wo.describe("The display mode being requested.")})});var Ek=C({mode:wo.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),Tk=ue([k("model"),k("app")]).describe("Tool visibility scope - who can access the tool.");C({resourceUri:z().optional(),visibility:ne(Tk).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
120
120
|
- "model": Tool visible to and callable by the agent
|
|
121
121
|
- "app": Tool callable by the app from this server only`)});C({mimeTypes:ne(z()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')});C({method:k("ui/download-file"),params:C({contents:ne(ue([_p,wp])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})});C({method:k("ui/message"),params:C({role:k("user").describe('Message role, currently only "user" is supported.'),content:ne(Ro).describe("Message content blocks (text, image, etc.).")})});C({method:k("ui/notifications/sandbox-resource-ready"),params:C({html:z().describe("HTML content to load into the inner iframe."),sandbox:z().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:Ua.optional().describe("CSP configuration from resource metadata."),permissions:Ha.optional().describe("Sandbox permissions from resource metadata.")})});var Ck=C({method:k("ui/notifications/tool-result"),params:is.describe("Standard MCP tool execution result.")}),zp=C({toolInfo:C({id:So.optional().describe("JSON-RPC id of the tools/call request."),tool:Fa.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:dk.optional().describe("Current color theme preference."),styles:kk.optional().describe("Style configuration for theming the app."),displayMode:wo.optional().describe("How the UI is currently displayed."),availableDisplayModes:ne(wo).optional().describe("Display modes the host supports."),containerDimensions:ue([C({height:le().describe("Fixed container height in pixels.")}),C({maxHeight:ue([le(),ca()]).optional().describe("Maximum container height in pixels.")})]).and(ue([C({width:le().describe("Fixed container width in pixels.")}),C({maxWidth:ue([le(),ca()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
122
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:z().optional().describe("User's language and region preference in BCP 47 format."),timeZone:z().optional().describe("User's timezone in IANA format."),userAgent:z().optional().describe("Host application identifier."),platform:ue([k("web"),k("desktop"),k("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:C({touch:ze().optional().describe("Whether the device supports touch input."),hover:ze().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:C({top:le().describe("Top safe area inset in pixels."),right:le().describe("Right safe area inset in pixels."),bottom:le().describe("Bottom safe area inset in pixels."),left:le().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),Rk=C({method:k("ui/notifications/host-context-changed"),params:zp.describe("Partial context update containing only changed fields.")});C({method:k("ui/update-model-context"),params:C({content:ne(Ro).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:we(z(),ke().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});C({method:k("ui/initialize"),params:C({appInfo:rs.describe("App identification (name and version)."),appCapabilities:zk.describe("Features and capabilities this app provides."),protocolVersion:z().describe("Protocol version this app supports.")})});var Pk=C({protocolVersion:z().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:rs.describe("Host application identification and version."),hostCapabilities:xk.describe("Features and capabilities provided by the host."),hostContext:zp.describe("Rich context about the host environment.")}).passthrough();class Nk extends lk{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(o,i={},a={autoResize:!0}){super(a),this._appInfo=o,this._capabilities=i,this.options=a,this.setRequestHandler(os,u=>(console.log("Received ping:",u.params),{})),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(o){this.setNotificationHandler(vk,i=>o(i.params))}set ontoolinputpartial(o){this.setNotificationHandler(yk,i=>o(i.params))}set ontoolresult(o){this.setNotificationHandler(Ck,i=>o(i.params))}set ontoolcancelled(o){this.setNotificationHandler(_k,i=>o(i.params))}set onhostcontextchanged(o){this.setNotificationHandler(Rk,i=>{this._hostContext={...this._hostContext,...i.params},o(i.params)})}set onteardown(o){this.setRequestHandler(Sk,(i,a)=>o(i.params,a))}set oncalltool(o){this.setRequestHandler(Sp,(i,a)=>o(i.params,a))}set onlisttools(o){this.setRequestHandler(kp,(i,a)=>o(i.params,a))}assertCapabilityForMethod(o){}assertRequestHandlerCapability(o){switch(o){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${o})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${o} registered`)}}assertNotificationCapability(o){}assertTaskCapability(o){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(o){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(o,i){if(typeof o=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${o}"). Did you mean: callServerTool({ name: "${o}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:o},is,i)}async readServerResource(o,i){return await this.request({method:"resources/read",params:o},yp,i)}async listServerResources(o,i){return await this.request({method:"resources/list",params:o},vp,i)}sendMessage(o,i){return this.request({method:"ui/message",params:o},gk,i)}sendLog(o){return this.notification({method:"notifications/message",params:o})}updateModelContext(o,i){return this.request({method:"ui/update-model-context",params:o},Ta,i)}openLink(o,i){return this.request({method:"ui/open-link",params:o},hk,i)}sendOpenLink=this.openLink;downloadFile(o,i){return this.request({method:"ui/download-file",params:o},mk,i)}requestDisplayMode(o,i){return this.request({method:"ui/request-display-mode",params:o},Ek,i)}sendSizeChanged(o){return this.notification({method:"ui/notifications/size-changed",params:o})}setupSizeChangedNotifications(){let o=!1,i=0,a=0,u=()=>{o||(o=!0,requestAnimationFrame(()=>{o=!1;let d=document.documentElement,h=d.style.width,v=d.style.height;d.style.width="fit-content",d.style.height="max-content";let S=d.getBoundingClientRect();d.style.width=h,d.style.height=v;let T=window.innerWidth-d.clientWidth,P=Math.ceil(S.width+T),I=Math.ceil(S.height);(P!==i||I!==a)&&(i=P,a=I,this.sendSizeChanged({width:P,height:I}))}))};u();let f=new ResizeObserver(u);return f.observe(document.documentElement),f.observe(document.body),()=>f.disconnect()}async connect(o=new ck(window.parent,window.parent),i){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(o);try{let a=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:ak}},Pk,i);if(a===void 0)throw Error(`Server sent invalid initialize result: ${a}`);this._hostCapabilities=a.hostCapabilities,this._hostInfo=a.hostInfo,this._hostContext=a.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(a){throw this.close(),a}}}function Fe(n){return`var(${n})`}const D={bg:{surface:Fe("--bg-surface"),elevated:Fe("--bg-elevated"),hover:Fe("--bg-hover")},text:{primary:Fe("--text-primary"),secondary:Fe("--text-secondary"),muted:Fe("--text-muted"),faint:Fe("--text-faint")},accent:Fe("--accent"),accentDim:Fe("--accent-dim"),border:Fe("--border"),borderSubtle:Fe("--border-subtle"),success:Fe("--success"),successDim:Fe("--success-dim"),error:Fe("--error"),errorDim:Fe("--error-dim"),warning:Fe("--warning"),warningDim:Fe("--warning-dim"),info:Fe("--info"),infoDim:Fe("--info-dim")},vt={sans:Fe("--font-sans"),mono:Fe("--font-mono")},Vt={card:{background:D.bg.surface,border:`1px solid ${D.border}`,borderRadius:"8px",padding:"16px"},badge:(n,o)=>({display:"inline-flex",alignItems:"center",padding:"2px 8px",fontSize:"11px",fontWeight:600,borderRadius:"4px",color:n,background:o,letterSpacing:"0.02em"}),input:{background:D.bg.elevated,border:`1px solid ${D.border}`,borderRadius:"6px",padding:"6px 12px",fontSize:"13px",color:D.text.primary,outline:"none",transition:"border-color 0.15s",width:"100%",fontFamily:vt.sans},button:{background:D.bg.elevated,border:`1px solid ${D.border}`,borderRadius:"6px",padding:"6px 14px",fontSize:"12px",color:D.text.secondary,cursor:"pointer",transition:"all 0.15s",fontFamily:vt.sans,whiteSpace:"nowrap"},buttonActive:{background:D.accentDim,borderColor:D.accent,color:D.accent},tableHeader:{padding:"8px 12px",textAlign:"left",fontSize:"11px",fontWeight:600,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",borderBottom:`1px solid ${D.border}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",transition:"color 0.15s"},tableCell:{padding:"8px 12px",fontSize:"13px",borderBottom:`1px solid ${D.borderSubtle}`,color:D.text.primary},mono:{fontFamily:vt.mono,fontSize:"12px"}};function Bi(n,o=2){return n.toLocaleString("en-US",{minimumFractionDigits:o,maximumFractionDigits:o})}function vf(n,o="USD"){return n.toLocaleString("en-US",{style:"currency",currency:o,minimumFractionDigits:2,maximumFractionDigits:2})}function Ik(){return j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[j.jsx("rect",{x:"1",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.9"}),j.jsx("rect",{x:"9",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),j.jsx("rect",{x:"1",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),j.jsx("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.35"})]})}function Ok(){const n={display:"flex",alignItems:"center",gap:7,padding:"0 14px",height:30,background:D.bg.surface,borderBottom:`1px solid ${D.border}`,flexShrink:0},o={fontFamily:vt.sans,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:D.accent},i={width:3,height:3,borderRadius:"50%",background:D.text.faint,marginLeft:2,marginRight:2,flexShrink:0},a={fontFamily:vt.sans,fontSize:10,color:D.text.muted,letterSpacing:"0.03em"};return j.jsxs("div",{style:n,children:[j.jsx("div",{style:{color:D.accent},children:j.jsx(Ik,{})}),j.jsx("span",{style:o,children:"ERPNext"}),j.jsx("div",{style:i}),j.jsx("span",{style:a,children:"gestion ERP"})]})}function $k(){const n={display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"6px 16px 8px",borderTop:`1px solid ${D.borderSubtle}`,marginTop:8},o={fontFamily:vt.sans,fontSize:10,color:D.text.faint,letterSpacing:"0.04em"};return j.jsx("div",{style:n,children:j.jsx("span",{style:o,children:"Casys AI"})})}function jk(n,o={}){return!n.request||n.visibilityState!=="visible"||n.refreshInFlight?!1:o.ignoreInterval?!0:n.now-n.lastRefreshStartedAt>=n.minIntervalMs}function yf(n,o){return n?.refreshRequest??o}function Mk(n){return n instanceof Error&&/timed? out/i.test(n.message)?"Refresh timed out":"Refresh failed"}function pa(n){return n.structuredContent?JSON.stringify(n.structuredContent):n.content?.find(o=>o.type==="text")?.text??null}function qi({label:n,value:o,bold:i}){return j.jsxs("div",{style:{padding:"4px 0"},children:[j.jsx("div",{style:{fontSize:10,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:2},children:n}),j.jsx("div",{style:{fontSize:i?15:13,fontWeight:i?600:500,color:D.text.primary,fontFamily:i?vt.mono:vt.sans},children:o??"—"})]})}const _f={success:{color:D.success,bg:D.successDim},error:{color:D.error,bg:D.errorDim},info:{color:D.info,bg:D.infoDim},default:{color:D.text.secondary,bg:D.bg.elevated}};function sa({label:n,variant:o="default",disabled:i,loading:a,confirm:u,onClick:f}){const[d,h]=Ce.useState(!1),v=Ce.useRef();Ce.useEffect(()=>()=>clearTimeout(v.current),[]);const S=_f[o]??_f.default;return j.jsx("button",{onClick:()=>{if(u&&!d){h(!0),clearTimeout(v.current),v.current=setTimeout(()=>h(!1),4e3);return}h(!1),f()},disabled:i||a,style:{...Vt.button,background:S.bg,color:S.color,borderColor:S.color,opacity:i||a?.5:1,fontSize:11,padding:"4px 10px"},children:a?"…":d?"Confirm?":n})}const wf=1e4;function Lk({app:n,itemCode:o,warehouse:i,onClose:a}){const[u,f]=Ce.useState(null),[d,h]=Ce.useState(null),[v,S]=Ce.useState(!0);return Ce.useEffect(()=>{let T=!1;return(async()=>{try{const[P,I]=await Promise.all([n.callServerTool({name:"erpnext_item_get",arguments:{name:o}},{timeout:wf}),n.callServerTool({name:"erpnext_stock_entry_list",arguments:{limit:5,item_code:o}},{timeout:wf})]);if(T)return;if(!P.isError){const b=pa(P);if(b){const G=JSON.parse(b);f(G.data??G)}}if(!I.isError){const b=pa(I);if(b){const G=JSON.parse(b);h(G.data??[])}}}catch{}T||S(!1)})(),()=>{T=!0}},[o]),v?j.jsx("div",{style:{padding:16,background:D.bg.surface,borderTop:`2px solid ${D.accent}`},children:[1,2].map(T=>j.jsx("div",{className:"skeleton",style:{height:14,width:`${30+T*15}%`,marginBottom:8}},T))}):j.jsxs("div",{style:{padding:16,background:D.bg.surface,borderTop:`2px solid ${D.accent}`},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[j.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[j.jsx("span",{style:{fontSize:14,fontWeight:600,color:D.text.primary,fontFamily:vt.mono},children:o}),j.jsx("span",{style:{fontSize:11,color:D.text.muted},children:i})]}),j.jsx("button",{onClick:a,style:{...Vt.button,padding:"2px 8px",fontSize:11},children:"✕"})]}),u&&j.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:6,marginBottom:10},children:[u.item_name&&j.jsx(qi,{label:"Name",value:String(u.item_name)}),u.item_group&&j.jsx(qi,{label:"Group",value:String(u.item_group)}),u.stock_uom&&j.jsx(qi,{label:"UOM",value:String(u.stock_uom)}),u.standard_rate!=null&&j.jsx(qi,{label:"Std Rate",value:String(u.standard_rate),bold:!0})]}),d&&d.length>0&&j.jsxs("div",{style:{marginBottom:10},children:[j.jsx("div",{style:{fontSize:10,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6},children:"Recent Movements"}),d.slice(0,4).map((T,P)=>j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",borderBottom:`1px solid ${D.borderSubtle}`,fontSize:12},children:[j.jsx("span",{style:{color:D.text.secondary},children:String(T.stock_entry_type??T.name??"—")}),j.jsx("span",{style:{fontFamily:vt.mono,color:D.text.primary},children:String(T.posting_date??"—")})]},P))]}),j.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",paddingTop:8,borderTop:`1px solid ${D.border}`},children:[j.jsx(sa,{label:"Stock chart",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show stock chart for item ${o}`}]})}catch{}}}),j.jsx(sa,{label:"Item details",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show me the full details of Item ${o}`}]})}catch{}}}),j.jsx(sa,{label:"Stock entries",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show stock entries for item ${o}`}]})}catch{}}})]})]})}const Jn=new Nk({name:"Stock Viewer",version:"2.0.0"}),bk=15e3,Dk=1e4;function Zk(){return j.jsx("div",{style:{padding:24},children:j.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[[1,2,3,4].map(n=>j.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:n===1?"40%":`${60+n*8}%`}},n)),j.jsx("div",{style:{marginTop:8},children:[1,2,3,4,5].map(n=>j.jsx("div",{className:"skeleton",style:{height:36,marginBottom:2}},n))})]})})}function Ak(){return j.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:D.text.muted,gap:16},children:[j.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[j.jsx("rect",{x:"8",y:"20",width:"16",height:"24",rx:"2",stroke:"currentColor",strokeWidth:"2"}),j.jsx("rect",{x:"28",y:"14",width:"16",height:"30",rx:"2",stroke:"currentColor",strokeWidth:"2"}),j.jsx("rect",{x:"18",y:"28",width:"16",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"2",fill:"#08080a"}),j.jsx("path",{d:"M14 32h4M34 26h4M24 34h4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",opacity:"0.5"})]}),j.jsxs("div",{style:{fontSize:13,textAlign:"center"},children:["No stock data",j.jsx("div",{style:{fontSize:11,color:D.text.faint,marginTop:4},children:"Run a stock balance query to see inventory levels"})]})]})}function Fk({qty:n}){let o,i;return n<=0?(o=D.error,i=D.errorDim):n<10?(o=D.warning,i=D.warningDim):(o=D.success,i=D.successDim),j.jsx("span",{style:{...Vt.badge(o,i),fontFamily:vt.mono,minWidth:48,justifyContent:"center"},children:Bi(n,0)})}function kf(n){return pa(n)}function Uk(){const[n,o]=Ce.useState(null),[i,a]=Ce.useState(!0),[u,f]=Ce.useState(!1),[d,h]=Ce.useState(null),v=Ce.useRef(null),S=Ce.useRef(null),T=Ce.useRef(!1),P=Ce.useRef(0);function I(V){v.current=V,S.current=yf(V,S.current),o(V)}function b(V){if(V.isError){const A=kf(V);return h(A??"Tool returned an error"),a(!1),!1}const ee=kf(V);if(!ee)return!1;try{const A=JSON.parse(ee);return I(A),h(null),a(!1),!0}catch{return h("Failed to parse stock payload"),a(!1),!1}}async function G(V={}){const ee=yf(v.current,S.current);if(!jk({request:ee,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:T.current,now:Date.now(),lastRefreshStartedAt:P.current,minIntervalMs:bk},V)||!ee||!Jn.getHostCapabilities()?.serverTools)return!1;T.current=!0,P.current=Date.now(),f(!0);try{const A=await Jn.callServerTool({name:ee.toolName,arguments:ee.arguments},{timeout:Dk});return A.isError?(h("Refresh failed"),!1):b(A)?!0:(h("Refresh returned no data"),!1)}catch(A){return h(Mk(A)),!1}finally{T.current=!1,f(!1)}}return Ce.useEffect(()=>{Jn.connect().catch(()=>{}),Jn.ontoolresult=V=>{b(V)},Jn.ontoolinputpartial=()=>{v.current||a(!0)}},[]),Ce.useEffect(()=>{function V(){G({ignoreInterval:!0})}function ee(){document.visibilityState==="visible"&&G({ignoreInterval:!0})}return window.addEventListener("focus",V),document.addEventListener("visibilitychange",ee),()=>{window.removeEventListener("focus",V),document.removeEventListener("visibilitychange",ee)}},[]),j.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},"aria-busy":u,children:[j.jsx(Ok,{}),j.jsx("div",{style:{flex:1},children:i?j.jsx(Zk,{}):n?j.jsx(Hk,{data:n,error:d,refreshing:u,onRefresh:()=>void G({ignoreInterval:!0})}):j.jsx(Ak,{})}),j.jsx($k,{})]})}const la=[{key:"item_code",label:"Item Code",align:"left",width:"22%"},{key:"warehouse",label:"Warehouse",align:"left",width:"22%"},{key:"actual_qty",label:"Actual Qty",align:"right",width:"12%"},{key:"reserved_qty",label:"Reserved",align:"right",width:"11%"},{key:"projected_qty",label:"Projected",align:"right",width:"11%"},{key:"valuation_rate",label:"Rate",align:"right",width:"11%"},{key:"stock_value",label:"Value",align:"right",width:"11%"}];function Hk({data:n,error:o,refreshing:i,onRefresh:a}){const[u,f]=Ce.useState("item_code"),[d,h]=Ce.useState("asc"),[v,S]=Ce.useState(""),[T,P]=Ce.useState(null),I=Jn.getHostCapabilities()?.serverTools,b=Ce.useMemo(()=>{if(!v)return n.data;const A=v.toLowerCase();return n.data.filter(oe=>oe.item_code.toLowerCase().includes(A)||oe.warehouse.toLowerCase().includes(A))},[n.data,v]),G=Ce.useMemo(()=>[...b].sort((A,oe)=>{const re=A[u],X=oe[u];if(re==null&&X==null)return 0;if(re==null)return 1;if(X==null)return-1;let fe;return typeof re=="number"&&typeof X=="number"?fe=re-X:fe=String(re).localeCompare(String(X)),d==="asc"?fe:-fe}),[b,u,d]),V=Ce.useMemo(()=>G.reduce((A,oe)=>A+(oe.stock_value??0),0),[G]);function ee(A){u===A?h(oe=>oe==="asc"?"desc":"asc"):(f(A),h("asc"))}return j.jsxs("div",{style:{padding:16,fontFamily:vt.sans},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16,flexWrap:"wrap",gap:8},children:[j.jsxs("div",{children:[j.jsx("div",{style:{fontSize:16,fontWeight:700,color:D.text.primary},children:"Stock Balance"}),j.jsxs("div",{style:{fontSize:12,color:D.text.muted},children:[G.length," entries",v?` (filtered from ${n.count})`:""]}),j.jsx("div",{"aria-live":"polite",style:{fontSize:11,color:o?D.error:D.text.faint,marginTop:4},children:o??(i?"Refreshing…":"Auto-refresh on focus")})]}),j.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[j.jsx("input",{type:"text",placeholder:"Filter items / warehouses...",value:v,onChange:A=>S(A.target.value),style:{...Vt.input,maxWidth:260},onFocus:A=>{A.target.style.borderColor=D.accent},onBlur:A=>{A.target.style.borderColor=D.border}}),j.jsx("button",{onClick:a,disabled:i,style:Vt.button,onMouseEnter:A=>{i||(A.currentTarget.style.borderColor=D.accent,A.currentTarget.style.color=D.accent)},onMouseLeave:A=>{A.currentTarget.style.borderColor=D.border,A.currentTarget.style.color=D.text.secondary},children:j.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[j.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:[j.jsx("path",{d:"M10 6a4 4 0 1 1-1.1-2.76",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),j.jsx("path",{d:"M10 2v2.8H7.2",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]}),i?"Refreshing":"Refresh"]})})]})]}),j.jsx("div",{style:{border:`1px solid ${D.border}`,borderRadius:8,overflow:"hidden"},children:j.jsx("div",{style:{overflowX:"auto"},children:j.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:600},children:[j.jsx("thead",{children:j.jsx("tr",{children:la.map(A=>j.jsxs("th",{onClick:()=>ee(A.key),style:{...Vt.tableHeader,textAlign:A.align,width:A.width,color:u===A.key?D.accent:D.text.muted,background:D.bg.surface},children:[A.label,j.jsx("span",{style:{marginLeft:4,opacity:u===A.key?1:.3,fontSize:10},children:u===A.key?d==="asc"?"▲":"▼":"⇅"})]},A.key))})}),j.jsx("tbody",{children:G.length===0?j.jsx("tr",{children:j.jsx("td",{colSpan:la.length,style:{...Vt.tableCell,textAlign:"center",color:D.text.muted,padding:32},children:"No matching entries"})}):G.map((A,oe)=>{const re=`${A.item_code}::${A.warehouse}`,X=T===re;return j.jsxs(Ce.Fragment,{children:[j.jsxs("tr",{style:{transition:"background 0.1s",cursor:I?"pointer":"default",background:X?D.bg.hover:"transparent"},onClick:I?()=>P(X?null:re):void 0,onMouseEnter:fe=>{X||(fe.currentTarget.style.background=D.bg.hover)},onMouseLeave:fe=>{X||(fe.currentTarget.style.background="transparent")},children:[j.jsx("td",{style:{...Vt.tableCell,fontWeight:500},children:A.item_code}),j.jsx("td",{style:{...Vt.tableCell,color:D.text.secondary},children:A.warehouse}),j.jsx("td",{style:{...Vt.tableCell,textAlign:"right"},children:j.jsx(Fk,{qty:A.actual_qty})}),j.jsx("td",{style:Vi,children:A.reserved_qty!=null?Bi(A.reserved_qty,0):"—"}),j.jsx("td",{style:Vi,children:A.projected_qty!=null?Bi(A.projected_qty,0):"—"}),j.jsx("td",{style:Vi,children:A.valuation_rate!=null?Bi(A.valuation_rate):"—"}),j.jsx("td",{style:{...Vi,fontWeight:500,color:D.text.primary},children:A.stock_value!=null?vf(A.stock_value):"—"})]}),X&&j.jsx("tr",{children:j.jsx("td",{colSpan:la.length,style:{padding:0,borderBottom:`1px solid ${D.border}`},children:j.jsx(Lk,{app:Jn,itemCode:A.item_code,warehouse:A.warehouse,onClose:()=>P(null)})})})]},`${re}-${oe}`)})})]})})}),j.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",marginTop:12,gap:12,padding:"8px 0"},children:[j.jsx("span",{style:{fontSize:12,color:D.text.muted},children:"Total Stock Value"}),j.jsx("span",{style:{fontSize:16,fontWeight:700,fontFamily:vt.mono,color:D.accent},children:vf(V)})]})]})}const Vi={...Vt.tableCell,textAlign:"right",fontFamily:vt.mono,fontSize:12,color:D.text.secondary};Pm.createRoot(document.getElementById("app")).render(j.jsx(Uk,{}));</script>
|
|
123
|
-
|
|
124
|
-
</head>
|
|
125
|
-
<body>
|
|
126
|
-
|
|
127
|
-
</body>
|
|
122
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:z().optional().describe("User's language and region preference in BCP 47 format."),timeZone:z().optional().describe("User's timezone in IANA format."),userAgent:z().optional().describe("Host application identifier."),platform:ue([k("web"),k("desktop"),k("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:C({touch:ze().optional().describe("Whether the device supports touch input."),hover:ze().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:C({top:le().describe("Top safe area inset in pixels."),right:le().describe("Right safe area inset in pixels."),bottom:le().describe("Bottom safe area inset in pixels."),left:le().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),Rk=C({method:k("ui/notifications/host-context-changed"),params:zp.describe("Partial context update containing only changed fields.")});C({method:k("ui/update-model-context"),params:C({content:ne(Ro).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:we(z(),ke().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});C({method:k("ui/initialize"),params:C({appInfo:rs.describe("App identification (name and version)."),appCapabilities:zk.describe("Features and capabilities this app provides."),protocolVersion:z().describe("Protocol version this app supports.")})});var Pk=C({protocolVersion:z().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:rs.describe("Host application identification and version."),hostCapabilities:xk.describe("Features and capabilities provided by the host."),hostContext:zp.describe("Rich context about the host environment.")}).passthrough();class Nk extends lk{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(o,i={},a={autoResize:!0}){super(a),this._appInfo=o,this._capabilities=i,this.options=a,this.setRequestHandler(os,u=>(console.log("Received ping:",u.params),{})),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(o){this.setNotificationHandler(vk,i=>o(i.params))}set ontoolinputpartial(o){this.setNotificationHandler(yk,i=>o(i.params))}set ontoolresult(o){this.setNotificationHandler(Ck,i=>o(i.params))}set ontoolcancelled(o){this.setNotificationHandler(_k,i=>o(i.params))}set onhostcontextchanged(o){this.setNotificationHandler(Rk,i=>{this._hostContext={...this._hostContext,...i.params},o(i.params)})}set onteardown(o){this.setRequestHandler(Sk,(i,a)=>o(i.params,a))}set oncalltool(o){this.setRequestHandler(Sp,(i,a)=>o(i.params,a))}set onlisttools(o){this.setRequestHandler(kp,(i,a)=>o(i.params,a))}assertCapabilityForMethod(o){}assertRequestHandlerCapability(o){switch(o){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${o})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${o} registered`)}}assertNotificationCapability(o){}assertTaskCapability(o){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(o){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(o,i){if(typeof o=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${o}"). Did you mean: callServerTool({ name: "${o}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:o},is,i)}async readServerResource(o,i){return await this.request({method:"resources/read",params:o},yp,i)}async listServerResources(o,i){return await this.request({method:"resources/list",params:o},vp,i)}sendMessage(o,i){return this.request({method:"ui/message",params:o},gk,i)}sendLog(o){return this.notification({method:"notifications/message",params:o})}updateModelContext(o,i){return this.request({method:"ui/update-model-context",params:o},Ta,i)}openLink(o,i){return this.request({method:"ui/open-link",params:o},hk,i)}sendOpenLink=this.openLink;downloadFile(o,i){return this.request({method:"ui/download-file",params:o},mk,i)}requestDisplayMode(o,i){return this.request({method:"ui/request-display-mode",params:o},Ek,i)}sendSizeChanged(o){return this.notification({method:"ui/notifications/size-changed",params:o})}setupSizeChangedNotifications(){let o=!1,i=0,a=0,u=()=>{o||(o=!0,requestAnimationFrame(()=>{o=!1;let d=document.documentElement,h=d.style.width,v=d.style.height;d.style.width="fit-content",d.style.height="max-content";let S=d.getBoundingClientRect();d.style.width=h,d.style.height=v;let T=window.innerWidth-d.clientWidth,P=Math.ceil(S.width+T),I=Math.ceil(S.height);(P!==i||I!==a)&&(i=P,a=I,this.sendSizeChanged({width:P,height:I}))}))};u();let f=new ResizeObserver(u);return f.observe(document.documentElement),f.observe(document.body),()=>f.disconnect()}async connect(o=new ck(window.parent,window.parent),i){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(o);try{let a=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:ak}},Pk,i);if(a===void 0)throw Error(`Server sent invalid initialize result: ${a}`);this._hostCapabilities=a.hostCapabilities,this._hostInfo=a.hostInfo,this._hostContext=a.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(a){throw this.close(),a}}}function Fe(n){return`var(${n})`}const D={bg:{surface:Fe("--bg-surface"),elevated:Fe("--bg-elevated"),hover:Fe("--bg-hover")},text:{primary:Fe("--text-primary"),secondary:Fe("--text-secondary"),muted:Fe("--text-muted"),faint:Fe("--text-faint")},accent:Fe("--accent"),accentDim:Fe("--accent-dim"),border:Fe("--border"),borderSubtle:Fe("--border-subtle"),success:Fe("--success"),successDim:Fe("--success-dim"),error:Fe("--error"),errorDim:Fe("--error-dim"),warning:Fe("--warning"),warningDim:Fe("--warning-dim"),info:Fe("--info"),infoDim:Fe("--info-dim")},vt={sans:Fe("--font-sans"),mono:Fe("--font-mono")},Vt={card:{background:D.bg.surface,border:`1px solid ${D.border}`,borderRadius:"8px",padding:"16px"},badge:(n,o)=>({display:"inline-flex",alignItems:"center",padding:"2px 8px",fontSize:"11px",fontWeight:600,borderRadius:"4px",color:n,background:o,letterSpacing:"0.02em"}),input:{background:D.bg.elevated,border:`1px solid ${D.border}`,borderRadius:"6px",padding:"6px 12px",fontSize:"13px",color:D.text.primary,outline:"none",transition:"border-color 0.15s",width:"100%",fontFamily:vt.sans},button:{background:D.bg.elevated,border:`1px solid ${D.border}`,borderRadius:"6px",padding:"6px 14px",fontSize:"12px",color:D.text.secondary,cursor:"pointer",transition:"all 0.15s",fontFamily:vt.sans,whiteSpace:"nowrap"},buttonActive:{background:D.accentDim,borderColor:D.accent,color:D.accent},tableHeader:{padding:"8px 12px",textAlign:"left",fontSize:"11px",fontWeight:600,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",borderBottom:`1px solid ${D.border}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",transition:"color 0.15s"},tableCell:{padding:"8px 12px",fontSize:"13px",borderBottom:`1px solid ${D.borderSubtle}`,color:D.text.primary},mono:{fontFamily:vt.mono,fontSize:"12px"}};function Bi(n,o=2){return n.toLocaleString("en-US",{minimumFractionDigits:o,maximumFractionDigits:o})}function vf(n,o="USD"){return n.toLocaleString("en-US",{style:"currency",currency:o,minimumFractionDigits:2,maximumFractionDigits:2})}function Ik(){return j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[j.jsx("rect",{x:"1",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.9"}),j.jsx("rect",{x:"9",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),j.jsx("rect",{x:"1",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),j.jsx("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.35"})]})}function Ok(){const n={display:"flex",alignItems:"center",gap:7,padding:"0 14px",height:30,background:D.bg.surface,borderBottom:`1px solid ${D.border}`,flexShrink:0},o={fontFamily:vt.sans,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:D.accent},i={width:3,height:3,borderRadius:"50%",background:D.text.faint,marginLeft:2,marginRight:2,flexShrink:0},a={fontFamily:vt.sans,fontSize:10,color:D.text.muted,letterSpacing:"0.03em"};return j.jsxs("div",{style:n,children:[j.jsx("div",{style:{color:D.accent},children:j.jsx(Ik,{})}),j.jsx("span",{style:o,children:"ERPNext"}),j.jsx("div",{style:i}),j.jsx("span",{style:a,children:"gestion ERP"})]})}function $k(){const n={display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"6px 16px 8px",borderTop:`1px solid ${D.borderSubtle}`,marginTop:8},o={fontFamily:vt.sans,fontSize:10,color:D.text.faint,letterSpacing:"0.04em"};return j.jsx("div",{style:n,children:j.jsx("span",{style:o,children:"Casys AI"})})}function jk(n,o={}){return!n.request||n.visibilityState!=="visible"||n.refreshInFlight?!1:o.ignoreInterval?!0:n.now-n.lastRefreshStartedAt>=n.minIntervalMs}function yf(n,o){return n?.refreshRequest??o}function Mk(n){return n instanceof Error&&/timed? out/i.test(n.message)?"Refresh timed out":"Refresh failed"}function pa(n){return n.structuredContent?JSON.stringify(n.structuredContent):n.content?.find(o=>o.type==="text")?.text??null}function qi({label:n,value:o,bold:i}){return j.jsxs("div",{style:{padding:"4px 0"},children:[j.jsx("div",{style:{fontSize:10,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:2},children:n}),j.jsx("div",{style:{fontSize:i?15:13,fontWeight:i?600:500,color:D.text.primary,fontFamily:i?vt.mono:vt.sans},children:o??"—"})]})}const _f={success:{color:D.success,bg:D.successDim},error:{color:D.error,bg:D.errorDim},info:{color:D.info,bg:D.infoDim},default:{color:D.text.secondary,bg:D.bg.elevated}};function sa({label:n,variant:o="default",disabled:i,loading:a,confirm:u,onClick:f}){const[d,h]=Ce.useState(!1),v=Ce.useRef();Ce.useEffect(()=>()=>clearTimeout(v.current),[]);const S=_f[o]??_f.default;return j.jsx("button",{onClick:()=>{if(u&&!d){h(!0),clearTimeout(v.current),v.current=setTimeout(()=>h(!1),4e3);return}h(!1),f()},disabled:i||a,style:{...Vt.button,background:S.bg,color:S.color,borderColor:S.color,opacity:i||a?.5:1,fontSize:11,padding:"4px 10px"},children:a?"…":d?"Confirm?":n})}const wf=1e4;function Lk({app:n,itemCode:o,warehouse:i,onClose:a}){const[u,f]=Ce.useState(null),[d,h]=Ce.useState(null),[v,S]=Ce.useState(!0);return Ce.useEffect(()=>{let T=!1;return(async()=>{try{const[P,I]=await Promise.all([n.callServerTool({name:"erpnext_item_get",arguments:{name:o}},{timeout:wf}),n.callServerTool({name:"erpnext_stock_entry_list",arguments:{limit:5,item_code:o}},{timeout:wf})]);if(T)return;if(!P.isError){const b=pa(P);if(b){const G=JSON.parse(b);f(G.data??G)}}if(!I.isError){const b=pa(I);if(b){const G=JSON.parse(b);h(G.data??[])}}}catch{}T||S(!1)})(),()=>{T=!0}},[o]),v?j.jsx("div",{style:{padding:16,background:D.bg.surface,borderTop:`2px solid ${D.accent}`},children:[1,2].map(T=>j.jsx("div",{className:"skeleton",style:{height:14,width:`${30+T*15}%`,marginBottom:8}},T))}):j.jsxs("div",{style:{padding:16,background:D.bg.surface,borderTop:`2px solid ${D.accent}`},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[j.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[j.jsx("span",{style:{fontSize:14,fontWeight:600,color:D.text.primary,fontFamily:vt.mono},children:o}),j.jsx("span",{style:{fontSize:11,color:D.text.muted},children:i})]}),j.jsx("button",{onClick:a,style:{...Vt.button,padding:"2px 8px",fontSize:11},children:"✕"})]}),u&&j.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:6,marginBottom:10},children:[u.item_name&&j.jsx(qi,{label:"Name",value:String(u.item_name)}),u.item_group&&j.jsx(qi,{label:"Group",value:String(u.item_group)}),u.stock_uom&&j.jsx(qi,{label:"UOM",value:String(u.stock_uom)}),u.standard_rate!=null&&j.jsx(qi,{label:"Std Rate",value:String(u.standard_rate),bold:!0})]}),d&&d.length>0&&j.jsxs("div",{style:{marginBottom:10},children:[j.jsx("div",{style:{fontSize:10,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6},children:"Recent Movements"}),d.slice(0,4).map((T,P)=>j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",borderBottom:`1px solid ${D.borderSubtle}`,fontSize:12},children:[j.jsx("span",{style:{color:D.text.secondary},children:String(T.stock_entry_type??T.name??"—")}),j.jsx("span",{style:{fontFamily:vt.mono,color:D.text.primary},children:String(T.posting_date??"—")})]},P))]}),j.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",paddingTop:8,borderTop:`1px solid ${D.border}`},children:[j.jsx(sa,{label:"Stock chart",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show stock chart for item ${o}`}]})}catch{}}}),j.jsx(sa,{label:"Item details",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show me the full details of Item ${o}`}]})}catch{}}}),j.jsx(sa,{label:"Stock entries",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show stock entries for item ${o}`}]})}catch{}}})]})]})}const Jn=new Nk({name:"Stock Viewer",version:"2.0.0"}),bk=15e3,Dk=1e4;function Zk(){return j.jsx("div",{style:{padding:24},children:j.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[[1,2,3,4].map(n=>j.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:n===1?"40%":`${60+n*8}%`}},n)),j.jsx("div",{style:{marginTop:8},children:[1,2,3,4,5].map(n=>j.jsx("div",{className:"skeleton",style:{height:36,marginBottom:2}},n))})]})})}function Ak(){return j.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:D.text.muted,gap:16},children:[j.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[j.jsx("rect",{x:"8",y:"20",width:"16",height:"24",rx:"2",stroke:"currentColor",strokeWidth:"2"}),j.jsx("rect",{x:"28",y:"14",width:"16",height:"30",rx:"2",stroke:"currentColor",strokeWidth:"2"}),j.jsx("rect",{x:"18",y:"28",width:"16",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"2",fill:"#08080a"}),j.jsx("path",{d:"M14 32h4M34 26h4M24 34h4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",opacity:"0.5"})]}),j.jsxs("div",{style:{fontSize:13,textAlign:"center"},children:["No stock data",j.jsx("div",{style:{fontSize:11,color:D.text.faint,marginTop:4},children:"Run a stock balance query to see inventory levels"})]})]})}function Fk({qty:n}){let o,i;return n<=0?(o=D.error,i=D.errorDim):n<10?(o=D.warning,i=D.warningDim):(o=D.success,i=D.successDim),j.jsx("span",{style:{...Vt.badge(o,i),fontFamily:vt.mono,minWidth:48,justifyContent:"center"},children:Bi(n,0)})}function kf(n){return pa(n)}function Uk(){const[n,o]=Ce.useState(null),[i,a]=Ce.useState(!0),[u,f]=Ce.useState(!1),[d,h]=Ce.useState(null),v=Ce.useRef(null),S=Ce.useRef(null),T=Ce.useRef(!1),P=Ce.useRef(0);function I(V){v.current=V,S.current=yf(V,S.current),o(V)}function b(V){if(V.isError){const A=kf(V);return h(A??"Tool returned an error"),a(!1),!1}const ee=kf(V);if(!ee)return!1;try{const A=JSON.parse(ee);return I(A),h(null),a(!1),!0}catch{return h("Failed to parse stock payload"),a(!1),!1}}async function G(V={}){const ee=yf(v.current,S.current);if(!jk({request:ee,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:T.current,now:Date.now(),lastRefreshStartedAt:P.current,minIntervalMs:bk},V)||!ee||!Jn.getHostCapabilities()?.serverTools)return!1;T.current=!0,P.current=Date.now(),f(!0);try{const A=await Jn.callServerTool({name:ee.toolName,arguments:ee.arguments},{timeout:Dk});return A.isError?(h("Refresh failed"),!1):b(A)?!0:(h("Refresh returned no data"),!1)}catch(A){return h(Mk(A)),!1}finally{T.current=!1,f(!1)}}return Ce.useEffect(()=>{Jn.connect().catch(()=>{}),Jn.ontoolresult=V=>{b(V)},Jn.ontoolinputpartial=()=>{v.current||a(!0)}},[]),Ce.useEffect(()=>{function V(){G({ignoreInterval:!0})}function ee(){document.visibilityState==="visible"&&G({ignoreInterval:!0})}return window.addEventListener("focus",V),document.addEventListener("visibilitychange",ee),()=>{window.removeEventListener("focus",V),document.removeEventListener("visibilitychange",ee)}},[]),j.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},"aria-busy":u,children:[j.jsx(Ok,{}),j.jsx("div",{style:{flex:1},children:i?j.jsx(Zk,{}):n?j.jsx(Hk,{data:n,error:d,refreshing:u,onRefresh:()=>void G({ignoreInterval:!0})}):j.jsx(Ak,{})}),j.jsx($k,{})]})}const la=[{key:"item_code",label:"Item Code",align:"left",width:"22%"},{key:"warehouse",label:"Warehouse",align:"left",width:"22%"},{key:"actual_qty",label:"Actual Qty",align:"right",width:"12%"},{key:"reserved_qty",label:"Reserved",align:"right",width:"11%"},{key:"projected_qty",label:"Projected",align:"right",width:"11%"},{key:"valuation_rate",label:"Rate",align:"right",width:"11%"},{key:"stock_value",label:"Value",align:"right",width:"11%"}];function Hk({data:n,error:o,refreshing:i,onRefresh:a}){const[u,f]=Ce.useState("item_code"),[d,h]=Ce.useState("asc"),[v,S]=Ce.useState(""),[T,P]=Ce.useState(null),I=Jn.getHostCapabilities()?.serverTools,b=Ce.useMemo(()=>{if(!v)return n.data;const A=v.toLowerCase();return n.data.filter(oe=>oe.item_code.toLowerCase().includes(A)||oe.warehouse.toLowerCase().includes(A))},[n.data,v]),G=Ce.useMemo(()=>[...b].sort((A,oe)=>{const re=A[u],X=oe[u];if(re==null&&X==null)return 0;if(re==null)return 1;if(X==null)return-1;let fe;return typeof re=="number"&&typeof X=="number"?fe=re-X:fe=String(re).localeCompare(String(X)),d==="asc"?fe:-fe}),[b,u,d]),V=Ce.useMemo(()=>G.reduce((A,oe)=>A+(oe.stock_value??0),0),[G]);function ee(A){u===A?h(oe=>oe==="asc"?"desc":"asc"):(f(A),h("asc"))}return j.jsxs("div",{style:{padding:16,fontFamily:vt.sans},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16,flexWrap:"wrap",gap:8},children:[j.jsxs("div",{children:[j.jsx("div",{style:{fontSize:16,fontWeight:700,color:D.text.primary},children:"Stock Balance"}),j.jsxs("div",{style:{fontSize:12,color:D.text.muted},children:[G.length," ","entries",v?` (filtered from ${n.count})`:""]}),j.jsx("div",{"aria-live":"polite",style:{fontSize:11,color:o?D.error:D.text.faint,marginTop:4},children:o??(i?"Refreshing…":"Auto-refresh on focus")})]}),j.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[j.jsx("input",{type:"text",placeholder:"Filter items / warehouses...",value:v,onChange:A=>S(A.target.value),style:{...Vt.input,maxWidth:260},onFocus:A=>{A.target.style.borderColor=D.accent},onBlur:A=>{A.target.style.borderColor=D.border}}),j.jsx("button",{onClick:a,disabled:i,style:Vt.button,onMouseEnter:A=>{i||(A.currentTarget.style.borderColor=D.accent,A.currentTarget.style.color=D.accent)},onMouseLeave:A=>{A.currentTarget.style.borderColor=D.border,A.currentTarget.style.color=D.text.secondary},children:j.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[j.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:[j.jsx("path",{d:"M10 6a4 4 0 1 1-1.1-2.76",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),j.jsx("path",{d:"M10 2v2.8H7.2",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]}),i?"Refreshing":"Refresh"]})})]})]}),j.jsx("div",{style:{border:`1px solid ${D.border}`,borderRadius:8,overflow:"hidden"},children:j.jsx("div",{style:{overflowX:"auto"},children:j.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:600},children:[j.jsx("thead",{children:j.jsx("tr",{children:la.map(A=>j.jsxs("th",{onClick:()=>ee(A.key),style:{...Vt.tableHeader,textAlign:A.align,width:A.width,color:u===A.key?D.accent:D.text.muted,background:D.bg.surface},children:[A.label,j.jsx("span",{style:{marginLeft:4,opacity:u===A.key?1:.3,fontSize:10},children:u===A.key?d==="asc"?"▲":"▼":"⇅"})]},A.key))})}),j.jsx("tbody",{children:G.length===0?j.jsx("tr",{children:j.jsx("td",{colSpan:la.length,style:{...Vt.tableCell,textAlign:"center",color:D.text.muted,padding:32},children:"No matching entries"})}):G.map((A,oe)=>{const re=`${A.item_code}::${A.warehouse}`,X=T===re;return j.jsxs(Ce.Fragment,{children:[j.jsxs("tr",{style:{transition:"background 0.1s",cursor:I?"pointer":"default",background:X?D.bg.hover:"transparent"},onClick:I?()=>P(X?null:re):void 0,onMouseEnter:fe=>{X||(fe.currentTarget.style.background=D.bg.hover)},onMouseLeave:fe=>{X||(fe.currentTarget.style.background="transparent")},children:[j.jsx("td",{style:{...Vt.tableCell,fontWeight:500},children:A.item_code}),j.jsx("td",{style:{...Vt.tableCell,color:D.text.secondary},children:A.warehouse}),j.jsx("td",{style:{...Vt.tableCell,textAlign:"right"},children:j.jsx(Fk,{qty:A.actual_qty})}),j.jsx("td",{style:Vi,children:A.reserved_qty!=null?Bi(A.reserved_qty,0):"—"}),j.jsx("td",{style:Vi,children:A.projected_qty!=null?Bi(A.projected_qty,0):"—"}),j.jsx("td",{style:Vi,children:A.valuation_rate!=null?Bi(A.valuation_rate):"—"}),j.jsx("td",{style:{...Vi,fontWeight:500,color:D.text.primary},children:A.stock_value!=null?vf(A.stock_value):"—"})]}),X&&j.jsx("tr",{children:j.jsx("td",{colSpan:la.length,style:{padding:0,borderBottom:`1px solid ${D.border}`},children:j.jsx(Lk,{app:Jn,itemCode:A.item_code,warehouse:A.warehouse,onClose:()=>P(null)})})})]},`${re}-${oe}`)})})]})})}),j.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",marginTop:12,gap:12,padding:"8px 0"},children:[j.jsx("span",{style:{fontSize:12,color:D.text.muted},children:"Total Stock Value"}),j.jsx("span",{style:{fontSize:16,fontWeight:700,fontFamily:vt.mono,color:D.accent},children:vf(V)})]})]})}const Vi={...Vt.tableCell,textAlign:"right",fontFamily:vt.mono,fontSize:12,color:D.text.secondary};Pm.createRoot(document.getElementById("app")).render(j.jsx(Uk,{}));</script>
|
|
123
|
+
<style rel="stylesheet" crossorigin>:root{--accent: #0089ff;--accent-dim: rgba(0, 137, 255, .15);--accent-border: rgba(0, 137, 255, .3);--success: #16a34a;--success-dim: rgba(22, 163, 74, .1);--error: #dc2626;--error-dim: rgba(220, 38, 38, .1);--warning: #d97706;--warning-dim: rgba(217, 119, 6, .1);--info: #2563eb;--info-dim: rgba(37, 99, 235, .1);--radius-sm: 4px;--radius-md: 6px;--radius-lg: 8px;--font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;--font-mono: "SF Mono", "Cascadia Code", "Fira Code", monospace;--bg-root: #ffffff;--bg-surface: #f9fafb;--bg-elevated: #f3f4f6;--bg-hover: #e5e7eb;--bg-active: #d1d5db;--text-primary: #111827;--text-secondary: #4b5563;--text-muted: #6b7280;--text-faint: #9ca3af;--border: #e5e7eb;--border-subtle: #f3f4f6;--shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);--shadow-md: 0 2px 8px rgba(0, 0, 0, .08)}@media(prefers-color-scheme:dark){:root{--bg-root: #08080a;--bg-surface: #111113;--bg-elevated: #18181b;--bg-hover: #1f1f23;--bg-active: #27272a;--text-primary: #e7e5e4;--text-secondary: #a8a29e;--text-muted: #78716c;--text-faint: #57534e;--border: #27272a;--border-subtle: #1f1f23;--success: #4ade80;--success-dim: rgba(74, 222, 128, .12);--error: #f87171;--error-dim: rgba(248, 113, 113, .12);--warning: #fbbf24;--warning-dim: rgba(251, 191, 36, .12);--info: #60a5fa;--info-dim: rgba(96, 165, 250, .12);--shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);--shadow-md: 0 2px 8px rgba(0, 0, 0, .4)}}*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}html{border-radius:var(--radius-lg);overflow:hidden}html,body{background:var(--bg-root);color:var(--text-primary);font-family:var(--font-sans);font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}body{overflow:auto}::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:var(--border);border-radius:3px}::-webkit-scrollbar-thumb:hover{background:var(--text-faint)}@keyframes pulse{0%,to{opacity:.4}50%{opacity:.15}}@keyframes shimmer{0%{background-position:-200% 0}to{background-position:200% 0}}.animate-pulse{animation:pulse 1.5s ease-in-out infinite}.skeleton{background:linear-gradient(90deg,var(--bg-elevated) 25%,var(--bg-hover) 50%,var(--bg-elevated) 75%);background-size:200% 100%;animation:shimmer 1.5s infinite;border-radius:var(--radius-sm)}.drag-scroll::-webkit-scrollbar{display:none}.drag-scroll{scrollbar-width:none}article button:hover:not(:disabled){background:var(--bg-hover)!important;color:var(--text-primary)!important}article[draggable=true]:active{cursor:grabbing;opacity:.85}.kanban-detail-backdrop{position:fixed;inset:0;z-index:100;background:#00000073;display:flex;align-items:flex-start;justify-content:center;padding:20px 12px;overflow-y:auto;backdrop-filter:blur(2px)}.kanban-detail-panel{background:var(--bg-root);border:1px solid var(--border);border-radius:10px;max-width:520px;width:100%;box-shadow:0 8px 32px #0000001f,0 2px 8px #0000000f;position:relative;display:flex;flex-direction:column}.kanban-detail-panel .detail-field-row{transition:background .1s}.kanban-detail-panel .detail-field-row:hover{background:var(--bg-surface)}.kanban-detail-panel .detail-field-cell{transition:background .1s;border-radius:4px}.kanban-detail-panel .detail-field-cell:hover{background:var(--bg-surface)}.kanban-detail-panel .detail-field-cell:hover input,.kanban-detail-panel .detail-field-cell:hover select{border-color:var(--border)!important;background:var(--bg-elevated)!important}.kanban-detail-panel select:focus{border-color:var(--accent)!important;box-shadow:0 0 0 2px var(--accent-dim);outline:none}.kanban-detail-panel input:focus{border-color:var(--accent)!important;box-shadow:0 0 0 2px var(--accent-dim);outline:none}.kanban-detail-panel textarea:focus{border-color:var(--accent)!important;box-shadow:0 0 0 2px var(--accent-dim);outline:none}@media(prefers-color-scheme:dark){.kanban-detail-backdrop{background:#000000a6}.kanban-detail-panel{box-shadow:0 8px 32px #0006,0 2px 8px #0000004d}}.kanban-card-title-link{cursor:pointer;text-decoration:none;color:inherit}.kanban-card-title-link:hover{text-decoration:underline;text-decoration-thickness:1px;text-underline-offset:2px}</style>
|
|
124
|
+
</head>
|
|
125
|
+
<body>
|
|
126
|
+
<div id="app"></div>
|
|
127
|
+
</body>
|
|
128
128
|
</html>
|