deepseek-harness-intelligent-ui 0.2.2 → 0.2.4
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/CHANGELOG.md +43 -1
- package/README.md +325 -110
- package/README.zh-CN.md +313 -100
- package/THIRD_PARTY_NOTICES.md +8 -0
- package/client/client.js +17 -17
- package/package.json +15 -7
- package/renderer/renderer.js +500 -0
- package/src/catalog/patch.js +283 -0
- package/src/compat.js +1 -1
- package/src/guidance.js +6 -1
- package/src/plugin.js +6 -2
- package/src/portable/artifacts.js +87 -0
- package/src/tools/patch.js +139 -0
- package/src/tools/render.js +4 -2
package/client/client.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/* deepseek-harness-intelligent-ui 0.2.
|
|
1
|
+
/* deepseek-harness-intelligent-ui 0.2.4 — generated by scripts/build-client.mjs; do not edit. */
|
|
2
2
|
window.__ModuleLoader__.load({ id: "deepseek-harness-intelligent-ui", factory: (require) => {
|
|
3
3
|
var module = { exports: {} }; var exports = module.exports;
|
|
4
|
-
"use strict";var
|
|
5
|
-
`){n++;continue}let i=/^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(e.slice(n));if(i){t.push({t:"num",v:Number(i[0]),at:n}),n+=i[0].length;continue}let a=/^[A-Za-z_][A-Za-z_0-9]*/.exec(e.slice(n));if(a){t.push({t:"id",v:a[0],at:n}),n+=a[0].length;continue}if(e.startsWith("**",n)){t.push({t:"op",v:"^",at:n}),n+=2;continue}if("+-*/%^".includes(r)){t.push({t:"op",v:r,at:n}),n++;continue}if(r==="("||r===")"||r===","){t.push({t:r,v:r,at:n}),n++;continue}if(r==="·"||r==="×"){t.push({t:"op",v:"*",at:n}),n++;continue}throw new SyntaxError(`unexpected character ${JSON.stringify(r)} at ${n}`)}return t}function dt(e,t){if(typeof e!="string"||!e.trim())throw new SyntaxError("empty expression");if(e.length>Ut)throw new SyntaxError(`longer than ${Ut} characters`);let n=new Set(t),r=Kn(e),i=0,a=()=>r[i],o=d=>{throw new SyntaxError(d)},s=d=>{let m=r[i];(!m||m.t!==d)&&o(`expected "${d}" ${m?`at ${m.at}`:"at end"}`),i++};function l(){let d=u();for(;a()?.t==="op"&&(a().v==="+"||a().v==="-");){let m=r[i++].v,v=d,h=u();d=m==="+"?S=>v(S)+h(S):S=>v(S)-h(S)}return d}function u(){let d=p();for(;;){let m=a();if(m?.t==="op"&&(m.v==="*"||m.v==="/"||m.v==="%")){i++;let h=d,S=p();d=m.v==="*"?y=>h(y)*S(y):m.v==="/"?y=>h(y)/S(y):y=>h(y)%S(y);continue}let v=r[i-1];if(m&&(m.t==="id"||m.t==="("||m.t==="num")&&v&&(v.t==="num"||v.t===")")&&!(m.t==="num"&&v.t==="num")){let h=d,S=p();d=y=>h(y)*S(y);continue}return d}}function p(){let d=a();if(d?.t==="op"&&(d.v==="-"||d.v==="+")){i++;let m=p();return d.v==="-"?v=>-m(v):m}return w()}function w(){let d=x();if(a()?.t==="op"&&a().v==="^"){i++;let m=p();return v=>d(v)**m(v)}return d}function x(){let d=r[i++];if(d||o("unexpected end of expression"),d.t==="num"){let m=d.v;return()=>m}if(d.t==="("){let m=l();return s(")"),m}if(d.t==="id"){let m=String(d.v);if(a()?.t==="("){let h=_t(Ie,m);h||o(`unknown function "${m}"; allowed: ${Object.keys(Ie).join(", ")}`),i++;let S=[];if(a()?.t!==")")for(S.push(l());a()?.t===",";)i++,S.push(l());s(")");let[y,N]=h;if(y>=0&&S.length!==y&&o(`${m}() takes ${y} argument(s), got ${S.length}`),y<0&&S.length===0&&o(`${m}() needs at least one argument`),S.length===1){let k=S[0];return E=>N(k(E))}if(S.length===2){let[k,E]=S;return T=>N(k(T),E(T))}return k=>N(...S.map(E=>E(k)))}if(n.has(m))return h=>h[m];let v=_t(Lt,m);if(v!==void 0)return()=>v;o(`unknown variable "${m}"; available: ${[...n,...Object.keys(Lt)].join(", ")}`)}o(`unexpected "${d.v}" at ${d.at}`)}let b=l();return i<r.length&&o(`unexpected "${r[i].v}" at ${r[i].at}`),b}function zt(e,t){try{dt(e,t);return}catch(n){return n instanceof Error?n.message:String(n)}}var Me=["default","muted","info","success","warning","error"],Gn=["text","number","range","select","checkbox","date","textarea"],Xn=["bar","line","area","pie"],W=Object.freeze({components:300,depth:24,tableRows:500,tableColumns:24,chartPoints:500,chartSeries:12,formFields:40,text:2e4,plotFunctions:8,plotParams:8,timelineItems:100}),Ce=Object.freeze({Card:{description:"Bordered container with optional title/subtitle/footer; children stack vertically.",children:!0,props:{title:{type:"string"},subtitle:{type:"string"},footer:{type:"string"}}},Stack:{description:"Lays out children vertically (default) or horizontally.",children:!0,props:{direction:{type:"enum",values:["vertical","horizontal"]},gap:{type:"number",min:0,max:64},wrap:{type:"boolean"},align:{type:"enum",values:["start","center","end","stretch"]}}},Grid:{description:"Responsive grid; `columns` is the column count on wide screens (1-6).",children:!0,props:{columns:{type:"number",required:!0,min:1,max:6}}},Tabs:{description:"Tabbed panels: labels[i] titles children[i].",children:!0,props:{labels:{type:"array",required:!0,items:{type:"string"},max:12}}},Text:{description:"Text with a markdown subset (**bold**, *italic*, `code`, [link](https://...), line breaks).",children:!1,props:{text:{type:"string",required:!0,max:W.text},variant:{type:"enum",values:["body","title","heading","caption"]},tone:{type:"enum",values:Me}}},Code:{description:"Monospaced code block.",children:!1,props:{code:{type:"string",required:!0,max:W.text},language:{type:"string"}}},Alert:{description:"Callout box with a tone.",children:!1,props:{title:{type:"string"},text:{type:"string",required:!0},tone:{type:"enum",values:Me}}},Badge:{description:"Small inline label.",children:!1,props:{text:{type:"string",required:!0},tone:{type:"enum",values:Me}}},Divider:{description:"Horizontal rule.",children:!1,props:{}},Stat:{description:"KPI tile: label, big value, optional delta with trend.",children:!1,props:{label:{type:"string",required:!0},value:{type:"scalar",required:!0},delta:{type:"string"},trend:{type:"enum",values:["up","down","flat"]},hint:{type:"string"}}},Progress:{description:"Progress bar; value out of max (default 100).",children:!1,props:{value:{type:"number",required:!0},max:{type:"number",min:0},label:{type:"string"},tone:{type:"enum",values:Me}}},List:{description:"Bulleted or numbered list of short markdown-subset strings.",children:!1,props:{items:{type:"array",required:!0,items:{type:"string"},max:200},ordered:{type:"boolean"}}},Table:{description:"Data table. rows[i][j] belongs to columns[j]. Click-to-sort when sortable.",children:!1,props:{columns:{type:"array",required:!0,items:{type:"string"},max:W.tableColumns},rows:{type:"array",required:!0,max:W.tableRows,items:{type:"array",items:{type:"scalar"},max:W.tableColumns}},caption:{type:"string"},sortable:{type:"boolean"}}},Chart:{description:"SVG chart. labels are the x categories (pie: slice names); each series has one value per label.",children:!1,props:{kind:{type:"enum",required:!0,values:Xn},labels:{type:"array",required:!0,items:{type:"scalar"},max:W.chartPoints},series:{type:"array",required:!0,max:W.chartSeries,items:{type:"object",props:{name:{type:"string",required:!0},values:{type:"array",required:!0,items:{type:"number"},max:W.chartPoints}}}},title:{type:"string"},unit:{type:"string"},stacked:{type:"boolean"},height:{type:"number",min:120,max:600}}},Button:{description:"Button that, when the user clicks it, sends `prompt` back to you as the user's next message.",children:!1,props:{label:{type:"string",required:!0},prompt:{type:"string",required:!0},variant:{type:"enum",values:["primary","secondary"]}}},Form:{description:"Input form. On submit the values are sent back to you as the user's next message (prefixed by `prompt` when given).",children:!1,props:{title:{type:"string"},submitLabel:{type:"string"},prompt:{type:"string"},fields:{type:"array",required:!0,max:W.formFields,items:{type:"object",props:{name:{type:"string",required:!0},label:{type:"string",required:!0},type:{type:"enum",required:!0,values:Gn},options:{type:"array",items:{type:"string"},max:100},required:{type:"boolean"},placeholder:{type:"string"},default:{type:"scalar"},min:{type:"number"},max:{type:"number"},step:{type:"number",min:0}}}}}},Timeline:{description:"Vertical timeline of events/steps in order.",children:!1,props:{items:{type:"array",required:!0,max:W.timelineItems,items:{type:"object",props:{title:{type:"string",required:!0},time:{type:"string"},text:{type:"string"},tone:{type:"enum",values:Me}}}}}},Plot:{description:"Function plot y = f(x) drawn natively. `params` become sliders the user drags; the curves update instantly in the browser (no message to you). Expressions use x, the param names, pi, e, + - * / ^, and functions like sin, cos, exp, ln, sqrt, abs.",children:!1,props:{functions:{type:"array",required:!0,max:W.plotFunctions,items:{type:"object",props:{expr:{type:"string",required:!0,max:500},label:{type:"string"}}}},xMin:{type:"number"},xMax:{type:"number"},yMin:{type:"number"},yMax:{type:"number"},params:{type:"array",max:W.plotParams,items:{type:"object",props:{name:{type:"string",required:!0},label:{type:"string"},min:{type:"number",required:!0},max:{type:"number",required:!0},step:{type:"number",min:0},value:{type:"number",required:!0}}}},title:{type:"string"},xLabel:{type:"string"},yLabel:{type:"string"},height:{type:"number",min:160,max:600}}},Math:{description:"LaTeX math typeset with KaTeX (block by default). Put related equations in one node (e.g. \\begin{aligned}...\\end{aligned}). In JSON, escape each backslash (\\\\frac).",children:!1,props:{tex:{type:"string",required:!0,max:5e3},display:{type:"boolean"}}},Mermaid:{description:"Diagram from Mermaid source (flowchart, sequenceDiagram, classDiagram, stateDiagram, erDiagram, gantt, timeline, mindmap, pie).",children:!1,props:{code:{type:"string",required:!0,max:W.text}}}}),Dt=Object.freeze(Object.keys(Ce));function he(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ce(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function qt(e,t,n,r){switch(t.type){case"any":return;case"string":if(typeof e!="string"){r.push(`${n}: expected string, got ${ce(e)}`);return}t.max!==void 0&&e.length>t.max&&r.push(`${n}: longer than ${t.max} characters`);return;case"number":if(typeof e!="number"||!Number.isFinite(e)){r.push(`${n}: expected finite number, got ${ce(e)}`);return}t.min!==void 0&&e<t.min&&r.push(`${n}: must be >= ${t.min}`),t.max!==void 0&&e>t.max&&r.push(`${n}: must be <= ${t.max}`);return;case"boolean":typeof e!="boolean"&&r.push(`${n}: expected boolean, got ${ce(e)}`);return;case"scalar":e===null||["string","number","boolean"].includes(typeof e)||r.push(`${n}: expected string, number, boolean or null, got ${ce(e)}`);return;case"enum":t.values.includes(e)||r.push(`${n}: expected one of ${t.values.join(" | ")}, got ${JSON.stringify(e)}`);return;case"array":if(!Array.isArray(e)){r.push(`${n}: expected array, got ${ce(e)}`);return}if(t.max!==void 0&&e.length>t.max){r.push(`${n}: more than ${t.max} items`);return}t.items&&e.forEach((i,a)=>qt(i,t.items,`${n}[${a}]`,r));return;case"object":if(!he(e)){r.push(`${n}: expected object, got ${ce(e)}`);return}Ht(e,t.props||{},n,r);return;default:r.push(`${n}: unknown spec type ${t.type}`)}}function Ht(e,t,n,r){for(let[i,a]of Object.entries(t)){let o=e[i];if(o===void 0){a.required&&r.push(`${n}.${i}: required`);continue}qt(o,a,`${n}.${i}`,r)}for(let i of Object.keys(e))i in t||r.push(`${n}.${i}: unknown prop`)}function Yn(e,t,n,r){if(e==="Chart"&&Array.isArray(t.labels)&&Array.isArray(t.series)&&(t.series.forEach((i,a)=>{he(i)&&Array.isArray(i.values)&&i.values.length!==t.labels.length&&r.push(`${n}.series[${a}].values: has ${i.values.length} values but labels has ${t.labels.length}`)}),t.kind==="pie"&&t.series.length>1&&r.push(`${n}.series: a pie chart takes exactly one series`)),e==="Form"&&Array.isArray(t.fields)){let i=new Set;t.fields.forEach((a,o)=>{he(a)&&(i.has(a.name)&&r.push(`${n}.fields[${o}].name: duplicate field name ${JSON.stringify(a.name)}`),i.add(a.name),a.type==="select"&&(!Array.isArray(a.options)||a.options.length===0)&&r.push(`${n}.fields[${o}].options: a select field needs options`),a.type==="range"&&!(typeof a.min=="number"&&typeof a.max=="number"&&a.min<a.max)&&r.push(`${n}.fields[${o}]: a range field needs numeric min < max`))})}e==="Plot"&&er(t,n,r)}var Zn=/^[A-Za-z_][A-Za-z_0-9]*$/,Qn=new Set(["x","pi","e","tau",...Object.keys(Ie)]);function er(e,t,n){let r=typeof e.xMin=="number"?e.xMin:-10,i=typeof e.xMax=="number"?e.xMax:10;r<i||n.push(`${t}: xMin must be less than xMax`),typeof e.yMin=="number"&&typeof e.yMax=="number"&&!(e.yMin<e.yMax)&&n.push(`${t}: yMin must be less than yMax`);let a=[];Array.isArray(e.params)&&e.params.forEach((o,s)=>{if(!he(o)||typeof o.name!="string")return;let l=`${t}.params[${s}]`;Zn.test(o.name)?Qn.has(o.name)?n.push(`${l}.name: "${o.name}" is reserved`):a.includes(o.name)&&n.push(`${l}.name: duplicate parameter "${o.name}"`):n.push(`${l}.name: must be an identifier like "a" or "omega"`),a.push(o.name),typeof o.min=="number"&&typeof o.max=="number"&&(o.min<o.max?typeof o.value=="number"&&(o.value<o.min||o.value>o.max)&&n.push(`${l}.value: must lie within [min, max]`):n.push(`${l}: min must be less than max`))}),Array.isArray(e.functions)&&e.functions.forEach((o,s)=>{if(!he(o)||typeof o.expr!="string")return;let l=zt(o.expr,["x",...a]);l&&n.push(`${t}.functions[${s}].expr: ${l}`)})}function Bt(e,t,n="props"){let r=Ce[e];if(!r)return[`${n}: unknown component type ${JSON.stringify(e)}; use one of ${Dt.join(", ")}`];let i=t===void 0?{}:t;if(!he(i))return[`${n}: expected object, got ${ce(i)}`];let a=[];return Ht(i,r.props,n,a),Yn(e,i,n,a),a}function B(e){return e==null}function Le(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Vt(e,t){return Object.fromEntries(Object.entries(e).filter(([n,r])=>t(n,r)))}function ee(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}function Jt(e,t,n){if(!t)return{...e};let r={};for(let i of t)(n||e[i]!==void 0)&&(r[i]=e[i]);return r}var Kt=Symbol.for("cosmokit.volatile.write");function ut(e,t=new Set){if(typeof e=="function")throw new TypeError("volatile config cannot contain functions");if(e===null||typeof e!="object")return e;if(t.has(e))throw new TypeError("volatile config cannot contain cycles");t.add(e);try{if(Array.isArray(e))return Object.freeze(e.map(n=>ut(n,t)));if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new TypeError("volatile config objects must be plain objects or arrays");return Object.freeze(Object.fromEntries(Object.entries(e).map(([n,r])=>[n,ut(r,t)])))}finally{t.delete(e)}}function ct(e){let t=ut(e);return Object.freeze({get:()=>t,[Kt]:n=>{t=n}})}function ye(e){return typeof e=="object"&&e!==null&&Kt in e}function re(e,t){return arguments.length===1?n=>re(e,n):e in globalThis&&t instanceof globalThis[e]||Object.prototype.toString.call(t).slice(8,-1)===e}function _e(e){return re("ArrayBuffer",e)||re("SharedArrayBuffer",e)}function tr(e){return _e(e)||ArrayBuffer.isView(e)}var J;(function(e){e.is=_e,e.isSource=tr;function t(o){return ArrayBuffer.isView(o)?o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength):o}e.fromSource=t;function n(o){if(o=t(o),typeof Buffer<"u")return Buffer.from(o).toString("base64");let s="",l=new Uint8Array(o);for(let u=0;u<l.byteLength;u++)s+=String.fromCharCode(l[u]);return btoa(s)}e.toBase64=n;function r(o){return typeof Buffer<"u"?t(Buffer.from(o,"base64")):Uint8Array.from(atob(o),s=>s.charCodeAt(0))}e.fromBase64=r;function i(o){return o=t(o),typeof Buffer<"u"?Buffer.from(o).toString("hex"):Array.from(new Uint8Array(o),s=>s.toString(16).padStart(2,"0")).join("")}e.toHex=i;function a(o){if(typeof Buffer<"u")return t(Buffer.from(o,"hex"));let s=o.length%2===0?o:o.slice(0,o.length-1),l=[];for(let u=0;u<s.length;u+=2)l.push(parseInt(`${s[u]}${s[u+1]}`,16));return Uint8Array.from(l).buffer}e.fromHex=a})(J||(J={}));var ri=J.fromBase64,ii=J.toBase64,oi=J.fromHex,ai=J.toHex;function Fe(e,t=new Map){if(!e||typeof e!="object")return e;if(re("Date",e))return new Date(e.valueOf());if(re("RegExp",e))return new RegExp(e.source,e.flags);if(_e(e))return e.slice(0);if(ArrayBuffer.isView(e))return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);let n=t.get(e);if(n)return n;if(Array.isArray(e)){let i=[];return t.set(e,i),e.forEach((a,o)=>{i[o]=Reflect.apply(Fe,null,[a,t])}),i}let r=Object.create(Object.getPrototypeOf(e));t.set(e,r);for(let i of Reflect.ownKeys(e)){let a={...Reflect.getOwnPropertyDescriptor(e,i)};"value"in a&&(a.value=Reflect.apply(Fe,null,[a.value,t])),Reflect.defineProperty(r,i,a)}return r}function Ue(e,t,n){let r=new Set;function i(a,o){if(a===o)return!0;if(ye(a)||ye(o))return ye(a)&&ye(o);if(!n&&B(a)&&B(o))return!0;if(typeof a!=typeof o||typeof a!="object"||!a||!o||r.has(a))return!1;function s(l,u){return l(a)?l(o)?u(a,o):!1:l(o)?!1:void 0}r.add(a);try{return s(Array.isArray,(l,u)=>{if(l.length!==u.length)return!1;for(let p=0;p<l.length;p++)if(!i(l[p],u[p]))return!1;return!0})??s(re("Date"),(l,u)=>l.valueOf()===u.valueOf())??s(re("URL"),(l,u)=>l.href===u.href)??s(re("RegExp"),(l,u)=>l.source===u.source&&l.flags===u.flags)??s(_e,(l,u)=>{if(l.byteLength!==u.byteLength)return!1;let p=new Uint8Array(l),w=new Uint8Array(u);for(let x=0;x<p.length;x++)if(p[x]!==w[x])return!1;return!0})??((!n||[a,o].every(l=>Object.getPrototypeOf(l)===Object.prototype||Object.getPrototypeOf(l)===null))&&Object.keys({...a,...o}).every(l=>i(a[l],o[l])))}finally{r.delete(a)}}return i(e,t)}var Wt;(function(e){e.millisecond=1,e.second=1e3,e.minute=e.second*60,e.hour=e.minute*60,e.day=e.hour*24,e.week=e.day*7;let t=new Date().getTimezoneOffset();function n(b){t=b}e.setTimezoneOffset=n;function r(){return t}e.getTimezoneOffset=r;function i(b=new Date,d){return typeof b=="number"&&(b=new Date(b)),d===void 0&&(d=t),Math.floor((b.valueOf()/e.minute-d)/1440)}e.getDateNumber=i;function a(b,d){let m=new Date(b*e.day);return d===void 0&&(d=t),new Date(+m+d*e.minute)}e.fromDateNumber=a;let o=/\d+(?:\.\d+)?/.source,s=new RegExp(`^${["w(?:eek(?:s)?)?","d(?:ay(?:s)?)?","h(?:our(?:s)?)?","m(?:in(?:ute)?(?:s)?)?","s(?:ec(?:ond)?(?:s)?)?"].map(b=>`(${o}${b})?`).join("")}$`);function l(b){let d=s.exec(b);return d?(parseFloat(d[1])*e.week||0)+(parseFloat(d[2])*e.day||0)+(parseFloat(d[3])*e.hour||0)+(parseFloat(d[4])*e.minute||0)+(parseFloat(d[5])*e.second||0):0}e.parseTime=l;function u(b){let d=l(b);return d?b=Date.now()+d:/^\d{1,2}(:\d{1,2}){1,2}$/.test(b)?b=`${new Date().toLocaleDateString()}-${b}`:/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(b)&&(b=`${new Date().getFullYear()}-${b}`),b?new Date(b):new Date}e.parseDate=u;function p(b){let d=Math.abs(b);return d>=e.day-e.hour/2?Math.round(b/e.day)+"d":d>=e.hour-e.minute/2?Math.round(b/e.hour)+"h":d>=e.minute-e.second/2?Math.round(b/e.minute)+"m":d>=e.second?Math.round(b/e.second)+"s":b+"ms"}e.format=p;function w(b,d=2){return b.toString().padStart(d,"0")}e.toDigits=w;function x(b,d=new Date){return b.replace("yyyy",d.getFullYear().toString()).replace("yy",d.getFullYear().toString().slice(2)).replace("MM",w(d.getMonth()+1)).replace("dd",w(d.getDate())).replace("hh",w(d.getHours())).replace("mm",w(d.getMinutes())).replace("ss",w(d.getSeconds())).replace("SSS",w(d.getMilliseconds(),3))}e.template=x})(Wt||(Wt={}));var je=Symbol.for("schemastery"),Yt=Symbol.for("ValidationError");globalThis.__schemastery_index__??(globalThis.__schemastery_index__=0);globalThis.__schemastery_refs__=void 0;var j=class extends TypeError{constructor(t,n){let r="$";for(let i of n.path||[])typeof i=="string"?r+="."+i:typeof i=="number"?r+="["+i+"]":typeof i=="symbol"&&(r+=`[Symbol(${i.toString()})]`);r.startsWith(".")&&(r=r.slice(1));super((r==="$"?"":`${r} `)+t);z(this,"options");z(this,"name","ValidationError");this.options=n}static is(t){return!!t?.[Yt]}};Object.defineProperty(j.prototype,Yt,{value:!0});var c=function(e){let t=function(n,r={}){return c.resolve(n,t,r)[0]};if(e.refs){let n=ee(e.refs,i=>new c(i)),r=i=>n[i];for(let i in n){let a=n[i];a.sKey=r(a.sKey),a.inner=r(a.inner),a.list=a.list&&a.list.map(r),a.dict=a.dict&&ee(a.dict,r)}return n[e.uid]}if(Object.assign(t,e),typeof t.callback=="string")try{t.callback=new Function("return "+t.callback)()}catch{}return Object.defineProperty(t,"uid",{value:globalThis.__schemastery_index__++}),Object.setPrototypeOf(t,c.prototype),t.meta||(t.meta={}),t.toString=t.toString.bind(t),t};c.prototype=Object.create(Function.prototype);c.prototype[je]=!0;Object.defineProperty(c.prototype,"~standard",{get(){return{version:1,vendor:"schemastery",validate:e=>{try{return{value:c.resolve(e,this,{})[0]}}catch(t){if(j.is(t))return{issues:[{message:t.message,path:t.options.path}]};throw t}}}}});c.ValidationError=j;c.prototype.toJSON=function(){var n,r;if(globalThis.__schemastery_refs__)return(n=globalThis.__schemastery_refs__)[r=this.uid]??(n[r]=JSON.parse(JSON.stringify({...this}))),this.uid;globalThis.__schemastery_refs__={[this.uid]:{...this}},globalThis.__schemastery_refs__[this.uid]=JSON.parse(JSON.stringify({...this}));let t={uid:this.uid,refs:globalThis.__schemastery_refs__};return globalThis.__schemastery_refs__=void 0,t};c.prototype.set=function(t,n){return this.dict[t]=n,this};c.prototype.push=function(t){return this.list.push(t),this};function nr(e,t){let n=typeof e=="string"?{"":e}:{...e};for(let r in t){let i=t[r];i?.$description||i?.$desc?n[r]=i.$description||i.$desc:typeof i=="string"&&(n[r]=i)}return n}function Oe(e){return e?.$value??e?.$inner}function Gt(e){return Vt(e??{},t=>!t.startsWith("$"))}c.prototype.i18n=function(t){let n=c(this),r=nr(n.meta.description,t);return Object.keys(r).length&&(n.meta.description=r),n.dict&&(n.dict=ee(n.dict,(i,a)=>i.i18n(ee(t,o=>Oe(o)?.[a]??o?.[a])))),n.list&&(n.list=n.list.map((i,a)=>i.i18n(ee(t,(o={})=>Array.isArray(Oe(o))?Oe(o)[a]:Array.isArray(o)?o[a]:Gt(o))))),n.inner&&(n.inner=n.inner.i18n(ee(t,i=>Oe(i)?Oe(i):Gt(i)))),n.sKey&&(n.sKey=n.sKey.i18n(ee(t,i=>i?.$key))),n};c.prototype.extra=function(t,n){let r=c(this);return r.meta={...r.meta,[t]:n},r};for(let e of["required","disabled","collapse","hidden","loose"])Object.assign(c.prototype,{[e](t=!0){let n=c(this);return n.meta={...n.meta,[e]:t},n}});c.prototype.deprecated=function(){var n;let t=c(this);return(n=t.meta).badges||(n.badges=[]),t.meta.badges.push({text:"deprecated",type:"danger"}),t};c.prototype.experimental=function(){var n;let t=c(this);return(n=t.meta).badges||(n.badges=[]),t.meta.badges.push({text:"experimental",type:"warning"}),t};c.prototype.pattern=function(t){let n=c(this),r=Jt(t,["source","flags"]);return n.meta={...n.meta,pattern:r},n};c.prototype.simplify=function(t){if(ye(t)&&(t=t.get()),Ue(t,this.meta.default,this.type==="dict"))return null;if(B(t))return t;if(this.type==="object"||this.type==="dict"){let n={};for(let r in t){let i=(this.type==="object"?this.dict[r]:this.inner)?.simplify(t[r]);(this.type==="dict"||!B(i))&&(n[r]=i)}return Ue(n,this.meta.default,this.type==="dict")?null:n}else if(this.type==="array"||this.type==="tuple"){let n=[];return t.forEach((r,i)=>{let a=this.type==="array"?this.inner:this.list[i],o=a?a.simplify(r):r;n.push(o)}),n}else if(this.type==="intersect"){let n={};for(let r of this.list)Object.assign(n,r.simplify(t));return n}else if(this.type==="union")for(let n of this.list)try{return c.resolve(t,n,{}),n.simplify(t)}catch{}return t};c.prototype.toString=function(t){return Qt[this.type]?.(this,t)??`Schema<${this.type}>`};c.prototype.role=function(e,t){let n=c(this);return n.meta={...n.meta,role:e,extra:t},n};for(let e of["default","link","comment","description","max","min","step"])Object.assign(c.prototype,{[e](t){let n=c(this);return n.meta={...n.meta,[e]:t},n}});c.prototype.volatile=function(){if(this.meta.volatile)throw new TypeError("volatile schema is already wrapped");return this.extra("volatile",!0)};var Zt={},Xt=Symbol("checked-volatile-schema");function be(e,t=[],n=!1,r=new Map){let i=r.get(e)??new Set;if(i.has(n))return;if(i.add(n),r.set(e,i),e.meta?.volatile&&n)throw new j("volatile fields require a fixed object path without an enclosing volatile field",{path:t});let a=n||!!e.meta?.volatile;if(e.dict)for(let[o,s]of Object.entries(e.dict))be(s,[...t,o],a,r);if(e.sKey&&be(e.sKey,[...t,"<key>"],!0,r),e.inner&&(e.type!=="lazy"||e.inner[je])&&be(e.inner,[...t,"*"],!0,r),e.list)for(let o=0;o<e.list.length;o++)be(e.list[o],[...t,String(o)],!0,r)}c.extend=function(t,n){Zt[t]=n};c.resolve=function(t,n,r={},i=!1){if(!n)return[t];if(r[Xt]||(be(n,r.path),r={...r,[Xt]:!0}),n.meta?.volatile){let o=c(n);o.meta={...n.meta,volatile:!1};let[s,l]=c.resolve(t,o,r,i);try{return[ct(s),l]}catch(u){throw new j(u instanceof Error?u.message:String(u),r)}}if(r.ignore?.(t,n))return[t];if(B(t)&&n.type!=="lazy"){if(n.meta.required)throw new j("missing required value",r);let o=n,s=n.meta.default;for(;o?.type==="intersect"&&B(s);)o=o.list[0],s=o?.meta.default;if(B(s))return[t];t=Fe(s)}let a=Zt[n.type];if(!a)throw new j(`unsupported type "${n.type}"`,r);try{return a(t,n,r,i)}catch(o){if(!n.meta.loose)throw o;return[n.meta.default]}};c.from=function(t){if(B(t))return c.any();if(["string","number","boolean"].includes(typeof t))return c.const(t).required();if(t[je])return t;if(typeof t=="function")switch(t){case String:return c.string().required();case Number:return c.number().required();case Boolean:return c.boolean().required();case Function:return c.function().required();default:return c.is(t).required()}else throw new TypeError(`cannot infer schema from ${t}`)};c.lazy=function(t){let n=()=>(r.inner[je]||(r.inner=r.builder(),r.inner.meta={...r.meta,...r.inner.meta}),r.inner.toJSON()),r=new c({type:"lazy",builder:t,inner:{toJSON:n}});return r};c.natural=function(){return c.number().step(1).min(0)};c.percent=function(){return c.number().step(.01).min(0).max(1).role("slider")};c.date=function(){return c.union([c.is(Date),c.transform(c.string().role("datetime"),(t,n)=>{let r=new Date(t);if(isNaN(+r))throw new j(`invalid date "${t}"`,n);return r},!0)])};c.regExp=function(t=""){return c.union([c.is(RegExp),c.transform(c.string().role("regexp",{flag:t}),(n,r)=>{try{return new RegExp(n,t)}catch(i){throw new j(i.message,r)}},!0)])};c.arrayBuffer=function(t){return c.union([c.is(ArrayBuffer),c.is(SharedArrayBuffer),c.transform(c.any(),(n,r)=>{if(J.isSource(n))return J.fromSource(n);throw new j(`expected ArrayBufferSource but got ${n}`,r)},!0),...t?[c.transform(c.string(),(n,r)=>{try{return t==="base64"?J.fromBase64(n):J.fromHex(n)}catch(i){throw new j(i.message,r)}},!0)]:[]])};c.extend("lazy",(e,t,n,r)=>(t.inner[je]||(t.inner=t.builder(),t.inner.meta={...t.meta,...t.inner.meta},be(t.inner,n.path,!0)),c.resolve(e,t.inner,n,r)));c.extend("any",e=>[e]);c.extend("never",(e,t,n)=>{throw new j(`expected nullable but got ${e}`,n)});c.extend("const",(e,{value:t},n)=>{if(Ue(e,t))return[t];throw new j(`expected ${t} but got ${e}`,n)});function pt(e,t,n,r,i=!1){let{max:a=1/0,min:o=-1/0}=t;if(e>a)throw new j(`expected ${n} <= ${a} but got ${e}`,r);if(e<o&&!i)throw new j(`expected ${n} >= ${o} but got ${e}`,r)}c.extend("string",(e,{meta:t},n)=>{if(typeof e!="string")throw new j(`expected string but got ${e}`,n);if(t.pattern){let r=new RegExp(t.pattern.source,t.pattern.flags);if(!r.test(e))throw new j(`expect string to match regexp ${r}`,n)}return pt(e.length,t,"string length",n),[e]});function ft(e,t){let n=e.toString();if(n.includes("e"))return e*Math.pow(10,t);let r=n.indexOf(".");if(r===-1)return e*Math.pow(10,t);let i=n.slice(r+1),a=n.slice(0,r);return i.length<=t?+(a+i.padEnd(t,"0")):+(a+i.slice(0,t)+"."+i.slice(t))}function rr(e,t,n){if(n=Math.abs(n),!/^\d+\.\d+$/.test(n.toString()))return(e-t)%n===0;let r=n.toString().indexOf("."),i=n.toString().slice(r+1).length;return Math.abs(ft(e,i)-ft(t,i))%ft(n,i)===0}c.extend("number",(e,{meta:t},n)=>{if(typeof e!="number")throw new j(`expected number but got ${e}`,n);pt(e,t,"number",n);let{step:r}=t;if(r&&!rr(e,t.min??0,r))throw new j(`expected number multiple of ${r} but got ${e}`,n);return[e]});c.extend("boolean",(e,t,n)=>{if(typeof e=="boolean")return[e];throw new j(`expected boolean but got ${e}`,n)});c.extend("bitset",(e,{bits:t,meta:n},r)=>{let i=0,a=[];if(typeof e=="number"){i=e;for(let o in t)e&t[o]&&a.push(o)}else if(Array.isArray(e)){a=e;for(let o of a){if(typeof o!="string")throw new j(`expected string but got ${o}`,r);o in t&&(i|=t[o])}}else throw new j(`expected number or array but got ${e}`,r);return i===n.default?[i]:[i,a]});c.extend("function",(e,t,n)=>{if(typeof e=="function")return[e];throw new j(`expected function but got ${e}`,n)});c.extend("is",(e,{constructor:t},n)=>{if(typeof t=="function"){if(e instanceof t)return[e];throw new j(`expected ${t.name} but got ${e}`,n)}else{if(B(e))throw new j(`expected ${t} but got ${e}`,n);let r=Object.getPrototypeOf(e);for(;r;){if(r.constructor?.name===t)return[e];r=Object.getPrototypeOf(r)}throw new j(`expected ${t} but got ${e}`,n)}});function ze(e,t,n,r){try{let[i,a]=c.resolve(e[t],n,{...r,path:[...r.path||[],t]});return a!==void 0&&(e[t]=a),i}catch(i){if(!r?.autofix)throw i;return delete e[t],n.meta.volatile?ct(n.meta.default):n.meta.default}}c.extend("array",(e,{inner:t,meta:n},r)=>{if(!Array.isArray(e))throw new j(`expected array but got ${e}`,r);return pt(e.length,n,"array length",r,!B(t.meta.default)),[e.map((i,a)=>ze(e,a,t,r))]});c.extend("dict",(e,{inner:t,sKey:n},r,i)=>{if(!Le(e))throw new j(`expected object but got ${e}`,r);let a={};for(let o in e){let s;try{s=c.resolve(o,n,r)[0]}catch(l){if(i)continue;throw l}a[s]=ze(e,o,t,r),e[s]=e[o],o!==s&&delete e[o]}return[a]});c.extend("tuple",(e,{list:t},n,r)=>{if(!Array.isArray(e))throw new j(`expected array but got ${e}`,n);let i=t.map((a,o)=>ze(e,o,a,n));return r?[i]:(i.push(...e.slice(t.length)),[i])});function mt(e,t){for(let n in t)n in e||(e[n]=t[n])}c.extend("object",(e,{dict:t},n,r)=>{if(!Le(e))throw new j(`expected object but got ${e}`,n);let i={};for(let a in t){let o=ze(e,a,t[a],n);(!B(o)||a in e)&&(i[a]=o)}return r||mt(i,e),[i]});c.extend("union",(e,{list:t,toString:n},r,i)=>{let a=[];for(let o of t)try{return c.resolve(e,o,r,i)}catch(s){a.push(s)}throw new j(`expected ${n()} but got ${JSON.stringify(e)}`,r)});c.extend("intersect",(e,{list:t,toString:n},r,i)=>{if(!t.length)return[e];let a;for(let o of t){let s=c.resolve(e,o,r,!0)[0];if(!B(s))if(B(a))a=s;else{if(typeof a!=typeof s)throw new j(`expected ${n()} but got ${JSON.stringify(e)}`,r);if(typeof s=="object")mt(a??(a={}),s);else if(a!==s)throw new j(`expected ${n()} but got ${JSON.stringify(e)}`,r)}}return!i&&Le(e)&&mt(a,e),[a]});c.extend("transform",(e,{inner:t,callback:n,preserve:r},i)=>{let[a,o=e]=c.resolve(e,t,i,!0);return r?[n(a)]:[n(a),n(o)]});var Qt={};function D(e,t,n){Qt[e]=n,Object.assign(c,{[e](...r){let i=new c({type:e});return t.forEach((a,o)=>{switch(a){case"sKey":i.sKey=r[o]??c.string();break;case"inner":i.inner=c.from(r[o]);break;case"list":i.list=r[o].map(c.from);break;case"dict":i.dict=ee(r[o],c.from);break;case"bits":i.bits={};for(let s in r[o])typeof r[o][s]=="number"&&(i.bits[s]=r[o][s]);break;case"callback":{let s=i.callback=r[o];s.toJSON||(s.toJSON=()=>s.toString());break}case"constructor":{let s=i.constructor=r[o];typeof s=="function"&&(s.toJSON||(s.toJSON=()=>s.name));break}default:i[a]=r[o]}}),e==="object"||e==="dict"?i.meta.default={}:e==="array"||e==="tuple"?i.meta.default=[]:e==="bitset"&&(i.meta.default=0),i}})}D("is",["constructor"],({constructor:e})=>typeof e=="function"?e.name:e);D("any",[],()=>"any");D("never",[],()=>"never");D("const",["value"],({value:e})=>typeof e=="string"?JSON.stringify(e):e);D("string",[],()=>"string");D("number",[],()=>"number");D("boolean",[],()=>"boolean");D("bitset",["bits"],()=>"bitset");D("function",[],()=>"function");D("array",["inner"],({inner:e})=>`${e.toString(!0)}[]`);D("dict",["inner","sKey"],({inner:e,sKey:t})=>`{ [key: ${t.toString()}]: ${e.toString()} }`);D("tuple",["list"],({list:e})=>`[${e.map(t=>t.toString()).join(", ")}]`);D("object",["dict"],({dict:e})=>Object.keys(e).length===0?"{}":`{ ${Object.entries(e).map(([t,n])=>`${t}${n.meta.required?"":"?"}: ${n.toString()}`).join(", ")} }`);D("union",["list"],({list:e},t)=>{let n=e.map(({toString:r})=>r()).join(" | ");return t?`(${n})`:n});D("intersect",["list"],({list:e})=>`${e.map(t=>t.toString(!0)).join(" & ")}`);D("transform",["inner","callback","preserve"],({inner:e},t)=>e.toString(t));var ie=Object.freeze({enableCatalog:!0,enableWidget:!0,injectGuidance:!0,cdnAllowlist:["https://esm.sh","https://cdn.jsdelivr.net","https://unpkg.com"],allowNetwork:!1,maxWidgetHeight:2400,maxWidgetBytes:4e5,sendPromptMaxChars:4e3,openLinkAllowedOrigins:[]}),mi=c.object({enableCatalog:c.boolean().default(ie.enableCatalog).description("Register `ui_render` (declarative cards, tables, charts, forms)."),enableWidget:c.boolean().default(ie.enableWidget).description("Register `ui_render_widget` (sandboxed streaming HTML/CSS/JS widgets)."),injectGuidance:c.boolean().default(ie.injectGuidance).description("Add a system-prompt section telling the model when and how to answer with UI."),cdnAllowlist:c.array(c.string()).default([...ie.cdnAllowlist]).description("Origins widgets may load scripts, styles, fonts and images from (CSP)."),allowNetwork:c.boolean().default(ie.allowNetwork).description("Allow widgets to fetch()/WebSocket to the CDN allowlist (CSP connect-src). Off: no network calls."),maxWidgetHeight:c.natural().min(200).max(8e3).default(ie.maxWidgetHeight).description("Maximum widget frame height in pixels."),maxWidgetBytes:c.natural().min(1e4).default(ie.maxWidgetBytes).description("Reject widgets whose html+css+js exceed this many characters."),sendPromptMaxChars:c.natural().min(100).max(2e4).default(ie.sendPromptMaxChars).description("Longest message a widget, button or form may send back to the conversation."),openLinkAllowedOrigins:c.array(c.string()).default([]).description("If non-empty, widgets may only open https links on these origins.")});var De="ui_render";var fe="ui_render_widget";var Ne=require("react");var V=class extends Error{constructor(n,r){super(r);z(this,"code",n)}},xe=class{constructor(t){z(this,"opts",t);z(this,"armedAt");z(this,"lastSend",-1/0);z(this,"now");z(this,"minInterval");this.now=t.now??(()=>Date.now()),this.armedAt=this.now()+(t.armDelayMs??1e3),this.minInterval=t.minIntervalMs??2e3}admitPrompt(t){let n=typeof t=="string"?t.trim():"";if(!n)throw new V("empty","sendPrompt needs non-empty text");if(n.length>this.opts.policy.sendPromptMaxChars)throw new V("too-long",`sendPrompt text exceeds ${this.opts.policy.sendPromptMaxChars} characters`);let r=this.now();if(r<this.armedAt)throw new V("not-armed","sendPrompt is only allowed in response to a user action, not on load");if(r-this.lastSend<this.minInterval)throw new V("rate-limited","sendPrompt called too often");return this.lastSend=r,n}admitLink(t){let n;try{n=new URL(String(t))}catch{throw new V("bad-url","openLink needs an absolute https URL")}if(n.protocol!=="https:")throw new V("bad-url","openLink only opens https URLs");let r=this.opts.policy.openLinkOrigins;if(r.length>0&&!r.some(i=>{try{return new URL(i).origin===n.origin}catch{return!1}}))throw new V("origin",`openLink: ${n.origin} is not an allowed origin`);return n.href}};function en(e,t,n){return`${t?.trim()||(e?`Form "${e}" submitted:`:"Form submitted:")}
|
|
6
|
-
${JSON.stringify(n,null,2)}`}function
|
|
7
|
-
`,"\r"]);function
|
|
8
|
-
`,r:"\r",t:" "}[i]??i,n+=1}return t}function
|
|
9
|
-
`).trim()}function
|
|
10
|
-
`);return(0,K.jsx)(K.Fragment,{children:t.map((n,r)=>(0,K.jsxs)(mn.Fragment,{children:[r>0&&(0,K.jsx)("br",{}),xr(n,String(r))]},r))})}var kn=require("react");var pn='var Idiomorph=function(){"use strict";const e=()=>{};const n={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:e=>e.getAttribute("im-preserve")==="true",shouldReAppend:e=>e.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},restoreFocus:true};function t(e,t,n={}){const o=u(e);const r=f(t);const i=d(o,r,n);return c(i,o,r,e=>{const t=a(e,()=>{if(e.morphStyle==="innerHTML"){s(e,o,r);return Array.from(o.childNodes)}else{return l(e,o,r)}});e.pantry.remove();return t})}function l(e,t,n){const o=f(t);s(e,o,n,t,t.nextSibling);return Array.from(o.childNodes)}function a(e,t){if(!e.config.restoreFocus)return t();let n=e.doc.activeElement;if(!(g.inputElement(n)||g.textAreaElement(n))){return t()}const{id:o,selectionStart:r,selectionEnd:i}=n;const l=t();if(o&&o!==e.doc.activeElement?.getAttribute("id")){n=e.target.querySelector(`[id="${CSS.escape(o)}"]`);n?.focus()}if(n&&!n.selectionEnd&&i){try{n.setSelectionRange(r,i)}catch{}}return l}const s=function(){function e(e,t,n,o=null,r=null){if(g.templateElement(t)&&g.templateElement(n)){t=t.content;n=n.content}o||=t.firstChild;for(const i of n.childNodes){if(o&&o!=r){const a=f(e,i,o,r);if(a){if(a!==o){m(e,o,a)}b(a,i,e);o=a.nextSibling;continue}}if(g.element(i)){const s=i.getAttribute("id");if(e.persistentIds.has(s)){const c=p(t,s,o,e);b(c,i,e);o=c.nextSibling;continue}}const l=u(t,i,o,e);if(l){o=l.nextSibling}}while(o&&o!=r){const d=o;o=o.nextSibling;h(e,d)}}function u(e,t,n,o){if(o.callbacks.beforeNodeAdded(t)===false)return null;if(o.idMap.has(t)){const r=o.doc.createElementNS(t.namespaceURI,t.localName);e.insertBefore(r,n);b(r,t,o);o.callbacks.afterNodeAdded(r);return r}else{const i=o.doc.importNode(t,true);e.insertBefore(i,n);o.callbacks.afterNodeAdded(i);return i}}const f=function(){function e(e,t,n,o){let r=null;let i=t.nextSibling;let l=0;let a=n;while(a&&a!=o){if(c(a,t)){if(s(e,a,t)){return a}if(r===null){if(!e.idMap.has(a)){r=a}}}if(r===null&&i&&c(a,i)){l++;i=i.nextSibling;if(l>=2){r=undefined}}if(e.activeElementAndParents.includes(a))break;a=a.nextSibling}return r||null}function s(e,t,n){let o=e.idMap.get(t);let r=e.idMap.get(n);if(!r||!o)return false;for(const i of o){if(r.has(i)){return true}}return false}function c(e,t){const n=e;const o=t;return n.nodeType===o.nodeType&&n.tagName===o.tagName&&(!n.getAttribute?.("id")||n.getAttribute?.("id")===o.getAttribute?.("id"))}return e}();function h(e,t){if(t===e.pantry)return;if(e.idMap.has(t)){a(e.pantry,t,null)}else{if(e.callbacks.beforeNodeRemoved(t)===false)return;t.parentNode?.removeChild(t);e.callbacks.afterNodeRemoved(t)}}function m(t,e,n){let o=e;while(o&&o!==n){let e=o;o=o.nextSibling;h(t,e)}return o}function p(e,t,n,o){const r=`[id="${CSS.escape(t)}"]`;const i=o.target.getAttribute?.("id")===t&&o.target||o.target.querySelector(r)||o.pantry.querySelector(r);l(i,o);a(e,i,n);return i}function l(t,n){const o=t.getAttribute("id");while(t=t.parentNode){let e=n.idMap.get(t);if(e){e.delete(o);if(!e.size){n.idMap.delete(t)}}}}function a(t,n,o){if(t.moveBefore){try{t.moveBefore(n,o)}catch(e){t.insertBefore(n,o)}}else{t.insertBefore(n,o)}}return e}();const b=function(){function e(e,t,n){if(n.ignoreActive&&e===n.doc.activeElement){return null}if(n.callbacks.beforeNodeMorphed(e,t)===false){return e}if(g.headElement(e)&&n.head.style==="none"){}else if(g.headElement(e)&&n.head.style!=="morph"){h(e,t,n)}else{o(e,t,n);if(!f(e,n)){s(n,e,t)}}n.callbacks.afterNodeMorphed(e,t);return e}function o(e,t,n){let o=t.nodeType;if(o===1){const r=e;const i=t;const l=r.attributes;const a=i.attributes;for(const s of a){if(r.getAttribute(s.name)===s.value){continue}if(u(s.name,r,"update",n)){continue}r.setAttributeNode(s.cloneNode())}for(let e=l.length-1;0<=e;e--){const c=l[e];if(!c)continue;if(!i.hasAttribute(c.name)){if(u(c.name,r,"remove",n)){continue}r.removeAttribute(c.name)}}if(!f(r,n)){d(r,i,n)}}if(o===8||o===3){if(e.nodeValue!==t.nodeValue){e.nodeValue=t.nodeValue}}}function d(n,o,r){if(g.inputElement(n)&&g.inputElement(o)&&o.type!=="file"){let e=o.value;let t=n.value;i(n,o,"checked",r);i(n,o,"disabled",r);if(!o.hasAttribute("value")){if(!u("value",n,"remove",r)){n.value="";n.removeAttribute("value")}}else if(t!==e){if(!u("value",n,"update",r)){n.setAttribute("value",e);n.value=e}}}else if(g.optionElement(n)&&g.optionElement(o)){i(n,o,"selected",r)}else if(g.textAreaElement(n)&&g.textAreaElement(o)){let e=o.value;let t=n.value;if(u("value",n,"update",r)){return}if(e!==t){n.value=e}if(n.firstChild&&n.firstChild.nodeValue!==e){n.firstChild.nodeValue=e}}}function i(e,t,n,o){const r=t[n],i=e[n];if(r!==i){const l=u(n,e,"update",o);if(!l){e[n]=t[n]}if(r){if(!l){e.setAttribute(n,"")}}else{if(!u(n,e,"remove",o)){e.removeAttribute(n)}}}}function u(e,t,n,o){if(e==="value"&&o.ignoreActiveValue&&t===o.doc.activeElement){return true}return o.callbacks.beforeAttributeUpdated(e,t,n)===false}function f(e,t){return!!t.ignoreActiveValue&&e===t.doc.activeElement&&e!==t.doc.body}return e}();function c(t,e,n,o){if(t.head.block&&t.head.style!=="none"){const r=e.querySelector("head");const i=n.querySelector("head");if(r&&i){const l=h(r,i,t);return Promise.all(l).then(()=>{const e=Object.assign(t,{head:{block:false,style:"none"}});return o(e)})}}return o(t)}function h(e,t,o){let r=[];let i=[];let l=[];let a=[];let s=new Map;for(const n of t.children){s.set(n.outerHTML,n)}for(const d of e.children){let e=s.has(d.outerHTML);let t=o.head.shouldReAppend(d);let n=o.head.shouldPreserve(d);if(e||n){if(t){i.push(d)}else{s.delete(d.outerHTML);l.push(d)}}else{if(o.head.style==="append"){if(t){i.push(d);a.push(d)}}else{if(o.head.shouldRemove(d)!==false){i.push(d)}}}}a.push(...s.values());let c=[];for(const u of a){let n=o.doc.createRange().createContextualFragment(u.outerHTML).firstChild;if(o.callbacks.beforeNodeAdded(n)!==false){if("href"in n&&n.href||"src"in n&&n.src){let t;let e=new Promise(function(e){t=e});n.addEventListener("load",function(){t()});c.push(e)}e.appendChild(n);o.callbacks.afterNodeAdded(n);r.push(n)}}for(const f of i){if(o.callbacks.beforeNodeRemoved(f)!==false){e.removeChild(f);o.callbacks.afterNodeRemoved(f)}}o.head.afterHeadMorphed(e,{added:r,kept:l,removed:i});return c}const d=function(){function e(e,t,n){const{persistentIds:o,idMap:r}=f(e,t);const i=c(n);const l=i.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(l)){throw`Do not understand how to morph style ${l}`}if(l==="innerHTML"&&!e.append){throw`Cannot morph the innerHTML of a ${e.nodeName} node, as it cannot have children`}const a=i.head.style||"merge";if(!["merge","append","morph","none"].includes(a)){throw`Do not understand how to morph head style ${a}`}const s=e.ownerDocument;return{target:e,newContent:t,doc:s,config:i,morphStyle:l,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,restoreFocus:i.restoreFocus,idMap:r,persistentIds:o,pantry:d(s),activeElementAndParents:u(e,s),callbacks:i.callbacks,head:i.head}}function c(e){let t=Object.assign({},n);Object.assign(t,e);t.callbacks=Object.assign({},n.callbacks,e.callbacks);t.head=Object.assign({},n.head,e.head);return t}function d(e){const t=e.createElement("div");t.hidden=true;e.documentElement.append(t);return t}function u(e,t){let n=[];let o=t.activeElement;if(o?.tagName!=="BODY"&&e.contains(o)){while(o){n.push(o);if(o===e)break;o=o.parentElement}}return n}function a(e){let t=[];const n=e;for(const r of n.querySelectorAll?.("[id]")??[]){const i=r.getAttribute("id");if(i)t.push({elt:r,id:i})}const o=n.getAttribute?.("id");if(o)t.push({elt:e,id:o});return t}function s(n,e,o,t){for(const{elt:r,id:i}of t){if(e.has(i)){let t=r;while(t){let e=n.get(t);if(e==null){e=new Set;n.set(t,e)}e.add(i);if(t===o)break;t=t.parentElement}}}}function f(e,t){const n=a(e);const o=a(t);const r=h(n,o);let i=new Map;s(i,r,e,n);const l=t.__idiomorphRoot||t;s(i,r,l,o);return{persistentIds:r,idMap:i}}function h(e,t){let n=new Set;let o=new Map;for(const{elt:i,id:l}of e){if(o.has(l)){n.add(l)}else{o.set(l,i.tagName)}}let r=new Set;for(const{elt:i,id:l}of t){if(r.has(l)){n.add(l)}else if(o.get(l)===i.tagName){r.add(l)}}for(const l of n){r.delete(l)}if(n.size){console.warn("[Warning] duplicate ids found during morph, state loss within these elements is possible:",Array.from(n))}return r}return e}();const{normalizeElement:u,normalizeParent:f}=function(){const r=new WeakSet;function e(e){if(g.document(e)){return e.documentElement}else{return e}}function o(e){if(e==null){return document.createElement("div")}else if(typeof e==="string"){return o(l(e))}else if(r.has(e)){return e}else if(g.node(e)){if(e.parentNode){return new i(e)}else{const t=document.createElement("div");t.append(e);return t}}else{const t=document.createElement("div");for(const n of[...e]){t.append(n)}return t}}class i{constructor(e){this.originalNode=e;this.realParentNode=e.parentNode;this.previousSibling=e.previousSibling;this.nextSibling=e.nextSibling}get childNodes(){const e=[];let t=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;while(t&&t!=this.nextSibling){e.push(t);t=t.nextSibling}return e}querySelectorAll(o){return this.childNodes.reduce((t,e)=>{if(g.element(e)){if(e.matches(o))t.push(e);const n=e.querySelectorAll(o);for(let e=0;e<n.length;e++){t.push(n[e])}}return t},[])}insertBefore(e,t){return this.realParentNode.insertBefore(e,t)}moveBefore(e,t){return this.realParentNode.moveBefore(e,t)}get __idiomorphRoot(){return this.originalNode}}function l(n){let o=new DOMParser;let e=n.replace(/<svg(\\s[^>]*>|>)([\\s\\S]*?)<\\/svg>/gim,"");if(e.match(/<\\/html>/)||e.match(/<\\/head>/)||e.match(/<\\/body>/)){let t=o.parseFromString(n,"text/html");t.doctype?.remove();if(e.match(/<\\/html>/)){r.add(t);return t}else{let e=t.firstChild;if(e){r.add(e)}return e}}else{let e=o.parseFromString("<body><template>"+n+"</template></body>","text/html");let t=e.body.querySelector("template").content;r.add(t);return t}}return{normalizeElement:e,normalizeParent:o}}();const g=function(){const n=e=>e instanceof Element||e?.nodeType===Node.ELEMENT_NODE;const t=(e,t)=>n(e)&&e.localName===t&&e.namespaceURI==="http://www.w3.org/1999/xhtml";return{element:n,node:e=>e instanceof Node||typeof e?.nodeType==="number",document:e=>e instanceof Document||e?.nodeType===Node.DOCUMENT_NODE,templateElement:e=>t(e,"template"),headElement:e=>t(e,"head"),inputElement:e=>t(e,"input"),optionElement:e=>t(e,"option"),textAreaElement:e=>t(e,"textarea")}}();return{morph:t,defaults:n}}();';var vr={three:"https://esm.sh/three@0.169.0","three/addons/":"https://esm.sh/three@0.169.0/examples/jsm/",d3:"https://esm.sh/d3@7.9.0","chart.js/auto":"https://esm.sh/chart.js@4.4.4/auto",gsap:"https://esm.sh/gsap@3.12.5","canvas-confetti":"https://esm.sh/canvas-confetti@1.9.3"};function Ze(e){let t=[];for(let n of e)try{let r=new URL(n);r.protocol==="https:"&&r.origin!=="null"&&t.push(r.origin)}catch{}return[...new Set(t)]}function wr(e){let t=Ze(e.cdn).join(" "),n=e.allowNetwork&&t?t:"'none'";return["default-src 'none'",`script-src 'unsafe-inline' 'unsafe-eval' blob: ${t}`.trim(),`style-src 'unsafe-inline' ${t}`.trim(),`img-src data: blob: ${t}`.trim(),`font-src data: ${t}`.trim(),`media-src data: blob: ${t}`.trim(),`connect-src ${n}`,"worker-src blob:","form-action 'none'","base-uri 'none'"].join("; ")}function Et(e,t){return e.replace(new RegExp(`</(${t})`,"gi"),"<\\/$1")}var kr=new RegExp("[\u2028\u2029]","g");function gn(e){return JSON.stringify(e).replace(/</g,"\\u003c").replace(kr,t=>"\\u"+t.charCodeAt(0).toString(16))}function Mt(e){let t=Object.entries(e).filter(([r,i])=>/^--ui-[a-z-]+$/.test(r)&&!/[;{}<]/.test(i)).map(([r,i])=>`${r}:${i};`).join(""),n=e["--ui-scheme"]==="dark"?"dark":"light";return`:root{${t}color-scheme:${n};}`}function Ot(e){return e["--ui-scheme"]==="dark"?"dark":"light"}var Sr=`
|
|
4
|
+
"use strict";var Be=Object.defineProperty;var Qn=Object.getOwnPropertyDescriptor;var er=Object.getOwnPropertyNames;var tr=Object.prototype.hasOwnProperty;var nr=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var rr=(e,t)=>{for(var n in t)Be(e,n,{get:t[n],enumerable:!0})},ir=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of er(t))!tr.call(e,i)&&i!==n&&Be(e,i,{get:()=>t[i],enumerable:!(r=Qn(t,i))||r.enumerable});return e};var or=e=>ir(Be({},"__esModule",{value:!0}),e);var H=(e,t,n)=>nr(e,typeof t!="symbol"?t+"":t,n);var pi={};rr(pi,{apply:()=>fi,inject:()=>ui,promptSession:()=>Zn});module.exports=or(pi);var Ve=Object.freeze({sin:[1,Math.sin],cos:[1,Math.cos],tan:[1,Math.tan],asin:[1,Math.asin],acos:[1,Math.acos],atan:[1,Math.atan],atan2:[2,Math.atan2],sinh:[1,Math.sinh],cosh:[1,Math.cosh],tanh:[1,Math.tanh],exp:[1,Math.exp],ln:[1,Math.log],log:[1,Math.log10],log10:[1,Math.log10],log2:[1,Math.log2],sqrt:[1,Math.sqrt],cbrt:[1,Math.cbrt],abs:[1,Math.abs],sign:[1,Math.sign],floor:[1,Math.floor],ceil:[1,Math.ceil],round:[1,Math.round],min:[-1,Math.min],max:[-1,Math.max],pow:[2,Math.pow],hypot:[-1,Math.hypot]}),Gt=Object.freeze({pi:Math.PI,e:Math.E,tau:2*Math.PI}),Yt=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0,Xt=500;function sr(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r===" "||r===" "||r===`
|
|
5
|
+
`){n++;continue}let i=/^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(e.slice(n));if(i){t.push({t:"num",v:Number(i[0]),at:n}),n+=i[0].length;continue}let s=/^[A-Za-z_][A-Za-z_0-9]*/.exec(e.slice(n));if(s){t.push({t:"id",v:s[0],at:n}),n+=s[0].length;continue}if(e.startsWith("**",n)){t.push({t:"op",v:"^",at:n}),n+=2;continue}if("+-*/%^".includes(r)){t.push({t:"op",v:r,at:n}),n++;continue}if(r==="("||r===")"||r===","){t.push({t:r,v:r,at:n}),n++;continue}if(r==="·"||r==="×"){t.push({t:"op",v:"*",at:n}),n++;continue}throw new SyntaxError(`unexpected character ${JSON.stringify(r)} at ${n}`)}return t}function xt(e,t){if(typeof e!="string"||!e.trim())throw new SyntaxError("empty expression");if(e.length>Xt)throw new SyntaxError(`longer than ${Xt} characters`);let n=new Set(t),r=sr(e),i=0,s=()=>r[i],o=p=>{throw new SyntaxError(p)},a=p=>{let d=r[i];(!d||d.t!==p)&&o(`expected "${p}" ${d?`at ${d.at}`:"at end"}`),i++};function l(){let p=c();for(;s()?.t==="op"&&(s().v==="+"||s().v==="-");){let d=r[i++].v,k=p,h=c();p=d==="+"?S=>k(S)+h(S):S=>k(S)-h(S)}return p}function c(){let p=y();for(;;){let d=s();if(d?.t==="op"&&(d.v==="*"||d.v==="/"||d.v==="%")){i++;let h=p,S=y();p=d.v==="*"?b=>h(b)*S(b):d.v==="/"?b=>h(b)/S(b):b=>h(b)%S(b);continue}let k=r[i-1];if(d&&(d.t==="id"||d.t==="("||d.t==="num")&&k&&(k.t==="num"||k.t===")")&&!(d.t==="num"&&k.t==="num")){let h=p,S=y();p=b=>h(b)*S(b);continue}return p}}function y(){let p=s();if(p?.t==="op"&&(p.v==="-"||p.v==="+")){i++;let d=y();return p.v==="-"?k=>-d(k):d}return x()}function x(){let p=v();if(s()?.t==="op"&&s().v==="^"){i++;let d=y();return k=>p(k)**d(k)}return p}function v(){let p=r[i++];if(p||o("unexpected end of expression"),p.t==="num"){let d=p.v;return()=>d}if(p.t==="("){let d=l();return a(")"),d}if(p.t==="id"){let d=String(p.v);if(s()?.t==="("){let h=Yt(Ve,d);h||o(`unknown function "${d}"; allowed: ${Object.keys(Ve).join(", ")}`),i++;let S=[];if(s()?.t!==")")for(S.push(l());s()?.t===",";)i++,S.push(l());a(")");let[b,w]=h;if(b>=0&&S.length!==b&&o(`${d}() takes ${b} argument(s), got ${S.length}`),b<0&&S.length===0&&o(`${d}() needs at least one argument`),S.length===1){let $=S[0];return E=>w($(E))}if(S.length===2){let[$,E]=S;return P=>w($(P),E(P))}return $=>w(...S.map(E=>E($)))}if(n.has(d))return h=>h[d];let k=Yt(Gt,d);if(k!==void 0)return()=>k;o(`unknown variable "${d}"; available: ${[...n,...Object.keys(Gt)].join(", ")}`)}o(`unexpected "${p.v}" at ${p.at}`)}let m=l();return i<r.length&&o(`unexpected "${r[i].v}" at ${r[i].at}`),m}function Zt(e,t){try{xt(e,t);return}catch(n){return n instanceof Error?n.message:String(n)}}var Le=["default","muted","info","success","warning","error"],ar=["text","number","range","select","checkbox","date","textarea"],lr=["bar","line","area","pie"],B=Object.freeze({components:300,depth:24,tableRows:500,tableColumns:24,chartPoints:500,chartSeries:12,formFields:40,text:2e4,plotFunctions:8,plotParams:8,timelineItems:100}),We=Object.freeze({Card:{description:"Bordered container with optional title/subtitle/footer; children stack vertically.",children:!0,props:{title:{type:"string"},subtitle:{type:"string"},footer:{type:"string"}}},Stack:{description:"Lays out children vertically (default) or horizontally.",children:!0,props:{direction:{type:"enum",values:["vertical","horizontal"]},gap:{type:"number",min:0,max:64},wrap:{type:"boolean"},align:{type:"enum",values:["start","center","end","stretch"]}}},Grid:{description:"Responsive grid; `columns` is the column count on wide screens (1-6).",children:!0,props:{columns:{type:"number",required:!0,min:1,max:6}}},Tabs:{description:"Tabbed panels: labels[i] titles children[i].",children:!0,props:{labels:{type:"array",required:!0,items:{type:"string"},max:12}}},Text:{description:"Text with a markdown subset (**bold**, *italic*, `code`, [link](https://...), line breaks).",children:!1,props:{text:{type:"string",required:!0,max:B.text},variant:{type:"enum",values:["body","title","heading","caption"]},tone:{type:"enum",values:Le}}},Code:{description:"Monospaced code block.",children:!1,props:{code:{type:"string",required:!0,max:B.text},language:{type:"string"}}},Alert:{description:"Callout box with a tone.",children:!1,props:{title:{type:"string"},text:{type:"string",required:!0},tone:{type:"enum",values:Le}}},Badge:{description:"Small inline label.",children:!1,props:{text:{type:"string",required:!0},tone:{type:"enum",values:Le}}},Divider:{description:"Horizontal rule.",children:!1,props:{}},Stat:{description:"KPI tile: label, big value, optional delta with trend.",children:!1,props:{label:{type:"string",required:!0},value:{type:"scalar",required:!0},delta:{type:"string"},trend:{type:"enum",values:["up","down","flat"]},hint:{type:"string"}}},Progress:{description:"Progress bar; value out of max (default 100).",children:!1,props:{value:{type:"number",required:!0},max:{type:"number",min:0},label:{type:"string"},tone:{type:"enum",values:Le}}},List:{description:"Bulleted or numbered list of short markdown-subset strings.",children:!1,props:{items:{type:"array",required:!0,items:{type:"string"},max:200},ordered:{type:"boolean"}}},Table:{description:"Data table. rows[i][j] belongs to columns[j]. Click-to-sort when sortable.",children:!1,props:{columns:{type:"array",required:!0,items:{type:"string"},max:B.tableColumns},rows:{type:"array",required:!0,max:B.tableRows,items:{type:"array",items:{type:"scalar"},max:B.tableColumns}},caption:{type:"string"},sortable:{type:"boolean"}}},Chart:{description:"SVG chart. labels are the x categories (pie: slice names); each series has one value per label.",children:!1,props:{kind:{type:"enum",required:!0,values:lr},labels:{type:"array",required:!0,items:{type:"scalar"},max:B.chartPoints},series:{type:"array",required:!0,max:B.chartSeries,items:{type:"object",props:{name:{type:"string",required:!0},values:{type:"array",required:!0,items:{type:"number"},max:B.chartPoints}}}},title:{type:"string"},unit:{type:"string"},stacked:{type:"boolean"},height:{type:"number",min:120,max:600}}},Button:{description:"Button that, when the user clicks it, sends `prompt` back to you as the user's next message.",children:!1,props:{label:{type:"string",required:!0},prompt:{type:"string",required:!0},variant:{type:"enum",values:["primary","secondary"]}}},Form:{description:"Input form. On submit the values are sent back to you as the user's next message (prefixed by `prompt` when given).",children:!1,props:{title:{type:"string"},submitLabel:{type:"string"},prompt:{type:"string"},fields:{type:"array",required:!0,max:B.formFields,items:{type:"object",props:{name:{type:"string",required:!0},label:{type:"string",required:!0},type:{type:"enum",required:!0,values:ar},options:{type:"array",items:{type:"string"},max:100},required:{type:"boolean"},placeholder:{type:"string"},default:{type:"scalar"},min:{type:"number"},max:{type:"number"},step:{type:"number",min:0}}}}}},Timeline:{description:"Vertical timeline of events/steps in order.",children:!1,props:{items:{type:"array",required:!0,max:B.timelineItems,items:{type:"object",props:{title:{type:"string",required:!0},time:{type:"string"},text:{type:"string"},tone:{type:"enum",values:Le}}}}}},Plot:{description:"Function plot y = f(x) drawn natively. `params` become sliders the user drags; the curves update instantly in the browser (no message to you). Expressions use x, the param names, pi, e, + - * / ^, and functions like sin, cos, exp, ln, sqrt, abs.",children:!1,props:{functions:{type:"array",required:!0,max:B.plotFunctions,items:{type:"object",props:{expr:{type:"string",required:!0,max:500},label:{type:"string"}}}},xMin:{type:"number"},xMax:{type:"number"},yMin:{type:"number"},yMax:{type:"number"},params:{type:"array",max:B.plotParams,items:{type:"object",props:{name:{type:"string",required:!0},label:{type:"string"},min:{type:"number",required:!0},max:{type:"number",required:!0},step:{type:"number",min:0},value:{type:"number",required:!0}}}},title:{type:"string"},xLabel:{type:"string"},yLabel:{type:"string"},height:{type:"number",min:160,max:600}}},Math:{description:"LaTeX math typeset with KaTeX (block by default). Put related equations in one node (e.g. \\begin{aligned}...\\end{aligned}). In JSON, escape each backslash (\\\\frac).",children:!1,props:{tex:{type:"string",required:!0,max:5e3},display:{type:"boolean"}}},Mermaid:{description:"Diagram from Mermaid source (flowchart, sequenceDiagram, classDiagram, stateDiagram, erDiagram, gantt, timeline, mindmap, pie).",children:!1,props:{code:{type:"string",required:!0,max:B.text}}}}),Je=Object.freeze(Object.keys(We));function Se(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ge(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Qt(e,t,n,r){switch(t.type){case"any":return;case"string":if(typeof e!="string"){r.push(`${n}: expected string, got ${ge(e)}`);return}t.max!==void 0&&e.length>t.max&&r.push(`${n}: longer than ${t.max} characters`);return;case"number":if(typeof e!="number"||!Number.isFinite(e)){r.push(`${n}: expected finite number, got ${ge(e)}`);return}t.min!==void 0&&e<t.min&&r.push(`${n}: must be >= ${t.min}`),t.max!==void 0&&e>t.max&&r.push(`${n}: must be <= ${t.max}`);return;case"boolean":typeof e!="boolean"&&r.push(`${n}: expected boolean, got ${ge(e)}`);return;case"scalar":e===null||["string","number","boolean"].includes(typeof e)||r.push(`${n}: expected string, number, boolean or null, got ${ge(e)}`);return;case"enum":t.values.includes(e)||r.push(`${n}: expected one of ${t.values.join(" | ")}, got ${JSON.stringify(e)}`);return;case"array":if(!Array.isArray(e)){r.push(`${n}: expected array, got ${ge(e)}`);return}if(t.max!==void 0&&e.length>t.max){r.push(`${n}: more than ${t.max} items`);return}t.items&&e.forEach((i,s)=>Qt(i,t.items,`${n}[${s}]`,r));return;case"object":if(!Se(e)){r.push(`${n}: expected object, got ${ge(e)}`);return}en(e,t.props||{},n,r);return;default:r.push(`${n}: unknown spec type ${t.type}`)}}function en(e,t,n,r){for(let[i,s]of Object.entries(t)){let o=e[i];if(o===void 0){s.required&&r.push(`${n}.${i}: required`);continue}Qt(o,s,`${n}.${i}`,r)}for(let i of Object.keys(e))i in t||r.push(`${n}.${i}: unknown prop`)}function dr(e,t,n,r){if(e==="Chart"&&Array.isArray(t.labels)&&Array.isArray(t.series)&&(t.series.forEach((i,s)=>{Se(i)&&Array.isArray(i.values)&&i.values.length!==t.labels.length&&r.push(`${n}.series[${s}].values: has ${i.values.length} values but labels has ${t.labels.length}`)}),t.kind==="pie"&&t.series.length>1&&r.push(`${n}.series: a pie chart takes exactly one series`)),e==="Form"&&Array.isArray(t.fields)){let i=new Set;t.fields.forEach((s,o)=>{Se(s)&&(i.has(s.name)&&r.push(`${n}.fields[${o}].name: duplicate field name ${JSON.stringify(s.name)}`),i.add(s.name),s.type==="select"&&(!Array.isArray(s.options)||s.options.length===0)&&r.push(`${n}.fields[${o}].options: a select field needs options`),s.type==="range"&&!(typeof s.min=="number"&&typeof s.max=="number"&&s.min<s.max)&&r.push(`${n}.fields[${o}]: a range field needs numeric min < max`))})}e==="Plot"&&fr(t,n,r)}var cr=/^[A-Za-z_][A-Za-z_0-9]*$/,ur=new Set(["x","pi","e","tau",...Object.keys(Ve)]);function fr(e,t,n){let r=typeof e.xMin=="number"?e.xMin:-10,i=typeof e.xMax=="number"?e.xMax:10;r<i||n.push(`${t}: xMin must be less than xMax`),typeof e.yMin=="number"&&typeof e.yMax=="number"&&!(e.yMin<e.yMax)&&n.push(`${t}: yMin must be less than yMax`);let s=[];Array.isArray(e.params)&&e.params.forEach((o,a)=>{if(!Se(o)||typeof o.name!="string")return;let l=`${t}.params[${a}]`;cr.test(o.name)?ur.has(o.name)?n.push(`${l}.name: "${o.name}" is reserved`):s.includes(o.name)&&n.push(`${l}.name: duplicate parameter "${o.name}"`):n.push(`${l}.name: must be an identifier like "a" or "omega"`),s.push(o.name),typeof o.min=="number"&&typeof o.max=="number"&&(o.min<o.max?typeof o.value=="number"&&(o.value<o.min||o.value>o.max)&&n.push(`${l}.value: must lie within [min, max]`):n.push(`${l}: min must be less than max`))}),Array.isArray(e.functions)&&e.functions.forEach((o,a)=>{if(!Se(o)||typeof o.expr!="string")return;let l=Zt(o.expr,["x",...s]);l&&n.push(`${t}.functions[${a}].expr: ${l}`)})}function tn(e,t,n="props"){let r=We[e];if(!r)return[`${n}: unknown component type ${JSON.stringify(e)}; use one of ${Je.join(", ")}`];let i=t===void 0?{}:t;if(!Se(i))return[`${n}: expected object, got ${ge(i)}`];let s=[];return en(i,r.props,n,s),dr(e,i,n,s),s}var mr=Object.freeze(["setProps","replaceNode","insertChild","removeNode"]),hr=Object.freeze({ops:50,nodesPerOp:B.components}),xi=Object.freeze({setProps:["id","props","unset"],replaceNode:["id","node","nodes"],insertChild:["parent","id","index","nodes"],removeNode:["id"]});function W(e){return e==null}function Ge(e){return e&&typeof e=="object"&&!Array.isArray(e)}function rn(e,t){return Object.fromEntries(Object.entries(e).filter(([n,r])=>t(n,r)))}function te(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}function on(e,t,n){if(!t)return{...e};let r={};for(let i of t)(n||e[i]!==void 0)&&(r[i]=e[i]);return r}var sn=Symbol.for("cosmokit.volatile.write");function vt(e,t=new Set){if(typeof e=="function")throw new TypeError("volatile config cannot contain functions");if(e===null||typeof e!="object")return e;if(t.has(e))throw new TypeError("volatile config cannot contain cycles");t.add(e);try{if(Array.isArray(e))return Object.freeze(e.map(n=>vt(n,t)));if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new TypeError("volatile config objects must be plain objects or arrays");return Object.freeze(Object.fromEntries(Object.entries(e).map(([n,r])=>[n,vt(r,t)])))}finally{t.delete(e)}}function wt(e){let t=vt(e);return Object.freeze({get:()=>t,[sn]:n=>{t=n}})}function $e(e){return typeof e=="object"&&e!==null&&sn in e}function oe(e,t){return arguments.length===1?n=>oe(e,n):e in globalThis&&t instanceof globalThis[e]||Object.prototype.toString.call(t).slice(8,-1)===e}function Ye(e){return oe("ArrayBuffer",e)||oe("SharedArrayBuffer",e)}function gr(e){return Ye(e)||ArrayBuffer.isView(e)}var Y;(function(e){e.is=Ye,e.isSource=gr;function t(o){return ArrayBuffer.isView(o)?o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength):o}e.fromSource=t;function n(o){if(o=t(o),typeof Buffer<"u")return Buffer.from(o).toString("base64");let a="",l=new Uint8Array(o);for(let c=0;c<l.byteLength;c++)a+=String.fromCharCode(l[c]);return btoa(a)}e.toBase64=n;function r(o){return typeof Buffer<"u"?t(Buffer.from(o,"base64")):Uint8Array.from(atob(o),a=>a.charCodeAt(0))}e.fromBase64=r;function i(o){return o=t(o),typeof Buffer<"u"?Buffer.from(o).toString("hex"):Array.from(new Uint8Array(o),a=>a.toString(16).padStart(2,"0")).join("")}e.toHex=i;function s(o){if(typeof Buffer<"u")return t(Buffer.from(o,"hex"));let a=o.length%2===0?o:o.slice(0,o.length-1),l=[];for(let c=0;c<a.length;c+=2)l.push(parseInt(`${a[c]}${a[c+1]}`,16));return Uint8Array.from(l).buffer}e.fromHex=s})(Y||(Y={}));var wi=Y.fromBase64,ki=Y.toBase64,Si=Y.fromHex,$i=Y.toHex;function Ke(e,t=new Map){if(!e||typeof e!="object")return e;if(oe("Date",e))return new Date(e.valueOf());if(oe("RegExp",e))return new RegExp(e.source,e.flags);if(Ye(e))return e.slice(0);if(ArrayBuffer.isView(e))return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);let n=t.get(e);if(n)return n;if(Array.isArray(e)){let i=[];return t.set(e,i),e.forEach((s,o)=>{i[o]=Reflect.apply(Ke,null,[s,t])}),i}let r=Object.create(Object.getPrototypeOf(e));t.set(e,r);for(let i of Reflect.ownKeys(e)){let s={...Reflect.getOwnPropertyDescriptor(e,i)};"value"in s&&(s.value=Reflect.apply(Ke,null,[s.value,t])),Reflect.defineProperty(r,i,s)}return r}function Xe(e,t,n){let r=new Set;function i(s,o){if(s===o)return!0;if($e(s)||$e(o))return $e(s)&&$e(o);if(!n&&W(s)&&W(o))return!0;if(typeof s!=typeof o||typeof s!="object"||!s||!o||r.has(s))return!1;function a(l,c){return l(s)?l(o)?c(s,o):!1:l(o)?!1:void 0}r.add(s);try{return a(Array.isArray,(l,c)=>{if(l.length!==c.length)return!1;for(let y=0;y<l.length;y++)if(!i(l[y],c[y]))return!1;return!0})??a(oe("Date"),(l,c)=>l.valueOf()===c.valueOf())??a(oe("URL"),(l,c)=>l.href===c.href)??a(oe("RegExp"),(l,c)=>l.source===c.source&&l.flags===c.flags)??a(Ye,(l,c)=>{if(l.byteLength!==c.byteLength)return!1;let y=new Uint8Array(l),x=new Uint8Array(c);for(let v=0;v<y.length;v++)if(y[v]!==x[v])return!1;return!0})??((!n||[s,o].every(l=>Object.getPrototypeOf(l)===Object.prototype||Object.getPrototypeOf(l)===null))&&Object.keys({...s,...o}).every(l=>i(s[l],o[l])))}finally{r.delete(s)}}return i(e,t)}var nn;(function(e){e.millisecond=1,e.second=1e3,e.minute=e.second*60,e.hour=e.minute*60,e.day=e.hour*24,e.week=e.day*7;let t=new Date().getTimezoneOffset();function n(m){t=m}e.setTimezoneOffset=n;function r(){return t}e.getTimezoneOffset=r;function i(m=new Date,p){return typeof m=="number"&&(m=new Date(m)),p===void 0&&(p=t),Math.floor((m.valueOf()/e.minute-p)/1440)}e.getDateNumber=i;function s(m,p){let d=new Date(m*e.day);return p===void 0&&(p=t),new Date(+d+p*e.minute)}e.fromDateNumber=s;let o=/\d+(?:\.\d+)?/.source,a=new RegExp(`^${["w(?:eek(?:s)?)?","d(?:ay(?:s)?)?","h(?:our(?:s)?)?","m(?:in(?:ute)?(?:s)?)?","s(?:ec(?:ond)?(?:s)?)?"].map(m=>`(${o}${m})?`).join("")}$`);function l(m){let p=a.exec(m);return p?(parseFloat(p[1])*e.week||0)+(parseFloat(p[2])*e.day||0)+(parseFloat(p[3])*e.hour||0)+(parseFloat(p[4])*e.minute||0)+(parseFloat(p[5])*e.second||0):0}e.parseTime=l;function c(m){let p=l(m);return p?m=Date.now()+p:/^\d{1,2}(:\d{1,2}){1,2}$/.test(m)?m=`${new Date().toLocaleDateString()}-${m}`:/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(m)&&(m=`${new Date().getFullYear()}-${m}`),m?new Date(m):new Date}e.parseDate=c;function y(m){let p=Math.abs(m);return p>=e.day-e.hour/2?Math.round(m/e.day)+"d":p>=e.hour-e.minute/2?Math.round(m/e.hour)+"h":p>=e.minute-e.second/2?Math.round(m/e.minute)+"m":p>=e.second?Math.round(m/e.second)+"s":m+"ms"}e.format=y;function x(m,p=2){return m.toString().padStart(p,"0")}e.toDigits=x;function v(m,p=new Date){return m.replace("yyyy",p.getFullYear().toString()).replace("yy",p.getFullYear().toString().slice(2)).replace("MM",x(p.getMonth()+1)).replace("dd",x(p.getDate())).replace("hh",x(p.getHours())).replace("mm",x(p.getMinutes())).replace("ss",x(p.getSeconds())).replace("SSS",x(p.getMilliseconds(),3))}e.template=v})(nn||(nn={}));var ze=Symbol.for("schemastery"),dn=Symbol.for("ValidationError");globalThis.__schemastery_index__??(globalThis.__schemastery_index__=0);globalThis.__schemastery_refs__=void 0;var I=class extends TypeError{constructor(t,n){let r="$";for(let i of n.path||[])typeof i=="string"?r+="."+i:typeof i=="number"?r+="["+i+"]":typeof i=="symbol"&&(r+=`[Symbol(${i.toString()})]`);r.startsWith(".")&&(r=r.slice(1));super((r==="$"?"":`${r} `)+t);H(this,"options");H(this,"name","ValidationError");this.options=n}static is(t){return!!t?.[dn]}};Object.defineProperty(I.prototype,dn,{value:!0});var u=function(e){let t=function(n,r={}){return u.resolve(n,t,r)[0]};if(e.refs){let n=te(e.refs,i=>new u(i)),r=i=>n[i];for(let i in n){let s=n[i];s.sKey=r(s.sKey),s.inner=r(s.inner),s.list=s.list&&s.list.map(r),s.dict=s.dict&&te(s.dict,r)}return n[e.uid]}if(Object.assign(t,e),typeof t.callback=="string")try{t.callback=new Function("return "+t.callback)()}catch{}return Object.defineProperty(t,"uid",{value:globalThis.__schemastery_index__++}),Object.setPrototypeOf(t,u.prototype),t.meta||(t.meta={}),t.toString=t.toString.bind(t),t};u.prototype=Object.create(Function.prototype);u.prototype[ze]=!0;Object.defineProperty(u.prototype,"~standard",{get(){return{version:1,vendor:"schemastery",validate:e=>{try{return{value:u.resolve(e,this,{})[0]}}catch(t){if(I.is(t))return{issues:[{message:t.message,path:t.options.path}]};throw t}}}}});u.ValidationError=I;u.prototype.toJSON=function(){var n,r;if(globalThis.__schemastery_refs__)return(n=globalThis.__schemastery_refs__)[r=this.uid]??(n[r]=JSON.parse(JSON.stringify({...this}))),this.uid;globalThis.__schemastery_refs__={[this.uid]:{...this}},globalThis.__schemastery_refs__[this.uid]=JSON.parse(JSON.stringify({...this}));let t={uid:this.uid,refs:globalThis.__schemastery_refs__};return globalThis.__schemastery_refs__=void 0,t};u.prototype.set=function(t,n){return this.dict[t]=n,this};u.prototype.push=function(t){return this.list.push(t),this};function yr(e,t){let n=typeof e=="string"?{"":e}:{...e};for(let r in t){let i=t[r];i?.$description||i?.$desc?n[r]=i.$description||i.$desc:typeof i=="string"&&(n[r]=i)}return n}function Fe(e){return e?.$value??e?.$inner}function an(e){return rn(e??{},t=>!t.startsWith("$"))}u.prototype.i18n=function(t){let n=u(this),r=yr(n.meta.description,t);return Object.keys(r).length&&(n.meta.description=r),n.dict&&(n.dict=te(n.dict,(i,s)=>i.i18n(te(t,o=>Fe(o)?.[s]??o?.[s])))),n.list&&(n.list=n.list.map((i,s)=>i.i18n(te(t,(o={})=>Array.isArray(Fe(o))?Fe(o)[s]:Array.isArray(o)?o[s]:an(o))))),n.inner&&(n.inner=n.inner.i18n(te(t,i=>Fe(i)?Fe(i):an(i)))),n.sKey&&(n.sKey=n.sKey.i18n(te(t,i=>i?.$key))),n};u.prototype.extra=function(t,n){let r=u(this);return r.meta={...r.meta,[t]:n},r};for(let e of["required","disabled","collapse","hidden","loose"])Object.assign(u.prototype,{[e](t=!0){let n=u(this);return n.meta={...n.meta,[e]:t},n}});u.prototype.deprecated=function(){var n;let t=u(this);return(n=t.meta).badges||(n.badges=[]),t.meta.badges.push({text:"deprecated",type:"danger"}),t};u.prototype.experimental=function(){var n;let t=u(this);return(n=t.meta).badges||(n.badges=[]),t.meta.badges.push({text:"experimental",type:"warning"}),t};u.prototype.pattern=function(t){let n=u(this),r=on(t,["source","flags"]);return n.meta={...n.meta,pattern:r},n};u.prototype.simplify=function(t){if($e(t)&&(t=t.get()),Xe(t,this.meta.default,this.type==="dict"))return null;if(W(t))return t;if(this.type==="object"||this.type==="dict"){let n={};for(let r in t){let i=(this.type==="object"?this.dict[r]:this.inner)?.simplify(t[r]);(this.type==="dict"||!W(i))&&(n[r]=i)}return Xe(n,this.meta.default,this.type==="dict")?null:n}else if(this.type==="array"||this.type==="tuple"){let n=[];return t.forEach((r,i)=>{let s=this.type==="array"?this.inner:this.list[i],o=s?s.simplify(r):r;n.push(o)}),n}else if(this.type==="intersect"){let n={};for(let r of this.list)Object.assign(n,r.simplify(t));return n}else if(this.type==="union")for(let n of this.list)try{return u.resolve(t,n,{}),n.simplify(t)}catch{}return t};u.prototype.toString=function(t){return un[this.type]?.(this,t)??`Schema<${this.type}>`};u.prototype.role=function(e,t){let n=u(this);return n.meta={...n.meta,role:e,extra:t},n};for(let e of["default","link","comment","description","max","min","step"])Object.assign(u.prototype,{[e](t){let n=u(this);return n.meta={...n.meta,[e]:t},n}});u.prototype.volatile=function(){if(this.meta.volatile)throw new TypeError("volatile schema is already wrapped");return this.extra("volatile",!0)};var cn={},ln=Symbol("checked-volatile-schema");function Ne(e,t=[],n=!1,r=new Map){let i=r.get(e)??new Set;if(i.has(n))return;if(i.add(n),r.set(e,i),e.meta?.volatile&&n)throw new I("volatile fields require a fixed object path without an enclosing volatile field",{path:t});let s=n||!!e.meta?.volatile;if(e.dict)for(let[o,a]of Object.entries(e.dict))Ne(a,[...t,o],s,r);if(e.sKey&&Ne(e.sKey,[...t,"<key>"],!0,r),e.inner&&(e.type!=="lazy"||e.inner[ze])&&Ne(e.inner,[...t,"*"],!0,r),e.list)for(let o=0;o<e.list.length;o++)Ne(e.list[o],[...t,String(o)],!0,r)}u.extend=function(t,n){cn[t]=n};u.resolve=function(t,n,r={},i=!1){if(!n)return[t];if(r[ln]||(Ne(n,r.path),r={...r,[ln]:!0}),n.meta?.volatile){let o=u(n);o.meta={...n.meta,volatile:!1};let[a,l]=u.resolve(t,o,r,i);try{return[wt(a),l]}catch(c){throw new I(c instanceof Error?c.message:String(c),r)}}if(r.ignore?.(t,n))return[t];if(W(t)&&n.type!=="lazy"){if(n.meta.required)throw new I("missing required value",r);let o=n,a=n.meta.default;for(;o?.type==="intersect"&&W(a);)o=o.list[0],a=o?.meta.default;if(W(a))return[t];t=Ke(a)}let s=cn[n.type];if(!s)throw new I(`unsupported type "${n.type}"`,r);try{return s(t,n,r,i)}catch(o){if(!n.meta.loose)throw o;return[n.meta.default]}};u.from=function(t){if(W(t))return u.any();if(["string","number","boolean"].includes(typeof t))return u.const(t).required();if(t[ze])return t;if(typeof t=="function")switch(t){case String:return u.string().required();case Number:return u.number().required();case Boolean:return u.boolean().required();case Function:return u.function().required();default:return u.is(t).required()}else throw new TypeError(`cannot infer schema from ${t}`)};u.lazy=function(t){let n=()=>(r.inner[ze]||(r.inner=r.builder(),r.inner.meta={...r.meta,...r.inner.meta}),r.inner.toJSON()),r=new u({type:"lazy",builder:t,inner:{toJSON:n}});return r};u.natural=function(){return u.number().step(1).min(0)};u.percent=function(){return u.number().step(.01).min(0).max(1).role("slider")};u.date=function(){return u.union([u.is(Date),u.transform(u.string().role("datetime"),(t,n)=>{let r=new Date(t);if(isNaN(+r))throw new I(`invalid date "${t}"`,n);return r},!0)])};u.regExp=function(t=""){return u.union([u.is(RegExp),u.transform(u.string().role("regexp",{flag:t}),(n,r)=>{try{return new RegExp(n,t)}catch(i){throw new I(i.message,r)}},!0)])};u.arrayBuffer=function(t){return u.union([u.is(ArrayBuffer),u.is(SharedArrayBuffer),u.transform(u.any(),(n,r)=>{if(Y.isSource(n))return Y.fromSource(n);throw new I(`expected ArrayBufferSource but got ${n}`,r)},!0),...t?[u.transform(u.string(),(n,r)=>{try{return t==="base64"?Y.fromBase64(n):Y.fromHex(n)}catch(i){throw new I(i.message,r)}},!0)]:[]])};u.extend("lazy",(e,t,n,r)=>(t.inner[ze]||(t.inner=t.builder(),t.inner.meta={...t.meta,...t.inner.meta},Ne(t.inner,n.path,!0)),u.resolve(e,t.inner,n,r)));u.extend("any",e=>[e]);u.extend("never",(e,t,n)=>{throw new I(`expected nullable but got ${e}`,n)});u.extend("const",(e,{value:t},n)=>{if(Xe(e,t))return[t];throw new I(`expected ${t} but got ${e}`,n)});function $t(e,t,n,r,i=!1){let{max:s=1/0,min:o=-1/0}=t;if(e>s)throw new I(`expected ${n} <= ${s} but got ${e}`,r);if(e<o&&!i)throw new I(`expected ${n} >= ${o} but got ${e}`,r)}u.extend("string",(e,{meta:t},n)=>{if(typeof e!="string")throw new I(`expected string but got ${e}`,n);if(t.pattern){let r=new RegExp(t.pattern.source,t.pattern.flags);if(!r.test(e))throw new I(`expect string to match regexp ${r}`,n)}return $t(e.length,t,"string length",n),[e]});function kt(e,t){let n=e.toString();if(n.includes("e"))return e*Math.pow(10,t);let r=n.indexOf(".");if(r===-1)return e*Math.pow(10,t);let i=n.slice(r+1),s=n.slice(0,r);return i.length<=t?+(s+i.padEnd(t,"0")):+(s+i.slice(0,t)+"."+i.slice(t))}function br(e,t,n){if(n=Math.abs(n),!/^\d+\.\d+$/.test(n.toString()))return(e-t)%n===0;let r=n.toString().indexOf("."),i=n.toString().slice(r+1).length;return Math.abs(kt(e,i)-kt(t,i))%kt(n,i)===0}u.extend("number",(e,{meta:t},n)=>{if(typeof e!="number")throw new I(`expected number but got ${e}`,n);$t(e,t,"number",n);let{step:r}=t;if(r&&!br(e,t.min??0,r))throw new I(`expected number multiple of ${r} but got ${e}`,n);return[e]});u.extend("boolean",(e,t,n)=>{if(typeof e=="boolean")return[e];throw new I(`expected boolean but got ${e}`,n)});u.extend("bitset",(e,{bits:t,meta:n},r)=>{let i=0,s=[];if(typeof e=="number"){i=e;for(let o in t)e&t[o]&&s.push(o)}else if(Array.isArray(e)){s=e;for(let o of s){if(typeof o!="string")throw new I(`expected string but got ${o}`,r);o in t&&(i|=t[o])}}else throw new I(`expected number or array but got ${e}`,r);return i===n.default?[i]:[i,s]});u.extend("function",(e,t,n)=>{if(typeof e=="function")return[e];throw new I(`expected function but got ${e}`,n)});u.extend("is",(e,{constructor:t},n)=>{if(typeof t=="function"){if(e instanceof t)return[e];throw new I(`expected ${t.name} but got ${e}`,n)}else{if(W(e))throw new I(`expected ${t} but got ${e}`,n);let r=Object.getPrototypeOf(e);for(;r;){if(r.constructor?.name===t)return[e];r=Object.getPrototypeOf(r)}throw new I(`expected ${t} but got ${e}`,n)}});function Ze(e,t,n,r){try{let[i,s]=u.resolve(e[t],n,{...r,path:[...r.path||[],t]});return s!==void 0&&(e[t]=s),i}catch(i){if(!r?.autofix)throw i;return delete e[t],n.meta.volatile?wt(n.meta.default):n.meta.default}}u.extend("array",(e,{inner:t,meta:n},r)=>{if(!Array.isArray(e))throw new I(`expected array but got ${e}`,r);return $t(e.length,n,"array length",r,!W(t.meta.default)),[e.map((i,s)=>Ze(e,s,t,r))]});u.extend("dict",(e,{inner:t,sKey:n},r,i)=>{if(!Ge(e))throw new I(`expected object but got ${e}`,r);let s={};for(let o in e){let a;try{a=u.resolve(o,n,r)[0]}catch(l){if(i)continue;throw l}s[a]=Ze(e,o,t,r),e[a]=e[o],o!==a&&delete e[o]}return[s]});u.extend("tuple",(e,{list:t},n,r)=>{if(!Array.isArray(e))throw new I(`expected array but got ${e}`,n);let i=t.map((s,o)=>Ze(e,o,s,n));return r?[i]:(i.push(...e.slice(t.length)),[i])});function St(e,t){for(let n in t)n in e||(e[n]=t[n])}u.extend("object",(e,{dict:t},n,r)=>{if(!Ge(e))throw new I(`expected object but got ${e}`,n);let i={};for(let s in t){let o=Ze(e,s,t[s],n);(!W(o)||s in e)&&(i[s]=o)}return r||St(i,e),[i]});u.extend("union",(e,{list:t,toString:n},r,i)=>{let s=[];for(let o of t)try{return u.resolve(e,o,r,i)}catch(a){s.push(a)}throw new I(`expected ${n()} but got ${JSON.stringify(e)}`,r)});u.extend("intersect",(e,{list:t,toString:n},r,i)=>{if(!t.length)return[e];let s;for(let o of t){let a=u.resolve(e,o,r,!0)[0];if(!W(a))if(W(s))s=a;else{if(typeof s!=typeof a)throw new I(`expected ${n()} but got ${JSON.stringify(e)}`,r);if(typeof a=="object")St(s??(s={}),a);else if(s!==a)throw new I(`expected ${n()} but got ${JSON.stringify(e)}`,r)}}return!i&&Ge(e)&&St(s,e),[s]});u.extend("transform",(e,{inner:t,callback:n,preserve:r},i)=>{let[s,o=e]=u.resolve(e,t,i,!0);return r?[n(s)]:[n(s),n(o)]});var un={};function D(e,t,n){un[e]=n,Object.assign(u,{[e](...r){let i=new u({type:e});return t.forEach((s,o)=>{switch(s){case"sKey":i.sKey=r[o]??u.string();break;case"inner":i.inner=u.from(r[o]);break;case"list":i.list=r[o].map(u.from);break;case"dict":i.dict=te(r[o],u.from);break;case"bits":i.bits={};for(let a in r[o])typeof r[o][a]=="number"&&(i.bits[a]=r[o][a]);break;case"callback":{let a=i.callback=r[o];a.toJSON||(a.toJSON=()=>a.toString());break}case"constructor":{let a=i.constructor=r[o];typeof a=="function"&&(a.toJSON||(a.toJSON=()=>a.name));break}default:i[s]=r[o]}}),e==="object"||e==="dict"?i.meta.default={}:e==="array"||e==="tuple"?i.meta.default=[]:e==="bitset"&&(i.meta.default=0),i}})}D("is",["constructor"],({constructor:e})=>typeof e=="function"?e.name:e);D("any",[],()=>"any");D("never",[],()=>"never");D("const",["value"],({value:e})=>typeof e=="string"?JSON.stringify(e):e);D("string",[],()=>"string");D("number",[],()=>"number");D("boolean",[],()=>"boolean");D("bitset",["bits"],()=>"bitset");D("function",[],()=>"function");D("array",["inner"],({inner:e})=>`${e.toString(!0)}[]`);D("dict",["inner","sKey"],({inner:e,sKey:t})=>`{ [key: ${t.toString()}]: ${e.toString()} }`);D("tuple",["list"],({list:e})=>`[${e.map(t=>t.toString()).join(", ")}]`);D("object",["dict"],({dict:e})=>Object.keys(e).length===0?"{}":`{ ${Object.entries(e).map(([t,n])=>`${t}${n.meta.required?"":"?"}: ${n.toString()}`).join(", ")} }`);D("union",["list"],({list:e},t)=>{let n=e.map(({toString:r})=>r()).join(" | ");return t?`(${n})`:n});D("intersect",["list"],({list:e})=>`${e.map(t=>t.toString(!0)).join(" & ")}`);D("transform",["inner","callback","preserve"],({inner:e},t)=>e.toString(t));var se=Object.freeze({enableCatalog:!0,enableWidget:!0,injectGuidance:!0,cdnAllowlist:["https://esm.sh","https://cdn.jsdelivr.net","https://unpkg.com"],allowNetwork:!1,maxWidgetHeight:2400,maxWidgetBytes:4e5,sendPromptMaxChars:4e3,openLinkAllowedOrigins:[]}),ji=u.object({enableCatalog:u.boolean().default(se.enableCatalog).description("Register `ui_render` (declarative cards, tables, charts, forms)."),enableWidget:u.boolean().default(se.enableWidget).description("Register `ui_render_widget` (sandboxed streaming HTML/CSS/JS widgets)."),injectGuidance:u.boolean().default(se.injectGuidance).description("Add a system-prompt section telling the model when and how to answer with UI."),cdnAllowlist:u.array(u.string()).default([...se.cdnAllowlist]).description("Origins widgets may load scripts, styles, fonts and images from (CSP)."),allowNetwork:u.boolean().default(se.allowNetwork).description("Allow widgets to fetch()/WebSocket to the CDN allowlist (CSP connect-src). Off: no network calls."),maxWidgetHeight:u.natural().min(200).max(8e3).default(se.maxWidgetHeight).description("Maximum widget frame height in pixels."),maxWidgetBytes:u.natural().min(1e4).default(se.maxWidgetBytes).description("Reject widgets whose html+css+js exceed this many characters."),sendPromptMaxChars:u.natural().min(100).max(2e4).default(se.sendPromptMaxChars).description("Longest message a widget, button or form may send back to the conversation."),openLinkAllowedOrigins:u.array(u.string()).default([]).description("If non-empty, widgets may only open https links on these origins.")});var Ee="ui_render";var ye="ui_patch",Bi={type:"object",properties:{id:{type:"string",description:"Unique new component id."},type:{type:"string",enum:[...Je]},props:{type:"object"},children:{type:"array",items:{type:"string"}}},required:["id","type"]};var be="ui_render_widget";var _e=require("react");var J=class extends Error{constructor(n,r){super(r);H(this,"code",n)}},ae=class{constructor(t){H(this,"opts",t);H(this,"armedAt");H(this,"lastSend",-1/0);H(this,"now");H(this,"minInterval");this.now=t.now??(()=>Date.now()),this.armedAt=this.now()+(t.armDelayMs??1e3),this.minInterval=t.minIntervalMs??2e3}admitPrompt(t){let n=typeof t=="string"?t.trim():"";if(!n)throw new J("empty","sendPrompt needs non-empty text");if(n.length>this.opts.policy.sendPromptMaxChars)throw new J("too-long",`sendPrompt text exceeds ${this.opts.policy.sendPromptMaxChars} characters`);let r=this.now();if(r<this.armedAt)throw new J("not-armed","sendPrompt is only allowed in response to a user action, not on load");if(r-this.lastSend<this.minInterval)throw new J("rate-limited","sendPrompt called too often");return this.lastSend=r,n}admitLink(t){let n;try{n=new URL(String(t))}catch{throw new J("bad-url","openLink needs an absolute https URL")}if(n.protocol!=="https:")throw new J("bad-url","openLink only opens https URLs");let r=this.opts.policy.openLinkOrigins;if(r.length>0&&!r.some(i=>{try{return new URL(i).origin===n.origin}catch{return!1}}))throw new J("origin",`openLink: ${n.origin} is not an allowed origin`);return n.href}};function pn(e,t,n){return`${t?.trim()||(e?`Form "${e}" submitted:`:"Form submitted:")}
|
|
6
|
+
${JSON.stringify(n,null,2)}`}function mn(e,t){if(!e||typeof e!="object")return;let n=e;if(n.__diui===t)switch(n.type){case"rpc":return typeof n.id=="number"&&typeof n.method=="string"?{type:"rpc",id:n.id,method:n.method,params:n.params&&typeof n.params=="object"?n.params:{}}:void 0;case"resize":return typeof n.height=="number"&&Number.isFinite(n.height)?{type:"resize",height:n.height}:void 0;case"error":return{type:"error",kind:String(n.kind??""),message:String(n.message??"").slice(0,500)};case"ready":return{type:"ready",final:n.final===!0};case"state":return n.state&&typeof n.state=="object"&&!Array.isArray(n.state)?{type:"state",state:n.state}:void 0;default:return}}var ne=require("react"),hn="diui:v1:interrupted:",xr=20,vr=2e5,Nt=Object.freeze([]),Et=new Map,Ot=new Map;function Mt(e){let t=Et.get(e);if(t)return t;let n=Nt;try{let r=localStorage.getItem(hn+e),i=r?JSON.parse(r):void 0;Array.isArray(i)&&(n=i.filter(s=>!!s&&typeof s.callId=="string"&&typeof s.argsRaw=="string"&&typeof s.at=="number"))}catch{}return Et.set(e,n),n}function wr(e,t){if(!t.argsRaw.trim()||t.argsRaw.length>vr)return;let n=[...Mt(e).filter(r=>r.callId!==t.callId),t].slice(-xr);Et.set(e,n);try{localStorage.setItem(hn+e,JSON.stringify(n))}catch{}for(let r of[...Ot.get(e)??[]])r()}function gn(e){let t=e??"",n=(0,ne.useCallback)(r=>{let i=Ot.get(t);return i||Ot.set(t,i=new Set),i.add(r),()=>{i.delete(r)}},[t]);return(0,ne.useSyncExternalStore)(n,()=>t?Mt(t):Nt,()=>t?Mt(t):Nt)}function yn(e,t,n){return t===void 0||t<1e12?!1:e.at>=t-500&&e.at<=(n??1/0)+3e3}function Oe(e,t){let n=(0,ne.useRef)({preparing:!1,raw:""});n.current=e.phase==="preparing"?{preparing:!0,raw:t||n.current.raw}:{preparing:!1,raw:""};let r=(0,ne.useRef)(e);r.current=e,(0,ne.useEffect)(()=>()=>{let{preparing:i,raw:s}=n.current,{sessionId:o,callId:a,toolName:l}=r.current;i&&s&&o&&wr(o,{callId:a,toolName:l,argsRaw:s,at:Date.now()})},[])}var K=Object.freeze({cdn:["https://esm.sh","https://cdn.jsdelivr.net","https://unpkg.com"],allowNetwork:!1,maxHeight:2400,sendPromptMaxChars:4e3,openLinkOrigins:[]}),bn=e=>Array.isArray(e)&&e.every(t=>typeof t=="string")?e:void 0;function Me(e){let t=e&&typeof e=="object"?e.policy:void 0;if(!t||typeof t!="object")return K;let n=(r,i)=>typeof r=="number"&&Number.isFinite(r)&&r>0?r:i;return{cdn:bn(t.cdn)??K.cdn,allowNetwork:typeof t.allowNetwork=="boolean"?t.allowNetwork:K.allowNetwork,maxHeight:n(t.maxHeight,K.maxHeight),sendPromptMaxChars:n(t.sendPromptMaxChars,K.sendPromptMaxChars),openLinkOrigins:bn(t.openLinkOrigins)??K.openLinkOrigins}}var V=require("react"),C=require("react/jsx-runtime");function Qe(e,t){let[n,r]=(0,V.useState)(e),i=(0,V.useRef)(e),s=(0,V.useRef)(0),o=(0,V.useRef)(void 0);return i.current=e,(0,V.useEffect)(()=>{let a=Date.now(),l=t-(a-s.current);if(l<=0){s.current=a,r(e);return}o.current===void 0&&(o.current=setTimeout(()=>{o.current=void 0,s.current=Date.now(),r(i.current)},l))},[e,t]),(0,V.useEffect)(()=>()=>{o.current!==void 0&&clearTimeout(o.current)},[]),n}function L(e){return(0,C.jsxs)("div",{className:"diui diui-shell","data-kind":e.kind,"data-state":e.state,"aria-busy":e.state==="generating"||void 0,children:[(0,C.jsxs)("div",{className:"diui-shell-head",children:[(0,C.jsx)("span",{className:"diui-shell-icon","aria-hidden":"true",children:e.kind==="widget"?"◇":"▦"}),(0,C.jsx)("span",{className:"diui-shell-title",children:e.title}),e.state==="generating"&&(0,C.jsxs)("span",{className:"diui-dots","aria-hidden":"true",children:[(0,C.jsx)("i",{}),(0,C.jsx)("i",{}),(0,C.jsx)("i",{})]}),e.status!==void 0&&(0,C.jsx)("span",{className:"diui-shell-status",role:"status","aria-live":"polite",children:e.status}),e.actions!==void 0&&(0,C.jsx)("span",{className:"diui-shell-actions",children:e.actions})]}),e.notice!==void 0&&(0,C.jsx)("div",{className:"diui-shell-notice",role:"status",children:e.notice}),e.children!==void 0&&(0,C.jsx)("div",{className:"diui-shell-body",children:e.children})]})}function Q(e){let[t,n]=(0,V.useState)(!1);return(0,C.jsxs)("div",{className:"diui-problem",role:"status",children:[(0,C.jsx)("span",{children:e.message}),e.detail&&(0,C.jsx)("button",{type:"button",className:"diui-link","aria-expanded":t,onClick:()=>n(r=>!r),children:t?e.t("details.hide"):e.t("details.show")}),t&&e.detail&&(0,C.jsx)("pre",{className:"diui-problem-detail",children:e.detail})]})}function et(e){let t=e.messages.length?e.messages:[e.fallback],[n,r]=(0,V.useState)(0);return(0,V.useEffect)(()=>{if(t.length<2)return;let i=setInterval(()=>r(s=>s+1),1800);return()=>clearInterval(i)},[t.length]),(0,C.jsxs)("div",{className:"diui-placeholder","aria-live":"polite",style:e.height?{minHeight:Math.min(e.height,480)}:void 0,children:[(0,C.jsx)("div",{className:"diui-skeleton"}),(0,C.jsx)("div",{className:"diui-placeholder-text",children:t[n%t.length]})]})}function le(e){return(0,C.jsx)("button",{type:"button",className:"diui-head-button",onClick:e.onClick,disabled:e.disabled,title:e.title,children:e.label})}function xn(){let[e,t]=(0,V.useState)(void 0),n=(0,V.useRef)(void 0);return(0,V.useEffect)(()=>()=>{n.current&&clearTimeout(n.current)},[]),[e,r=>{t(r),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>t(void 0),4e3)}]}var tt=require("react");function vn(e){if(!e||typeof e!="object")return"";let{chunks:t}=e;if(Array.isArray(t)&&t.every(r=>typeof r=="string"))return t.join("");if(typeof e.keys!="function")return"";let n=[];for(let r of e.keys()){let i=e.text?.(r);if(i!==void 0){let o=e.complete?.(r)??!1,a=JSON.stringify(i);if(n.push(`${JSON.stringify(r)}:${o?a:a.slice(0,-1)}`),!o)break;continue}let s=e.value?.(r);if(s===void 0)break;n.push(`${JSON.stringify(r)}:${JSON.stringify(s)}`)}return`{${n.join(",")}${e.closed?.()?"}":""}`}function kr(e){if(e.phase!=="preparing")return;let t=e.block.args;return t&&typeof t=="object"?t:void 0}function Ie(e,t=100){let n=e.useToolCallArgumentsPartial?.(),r=n===void 0?kr(e):void 0,[i,s]=(0,tt.useState)(()=>vn(r));return(0,tt.useEffect)(()=>{if(!r)return;let o=()=>s(l=>{let c=vn(r);return c===l?l:c});o();let a=setInterval(o,t);return()=>clearInterval(a)},[r,t]),n!==void 0?n:r?i:""}var wn=new Set([" "," ",`
|
|
7
|
+
`,"\r"]);function It(e){let t="";for(let n=0;n<e.length;n++){let r=e[n];if(r!=="\\"){t+=r;continue}let i=e[n+1];if(i===void 0)break;if(i==="u"){let o=e.slice(n+2,n+6);if(o.length<4||!/^[0-9a-fA-F]{4}$/.test(o))break;let a=parseInt(o,16);if(a>=55296&&a<=56319){let l=e.slice(n+6,n+12);if(!/^\\u[dD][c-fC-F][0-9a-fA-F]{2}$/.test(l)){if(l.length<6)break;t+=String.fromCharCode(a),n+=5;continue}t+=String.fromCharCode(a,parseInt(l.slice(2),16)),n+=11;continue}t+=String.fromCharCode(a),n+=5;continue}t+={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
8
|
+
`,r:"\r",t:" "}[i]??i,n+=1}return t}function Pt(e,t){for(let n=t+1;n<e.length;n++){let r=e[n];if(r==="\\"){n++;continue}if(r==='"')return n+1}return-1}function kn(e,t){let n=e[t];if(n==='"')return Pt(e,t);if(n==="{"||n==="["){let i=0;for(let s=t;s<e.length;s++){let o=e[s];if(o==='"'){let a=Pt(e,s);if(a<0)return-1;s=a-1;continue}if(o==="{"||o==="[")i++;else if((o==="}"||o==="]")&&(i--,i===0))return s+1}return-1}let r=t;for(;r<e.length&&!wn.has(e[r])&&e[r]!==","&&e[r]!=="}"&&e[r]!=="]";)r++;return r<e.length?r:-1}function re(e,t){for(;t<e.length&&wn.has(e[t]);)t++;return t}function jt(e){try{return{ok:!0,value:JSON.parse(e)}}catch{return{ok:!1}}}function Sr(e,t){let n=[],r=re(e,t+1);for(;;){if(r>=e.length)return{value:n,complete:!1,completeItems:n.length};if(e[r]==="]")return{value:n,complete:!0,completeItems:n.length};let i=kn(e,r);if(i<0){let o={value:n,complete:!1,completeItems:n.length};return e[r]==='"'&&(o.partialItem=It(e.slice(r+1))),o}let s=jt(e.slice(r,i));if(!s.ok)return{value:n,complete:!1,completeItems:n.length};n.push(s.value),r=re(e,i),e[r]===","&&(r=re(e,r+1))}}function Pe(e){let t={},n=re(e,0);if(e[n]!=="{")return t;for(n=re(e,n+1);n<e.length&&!(e[n]==="}"||e[n]!=='"');){let r=Pt(e,n);if(r<0)break;let i=It(e.slice(n+1,r-1));if(n=re(e,r),e[n]!==":"||(n=re(e,n+1),n>=e.length))break;let s=kn(e,n);if(s>=0){let a=jt(e.slice(n,s));if(!a.ok)break;let l={value:a.value,complete:!0};Array.isArray(a.value)&&(l.completeItems=a.value.length),t[i]=l,n=re(e,s),e[n]===","&&(n=re(e,n+1));continue}let o=e[n];o==='"'?t[i]={value:It(e.slice(n+1)),complete:!1}:o==="["?t[i]=Sr(e,n):t[i]={value:void 0,complete:!1};break}return t}function je(e){if(!e)return;let t=jt(e);if(!(!t.ok||typeof t.value!="object"||t.value===null||Array.isArray(t.value)))return t.value}var Sn=require("react");var rt=require("react"),nt=new Map,Tt=new Map;function At(e,t,n){let r=nt.get(e);if(!(r&&r.version>=t)){nt.set(e,{version:t,title:n??r?.title});for(let i of[...Tt.get(e)??[]])i()}}function it(e){let t=e??"",n=(0,rt.useCallback)(r=>{let i=Tt.get(t);return i||Tt.set(t,i=new Set),i.add(r),()=>{i.delete(r)}},[t]);return(0,rt.useSyncExternalStore)(n,()=>nt.get(t),()=>nt.get(t))}var ot="intelligent-ui",$r=new Set([Ee,ye,be]);function Nr(e,t){return t?!1:!(e&&typeof e=="object"&&e.ok===!1)}function Rt(e){let t=e&&typeof e=="object"?e.ui:void 0;if(!t||typeof t!="object")return;let n=t;return typeof n.uiId=="string"&&typeof n.version=="number"&&typeof n.root=="string"&&Array.isArray(n.components)?n:void 0}function Er(e,t,n){if(t.name===ye){let i=Rt(n);i&&At(i.uiId,i.version,i.title);return}if(t.name!==Ee)return;let r;try{let i=JSON.parse(t.argsRaw);r=typeof i.title=="string"?i.title:void 0}catch{}At(e,1,r)}var $n={kind:ot,match:e=>e.type==="turn/start"?{id:String(e.data.turn),role:"start"}:e.type==="tool/call"?{id:String(e.data.turn),role:"update"}:e.type==="tool/result"&&e.surfaceOp==="append"?{id:String(e.data.turn),role:"update"}:null,start:(e,t)=>{if(t.event.type!=="turn/start")throw new Error("intelligent-ui start requires turn/start");return{turn:t.event.data.turn,calls:new Map,results:[]}},update:(e,t)=>{let{event:n}=t;if(n.type==="tool/call"){if(!$r.has(n.data.name))return e.state;let a=new Map(e.state.calls);return a.set(String(n.data.callId),{name:n.data.name,argsRaw:n.data.arguments}),{...e.state,calls:a}}if(n.type!=="tool/result")return e.state;let r=n.data.message,i=String(r.source.callId),s=e.state.calls.get(i);if(!s||!Nr(n.data.meta,r.isError===!0))return e.state;Er(i,s,n.data.meta);let o={kind:"tool-result",callId:i,call:s,content:r.content,isError:!1,meta:n.data.meta,seq:n.seq};return{...e.state,results:[...e.state.results,o]}},buildLocationData:(e,t,n)=>t!=="turn"||e.state===void 0?null:n?.kind==="turn"&&n.turn===e.state.turn&&n.key===ot&&n.value.results===e.state.results?n:{kind:"turn",turn:e.state.turn,key:ot,value:{results:e.state.results}}};function Nn(e){let t=e.turn.data.get(ot);if(!t)return[];let n=e.turn.end?.seq??e.seq;return t.results.filter(r=>(r.seq??0)<=n)}var Ct=class{constructor(){H(this,"counts",new Map);H(this,"listeners",new Set);H(this,"version",0);H(this,"subscribe",t=>(this.listeners.add(t),()=>{this.listeners.delete(t)}));H(this,"snapshot",()=>this.version)}add(t){return this.counts.set(t,(this.counts.get(t)??0)+1),this.bump(),()=>{let n=(this.counts.get(t)??1)-1;n<=0?this.counts.delete(t):this.counts.set(t,n),this.bump()}}has(t){return this.counts.has(t)}bump(){this.version++;for(let t of[...this.listeners])t()}},Te=new Ct;function En(e){return(0,Sn.useSyncExternalStore)(Te.subscribe,Te.snapshot,Te.snapshot),Te.has(e)}function Ae(e){return e.phase==="start"?e.block.argsRaw:e.phase==="result"?e.block.call?.argsRaw??"":""}function de(e){return e.content.map(t=>t.type==="text"?t.text??"":"").join(`
|
|
9
|
+
`).trim()}function ce(e){return e.error?.code==="interrupted"}function xe(e){let t=e.meta;return!!t&&typeof t=="object"&&t.ok===!1}var G=require("react");var De=require("react"),Lt="diui:v1:",Or=1e5,On=200,Ut=new Map,_t=new Map;function Mn(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}function He(e){let t=Ut.get(e);if(t)return t;let n={};try{let r=Mn()?.getItem(Lt+e),i=r?JSON.parse(r):void 0;i&&typeof i=="object"&&!Array.isArray(i)&&(n=i.v??{})}catch{}return Ut.set(e,n),n}function Mr(e,t){let n=Mn();if(n)try{n.setItem(Lt+e,JSON.stringify({t:Date.now(),v:t})),Ir(n)}catch{}}function Ir(e){let t=[];for(let n=0;n<e.length;n++){let r=e.key(n);if(!r?.startsWith(Lt))continue;let i=0;try{i=JSON.parse(e.getItem(r)??"{}").t??0}catch{}t.push({key:r,t:i})}if(!(t.length<=On)){t.sort((n,r)=>n.t-r.t);for(let{key:n}of t.slice(0,t.length-On))e.removeItem(n)}}function st(e,t){return He(e)[t]}function at(e,t,n){let i={...He(e),[t]:n},s;try{s=JSON.stringify(i)}catch{return!1}if(s.length>Or)return!1;Ut.set(e,i),Mr(e,i);for(let o of[..._t.get(e)??[]])o();return!0}function Pr(e,t){let n=_t.get(e);return n||_t.set(e,n=new Set),n.add(t),()=>{n.delete(t)}}function ve(e,t,n){let r=e??"",i=(0,De.useCallback)(l=>Pr(r,l),[r]),s=(0,De.useSyncExternalStore)(i,()=>He(r)[t],()=>He(r)[t]),o=s===void 0?typeof n=="function"?n():n:s,a=(0,De.useCallback)(l=>{let c=He(r)[t]??(typeof n=="function"?n():n);at(r,t,typeof l=="function"?l(c):l)},[r,t]);return[o,a]}var Ft=require("react"),M=require("react/jsx-runtime"),U=["#4d6bfe","#22a06b","#f2a33a","#e5484d","#8e6cef","#12a5c4","#e0569b","#7fae2e","#f07a2e","#6b7a90","#1aa89a","#b25fe0"],ue=640,F={top:12,right:16,bottom:36,left:52};function lt(e,t,n=5){e===t&&(t=e+1,e=Math.min(0,e));let i=(t-e)/n,s=10**Math.floor(Math.log10(i)),o=[1,2,2.5,5,10].map(y=>y*s).find(y=>y>=i)??10*s,a=Math.floor(e/o)*o,l=Math.ceil(t/o)*o,c=[];for(let y=a;y<=l+o/2;y+=o)c.push(Number(y.toPrecision(12)));return c}function ee(e){let t=Math.abs(e);return t>=1e9?`${+(e/1e9).toFixed(1)}B`:t>=1e6?`${+(e/1e6).toFixed(1)}M`:t>=1e4?`${+(e/1e3).toFixed(1)}k`:String(+e.toFixed(2))}function In(e){let[t,n]=(0,Ft.useState)(new Set),[r,i]=(0,Ft.useState)(void 0),s=e.series.filter((c,y)=>!t.has(y)),o=e.labels.length;if(o===0||e.series.length===0)return(0,M.jsx)("div",{className:"diui-empty",children:e.emptyText});let a=e.height??260,l=(0,M.jsx)("div",{className:"diui-legend",children:e.series.map((c,y)=>(0,M.jsxs)("button",{type:"button",className:"diui-legend-item","data-off":t.has(y)||void 0,"aria-pressed":!t.has(y),onClick:()=>e.kind!=="pie"&&n(x=>{let v=new Set(x);return v.has(y)?v.delete(y):v.add(y),v}),children:[(0,M.jsx)("i",{style:{background:U[y%U.length]}}),c.name]},y))});return(0,M.jsxs)("figure",{className:"diui-chart",children:[e.title&&(0,M.jsx)("figcaption",{className:"diui-chart-title",children:e.title}),e.kind==="pie"?(0,M.jsx)(Tr,{...e,height:a}):(0,M.jsxs)("div",{className:"diui-plot-stage",children:[(0,M.jsx)(jr,{...e,series:s,height:a,colorOf:c=>U[e.series.indexOf(c)%U.length],n:o,hover:r,onHover:i}),r!==void 0&&s.length>0&&(0,M.jsxs)("div",{className:"diui-tooltip",style:{left:`${(F.left+(ue-F.left-F.right)/o*(r+.5))/ue*100}%`},children:[(0,M.jsx)("div",{className:"diui-tooltip-head",children:String(e.labels[r]??"")}),s.map(c=>(0,M.jsxs)("div",{children:[(0,M.jsx)("i",{style:{background:U[e.series.indexOf(c)%U.length]}}),c.name,": ",ee(c.values[r]??0),e.unit?` ${e.unit}`:""]},c.name))]})]}),e.kind!=="pie"&&e.series.length>1&&l,e.kind==="pie"&&(0,M.jsx)(Ar,{labels:e.labels,values:e.series[0]?.values??[],unit:e.unit})]})}function jr(e){let{series:t,n,height:r}=e,i=!!e.stacked&&(e.kind==="bar"||e.kind==="area"),s=0,o=0;for(let b=0;b<n;b++){let w=0,$=0;for(let E of t){let P=E.values[b]??0;i?P>=0?w+=P:$+=P:(o=Math.max(o,P),s=Math.min(s,P))}i&&(o=Math.max(o,w),s=Math.min(s,$))}let a=lt(s,o),l=a[0],c=a[a.length-1],y=ue-F.left-F.right,x=r-F.top-F.bottom,v=b=>F.top+x-(b-l)/(c-l)*x,m=y/n,p=b=>F.left+m*b+m/2,d=Math.max(1,Math.ceil(n/12)),k=e.unit?` ${e.unit}`:"",h=[];if(e.kind==="bar"){let b=m*.72,w=i?b:b/Math.max(1,t.length);for(let $=0;$<n;$++){let E=0,P=0;t.forEach((q,A)=>{let j=q.values[$]??0,g=0,N=j;i&&(j>=0?(g=E,N=E+j,E=N):(g=P,N=P+j,P=N));let T=F.left+m*$+(m-b)/2+(i?0:A*w),he=v(Math.max(g,N)),bt=Math.max(1,Math.abs(v(g)-v(N)));h.push((0,M.jsx)("rect",{x:T,y:he,width:Math.max(1,w-2),height:bt,rx:2,fill:e.colorOf(q),children:(0,M.jsx)("title",{children:`${String(e.labels[$])} · ${q.name}: ${j}${k}`})},`${A}-${$}`))})}}else{let b=new Array(n).fill(0);t.forEach((w,$)=>{let E=Array.from({length:n},(A,j)=>{let g=w.values[j]??0,N=i?b[j]+g:g;return{x:p(j),y:v(N),y0:v(i?b[j]:Math.max(l,Math.min(0,c))),v:g,i:j}});i&&E.forEach(A=>{b[A.i]=b[A.i]+A.v});let P=E.map((A,j)=>`${j?"L":"M"}${A.x.toFixed(1)},${A.y.toFixed(1)}`).join(""),q=e.colorOf(w);if(e.kind==="area"){let A=[...E].reverse().map(j=>`L${j.x.toFixed(1)},${j.y0.toFixed(1)}`).join("");h.push((0,M.jsx)("path",{d:`${P}${A}Z`,fill:q,opacity:.18},`a${$}`))}h.push((0,M.jsx)("path",{d:P,fill:"none",stroke:q,strokeWidth:2,strokeLinejoin:"round"},`l${$}`)),n<=60&&E.forEach(A=>h.push((0,M.jsx)("circle",{cx:A.x,cy:A.y,r:3,fill:q,children:(0,M.jsx)("title",{children:`${String(e.labels[A.i])} · ${w.name}: ${A.v}${k}`})},`p${$}-${A.i}`)))})}let S=b=>{let w=b.currentTarget.getBoundingClientRect();if(w.width<=0)return;let $=(b.clientX-w.left)/w.width*ue,E=Math.floor(($-F.left)/m);e.onHover(E>=0&&E<n?E:void 0)};return(0,M.jsxs)("svg",{className:"diui-chart-svg",viewBox:`0 0 ${ue} ${r}`,role:"img","aria-label":e.title??"chart",onPointerMove:S,onPointerLeave:()=>e.onHover(void 0),children:[e.hover!==void 0&&(0,M.jsx)("rect",{x:F.left+m*e.hover,y:F.top,width:m,height:x,className:"diui-hover-band"}),a.map(b=>(0,M.jsxs)("g",{children:[(0,M.jsx)("line",{x1:F.left,x2:ue-F.right,y1:v(b),y2:v(b),className:b===0?"diui-axis-zero":"diui-grid"}),(0,M.jsx)("text",{x:F.left-6,y:v(b),dy:"0.32em",textAnchor:"end",className:"diui-tick",children:ee(b)})]},b)),e.labels.map((b,w)=>w%d===0&&(0,M.jsx)("text",{x:p(w),y:r-F.bottom+16,textAnchor:"middle",className:"diui-tick",children:Cr(String(b??""),14)},w)),h]})}function Tr(e){let t=(e.series[0]?.values??[]).map(c=>Math.max(0,c)),n=t.reduce((c,y)=>c+y,0);if(n<=0)return(0,M.jsx)("div",{className:"diui-empty",children:e.emptyText});let r=e.height,i=Math.min(r/2-8,120),s=ue/2,o=r/2,a=-Math.PI/2,l=e.unit?` ${e.unit}`:"";return(0,M.jsx)("svg",{className:"diui-chart-svg",viewBox:`0 0 ${ue} ${r}`,role:"img","aria-label":e.title??"chart",children:t.map((c,y)=>{let x=a,v=a+c/n*Math.PI*2;a=v;let m=v-x>Math.PI?1:0,p=[s+i*Math.cos(x),o+i*Math.sin(x)],d=[s+i*Math.cos(v),o+i*Math.sin(v)],k=t.filter(h=>h>0).length===1?`M${s-i},${o}a${i},${i} 0 1,0 ${2*i},0a${i},${i} 0 1,0 ${-2*i},0`:`M${s},${o}L${p[0].toFixed(1)},${p[1].toFixed(1)}A${i},${i} 0 ${m} 1 ${d[0].toFixed(1)},${d[1].toFixed(1)}Z`;return(0,M.jsx)("path",{d:k,fill:U[y%U.length],className:"diui-slice",children:(0,M.jsx)("title",{children:`${String(e.labels[y])}: ${c}${l} (${(c/n*100).toFixed(1)}%)`})},y)})})}function Ar(e){let t=e.values.reduce((n,r)=>n+Math.max(0,r),0)||1;return(0,M.jsx)("div",{className:"diui-legend",children:e.labels.map((n,r)=>(0,M.jsxs)("span",{className:"diui-legend-item",children:[(0,M.jsx)("i",{style:{background:U[r%U.length]}}),String(n)," · ",((e.values[r]??0)/t*100).toFixed(1),"%"]},r))})}function Cr(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}var Pn=require("react"),X=require("react/jsx-runtime"),Rr=/(\*\*[^*\n]+\*\*|`[^`\n]+`|\[[^\]\n]+\]\([^)\s]+\)|\*[^*\n]+\*|_[^_\n]+_)/g;function Ur(e){try{let t=new URL(e);return t.protocol==="https:"||t.protocol==="http:"?t.href:void 0}catch{return}}function _r(e,t){let n=[],r=0,i=0;for(let s of e.matchAll(Rr)){let o=s[0],a=s.index??0;a>r&&n.push(e.slice(r,a));let l=`${t}-${i++}`;if(o.startsWith("**"))n.push((0,X.jsx)("strong",{children:o.slice(2,-2)},l));else if(o.startsWith("`"))n.push((0,X.jsx)("code",{className:"diui-code-inline",children:o.slice(1,-1)},l));else if(o.startsWith("[")){let c=o.indexOf("]("),y=o.slice(1,c),x=Ur(o.slice(c+2,-1));n.push(x?(0,X.jsx)("a",{href:x,target:"_blank",rel:"noopener noreferrer",children:y},l):y)}else n.push((0,X.jsx)("em",{children:o.slice(1,-1)},l));r=a+o.length}return r<e.length&&n.push(e.slice(r)),n}function fe(e){let t=e.text.split(`
|
|
10
|
+
`);return(0,X.jsx)(X.Fragment,{children:t.map((n,r)=>(0,X.jsxs)(Pn.Fragment,{children:[r>0&&(0,X.jsx)("br",{}),_r(n,String(r))]},r))})}var Fn=require("react");var jn='var Idiomorph=function(){"use strict";const e=()=>{};const n={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:e=>e.getAttribute("im-preserve")==="true",shouldReAppend:e=>e.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},restoreFocus:true};function t(e,t,n={}){const o=u(e);const r=f(t);const i=d(o,r,n);return c(i,o,r,e=>{const t=a(e,()=>{if(e.morphStyle==="innerHTML"){s(e,o,r);return Array.from(o.childNodes)}else{return l(e,o,r)}});e.pantry.remove();return t})}function l(e,t,n){const o=f(t);s(e,o,n,t,t.nextSibling);return Array.from(o.childNodes)}function a(e,t){if(!e.config.restoreFocus)return t();let n=e.doc.activeElement;if(!(g.inputElement(n)||g.textAreaElement(n))){return t()}const{id:o,selectionStart:r,selectionEnd:i}=n;const l=t();if(o&&o!==e.doc.activeElement?.getAttribute("id")){n=e.target.querySelector(`[id="${CSS.escape(o)}"]`);n?.focus()}if(n&&!n.selectionEnd&&i){try{n.setSelectionRange(r,i)}catch{}}return l}const s=function(){function e(e,t,n,o=null,r=null){if(g.templateElement(t)&&g.templateElement(n)){t=t.content;n=n.content}o||=t.firstChild;for(const i of n.childNodes){if(o&&o!=r){const a=f(e,i,o,r);if(a){if(a!==o){m(e,o,a)}b(a,i,e);o=a.nextSibling;continue}}if(g.element(i)){const s=i.getAttribute("id");if(e.persistentIds.has(s)){const c=p(t,s,o,e);b(c,i,e);o=c.nextSibling;continue}}const l=u(t,i,o,e);if(l){o=l.nextSibling}}while(o&&o!=r){const d=o;o=o.nextSibling;h(e,d)}}function u(e,t,n,o){if(o.callbacks.beforeNodeAdded(t)===false)return null;if(o.idMap.has(t)){const r=o.doc.createElementNS(t.namespaceURI,t.localName);e.insertBefore(r,n);b(r,t,o);o.callbacks.afterNodeAdded(r);return r}else{const i=o.doc.importNode(t,true);e.insertBefore(i,n);o.callbacks.afterNodeAdded(i);return i}}const f=function(){function e(e,t,n,o){let r=null;let i=t.nextSibling;let l=0;let a=n;while(a&&a!=o){if(c(a,t)){if(s(e,a,t)){return a}if(r===null){if(!e.idMap.has(a)){r=a}}}if(r===null&&i&&c(a,i)){l++;i=i.nextSibling;if(l>=2){r=undefined}}if(e.activeElementAndParents.includes(a))break;a=a.nextSibling}return r||null}function s(e,t,n){let o=e.idMap.get(t);let r=e.idMap.get(n);if(!r||!o)return false;for(const i of o){if(r.has(i)){return true}}return false}function c(e,t){const n=e;const o=t;return n.nodeType===o.nodeType&&n.tagName===o.tagName&&(!n.getAttribute?.("id")||n.getAttribute?.("id")===o.getAttribute?.("id"))}return e}();function h(e,t){if(t===e.pantry)return;if(e.idMap.has(t)){a(e.pantry,t,null)}else{if(e.callbacks.beforeNodeRemoved(t)===false)return;t.parentNode?.removeChild(t);e.callbacks.afterNodeRemoved(t)}}function m(t,e,n){let o=e;while(o&&o!==n){let e=o;o=o.nextSibling;h(t,e)}return o}function p(e,t,n,o){const r=`[id="${CSS.escape(t)}"]`;const i=o.target.getAttribute?.("id")===t&&o.target||o.target.querySelector(r)||o.pantry.querySelector(r);l(i,o);a(e,i,n);return i}function l(t,n){const o=t.getAttribute("id");while(t=t.parentNode){let e=n.idMap.get(t);if(e){e.delete(o);if(!e.size){n.idMap.delete(t)}}}}function a(t,n,o){if(t.moveBefore){try{t.moveBefore(n,o)}catch(e){t.insertBefore(n,o)}}else{t.insertBefore(n,o)}}return e}();const b=function(){function e(e,t,n){if(n.ignoreActive&&e===n.doc.activeElement){return null}if(n.callbacks.beforeNodeMorphed(e,t)===false){return e}if(g.headElement(e)&&n.head.style==="none"){}else if(g.headElement(e)&&n.head.style!=="morph"){h(e,t,n)}else{o(e,t,n);if(!f(e,n)){s(n,e,t)}}n.callbacks.afterNodeMorphed(e,t);return e}function o(e,t,n){let o=t.nodeType;if(o===1){const r=e;const i=t;const l=r.attributes;const a=i.attributes;for(const s of a){if(r.getAttribute(s.name)===s.value){continue}if(u(s.name,r,"update",n)){continue}r.setAttributeNode(s.cloneNode())}for(let e=l.length-1;0<=e;e--){const c=l[e];if(!c)continue;if(!i.hasAttribute(c.name)){if(u(c.name,r,"remove",n)){continue}r.removeAttribute(c.name)}}if(!f(r,n)){d(r,i,n)}}if(o===8||o===3){if(e.nodeValue!==t.nodeValue){e.nodeValue=t.nodeValue}}}function d(n,o,r){if(g.inputElement(n)&&g.inputElement(o)&&o.type!=="file"){let e=o.value;let t=n.value;i(n,o,"checked",r);i(n,o,"disabled",r);if(!o.hasAttribute("value")){if(!u("value",n,"remove",r)){n.value="";n.removeAttribute("value")}}else if(t!==e){if(!u("value",n,"update",r)){n.setAttribute("value",e);n.value=e}}}else if(g.optionElement(n)&&g.optionElement(o)){i(n,o,"selected",r)}else if(g.textAreaElement(n)&&g.textAreaElement(o)){let e=o.value;let t=n.value;if(u("value",n,"update",r)){return}if(e!==t){n.value=e}if(n.firstChild&&n.firstChild.nodeValue!==e){n.firstChild.nodeValue=e}}}function i(e,t,n,o){const r=t[n],i=e[n];if(r!==i){const l=u(n,e,"update",o);if(!l){e[n]=t[n]}if(r){if(!l){e.setAttribute(n,"")}}else{if(!u(n,e,"remove",o)){e.removeAttribute(n)}}}}function u(e,t,n,o){if(e==="value"&&o.ignoreActiveValue&&t===o.doc.activeElement){return true}return o.callbacks.beforeAttributeUpdated(e,t,n)===false}function f(e,t){return!!t.ignoreActiveValue&&e===t.doc.activeElement&&e!==t.doc.body}return e}();function c(t,e,n,o){if(t.head.block&&t.head.style!=="none"){const r=e.querySelector("head");const i=n.querySelector("head");if(r&&i){const l=h(r,i,t);return Promise.all(l).then(()=>{const e=Object.assign(t,{head:{block:false,style:"none"}});return o(e)})}}return o(t)}function h(e,t,o){let r=[];let i=[];let l=[];let a=[];let s=new Map;for(const n of t.children){s.set(n.outerHTML,n)}for(const d of e.children){let e=s.has(d.outerHTML);let t=o.head.shouldReAppend(d);let n=o.head.shouldPreserve(d);if(e||n){if(t){i.push(d)}else{s.delete(d.outerHTML);l.push(d)}}else{if(o.head.style==="append"){if(t){i.push(d);a.push(d)}}else{if(o.head.shouldRemove(d)!==false){i.push(d)}}}}a.push(...s.values());let c=[];for(const u of a){let n=o.doc.createRange().createContextualFragment(u.outerHTML).firstChild;if(o.callbacks.beforeNodeAdded(n)!==false){if("href"in n&&n.href||"src"in n&&n.src){let t;let e=new Promise(function(e){t=e});n.addEventListener("load",function(){t()});c.push(e)}e.appendChild(n);o.callbacks.afterNodeAdded(n);r.push(n)}}for(const f of i){if(o.callbacks.beforeNodeRemoved(f)!==false){e.removeChild(f);o.callbacks.afterNodeRemoved(f)}}o.head.afterHeadMorphed(e,{added:r,kept:l,removed:i});return c}const d=function(){function e(e,t,n){const{persistentIds:o,idMap:r}=f(e,t);const i=c(n);const l=i.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(l)){throw`Do not understand how to morph style ${l}`}if(l==="innerHTML"&&!e.append){throw`Cannot morph the innerHTML of a ${e.nodeName} node, as it cannot have children`}const a=i.head.style||"merge";if(!["merge","append","morph","none"].includes(a)){throw`Do not understand how to morph head style ${a}`}const s=e.ownerDocument;return{target:e,newContent:t,doc:s,config:i,morphStyle:l,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,restoreFocus:i.restoreFocus,idMap:r,persistentIds:o,pantry:d(s),activeElementAndParents:u(e,s),callbacks:i.callbacks,head:i.head}}function c(e){let t=Object.assign({},n);Object.assign(t,e);t.callbacks=Object.assign({},n.callbacks,e.callbacks);t.head=Object.assign({},n.head,e.head);return t}function d(e){const t=e.createElement("div");t.hidden=true;e.documentElement.append(t);return t}function u(e,t){let n=[];let o=t.activeElement;if(o?.tagName!=="BODY"&&e.contains(o)){while(o){n.push(o);if(o===e)break;o=o.parentElement}}return n}function a(e){let t=[];const n=e;for(const r of n.querySelectorAll?.("[id]")??[]){const i=r.getAttribute("id");if(i)t.push({elt:r,id:i})}const o=n.getAttribute?.("id");if(o)t.push({elt:e,id:o});return t}function s(n,e,o,t){for(const{elt:r,id:i}of t){if(e.has(i)){let t=r;while(t){let e=n.get(t);if(e==null){e=new Set;n.set(t,e)}e.add(i);if(t===o)break;t=t.parentElement}}}}function f(e,t){const n=a(e);const o=a(t);const r=h(n,o);let i=new Map;s(i,r,e,n);const l=t.__idiomorphRoot||t;s(i,r,l,o);return{persistentIds:r,idMap:i}}function h(e,t){let n=new Set;let o=new Map;for(const{elt:i,id:l}of e){if(o.has(l)){n.add(l)}else{o.set(l,i.tagName)}}let r=new Set;for(const{elt:i,id:l}of t){if(r.has(l)){n.add(l)}else if(o.get(l)===i.tagName){r.add(l)}}for(const l of n){r.delete(l)}if(n.size){console.warn("[Warning] duplicate ids found during morph, state loss within these elements is possible:",Array.from(n))}return r}return e}();const{normalizeElement:u,normalizeParent:f}=function(){const r=new WeakSet;function e(e){if(g.document(e)){return e.documentElement}else{return e}}function o(e){if(e==null){return document.createElement("div")}else if(typeof e==="string"){return o(l(e))}else if(r.has(e)){return e}else if(g.node(e)){if(e.parentNode){return new i(e)}else{const t=document.createElement("div");t.append(e);return t}}else{const t=document.createElement("div");for(const n of[...e]){t.append(n)}return t}}class i{constructor(e){this.originalNode=e;this.realParentNode=e.parentNode;this.previousSibling=e.previousSibling;this.nextSibling=e.nextSibling}get childNodes(){const e=[];let t=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;while(t&&t!=this.nextSibling){e.push(t);t=t.nextSibling}return e}querySelectorAll(o){return this.childNodes.reduce((t,e)=>{if(g.element(e)){if(e.matches(o))t.push(e);const n=e.querySelectorAll(o);for(let e=0;e<n.length;e++){t.push(n[e])}}return t},[])}insertBefore(e,t){return this.realParentNode.insertBefore(e,t)}moveBefore(e,t){return this.realParentNode.moveBefore(e,t)}get __idiomorphRoot(){return this.originalNode}}function l(n){let o=new DOMParser;let e=n.replace(/<svg(\\s[^>]*>|>)([\\s\\S]*?)<\\/svg>/gim,"");if(e.match(/<\\/html>/)||e.match(/<\\/head>/)||e.match(/<\\/body>/)){let t=o.parseFromString(n,"text/html");t.doctype?.remove();if(e.match(/<\\/html>/)){r.add(t);return t}else{let e=t.firstChild;if(e){r.add(e)}return e}}else{let e=o.parseFromString("<body><template>"+n+"</template></body>","text/html");let t=e.body.querySelector("template").content;r.add(t);return t}}return{normalizeElement:e,normalizeParent:o}}();const g=function(){const n=e=>e instanceof Element||e?.nodeType===Node.ELEMENT_NODE;const t=(e,t)=>n(e)&&e.localName===t&&e.namespaceURI==="http://www.w3.org/1999/xhtml";return{element:n,node:e=>e instanceof Node||typeof e?.nodeType==="number",document:e=>e instanceof Document||e?.nodeType===Node.DOCUMENT_NODE,templateElement:e=>t(e,"template"),headElement:e=>t(e,"head"),inputElement:e=>t(e,"input"),optionElement:e=>t(e,"option"),textAreaElement:e=>t(e,"textarea")}}();return{morph:t,defaults:n}}();';var Lr={three:"https://esm.sh/three@0.169.0","three/addons/":"https://esm.sh/three@0.169.0/examples/jsm/",d3:"https://esm.sh/d3@7.9.0","chart.js/auto":"https://esm.sh/chart.js@4.4.4/auto",gsap:"https://esm.sh/gsap@3.12.5","canvas-confetti":"https://esm.sh/canvas-confetti@1.9.3"};function dt(e){let t=[];for(let n of e)try{let r=new URL(n);r.protocol==="https:"&&r.origin!=="null"&&t.push(r.origin)}catch{}return[...new Set(t)]}function Fr(e){let t=dt(e.cdn).join(" "),n=e.allowNetwork&&t?t:"'none'";return["default-src 'none'",`script-src 'unsafe-inline' 'unsafe-eval' blob: ${t}`.trim(),`style-src 'unsafe-inline' ${t}`.trim(),`img-src data: blob: ${t}`.trim(),`font-src data: ${t}`.trim(),`media-src data: blob: ${t}`.trim(),`connect-src ${n}`,"worker-src blob:","form-action 'none'","base-uri 'none'"].join("; ")}function zt(e,t){return e.replace(new RegExp(`</(${t})`,"gi"),"<\\/$1")}var zr=new RegExp("[\u2028\u2029]","g");function Tn(e){return JSON.stringify(e).replace(/</g,"\\u003c").replace(zr,t=>"\\u"+t.charCodeAt(0).toString(16))}function Ht(e){let t=Object.entries(e).filter(([r,i])=>/^--ui-[a-z-]+$/.test(r)&&!/[;{}<]/.test(i)).map(([r,i])=>`${r}:${i};`).join(""),n=e["--ui-scheme"]==="dark"?"dark":"light";return`:root{${t}color-scheme:${n};}`}function Dt(e){return e["--ui-scheme"]==="dark"?"dark":"light"}var Hr=`
|
|
11
11
|
*,*::before,*::after{box-sizing:border-box}
|
|
12
12
|
html,body{margin:0;padding:0;background:transparent;color:var(--ui-text);font:14px/1.5 var(--ui-font);-webkit-font-smoothing:antialiased}
|
|
13
13
|
#ui-root{padding:12px}
|
|
@@ -37,7 +37,7 @@ svg,canvas,img,video{max-width:100%}
|
|
|
37
37
|
.ui-stage{position:relative;width:100%;height:360px;border-radius:var(--ui-radius);overflow:hidden;background:var(--ui-surface);touch-action:none}
|
|
38
38
|
.ui-stage canvas{display:block;width:100%;height:100%}
|
|
39
39
|
@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}}
|
|
40
|
-
|
|
40
|
+
`,Dr=`
|
|
41
41
|
(function(){
|
|
42
42
|
var TOKEN = __TOKEN__, MAX = __MAX__, seq = 0, pending = {}, finalized = false;
|
|
43
43
|
var doc = document.documentElement;
|
|
@@ -255,15 +255,15 @@ svg,canvas,img,video{max-width:100%}
|
|
|
255
255
|
}
|
|
256
256
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); else boot();
|
|
257
257
|
})();
|
|
258
|
-
`;function
|
|
258
|
+
`;function qt(e){return{functions:e.jsFunctions??"",expressions:e.jsExpressions??[],state:e.state??null}}function An(e){let n=dt(e.policy.cdn).includes("https://esm.sh")?Lr:{},r=Dr.replace("__TOKEN__",JSON.stringify(e.token)).replace("__MAX__",String(Math.max(50,Math.floor(e.policy.maxHeight)))).replace("__SCHEME__",JSON.stringify(Dt(e.theme))),i=e.mode==="final"?`<script type="application/json" id="ui-code">${Tn(qt(e))}<\/script>`:"";return['<!doctype html><html><head><meta charset="utf-8">',`<meta http-equiv="Content-Security-Policy" content="${Fr(e.policy).replace(/"/g,""")}">`,'<meta name="viewport" content="width=device-width,initial-scale=1">',Object.keys(n).length?`<script type="importmap">${Tn({imports:n})}<\/script>`:"",`<style id="ui-theme">${zt(Ht(e.theme),"style")}</style>`,`<style>${Hr}</style>`,`<style id="ui-css">${zt(e.css,"style")}</style>`,`<script>${zt(jn,"script")}<\/script>`,`<script>${r}<\/script>`,"</head><body>",`<div id="ui-root">${e.html}</div>`,i,"</body></html>"].join("")}var _=require("react");var qr=[["--ui-bg",["--dsw-alias-bg-base"],"#ffffff","#151517"],["--ui-surface",["--dsw-alias-bg-module-platform","--dsw-alias-bg-layer-1"],"#f5f6f7","#232324",["--dsw-alias-bg-layer-1"]],["--ui-text",["--dsw-alias-label-primary"],"#0f1115","#f9fafb"],["--ui-muted",["--dsw-alias-label-tertiary","--dsw-alias-label-secondary"],"#81858c","#adb2b8"],["--ui-border",["--dsw-alias-border-l2","--dsw-alias-border-l1"],"#0000001a","#ffffff1f"],["--ui-accent",["--dsw-alias-state-business-primary","--dsw-alias-brand-primary"],"#4176e6","#7aaaff"],["--ui-accent-text",["--dsw-alias-label-primary-inverted"],"#ffffff","#151517"],["--ui-success",["--dsw-alias-state-success-primary"],"#22c55e","#22c55e"],["--ui-warning",["--dsw-alias-state-warn-primary"],"#f59e0b","#f59e0b"],["--ui-error",["--dsw-alias-state-error-primary"],"#ec1313","#f25a5a"],["--ui-radius",["--dsw-radius-sm"],"8px","8px"],["--ui-font",["--dsw-font-family","--ds-font-family-sans"],'system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif','system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif'],["--ui-mono",["--ds-font-family-code"],"ui-monospace, SFMono-Regular, Consolas, monospace","ui-monospace, SFMono-Regular, Consolas, monospace"]];function Br(e){let t=/^#([0-9a-f]{6})/i.exec(e)??/^#([0-9a-f]{3})\b/i.exec(e);if(t){let r=t[1].length===3?t[1].split("").map(a=>a+a).join(""):t[1],[i,s,o]=[0,2,4].map(a=>parseInt(r.slice(a,a+2),16));return .299*i+.587*s+.114*o<128}let n=/rgba?\((\d+)[ ,]+(\d+)[ ,]+(\d+)/.exec(e);if(n)return .299*+n[1]+.587*+n[2]+.114*+n[3]<128}function Vr(e=document){let t=getComputedStyle(e.documentElement).colorScheme||"";if(/\bdark\b/.test(t)&&!/\blight\b/.test(t))return!0;if(/\blight\b/.test(t)&&!/\bdark\b/.test(t))return!1;let n=getComputedStyle(e.body??e.documentElement),r=Br(n.getPropertyValue("--dsw-alias-bg-base").trim());return r!==void 0?r:typeof matchMedia=="function"&&matchMedia("(prefers-color-scheme: dark)").matches}function Bt(e=document){let t=getComputedStyle(e.body??e.documentElement),n=Vr(e),r={};for(let[i,s,o,a,l]of qr){let c="";for(let y of n&&l?l:s)if(c=t.getPropertyValue(y).trim(),c)break;r[i]=c||(n?a:o)}return r["--ui-scheme"]=n?"dark":"light",r}function Cn(e,t=document){let n=new MutationObserver(e),r=["class","style","data-theme","data-color-scheme","data-ds-theme","data-ds-theme-source"];n.observe(t.documentElement,{attributes:!0,attributeFilter:r}),t.body&&n.observe(t.body,{attributes:!0,attributeFilter:r});let i=typeof matchMedia=="function"?matchMedia("(prefers-color-scheme: dark)"):void 0;return i?.addEventListener?.("change",e),()=>{n.disconnect(),i?.removeEventListener?.("change",e)}}var Wr=/<(script|style|head)\b[^>]*>[\s\S]*?(<\/\1\s*>|$)/gi;function Vt(e){let t=e,n=t.lastIndexOf("<!--");n>=0&&t.indexOf("-->",n)<0&&(t=t.slice(0,n));let r=t.lastIndexOf("<");return r>=0&&t.indexOf(">",r)<0&&(t=t.slice(0,r)),t=t.replace(/&[#a-zA-Z0-9]{0,10}$/,""),t=t.replace(Wr,""),t=t.replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi,""),t}var _n=require("react/jsx-runtime"),Rn=new Map;function Jr(){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function ct(e){let t=(0,_.useRef)(null),n=(0,_.useMemo)(Jr,[]),r=e.persist!==!1,i=(0,_.useRef)(Bt()),[s,o]=(0,_.useState)(()=>Rn.get(e.callId)??(r?st(e.callId,"height"):void 0)??Un(e.initialHeight??160,e.policy.maxHeight)),a=(0,_.useRef)(!1),l=(0,_.useRef)(!1),c=(0,_.useRef)([]),y=JSON.stringify(e.policy),x=(0,_.useMemo)(()=>e.policy,[y]),v=(0,_.useMemo)(()=>new ae({policy:x}),[x]),m=(0,_.useRef)(e);m.current=e;let p=(0,_.useMemo)(()=>{let h=m.current;return l.current=h.mode==="final",a.current=!1,c.current=[],An({token:n,mode:h.mode,css:h.css,html:h.mode==="final"?h.html:"",jsFunctions:h.jsFunctions,jsExpressions:h.jsExpressions,theme:i.current,policy:x,state:h.mode==="final"&&r?st(h.callId,"widget"):void 0})},[n,e.css,x,e.generation]),d=h=>{t.current?.contentWindow?.postMessage({...h,__diui:n},"*")},k=()=>{let h=m.current;l.current||!a.current||h.mode!=="final"||(l.current=!0,d({type:"final",html:h.html,code:qt({jsFunctions:h.jsFunctions,jsExpressions:h.jsExpressions,state:r?st(h.callId,"widget"):void 0})}))};return(0,_.useEffect)(()=>Cn(()=>{let h=Bt();JSON.stringify(h)!==JSON.stringify(i.current)&&(i.current=h,d({type:"theme",css:Ht(h),scheme:Dt(h)}))}),[n]),(0,_.useEffect)(()=>{e.mode==="preview"?a.current&&!l.current&&d({type:"html",html:Vt(e.html)}):k()},[e.html,e.mode]),(0,_.useEffect)(()=>{let h=b=>{let w=t.current;if(!w||b.source!==w.contentWindow)return;let $=mn(b.data,n);if(!$)return;let E=m.current;switch($.type){case"ready":a.current=!0,$.final||(E.mode==="preview"?d({type:"html",html:Vt(E.html)}):k());break;case"resize":{let P=Un($.height,E.policy.maxHeight);Rn.set(E.callId,P),r&&l.current&&at(E.callId,"height",P),o(P);break}case"state":r&&l.current&&at(E.callId,"widget",$.state);break;case"error":l.current&&(c.current=[...c.current,`${$.kind}: ${$.message}`].slice(-20),E.onErrors?.(c.current));break;case"rpc":S($.id,$.method,$.params);break}},S=async(b,w,$)=>{let E=m.current;try{if(!l.current||E.mode!=="final")throw new J("unavailable","the widget is still generating");if(w==="sendPrompt"){let P=v.admitPrompt($.text);E.onSending?.(!0);try{await E.sendPrompt(P)}finally{E.onSending?.(!1)}E.onSent?.(!0),d({type:"rpc-result",id:b,ok:!0,value:{accepted:!0}})}else if(w==="openLink"){let P=v.admitLink($.url);window.open(P,"_blank","noopener,noreferrer"),d({type:"rpc-result",id:b,ok:!0,value:{opened:!0}})}else throw new J("unavailable",`unknown bridge method ${w}`)}catch(P){let q=P instanceof Error?P.message:String(P);w==="sendPrompt"&&E.onSent?.(!1,q),d({type:"rpc-result",id:b,ok:!1,error:q})}};return window.addEventListener("message",h),()=>window.removeEventListener("message",h)},[n,v]),(0,_n.jsx)("iframe",{ref:t,className:"diui-frame",title:e.title,sandbox:"allow-scripts allow-forms",referrerPolicy:"no-referrer",srcDoc:p,style:{height:s},"data-mode":e.mode})}function Un(e,t){return Math.max(50,Math.min(t,Math.round(e)))}var ut=require("react/jsx-runtime"),Ce="0.16.11",Wt="11.4.1",Ln={"https://cdn.jsdelivr.net":{katexJs:`https://cdn.jsdelivr.net/npm/katex@${Ce}/dist/katex.mjs`,katexCss:`https://cdn.jsdelivr.net/npm/katex@${Ce}/dist/katex.min.css`,mermaid:`https://cdn.jsdelivr.net/npm/mermaid@${Wt}/dist/mermaid.esm.min.mjs`},"https://unpkg.com":{katexJs:`https://unpkg.com/katex@${Ce}/dist/katex.mjs`,katexCss:`https://unpkg.com/katex@${Ce}/dist/katex.min.css`,mermaid:`https://unpkg.com/mermaid@${Wt}/dist/mermaid.esm.min.mjs`},"https://esm.sh":{katexJs:`https://esm.sh/katex@${Ce}`,katexCss:`https://esm.sh/katex@${Ce}/dist/katex.min.css`,mermaid:`https://esm.sh/mermaid@${Wt}`}};function Kr(e){let t=dt(e.cdn),n=Object.keys(Ln).find(r=>t.includes(r));return n?Ln[n]:void 0}function Gr(e,t,n,r){let i='function fallback(e){var r=document.getElementById("out");r.className="src";r.textContent=SRC;if(e)console.warn(e)}';return e==="math"?{css:`@import url(${JSON.stringify(r.katexCss)});#ui-root{padding:4px 2px;overflow-x:auto}#out{color:var(--ui-text);font-size:1.12em}#out.inline{display:inline-block}.src{font-family:var(--ui-mono);white-space:pre-wrap;color:var(--ui-muted)}.katex-display{margin:.4em 0}`,html:`<div id="out" class="${n.display===!1?"inline":""}"></div>`,js:`var SRC=${JSON.stringify(t)};${i}
|
|
259
259
|
function render(){import(${JSON.stringify(r.katexJs)}).then(function(m){var k=m.default||m;k.render(SRC,document.getElementById("out"),{displayMode:${n.display!==!1},throwOnError:false,output:"htmlAndMathml"})}).catch(fallback)}`}:{css:"#ui-root{padding:8px;overflow-x:auto}#out{display:flex;justify-content:center}#out svg{max-width:100%;height:auto}.src{font-family:var(--ui-mono);white-space:pre-wrap;color:var(--ui-muted);display:block}",html:'<div id="out" role="img"></div>',js:`var SRC=${JSON.stringify(t)},n=0;${i}
|
|
260
260
|
function render(){import(${JSON.stringify(r.mermaid)}).then(function(m){var mm=m.default||m;function draw(){mm.initialize({startOnLoad:false,securityLevel:"strict",theme:UI.scheme==="dark"?"dark":"default",fontFamily:UI.css("font")});return mm.render("m"+(++n),SRC).then(function(r){document.getElementById("out").innerHTML=r.svg})}
|
|
261
|
-
UI.onTheme(function(){draw().catch(fallback)});return draw()}).catch(fallback)}`}}function
|
|
262
|
-
`),children:t.t("node.invalid",{id:e,type:i.type})},e);let o=new Set(r).add(e),s=Ce[i.type]?.children?(i.children??[]).map(l=>It(l,t,n+1,o)):[];return(0,f.jsx)(Fr,{node:i,env:t,children:s},e)}function Fr({node:e,env:t,children:n}){let r=e.props??{};switch(e.type){case"Card":return(0,f.jsxs)("section",{className:"diui-card",children:[(r.title||r.subtitle)&&(0,f.jsxs)("header",{className:"diui-card-head",children:[r.title&&(0,f.jsx)("h3",{className:"diui-card-title",children:r.title}),r.subtitle&&(0,f.jsx)("p",{className:"diui-card-subtitle",children:r.subtitle})]}),(0,f.jsx)("div",{className:"diui-stack",style:{gap:10},children:n}),r.footer&&(0,f.jsx)("footer",{className:"diui-card-foot",children:(0,f.jsx)(se,{text:r.footer})})]});case"Stack":return(0,f.jsx)("div",{className:"diui-stack","data-direction":r.direction??"vertical",style:{gap:r.gap??10,flexWrap:r.wrap?"wrap":void 0,alignItems:Lr(r.align)},children:n});case"Grid":return(0,f.jsx)("div",{className:"diui-grid",style:{"--diui-cols":Math.round(r.columns)},children:n});case"Tabs":return(0,f.jsx)(_r,{labels:r.labels,env:t,nodeId:e.id,children:n});case"Text":{let i=r.variant==="title"?"h2":r.variant==="heading"?"h4":"p";return(0,f.jsx)(i,{className:"diui-text","data-variant":r.variant??"body","data-tone":r.tone??"default",children:(0,f.jsx)(se,{text:r.text})})}case"Code":return(0,f.jsx)("pre",{className:"diui-code","data-language":r.language,children:(0,f.jsx)("code",{children:r.code})});case"Alert":return(0,f.jsxs)("div",{className:"diui-alert","data-tone":r.tone??"info",role:"note",children:[r.title&&(0,f.jsx)("strong",{className:"diui-alert-title",children:r.title}),(0,f.jsx)("div",{children:(0,f.jsx)(se,{text:r.text})})]});case"Badge":return(0,f.jsx)("span",{className:"diui-badge","data-tone":r.tone??"default",children:r.text});case"Divider":return(0,f.jsx)("hr",{className:"diui-divider"});case"Stat":return(0,f.jsxs)("div",{className:"diui-stat",children:[(0,f.jsx)("div",{className:"diui-stat-label",children:r.label}),(0,f.jsx)("div",{className:"diui-stat-value",children:String(r.value??"")}),r.delta&&(0,f.jsxs)("div",{className:"diui-stat-delta","data-trend":r.trend??"flat",children:[r.trend==="up"?"▲ ":r.trend==="down"?"▼ ":"",r.delta]}),r.hint&&(0,f.jsx)("div",{className:"diui-stat-hint",children:r.hint})]});case"Progress":{let i=r.max&&r.max>0?r.max:100,a=Math.max(0,Math.min(100,r.value/i*100));return(0,f.jsxs)("div",{className:"diui-progress","data-tone":r.tone??"default",children:[r.label&&(0,f.jsxs)("div",{className:"diui-progress-label",children:[(0,f.jsx)("span",{children:r.label}),(0,f.jsxs)("span",{children:[Math.round(a),"%"]})]}),(0,f.jsx)("div",{className:"diui-progress-track",role:"progressbar","aria-valuenow":r.value,"aria-valuemin":0,"aria-valuemax":i,children:(0,f.jsx)("div",{className:"diui-progress-bar",style:{width:`${a}%`}})})]})}case"List":{let i=r.ordered?"ol":"ul";return(0,f.jsx)(i,{className:"diui-list",children:r.items.map((a,o)=>(0,f.jsx)("li",{children:(0,f.jsx)(se,{text:a})},o))})}case"Table":return(0,f.jsx)(Ur,{columns:r.columns,rows:r.rows,caption:r.caption,sortable:r.sortable,env:t,nodeId:e.id});case"Chart":return(0,f.jsx)(fn,{...r,emptyText:t.t("chart.empty")});case"Button":return(0,f.jsx)(qr,{label:r.label,prompt:r.prompt,variant:r.variant,env:t});case"Form":return(0,f.jsx)(Br,{props:r,env:t,nodeId:e.id});case"Timeline":return(0,f.jsx)("ol",{className:"diui-timeline",children:r.items.map((i,a)=>(0,f.jsxs)("li",{className:"diui-timeline-item","data-tone":i.tone??"default",children:[(0,f.jsx)("span",{className:"diui-timeline-dot","aria-hidden":"true"}),(0,f.jsxs)("div",{className:"diui-timeline-body",children:[i.time&&(0,f.jsx)("div",{className:"diui-timeline-time",children:i.time}),(0,f.jsx)("div",{className:"diui-timeline-title",children:(0,f.jsx)(se,{text:i.title})}),i.text&&(0,f.jsx)("div",{className:"diui-timeline-text",children:(0,f.jsx)(se,{text:i.text})})]})]},a))});case"Plot":return(0,f.jsx)(Sn,{...r,callId:t.callId,nodeId:e.id,t:t.t});case"Math":return t.streaming?(0,f.jsx)("pre",{className:"diui-code diui-src-preview",children:r.tex}):(0,f.jsx)(Rt,{kind:"math",source:r.tex,display:r.display,surfaceId:`${t.callId??""}:${e.id}`,policy:t.policy,title:t.t("lib.math")});case"Mermaid":return t.streaming?(0,f.jsx)("pre",{className:"diui-code diui-src-preview",children:r.code}):(0,f.jsx)(Rt,{kind:"mermaid",source:r.code,surfaceId:`${t.callId??""}:${e.id}`,policy:t.policy,title:t.t("lib.diagram")});default:return null}}function Lr(e){return e==="start"?"flex-start":e==="end"?"flex-end":typeof e=="string"?e:void 0}function _r(e){let[t,n]=me(e.env.callId,`${e.nodeId}:tab`,0),r=(0,G.useId)(),i=(0,G.useRef)(null),a=Math.min(e.labels.length,Math.max(1,e.children.length)),o=Math.min(t,a-1);return(0,f.jsxs)("div",{className:"diui-tabs",children:[(0,f.jsx)("div",{className:"diui-tablist",role:"tablist",ref:i,onKeyDown:l=>{let u=l.key==="ArrowRight"?o+1:l.key==="ArrowLeft"?o-1:l.key==="Home"?0:l.key==="End"?a-1:void 0;if(u===void 0)return;l.preventDefault();let p=(u+a)%a;n(p),i.current?.querySelectorAll("[role=tab]")[p]?.focus()},children:e.labels.slice(0,a).map((l,u)=>(0,f.jsx)("button",{id:`${r}-tab-${u}`,type:"button",role:"tab","aria-selected":u===o,"aria-controls":`${r}-panel`,tabIndex:u===o?0:-1,className:"diui-tab",onClick:()=>n(u),children:l},u))}),(0,f.jsx)("div",{className:"diui-tabpanel",role:"tabpanel",id:`${r}-panel`,"aria-labelledby":`${r}-tab-${o}`,children:e.children[o]})]})}function Ur(e){let[t,n]=me(e.env.callId,`${e.nodeId}:sort`,null),r=(0,G.useMemo)(()=>{if(!t)return e.rows;let{col:a,dir:o}=t;return[...e.rows].sort((s,l)=>Dr(s[a]??null,l[a]??null)*o)},[e.rows,t]),i=e.columns.map((a,o)=>e.rows.length>0&&e.rows.every(s=>typeof s[o]=="number"||s[o]===null||s[o]===void 0));return(0,f.jsx)("div",{className:"diui-table-wrap",children:(0,f.jsxs)("table",{className:"diui-table",children:[e.caption&&(0,f.jsx)("caption",{children:e.caption}),(0,f.jsx)("thead",{children:(0,f.jsx)("tr",{children:e.columns.map((a,o)=>(0,f.jsx)("th",{"data-numeric":i[o]||void 0,"aria-sort":t?.col===o?t.dir===1?"ascending":"descending":void 0,children:e.sortable?(0,f.jsxs)("button",{type:"button",className:"diui-th-button",onClick:()=>n(s=>s?.col===o?s.dir===1?{col:o,dir:-1}:null:{col:o,dir:1}),children:[a,(0,f.jsx)("span",{className:"diui-sort","aria-hidden":"true",children:t?.col===o?t.dir===1?"↑":"↓":"↕"})]}):a},o))})}),(0,f.jsxs)("tbody",{children:[r.length===0&&(0,f.jsx)("tr",{children:(0,f.jsx)("td",{colSpan:e.columns.length,className:"diui-empty",children:e.env.t("table.empty")})}),r.map((a,o)=>(0,f.jsx)("tr",{children:e.columns.map((s,l)=>(0,f.jsx)("td",{"data-numeric":i[l]||void 0,children:zr(a[l])},l))},o))]})]})})}function zr(e){return e==null?"—":typeof e=="boolean"?e?"✓":"✗":typeof e=="string"?(0,f.jsx)(se,{text:e}):String(e)}function Dr(e,t){return e===t?0:e===null?1:t===null?-1:typeof e=="number"&&typeof t=="number"?e-t:String(e).localeCompare(String(t),void 0,{numeric:!0})}function $n(e){let[t,n]=(0,G.useState)(!1),[r,i]=(0,G.useState)(void 0),a=(0,G.useRef)(!1);return[async s=>{if(a.current)return!1;a.current=!0,n(!0),i(e.t("bridge.sending"));try{return await e.send(s),i(e.t("bridge.sent")),!0}catch(l){return i(e.t("bridge.failed",{reason:l instanceof Error?l.message:String(l)})),!1}finally{a.current=!1,n(!1)}},t,r]}function qr(e){let[t,n,r]=$n(e.env);return(0,f.jsxs)("span",{className:"diui-action",children:[(0,f.jsx)("button",{type:"button",className:"diui-button","data-variant":e.variant??"secondary",disabled:n||e.env.streaming,"aria-busy":n||void 0,onClick:()=>{t(e.prompt)},children:e.label}),r&&(0,f.jsx)("span",{className:"diui-note",children:r})]})}function Hr(e){return e.type==="checkbox"?e.default===!0:e.type==="range"?typeof e.default=="number"?e.default:((e.min??0)+(e.max??100))/2:e.default===void 0||e.default===null?"":e.type==="number"?Number(e.default):String(e.default)}function Br({props:e,env:t,nodeId:n}){let r=e.fields,[i,a]=me(t.callId,`${n}:values`,()=>Object.fromEntries(r.map(d=>[d.name,Hr(d)]))),[o,s,l]=$n(t),[u,p]=me(t.callId,`${n}:submitted`,!1),w=(0,G.useId)(),x=(d,m)=>a(v=>({...v,[d]:m})),b=async d=>{d.preventDefault();let m={};for(let v of r){let h=i[v.name];m[v.name]=v.type==="number"||v.type==="range"?h===""||h===void 0?null:Number(h):h}await o(en(e.title,e.prompt,m))&&p(!0)};return(0,f.jsxs)("form",{className:"diui-form",onSubmit:d=>{b(d)},children:[e.title&&(0,f.jsx)("h4",{className:"diui-form-title",children:e.title}),r.map(d=>{let m=`${w}-${d.name}`,v=i[d.name],h={id:m,name:d.name,required:d.required,disabled:u||t.streaming},S;switch(d.type){case"textarea":S=(0,f.jsx)("textarea",{...h,rows:3,placeholder:d.placeholder,value:String(v??""),onChange:y=>x(d.name,y.target.value)});break;case"select":S=(0,f.jsxs)("select",{...h,value:String(v??""),onChange:y=>x(d.name,y.target.value),children:[(0,f.jsx)("option",{value:"",disabled:!0,children:d.placeholder??t.t("form.choose")}),(d.options??[]).map(y=>(0,f.jsx)("option",{value:y,children:y},y))]});break;case"checkbox":S=(0,f.jsx)("input",{...h,required:!1,type:"checkbox",checked:v===!0,onChange:y=>x(d.name,y.target.checked)});break;case"range":S=(0,f.jsxs)("span",{className:"diui-range",children:[(0,f.jsx)("input",{...h,type:"range",min:d.min,max:d.max,step:d.step??"any",value:Number(v),onChange:y=>x(d.name,Number(y.target.value))}),(0,f.jsx)("output",{htmlFor:m,children:Z(Number(v))})]});break;default:S=(0,f.jsx)("input",{...h,type:d.type==="number"?"number":d.type==="date"?"date":"text",placeholder:d.placeholder,min:d.min,max:d.max,value:String(v??""),onChange:y=>x(d.name,y.target.value)})}return(0,f.jsxs)("label",{className:"diui-field","data-type":d.type,htmlFor:m,children:[(0,f.jsxs)("span",{className:"diui-field-label",children:[d.label,d.required&&(0,f.jsx)("span",{className:"diui-required",title:t.t("form.required"),children:" *"})]}),S]},d.name)}),(0,f.jsxs)("div",{className:"diui-form-actions",children:[(0,f.jsx)("button",{type:"submit",className:"diui-button","data-variant":"primary",disabled:s||u||t.streaming,"aria-busy":s||void 0,children:e.submitLabel??t.t("form.submit")}),(l??(u?t.t("form.submitted"):void 0))&&(0,f.jsx)("span",{className:"diui-note",role:"status",children:l??t.t("form.submitted")})]})]})}var tt=require("react");function Nn(e){if(!e||typeof e!="object")return"";let{chunks:t}=e;if(Array.isArray(t)&&t.every(r=>typeof r=="string"))return t.join("");if(typeof e.keys!="function")return"";let n=[];for(let r of e.keys()){let i=e.text?.(r);if(i!==void 0){let o=e.complete?.(r)??!1,s=JSON.stringify(i);if(n.push(`${JSON.stringify(r)}:${o?s:s.slice(0,-1)}`),!o)break;continue}let a=e.value?.(r);if(a===void 0)break;n.push(`${JSON.stringify(r)}:${JSON.stringify(a)}`)}return`{${n.join(",")}${e.closed?.()?"}":""}`}function Wr(e){if(e.phase!=="preparing")return;let t=e.block.args;return t&&typeof t=="object"?t:void 0}function nt(e,t=100){let n=e.useToolCallArgumentsPartial?.(),r=n===void 0?Wr(e):void 0,[i,a]=(0,tt.useState)(()=>Nn(r));return(0,tt.useEffect)(()=>{if(!r)return;let o=()=>a(l=>{let u=Nn(r);return u===l?l:u});o();let s=setInterval(o,t);return()=>clearInterval(s)},[r,t]),n!==void 0?n:r?i:""}var Q=require("react/jsx-runtime");function Vr(e){return!!e&&typeof e=="object"&&typeof e.id=="string"&&typeof e.type=="string"}function En(e){let t=new Map;if(Array.isArray(e))for(let n of e)Vr(n)&&!t.has(n.id)&&t.set(n.id,n);return t}function Mn(e,t){if(!t){let a=Ve(e);if(a)return{title:typeof a.title=="string"?a.title:void 0,root:typeof a.root=="string"?a.root:void 0,nodes:En(a.components),complete:!0}}let n=We(e);if(Object.keys(n).length===0)return;let r=En(n.components?.value),i=n.root?.complete&&typeof n.root.value=="string"?n.root.value:r.keys().next().value;return{title:typeof n.title?.value=="string"?n.title.value:void 0,root:i,nodes:r,complete:!1}}function rt(e){let t=nt(e,100);Je(e,t);let n=He(e.phase==="preparing"?t:"",100),r=Ke(e),i=(0,Ne.useMemo)(()=>e.phase==="preparing"?Mn(n,!0):Mn(r,!1),[e.phase,n,r]),a=e.phase==="result"?e.block.meta:void 0,o=(0,Ne.useMemo)(()=>a===void 0?X:qe(a),[a]),s=(0,Ne.useMemo)(()=>new xe({policy:o,armDelayMs:0,minIntervalMs:1e3}),[o]),[l,u]=(0,Ne.useState)(!1),{t:p}=e,w=i?.title||p("render.title"),x=e.phase==="result"?e.block:void 0;if(x&&Te(x))return(0,Q.jsx)(Y,{kind:"render",title:w,state:"error",children:(0,Q.jsx)(oe,{t:p,message:p("render.invalid"),detail:we(x)})});let b=!!x&&(ke(x)||x.isError);if(e.phase!=="preparing"&&!b&&(!i?.complete||i.root===void 0))return(0,Q.jsx)(Y,{kind:"render",title:w,state:"error",children:(0,Q.jsx)(oe,{t:p,message:p("render.malformed")})});let d=e.phase!=="preparing"&&!b,m={nodes:i?.nodes??new Map,streaming:!d,stopped:b,t:p,callId:e.callId,policy:o,send:d?async h=>{await e.sendPrompt(s.admitPrompt(h))}:()=>Promise.reject(new Error(p("render.notReady")))},v=async()=>{u(!0);try{await e.sendPrompt(p("prompt.regenerateUi",{title:w}))}catch{}finally{u(!1)}};return(0,Q.jsx)(Y,{kind:"render",title:w,state:b?"stopped":e.phase==="result"?"ready":"generating",notice:b?ke(x)?p("render.stopped"):p("render.failed"):void 0,actions:b?(0,Q.jsx)(ve,{label:p("action.regenerate"),disabled:l,onClick:()=>{v()}}):void 0,children:i?.root!==void 0?(0,Q.jsx)("div",{className:"diui-render",children:It(i.root,m)}):b?(0,Q.jsx)(oe,{t:p,message:p("render.nothingToShow"),detail:x?we(x):void 0}):(0,Q.jsx)(Be,{messages:[],fallback:p("render.generating")})})}var it="intelligentUi",On={"widget.title":"交互组件","widget.generating":"正在生成组件…","widget.preview":"实时预览","widget.invalid":"组件未通过校验,模型会修正后重试","widget.failed":"组件调用失败","widget.malformed":"无法解析组件参数","widget.scriptErrors":"{count} 个脚本错误","render.title":"界面","render.generating":"正在生成界面…","render.invalid":"界面未通过校验,模型会修正后重试","render.failed":"界面调用失败","render.malformed":"无法解析界面参数","node.invalid":"组件 {id}({type})参数无效","node.missing":"缺少组件 {id}","bridge.sent":"已发送到对话","bridge.failed":"发送失败:{reason}","bridge.source":"由组件发送","form.submit":"提交","form.required":"必填","form.yes":"是","form.no":"否","form.choose":"请选择…","table.empty":"无数据","table.rows":"{count} 行","chart.empty":"无数据","details.show":"详情","details.hide":"收起","turn.shownBelow":"已在回复下方显示","widget.stopped":"生成已中断,以下为已生成部分的静态预览","widget.nothingToShow":"生成已中断,尚无可显示的内容","render.stopped":"生成已中断,以下为已完成的部分","render.nothingToShow":"生成已中断,尚无可显示的内容","render.notReady":"界面仍在生成中","action.regenerate":"重新生成","action.reload":"重新加载","action.fix":"让模型修复","prompt.regenerateWidget":"组件「{title}」的生成被中断了,请重新生成完整的组件。","prompt.regenerateUi":"界面「{title}」的生成被中断了,请重新生成完整的界面。","prompt.fixWidget":`组件「{title}」运行时报告了脚本错误:
|
|
261
|
+
UI.onTheme(function(){draw().catch(fallback)});return draw()}).catch(fallback)}`}}function Jt(e){let t=Kr(e.policy),n=(0,Fn.useMemo)(()=>t&&Gr(e.kind,e.source,{display:e.display},t),[t,e.kind,e.source,e.display]);return n?(0,ut.jsx)("div",{className:"diui-lib","data-kind":e.kind,children:(0,ut.jsx)(ct,{callId:e.surfaceId,mode:"final",css:n.css,html:n.html,jsFunctions:n.js,jsExpressions:["render()"],initialHeight:e.kind==="math"?56:240,policy:e.policy,title:e.title,persist:!0,sendPrompt:()=>Promise.reject(new Error("not available here"))})}):(0,ut.jsx)("pre",{className:"diui-code",children:e.source})}var pe=require("react");var O=require("react/jsx-runtime"),Re=640,R={top:12,right:16,bottom:34,left:48},Yr=480;function Xr(e,t,n,r,i=Yr){let s=[],o={...r};for(let a=0;a<=i;a++){let l=t+(n-t)*a/i;o.x=l;let c;try{c=e(o)}catch{c=NaN}s.push({x:l,y:Number.isFinite(c)?c:NaN})}return s}function Zr(e){let t=e.filter(Number.isFinite).sort((s,o)=>s-o);if(t.length===0)return[-1,1];let n=t[Math.floor(t.length*.02)],r=t[Math.max(0,Math.ceil(t.length*.98)-1)];r-n<1e-9&&(n-=1,r+=1);let i=(r-n)*.08;return[n-i,r+i]}function Qr(e,t,n,r,i){let s=i-r,o="",a=!1,l;for(let c of e){let y=!Number.isFinite(c.y)||c.y<r-s*4||c.y>i+s*4,x=l!==void 0&&Number.isFinite(c.y)&&Math.abs(c.y-l)>s*3;if((y||x)&&(a=!1,l=Number.isFinite(c.y)?c.y:void 0,y))continue;let v=Math.max(r-s,Math.min(i+s,c.y));o+=`${a?"L":"M"}${t(c.x).toFixed(1)},${n(v).toFixed(1)}`,a=!0,l=c.y}return o}function zn(e){let t=e.params??[],n=(0,pe.useMemo)(()=>Object.fromEntries(t.map(g=>[g.name,g.value])),[t]),[r,i]=ve(e.callId,`${e.nodeId}:params`,n),s=(0,pe.useMemo)(()=>({...n,...r}),[n,r]),[o,a]=(0,pe.useState)(void 0),l=(0,pe.useId)(),c=t.map(g=>g.name),y=(0,pe.useMemo)(()=>e.functions.map(g=>{try{return{fn:xt(g.expr,["x",...c])}}catch(N){return{error:N instanceof Error?N.message:String(N)}}}),[e.functions,c.join(",")]),x=e.xMin??-10,v=e.xMax??10,m=e.height??300,p=y.map(g=>"fn"in g&&g.fn?Xr(g.fn,x,v,s):[]),d=Zr(p.flatMap(g=>g.map(N=>N.y))),k=e.yMin??d[0],h=e.yMax??d[1],S=Re-R.left-R.right,b=m-R.top-R.bottom,w=g=>R.left+(g-x)/(v-x)*S,$=g=>R.top+b-(g-k)/(h-k)*b,E=lt(x,v,8).filter(g=>g>=x&&g<=v),P=lt(k,h,5).filter(g=>g>=k&&g<=h),q=g=>e.functions[g]?.label||`y = ${e.functions[g]?.expr??""}`,A=g=>{let N=g.currentTarget.getBoundingClientRect();if(N.width<=0)return;let T=(g.clientX-N.left)/N.width*Re,he=x+(T-R.left)/S*(v-x);a(he>=x&&he<=v?he:void 0)},j=(g,N)=>{let T=y[g];if(!T||!("fn"in T)||!T.fn)return NaN;try{return T.fn({...s,x:N})}catch{return NaN}};return(0,O.jsxs)("figure",{className:"diui-plot",children:[e.title&&(0,O.jsx)("figcaption",{className:"diui-chart-title",children:e.title}),(0,O.jsxs)("div",{className:"diui-plot-stage",children:[(0,O.jsxs)("svg",{className:"diui-chart-svg",viewBox:`0 0 ${Re} ${m}`,role:"img","aria-label":e.title??e.functions.map((g,N)=>q(N)).join(", "),onPointerMove:A,onPointerLeave:()=>a(void 0),children:[P.map(g=>(0,O.jsxs)("g",{children:[(0,O.jsx)("line",{x1:R.left,x2:Re-R.right,y1:$(g),y2:$(g),className:g===0?"diui-axis-zero":"diui-grid"}),(0,O.jsx)("text",{x:R.left-6,y:$(g),dy:"0.32em",textAnchor:"end",className:"diui-tick",children:ee(g)})]},`y${g}`)),E.map(g=>(0,O.jsxs)("g",{children:[(0,O.jsx)("line",{y1:R.top,y2:m-R.bottom,x1:w(g),x2:w(g),className:g===0?"diui-axis-zero":"diui-grid"}),(0,O.jsx)("text",{x:w(g),y:m-R.bottom+16,textAnchor:"middle",className:"diui-tick",children:ee(g)})]},`x${g}`)),e.xLabel&&(0,O.jsx)("text",{x:Re-R.right,y:m-4,textAnchor:"end",className:"diui-tick",children:e.xLabel}),e.yLabel&&(0,O.jsx)("text",{x:R.left,y:R.top-2,className:"diui-tick",children:e.yLabel}),(0,O.jsx)("clipPath",{id:`${l}-clip`,children:(0,O.jsx)("rect",{x:R.left,y:R.top,width:S,height:b})}),(0,O.jsxs)("g",{clipPath:`url(#${l}-clip)`,children:[p.map((g,N)=>(0,O.jsx)("path",{d:Qr(g,w,$,k,h),fill:"none",stroke:U[N%U.length],strokeWidth:2.2,strokeLinejoin:"round",strokeLinecap:"round"},N)),o!==void 0&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("line",{x1:w(o),x2:w(o),y1:R.top,y2:m-R.bottom,className:"diui-crosshair"}),p.map((g,N)=>{let T=j(N,o);return Number.isFinite(T)&&T>=k&&T<=h?(0,O.jsx)("circle",{cx:w(o),cy:$(T),r:4,fill:U[N%U.length],className:"diui-hover-dot"},N):null})]})]})]}),o!==void 0&&(0,O.jsxs)("div",{className:"diui-tooltip",style:{left:`${w(o)/Re*100}%`},children:[(0,O.jsxs)("div",{children:["x = ",ee(o)]}),y.map((g,N)=>{let T=j(N,o);return(0,O.jsxs)("div",{children:[(0,O.jsx)("i",{style:{background:U[N%U.length]}}),Number.isFinite(T)?ee(T):"—"]},N)})]})]}),(0,O.jsx)("div",{className:"diui-legend",children:e.functions.map((g,N)=>{let T=y[N];return(0,O.jsxs)("span",{className:"diui-legend-item","data-error":T&&"error"in T?!0:void 0,title:T&&"error"in T?T.error:void 0,children:[(0,O.jsx)("i",{style:{background:U[N%U.length]}}),q(N)]},N)})}),t.length>0&&(0,O.jsxs)("div",{className:"diui-params",children:[t.map(g=>{let N=`${l}-${g.name}`,T=s[g.name]??g.value;return(0,O.jsxs)("label",{className:"diui-param",htmlFor:N,children:[(0,O.jsx)("span",{className:"diui-param-name",children:g.label??g.name}),(0,O.jsx)("input",{id:N,type:"range",min:g.min,max:g.max,step:g.step??(g.max-g.min)/100,value:T,onChange:he=>i(bt=>({...bt,[g.name]:Number(he.target.value)}))}),(0,O.jsx)("output",{htmlFor:N,className:"diui-param-value",children:ee(T)})]},g.name)}),(0,O.jsx)("button",{type:"button",className:"diui-link diui-param-reset",onClick:()=>i(n),children:e.t("plot.reset")})]})]})}var f=require("react/jsx-runtime");function qe(e,t,n=0,r=new Set){let i=t.nodes.get(e);if(!i)return t.stopped?null:t.streaming?(0,f.jsx)("div",{className:"diui-shimmer"},e):(0,f.jsx)("div",{className:"diui-node-error",children:t.t("node.missing",{id:e})},e);if(r.has(e)||n>24)return null;let s=tn(i.type,i.props);if(s.length)return t.streaming?t.stopped?null:(0,f.jsx)("div",{className:"diui-shimmer"},e):(0,f.jsx)("div",{className:"diui-node-error",title:s.join(`
|
|
262
|
+
`),children:t.t("node.invalid",{id:e,type:i.type})},e);let o=new Set(r).add(e),a=We[i.type]?.children?(i.children??[]).map(l=>qe(l,t,n+1,o)):[];return(0,f.jsx)(ei,{node:i,env:t,children:a},e)}function ei({node:e,env:t,children:n}){let r=e.props??{};switch(e.type){case"Card":return(0,f.jsxs)("section",{className:"diui-card",children:[(r.title||r.subtitle)&&(0,f.jsxs)("header",{className:"diui-card-head",children:[r.title&&(0,f.jsx)("h3",{className:"diui-card-title",children:r.title}),r.subtitle&&(0,f.jsx)("p",{className:"diui-card-subtitle",children:r.subtitle})]}),(0,f.jsx)("div",{className:"diui-stack",style:{gap:10},children:n}),r.footer&&(0,f.jsx)("footer",{className:"diui-card-foot",children:(0,f.jsx)(fe,{text:r.footer})})]});case"Stack":return(0,f.jsx)("div",{className:"diui-stack","data-direction":r.direction??"vertical",style:{gap:r.gap??10,flexWrap:r.wrap?"wrap":void 0,alignItems:ti(r.align)},children:n});case"Grid":return(0,f.jsx)("div",{className:"diui-grid",style:{"--diui-cols":Math.round(r.columns)},children:n});case"Tabs":return(0,f.jsx)(ni,{labels:r.labels,env:t,nodeId:e.id,children:n});case"Text":{let i=r.variant==="title"?"h2":r.variant==="heading"?"h4":"p";return(0,f.jsx)(i,{className:"diui-text","data-variant":r.variant??"body","data-tone":r.tone??"default",children:(0,f.jsx)(fe,{text:r.text})})}case"Code":return(0,f.jsx)("pre",{className:"diui-code","data-language":r.language,children:(0,f.jsx)("code",{children:r.code})});case"Alert":return(0,f.jsxs)("div",{className:"diui-alert","data-tone":r.tone??"info",role:"note",children:[r.title&&(0,f.jsx)("strong",{className:"diui-alert-title",children:r.title}),(0,f.jsx)("div",{children:(0,f.jsx)(fe,{text:r.text})})]});case"Badge":return(0,f.jsx)("span",{className:"diui-badge","data-tone":r.tone??"default",children:r.text});case"Divider":return(0,f.jsx)("hr",{className:"diui-divider"});case"Stat":return(0,f.jsxs)("div",{className:"diui-stat",children:[(0,f.jsx)("div",{className:"diui-stat-label",children:r.label}),(0,f.jsx)("div",{className:"diui-stat-value",children:String(r.value??"")}),r.delta&&(0,f.jsxs)("div",{className:"diui-stat-delta","data-trend":r.trend??"flat",children:[r.trend==="up"?"▲ ":r.trend==="down"?"▼ ":"",r.delta]}),r.hint&&(0,f.jsx)("div",{className:"diui-stat-hint",children:r.hint})]});case"Progress":{let i=r.max&&r.max>0?r.max:100,s=Math.max(0,Math.min(100,r.value/i*100));return(0,f.jsxs)("div",{className:"diui-progress","data-tone":r.tone??"default",children:[r.label&&(0,f.jsxs)("div",{className:"diui-progress-label",children:[(0,f.jsx)("span",{children:r.label}),(0,f.jsxs)("span",{children:[Math.round(s),"%"]})]}),(0,f.jsx)("div",{className:"diui-progress-track",role:"progressbar","aria-valuenow":r.value,"aria-valuemin":0,"aria-valuemax":i,children:(0,f.jsx)("div",{className:"diui-progress-bar",style:{width:`${s}%`}})})]})}case"List":{let i=r.ordered?"ol":"ul";return(0,f.jsx)(i,{className:"diui-list",children:r.items.map((s,o)=>(0,f.jsx)("li",{children:(0,f.jsx)(fe,{text:s})},o))})}case"Table":return(0,f.jsx)(ri,{columns:r.columns,rows:r.rows,caption:r.caption,sortable:r.sortable,env:t,nodeId:e.id});case"Chart":return(0,f.jsx)(In,{...r,emptyText:t.t("chart.empty")});case"Button":return(0,f.jsx)(si,{label:r.label,prompt:r.prompt,variant:r.variant,env:t});case"Form":return(0,f.jsx)(ai,{props:r,env:t,nodeId:e.id});case"Timeline":return(0,f.jsx)("ol",{className:"diui-timeline",children:r.items.map((i,s)=>(0,f.jsxs)("li",{className:"diui-timeline-item","data-tone":i.tone??"default",children:[(0,f.jsx)("span",{className:"diui-timeline-dot","aria-hidden":"true"}),(0,f.jsxs)("div",{className:"diui-timeline-body",children:[i.time&&(0,f.jsx)("div",{className:"diui-timeline-time",children:i.time}),(0,f.jsx)("div",{className:"diui-timeline-title",children:(0,f.jsx)(fe,{text:i.title})}),i.text&&(0,f.jsx)("div",{className:"diui-timeline-text",children:(0,f.jsx)(fe,{text:i.text})})]})]},s))});case"Plot":return(0,f.jsx)(zn,{...r,callId:t.callId,nodeId:e.id,t:t.t});case"Math":return t.streaming?(0,f.jsx)("pre",{className:"diui-code diui-src-preview",children:r.tex}):(0,f.jsx)(Jt,{kind:"math",source:r.tex,display:r.display,surfaceId:`${t.callId??""}:${e.id}`,policy:t.policy,title:t.t("lib.math")});case"Mermaid":return t.streaming?(0,f.jsx)("pre",{className:"diui-code diui-src-preview",children:r.code}):(0,f.jsx)(Jt,{kind:"mermaid",source:r.code,surfaceId:`${t.callId??""}:${e.id}`,policy:t.policy,title:t.t("lib.diagram")});default:return null}}function ti(e){return e==="start"?"flex-start":e==="end"?"flex-end":typeof e=="string"?e:void 0}function ni(e){let[t,n]=ve(e.env.callId,`${e.nodeId}:tab`,0),r=(0,G.useId)(),i=(0,G.useRef)(null),s=Math.min(e.labels.length,Math.max(1,e.children.length)),o=Math.min(t,s-1);return(0,f.jsxs)("div",{className:"diui-tabs",children:[(0,f.jsx)("div",{className:"diui-tablist",role:"tablist",ref:i,onKeyDown:l=>{let c=l.key==="ArrowRight"?o+1:l.key==="ArrowLeft"?o-1:l.key==="Home"?0:l.key==="End"?s-1:void 0;if(c===void 0)return;l.preventDefault();let y=(c+s)%s;n(y),i.current?.querySelectorAll("[role=tab]")[y]?.focus()},children:e.labels.slice(0,s).map((l,c)=>(0,f.jsx)("button",{id:`${r}-tab-${c}`,type:"button",role:"tab","aria-selected":c===o,"aria-controls":`${r}-panel`,tabIndex:c===o?0:-1,className:"diui-tab",onClick:()=>n(c),children:l},c))}),(0,f.jsx)("div",{className:"diui-tabpanel",role:"tabpanel",id:`${r}-panel`,"aria-labelledby":`${r}-tab-${o}`,children:e.children[o]})]})}function ri(e){let[t,n]=ve(e.env.callId,`${e.nodeId}:sort`,null),r=t&&t.col<e.columns.length?t:null,i=(0,G.useMemo)(()=>{if(!r)return e.rows;let{col:o,dir:a}=r;return[...e.rows].sort((l,c)=>oi(l[o]??null,c[o]??null)*a)},[e.rows,r]),s=e.columns.map((o,a)=>e.rows.length>0&&e.rows.every(l=>typeof l[a]=="number"||l[a]===null||l[a]===void 0));return(0,f.jsx)("div",{className:"diui-table-wrap",children:(0,f.jsxs)("table",{className:"diui-table",children:[e.caption&&(0,f.jsx)("caption",{children:e.caption}),(0,f.jsx)("thead",{children:(0,f.jsx)("tr",{children:e.columns.map((o,a)=>(0,f.jsx)("th",{"data-numeric":s[a]||void 0,"aria-sort":r?.col===a?r.dir===1?"ascending":"descending":void 0,children:e.sortable?(0,f.jsxs)("button",{type:"button",className:"diui-th-button",onClick:()=>n(l=>l?.col===a?l.dir===1?{col:a,dir:-1}:null:{col:a,dir:1}),children:[o,(0,f.jsx)("span",{className:"diui-sort","aria-hidden":"true",children:r?.col===a?r.dir===1?"↑":"↓":"↕"})]}):o},a))})}),(0,f.jsxs)("tbody",{children:[i.length===0&&(0,f.jsx)("tr",{children:(0,f.jsx)("td",{colSpan:e.columns.length,className:"diui-empty",children:e.env.t("table.empty")})}),i.map((o,a)=>(0,f.jsx)("tr",{children:e.columns.map((l,c)=>(0,f.jsx)("td",{"data-numeric":s[c]||void 0,children:ii(o[c])},c))},a))]})]})})}function ii(e){return e==null?"—":typeof e=="boolean"?e?"✓":"✗":typeof e=="string"?(0,f.jsx)(fe,{text:e}):String(e)}function oi(e,t){return e===t?0:e===null?1:t===null?-1:typeof e=="number"&&typeof t=="number"?e-t:String(e).localeCompare(String(t),void 0,{numeric:!0})}function Dn(e){let[t,n]=(0,G.useState)(!1),[r,i]=(0,G.useState)(void 0),s=(0,G.useRef)(!1);return[async a=>{if(s.current)return!1;s.current=!0,n(!0),i(e.t("bridge.sending"));try{return await e.send(a),i(e.t("bridge.sent")),!0}catch(l){return i(e.t("bridge.failed",{reason:l instanceof Error?l.message:String(l)})),!1}finally{s.current=!1,n(!1)}},t,r]}function si(e){let[t,n,r]=Dn(e.env);return(0,f.jsxs)("span",{className:"diui-action",children:[(0,f.jsx)("button",{type:"button",className:"diui-button","data-variant":e.variant??"secondary",disabled:n||e.env.streaming,"aria-busy":n||void 0,onClick:()=>{t(e.prompt)},children:e.label}),r&&(0,f.jsx)("span",{className:"diui-note",children:r})]})}function Hn(e){return e.type==="checkbox"?e.default===!0:e.type==="range"?typeof e.default=="number"?e.default:((e.min??0)+(e.max??100))/2:e.default===void 0||e.default===null?"":e.type==="number"?Number(e.default):String(e.default)}function ai({props:e,env:t,nodeId:n}){let r=e.fields,[i,s]=ve(t.callId,`${n}:values`,()=>Object.fromEntries(r.map(d=>[d.name,Hn(d)]))),o=(0,G.useMemo)(()=>({...Object.fromEntries(r.map(d=>[d.name,Hn(d)])),...i}),[r,i]),[a,l,c]=Dn(t),[y,x]=ve(t.callId,`${n}:submitted`,!1),v=(0,G.useId)(),m=(d,k)=>s(h=>({...h,[d]:k})),p=async d=>{d.preventDefault();let k={};for(let h of r){let S=o[h.name];k[h.name]=h.type==="number"||h.type==="range"?S===""||S===void 0?null:Number(S):S}await a(pn(e.title,e.prompt,k))&&x(!0)};return(0,f.jsxs)("form",{className:"diui-form",onSubmit:d=>{p(d)},children:[e.title&&(0,f.jsx)("h4",{className:"diui-form-title",children:e.title}),r.map(d=>{let k=`${v}-${d.name}`,h=o[d.name],S={id:k,name:d.name,required:d.required,disabled:y||t.streaming},b;switch(d.type){case"textarea":b=(0,f.jsx)("textarea",{...S,rows:3,placeholder:d.placeholder,value:String(h??""),onChange:w=>m(d.name,w.target.value)});break;case"select":b=(0,f.jsxs)("select",{...S,value:String(h??""),onChange:w=>m(d.name,w.target.value),children:[(0,f.jsx)("option",{value:"",disabled:!0,children:d.placeholder??t.t("form.choose")}),(d.options??[]).map(w=>(0,f.jsx)("option",{value:w,children:w},w))]});break;case"checkbox":b=(0,f.jsx)("input",{...S,required:!1,type:"checkbox",checked:h===!0,onChange:w=>m(d.name,w.target.checked)});break;case"range":b=(0,f.jsxs)("span",{className:"diui-range",children:[(0,f.jsx)("input",{...S,type:"range",min:d.min,max:d.max,step:d.step??"any",value:Number(h),onChange:w=>m(d.name,Number(w.target.value))}),(0,f.jsx)("output",{htmlFor:k,children:ee(Number(h))})]});break;default:b=(0,f.jsx)("input",{...S,type:d.type==="number"?"number":d.type==="date"?"date":"text",placeholder:d.placeholder,min:d.min,max:d.max,value:String(h??""),onChange:w=>m(d.name,w.target.value)})}return(0,f.jsxs)("label",{className:"diui-field","data-type":d.type,htmlFor:k,children:[(0,f.jsxs)("span",{className:"diui-field-label",children:[d.label,d.required&&(0,f.jsx)("span",{className:"diui-required",title:t.t("form.required"),children:" *"})]}),b]},d.name)}),(0,f.jsxs)("div",{className:"diui-form-actions",children:[(0,f.jsx)("button",{type:"submit",className:"diui-button","data-variant":"primary",disabled:l||y||t.streaming,"aria-busy":l||void 0,children:e.submitLabel??t.t("form.submit")}),(c??(y?t.t("form.submitted"):void 0))&&(0,f.jsx)("span",{className:"diui-note",role:"status",children:c??t.t("form.submitted")})]})]})}var Ue=require("react");var Z=require("react/jsx-runtime");function li(e){return!!e&&typeof e=="object"&&typeof e.id=="string"&&typeof e.type=="string"}function ft(e){let t=new Map;if(Array.isArray(e))for(let n of e)li(n)&&!t.has(n.id)&&t.set(n.id,n);return t}function qn(e,t){if(!t){let s=je(e);if(s)return{title:typeof s.title=="string"?s.title:void 0,root:typeof s.root=="string"?s.root:void 0,nodes:ft(s.components),complete:!0}}let n=Pe(e);if(Object.keys(n).length===0)return;let r=ft(n.components?.value),i=n.root?.complete&&typeof n.root.value=="string"?n.root.value:r.keys().next().value;return{title:typeof n.title?.value=="string"?n.title.value:void 0,root:i,nodes:r,complete:!1}}function pt(e){let t=Ie(e,100);Oe(e,t);let n=Qe(e.phase==="preparing"?t:"",100),r=Ae(e),i=(0,Ue.useMemo)(()=>e.phase==="preparing"?qn(n,!0):qn(r,!1),[e.phase,n,r]),s=e.phase==="result"?e.block.meta:void 0,o=(0,Ue.useMemo)(()=>s===void 0?K:Me(s),[s]),a=(0,Ue.useMemo)(()=>new ae({policy:o,armDelayMs:0,minIntervalMs:1e3}),[o]),[l,c]=(0,Ue.useState)(!1),y=it(e.phase==="result"?e.callId:void 0),{t:x}=e,v=i?.title||x("render.title"),m=e.phase==="result"?e.block:void 0;if(m&&xe(m))return(0,Z.jsx)(L,{kind:"render",title:v,state:"error",children:(0,Z.jsx)(Q,{t:x,message:x("render.invalid"),detail:de(m)})});let p=!!m&&(ce(m)||m.isError);if(e.phase!=="preparing"&&!p&&(!i?.complete||i.root===void 0))return(0,Z.jsx)(L,{kind:"render",title:v,state:"error",children:(0,Z.jsx)(Q,{t:x,message:x("render.malformed")})});let d=e.phase!=="preparing"&&!p;if(d&&y&&y.version>1)return(0,Z.jsx)(L,{kind:"render",title:v,state:"ready",status:x("patch.superseded",{version:y.version})});let k={nodes:i?.nodes??new Map,streaming:!d,stopped:p,t:x,callId:e.callId,policy:o,send:d?async S=>{await e.sendPrompt(a.admitPrompt(S))}:()=>Promise.reject(new Error(x("render.notReady")))},h=async()=>{c(!0);try{await e.sendPrompt(x("prompt.regenerateUi",{title:v}))}catch{}finally{c(!1)}};return(0,Z.jsx)(L,{kind:"render",title:v,state:p?"stopped":e.phase==="result"?"ready":"generating",notice:p?ce(m)?x("render.stopped"):x("render.failed"):void 0,actions:p?(0,Z.jsx)(le,{label:x("action.regenerate"),disabled:l,onClick:()=>{h()}}):void 0,children:i?.root!==void 0?(0,Z.jsx)("div",{className:"diui-render",children:qe(i.root,k)}):p?(0,Z.jsx)(Q,{t:x,message:x("render.nothingToShow"),detail:m?de(m):void 0}):(0,Z.jsx)(et,{messages:[],fallback:x("render.generating")})})}var ie=require("react/jsx-runtime");function di(e,t){if(!t){let r=je(e);if(r)return typeof r.uiId=="string"?r.uiId:void 0}let n=Pe(e);return n.uiId?.complete&&typeof n.uiId.value=="string"?n.uiId.value:void 0}function mt(e){let t=Ie(e,100);Oe(e,t);let n=e.phase==="result"?e.block:void 0,r=n&&!n.isError?Rt(n.meta):void 0,i=r?.uiId??di(e.phase==="preparing"?t:Ae(e),e.phase==="preparing"),s=it(i),o=n?.meta,a=(0,_e.useMemo)(()=>o===void 0?K:Me(o),[o]),l=(0,_e.useMemo)(()=>new ae({policy:a,armDelayMs:0,minIntervalMs:1e3}),[a]),c=(0,_e.useMemo)(()=>ft(r?.components),[r]),[y,x]=(0,_e.useState)(!1),{t:v}=e,m=r?.title||s?.title||v("render.title");if(!n)return(0,ie.jsx)(L,{kind:"render",title:m,state:"generating",status:v("patch.updating")});if(xe(n))return(0,ie.jsx)(L,{kind:"render",title:m,state:"error",children:(0,ie.jsx)(Q,{t:v,message:v("patch.invalid"),detail:de(n)})});if(!r){let d=async()=>{x(!0);try{await e.sendPrompt(v("prompt.regeneratePatch",{title:m}))}catch{}finally{x(!1)}};return(0,ie.jsx)(L,{kind:"render",title:m,state:"stopped",notice:ce(n)?v("patch.stopped"):v("patch.failed"),actions:(0,ie.jsx)(le,{label:v("action.regenerate"),disabled:y,onClick:()=>{d()}})})}if(s&&s.version>r.version)return(0,ie.jsx)(L,{kind:"render",title:m,state:"ready",status:v("patch.superseded",{version:s.version})});let p={nodes:c,streaming:!1,t:v,callId:r.uiId,policy:a,send:async d=>{await e.sendPrompt(l.admitPrompt(d))}};return(0,ie.jsx)(L,{kind:"render",title:m,state:"ready",status:v("patch.version",{version:r.version}),children:(0,ie.jsx)("div",{className:"diui-render",children:qe(r.root,p)})})}var ht="intelligentUi",Bn={"widget.title":"交互组件","widget.generating":"正在生成组件…","widget.preview":"实时预览","widget.invalid":"组件未通过校验,模型会修正后重试","widget.failed":"组件调用失败","widget.malformed":"无法解析组件参数","widget.scriptErrors":"{count} 个脚本错误","render.title":"界面","render.generating":"正在生成界面…","render.invalid":"界面未通过校验,模型会修正后重试","render.failed":"界面调用失败","render.malformed":"无法解析界面参数","node.invalid":"组件 {id}({type})参数无效","node.missing":"缺少组件 {id}","bridge.sent":"已发送到对话","bridge.failed":"发送失败:{reason}","bridge.source":"由组件发送","form.submit":"提交","form.required":"必填","form.yes":"是","form.no":"否","form.choose":"请选择…","table.empty":"无数据","table.rows":"{count} 行","chart.empty":"无数据","details.show":"详情","details.hide":"收起","turn.shownBelow":"已在回复下方显示","widget.stopped":"生成已中断,以下为已生成部分的静态预览","widget.nothingToShow":"生成已中断,尚无可显示的内容","render.stopped":"生成已中断,以下为已完成的部分","render.nothingToShow":"生成已中断,尚无可显示的内容","render.notReady":"界面仍在生成中","action.regenerate":"重新生成","action.reload":"重新加载","action.fix":"让模型修复","prompt.regenerateWidget":"组件「{title}」的生成被中断了,请重新生成完整的组件。","prompt.regenerateUi":"界面「{title}」的生成被中断了,请重新生成完整的界面。","prompt.fixWidget":`组件「{title}」运行时报告了脚本错误:
|
|
263
263
|
{errors}
|
|
264
|
-
请修复后重新生成该组件。`,"bridge.sending":"正在发送…","form.submitted":"已提交","plot.reset":"重置参数","lib.math":"数学公式","lib.diagram":"图表"},
|
|
264
|
+
请修复后重新生成该组件。`,"bridge.sending":"正在发送…","form.submitted":"已提交","plot.reset":"重置参数","lib.math":"数学公式","lib.diagram":"图表","patch.updating":"正在更新界面…","patch.invalid":"界面更新未通过校验,已保留上一版本;模型会修正后重试","patch.failed":"界面更新失败,上一版本保持不变","patch.stopped":"更新已中断,上一版本保持不变","patch.superseded":"已更新为第 {version} 版,见后续回复","patch.version":"第 {version} 版","prompt.regeneratePatch":"对界面「{title}」的更新被中断了,请重新执行这次更新。"},Vn={"widget.title":"Widget","widget.generating":"Generating widget…","widget.preview":"Live preview","widget.invalid":"The widget failed validation; the model will fix it and retry","widget.failed":"Widget call failed","widget.malformed":"Could not parse the widget arguments","widget.scriptErrors":"{count} script error(s)","render.title":"UI","render.generating":"Generating UI…","render.invalid":"The UI failed validation; the model will fix it and retry","render.failed":"UI call failed","render.malformed":"Could not parse the UI arguments","node.invalid":"Component {id} ({type}) has invalid props","node.missing":"Missing component {id}","bridge.sent":"Sent to the conversation","bridge.failed":"Could not send: {reason}","bridge.source":"Sent from a widget","form.submit":"Submit","form.required":"required","form.yes":"Yes","form.no":"No","form.choose":"Choose…","table.empty":"No data","table.rows":"{count} rows","chart.empty":"No data","details.show":"Details","details.hide":"Hide","turn.shownBelow":"Shown below the reply","widget.stopped":"Generation stopped — showing a static preview of what was generated","widget.nothingToShow":"Generation stopped before anything could be shown","render.stopped":"Generation stopped — showing the finished part","render.nothingToShow":"Generation stopped before anything could be shown","render.notReady":"the UI is still generating","action.regenerate":"Regenerate","action.reload":"Reload","action.fix":"Ask to fix","prompt.regenerateWidget":'Generating the widget "{title}" was interrupted. Please generate the complete widget again.',"prompt.regenerateUi":'Generating the UI "{title}" was interrupted. Please generate the complete UI again.',"prompt.fixWidget":`The widget "{title}" reported script errors:
|
|
265
265
|
{errors}
|
|
266
|
-
Please fix them and render the widget again.`,"bridge.sending":"Sending…","form.submitted":"Submitted","plot.reset":"Reset","lib.math":"Math","lib.diagram":"Diagram"};var
|
|
266
|
+
Please fix them and render the widget again.`,"bridge.sending":"Sending…","form.submitted":"Submitted","plot.reset":"Reset","lib.math":"Math","lib.diagram":"Diagram","patch.updating":"Updating the UI…","patch.invalid":"The update failed validation; the previous version is kept and the model will retry","patch.failed":"The update failed; the previous version is unchanged","patch.stopped":"Update stopped; the previous version is unchanged","patch.superseded":"Updated to version {version}, shown further down","patch.version":"Version {version}","prompt.regeneratePatch":'Updating the UI "{title}" was interrupted. Please apply the update again.'};var Wn=`
|
|
267
267
|
.diui{
|
|
268
268
|
--ui-bg:var(--dsw-alias-bg-base,#fff);
|
|
269
269
|
--ui-surface:color-mix(in srgb,var(--dsw-alias-label-primary,#0f1115) 4%,var(--dsw-alias-bg-base,#fff));
|
|
@@ -439,7 +439,7 @@ th[aria-sort] .diui-sort{opacity:1;color:var(--ui-accent)}
|
|
|
439
439
|
.diui-lib{min-width:0}
|
|
440
440
|
.diui-button[aria-busy=true]{cursor:progress}
|
|
441
441
|
@media (prefers-reduced-motion:reduce){.diui-dots i,.diui-skeleton,.diui-shimmer{animation:none}.diui-frame,.diui-progress-bar{transition:none}}
|
|
442
|
-
`;var
|
|
443
|
-
`),children:
|
|
444
|
-
`)}))}})]})):e.phase==="preparing"&&i?.cssDone&&(
|
|
442
|
+
`;var yt=require("react");var ke=require("react");var z=require("react/jsx-runtime");function gt(e){let t=Ie(e,120);Oe(e,t);let n=Qe(e.phase==="preparing"?t:"",120),r=Ae(e),{args:i,full:s}=(0,ke.useMemo)(()=>{if(e.phase==="preparing")return{args:Jn(n),full:!1};let j=je(r);return j&&typeof j.html=="string"&&j.html!==""?{args:ci(j),full:!0}:{args:r?Jn(r):void 0,full:!1}},[e.phase,n,r]),o=(0,ke.useMemo)(()=>e.phase==="result"?Me(e.block.meta):K,[e.phase,e.phase==="result"?e.block.meta:void 0]),[a,l]=xn(),[c,y]=(0,ke.useState)(!1),[x,v]=(0,ke.useState)([]),[m,p]=(0,ke.useState)(0),{t:d}=e,k=i?.title||d("widget.title"),h=e.phase==="result"?e.block:void 0,S=!!h&&(ce(h)||h.isError&&!xe(h));if(h&&xe(h))return(0,z.jsx)(L,{kind:"widget",title:k,state:"error",children:(0,z.jsx)(Q,{t:d,message:d("widget.invalid"),detail:de(h)})});let b=s&&!!i;if(e.phase!=="preparing"&&!S&&!b)return(0,z.jsx)(L,{kind:"widget",title:k,state:"error",children:(0,z.jsx)(Q,{t:d,message:d("widget.malformed")})});let w=async j=>{y(!0);try{await e.sendPrompt(j),l(d("bridge.sent"))}catch(g){l(d("bridge.failed",{reason:g instanceof Error?g.message:String(g)}))}finally{y(!1)}},$,E,P;S?(P=ce(h)?d("widget.stopped"):d("widget.failed"),E=(0,z.jsx)(le,{label:d("action.regenerate"),disabled:c,onClick:()=>{w(d("prompt.regenerateWidget",{title:k}))}})):c?$=d("bridge.sending"):a?$=a:x.length?($=(0,z.jsx)("span",{className:"diui-error-count",title:x.join(`
|
|
443
|
+
`),children:d("widget.scriptErrors",{count:x.length})}),E=(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(le,{label:d("action.reload"),onClick:()=>{v([]),p(j=>j+1)}}),(0,z.jsx)(le,{label:d("action.fix"),disabled:c,onClick:()=>{w(d("prompt.fixWidget",{title:k,errors:x.slice(0,8).map(j=>`- ${j}`).join(`
|
|
444
|
+
`)}))}})]})):e.phase==="preparing"&&i?.cssDone&&($=d("widget.preview"));let q=!!i&&i.cssDone,A=b?"final":"preview";return(0,z.jsx)(L,{kind:"widget",title:k,state:S?"stopped":b&&e.phase==="result"?"ready":"generating",status:$,actions:E,notice:P,children:q?(0,z.jsx)(ct,{callId:e.callId,mode:A,css:i.css,html:i.html,jsFunctions:b?i.jsFunctions:void 0,jsExpressions:b?i.jsExpressions:void 0,initialHeight:i.initialHeight,policy:o,title:k,generation:m,sendPrompt:e.sendPrompt,onSending:y,onSent:(j,g)=>l(j?d("bridge.sent"):d("bridge.failed",{reason:g??""})),onErrors:v}):S?(0,z.jsx)(Q,{t:d,message:d("widget.nothingToShow"),detail:h?de(h):void 0}):(0,z.jsx)(et,{messages:i?.placeholderMessages??[],fallback:d("widget.generating"),height:i?.initialHeight})})}function Jn(e){let t=Pe(e);if(Object.keys(t).length!==0)return{title:we(t.title?.value),css:we(t.css?.value),html:we(t.html?.value),jsFunctions:"",jsExpressions:[],initialHeight:Kn(t.initialHeight?.value),placeholderMessages:Kt(t.placeholderMessages?.value),cssDone:t.css?.complete===!0||t.css===void 0&&t.html!==void 0}}function ci(e){return{title:we(e.title),css:we(e.css),html:we(e.html),jsFunctions:we(e.jsFunctions),jsExpressions:Kt(e.jsExpressions),initialHeight:Kn(e.initialHeight),placeholderMessages:Kt(e.placeholderMessages),cssDone:!0}}var we=e=>typeof e=="string"?e:"",Kn=e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,Kt=e=>Array.isArray(e)?e.filter(t=>typeof t=="string"):[];var me=require("react/jsx-runtime");function Yn(e){let t=Nn(e),n=gn(e.sessionId),r=e.turn.start?.time,i=e.turn.end?.time,s=(0,yt.useMemo)(()=>n.filter(o=>yn(o,r,i)&&!t.some(a=>a.callId===o.callId)).map(o=>({kind:"tool-result",callId:o.callId,call:{name:o.toolName,argsRaw:o.argsRaw},content:[],isError:!0,error:{name:"Interrupted",code:"interrupted"}})),[n,r,i,t]);return t.length===0&&s.length===0?null:(0,me.jsxs)("div",{className:"diui-tail",children:[t.map(o=>(0,me.jsx)(Gn,{block:o,t:e.t,sendPrompt:e.sendPrompt,sessionId:e.sessionId},o.callId)),s.map(o=>(0,me.jsx)(Gn,{block:o,t:e.t,sendPrompt:e.sendPrompt,sessionId:e.sessionId},o.callId))]})}function Gn(e){let{block:t}=e;(0,yt.useLayoutEffect)(()=>Te.add(t.callId),[t.callId]);let n=t.call?.name??"";return(0,me.jsx)(n===be?gt:n===ye?mt:pt,{phase:"result",block:t,callId:t.callId,toolName:n,t:e.t,sendPrompt:e.sendPrompt,sessionId:e.sessionId})}function Xn(e){return function(n){return En(n.callId)&&n.phase==="result"?(0,me.jsx)(L,{kind:n.toolName===be?"widget":"render",title:n.t("turn.shownBelow"),state:"ready"}):(0,me.jsx)(e,{...n})}}var ui=["slots","locale","sessions","uiConversation"];async function Zn(e,t,n){let r=e.binding(t)?.session;if(!r)throw new Error("this conversation is not open");let i=r.beginSubmission?.({mode:"queue",text:n,attachments:[]}),s;try{s=await r.prompt([{type:"text",text:n}],"queue",void 0,i?.requestId)}catch(o){throw i?.abandon(),o}if(!s.ok)throw new Error(s.error?.message??"the message was not accepted")}function fi(e){e.effect(()=>e.locale.register(ht,{zh:Bn,en:Vn}),"intelligent-ui: dictionaries"),e.effect(()=>{let n=document.createElement("style");return n.dataset.owner="deepseek-harness-intelligent-ui",n.textContent=Wn,document.head.appendChild(n),()=>n.remove()},"intelligent-ui: styles");let t=n=>({sendPrompt:r=>Zn(e.sessions,n,r),sessionId:n});for(let[n,r]of[[Ee,pt],[ye,mt],[be,gt]])e.slots.inject("tool.call.toolview",()=>e.slots.register({name:"tool.call.toolview",key:n,locale:ht,inject:t},Xn(r)));e.uiConversation.events.register($n),e.slots.inject("conversation.chat.turnTail",()=>e.slots.register({name:"conversation.chat.turnTail",id:"intelligent-ui",order:15,locale:ht,inject:t},Yn))}
|
|
445
445
|
return module.exports; } });
|