@casys/mcp-erpnext 2.5.0 → 3.0.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 +50 -133
- package/mcp-erpnext.mjs +4257 -1434
- package/package.json +1 -1
- package/ui-dist/chart-viewer/index.html +1 -1
- package/ui-dist/doclist-viewer/index.html +1 -1
- package/ui-dist/funnel-viewer/index.html +1 -1
- package/ui-dist/invoice-viewer/index.html +1 -1
- package/ui-dist/kanban-viewer/index.html +1 -1
- package/ui-dist/kpi-viewer/index.html +1 -1
- package/ui-dist/stock-viewer/index.html +1 -1
|
@@ -147,7 +147,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
147
147
|
- "app": Tool callable by the app from this server only`),csp:_r().optional(),permissions:_r().optional()});j({mimeTypes:le(I()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')});j({method:x("ui/download-file"),params:j({contents:le(ve([_S,$S])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})});j({method:x("ui/message"),params:j({role:x("user").describe('Message role, currently only "user" is supported.'),content:le(ya).describe("Message content blocks (text, image, etc.).")})});j({method:x("ui/notifications/sandbox-resource-ready"),params:j({html:I().describe("HTML content to load into the inner iframe."),sandbox:I().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:ep.optional().describe("CSP configuration from resource metadata."),permissions:tp.optional().describe("Sandbox permissions from resource metadata.")})});var h4=j({method:x("ui/notifications/tool-result"),params:ru.describe("Standard MCP tool execution result.")}),IS=j({toolInfo:j({id:fa.optional().describe("JSON-RPC id of the tools/call request."),tool:Ym.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:e4.optional().describe("Current color theme preference."),styles:c4.optional().describe("Style configuration for theming the app."),displayMode:ho.optional().describe("How the UI is currently displayed."),availableDisplayModes:le(ho).optional().describe("Display modes the host supports."),containerDimensions:ve([j({height:de().describe("Fixed container height in pixels.")}),j({maxHeight:ve([de(),ii()]).optional().describe("Maximum container height in pixels.")})]).and(ve([j({width:de().describe("Fixed container width in pixels.")}),j({maxWidth:ve([de(),ii()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
148
148
|
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:I().optional().describe("User's language and region preference in BCP 47 format."),timeZone:I().optional().describe("User's timezone in IANA format."),userAgent:I().optional().describe("Host application identifier."),platform:ve([x("web"),x("desktop"),x("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:j({touch:Pe().optional().describe("Whether the device supports touch input."),hover:Pe().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:j({top:de().describe("Top safe area inset in pixels."),right:de().describe("Right safe area inset in pixels."),bottom:de().describe("Bottom safe area inset in pixels."),left:de().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),v4=j({method:x("ui/notifications/host-context-changed"),params:IS.describe("Partial context update containing only changed fields.")});j({method:x("ui/update-model-context"),params:j({content:le(ya).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:be(I(),Ee().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});j({method:x("ui/initialize"),params:j({appInfo:tu.describe("App identification (name and version)."),appCapabilities:m4.describe("Features and capabilities this app provides."),protocolVersion:I().describe("Protocol version this app supports.")})});var y4=j({protocolVersion:I().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:tu.describe("Host application identification and version."),hostCapabilities:f4.describe("Features and capabilities provided by the host."),hostContext:IS.describe("Rich context about the host environment.")}).passthrough(),_4={target:"draft-2020-12"};async function Rv(n,r){let o=n["~standard"];if(o.jsonSchema)return o.jsonSchema[r](_4);if(o.vendor==="zod"){let{z:s}=await Db(()=>Promise.resolve().then(()=>lz),void 0,import.meta.url);return s.toJSONSchema(n,{io:r})}throw Error(`Schema (vendor: ${o.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function Lv(n,r,o=""){let s=await n["~standard"].validate(r);if(s.issues){let t=s.issues.map(a=>{let c=a.path?.map(f=>typeof f=="object"?f.key:f).join(".");return c?`${c}: ${a.message}`:a.message}).join("; ");throw Error(o+t)}return s.value}class np extends G1{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(r){if(this._initializedSent)return;let o=`[ext-apps] App.${r}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(o);console.warn(`${o}. This will throw in a future release.`)}eventSchemas={toolinput:a4,toolinputpartial:l4,toolresult:h4,toolcancelled:s4,hostcontextchanged:v4};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(r){if(!np.ONE_SHOT_EVENTS.has(r)||this._everHadListener.has(r)||(this._everHadListener.add(r),!this._initializedSent))return;let o=`[ext-apps] "${String(r)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(o);console.warn(o)}setEventHandler(r,o){o&&this._assertHandlerTiming(r),super.setEventHandler(r,o)}addEventListener(r,o){this._assertHandlerTiming(r),super.addEventListener(r,o)}onEventDispatch(r,o){r==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...o})}constructor(r,o={},s={autoResize:!0}){super(s),this._appInfo=r,this._capabilities=o,this.options=s,s.allowUnsafeEval||rt({jitless:!0}),this.setRequestHandler(nu,t=>(console.log("Received ping:",t.params),{})),this.setEventHandler("hostcontextchanged",void 0)}registerCapabilities(r){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._capabilities=K1(this._capabilities,r)}registerTool(r,o,s){if(this._registeredTools[r])throw Error(`Tool ${r} is already registered`);let t=this,a=()=>{t._initializedSent&&t._capabilities.tools?.listChanged&&t.sendToolListChanged()},c=o.inputSchema!==void 0,f={title:o.title,description:o.description,inputSchema:o.inputSchema,outputSchema:o.outputSchema,annotations:o.annotations,_meta:o._meta,enabled:!0,enable(){this.enabled=!0,a()},disable(){this.enabled=!1,a()},update(g){Object.assign(this,g),a()},remove(){t._registeredTools[r]===f&&(delete t._registeredTools[r],a())},handler:async(g,h)=>{if(!f.enabled)throw Error(`Tool ${r} is disabled`);let y;if(c){let S=f.inputSchema,T=S?await Lv(S,g??{},`Invalid input for tool ${r}: `):g??{};y=await s(T,h)}else y=await s(h);return f.outputSchema&&!y.isError&&(y.structuredContent=await Lv(f.outputSchema,y.structuredContent,`Invalid output for tool ${r}: `)),y}};return this._registeredTools[r]=f,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),a(),f}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(r,o)=>{let s=this._registeredTools[r.name];if(!s)throw Error(`Tool ${r.name} not found`);return s.handler(r.arguments,o)},this.onlisttools=async(r,o)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([s,t])=>t.enabled).map(async([s,t])=>{let a={name:s,title:t.title,description:t.description,inputSchema:t.inputSchema?await Rv(t.inputSchema,"input"):{type:"object",properties:{}}};return t.outputSchema&&(a.outputSchema=await Rv(t.outputSchema,"output")),t.annotations&&(a.annotations=t.annotations),t._meta&&(a._meta=t._meta),a}))}))}async sendToolListChanged(r={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:r})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(r){this.setEventHandler("toolinput",r)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(r){this.setEventHandler("toolinputpartial",r)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(r){this.setEventHandler("toolresult",r)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(r){this.setEventHandler("toolcancelled",r)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(r){this.setEventHandler("hostcontextchanged",r)}_onteardown;get onteardown(){return this._onteardown}set onteardown(r){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,r),this._onteardown=r,this.replaceRequestHandler(d4,(o,s)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(o.params,s)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(r){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,r),this._oncalltool=r,this.replaceRequestHandler(SS,(o,s)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(o.params,s)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(r){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,r),this._onlisttools=r,this.replaceRequestHandler(kS,(o,s)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(o.params,s)})}assertCapabilityForMethod(r){switch(r){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${r})`);break}}assertRequestHandlerCapability(r){switch(r){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${r})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${r} registered`)}}assertNotificationCapability(r){}assertTaskCapability(r){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(r){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(r,o){if(this._assertInitialized("callServerTool"),typeof r=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${r}"). Did you mean: callServerTool({ name: "${r}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:r},ru,{onprogress:()=>{},resetTimeoutOnProgress:!0,...o})}async readServerResource(r,o){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:r},yS,o)}async listServerResources(r,o){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:r},vS,o)}async createSamplingMessage(r,o){this._assertInitialized("createSamplingMessage");let s=r.tools?xS:bS;return await this.request({method:"sampling/createMessage",params:r},s,o)}sendMessage(r,o){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:r},o4,o)}sendLog(r){return this.notification({method:"notifications/message",params:r})}updateModelContext(r,o){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:r},Lm,o)}openLink(r,o){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:r},r4,o)}sendOpenLink=this.openLink;downloadFile(r,o){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:r},i4,o)}requestTeardown(r={}){return this.notification({method:"ui/notifications/request-teardown",params:r})}requestDisplayMode(r,o){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:r},p4,o)}sendSizeChanged(r){return this.notification({method:"ui/notifications/size-changed",params:r})}setupSizeChangedNotifications(){let r=!1,o=0,s=0,t=()=>{r||(r=!0,requestAnimationFrame(()=>{r=!1;let c=document.documentElement,f=c.style.height;c.style.height="max-content";let g=Math.ceil(c.getBoundingClientRect().height);c.style.height=f;let h=Math.ceil(window.innerWidth);(h!==o||g!==s)&&(o=h,s=g,this.sendSizeChanged({width:h,height:g}))}))};t();let a=new ResizeObserver(t);return a.observe(document.documentElement),a.observe(document.body),()=>a.disconnect()}async connect(r=new Y1(window.parent,window.parent),o){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1,await super.connect(r);try{let s=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:Q1}},y4,o);if(s===void 0)throw Error(`Server sent invalid initialize result: ${s}`);this._hostCapabilities=s.hostCapabilities,this._hostInfo=s.hostInfo,this._hostContext=s.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(s){throw this.close(),s}}}function Ge(n){return`var(${n})`}const D={bg:{surface:Ge("--bg-surface"),elevated:Ge("--bg-elevated"),hover:Ge("--bg-hover")},text:{primary:Ge("--text-primary"),secondary:Ge("--text-secondary"),muted:Ge("--text-muted"),faint:Ge("--text-faint")},accent:Ge("--accent"),accentDim:Ge("--accent-dim"),border:Ge("--border"),borderSubtle:Ge("--border-subtle"),success:Ge("--success"),successDim:Ge("--success-dim"),error:Ge("--error"),errorDim:Ge("--error-dim"),warning:Ge("--warning"),warningDim:Ge("--warning-dim"),info:Ge("--info"),infoDim:Ge("--info-dim")},cn={sans:Ge("--font-sans"),mono:Ge("--font-mono")},Rt={card:{background:D.bg.surface,border:`1px solid ${D.border}`,borderRadius:"8px",padding:"16px"},badge:(n,r)=>({display:"inline-flex",alignItems:"center",padding:"2px 8px",fontSize:"11px",fontWeight:600,borderRadius:"4px",color:n,background:r,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:cn.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:cn.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:cn.mono,fontSize:"12px"}};function $4(n,r=2){return n.toLocaleString("en-US",{minimumFractionDigits:r,maximumFractionDigits:r})}function k4(){return U.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[U.jsx("rect",{x:"1",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.9"}),U.jsx("rect",{x:"9",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),U.jsx("rect",{x:"1",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),U.jsx("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.35"})]})}function S4(){const n={display:"flex",alignItems:"center",gap:7,padding:"0 14px",height:30,background:D.bg.surface,borderBottom:`1px solid ${D.border}`,flexShrink:0},r={fontFamily:cn.sans,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:D.accent},o={width:3,height:3,borderRadius:"50%",background:D.text.faint,marginLeft:2,marginRight:2,flexShrink:0},s={fontFamily:cn.sans,fontSize:10,color:D.text.muted,letterSpacing:"0.03em"};return U.jsxs("div",{style:n,children:[U.jsx("div",{style:{color:D.accent},children:U.jsx(k4,{})}),U.jsx("span",{style:r,children:"ERPNext"}),U.jsx("div",{style:o}),U.jsx("span",{style:s,children:"gestion ERP"})]})}function w4(){const n={display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"6px 16px 8px",borderTop:`1px solid ${D.borderSubtle}`,marginTop:8},r={fontFamily:cn.sans,fontSize:10,color:D.text.faint,letterSpacing:"0.04em"};return U.jsx("div",{style:n,children:U.jsx("span",{style:r,children:"Casys AI"})})}function b4(n,r={}){return!n.request||n.visibilityState!=="visible"||n.refreshInFlight?!1:r.ignoreInterval?!0:n.now-n.lastRefreshStartedAt>=n.minIntervalMs}function Zv(n,r){return n?.refreshRequest??r}function x4(n){return n instanceof Error&&/timed? out/i.test(n.message)?"Refresh timed out":"Refresh failed"}function Hl(n){return n.structuredContent?JSON.stringify(n.structuredContent):n.content?.find(r=>r.type==="text")?.text??null}const I4=new Set(["status","docstatus","workflow_state"]),z4=new Set(["doctype","owner","modified_by","creation","modified","idx","_rowAction","_sendMessageHints"]),T4=new Set(["status","workflow_state","company","territory","customer_group","item_group","supplier_group","priority","type"]),j4=6,E4=["name","status","customer","customer_name","supplier","supplier_name","item_code","item_name","employee_name","project","subject","grand_total","outstanding_amount","posting_date","transaction_date","delivery_date"];function P4(n){const r=[],o=[];for(const s of E4)n.includes(s)&&r.push(s);for(const s of n.sort())r.includes(s)||o.push(s);return[...r,...o].slice(0,j4)}function Av(n){return I4.has(n.toLowerCase())}function Jl(n){return n==null?"—":typeof n=="number"?$4(n,n%1===0?0:2):typeof n=="boolean"?n?"Yes":"No":typeof n=="object"?JSON.stringify(n):String(n)}function N4(n,r,o){const s=n.join(","),t=r.map(h=>n.map(y=>{const S=Jl(h[y]);return S.includes(",")||S.includes('"')?`"${S.replace(/"/g,'""')}"`:S}).join(",")).join(`
|
|
149
149
|
`),a=`${s}
|
|
150
|
-
${t}`,c=new Blob([a],{type:"text/csv"}),f=URL.createObjectURL(c),g=document.createElement("a");g.href=f,g.download=`${o??"export"}.csv`,g.click(),URL.revokeObjectURL(f)}function Mv(n,r){let o=n;for(const s of r.split(".")){if(o==null||typeof o!="object")return;o=o[s]}return o}const rp={Submitted:{color:D.success,bg:D.successDim},Completed:{color:D.success,bg:D.successDim},Paid:{color:D.success,bg:D.successDim},Active:{color:D.success,bg:D.successDim},Enabled:{color:D.success,bg:D.successDim},"To Deliver and Bill":{color:D.info,bg:D.infoDim},"To Bill":{color:D.info,bg:D.infoDim},"To Deliver":{color:D.info,bg:D.infoDim},Draft:{color:D.text.muted,bg:D.bg.elevated},Pending:{color:D.warning,bg:D.warningDim},Open:{color:D.warning,bg:D.warningDim},"Partly Paid":{color:D.warning,bg:D.warningDim},"Partly Delivered":{color:D.warning,bg:D.warningDim},Cancelled:{color:D.error,bg:D.errorDim},Overdue:{color:D.error,bg:D.errorDim},Closed:{color:D.text.faint,bg:D.bg.elevated},Disabled:{color:D.text.faint,bg:D.bg.elevated}};function O4({value:n}){const r=rp[n];return r?U.jsx("span",{style:Rt.badge(r.color,r.bg),children:n}):U.jsx("span",{children:n})}function D4(){return U.jsx("div",{style:{padding:24},children:U.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[[1,2,3,4].map(n=>U.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:n===1?"40%":`${60+n*8}%`}},n)),U.jsx("div",{style:{marginTop:8},children:[1,2,3,4,5].map(n=>U.jsx("div",{className:"skeleton",style:{height:36,marginBottom:2}},n))})]})})}function U4(){return U.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:D.text.muted,gap:16},children:[U.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[U.jsx("rect",{x:"8",y:"8",width:"40",height:"40",rx:"4",stroke:"currentColor",strokeWidth:"2"}),U.jsx("path",{d:"M8 18h40",stroke:"currentColor",strokeWidth:"2"}),U.jsx("path",{d:"M20 8v40M36 8v40",stroke:"currentColor",strokeWidth:"1",opacity:"0.3"}),U.jsx("path",{d:"M8 28h40M8 38h40",stroke:"currentColor",strokeWidth:"1",opacity:"0.3"})]}),U.jsxs("div",{style:{fontSize:13,textAlign:"center"},children:["No documents to display",U.jsx("div",{style:{fontSize:11,color:D.text.faint,marginTop:4},children:"Query a DocType to see results in this table"})]})]})}const Fv={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 Dl({label:n,variant:r="default",disabled:o,loading:s,confirm:t,onClick:a}){const[c,f]=we.useState(!1),g=we.useRef();we.useEffect(()=>()=>clearTimeout(g.current),[]);const h=Fv[r]??Fv.default;return U.jsx("button",{onClick:()=>{if(t&&!c){f(!0),clearTimeout(g.current),g.current=setTimeout(()=>f(!1),4e3);return}f(!1),a()},disabled:o||s,style:{...Rt.button,background:h.bg,color:h.color,borderColor:h.color,opacity:o||s?.5:1,fontSize:11,padding:"4px 10px"},children:s?"…":c?"Confirm?":n})}function C4({label:n,value:r,bold:o}){return U.jsxs("div",{style:{padding:"4px 0"},children:[U.jsx("div",{style:{fontSize:10,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:2},children:n}),U.jsx("div",{style:{fontSize:o?15:13,fontWeight:o?600:500,color:D.text.primary,fontFamily:o?cn.mono:cn.sans},children:r??"—"})]})}function R4({app:n,data:r,loading:o,doctype:s,sendMessageHints:t,onClose:a,onAction:c}){const[f,g]=we.useState(null),[h,y]=we.useState(null),[S,T]=we.useState(!0);if(o)return U.jsx("div",{style:{padding:16,background:D.bg.surface},children:[1,2,3].map(ee=>U.jsx("div",{className:"skeleton",style:{height:14,width:`${30+ee*15}%`,marginBottom:8}},ee))});if(!r)return null;async function N(ee,ge,$e,xe){g(ee),y(null);const Pt=await c(ge,$e);T(Pt),y(Pt?xe:"Action failed"),g(null)}const A=[];for(const[ee,ge]of Object.entries(r))if(!(ee.startsWith("_")||ee==="refreshRequest"||ee==="doctype")&&ge!=null)if(Array.isArray(ge))A.push([ee,`${ge.length} item${ge.length>1?"s":""}`]);else if(typeof ge=="object")for(const[$e,xe]of Object.entries(ge))xe!=null&&typeof xe!="object"&&A.push([`${ee}.${$e}`,String(xe)]);else A.push([ee,Jl(ge)]);const J=String(r.name??""),F=String(r.status??r.docstatus??""),ye=rp[F],ke=F==="Draft"||r.docstatus===0,me=r.docstatus===1,se=t?.map(ee=>({...ee,message:ee.message.replace(/\{id\}/g,J).replace(/\{doctype\}/g,s??"")}))??[];return U.jsxs("div",{style:{padding:16,background:D.bg.surface,borderTop:`2px solid ${D.accent}`},children:[U.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[U.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[U.jsx("span",{style:{fontSize:14,fontWeight:600,color:D.text.primary,fontFamily:cn.mono},children:J}),ye&&U.jsx("span",{style:Rt.badge(ye.color,ye.bg),children:F}),s&&U.jsx("span",{style:{fontSize:11,color:D.text.muted},children:s})]}),U.jsx("button",{onClick:a,style:{...Rt.button,padding:"2px 8px",fontSize:11},children:"✕"})]}),U.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gap:6,marginBottom:10},children:A.slice(0,12).map(([ee,ge])=>U.jsx(C4,{label:ee.replace(/_/g," ").replace(/\./g," > "),value:ge,bold:ee==="grand_total"||ee==="total"||ee==="amount"},ee))}),h&&U.jsx("div",{style:{fontSize:11,color:S?D.success:D.error,marginBottom:8},children:h}),U.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",paddingTop:8,borderTop:`1px solid ${D.border}`},children:[ke&&J&&U.jsx(Dl,{label:"Submit",variant:"success",loading:f==="submit",confirm:!0,onClick:()=>N("submit","erpnext_doc_submit",{doctype:s??"",name:J},"Submitted")}),me&&J&&U.jsx(Dl,{label:"Cancel",variant:"error",loading:f==="cancel",confirm:!0,onClick:()=>N("cancel","erpnext_doc_cancel",{doctype:s??"",name:J},"Cancelled")}),se.map((ee,ge)=>U.jsx(Dl,{label:ee.label,onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:ee.message}]})}catch{}}},ge)),J&&s&&se.length===0&&U.jsx(Dl,{label:"Full details",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show me the full details of ${s} ${J}`}]})}catch{}}})]})]})}function L4(n){return["status","docstatus","workflow_state"].includes(n.toLowerCase())}function Z4({columns:n,chipFilters:r,onFilterChange:o}){return n.length===0?null:U.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center",marginBottom:12},children:n.map(({col:s,values:t})=>U.jsxs(we.Fragment,{children:[U.jsx("span",{style:{fontSize:10,color:D.text.faint,textTransform:"uppercase",letterSpacing:"0.1em",fontWeight:700},children:s.replace(/_/g," ")}),U.jsx("button",{onClick:()=>o(s,null),style:{...Rt.button,padding:"4px 10px",fontSize:10,borderRadius:8,border:"1px solid transparent",background:r[s]==null?D.accentDim:D.bg.elevated,color:r[s]==null?D.accent:D.text.secondary,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},children:"All"}),t.map(a=>{const c=r[s]===a,f=L4(s)?rp[a]:null;return U.jsx("button",{onClick:()=>o(s,a),style:{...Rt.button,padding:"4px 10px",fontSize:10,borderRadius:8,border:"1px solid transparent",background:c?f?.bg??D.accentDim:D.bg.elevated,color:c?f?.color??D.accent:D.text.secondary,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},children:a},a)})]},s))})}function Ul({label:n,disabled:r,onClick:o}){return U.jsx("button",{onClick:o,disabled:r,style:{...Rt.button,padding:"4px 10px",fontSize:11,opacity:r?.4:1,cursor:r?"default":"pointer"},onMouseEnter:s=>{r||(s.currentTarget.style.borderColor=D.accent)},onMouseLeave:s=>{s.currentTarget.style.borderColor=D.border},children:n})}const zn=new np({name:"Doclist Viewer",version:"2.0.0"}),A4=15e3,Cl=1e4;function M4(){const[n,r]=we.useState(null),[o,s]=we.useState(!0),[t,a]=we.useState(!1),[c,f]=we.useState(null),g=we.useRef(null),h=we.useRef(null),y=we.useRef(!1),S=we.useRef(0);function T(J){g.current=J,h.current=Zv(J,h.current),r(J)}function N(J){if(J.isError){const ye=Hl(J);return f(ye??"Tool returned an error"),s(!1),!1}const F=Hl(J);if(!F)return!1;try{const ye=JSON.parse(F);if(!ye)return!1;if(!Array.isArray(ye.data))if(ye._title||ye._rowAction||ye.count!=null)ye.data=[];else return!1;return T(ye),f(null),s(!1),!0}catch{return f("Failed to parse doclist payload"),s(!1),!1}}async function A(J={}){const F=Zv(g.current,h.current);if(b4({request:F,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:y.current,now:Date.now(),lastRefreshStartedAt:S.current,minIntervalMs:A4},J)&&!(!F||!zn.getHostCapabilities()?.serverTools)){y.current=!0,S.current=Date.now(),a(!0);try{const ye=await zn.callServerTool({name:F.toolName,arguments:F.arguments},{timeout:Cl});ye.isError?f("Refresh failed"):N(ye)||f("Refresh returned no data")}catch(ye){f(x4(ye))}finally{y.current=!1,a(!1)}}}return we.useEffect(()=>{zn.connect().catch(()=>{}),zn.ontoolresult=J=>{N(J)},zn.ontoolinputpartial=()=>{g.current||s(!0)}},[]),we.useEffect(()=>{const J=()=>void A({ignoreInterval:!0}),F=()=>{document.visibilityState==="visible"&&A({ignoreInterval:!0})};return window.addEventListener("focus",J),document.addEventListener("visibilitychange",F),()=>{window.removeEventListener("focus",J),document.removeEventListener("visibilitychange",F)}},[]),U.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},"aria-busy":t,children:[U.jsx(S4,{}),U.jsx("div",{style:{flex:1},children:o?U.jsx(D4,{}):n?U.jsx(F4,{data:n,error:c,refreshing:t,onRefresh:()=>void A({ignoreInterval:!0}),onError:f}):U.jsx(U4,{})}),U.jsx(w4,{})]})}const nd=20;function F4({data:n,error:r,refreshing:o,onRefresh:s,onError:t}){const[a,c]=we.useState(null),[f,g]=we.useState("asc"),[h,y]=we.useState(""),[S,T]=we.useState(0),[N,A]=we.useState(null),[J,F]=we.useState(null),[ye,ke]=we.useState(!1),[me,se]=we.useState({}),ee=we.useRef(),ge=we.useRef(null),$e=n._rowAction,xe=n.data??[],Pt=xe.length>0&&xe[0]._detail!=null,Ht=!!$e||Pt;async function yn(_){const P=String($e?Mv(_,$e.idField)??"":_._id??_.name??"");if(P){if(N===P){A(null),F(null);return}if(!$e&&_._detail){A(P),F(_._detail);return}if($e){A(P),F(null),ke(!0),ge.current=P;try{const V={...$e.extraArgs,[$e.argName]:P},K=await zn.callServerTool({name:$e.toolName,arguments:V},{timeout:Cl});if(ge.current!==P)return;if(K.isError)t("Failed to load details"),A(null);else{const te=Hl(K);if(te){const pe=JSON.parse(te);F(pe.data??pe),t(null)}}}catch(V){if(ge.current!==P)return;t(V instanceof Error?V.message:"Failed to load details"),A(null)}finally{ge.current===P&&ke(!1)}}}}async function Jt(_,P){try{if((await zn.callServerTool({name:_,arguments:P},{timeout:Cl})).isError)return!1;const K=N;return clearTimeout(ee.current),ee.current=setTimeout(async()=>{if(K&&$e&&ge.current===K)try{const te=await zn.callServerTool({name:$e.toolName,arguments:{...$e.extraArgs,[$e.argName]:K}},{timeout:Cl});if(ge.current!==K)return;if(!te.isError){const pe=Hl(te);if(pe){const Se=JSON.parse(pe);F(Se.data??Se)}}}catch{}},1500),!0}catch{return!1}}we.useEffect(()=>{A(null),F(null)},[a,f,h,S,me]);const yt=we.useMemo(()=>{if(xe.length<2)return[];const _=[];for(const P of Object.keys(xe[0]??{})){if(!T4.has(P)&&!Av(P))continue;const V=new Set;for(const K of xe){const te=K[P];if(te!=null&&typeof te=="string"&&V.add(te),V.size>8)break}V.size>=2&&V.size<=8&&_.push({col:P,values:Array.from(V).sort()})}return _},[xe]),Qe=we.useMemo(()=>{if(xe.length===0)return[];const _=new Set;for(const P of xe)for(const V of Object.keys(P))!z4.has(V)&&!V.startsWith("_")&&_.add(V);return P4(Array.from(_))},[xe]),wt=we.useMemo(()=>{let _=xe;for(const[P,V]of Object.entries(me))V&&(_=_.filter(K=>K[P]===V));if(h){const P=h.toLowerCase();_=_.filter(V=>Qe.some(K=>Jl(V[K]).toLowerCase().includes(P)))}return _},[xe,h,Qe,me]),Ye=we.useMemo(()=>a?[...wt].sort((_,P)=>{const V=_[a],K=P[a];if(V==null&&K==null)return 0;if(V==null)return 1;if(K==null)return-1;const te=typeof V=="number"&&typeof K=="number"?V-K:String(V).localeCompare(String(K));return f==="asc"?te:-te}):wt,[wt,a,f]),De=Math.ceil(Ye.length/nd),q=Ye.slice(S*nd,(S+1)*nd),oe=we.useCallback(_=>{a===_?g(P=>P==="asc"?"desc":"asc"):(c(_),g("asc"))},[a]),B=n._title??n.doctype??"Documents";return U.jsxs("div",{style:{padding:16,fontFamily:cn.sans},children:[U.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12,flexWrap:"wrap",gap:8},children:[U.jsxs("div",{children:[U.jsx("div",{style:{fontSize:16,fontWeight:700,color:D.text.primary},children:B}),U.jsxs("div",{style:{fontSize:12,color:D.text.muted},children:[Ye.length," of ",n.count??xe.length," records"]}),U.jsx("div",{"aria-live":"polite",style:{fontSize:11,color:r?D.error:D.text.faint,marginTop:4},children:r??(o?"Refreshing…":"Auto-refresh on focus")})]}),U.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[U.jsx("input",{type:"text",placeholder:"Search...",value:h,onChange:_=>{y(_.target.value),T(0)},style:{...Rt.input,maxWidth:200},onFocus:_=>{_.target.style.borderColor=D.accent},onBlur:_=>{_.target.style.borderColor=D.border}}),U.jsx("button",{onClick:s,disabled:o,style:Rt.button,onMouseEnter:_=>{o||(_.currentTarget.style.borderColor=D.accent,_.currentTarget.style.color=D.accent)},onMouseLeave:_=>{_.currentTarget.style.borderColor=D.border,_.currentTarget.style.color=D.text.secondary},children:U.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[U.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:[U.jsx("path",{d:"M10 6a4 4 0 1 1-1.1-2.76",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),U.jsx("path",{d:"M10 2v2.8H7.2",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]}),o?"Refreshing":"Refresh"]})}),U.jsx("button",{onClick:()=>N4(Qe,Ye,n.doctype),style:Rt.button,onMouseEnter:_=>{_.currentTarget.style.borderColor=D.accent,_.currentTarget.style.color=D.accent},onMouseLeave:_=>{_.currentTarget.style.borderColor=D.border,_.currentTarget.style.color=D.text.secondary},children:U.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[U.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:U.jsx("path",{d:"M6 1v8M6 9l-3-3M6 9l3-3M2 11h8",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})}),"CSV"]})})]})]}),U.jsx(Z4,{columns:yt,chipFilters:me,onFilterChange:(_,P)=>{se(V=>{if(P===null){const K={...V};return delete K[_],K}return{...V,[_]:P}}),T(0)}}),U.jsx("div",{style:{border:`1px solid ${D.border}`,borderRadius:8,overflow:"hidden"},children:U.jsx("div",{style:{overflowX:"auto"},children:U.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:Math.max(600,Qe.length*120)},children:[U.jsx("thead",{children:U.jsx("tr",{children:Qe.map(_=>U.jsxs("th",{onClick:()=>oe(_),style:{...Rt.tableHeader,background:D.bg.surface,color:a===_?D.accent:D.text.muted},children:[_.replace(/_/g," "),U.jsx("span",{style:{marginLeft:4,opacity:a===_?1:.3,fontSize:10},children:a===_?f==="asc"?"▲":"▼":"⇅"})]},_))})}),U.jsx("tbody",{children:q.length===0?U.jsx("tr",{children:U.jsx("td",{colSpan:Qe.length,style:{...Rt.tableCell,textAlign:"center",color:D.text.muted,padding:32},children:"No matching records"})}):q.map((_,P)=>{const V=String($e?Mv(_,$e.idField)??"":_._id??_.name??P),K=N===V&&V!=="";return U.jsxs(we.Fragment,{children:[U.jsx("tr",{style:{transition:"background 0.1s",cursor:Ht?"pointer":"default",background:K?D.bg.hover:"transparent"},onClick:Ht?()=>void yn(_):void 0,onMouseEnter:te=>{K||(te.currentTarget.style.background=D.bg.hover)},onMouseLeave:te=>{K||(te.currentTarget.style.background="transparent")},children:Qe.map((te,pe)=>{const Se=_[te],Te=typeof Se=="number",Ze=Av(te)&&typeof Se=="string";return U.jsx("td",{style:{...Rt.tableCell,...Te?{textAlign:"right",fontFamily:cn.mono,fontSize:12}:{},...te==="name"?{fontWeight:500}:{},maxWidth:250,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:U.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,justifyContent:Te?"flex-end":"flex-start"},children:[ye&&K&&pe===0&&U.jsx("span",{className:"skeleton",style:{width:12,height:12,borderRadius:"50%",display:"inline-block",flexShrink:0}}),Ze?U.jsx(O4,{value:Se}):Jl(Se)]})},te)})}),K&&U.jsx("tr",{children:U.jsx("td",{colSpan:Qe.length,style:{padding:0,borderBottom:`1px solid ${D.border}`},children:U.jsx(R4,{app:zn,data:J,loading:ye,doctype:n.doctype,sendMessageHints:n._sendMessageHints,onClose:()=>{A(null),F(null)},onAction:Jt})})})]},P)})})]})})}),De>1&&U.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:12,flexWrap:"wrap",gap:8},children:[U.jsxs("div",{style:{fontSize:12,color:D.text.muted},children:["Page ",S+1," of ",De]}),U.jsxs("div",{style:{display:"flex",gap:4},children:[U.jsx(Ul,{label:"First",disabled:S===0,onClick:()=>T(0)}),U.jsx(Ul,{label:"Prev",disabled:S===0,onClick:()=>T(_=>_-1)}),U.jsx(Ul,{label:"Next",disabled:S>=De-1,onClick:()=>T(_=>_+1)}),U.jsx(Ul,{label:"Last",disabled:S>=De-1,onClick:()=>T(De-1)})]})]})]})}Pb.createRoot(document.getElementById("app")).render(U.jsx(M4,{}));</script>
|
|
150
|
+
${t}`,c=new Blob([a],{type:"text/csv"}),f=URL.createObjectURL(c),g=document.createElement("a");g.href=f,g.download=`${o??"export"}.csv`,g.click(),URL.revokeObjectURL(f)}function Mv(n,r){let o=n;for(const s of r.split(".")){if(o==null||typeof o!="object")return;o=o[s]}return o}const rp={Submitted:{color:D.success,bg:D.successDim},Completed:{color:D.success,bg:D.successDim},Paid:{color:D.success,bg:D.successDim},Active:{color:D.success,bg:D.successDim},Enabled:{color:D.success,bg:D.successDim},"To Deliver and Bill":{color:D.info,bg:D.infoDim},"To Bill":{color:D.info,bg:D.infoDim},"To Deliver":{color:D.info,bg:D.infoDim},Draft:{color:D.text.muted,bg:D.bg.elevated},Pending:{color:D.warning,bg:D.warningDim},Open:{color:D.warning,bg:D.warningDim},"Partly Paid":{color:D.warning,bg:D.warningDim},"Partly Delivered":{color:D.warning,bg:D.warningDim},Cancelled:{color:D.error,bg:D.errorDim},Overdue:{color:D.error,bg:D.errorDim},Closed:{color:D.text.faint,bg:D.bg.elevated},Disabled:{color:D.text.faint,bg:D.bg.elevated}};function O4({value:n}){const r=rp[n];return r?U.jsx("span",{style:Rt.badge(r.color,r.bg),children:n}):U.jsx("span",{children:n})}function D4(){return U.jsx("div",{style:{padding:24},children:U.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[[1,2,3,4].map(n=>U.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:n===1?"40%":`${60+n*8}%`}},n)),U.jsx("div",{style:{marginTop:8},children:[1,2,3,4,5].map(n=>U.jsx("div",{className:"skeleton",style:{height:36,marginBottom:2}},n))})]})})}function U4(){return U.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:D.text.muted,gap:16},children:[U.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[U.jsx("rect",{x:"8",y:"8",width:"40",height:"40",rx:"4",stroke:"currentColor",strokeWidth:"2"}),U.jsx("path",{d:"M8 18h40",stroke:"currentColor",strokeWidth:"2"}),U.jsx("path",{d:"M20 8v40M36 8v40",stroke:"currentColor",strokeWidth:"1",opacity:"0.3"}),U.jsx("path",{d:"M8 28h40M8 38h40",stroke:"currentColor",strokeWidth:"1",opacity:"0.3"})]}),U.jsxs("div",{style:{fontSize:13,textAlign:"center"},children:["No documents to display",U.jsx("div",{style:{fontSize:11,color:D.text.faint,marginTop:4},children:"Query a DocType to see results in this table"})]})]})}const Fv={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 Dl({label:n,variant:r="default",disabled:o,loading:s,confirm:t,onClick:a}){const[c,f]=we.useState(!1),g=we.useRef();we.useEffect(()=>()=>clearTimeout(g.current),[]);const h=Fv[r]??Fv.default;return U.jsx("button",{onClick:()=>{if(t&&!c){f(!0),clearTimeout(g.current),g.current=setTimeout(()=>f(!1),4e3);return}f(!1),a()},disabled:o||s,style:{...Rt.button,background:h.bg,color:h.color,borderColor:h.color,opacity:o||s?.5:1,fontSize:11,padding:"4px 10px"},children:s?"…":c?"Confirm?":n})}function C4({label:n,value:r,bold:o}){return U.jsxs("div",{style:{padding:"4px 0"},children:[U.jsx("div",{style:{fontSize:10,color:D.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:2},children:n}),U.jsx("div",{style:{fontSize:o?15:13,fontWeight:o?600:500,color:D.text.primary,fontFamily:o?cn.mono:cn.sans},children:r??"—"})]})}function R4({app:n,data:r,loading:o,doctype:s,sendMessageHints:t,onClose:a,onAction:c}){const[f,g]=we.useState(null),[h,y]=we.useState(null),[S,T]=we.useState(!0);if(o)return U.jsx("div",{style:{padding:16,background:D.bg.surface},children:[1,2,3].map(ee=>U.jsx("div",{className:"skeleton",style:{height:14,width:`${30+ee*15}%`,marginBottom:8}},ee))});if(!r)return null;async function N(ee,ge,$e,xe){g(ee),y(null);const Pt=await c(ge,$e);T(Pt),y(Pt?xe:"Action failed"),g(null)}const A=[];for(const[ee,ge]of Object.entries(r))if(!(ee.startsWith("_")||ee==="refreshRequest"||ee==="doctype")&&ge!=null)if(Array.isArray(ge))A.push([ee,`${ge.length} item${ge.length>1?"s":""}`]);else if(typeof ge=="object")for(const[$e,xe]of Object.entries(ge))xe!=null&&typeof xe!="object"&&A.push([`${ee}.${$e}`,String(xe)]);else A.push([ee,Jl(ge)]);const J=String(r.name??""),F=String(r.status??r.docstatus??""),ye=rp[F],ke=F==="Draft"||r.docstatus===0,me=r.docstatus===1,se=t?.map(ee=>({...ee,message:ee.message.replace(/\{id\}/g,J).replace(/\{doctype\}/g,s??"")}))??[];return U.jsxs("div",{style:{padding:16,background:D.bg.surface,borderTop:`2px solid ${D.accent}`},children:[U.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[U.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[U.jsx("span",{style:{fontSize:14,fontWeight:600,color:D.text.primary,fontFamily:cn.mono},children:J}),ye&&U.jsx("span",{style:Rt.badge(ye.color,ye.bg),children:F}),s&&U.jsx("span",{style:{fontSize:11,color:D.text.muted},children:s})]}),U.jsx("button",{onClick:a,style:{...Rt.button,padding:"2px 8px",fontSize:11},children:"✕"})]}),U.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gap:6,marginBottom:10},children:A.slice(0,12).map(([ee,ge])=>U.jsx(C4,{label:ee.replace(/_/g," ").replace(/\./g," > "),value:ge,bold:ee==="grand_total"||ee==="total"||ee==="amount"},ee))}),h&&U.jsx("div",{style:{fontSize:11,color:S?D.success:D.error,marginBottom:8},children:h}),U.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",paddingTop:8,borderTop:`1px solid ${D.border}`},children:[ke&&J&&U.jsx(Dl,{label:"Submit",variant:"success",loading:f==="submit",confirm:!0,onClick:()=>N("submit","erpnext_doc_submit",{doctype:s??"",name:J},"Submitted")}),me&&J&&U.jsx(Dl,{label:"Cancel",variant:"error",loading:f==="cancel",confirm:!0,onClick:()=>N("cancel","erpnext_doc_cancel",{doctype:s??"",name:J},"Cancelled")}),se.map((ee,ge)=>U.jsx(Dl,{label:ee.label,onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:ee.message}]})}catch{}}},ge)),J&&s&&se.length===0&&U.jsx(Dl,{label:"Full details",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show me the full details of ${s} ${J}`}]})}catch{}}})]})]})}function L4(n){return["status","docstatus","workflow_state"].includes(n.toLowerCase())}function Z4({columns:n,chipFilters:r,onFilterChange:o}){return n.length===0?null:U.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center",marginBottom:12},children:n.map(({col:s,values:t})=>U.jsxs(we.Fragment,{children:[U.jsx("span",{style:{fontSize:10,color:D.text.faint,textTransform:"uppercase",letterSpacing:"0.1em",fontWeight:700},children:s.replace(/_/g," ")}),U.jsx("button",{onClick:()=>o(s,null),style:{...Rt.button,padding:"4px 10px",fontSize:10,borderRadius:8,border:"1px solid transparent",background:r[s]==null?D.accentDim:D.bg.elevated,color:r[s]==null?D.accent:D.text.secondary,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},children:"All"}),t.map(a=>{const c=r[s]===a,f=L4(s)?rp[a]:null;return U.jsx("button",{onClick:()=>o(s,a),style:{...Rt.button,padding:"4px 10px",fontSize:10,borderRadius:8,border:"1px solid transparent",background:c?f?.bg??D.accentDim:D.bg.elevated,color:c?f?.color??D.accent:D.text.secondary,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},children:a},a)})]},s))})}function Ul({label:n,disabled:r,onClick:o}){return U.jsx("button",{onClick:o,disabled:r,style:{...Rt.button,padding:"4px 10px",fontSize:11,opacity:r?.4:1,cursor:r?"default":"pointer"},onMouseEnter:s=>{r||(s.currentTarget.style.borderColor=D.accent)},onMouseLeave:s=>{s.currentTarget.style.borderColor=D.border},children:n})}const zn=new np({name:"Doclist Viewer",version:"2.0.0"}),A4=15e3,Cl=1e4;function M4(){const[n,r]=we.useState(null),[o,s]=we.useState(!0),[t,a]=we.useState(!1),[c,f]=we.useState(null),g=we.useRef(null),h=we.useRef(null),y=we.useRef(!1),S=we.useRef(0);function T(J){g.current=J,h.current=Zv(J,h.current),r(J)}function N(J){if(J.isError){const ye=Hl(J);return f(ye??"Tool returned an error"),s(!1),!1}const F=Hl(J);if(!F)return!1;try{const ye=JSON.parse(F);if(!ye)return!1;if(!Array.isArray(ye.data))if(ye._title||ye._rowAction||ye.count!=null)ye.data=[];else return!1;return T(ye),f(null),s(!1),!0}catch{return f("Failed to parse doclist payload"),s(!1),!1}}async function A(J={}){const F=Zv(g.current,h.current);if(b4({request:F,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:y.current,now:Date.now(),lastRefreshStartedAt:S.current,minIntervalMs:A4},J)&&!(!F||!zn.getHostCapabilities()?.serverTools)){y.current=!0,S.current=Date.now(),a(!0);try{const ye=await zn.callServerTool({name:F.toolName,arguments:F.arguments},{timeout:Cl});ye.isError?f("Refresh failed"):N(ye)||f("Refresh returned no data")}catch(ye){f(x4(ye))}finally{y.current=!1,a(!1)}}}return we.useEffect(()=>{zn.ontoolresult=J=>{N(J)},zn.ontoolinputpartial=()=>{g.current||s(!0)},zn.connect().catch(()=>{})},[]),we.useEffect(()=>{const J=()=>void A({ignoreInterval:!0}),F=()=>{document.visibilityState==="visible"&&A({ignoreInterval:!0})};return window.addEventListener("focus",J),document.addEventListener("visibilitychange",F),()=>{window.removeEventListener("focus",J),document.removeEventListener("visibilitychange",F)}},[]),U.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},"aria-busy":t,children:[U.jsx(S4,{}),U.jsx("div",{style:{flex:1},children:o?U.jsx(D4,{}):n?U.jsx(F4,{data:n,error:c,refreshing:t,onRefresh:()=>void A({ignoreInterval:!0}),onError:f}):U.jsx(U4,{})}),U.jsx(w4,{})]})}const nd=20;function F4({data:n,error:r,refreshing:o,onRefresh:s,onError:t}){const[a,c]=we.useState(null),[f,g]=we.useState("asc"),[h,y]=we.useState(""),[S,T]=we.useState(0),[N,A]=we.useState(null),[J,F]=we.useState(null),[ye,ke]=we.useState(!1),[me,se]=we.useState({}),ee=we.useRef(),ge=we.useRef(null),$e=n._rowAction,xe=n.data??[],Pt=xe.length>0&&xe[0]._detail!=null,Ht=!!$e||Pt;async function yn(_){const P=String($e?Mv(_,$e.idField)??"":_._id??_.name??"");if(P){if(N===P){A(null),F(null);return}if(!$e&&_._detail){A(P),F(_._detail);return}if($e){A(P),F(null),ke(!0),ge.current=P;try{const V={...$e.extraArgs,[$e.argName]:P},K=await zn.callServerTool({name:$e.toolName,arguments:V},{timeout:Cl});if(ge.current!==P)return;if(K.isError)t("Failed to load details"),A(null);else{const te=Hl(K);if(te){const pe=JSON.parse(te);F(pe.data??pe),t(null)}}}catch(V){if(ge.current!==P)return;t(V instanceof Error?V.message:"Failed to load details"),A(null)}finally{ge.current===P&&ke(!1)}}}}async function Jt(_,P){try{if((await zn.callServerTool({name:_,arguments:P},{timeout:Cl})).isError)return!1;const K=N;return clearTimeout(ee.current),ee.current=setTimeout(async()=>{if(K&&$e&&ge.current===K)try{const te=await zn.callServerTool({name:$e.toolName,arguments:{...$e.extraArgs,[$e.argName]:K}},{timeout:Cl});if(ge.current!==K)return;if(!te.isError){const pe=Hl(te);if(pe){const Se=JSON.parse(pe);F(Se.data??Se)}}}catch{}},1500),!0}catch{return!1}}we.useEffect(()=>{A(null),F(null)},[a,f,h,S,me]);const yt=we.useMemo(()=>{if(xe.length<2)return[];const _=[];for(const P of Object.keys(xe[0]??{})){if(!T4.has(P)&&!Av(P))continue;const V=new Set;for(const K of xe){const te=K[P];if(te!=null&&typeof te=="string"&&V.add(te),V.size>8)break}V.size>=2&&V.size<=8&&_.push({col:P,values:Array.from(V).sort()})}return _},[xe]),Qe=we.useMemo(()=>{if(xe.length===0)return[];const _=new Set;for(const P of xe)for(const V of Object.keys(P))!z4.has(V)&&!V.startsWith("_")&&_.add(V);return P4(Array.from(_))},[xe]),wt=we.useMemo(()=>{let _=xe;for(const[P,V]of Object.entries(me))V&&(_=_.filter(K=>K[P]===V));if(h){const P=h.toLowerCase();_=_.filter(V=>Qe.some(K=>Jl(V[K]).toLowerCase().includes(P)))}return _},[xe,h,Qe,me]),Ye=we.useMemo(()=>a?[...wt].sort((_,P)=>{const V=_[a],K=P[a];if(V==null&&K==null)return 0;if(V==null)return 1;if(K==null)return-1;const te=typeof V=="number"&&typeof K=="number"?V-K:String(V).localeCompare(String(K));return f==="asc"?te:-te}):wt,[wt,a,f]),De=Math.ceil(Ye.length/nd),q=Ye.slice(S*nd,(S+1)*nd),oe=we.useCallback(_=>{a===_?g(P=>P==="asc"?"desc":"asc"):(c(_),g("asc"))},[a]),B=n._title??n.doctype??"Documents";return U.jsxs("div",{style:{padding:16,fontFamily:cn.sans},children:[U.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12,flexWrap:"wrap",gap:8},children:[U.jsxs("div",{children:[U.jsx("div",{style:{fontSize:16,fontWeight:700,color:D.text.primary},children:B}),U.jsxs("div",{style:{fontSize:12,color:D.text.muted},children:[Ye.length," of ",n.count??xe.length," records"]}),U.jsx("div",{"aria-live":"polite",style:{fontSize:11,color:r?D.error:D.text.faint,marginTop:4},children:r??(o?"Refreshing…":"Auto-refresh on focus")})]}),U.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[U.jsx("input",{type:"text",placeholder:"Search...",value:h,onChange:_=>{y(_.target.value),T(0)},style:{...Rt.input,maxWidth:200},onFocus:_=>{_.target.style.borderColor=D.accent},onBlur:_=>{_.target.style.borderColor=D.border}}),U.jsx("button",{onClick:s,disabled:o,style:Rt.button,onMouseEnter:_=>{o||(_.currentTarget.style.borderColor=D.accent,_.currentTarget.style.color=D.accent)},onMouseLeave:_=>{_.currentTarget.style.borderColor=D.border,_.currentTarget.style.color=D.text.secondary},children:U.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[U.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:[U.jsx("path",{d:"M10 6a4 4 0 1 1-1.1-2.76",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"}),U.jsx("path",{d:"M10 2v2.8H7.2",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})]}),o?"Refreshing":"Refresh"]})}),U.jsx("button",{onClick:()=>N4(Qe,Ye,n.doctype),style:Rt.button,onMouseEnter:_=>{_.currentTarget.style.borderColor=D.accent,_.currentTarget.style.color=D.accent},onMouseLeave:_=>{_.currentTarget.style.borderColor=D.border,_.currentTarget.style.color=D.text.secondary},children:U.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[U.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:U.jsx("path",{d:"M6 1v8M6 9l-3-3M6 9l3-3M2 11h8",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})}),"CSV"]})})]})]}),U.jsx(Z4,{columns:yt,chipFilters:me,onFilterChange:(_,P)=>{se(V=>{if(P===null){const K={...V};return delete K[_],K}return{...V,[_]:P}}),T(0)}}),U.jsx("div",{style:{border:`1px solid ${D.border}`,borderRadius:8,overflow:"hidden"},children:U.jsx("div",{style:{overflowX:"auto"},children:U.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",minWidth:Math.max(600,Qe.length*120)},children:[U.jsx("thead",{children:U.jsx("tr",{children:Qe.map(_=>U.jsxs("th",{onClick:()=>oe(_),style:{...Rt.tableHeader,background:D.bg.surface,color:a===_?D.accent:D.text.muted},children:[_.replace(/_/g," "),U.jsx("span",{style:{marginLeft:4,opacity:a===_?1:.3,fontSize:10},children:a===_?f==="asc"?"▲":"▼":"⇅"})]},_))})}),U.jsx("tbody",{children:q.length===0?U.jsx("tr",{children:U.jsx("td",{colSpan:Qe.length,style:{...Rt.tableCell,textAlign:"center",color:D.text.muted,padding:32},children:"No matching records"})}):q.map((_,P)=>{const V=String($e?Mv(_,$e.idField)??"":_._id??_.name??P),K=N===V&&V!=="";return U.jsxs(we.Fragment,{children:[U.jsx("tr",{style:{transition:"background 0.1s",cursor:Ht?"pointer":"default",background:K?D.bg.hover:"transparent"},onClick:Ht?()=>void yn(_):void 0,onMouseEnter:te=>{K||(te.currentTarget.style.background=D.bg.hover)},onMouseLeave:te=>{K||(te.currentTarget.style.background="transparent")},children:Qe.map((te,pe)=>{const Se=_[te],Te=typeof Se=="number",Ze=Av(te)&&typeof Se=="string";return U.jsx("td",{style:{...Rt.tableCell,...Te?{textAlign:"right",fontFamily:cn.mono,fontSize:12}:{},...te==="name"?{fontWeight:500}:{},maxWidth:250,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:U.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,justifyContent:Te?"flex-end":"flex-start"},children:[ye&&K&&pe===0&&U.jsx("span",{className:"skeleton",style:{width:12,height:12,borderRadius:"50%",display:"inline-block",flexShrink:0}}),Ze?U.jsx(O4,{value:Se}):Jl(Se)]})},te)})}),K&&U.jsx("tr",{children:U.jsx("td",{colSpan:Qe.length,style:{padding:0,borderBottom:`1px solid ${D.border}`},children:U.jsx(R4,{app:zn,data:J,loading:ye,doctype:n.doctype,sendMessageHints:n._sendMessageHints,onClose:()=>{A(null),F(null)},onAction:Jt})})})]},P)})})]})})}),De>1&&U.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:12,flexWrap:"wrap",gap:8},children:[U.jsxs("div",{style:{fontSize:12,color:D.text.muted},children:["Page ",S+1," of ",De]}),U.jsxs("div",{style:{display:"flex",gap:4},children:[U.jsx(Ul,{label:"First",disabled:S===0,onClick:()=>T(0)}),U.jsx(Ul,{label:"Prev",disabled:S===0,onClick:()=>T(_=>_-1)}),U.jsx(Ul,{label:"Next",disabled:S>=De-1,onClick:()=>T(_=>_+1)}),U.jsx(Ul,{label:"Last",disabled:S>=De-1,onClick:()=>T(De-1)})]})]})]})}Pb.createRoot(document.getElementById("app")).render(U.jsx(M4,{}));</script>
|
|
151
151
|
<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>
|
|
152
152
|
</head>
|
|
153
153
|
<body>
|
|
@@ -145,7 +145,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
145
145
|
- omitted: host decides border`)});E({method:x("ui/request-display-mode"),params:E({mode:go.describe("The display mode being requested.")})});var a4=E({mode:go.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),l4=ce([x("model"),x("app")]).describe("Tool visibility scope - who can access the tool.");E({resourceUri:I().optional(),visibility:te(l4).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
146
146
|
- "model": Tool visible to and callable by the agent
|
|
147
147
|
- "app": Tool callable by the app from this server only`),csp:yr().optional(),permissions:yr().optional()});E({mimeTypes:te(I()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')});E({method:x("ui/download-file"),params:E({contents:te(ce([cS,dS])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})});E({method:x("ui/message"),params:E({role:x("user").describe('Message role, currently only "user" is supported.'),content:te(va).describe("Message content blocks (text, image, etc.).")})});E({method:x("ui/notifications/sandbox-resource-ready"),params:E({html:I().describe("HTML content to load into the inner iframe."),sandbox:I().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:Bm.optional().describe("CSP configuration from resource metadata."),permissions:Km.optional().describe("Sandbox permissions from resource metadata.")})});var s4=E({method:x("ui/notifications/tool-result"),params:Qs.describe("Standard MCP tool execution result.")}),vS=E({toolInfo:E({id:da.optional().describe("JSON-RPC id of the tools/call request."),tool:Wm.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:V1.optional().describe("Current color theme preference."),styles:n4.optional().describe("Style configuration for theming the app."),displayMode:go.optional().describe("How the UI is currently displayed."),availableDisplayModes:te(go).optional().describe("Display modes the host supports."),containerDimensions:ce([E({height:ae().describe("Fixed container height in pixels.")}),E({maxHeight:ce([ae(),ri()]).optional().describe("Maximum container height in pixels.")})]).and(ce([E({width:ae().describe("Fixed container width in pixels.")}),E({maxWidth:ce([ae(),ri()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
148
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:I().optional().describe("User's language and region preference in BCP 47 format."),timeZone:I().optional().describe("User's timezone in IANA format."),userAgent:I().optional().describe("Host application identifier."),platform:ce([x("web"),x("desktop"),x("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:E({touch:Se().optional().describe("Whether the device supports touch input."),hover:Se().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:E({top:ae().describe("Top safe area inset in pixels."),right:ae().describe("Right safe area inset in pixels."),bottom:ae().describe("Bottom safe area inset in pixels."),left:ae().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),u4=E({method:x("ui/notifications/host-context-changed"),params:vS.describe("Partial context update containing only changed fields.")});E({method:x("ui/update-model-context"),params:E({content:te(va).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:pe(I(),$e().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});E({method:x("ui/initialize"),params:E({appInfo:Ks.describe("App identification (name and version)."),appCapabilities:o4.describe("Features and capabilities this app provides."),protocolVersion:I().describe("Protocol version this app supports.")})});var c4=E({protocolVersion:I().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Ks.describe("Host application identification and version."),hostCapabilities:i4.describe("Features and capabilities provided by the host."),hostContext:vS.describe("Rich context about the host environment.")}).passthrough(),d4={target:"draft-2020-12"};async function Pv(n,i){let o=n["~standard"];if(o.jsonSchema)return o.jsonSchema[i](d4);if(o.vendor==="zod"){let{z:s}=await Ib(()=>Promise.resolve().then(()=>YI),void 0,import.meta.url);return s.toJSONSchema(n,{io:i})}throw Error(`Schema (vendor: ${o.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function jv(n,i,o=""){let s=await n["~standard"].validate(i);if(s.issues){let t=s.issues.map(a=>{let c=a.path?.map(m=>typeof m=="object"?m.key:m).join(".");return c?`${c}: ${a.message}`:a.message}).join("; ");throw Error(o+t)}return s.value}class Gm extends F1{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(i){if(this._initializedSent)return;let o=`[ext-apps] App.${i}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(o);console.warn(`${o}. This will throw in a future release.`)}eventSchemas={toolinput:X1,toolinputpartial:Y1,toolresult:s4,toolcancelled:e4,hostcontextchanged:u4};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(i){if(!Gm.ONE_SHOT_EVENTS.has(i)||this._everHadListener.has(i)||(this._everHadListener.add(i),!this._initializedSent))return;let o=`[ext-apps] "${String(i)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(o);console.warn(o)}setEventHandler(i,o){o&&this._assertHandlerTiming(i),super.setEventHandler(i,o)}addEventListener(i,o){this._assertHandlerTiming(i),super.addEventListener(i,o)}onEventDispatch(i,o){i==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...o})}constructor(i,o={},s={autoResize:!0}){super(s),this._appInfo=i,this._capabilities=o,this.options=s,s.allowUnsafeEval||Ge({jitless:!0}),this.setRequestHandler(Gs,t=>(console.log("Received ping:",t.params),{})),this.setEventHandler("hostcontextchanged",void 0)}registerCapabilities(i){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._capabilities=M1(this._capabilities,i)}registerTool(i,o,s){if(this._registeredTools[i])throw Error(`Tool ${i} is already registered`);let t=this,a=()=>{t._initializedSent&&t._capabilities.tools?.listChanged&&t.sendToolListChanged()},c=o.inputSchema!==void 0,m={title:o.title,description:o.description,inputSchema:o.inputSchema,outputSchema:o.outputSchema,annotations:o.annotations,_meta:o._meta,enabled:!0,enable(){this.enabled=!0,a()},disable(){this.enabled=!1,a()},update(g){Object.assign(this,g),a()},remove(){t._registeredTools[i]===m&&(delete t._registeredTools[i],a())},handler:async(g,h)=>{if(!m.enabled)throw Error(`Tool ${i} is disabled`);let y;if(c){let S=m.inputSchema,z=S?await jv(S,g??{},`Invalid input for tool ${i}: `):g??{};y=await s(z,h)}else y=await s(h);return m.outputSchema&&!y.isError&&(y.structuredContent=await jv(m.outputSchema,y.structuredContent,`Invalid output for tool ${i}: `)),y}};return this._registeredTools[i]=m,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),a(),m}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(i,o)=>{let s=this._registeredTools[i.name];if(!s)throw Error(`Tool ${i.name} not found`);return s.handler(i.arguments,o)},this.onlisttools=async(i,o)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([s,t])=>t.enabled).map(async([s,t])=>{let a={name:s,title:t.title,description:t.description,inputSchema:t.inputSchema?await Pv(t.inputSchema,"input"):{type:"object",properties:{}}};return t.outputSchema&&(a.outputSchema=await Pv(t.outputSchema,"output")),t.annotations&&(a.annotations=t.annotations),t._meta&&(a._meta=t._meta),a}))}))}async sendToolListChanged(i={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:i})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(i){this.setEventHandler("toolinput",i)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(i){this.setEventHandler("toolinputpartial",i)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(i){this.setEventHandler("toolresult",i)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(i){this.setEventHandler("toolcancelled",i)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(i){this.setEventHandler("hostcontextchanged",i)}_onteardown;get onteardown(){return this._onteardown}set onteardown(i){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,i),this._onteardown=i,this.replaceRequestHandler(r4,(o,s)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(o.params,s)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(i){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,i),this._oncalltool=i,this.replaceRequestHandler(mS,(o,s)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(o.params,s)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(i){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,i),this._onlisttools=i,this.replaceRequestHandler(fS,(o,s)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(o.params,s)})}assertCapabilityForMethod(i){switch(i){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${i})`);break}}assertRequestHandlerCapability(i){switch(i){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${i})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${i} registered`)}}assertNotificationCapability(i){}assertTaskCapability(i){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(i){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(i,o){if(this._assertInitialized("callServerTool"),typeof i=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${i}"). Did you mean: callServerTool({ name: "${i}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:i},Qs,{onprogress:()=>{},resetTimeoutOnProgress:!0,...o})}async readServerResource(i,o){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:i},uS,o)}async listServerResources(i,o){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:i},sS,o)}async createSamplingMessage(i,o){this._assertInitialized("createSamplingMessage");let s=i.tools?hS:gS;return await this.request({method:"sampling/createMessage",params:i},s,o)}sendMessage(i,o){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:i},Q1,o)}sendLog(i){return this.notification({method:"notifications/message",params:i})}updateModelContext(i,o){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:i},Nm,o)}openLink(i,o){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:i},K1,o)}sendOpenLink=this.openLink;downloadFile(i,o){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:i},G1,o)}requestTeardown(i={}){return this.notification({method:"ui/notifications/request-teardown",params:i})}requestDisplayMode(i,o){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:i},a4,o)}sendSizeChanged(i){return this.notification({method:"ui/notifications/size-changed",params:i})}setupSizeChangedNotifications(){let i=!1,o=0,s=0,t=()=>{i||(i=!0,requestAnimationFrame(()=>{i=!1;let c=document.documentElement,m=c.style.height;c.style.height="max-content";let g=Math.ceil(c.getBoundingClientRect().height);c.style.height=m;let h=Math.ceil(window.innerWidth);(h!==o||g!==s)&&(o=h,s=g,this.sendSizeChanged({width:h,height:g}))}))};t();let a=new ResizeObserver(t);return a.observe(document.documentElement),a.observe(document.body),()=>a.disconnect()}async connect(i=new J1(window.parent,window.parent),o){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1,await super.connect(i);try{let s=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:q1}},c4,o);if(s===void 0)throw Error(`Server sent invalid initialize result: ${s}`);this._hostCapabilities=s.hostCapabilities,this._hostInfo=s.hostInfo,this._hostContext=s.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(s){throw this.close(),s}}}function Nt(n){return`var(${n})`}const ke={bg:{surface:Nt("--bg-surface"),elevated:Nt("--bg-elevated")},text:{primary:Nt("--text-primary"),secondary:Nt("--text-secondary"),muted:Nt("--text-muted"),faint:Nt("--text-faint")},accent:Nt("--accent"),border:Nt("--border"),success:Nt("--success"),error:Nt("--error"),warning:Nt("--warning")},Bn={sans:Nt("--font-sans"),mono:Nt("--font-mono")},Gc={card:{background:ke.bg.surface,border:`1px solid ${ke.border}`,borderRadius:"8px",padding:"16px"},button:{background:ke.bg.elevated,border:`1px solid ${ke.border}`,borderRadius:"6px",padding:"6px 14px",fontSize:"12px",color:ke.text.secondary,cursor:"pointer",transition:"all 0.15s",fontFamily:Bn.sans,whiteSpace:"nowrap"}};function f4(n,i=2){return n.toLocaleString("en-US",{minimumFractionDigits:i,maximumFractionDigits:i})}function m4(n,i="USD"){return n.toLocaleString("en-US",{style:"currency",currency:i,minimumFractionDigits:2,maximumFractionDigits:2})}function p4(){return G.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[G.jsx("rect",{x:"1",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.9"}),G.jsx("rect",{x:"9",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),G.jsx("rect",{x:"1",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),G.jsx("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.35"})]})}function g4(){const n={display:"flex",alignItems:"center",gap:7,padding:"0 14px",height:30,background:ke.bg.surface,borderBottom:`1px solid ${ke.border}`,flexShrink:0},i={fontFamily:Bn.sans,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:ke.accent},o={width:3,height:3,borderRadius:"50%",background:ke.text.faint,marginLeft:2,marginRight:2,flexShrink:0},s={fontFamily:Bn.sans,fontSize:10,color:ke.text.muted,letterSpacing:"0.03em"};return G.jsxs("div",{style:n,children:[G.jsx("div",{style:{color:ke.accent},children:G.jsx(p4,{})}),G.jsx("span",{style:i,children:"ERPNext"}),G.jsx("div",{style:o}),G.jsx("span",{style:s,children:"gestion ERP"})]})}function h4(n,i={}){return!n.request||n.visibilityState!=="visible"||n.refreshInFlight?!1:i.ignoreInterval?!0:n.now-n.lastRefreshStartedAt>=n.minIntervalMs}function Nv(n,i){return n?.refreshRequest??i}function v4(n){return n instanceof Error&&/timed? out/i.test(n.message)?"Refresh timed out":"Refresh failed"}function y4(n){return n.structuredContent?JSON.stringify(n.structuredContent):n.content?.find(i=>i.type==="text")?.text??null}const mr=new Gm({name:"Funnel Viewer",version:"1.0.0"}),_4=15e3,$4=1e4;function k4(){return G.jsx("div",{style:{padding:24},children:G.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[[1,2,3,4].map(n=>G.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:n===1?"40%":`${60+n*8}%`}},n)),G.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",alignItems:"center",gap:8},children:[100,82,64,46].map((n,i)=>G.jsx("div",{className:"skeleton",style:{height:56,width:`${n}%`,borderRadius:6}},i))})]})})}function yS(){return G.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:ke.text.muted,gap:16},children:[G.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[G.jsx("path",{d:"M8 10 L48 10 L36 46 L20 46 Z",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinejoin:"round"}),G.jsx("line",{x1:"12",y1:"19",x2:"44",y2:"19",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.5"}),G.jsx("line",{x1:"16",y1:"28",x2:"40",y2:"28",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.4"}),G.jsx("line",{x1:"19",y1:"37",x2:"37",y2:"37",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"})]}),G.jsxs("div",{style:{fontSize:13,textAlign:"center"},children:["No funnel data",G.jsx("div",{style:{fontSize:11,color:ke.text.faint,marginTop:4},children:"Run the sales funnel tool to visualize your pipeline"})]})]})}const Ov=["polygon(0% 0%, 100% 0%, 92% 100%, 8% 100%)","polygon(8% 0%, 92% 0%, 82% 100%, 18% 100%)","polygon(18% 0%, 82% 0%, 74% 100%, 26% 100%)","polygon(26% 0%, 74% 0%, 74% 100%, 26% 100%)"];function S4(n){const i=Math.max(0,parseInt(n.slice(1,3),16)-40),o=Math.max(0,parseInt(n.slice(3,5),16)-40),s=Math.max(0,parseInt(n.slice(5,7),16)-40);return`#${i.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function w4({stage:n,stageIndex:i,currency:o,onClick:s}){const t=n.count===0,a=Ov[Math.min(i,Ov.length-1)],c=t?"linear-gradient(180deg, #333 0%, #222 100%)":`linear-gradient(180deg, ${n.color} 0%, ${S4(n.color)} 100%)`;return G.jsxs("div",{style:{clipPath:a,background:c,padding:"16px 20px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:4,minHeight:56,cursor:s?"pointer":"default",transition:"transform 0.15s, box-shadow 0.15s",opacity:t?.4:1,position:"relative"},onClick:s,onMouseEnter:m=>{!s||t||(m.currentTarget.style.transform="scale(1.02)",m.currentTarget.style.boxShadow=`0 0 20px ${n.color}30`)},onMouseLeave:m=>{m.currentTarget.style.transform="scale(1)",m.currentTarget.style.boxShadow="none"},title:s?`Click to see ${n.label}`:void 0,children:[G.jsx("span",{style:{fontSize:24,fontWeight:700,fontFamily:Bn.mono,color:"#fff",textShadow:"0 2px 4px rgba(0,0,0,0.3)",lineHeight:1},children:f4(n.count,0)}),G.jsx("span",{style:{fontSize:10,fontWeight:700,color:"rgba(255,255,255,0.85)",textTransform:"uppercase",letterSpacing:"0.1em"},children:n.label}),n.value!=null&&n.value>0&&G.jsx("span",{style:{fontSize:11,fontFamily:Bn.mono,color:"rgba(255,255,255,0.6)",marginTop:2},children:m4(n.value,o)})]})}function b4({rate:n,color:i}){return G.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:0,margin:"2px 0"},children:[G.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{opacity:.4},children:G.jsx("path",{d:"M6 1v10M6 11l-3-3M6 11l3-3",stroke:i??ke.text.muted,strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),G.jsxs("span",{style:{display:"inline-flex",alignItems:"center",padding:"2px 10px",fontSize:10,fontWeight:700,fontFamily:Bn.mono,borderRadius:10,background:ke.bg.elevated,color:i??ke.text.secondary,letterSpacing:"0.02em"},children:[n,"%"]})]})}function x4(){const[n,i]=dn.useState(null),[o,s]=dn.useState(!0),[t,a]=dn.useState(!1),[c,m]=dn.useState(null),g=dn.useRef(null),h=dn.useRef(null),y=dn.useRef(!1),S=dn.useRef(0);function z(B){g.current=B,h.current=Nv(B,h.current),i(B)}function j(B){const q=y4(B);if(!q)return!1;try{const Ue=JSON.parse(q);return z(Ue),m(null),s(!1),!0}catch(Ue){return console.error("Parse error:",Ue),m("Failed to parse funnel payload"),s(!1),!1}}async function Z(B={}){const q=Nv(g.current,h.current);if(!h4({request:q,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:y.current,now:Date.now(),lastRefreshStartedAt:S.current,minIntervalMs:_4},B)||!q||!mr.getHostCapabilities()?.serverTools)return!1;y.current=!0,S.current=Date.now(),a(!0);try{const Ue=await mr.callServerTool({name:q.toolName,arguments:q.arguments},{timeout:$4});return Ue.isError?(m("Refresh failed"),!1):j(Ue)?!0:(m("Refresh returned no data"),!1)}catch(Ue){return m(v4(Ue)),!1}finally{y.current=!1,a(!1)}}return dn.useEffect(()=>{mr.connect().catch(()=>{}),mr.ontoolresult=B=>{j(B)},mr.ontoolinputpartial=()=>{g.current||s(!0)}},[]),dn.useEffect(()=>{function B(){Z({ignoreInterval:!0})}function q(){document.visibilityState==="visible"&&Z({ignoreInterval:!0})}return window.addEventListener("focus",B),document.addEventListener("visibilitychange",q),()=>{window.removeEventListener("focus",B),document.removeEventListener("visibilitychange",q)}},[]),G.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},"aria-busy":t,children:[G.jsx(g4,{}),G.jsx("div",{style:{flex:1},children:o?G.jsx(k4,{}):n?G.jsx(I4,{data:n,error:c,refreshing:t,onRefresh:()=>void Z({ignoreInterval:!0})}):G.jsx(yS,{})})]})}function I4({data:n,error:i,refreshing:o,onRefresh:s}){const t=n.currency??"EUR",a=n.stages??[],c=mr.getHostCapabilities()?.serverTools,m={Leads:"Show all leads",Lead:"Show all leads",Opportunities:"Show all open opportunities",Opportunity:"Show all open opportunities",Quotations:"Show all quotations",Quotation:"Show all quotations","Sales Orders":"Show all sales orders","Sales Order":"Show all sales orders",Orders:"Show all sales orders"};function g(z){const j=z._drillDown??m[z.label];j&&mr.sendMessage({role:"user",content:[{type:"text",text:j}]}).catch(()=>{})}if(a.length===0)return G.jsx(yS,{});const h=a[0].count,y=a[a.length-1].count,S=h>0?Math.round(y/h*100):0;return G.jsxs("div",{style:{padding:20,fontFamily:Bn.sans,maxWidth:680,margin:"0 auto"},children:[G.jsxs("div",{style:{marginBottom:20,display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:12},children:[G.jsxs("div",{children:[G.jsx("div",{style:{fontSize:18,fontWeight:700,color:ke.text.primary},children:n.title}),n.subtitle&&G.jsx("div",{style:{fontSize:12,color:ke.text.muted,marginTop:2},children:n.subtitle}),G.jsx("div",{"aria-live":"polite",style:{fontSize:11,color:i?ke.error:ke.text.faint,marginTop:6},children:i??(o?"Refreshing…":"Auto-refresh on focus")})]}),G.jsx("button",{onClick:s,disabled:o,style:Gc.button,onMouseEnter:z=>{o||(z.currentTarget.style.borderColor=ke.accent,z.currentTarget.style.color=ke.accent)},onMouseLeave:z=>{z.currentTarget.style.borderColor=ke.border,z.currentTarget.style.color=ke.text.secondary},children:o?"Refreshing":"Refresh"})]}),G.jsx("div",{style:{display:"flex",flexDirection:"column",gap:0},children:a.map((z,j)=>G.jsxs("div",{children:[G.jsx(w4,{stage:z,stageIndex:j,currency:t,onClick:c?()=>g(z):void 0}),j<a.length-1&&a[j+1].conversionRate!=null&&G.jsx(b4,{rate:a[j+1].conversionRate,color:a[j+1].color})]},z.label))}),G.jsxs("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:12,marginTop:20,padding:"12px 16px",...Gc.card},children:[G.jsx("span",{style:{fontSize:12,color:ke.text.muted},children:"Overall Conversion"}),G.jsxs("span",{style:{fontSize:11,color:ke.text.faint},children:[a[0].label," → ",a[a.length-1].label]}),G.jsxs("span",{style:{fontSize:18,fontWeight:700,fontFamily:Bn.mono,color:S>20?ke.success:S>5?ke.warning:ke.error},children:[S,"%"]})]}),c&&G.jsx("div",{style:{display:"flex",gap:8,justifyContent:"center",marginTop:12},children:a.map(z=>G.jsx("button",{onClick:()=>g(z),style:{...Gc.button,fontSize:11,padding:"4px 12px",borderColor:z.color+"40",color:ke.text.secondary,transition:"all 0.15s"},onMouseEnter:j=>{j.currentTarget.style.borderColor=z.color,j.currentTarget.style.color=z.color},onMouseLeave:j=>{j.currentTarget.style.borderColor=z.color+"40",j.currentTarget.style.color=ke.text.secondary},children:z.label},z.label))})]})}wb.createRoot(document.getElementById("app")).render(G.jsx(x4,{}));</script>
|
|
148
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:I().optional().describe("User's language and region preference in BCP 47 format."),timeZone:I().optional().describe("User's timezone in IANA format."),userAgent:I().optional().describe("Host application identifier."),platform:ce([x("web"),x("desktop"),x("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:E({touch:Se().optional().describe("Whether the device supports touch input."),hover:Se().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:E({top:ae().describe("Top safe area inset in pixels."),right:ae().describe("Right safe area inset in pixels."),bottom:ae().describe("Bottom safe area inset in pixels."),left:ae().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),u4=E({method:x("ui/notifications/host-context-changed"),params:vS.describe("Partial context update containing only changed fields.")});E({method:x("ui/update-model-context"),params:E({content:te(va).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:pe(I(),$e().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});E({method:x("ui/initialize"),params:E({appInfo:Ks.describe("App identification (name and version)."),appCapabilities:o4.describe("Features and capabilities this app provides."),protocolVersion:I().describe("Protocol version this app supports.")})});var c4=E({protocolVersion:I().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Ks.describe("Host application identification and version."),hostCapabilities:i4.describe("Features and capabilities provided by the host."),hostContext:vS.describe("Rich context about the host environment.")}).passthrough(),d4={target:"draft-2020-12"};async function Pv(n,i){let o=n["~standard"];if(o.jsonSchema)return o.jsonSchema[i](d4);if(o.vendor==="zod"){let{z:s}=await Ib(()=>Promise.resolve().then(()=>YI),void 0,import.meta.url);return s.toJSONSchema(n,{io:i})}throw Error(`Schema (vendor: ${o.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function jv(n,i,o=""){let s=await n["~standard"].validate(i);if(s.issues){let t=s.issues.map(a=>{let c=a.path?.map(m=>typeof m=="object"?m.key:m).join(".");return c?`${c}: ${a.message}`:a.message}).join("; ");throw Error(o+t)}return s.value}class Gm extends F1{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(i){if(this._initializedSent)return;let o=`[ext-apps] App.${i}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(o);console.warn(`${o}. This will throw in a future release.`)}eventSchemas={toolinput:X1,toolinputpartial:Y1,toolresult:s4,toolcancelled:e4,hostcontextchanged:u4};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(i){if(!Gm.ONE_SHOT_EVENTS.has(i)||this._everHadListener.has(i)||(this._everHadListener.add(i),!this._initializedSent))return;let o=`[ext-apps] "${String(i)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(o);console.warn(o)}setEventHandler(i,o){o&&this._assertHandlerTiming(i),super.setEventHandler(i,o)}addEventListener(i,o){this._assertHandlerTiming(i),super.addEventListener(i,o)}onEventDispatch(i,o){i==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...o})}constructor(i,o={},s={autoResize:!0}){super(s),this._appInfo=i,this._capabilities=o,this.options=s,s.allowUnsafeEval||Ge({jitless:!0}),this.setRequestHandler(Gs,t=>(console.log("Received ping:",t.params),{})),this.setEventHandler("hostcontextchanged",void 0)}registerCapabilities(i){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._capabilities=M1(this._capabilities,i)}registerTool(i,o,s){if(this._registeredTools[i])throw Error(`Tool ${i} is already registered`);let t=this,a=()=>{t._initializedSent&&t._capabilities.tools?.listChanged&&t.sendToolListChanged()},c=o.inputSchema!==void 0,m={title:o.title,description:o.description,inputSchema:o.inputSchema,outputSchema:o.outputSchema,annotations:o.annotations,_meta:o._meta,enabled:!0,enable(){this.enabled=!0,a()},disable(){this.enabled=!1,a()},update(g){Object.assign(this,g),a()},remove(){t._registeredTools[i]===m&&(delete t._registeredTools[i],a())},handler:async(g,h)=>{if(!m.enabled)throw Error(`Tool ${i} is disabled`);let y;if(c){let S=m.inputSchema,z=S?await jv(S,g??{},`Invalid input for tool ${i}: `):g??{};y=await s(z,h)}else y=await s(h);return m.outputSchema&&!y.isError&&(y.structuredContent=await jv(m.outputSchema,y.structuredContent,`Invalid output for tool ${i}: `)),y}};return this._registeredTools[i]=m,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),a(),m}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(i,o)=>{let s=this._registeredTools[i.name];if(!s)throw Error(`Tool ${i.name} not found`);return s.handler(i.arguments,o)},this.onlisttools=async(i,o)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([s,t])=>t.enabled).map(async([s,t])=>{let a={name:s,title:t.title,description:t.description,inputSchema:t.inputSchema?await Pv(t.inputSchema,"input"):{type:"object",properties:{}}};return t.outputSchema&&(a.outputSchema=await Pv(t.outputSchema,"output")),t.annotations&&(a.annotations=t.annotations),t._meta&&(a._meta=t._meta),a}))}))}async sendToolListChanged(i={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:i})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(i){this.setEventHandler("toolinput",i)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(i){this.setEventHandler("toolinputpartial",i)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(i){this.setEventHandler("toolresult",i)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(i){this.setEventHandler("toolcancelled",i)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(i){this.setEventHandler("hostcontextchanged",i)}_onteardown;get onteardown(){return this._onteardown}set onteardown(i){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,i),this._onteardown=i,this.replaceRequestHandler(r4,(o,s)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(o.params,s)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(i){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,i),this._oncalltool=i,this.replaceRequestHandler(mS,(o,s)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(o.params,s)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(i){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,i),this._onlisttools=i,this.replaceRequestHandler(fS,(o,s)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(o.params,s)})}assertCapabilityForMethod(i){switch(i){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${i})`);break}}assertRequestHandlerCapability(i){switch(i){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${i})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${i} registered`)}}assertNotificationCapability(i){}assertTaskCapability(i){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(i){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(i,o){if(this._assertInitialized("callServerTool"),typeof i=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${i}"). Did you mean: callServerTool({ name: "${i}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:i},Qs,{onprogress:()=>{},resetTimeoutOnProgress:!0,...o})}async readServerResource(i,o){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:i},uS,o)}async listServerResources(i,o){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:i},sS,o)}async createSamplingMessage(i,o){this._assertInitialized("createSamplingMessage");let s=i.tools?hS:gS;return await this.request({method:"sampling/createMessage",params:i},s,o)}sendMessage(i,o){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:i},Q1,o)}sendLog(i){return this.notification({method:"notifications/message",params:i})}updateModelContext(i,o){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:i},Nm,o)}openLink(i,o){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:i},K1,o)}sendOpenLink=this.openLink;downloadFile(i,o){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:i},G1,o)}requestTeardown(i={}){return this.notification({method:"ui/notifications/request-teardown",params:i})}requestDisplayMode(i,o){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:i},a4,o)}sendSizeChanged(i){return this.notification({method:"ui/notifications/size-changed",params:i})}setupSizeChangedNotifications(){let i=!1,o=0,s=0,t=()=>{i||(i=!0,requestAnimationFrame(()=>{i=!1;let c=document.documentElement,m=c.style.height;c.style.height="max-content";let g=Math.ceil(c.getBoundingClientRect().height);c.style.height=m;let h=Math.ceil(window.innerWidth);(h!==o||g!==s)&&(o=h,s=g,this.sendSizeChanged({width:h,height:g}))}))};t();let a=new ResizeObserver(t);return a.observe(document.documentElement),a.observe(document.body),()=>a.disconnect()}async connect(i=new J1(window.parent,window.parent),o){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1,await super.connect(i);try{let s=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:q1}},c4,o);if(s===void 0)throw Error(`Server sent invalid initialize result: ${s}`);this._hostCapabilities=s.hostCapabilities,this._hostInfo=s.hostInfo,this._hostContext=s.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(s){throw this.close(),s}}}function Nt(n){return`var(${n})`}const ke={bg:{surface:Nt("--bg-surface"),elevated:Nt("--bg-elevated")},text:{primary:Nt("--text-primary"),secondary:Nt("--text-secondary"),muted:Nt("--text-muted"),faint:Nt("--text-faint")},accent:Nt("--accent"),border:Nt("--border"),success:Nt("--success"),error:Nt("--error"),warning:Nt("--warning")},Bn={sans:Nt("--font-sans"),mono:Nt("--font-mono")},Gc={card:{background:ke.bg.surface,border:`1px solid ${ke.border}`,borderRadius:"8px",padding:"16px"},button:{background:ke.bg.elevated,border:`1px solid ${ke.border}`,borderRadius:"6px",padding:"6px 14px",fontSize:"12px",color:ke.text.secondary,cursor:"pointer",transition:"all 0.15s",fontFamily:Bn.sans,whiteSpace:"nowrap"}};function f4(n,i=2){return n.toLocaleString("en-US",{minimumFractionDigits:i,maximumFractionDigits:i})}function m4(n,i="USD"){return n.toLocaleString("en-US",{style:"currency",currency:i,minimumFractionDigits:2,maximumFractionDigits:2})}function p4(){return G.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[G.jsx("rect",{x:"1",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.9"}),G.jsx("rect",{x:"9",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),G.jsx("rect",{x:"1",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),G.jsx("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.35"})]})}function g4(){const n={display:"flex",alignItems:"center",gap:7,padding:"0 14px",height:30,background:ke.bg.surface,borderBottom:`1px solid ${ke.border}`,flexShrink:0},i={fontFamily:Bn.sans,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:ke.accent},o={width:3,height:3,borderRadius:"50%",background:ke.text.faint,marginLeft:2,marginRight:2,flexShrink:0},s={fontFamily:Bn.sans,fontSize:10,color:ke.text.muted,letterSpacing:"0.03em"};return G.jsxs("div",{style:n,children:[G.jsx("div",{style:{color:ke.accent},children:G.jsx(p4,{})}),G.jsx("span",{style:i,children:"ERPNext"}),G.jsx("div",{style:o}),G.jsx("span",{style:s,children:"gestion ERP"})]})}function h4(n,i={}){return!n.request||n.visibilityState!=="visible"||n.refreshInFlight?!1:i.ignoreInterval?!0:n.now-n.lastRefreshStartedAt>=n.minIntervalMs}function Nv(n,i){return n?.refreshRequest??i}function v4(n){return n instanceof Error&&/timed? out/i.test(n.message)?"Refresh timed out":"Refresh failed"}function y4(n){return n.structuredContent?JSON.stringify(n.structuredContent):n.content?.find(i=>i.type==="text")?.text??null}const mr=new Gm({name:"Funnel Viewer",version:"1.0.0"}),_4=15e3,$4=1e4;function k4(){return G.jsx("div",{style:{padding:24},children:G.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[[1,2,3,4].map(n=>G.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:n===1?"40%":`${60+n*8}%`}},n)),G.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",alignItems:"center",gap:8},children:[100,82,64,46].map((n,i)=>G.jsx("div",{className:"skeleton",style:{height:56,width:`${n}%`,borderRadius:6}},i))})]})})}function yS(){return G.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:ke.text.muted,gap:16},children:[G.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[G.jsx("path",{d:"M8 10 L48 10 L36 46 L20 46 Z",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinejoin:"round"}),G.jsx("line",{x1:"12",y1:"19",x2:"44",y2:"19",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.5"}),G.jsx("line",{x1:"16",y1:"28",x2:"40",y2:"28",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.4"}),G.jsx("line",{x1:"19",y1:"37",x2:"37",y2:"37",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"})]}),G.jsxs("div",{style:{fontSize:13,textAlign:"center"},children:["No funnel data",G.jsx("div",{style:{fontSize:11,color:ke.text.faint,marginTop:4},children:"Run the sales funnel tool to visualize your pipeline"})]})]})}const Ov=["polygon(0% 0%, 100% 0%, 92% 100%, 8% 100%)","polygon(8% 0%, 92% 0%, 82% 100%, 18% 100%)","polygon(18% 0%, 82% 0%, 74% 100%, 26% 100%)","polygon(26% 0%, 74% 0%, 74% 100%, 26% 100%)"];function S4(n){const i=Math.max(0,parseInt(n.slice(1,3),16)-40),o=Math.max(0,parseInt(n.slice(3,5),16)-40),s=Math.max(0,parseInt(n.slice(5,7),16)-40);return`#${i.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function w4({stage:n,stageIndex:i,currency:o,onClick:s}){const t=n.count===0,a=Ov[Math.min(i,Ov.length-1)],c=t?"linear-gradient(180deg, #333 0%, #222 100%)":`linear-gradient(180deg, ${n.color} 0%, ${S4(n.color)} 100%)`;return G.jsxs("div",{style:{clipPath:a,background:c,padding:"16px 20px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:4,minHeight:56,cursor:s?"pointer":"default",transition:"transform 0.15s, box-shadow 0.15s",opacity:t?.4:1,position:"relative"},onClick:s,onMouseEnter:m=>{!s||t||(m.currentTarget.style.transform="scale(1.02)",m.currentTarget.style.boxShadow=`0 0 20px ${n.color}30`)},onMouseLeave:m=>{m.currentTarget.style.transform="scale(1)",m.currentTarget.style.boxShadow="none"},title:s?`Click to see ${n.label}`:void 0,children:[G.jsx("span",{style:{fontSize:24,fontWeight:700,fontFamily:Bn.mono,color:"#fff",textShadow:"0 2px 4px rgba(0,0,0,0.3)",lineHeight:1},children:f4(n.count,0)}),G.jsx("span",{style:{fontSize:10,fontWeight:700,color:"rgba(255,255,255,0.85)",textTransform:"uppercase",letterSpacing:"0.1em"},children:n.label}),n.value!=null&&n.value>0&&G.jsx("span",{style:{fontSize:11,fontFamily:Bn.mono,color:"rgba(255,255,255,0.6)",marginTop:2},children:m4(n.value,o)})]})}function b4({rate:n,color:i}){return G.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:0,margin:"2px 0"},children:[G.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{opacity:.4},children:G.jsx("path",{d:"M6 1v10M6 11l-3-3M6 11l3-3",stroke:i??ke.text.muted,strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),G.jsxs("span",{style:{display:"inline-flex",alignItems:"center",padding:"2px 10px",fontSize:10,fontWeight:700,fontFamily:Bn.mono,borderRadius:10,background:ke.bg.elevated,color:i??ke.text.secondary,letterSpacing:"0.02em"},children:[n,"%"]})]})}function x4(){const[n,i]=dn.useState(null),[o,s]=dn.useState(!0),[t,a]=dn.useState(!1),[c,m]=dn.useState(null),g=dn.useRef(null),h=dn.useRef(null),y=dn.useRef(!1),S=dn.useRef(0);function z(B){g.current=B,h.current=Nv(B,h.current),i(B)}function j(B){const q=y4(B);if(!q)return!1;try{const Ue=JSON.parse(q);return z(Ue),m(null),s(!1),!0}catch(Ue){return console.error("Parse error:",Ue),m("Failed to parse funnel payload"),s(!1),!1}}async function Z(B={}){const q=Nv(g.current,h.current);if(!h4({request:q,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:y.current,now:Date.now(),lastRefreshStartedAt:S.current,minIntervalMs:_4},B)||!q||!mr.getHostCapabilities()?.serverTools)return!1;y.current=!0,S.current=Date.now(),a(!0);try{const Ue=await mr.callServerTool({name:q.toolName,arguments:q.arguments},{timeout:$4});return Ue.isError?(m("Refresh failed"),!1):j(Ue)?!0:(m("Refresh returned no data"),!1)}catch(Ue){return m(v4(Ue)),!1}finally{y.current=!1,a(!1)}}return dn.useEffect(()=>{mr.ontoolresult=B=>{j(B)},mr.ontoolinputpartial=()=>{g.current||s(!0)},mr.connect().catch(()=>{})},[]),dn.useEffect(()=>{function B(){Z({ignoreInterval:!0})}function q(){document.visibilityState==="visible"&&Z({ignoreInterval:!0})}return window.addEventListener("focus",B),document.addEventListener("visibilitychange",q),()=>{window.removeEventListener("focus",B),document.removeEventListener("visibilitychange",q)}},[]),G.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},"aria-busy":t,children:[G.jsx(g4,{}),G.jsx("div",{style:{flex:1},children:o?G.jsx(k4,{}):n?G.jsx(I4,{data:n,error:c,refreshing:t,onRefresh:()=>void Z({ignoreInterval:!0})}):G.jsx(yS,{})})]})}function I4({data:n,error:i,refreshing:o,onRefresh:s}){const t=n.currency??"EUR",a=n.stages??[],c=mr.getHostCapabilities()?.serverTools,m={Leads:"Show all leads",Lead:"Show all leads",Opportunities:"Show all open opportunities",Opportunity:"Show all open opportunities",Quotations:"Show all quotations",Quotation:"Show all quotations","Sales Orders":"Show all sales orders","Sales Order":"Show all sales orders",Orders:"Show all sales orders"};function g(z){const j=z._drillDown??m[z.label];j&&mr.sendMessage({role:"user",content:[{type:"text",text:j}]}).catch(()=>{})}if(a.length===0)return G.jsx(yS,{});const h=a[0].count,y=a[a.length-1].count,S=h>0?Math.round(y/h*100):0;return G.jsxs("div",{style:{padding:20,fontFamily:Bn.sans,maxWidth:680,margin:"0 auto"},children:[G.jsxs("div",{style:{marginBottom:20,display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:12},children:[G.jsxs("div",{children:[G.jsx("div",{style:{fontSize:18,fontWeight:700,color:ke.text.primary},children:n.title}),n.subtitle&&G.jsx("div",{style:{fontSize:12,color:ke.text.muted,marginTop:2},children:n.subtitle}),G.jsx("div",{"aria-live":"polite",style:{fontSize:11,color:i?ke.error:ke.text.faint,marginTop:6},children:i??(o?"Refreshing…":"Auto-refresh on focus")})]}),G.jsx("button",{onClick:s,disabled:o,style:Gc.button,onMouseEnter:z=>{o||(z.currentTarget.style.borderColor=ke.accent,z.currentTarget.style.color=ke.accent)},onMouseLeave:z=>{z.currentTarget.style.borderColor=ke.border,z.currentTarget.style.color=ke.text.secondary},children:o?"Refreshing":"Refresh"})]}),G.jsx("div",{style:{display:"flex",flexDirection:"column",gap:0},children:a.map((z,j)=>G.jsxs("div",{children:[G.jsx(w4,{stage:z,stageIndex:j,currency:t,onClick:c?()=>g(z):void 0}),j<a.length-1&&a[j+1].conversionRate!=null&&G.jsx(b4,{rate:a[j+1].conversionRate,color:a[j+1].color})]},z.label))}),G.jsxs("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:12,marginTop:20,padding:"12px 16px",...Gc.card},children:[G.jsx("span",{style:{fontSize:12,color:ke.text.muted},children:"Overall Conversion"}),G.jsxs("span",{style:{fontSize:11,color:ke.text.faint},children:[a[0].label," → ",a[a.length-1].label]}),G.jsxs("span",{style:{fontSize:18,fontWeight:700,fontFamily:Bn.mono,color:S>20?ke.success:S>5?ke.warning:ke.error},children:[S,"%"]})]}),c&&G.jsx("div",{style:{display:"flex",gap:8,justifyContent:"center",marginTop:12},children:a.map(z=>G.jsx("button",{onClick:()=>g(z),style:{...Gc.button,fontSize:11,padding:"4px 12px",borderColor:z.color+"40",color:ke.text.secondary,transition:"all 0.15s"},onMouseEnter:j=>{j.currentTarget.style.borderColor=z.color,j.currentTarget.style.color=z.color},onMouseLeave:j=>{j.currentTarget.style.borderColor=z.color+"40",j.currentTarget.style.color=ke.text.secondary},children:z.label},z.label))})]})}wb.createRoot(document.getElementById("app")).render(G.jsx(x4,{}));</script>
|
|
149
149
|
<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>
|
|
150
150
|
</head>
|
|
151
151
|
<body>
|
|
@@ -145,7 +145,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
145
145
|
- omitted: host decides border`)});j({method:x("ui/request-display-mode"),params:j({mode:_o.describe("The display mode being requested.")})});var p4=j({mode:_o.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),g4=fe([x("model"),x("app")]).describe("Tool visibility scope - who can access the tool.");j({resourceUri:I().optional(),visibility:re(g4).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
146
146
|
- "model": Tool visible to and callable by the agent
|
|
147
147
|
- "app": Tool callable by the app from this server only`),csp:_r().optional(),permissions:_r().optional()});j({mimeTypes:re(I()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')});j({method:x("ui/download-file"),params:j({contents:re(fe([_S,$S])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})});j({method:x("ui/message"),params:j({role:x("user").describe('Message role, currently only "user" is supported.'),content:re(ka).describe("Message content blocks (text, image, etc.).")})});j({method:x("ui/notifications/sandbox-resource-ready"),params:j({html:I().describe("HTML content to load into the inner iframe."),sandbox:I().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:tp.optional().describe("CSP configuration from resource metadata."),permissions:np.optional().describe("Sandbox permissions from resource metadata.")})});var h4=j({method:x("ui/notifications/tool-result"),params:nu.describe("Standard MCP tool execution result.")}),IS=j({toolInfo:j({id:ga.optional().describe("JSON-RPC id of the tools/call request."),tool:ep.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:e4.optional().describe("Current color theme preference."),styles:c4.optional().describe("Style configuration for theming the app."),displayMode:_o.optional().describe("How the UI is currently displayed."),availableDisplayModes:re(_o).optional().describe("Display modes the host supports."),containerDimensions:fe([j({height:le().describe("Fixed container height in pixels.")}),j({maxHeight:fe([le(),ai()]).optional().describe("Maximum container height in pixels.")})]).and(fe([j({width:le().describe("Fixed container width in pixels.")}),j({maxWidth:fe([le(),ai()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
148
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:I().optional().describe("User's language and region preference in BCP 47 format."),timeZone:I().optional().describe("User's timezone in IANA format."),userAgent:I().optional().describe("Host application identifier."),platform:fe([x("web"),x("desktop"),x("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:j({touch:be().optional().describe("Whether the device supports touch input."),hover:be().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:j({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(),v4=j({method:x("ui/notifications/host-context-changed"),params:IS.describe("Partial context update containing only changed fields.")});j({method:x("ui/update-model-context"),params:j({content:re(ka).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:ge(I(),Se().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});j({method:x("ui/initialize"),params:j({appInfo:eu.describe("App identification (name and version)."),appCapabilities:m4.describe("Features and capabilities this app provides."),protocolVersion:I().describe("Protocol version this app supports.")})});var y4=j({protocolVersion:I().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:eu.describe("Host application identification and version."),hostCapabilities:f4.describe("Features and capabilities provided by the host."),hostContext:IS.describe("Rich context about the host environment.")}).passthrough(),_4={target:"draft-2020-12"};async function Rv(n,i){let o=n["~standard"];if(o.jsonSchema)return o.jsonSchema[i](_4);if(o.vendor==="zod"){let{z:s}=await Ub(()=>Promise.resolve().then(()=>lz),void 0,import.meta.url);return s.toJSONSchema(n,{io:i})}throw Error(`Schema (vendor: ${o.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function Lv(n,i,o=""){let s=await n["~standard"].validate(i);if(s.issues){let t=s.issues.map(a=>{let c=a.path?.map(m=>typeof m=="object"?m.key:m).join(".");return c?`${c}: ${a.message}`:a.message}).join("; ");throw Error(o+t)}return s.value}class rp extends G1{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(i){if(this._initializedSent)return;let o=`[ext-apps] App.${i}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(o);console.warn(`${o}. This will throw in a future release.`)}eventSchemas={toolinput:a4,toolinputpartial:l4,toolresult:h4,toolcancelled:s4,hostcontextchanged:v4};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(i){if(!rp.ONE_SHOT_EVENTS.has(i)||this._everHadListener.has(i)||(this._everHadListener.add(i),!this._initializedSent))return;let o=`[ext-apps] "${String(i)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(o);console.warn(o)}setEventHandler(i,o){o&&this._assertHandlerTiming(i),super.setEventHandler(i,o)}addEventListener(i,o){this._assertHandlerTiming(i),super.addEventListener(i,o)}onEventDispatch(i,o){i==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...o})}constructor(i,o={},s={autoResize:!0}){super(s),this._appInfo=i,this._capabilities=o,this.options=s,s.allowUnsafeEval||tt({jitless:!0}),this.setRequestHandler(tu,t=>(console.log("Received ping:",t.params),{})),this.setEventHandler("hostcontextchanged",void 0)}registerCapabilities(i){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._capabilities=K1(this._capabilities,i)}registerTool(i,o,s){if(this._registeredTools[i])throw Error(`Tool ${i} is already registered`);let t=this,a=()=>{t._initializedSent&&t._capabilities.tools?.listChanged&&t.sendToolListChanged()},c=o.inputSchema!==void 0,m={title:o.title,description:o.description,inputSchema:o.inputSchema,outputSchema:o.outputSchema,annotations:o.annotations,_meta:o._meta,enabled:!0,enable(){this.enabled=!0,a()},disable(){this.enabled=!1,a()},update(g){Object.assign(this,g),a()},remove(){t._registeredTools[i]===m&&(delete t._registeredTools[i],a())},handler:async(g,h)=>{if(!m.enabled)throw Error(`Tool ${i} is disabled`);let y;if(c){let S=m.inputSchema,T=S?await Lv(S,g??{},`Invalid input for tool ${i}: `):g??{};y=await s(T,h)}else y=await s(h);return m.outputSchema&&!y.isError&&(y.structuredContent=await Lv(m.outputSchema,y.structuredContent,`Invalid output for tool ${i}: `)),y}};return this._registeredTools[i]=m,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),a(),m}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(i,o)=>{let s=this._registeredTools[i.name];if(!s)throw Error(`Tool ${i.name} not found`);return s.handler(i.arguments,o)},this.onlisttools=async(i,o)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([s,t])=>t.enabled).map(async([s,t])=>{let a={name:s,title:t.title,description:t.description,inputSchema:t.inputSchema?await Rv(t.inputSchema,"input"):{type:"object",properties:{}}};return t.outputSchema&&(a.outputSchema=await Rv(t.outputSchema,"output")),t.annotations&&(a.annotations=t.annotations),t._meta&&(a._meta=t._meta),a}))}))}async sendToolListChanged(i={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:i})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(i){this.setEventHandler("toolinput",i)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(i){this.setEventHandler("toolinputpartial",i)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(i){this.setEventHandler("toolresult",i)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(i){this.setEventHandler("toolcancelled",i)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(i){this.setEventHandler("hostcontextchanged",i)}_onteardown;get onteardown(){return this._onteardown}set onteardown(i){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,i),this._onteardown=i,this.replaceRequestHandler(d4,(o,s)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(o.params,s)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(i){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,i),this._oncalltool=i,this.replaceRequestHandler(SS,(o,s)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(o.params,s)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(i){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,i),this._onlisttools=i,this.replaceRequestHandler(kS,(o,s)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(o.params,s)})}assertCapabilityForMethod(i){switch(i){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${i})`);break}}assertRequestHandlerCapability(i){switch(i){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${i})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${i} registered`)}}assertNotificationCapability(i){}assertTaskCapability(i){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(i){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(i,o){if(this._assertInitialized("callServerTool"),typeof i=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${i}"). Did you mean: callServerTool({ name: "${i}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:i},nu,{onprogress:()=>{},resetTimeoutOnProgress:!0,...o})}async readServerResource(i,o){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:i},yS,o)}async listServerResources(i,o){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:i},vS,o)}async createSamplingMessage(i,o){this._assertInitialized("createSamplingMessage");let s=i.tools?xS:bS;return await this.request({method:"sampling/createMessage",params:i},s,o)}sendMessage(i,o){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:i},o4,o)}sendLog(i){return this.notification({method:"notifications/message",params:i})}updateModelContext(i,o){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:i},Zm,o)}openLink(i,o){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:i},r4,o)}sendOpenLink=this.openLink;downloadFile(i,o){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:i},i4,o)}requestTeardown(i={}){return this.notification({method:"ui/notifications/request-teardown",params:i})}requestDisplayMode(i,o){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:i},p4,o)}sendSizeChanged(i){return this.notification({method:"ui/notifications/size-changed",params:i})}setupSizeChangedNotifications(){let i=!1,o=0,s=0,t=()=>{i||(i=!0,requestAnimationFrame(()=>{i=!1;let c=document.documentElement,m=c.style.height;c.style.height="max-content";let g=Math.ceil(c.getBoundingClientRect().height);c.style.height=m;let h=Math.ceil(window.innerWidth);(h!==o||g!==s)&&(o=h,s=g,this.sendSizeChanged({width:h,height:g}))}))};t();let a=new ResizeObserver(t);return a.observe(document.documentElement),a.observe(document.body),()=>a.disconnect()}async connect(i=new Y1(window.parent,window.parent),o){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1,await super.connect(i);try{let s=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:Q1}},y4,o);if(s===void 0)throw Error(`Server sent invalid initialize result: ${s}`);this._hostCapabilities=s.hostCapabilities,this._hostInfo=s.hostInfo,this._hostContext=s.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(s){throw this.close(),s}}}function We(n){return`var(${n})`}const R={bg:{surface:We("--bg-surface"),elevated:We("--bg-elevated"),hover:We("--bg-hover")},text:{primary:We("--text-primary"),secondary:We("--text-secondary"),muted:We("--text-muted"),faint:We("--text-faint")},accent:We("--accent"),accentDim:We("--accent-dim"),border:We("--border"),borderSubtle:We("--border-subtle"),success:We("--success"),successDim:We("--success-dim"),error:We("--error"),errorDim:We("--error-dim"),warning:We("--warning"),warningDim:We("--warning-dim"),info:We("--info"),infoDim:We("--info-dim")},ot={sans:We("--font-sans"),mono:We("--font-mono")},Qt={card:{background:R.bg.surface,border:`1px solid ${R.border}`,borderRadius:"8px",padding:"16px"},badge:(n,i)=>({display:"inline-flex",alignItems:"center",padding:"2px 8px",fontSize:"11px",fontWeight:600,borderRadius:"4px",color:n,background:i,letterSpacing:"0.02em"}),input:{background:R.bg.elevated,border:`1px solid ${R.border}`,borderRadius:"6px",padding:"6px 12px",fontSize:"13px",color:R.text.primary,outline:"none",transition:"border-color 0.15s",width:"100%",fontFamily:ot.sans},button:{background:R.bg.elevated,border:`1px solid ${R.border}`,borderRadius:"6px",padding:"6px 14px",fontSize:"12px",color:R.text.secondary,cursor:"pointer",transition:"all 0.15s",fontFamily:ot.sans,whiteSpace:"nowrap"},buttonActive:{background:R.accentDim,borderColor:R.accent,color:R.accent},tableHeader:{padding:"8px 12px",textAlign:"left",fontSize:"11px",fontWeight:600,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",borderBottom:`1px solid ${R.border}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",transition:"color 0.15s"},tableCell:{padding:"8px 12px",fontSize:"13px",borderBottom:`1px solid ${R.borderSubtle}`,color:R.text.primary},mono:{fontFamily:ot.mono,fontSize:"12px"}};function Qr(n,i="USD"){return n.toLocaleString("en-US",{style:"currency",currency:i,minimumFractionDigits:2,maximumFractionDigits:2})}function $4(){return N.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[N.jsx("rect",{x:"1",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.9"}),N.jsx("rect",{x:"9",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),N.jsx("rect",{x:"1",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),N.jsx("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.35"})]})}function td(){const n={display:"flex",alignItems:"center",gap:7,padding:"0 14px",height:30,background:R.bg.surface,borderBottom:`1px solid ${R.border}`,flexShrink:0},i={fontFamily:ot.sans,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:R.accent},o={width:3,height:3,borderRadius:"50%",background:R.text.faint,marginLeft:2,marginRight:2,flexShrink:0},s={fontFamily:ot.sans,fontSize:10,color:R.text.muted,letterSpacing:"0.03em"};return N.jsxs("div",{style:n,children:[N.jsx("div",{style:{color:R.accent},children:N.jsx($4,{})}),N.jsx("span",{style:i,children:"ERPNext"}),N.jsx("div",{style:o}),N.jsx("span",{style:s,children:"gestion ERP"})]})}function nd(){const n={display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"6px 16px 8px",borderTop:`1px solid ${R.borderSubtle}`,marginTop:8},i={fontFamily:ot.sans,fontSize:10,color:R.text.faint,letterSpacing:"0.04em"};return N.jsx("div",{style:n,children:N.jsx("span",{style:i,children:"Casys AI"})})}const Zv={success:{color:R.success,bg:R.successDim},error:{color:R.error,bg:R.errorDim},info:{color:R.info,bg:R.infoDim},default:{color:R.text.secondary,bg:R.bg.elevated}};function Xr({label:n,variant:i="default",disabled:o,loading:s,confirm:t,onClick:a}){const[c,m]=He.useState(!1),g=He.useRef();He.useEffect(()=>()=>clearTimeout(g.current),[]);const h=Zv[i]??Zv.default;return N.jsx("button",{onClick:()=>{if(t&&!c){m(!0),clearTimeout(g.current),g.current=setTimeout(()=>m(!1),4e3);return}m(!1),a()},disabled:o||s,style:{...Qt.button,background:h.bg,color:h.color,borderColor:h.color,opacity:o||s?.5:1,fontSize:11,padding:"4px 10px"},children:s?"…":c?"Confirm?":n})}function k4(n,i={}){return!n.request||n.visibilityState!=="visible"||n.refreshInFlight?!1:i.ignoreInterval?!0:n.now-n.lastRefreshStartedAt>=n.minIntervalMs}function S4(n,i){return n?.refreshRequest??i}function w4(n){return n instanceof Error&&/timed? out/i.test(n.message)?"Refresh timed out":"Refresh failed"}function po(n){return n.structuredContent?JSON.stringify(n.structuredContent):n.content?.find(i=>i.type==="text")?.text??null}const b4={Paid:{color:R.success,bg:R.successDim},Submitted:{color:R.info,bg:R.infoDim},Draft:{color:R.text.muted,bg:R.bg.elevated},Cancelled:{color:R.error,bg:R.errorDim},Overdue:{color:R.error,bg:R.errorDim},Unpaid:{color:R.warning,bg:R.warningDim},"Partly Paid":{color:R.warning,bg:R.warningDim},Return:{color:R.text.muted,bg:R.bg.elevated}};function x4({status:n}){const i=b4[n]??{color:R.text.secondary,bg:R.bg.elevated};return N.jsx("span",{style:Qt.badge(i.color,i.bg),children:n})}function Rl({label:n,value:i,bold:o}){return N.jsxs("div",{style:{padding:"4px 0"},children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:2},children:n}),N.jsx("div",{style:{fontSize:o?15:13,fontWeight:o?600:500,color:R.text.primary,fontFamily:o?ot.mono:ot.sans},children:i??"—"})]})}const Av=1e4;function I4({app:n,itemCode:i,onClose:o}){const[s,t]=He.useState(null),[a,c]=He.useState(null),[m,g]=He.useState(!0),[h,y]=He.useState(null);return He.useEffect(()=>{let S=!1;return(async()=>{try{const[T,P]=await Promise.all([n.callServerTool({name:"erpnext_item_get",arguments:{name:i}},{timeout:Av}),n.callServerTool({name:"erpnext_stock_balance",arguments:{item_code:i}},{timeout:Av})]);if(S)return;if(!T.isError){const F=po(T);if(F){const X=JSON.parse(F);t(X.data??X)}}if(!P.isError){const F=po(P);if(F){const X=JSON.parse(F);c(X.data??[])}}T.isError&&P.isError&&y("Failed to load item details")}catch(T){S||y(T instanceof Error?T.message:"Failed to load item details")}finally{S||g(!1)}})(),()=>{S=!0}},[i]),m?N.jsx("div",{style:{padding:16,background:R.bg.surface,borderTop:`2px solid ${R.accent}`},children:[1,2].map(S=>N.jsx("div",{className:"skeleton",style:{height:14,width:`${30+S*15}%`,marginBottom:8}},S))}):N.jsxs("div",{style:{padding:16,background:R.bg.surface,borderTop:`2px solid ${R.accent}`},children:[N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[N.jsx("span",{style:{fontSize:14,fontWeight:600,color:R.text.primary,fontFamily:ot.mono},children:i}),N.jsx("button",{onClick:o,style:{...Qt.button,padding:"2px 8px",fontSize:11},children:"✕"})]}),h&&N.jsx("div",{style:{fontSize:11,color:R.error,marginBottom:8},children:h}),s&&N.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:6,marginBottom:10},children:[s.item_name&&N.jsx(Rl,{label:"Name",value:String(s.item_name)}),s.item_group&&N.jsx(Rl,{label:"Group",value:String(s.item_group)}),s.stock_uom&&N.jsx(Rl,{label:"UOM",value:String(s.stock_uom)}),s.standard_rate!=null&&N.jsx(Rl,{label:"Std Rate",value:String(s.standard_rate),bold:!0})]}),a&&a.length>0&&N.jsxs("div",{style:{marginBottom:10},children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6},children:"Stock"}),a.slice(0,5).map((S,T)=>N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",borderBottom:`1px solid ${R.borderSubtle}`},children:[N.jsx("span",{style:{fontSize:12,color:R.text.secondary},children:String(S.warehouse??"—")}),N.jsx("span",{style:{fontSize:12,fontFamily:ot.mono,fontWeight:600,color:Number(S.actual_qty??0)>0?R.success:R.error},children:String(S.actual_qty??0)})]},T))]}),N.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",paddingTop:8,borderTop:`1px solid ${R.border}`},children:[N.jsx(Xr,{label:"Full stock view",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show stock balance for item ${i}`}]})}catch{}}}),N.jsx(Xr,{label:"Item details",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show me the full details of Item ${i}`}]})}catch{}}})]})]})}const vn=new rp({name:"Invoice Viewer",version:"3.0.0"}),z4=15e3,Mv=1e4;function T4(){return N.jsx("div",{style:{padding:24},children:[1,2,3,4,5].map(n=>N.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:`${40+n*10}%`,marginBottom:8}},n))})}function j4(){return N.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:R.text.muted,gap:12,flex:1},children:[N.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[N.jsx("rect",{x:"12",y:"6",width:"32",height:"44",rx:"3",stroke:"currentColor",strokeWidth:"2"}),N.jsx("path",{d:"M20 16h16M20 22h12M20 28h14M20 34h8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",opacity:"0.6"})]}),N.jsx("div",{style:{fontSize:13},children:"No invoice data"})]})}function Fv({type:n,message:i,onDismiss:o}){const s=n==="error";return N.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",marginBottom:12,borderRadius:8,fontSize:12,background:s?R.errorDim:R.successDim,color:s?R.error:R.success,border:`1px solid ${s?R.error+"30":R.success+"30"}`},children:[N.jsx("span",{children:i}),o&&N.jsx("button",{onClick:o,style:{background:"none",border:"none",color:"inherit",cursor:"pointer",fontSize:14,padding:"0 4px"},children:"✕"})]})}function rd({label:n,value:i,bold:o}){return N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",fontSize:o?14:13},children:[N.jsx("span",{style:{color:R.text.secondary},children:n}),N.jsx("span",{style:{fontFamily:ot.mono,fontWeight:o?700:400,color:o?R.accent:R.text.primary},children:i})]})}function E4(){const[n,i]=He.useState(null),[o,s]=He.useState(!0),[t,a]=He.useState(!1),[c,m]=He.useState(null),[g,h]=He.useState(null),[y,S]=He.useState(null),[T,P]=He.useState(null),F=He.useRef(null),X=He.useRef(null),Q=He.useRef(!1),Qe=He.useRef(0);function we(q){F.current=q,i(q)}function pe(q){if(q.isError){const k=po(q);return m(k??"Tool returned an error"),s(!1),!1}const M=po(q);if(!M)return!1;try{const k=JSON.parse(M);return X.current=S4(k,X.current),we(k.data??k),m(null),s(!1),!0}catch{return m("Failed to parse invoice payload"),s(!1),!1}}async function ie(q={}){const M=X.current;if(k4({request:M,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:Q.current,now:Date.now(),lastRefreshStartedAt:Qe.current,minIntervalMs:z4},q)&&!(!M||!vn.getHostCapabilities()?.serverTools)){Q.current=!0,Qe.current=Date.now(),a(!0);try{const k=await vn.callServerTool({name:M.toolName,arguments:M.arguments},{timeout:Mv});k.isError?m("Refresh failed"):pe(k)}catch(k){m(w4(k))}finally{Q.current=!1,a(!1)}}}async function ye(q,M,k,U){if(vn.getHostCapabilities()?.serverTools){h(q),S(null);try{const ue=await vn.callServerTool({name:M,arguments:k},{timeout:Mv});if(ue.isError){const ce=po(ue);S(ce??"Action failed")}else S(U),setTimeout(()=>void ie({ignoreInterval:!0}),1500)}catch{S("Action failed")}finally{h(null)}}}async function Je(q,M){h(q);try{await vn.sendMessage({role:"user",content:[{type:"text",text:M}]})}catch{}h(null)}if(He.useEffect(()=>{vn.connect().catch(()=>{}),vn.ontoolresult=q=>{pe(q)},vn.ontoolinputpartial=()=>{F.current||s(!0)}},[]),He.useEffect(()=>{const q=()=>void ie({ignoreInterval:!0}),M=()=>{document.visibilityState==="visible"&&ie({ignoreInterval:!0})};return window.addEventListener("focus",q),document.addEventListener("visibilitychange",M),()=>{window.removeEventListener("focus",q),document.removeEventListener("visibilitychange",M)}},[]),He.useEffect(()=>{P(null)},[n?.name]),o)return N.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[N.jsx(td,{}),N.jsx(T4,{}),N.jsx(nd,{})]});if(!n)return N.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[N.jsx(td,{}),N.jsx(j4,{}),N.jsx(nd,{})]});const Ce=n.currency??"USD",Ke=!!n.customer,Nt=Ke?"Sales Invoice":"Purchase Invoice",tn=n.customer_name??n.customer??n.supplier_name??n.supplier??"—",dn=n.outstanding_amount??0,wt=dn<=0,at=n.items??[],bt=n.net_total??at.reduce((q,M)=>q+M.amount,0),Ot=n.total_taxes_and_charges??n.grand_total-bt,mt=n.status==="Draft"||n.docstatus===0,Re=n.docstatus===1,H=vn.getHostCapabilities()?.serverTools;return N.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[N.jsx(td,{}),N.jsxs("div",{style:{padding:16,fontFamily:ot.sans,flex:1,maxWidth:720},children:[N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:16,flexWrap:"wrap",gap:8},children:[N.jsxs("div",{children:[N.jsx("div",{style:{fontSize:11,fontWeight:600,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4},children:Nt}),N.jsx("div",{style:{fontSize:20,fontWeight:700,color:R.text.primary,fontFamily:ot.mono},children:n.name}),N.jsxs("div",{style:{display:"flex",gap:8,marginTop:6,alignItems:"center",flexWrap:"wrap"},children:[N.jsx(x4,{status:n.status}),n.company&&N.jsx("span",{style:{fontSize:11,color:R.text.faint},children:n.company})]})]}),N.jsx("button",{onClick:()=>void ie({ignoreInterval:!0}),disabled:t,style:Qt.button,children:t?"…":"Refresh"})]}),c&&N.jsx(Fv,{type:"error",message:c,onDismiss:()=>m(null)}),!c&&y&&N.jsx(Fv,{type:"success",message:y}),N.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16,marginBottom:16,borderBottom:`1px solid ${R.border}`,paddingBottom:16},children:[N.jsxs("div",{children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:4},children:Ke?"Customer":"Supplier"}),N.jsx("div",{style:{fontSize:14,fontWeight:600,color:R.text.primary},children:tn}),n.contact_email&&N.jsx("div",{style:{fontSize:11,color:R.text.secondary},children:n.contact_email})]}),N.jsxs("div",{children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:4},children:"Outstanding"}),N.jsx("div",{style:{fontSize:14,fontWeight:600,color:wt?R.success:R.error,fontFamily:ot.mono},children:Qr(dn,Ce)}),N.jsx("div",{style:{fontSize:11,color:wt?R.success:R.error},children:wt?"Paid":"Unpaid"})]})]}),N.jsxs("div",{style:{display:"flex",gap:24,marginBottom:16,fontSize:12},children:[N.jsxs("span",{children:[N.jsx("span",{style:{color:R.text.muted},children:"Date"}),N.jsx("span",{style:{color:R.text.primary,fontWeight:500},children:n.posting_date})]}),n.due_date&&N.jsxs("span",{children:[N.jsx("span",{style:{color:R.text.muted},children:"Due"}),N.jsx("span",{style:{color:R.text.primary,fontWeight:500},children:n.due_date})]})]}),at.length>0&&N.jsx("div",{style:{border:`1px solid ${R.border}`,borderRadius:12,overflowX:"auto",marginBottom:16},children:N.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[N.jsx("thead",{children:N.jsxs("tr",{children:[N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface},children:"Item"}),N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface,textAlign:"right"},children:"Qty"}),N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface,textAlign:"right"},children:"Rate"}),N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface,textAlign:"right"},children:"Amount"})]})}),N.jsx("tbody",{children:at.map((q,M)=>{const k=T===M;return N.jsx("tr",{children:N.jsxs("td",{colSpan:4,style:{padding:0},children:[N.jsxs("div",{style:{display:"grid",gridTemplateColumns:"35% 15% 25% 25%",cursor:H?"pointer":"default",transition:"background 0.1s",background:k?R.bg.hover:"transparent"},onClick:H?()=>P(k?null:M):void 0,onMouseEnter:U=>{k||(U.currentTarget.style.background=R.bg.hover)},onMouseLeave:U=>{k||(U.currentTarget.style.background="transparent")},children:[N.jsxs("div",{style:Qt.tableCell,children:[N.jsx("div",{style:{fontWeight:500,color:R.text.primary},children:q.item_name??q.item_code}),q.item_name&&N.jsx("div",{style:{fontSize:11,color:R.text.faint,fontFamily:ot.mono},children:q.item_code})]}),N.jsx("div",{style:{...Qt.tableCell,textAlign:"right",fontFamily:ot.mono},children:q.qty}),N.jsx("div",{style:{...Qt.tableCell,textAlign:"right",fontFamily:ot.mono,color:R.text.secondary},children:Qr(q.rate,Ce)}),N.jsx("div",{style:{...Qt.tableCell,textAlign:"right",fontFamily:ot.mono,fontWeight:500},children:Qr(q.amount,Ce)})]}),k&&N.jsx(I4,{app:vn,itemCode:q.item_code,onClose:()=>P(null)})]})},M)})})]})}),N.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:16},children:N.jsxs("div",{style:{minWidth:220,borderTop:`1px solid ${R.border}`,paddingTop:8},children:[N.jsx(rd,{label:"Subtotal",value:Qr(bt,Ce)}),Ot!==0&&N.jsx(rd,{label:"Taxes",value:Qr(Ot,Ce)}),N.jsx(rd,{label:"Grand Total",value:Qr(n.grand_total,Ce),bold:!0})]})}),H&&N.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",padding:"12px 0",borderTop:`1px solid ${R.border}`},children:[mt&&N.jsx(Xr,{label:"Submit",variant:"success",confirm:!0,loading:g==="submit",onClick:()=>ye("submit","erpnext_doc_submit",{doctype:Nt,name:n.name},"Submitted")}),Re&&N.jsx(Xr,{label:"Cancel",variant:"error",confirm:!0,loading:g==="cancel",onClick:()=>ye("cancel","erpnext_doc_cancel",{doctype:Nt,name:n.name},"Cancelled")}),N.jsx(Xr,{label:"Payments",loading:g==="nav_payments",onClick:()=>Je("nav_payments",`Show payment entries for ${Nt} ${n.name}`)}),(n.customer??n.supplier)&&N.jsx(Xr,{label:Ke?"Customer invoices":"Supplier invoices",loading:g==="nav_party",onClick:()=>{const q=n.customer??n.supplier;Je("nav_party",`Show all ${Ke?"sales":"purchase"} invoices for ${Ke?"customer":"supplier"} ${q}`)}})]})]}),N.jsx(nd,{})]})}Pb.createRoot(document.getElementById("app")).render(N.jsx(E4,{}));</script>
|
|
148
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:I().optional().describe("User's language and region preference in BCP 47 format."),timeZone:I().optional().describe("User's timezone in IANA format."),userAgent:I().optional().describe("Host application identifier."),platform:fe([x("web"),x("desktop"),x("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:j({touch:be().optional().describe("Whether the device supports touch input."),hover:be().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:j({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(),v4=j({method:x("ui/notifications/host-context-changed"),params:IS.describe("Partial context update containing only changed fields.")});j({method:x("ui/update-model-context"),params:j({content:re(ka).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:ge(I(),Se().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});j({method:x("ui/initialize"),params:j({appInfo:eu.describe("App identification (name and version)."),appCapabilities:m4.describe("Features and capabilities this app provides."),protocolVersion:I().describe("Protocol version this app supports.")})});var y4=j({protocolVersion:I().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:eu.describe("Host application identification and version."),hostCapabilities:f4.describe("Features and capabilities provided by the host."),hostContext:IS.describe("Rich context about the host environment.")}).passthrough(),_4={target:"draft-2020-12"};async function Rv(n,i){let o=n["~standard"];if(o.jsonSchema)return o.jsonSchema[i](_4);if(o.vendor==="zod"){let{z:s}=await Ub(()=>Promise.resolve().then(()=>lz),void 0,import.meta.url);return s.toJSONSchema(n,{io:i})}throw Error(`Schema (vendor: ${o.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function Lv(n,i,o=""){let s=await n["~standard"].validate(i);if(s.issues){let t=s.issues.map(a=>{let c=a.path?.map(m=>typeof m=="object"?m.key:m).join(".");return c?`${c}: ${a.message}`:a.message}).join("; ");throw Error(o+t)}return s.value}class rp extends G1{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(i){if(this._initializedSent)return;let o=`[ext-apps] App.${i}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(o);console.warn(`${o}. This will throw in a future release.`)}eventSchemas={toolinput:a4,toolinputpartial:l4,toolresult:h4,toolcancelled:s4,hostcontextchanged:v4};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(i){if(!rp.ONE_SHOT_EVENTS.has(i)||this._everHadListener.has(i)||(this._everHadListener.add(i),!this._initializedSent))return;let o=`[ext-apps] "${String(i)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(o);console.warn(o)}setEventHandler(i,o){o&&this._assertHandlerTiming(i),super.setEventHandler(i,o)}addEventListener(i,o){this._assertHandlerTiming(i),super.addEventListener(i,o)}onEventDispatch(i,o){i==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...o})}constructor(i,o={},s={autoResize:!0}){super(s),this._appInfo=i,this._capabilities=o,this.options=s,s.allowUnsafeEval||tt({jitless:!0}),this.setRequestHandler(tu,t=>(console.log("Received ping:",t.params),{})),this.setEventHandler("hostcontextchanged",void 0)}registerCapabilities(i){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._capabilities=K1(this._capabilities,i)}registerTool(i,o,s){if(this._registeredTools[i])throw Error(`Tool ${i} is already registered`);let t=this,a=()=>{t._initializedSent&&t._capabilities.tools?.listChanged&&t.sendToolListChanged()},c=o.inputSchema!==void 0,m={title:o.title,description:o.description,inputSchema:o.inputSchema,outputSchema:o.outputSchema,annotations:o.annotations,_meta:o._meta,enabled:!0,enable(){this.enabled=!0,a()},disable(){this.enabled=!1,a()},update(g){Object.assign(this,g),a()},remove(){t._registeredTools[i]===m&&(delete t._registeredTools[i],a())},handler:async(g,h)=>{if(!m.enabled)throw Error(`Tool ${i} is disabled`);let y;if(c){let S=m.inputSchema,T=S?await Lv(S,g??{},`Invalid input for tool ${i}: `):g??{};y=await s(T,h)}else y=await s(h);return m.outputSchema&&!y.isError&&(y.structuredContent=await Lv(m.outputSchema,y.structuredContent,`Invalid output for tool ${i}: `)),y}};return this._registeredTools[i]=m,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),a(),m}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(i,o)=>{let s=this._registeredTools[i.name];if(!s)throw Error(`Tool ${i.name} not found`);return s.handler(i.arguments,o)},this.onlisttools=async(i,o)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([s,t])=>t.enabled).map(async([s,t])=>{let a={name:s,title:t.title,description:t.description,inputSchema:t.inputSchema?await Rv(t.inputSchema,"input"):{type:"object",properties:{}}};return t.outputSchema&&(a.outputSchema=await Rv(t.outputSchema,"output")),t.annotations&&(a.annotations=t.annotations),t._meta&&(a._meta=t._meta),a}))}))}async sendToolListChanged(i={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:i})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(i){this.setEventHandler("toolinput",i)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(i){this.setEventHandler("toolinputpartial",i)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(i){this.setEventHandler("toolresult",i)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(i){this.setEventHandler("toolcancelled",i)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(i){this.setEventHandler("hostcontextchanged",i)}_onteardown;get onteardown(){return this._onteardown}set onteardown(i){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,i),this._onteardown=i,this.replaceRequestHandler(d4,(o,s)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(o.params,s)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(i){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,i),this._oncalltool=i,this.replaceRequestHandler(SS,(o,s)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(o.params,s)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(i){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,i),this._onlisttools=i,this.replaceRequestHandler(kS,(o,s)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(o.params,s)})}assertCapabilityForMethod(i){switch(i){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${i})`);break}}assertRequestHandlerCapability(i){switch(i){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${i})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${i} registered`)}}assertNotificationCapability(i){}assertTaskCapability(i){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(i){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(i,o){if(this._assertInitialized("callServerTool"),typeof i=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${i}"). Did you mean: callServerTool({ name: "${i}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:i},nu,{onprogress:()=>{},resetTimeoutOnProgress:!0,...o})}async readServerResource(i,o){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:i},yS,o)}async listServerResources(i,o){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:i},vS,o)}async createSamplingMessage(i,o){this._assertInitialized("createSamplingMessage");let s=i.tools?xS:bS;return await this.request({method:"sampling/createMessage",params:i},s,o)}sendMessage(i,o){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:i},o4,o)}sendLog(i){return this.notification({method:"notifications/message",params:i})}updateModelContext(i,o){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:i},Zm,o)}openLink(i,o){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:i},r4,o)}sendOpenLink=this.openLink;downloadFile(i,o){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:i},i4,o)}requestTeardown(i={}){return this.notification({method:"ui/notifications/request-teardown",params:i})}requestDisplayMode(i,o){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:i},p4,o)}sendSizeChanged(i){return this.notification({method:"ui/notifications/size-changed",params:i})}setupSizeChangedNotifications(){let i=!1,o=0,s=0,t=()=>{i||(i=!0,requestAnimationFrame(()=>{i=!1;let c=document.documentElement,m=c.style.height;c.style.height="max-content";let g=Math.ceil(c.getBoundingClientRect().height);c.style.height=m;let h=Math.ceil(window.innerWidth);(h!==o||g!==s)&&(o=h,s=g,this.sendSizeChanged({width:h,height:g}))}))};t();let a=new ResizeObserver(t);return a.observe(document.documentElement),a.observe(document.body),()=>a.disconnect()}async connect(i=new Y1(window.parent,window.parent),o){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1,await super.connect(i);try{let s=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:Q1}},y4,o);if(s===void 0)throw Error(`Server sent invalid initialize result: ${s}`);this._hostCapabilities=s.hostCapabilities,this._hostInfo=s.hostInfo,this._hostContext=s.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(s){throw this.close(),s}}}function We(n){return`var(${n})`}const R={bg:{surface:We("--bg-surface"),elevated:We("--bg-elevated"),hover:We("--bg-hover")},text:{primary:We("--text-primary"),secondary:We("--text-secondary"),muted:We("--text-muted"),faint:We("--text-faint")},accent:We("--accent"),accentDim:We("--accent-dim"),border:We("--border"),borderSubtle:We("--border-subtle"),success:We("--success"),successDim:We("--success-dim"),error:We("--error"),errorDim:We("--error-dim"),warning:We("--warning"),warningDim:We("--warning-dim"),info:We("--info"),infoDim:We("--info-dim")},ot={sans:We("--font-sans"),mono:We("--font-mono")},Qt={card:{background:R.bg.surface,border:`1px solid ${R.border}`,borderRadius:"8px",padding:"16px"},badge:(n,i)=>({display:"inline-flex",alignItems:"center",padding:"2px 8px",fontSize:"11px",fontWeight:600,borderRadius:"4px",color:n,background:i,letterSpacing:"0.02em"}),input:{background:R.bg.elevated,border:`1px solid ${R.border}`,borderRadius:"6px",padding:"6px 12px",fontSize:"13px",color:R.text.primary,outline:"none",transition:"border-color 0.15s",width:"100%",fontFamily:ot.sans},button:{background:R.bg.elevated,border:`1px solid ${R.border}`,borderRadius:"6px",padding:"6px 14px",fontSize:"12px",color:R.text.secondary,cursor:"pointer",transition:"all 0.15s",fontFamily:ot.sans,whiteSpace:"nowrap"},buttonActive:{background:R.accentDim,borderColor:R.accent,color:R.accent},tableHeader:{padding:"8px 12px",textAlign:"left",fontSize:"11px",fontWeight:600,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",borderBottom:`1px solid ${R.border}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",transition:"color 0.15s"},tableCell:{padding:"8px 12px",fontSize:"13px",borderBottom:`1px solid ${R.borderSubtle}`,color:R.text.primary},mono:{fontFamily:ot.mono,fontSize:"12px"}};function Qr(n,i="USD"){return n.toLocaleString("en-US",{style:"currency",currency:i,minimumFractionDigits:2,maximumFractionDigits:2})}function $4(){return N.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[N.jsx("rect",{x:"1",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.9"}),N.jsx("rect",{x:"9",y:"1",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),N.jsx("rect",{x:"1",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.6"}),N.jsx("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.5",fill:"currentColor",opacity:"0.35"})]})}function td(){const n={display:"flex",alignItems:"center",gap:7,padding:"0 14px",height:30,background:R.bg.surface,borderBottom:`1px solid ${R.border}`,flexShrink:0},i={fontFamily:ot.sans,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:R.accent},o={width:3,height:3,borderRadius:"50%",background:R.text.faint,marginLeft:2,marginRight:2,flexShrink:0},s={fontFamily:ot.sans,fontSize:10,color:R.text.muted,letterSpacing:"0.03em"};return N.jsxs("div",{style:n,children:[N.jsx("div",{style:{color:R.accent},children:N.jsx($4,{})}),N.jsx("span",{style:i,children:"ERPNext"}),N.jsx("div",{style:o}),N.jsx("span",{style:s,children:"gestion ERP"})]})}function nd(){const n={display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"6px 16px 8px",borderTop:`1px solid ${R.borderSubtle}`,marginTop:8},i={fontFamily:ot.sans,fontSize:10,color:R.text.faint,letterSpacing:"0.04em"};return N.jsx("div",{style:n,children:N.jsx("span",{style:i,children:"Casys AI"})})}const Zv={success:{color:R.success,bg:R.successDim},error:{color:R.error,bg:R.errorDim},info:{color:R.info,bg:R.infoDim},default:{color:R.text.secondary,bg:R.bg.elevated}};function Xr({label:n,variant:i="default",disabled:o,loading:s,confirm:t,onClick:a}){const[c,m]=He.useState(!1),g=He.useRef();He.useEffect(()=>()=>clearTimeout(g.current),[]);const h=Zv[i]??Zv.default;return N.jsx("button",{onClick:()=>{if(t&&!c){m(!0),clearTimeout(g.current),g.current=setTimeout(()=>m(!1),4e3);return}m(!1),a()},disabled:o||s,style:{...Qt.button,background:h.bg,color:h.color,borderColor:h.color,opacity:o||s?.5:1,fontSize:11,padding:"4px 10px"},children:s?"…":c?"Confirm?":n})}function k4(n,i={}){return!n.request||n.visibilityState!=="visible"||n.refreshInFlight?!1:i.ignoreInterval?!0:n.now-n.lastRefreshStartedAt>=n.minIntervalMs}function S4(n,i){return n?.refreshRequest??i}function w4(n){return n instanceof Error&&/timed? out/i.test(n.message)?"Refresh timed out":"Refresh failed"}function po(n){return n.structuredContent?JSON.stringify(n.structuredContent):n.content?.find(i=>i.type==="text")?.text??null}const b4={Paid:{color:R.success,bg:R.successDim},Submitted:{color:R.info,bg:R.infoDim},Draft:{color:R.text.muted,bg:R.bg.elevated},Cancelled:{color:R.error,bg:R.errorDim},Overdue:{color:R.error,bg:R.errorDim},Unpaid:{color:R.warning,bg:R.warningDim},"Partly Paid":{color:R.warning,bg:R.warningDim},Return:{color:R.text.muted,bg:R.bg.elevated}};function x4({status:n}){const i=b4[n]??{color:R.text.secondary,bg:R.bg.elevated};return N.jsx("span",{style:Qt.badge(i.color,i.bg),children:n})}function Rl({label:n,value:i,bold:o}){return N.jsxs("div",{style:{padding:"4px 0"},children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:2},children:n}),N.jsx("div",{style:{fontSize:o?15:13,fontWeight:o?600:500,color:R.text.primary,fontFamily:o?ot.mono:ot.sans},children:i??"—"})]})}const Av=1e4;function I4({app:n,itemCode:i,onClose:o}){const[s,t]=He.useState(null),[a,c]=He.useState(null),[m,g]=He.useState(!0),[h,y]=He.useState(null);return He.useEffect(()=>{let S=!1;return(async()=>{try{const[T,P]=await Promise.all([n.callServerTool({name:"erpnext_item_get",arguments:{name:i}},{timeout:Av}),n.callServerTool({name:"erpnext_stock_balance",arguments:{item_code:i}},{timeout:Av})]);if(S)return;if(!T.isError){const F=po(T);if(F){const X=JSON.parse(F);t(X.data??X)}}if(!P.isError){const F=po(P);if(F){const X=JSON.parse(F);c(X.data??[])}}T.isError&&P.isError&&y("Failed to load item details")}catch(T){S||y(T instanceof Error?T.message:"Failed to load item details")}finally{S||g(!1)}})(),()=>{S=!0}},[i]),m?N.jsx("div",{style:{padding:16,background:R.bg.surface,borderTop:`2px solid ${R.accent}`},children:[1,2].map(S=>N.jsx("div",{className:"skeleton",style:{height:14,width:`${30+S*15}%`,marginBottom:8}},S))}):N.jsxs("div",{style:{padding:16,background:R.bg.surface,borderTop:`2px solid ${R.accent}`},children:[N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[N.jsx("span",{style:{fontSize:14,fontWeight:600,color:R.text.primary,fontFamily:ot.mono},children:i}),N.jsx("button",{onClick:o,style:{...Qt.button,padding:"2px 8px",fontSize:11},children:"✕"})]}),h&&N.jsx("div",{style:{fontSize:11,color:R.error,marginBottom:8},children:h}),s&&N.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:6,marginBottom:10},children:[s.item_name&&N.jsx(Rl,{label:"Name",value:String(s.item_name)}),s.item_group&&N.jsx(Rl,{label:"Group",value:String(s.item_group)}),s.stock_uom&&N.jsx(Rl,{label:"UOM",value:String(s.stock_uom)}),s.standard_rate!=null&&N.jsx(Rl,{label:"Std Rate",value:String(s.standard_rate),bold:!0})]}),a&&a.length>0&&N.jsxs("div",{style:{marginBottom:10},children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6},children:"Stock"}),a.slice(0,5).map((S,T)=>N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",borderBottom:`1px solid ${R.borderSubtle}`},children:[N.jsx("span",{style:{fontSize:12,color:R.text.secondary},children:String(S.warehouse??"—")}),N.jsx("span",{style:{fontSize:12,fontFamily:ot.mono,fontWeight:600,color:Number(S.actual_qty??0)>0?R.success:R.error},children:String(S.actual_qty??0)})]},T))]}),N.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",paddingTop:8,borderTop:`1px solid ${R.border}`},children:[N.jsx(Xr,{label:"Full stock view",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show stock balance for item ${i}`}]})}catch{}}}),N.jsx(Xr,{label:"Item details",onClick:async()=>{try{await n.sendMessage({role:"user",content:[{type:"text",text:`Show me the full details of Item ${i}`}]})}catch{}}})]})]})}const vn=new rp({name:"Invoice Viewer",version:"3.0.0"}),z4=15e3,Mv=1e4;function T4(){return N.jsx("div",{style:{padding:24},children:[1,2,3,4,5].map(n=>N.jsx("div",{className:"skeleton",style:{height:n===1?32:20,width:`${40+n*10}%`,marginBottom:8}},n))})}function j4(){return N.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 24px",color:R.text.muted,gap:12,flex:1},children:[N.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",fill:"none",style:{opacity:.35},children:[N.jsx("rect",{x:"12",y:"6",width:"32",height:"44",rx:"3",stroke:"currentColor",strokeWidth:"2"}),N.jsx("path",{d:"M20 16h16M20 22h12M20 28h14M20 34h8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",opacity:"0.6"})]}),N.jsx("div",{style:{fontSize:13},children:"No invoice data"})]})}function Fv({type:n,message:i,onDismiss:o}){const s=n==="error";return N.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",marginBottom:12,borderRadius:8,fontSize:12,background:s?R.errorDim:R.successDim,color:s?R.error:R.success,border:`1px solid ${s?R.error+"30":R.success+"30"}`},children:[N.jsx("span",{children:i}),o&&N.jsx("button",{onClick:o,style:{background:"none",border:"none",color:"inherit",cursor:"pointer",fontSize:14,padding:"0 4px"},children:"✕"})]})}function rd({label:n,value:i,bold:o}){return N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",fontSize:o?14:13},children:[N.jsx("span",{style:{color:R.text.secondary},children:n}),N.jsx("span",{style:{fontFamily:ot.mono,fontWeight:o?700:400,color:o?R.accent:R.text.primary},children:i})]})}function E4(){const[n,i]=He.useState(null),[o,s]=He.useState(!0),[t,a]=He.useState(!1),[c,m]=He.useState(null),[g,h]=He.useState(null),[y,S]=He.useState(null),[T,P]=He.useState(null),F=He.useRef(null),X=He.useRef(null),Q=He.useRef(!1),Qe=He.useRef(0);function we(q){F.current=q,i(q)}function pe(q){if(q.isError){const k=po(q);return m(k??"Tool returned an error"),s(!1),!1}const M=po(q);if(!M)return!1;try{const k=JSON.parse(M);return X.current=S4(k,X.current),we(k.data??k),m(null),s(!1),!0}catch{return m("Failed to parse invoice payload"),s(!1),!1}}async function ie(q={}){const M=X.current;if(k4({request:M,visibilityState:typeof document>"u"?"visible":document.visibilityState,refreshInFlight:Q.current,now:Date.now(),lastRefreshStartedAt:Qe.current,minIntervalMs:z4},q)&&!(!M||!vn.getHostCapabilities()?.serverTools)){Q.current=!0,Qe.current=Date.now(),a(!0);try{const k=await vn.callServerTool({name:M.toolName,arguments:M.arguments},{timeout:Mv});k.isError?m("Refresh failed"):pe(k)}catch(k){m(w4(k))}finally{Q.current=!1,a(!1)}}}async function ye(q,M,k,U){if(vn.getHostCapabilities()?.serverTools){h(q),S(null);try{const ue=await vn.callServerTool({name:M,arguments:k},{timeout:Mv});if(ue.isError){const ce=po(ue);S(ce??"Action failed")}else S(U),setTimeout(()=>void ie({ignoreInterval:!0}),1500)}catch{S("Action failed")}finally{h(null)}}}async function Je(q,M){h(q);try{await vn.sendMessage({role:"user",content:[{type:"text",text:M}]})}catch{}h(null)}if(He.useEffect(()=>{vn.ontoolresult=q=>{pe(q)},vn.ontoolinputpartial=()=>{F.current||s(!0)},vn.connect().catch(()=>{})},[]),He.useEffect(()=>{const q=()=>void ie({ignoreInterval:!0}),M=()=>{document.visibilityState==="visible"&&ie({ignoreInterval:!0})};return window.addEventListener("focus",q),document.addEventListener("visibilitychange",M),()=>{window.removeEventListener("focus",q),document.removeEventListener("visibilitychange",M)}},[]),He.useEffect(()=>{P(null)},[n?.name]),o)return N.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[N.jsx(td,{}),N.jsx(T4,{}),N.jsx(nd,{})]});if(!n)return N.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[N.jsx(td,{}),N.jsx(j4,{}),N.jsx(nd,{})]});const Ce=n.currency??"USD",Ke=!!n.customer,Nt=Ke?"Sales Invoice":"Purchase Invoice",tn=n.customer_name??n.customer??n.supplier_name??n.supplier??"—",dn=n.outstanding_amount??0,wt=dn<=0,at=n.items??[],bt=n.net_total??at.reduce((q,M)=>q+M.amount,0),Ot=n.total_taxes_and_charges??n.grand_total-bt,mt=n.status==="Draft"||n.docstatus===0,Re=n.docstatus===1,H=vn.getHostCapabilities()?.serverTools;return N.jsxs("div",{style:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[N.jsx(td,{}),N.jsxs("div",{style:{padding:16,fontFamily:ot.sans,flex:1,maxWidth:720},children:[N.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:16,flexWrap:"wrap",gap:8},children:[N.jsxs("div",{children:[N.jsx("div",{style:{fontSize:11,fontWeight:600,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:4},children:Nt}),N.jsx("div",{style:{fontSize:20,fontWeight:700,color:R.text.primary,fontFamily:ot.mono},children:n.name}),N.jsxs("div",{style:{display:"flex",gap:8,marginTop:6,alignItems:"center",flexWrap:"wrap"},children:[N.jsx(x4,{status:n.status}),n.company&&N.jsx("span",{style:{fontSize:11,color:R.text.faint},children:n.company})]})]}),N.jsx("button",{onClick:()=>void ie({ignoreInterval:!0}),disabled:t,style:Qt.button,children:t?"…":"Refresh"})]}),c&&N.jsx(Fv,{type:"error",message:c,onDismiss:()=>m(null)}),!c&&y&&N.jsx(Fv,{type:"success",message:y}),N.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16,marginBottom:16,borderBottom:`1px solid ${R.border}`,paddingBottom:16},children:[N.jsxs("div",{children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:4},children:Ke?"Customer":"Supplier"}),N.jsx("div",{style:{fontSize:14,fontWeight:600,color:R.text.primary},children:tn}),n.contact_email&&N.jsx("div",{style:{fontSize:11,color:R.text.secondary},children:n.contact_email})]}),N.jsxs("div",{children:[N.jsx("div",{style:{fontSize:10,color:R.text.muted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:4},children:"Outstanding"}),N.jsx("div",{style:{fontSize:14,fontWeight:600,color:wt?R.success:R.error,fontFamily:ot.mono},children:Qr(dn,Ce)}),N.jsx("div",{style:{fontSize:11,color:wt?R.success:R.error},children:wt?"Paid":"Unpaid"})]})]}),N.jsxs("div",{style:{display:"flex",gap:24,marginBottom:16,fontSize:12},children:[N.jsxs("span",{children:[N.jsx("span",{style:{color:R.text.muted},children:"Date"}),N.jsx("span",{style:{color:R.text.primary,fontWeight:500},children:n.posting_date})]}),n.due_date&&N.jsxs("span",{children:[N.jsx("span",{style:{color:R.text.muted},children:"Due"}),N.jsx("span",{style:{color:R.text.primary,fontWeight:500},children:n.due_date})]})]}),at.length>0&&N.jsx("div",{style:{border:`1px solid ${R.border}`,borderRadius:12,overflowX:"auto",marginBottom:16},children:N.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[N.jsx("thead",{children:N.jsxs("tr",{children:[N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface},children:"Item"}),N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface,textAlign:"right"},children:"Qty"}),N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface,textAlign:"right"},children:"Rate"}),N.jsx("th",{style:{...Qt.tableHeader,background:R.bg.surface,textAlign:"right"},children:"Amount"})]})}),N.jsx("tbody",{children:at.map((q,M)=>{const k=T===M;return N.jsx("tr",{children:N.jsxs("td",{colSpan:4,style:{padding:0},children:[N.jsxs("div",{style:{display:"grid",gridTemplateColumns:"35% 15% 25% 25%",cursor:H?"pointer":"default",transition:"background 0.1s",background:k?R.bg.hover:"transparent"},onClick:H?()=>P(k?null:M):void 0,onMouseEnter:U=>{k||(U.currentTarget.style.background=R.bg.hover)},onMouseLeave:U=>{k||(U.currentTarget.style.background="transparent")},children:[N.jsxs("div",{style:Qt.tableCell,children:[N.jsx("div",{style:{fontWeight:500,color:R.text.primary},children:q.item_name??q.item_code}),q.item_name&&N.jsx("div",{style:{fontSize:11,color:R.text.faint,fontFamily:ot.mono},children:q.item_code})]}),N.jsx("div",{style:{...Qt.tableCell,textAlign:"right",fontFamily:ot.mono},children:q.qty}),N.jsx("div",{style:{...Qt.tableCell,textAlign:"right",fontFamily:ot.mono,color:R.text.secondary},children:Qr(q.rate,Ce)}),N.jsx("div",{style:{...Qt.tableCell,textAlign:"right",fontFamily:ot.mono,fontWeight:500},children:Qr(q.amount,Ce)})]}),k&&N.jsx(I4,{app:vn,itemCode:q.item_code,onClose:()=>P(null)})]})},M)})})]})}),N.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:16},children:N.jsxs("div",{style:{minWidth:220,borderTop:`1px solid ${R.border}`,paddingTop:8},children:[N.jsx(rd,{label:"Subtotal",value:Qr(bt,Ce)}),Ot!==0&&N.jsx(rd,{label:"Taxes",value:Qr(Ot,Ce)}),N.jsx(rd,{label:"Grand Total",value:Qr(n.grand_total,Ce),bold:!0})]})}),H&&N.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",padding:"12px 0",borderTop:`1px solid ${R.border}`},children:[mt&&N.jsx(Xr,{label:"Submit",variant:"success",confirm:!0,loading:g==="submit",onClick:()=>ye("submit","erpnext_doc_submit",{doctype:Nt,name:n.name},"Submitted")}),Re&&N.jsx(Xr,{label:"Cancel",variant:"error",confirm:!0,loading:g==="cancel",onClick:()=>ye("cancel","erpnext_doc_cancel",{doctype:Nt,name:n.name},"Cancelled")}),N.jsx(Xr,{label:"Payments",loading:g==="nav_payments",onClick:()=>Je("nav_payments",`Show payment entries for ${Nt} ${n.name}`)}),(n.customer??n.supplier)&&N.jsx(Xr,{label:Ke?"Customer invoices":"Supplier invoices",loading:g==="nav_party",onClick:()=>{const q=n.customer??n.supplier;Je("nav_party",`Show all ${Ke?"sales":"purchase"} invoices for ${Ke?"customer":"supplier"} ${q}`)}})]})]}),N.jsx(nd,{})]})}Pb.createRoot(document.getElementById("app")).render(N.jsx(E4,{}));</script>
|
|
149
149
|
<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>
|
|
150
150
|
</head>
|
|
151
151
|
<body>
|