@zhama/a2ui-core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builders/index.cjs +2 -2
- package/dist/builders/index.d.cts +2 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.js +2 -2
- package/dist/index.cjs +3 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/types/index.d.cts +5 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/validators/index.cjs +1 -2
- package/dist/validators/index.d.cts +1 -72
- package/dist/validators/index.d.ts +1 -72
- package/dist/validators/index.js +1 -2
- package/package.json +1 -5
package/dist/builders/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var l=0;function i(t="comp"){return `${t}_${Date.now()}_${l++}`}function I(){l=0;}function y(){return l}function p(t,e={}){let{id:n=i("text"),weight:o,usageHint:r,classes:a}=e;return {id:n,component:"Text",text:t,...o!==void 0&&{weight:o},...r&&{usageHint:r},...a&&a.length>0&&{classes:a}}}function S(t,e={}){let{id:n=i("image"),weight:o,fit:r,usageHint:a}=e;return {id:n,component:"Image",url:t,...o!==void 0&&{weight:o},...r&&{fit:r},...a&&{usageHint:a}}}function b(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function T(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function v(t,e={}){let{id:n=i("audio"),weight:o,description:r}=e;return {id:n,component:"AudioPlayer",url:t,...o!==void 0&&{weight:o},...r&&{description:r}}}function D(t,e={}){let{id:n=i("row"),weight:o,alignment:r,distribution:a}=e;return {id:n,component:"Row",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a}}}function P(t,e={}){let{id:n=i("column"),weight:o,alignment:r,distribution:a,classes:s}=e;return {id:n,component:"Column",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a},...s&&s.length>0&&{classes:s}}}function V(t,e={}){let{id:n=i("list"),weight:o,direction:r,alignment:a}=e;return {id:n,component:"List",children:t,...o!==void 0&&{weight:o},...r&&{direction:r},...a&&{alignment:a}}}function A(t,e={}){let{id:n=i("card"),weight:o,classes:r}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o},...r&&r.length>0&&{classes:r}}}function w(t,e={}){let{id:n=i("tabs"),weight:o}=e;return {id:n,component:"Tabs",tabItems:t.map(r=>({title:r.title,child:r.childId})),...o!==void 0&&{weight:o}}}function U(t={}){let{id:e=i("divider"),weight:n,axis:o}=t;return {id:e,component:"Divider",...n!==void 0&&{weight:n},...o&&{axis:o}}}function E(t,e,n={}){let{id:o=i("modal"),weight:r}=n;return {id:o,component:"Modal",entryPointChild:t,contentChild:e,...r!==void 0&&{weight:r}}}function m(t,e,n={}){let{id:o=i("button"),weight:r,primary:a}=n;return {id:o,component:"Button",child:t,action:e,...r!==void 0&&{weight:r},...a!==void 0&&{primary:a}}}function j(t,e,n={}){let{id:o=i("checkbox"),weight:r}=n;return {id:o,component:"CheckBox",label:t,value:e,...r!==void 0&&{weight:r}}}function k(t,e,n={}){let{id:o=i("textfield"),weight:r,usageHint:a,validationRegexp:s}=n;return {id:o,component:"TextField",label:t,...e!==void 0&&{text:e},...r!==void 0&&{weight:r},...a&&{usageHint:a},...s&&{validationRegexp:s}}}function _(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:r,enableTime:a,outputFormat:s,label:u}=e;return {id:n,component:"DateTimeInput",value:t,...o!==void 0&&{weight:o},...r!==void 0&&{enableDate:r},...a!==void 0&&{enableTime:a},...s&&{outputFormat:s},...u&&{label:u}}}function H(t,e,n,o={}){let{id:r=i("choice"),weight:a,label:s}=o;return {id:r,component:"ChoicePicker",options:t,value:e,usageHint:n,...a!==void 0&&{weight:a},...s&&{label:s}}}function B(t,e={}){let{id:n=i("slider"),weight:o,label:r,min:a,max:s}=e;return {id:n,component:"Slider",value:t,...o!==void 0&&{weight:o},...r&&{label:r},...a!==void 0&&{min:a},...s!==void 0&&{max:s}}}function N(t,e,n={}){let o=n.textId??i("btn_text"),r=p(t,{id:o}),a=m(o,e,n);return [r,a]}function R(t,e={}){return p(t,{...e,usageHint:"h1"})}function L(t,e={}){return p(t,{...e,usageHint:"h2"})}function F(t,e={}){return p(t,{...e,usageHint:"h3"})}function $(t,e={}){return p(t,{...e,usageHint:"h4"})}function G(t,e={}){return p(t,{...e,usageHint:"h5"})}function z(t,e={}){return p(t,{...e,usageHint:"caption"})}function J(t,e={}){return p(t,{...e,usageHint:"body"})}var d="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function f(t,e=d){return {createSurface:{surfaceId:t,catalogId:e}}}function C(t,e){return {updateComponents:{surfaceId:t,components:e}}}function x(t,e,n,o="replace"){return {updateDataModel:{surfaceId:t,...n&&{path:n},op:o,...o!=="remove"&&{value:e}}}}function W(t){return {deleteSurface:{surfaceId:t}}}function X(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:r}=t,a=[f(e,n),C(e,o)];return r&&a.push(x(e,r)),a}function Y(t){return t.map(e=>JSON.stringify(e)).join(`
|
|
2
2
|
`)}function K(t){return t.split(`
|
|
3
|
-
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,r]of Object.entries(t)){let a=e?`${e}/${o}`:`/${o}`;n.push(c(a,r));}return n}function c(t,e){if(e==null)return {key:t,valueString:""};if(typeof e=="string")return {key:t,valueString:e};if(typeof e=="number")return {key:t,valueNumber:e};if(typeof e=="boolean")return {key:t,valueBoolean:e};if(Array.isArray(e))return {key:t,valueMap:e.map((n,o)=>c(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,r]of Object.entries(e))n.push(c(o,r));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function h(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,r]of Object.entries(e)){let a=new RegExp(`^/${o}(/|$)`);a.test(n)&&(n=n.replace(a,`/${r}$1`));}return n}function Q(t,e="",n=O){let o=[];for(let r of t){let a=r.path.startsWith("/")?r.path:`${e}/${r.path}`,s=h(a,n);if(r.value!==null&&typeof r.value=="object"&&!Array.isArray(r.value)){let u=g(r.value,s);o.push(...u);}else o.push(c(s,r.value));}return o}function g(t,e){let n=[];for(let[o,r]of Object.entries(t)){let a=`${e}/${o}`;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=g(r,a);n.push(...s);}else n.push(c(a,r));}return n}function M(t){let e={};for(let n of t){let o=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?e[o]=n.valueString:n.valueNumber!==void 0?e[o]=n.valueNumber:n.valueBoolean!==void 0?e[o]=n.valueBoolean:n.valueMap!==void 0&&(e[o]=M(n.valueMap));}return e}exports.DEFAULT_PATH_MAPPINGS=O;exports.audioPlayer=v;exports.body=J;exports.button=
|
|
3
|
+
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,r]of Object.entries(t)){let a=e?`${e}/${o}`:`/${o}`;n.push(c(a,r));}return n}function c(t,e){if(e==null)return {key:t,valueString:""};if(typeof e=="string")return {key:t,valueString:e};if(typeof e=="number")return {key:t,valueNumber:e};if(typeof e=="boolean")return {key:t,valueBoolean:e};if(Array.isArray(e))return {key:t,valueMap:e.map((n,o)=>c(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,r]of Object.entries(e))n.push(c(o,r));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function h(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,r]of Object.entries(e)){let a=new RegExp(`^/${o}(/|$)`);a.test(n)&&(n=n.replace(a,`/${r}$1`));}return n}function Q(t,e="",n=O){let o=[];for(let r of t){let a=r.path.startsWith("/")?r.path:`${e}/${r.path}`,s=h(a,n);if(r.value!==null&&typeof r.value=="object"&&!Array.isArray(r.value)){let u=g(r.value,s);o.push(...u);}else o.push(c(s,r.value));}return o}function g(t,e){let n=[];for(let[o,r]of Object.entries(t)){let a=`${e}/${o}`;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=g(r,a);n.push(...s);}else n.push(c(a,r));}return n}function M(t){let e={};for(let n of t){let o=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?e[o]=n.valueString:n.valueNumber!==void 0?e[o]=n.valueNumber:n.valueBoolean!==void 0?e[o]=n.valueBoolean:n.valueMap!==void 0&&(e[o]=M(n.valueMap));}return e}exports.DEFAULT_PATH_MAPPINGS=O;exports.audioPlayer=v;exports.body=J;exports.button=m;exports.caption=z;exports.card=A;exports.checkbox=j;exports.choicePicker=H;exports.column=P;exports.createSurface=f;exports.createV09Messages=X;exports.dateTimeInput=_;exports.deleteSurface=W;exports.divider=U;exports.flattenObjectToValueMap=g;exports.generateId=i;exports.getIdCounter=y;exports.h1=R;exports.h2=L;exports.h3=F;exports.h4=$;exports.h5=G;exports.icon=b;exports.image=S;exports.jsonlToMessages=K;exports.list=V;exports.messagesToJsonl=Y;exports.modal=E;exports.normalizePath=h;exports.objectToValueMap=q;exports.resetIdCounter=I;exports.row=D;exports.slider=B;exports.tabs=w;exports.text=p;exports.textButton=N;exports.textField=k;exports.updateComponents=C;exports.updateDataModel=x;exports.updatesToValueMap=Q;exports.valueMapToObject=M;exports.valueToValueMap=c;exports.video=T;
|
package/dist/builders/index.d.ts
CHANGED
package/dist/builders/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=0;function i(t="comp"){return `${t}_${Date.now()}_${l++}`}function I(){l=0;}function y(){return l}function p(t,e={}){let{id:n=i("text"),weight:o,usageHint:r,classes:a}=e;return {id:n,component:"Text",text:t,...o!==void 0&&{weight:o},...r&&{usageHint:r},...a&&a.length>0&&{classes:a}}}function S(t,e={}){let{id:n=i("image"),weight:o,fit:r,usageHint:a}=e;return {id:n,component:"Image",url:t,...o!==void 0&&{weight:o},...r&&{fit:r},...a&&{usageHint:a}}}function b(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function T(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function v(t,e={}){let{id:n=i("audio"),weight:o,description:r}=e;return {id:n,component:"AudioPlayer",url:t,...o!==void 0&&{weight:o},...r&&{description:r}}}function D(t,e={}){let{id:n=i("row"),weight:o,alignment:r,distribution:a}=e;return {id:n,component:"Row",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a}}}function P(t,e={}){let{id:n=i("column"),weight:o,alignment:r,distribution:a,classes:s}=e;return {id:n,component:"Column",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a},...s&&s.length>0&&{classes:s}}}function V(t,e={}){let{id:n=i("list"),weight:o,direction:r,alignment:a}=e;return {id:n,component:"List",children:t,...o!==void 0&&{weight:o},...r&&{direction:r},...a&&{alignment:a}}}function A(t,e={}){let{id:n=i("card"),weight:o,classes:r}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o},...r&&r.length>0&&{classes:r}}}function w(t,e={}){let{id:n=i("tabs"),weight:o}=e;return {id:n,component:"Tabs",tabItems:t.map(r=>({title:r.title,child:r.childId})),...o!==void 0&&{weight:o}}}function U(t={}){let{id:e=i("divider"),weight:n,axis:o}=t;return {id:e,component:"Divider",...n!==void 0&&{weight:n},...o&&{axis:o}}}function E(t,e,n={}){let{id:o=i("modal"),weight:r}=n;return {id:o,component:"Modal",entryPointChild:t,contentChild:e,...r!==void 0&&{weight:r}}}function m(t,e,n={}){let{id:o=i("button"),weight:r,primary:a}=n;return {id:o,component:"Button",child:t,action:e,...r!==void 0&&{weight:r},...a!==void 0&&{primary:a}}}function j(t,e,n={}){let{id:o=i("checkbox"),weight:r}=n;return {id:o,component:"CheckBox",label:t,value:e,...r!==void 0&&{weight:r}}}function k(t,e,n={}){let{id:o=i("textfield"),weight:r,usageHint:a,validationRegexp:s}=n;return {id:o,component:"TextField",label:t,...e!==void 0&&{text:e},...r!==void 0&&{weight:r},...a&&{usageHint:a},...s&&{validationRegexp:s}}}function _(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:r,enableTime:a,outputFormat:s,label:u}=e;return {id:n,component:"DateTimeInput",value:t,...o!==void 0&&{weight:o},...r!==void 0&&{enableDate:r},...a!==void 0&&{enableTime:a},...s&&{outputFormat:s},...u&&{label:u}}}function H(t,e,n,o={}){let{id:r=i("choice"),weight:a,label:s}=o;return {id:r,component:"ChoicePicker",options:t,value:e,usageHint:n,...a!==void 0&&{weight:a},...s&&{label:s}}}function B(t,e={}){let{id:n=i("slider"),weight:o,label:r,min:a,max:s}=e;return {id:n,component:"Slider",value:t,...o!==void 0&&{weight:o},...r&&{label:r},...a!==void 0&&{min:a},...s!==void 0&&{max:s}}}function N(t,e,n={}){let o=n.textId??i("btn_text"),r=p(t,{id:o}),a=m(o,e,n);return [r,a]}function R(t,e={}){return p(t,{...e,usageHint:"h1"})}function L(t,e={}){return p(t,{...e,usageHint:"h2"})}function F(t,e={}){return p(t,{...e,usageHint:"h3"})}function $(t,e={}){return p(t,{...e,usageHint:"h4"})}function G(t,e={}){return p(t,{...e,usageHint:"h5"})}function z(t,e={}){return p(t,{...e,usageHint:"caption"})}function J(t,e={}){return p(t,{...e,usageHint:"body"})}var d="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function f(t,e=d){return {createSurface:{surfaceId:t,catalogId:e}}}function C(t,e){return {updateComponents:{surfaceId:t,components:e}}}function x(t,e,n,o="replace"){return {updateDataModel:{surfaceId:t,...n&&{path:n},op:o,...o!=="remove"&&{value:e}}}}function W(t){return {deleteSurface:{surfaceId:t}}}function X(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:r}=t,a=[f(e,n),C(e,o)];return r&&a.push(x(e,r)),a}function Y(t){return t.map(e=>JSON.stringify(e)).join(`
|
|
2
2
|
`)}function K(t){return t.split(`
|
|
3
|
-
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,r]of Object.entries(t)){let a=e?`${e}/${o}`:`/${o}`;n.push(c(a,r));}return n}function c(t,e){if(e==null)return {key:t,valueString:""};if(typeof e=="string")return {key:t,valueString:e};if(typeof e=="number")return {key:t,valueNumber:e};if(typeof e=="boolean")return {key:t,valueBoolean:e};if(Array.isArray(e))return {key:t,valueMap:e.map((n,o)=>c(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,r]of Object.entries(e))n.push(c(o,r));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function h(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,r]of Object.entries(e)){let a=new RegExp(`^/${o}(/|$)`);a.test(n)&&(n=n.replace(a,`/${r}$1`));}return n}function Q(t,e="",n=O){let o=[];for(let r of t){let a=r.path.startsWith("/")?r.path:`${e}/${r.path}`,s=h(a,n);if(r.value!==null&&typeof r.value=="object"&&!Array.isArray(r.value)){let u=g(r.value,s);o.push(...u);}else o.push(c(s,r.value));}return o}function g(t,e){let n=[];for(let[o,r]of Object.entries(t)){let a=`${e}/${o}`;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=g(r,a);n.push(...s);}else n.push(c(a,r));}return n}function M(t){let e={};for(let n of t){let o=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?e[o]=n.valueString:n.valueNumber!==void 0?e[o]=n.valueNumber:n.valueBoolean!==void 0?e[o]=n.valueBoolean:n.valueMap!==void 0&&(e[o]=M(n.valueMap));}return e}export{O as DEFAULT_PATH_MAPPINGS,v as audioPlayer,J as body,
|
|
3
|
+
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,r]of Object.entries(t)){let a=e?`${e}/${o}`:`/${o}`;n.push(c(a,r));}return n}function c(t,e){if(e==null)return {key:t,valueString:""};if(typeof e=="string")return {key:t,valueString:e};if(typeof e=="number")return {key:t,valueNumber:e};if(typeof e=="boolean")return {key:t,valueBoolean:e};if(Array.isArray(e))return {key:t,valueMap:e.map((n,o)=>c(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,r]of Object.entries(e))n.push(c(o,r));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function h(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,r]of Object.entries(e)){let a=new RegExp(`^/${o}(/|$)`);a.test(n)&&(n=n.replace(a,`/${r}$1`));}return n}function Q(t,e="",n=O){let o=[];for(let r of t){let a=r.path.startsWith("/")?r.path:`${e}/${r.path}`,s=h(a,n);if(r.value!==null&&typeof r.value=="object"&&!Array.isArray(r.value)){let u=g(r.value,s);o.push(...u);}else o.push(c(s,r.value));}return o}function g(t,e){let n=[];for(let[o,r]of Object.entries(t)){let a=`${e}/${o}`;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=g(r,a);n.push(...s);}else n.push(c(a,r));}return n}function M(t){let e={};for(let n of t){let o=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?e[o]=n.valueString:n.valueNumber!==void 0?e[o]=n.valueNumber:n.valueBoolean!==void 0?e[o]=n.valueBoolean:n.valueMap!==void 0&&(e[o]=M(n.valueMap));}return e}export{O as DEFAULT_PATH_MAPPINGS,v as audioPlayer,J as body,m as button,z as caption,A as card,j as checkbox,H as choicePicker,P as column,f as createSurface,X as createV09Messages,_ as dateTimeInput,W as deleteSurface,U as divider,g as flattenObjectToValueMap,i as generateId,y as getIdCounter,R as h1,L as h2,F as h3,$ as h4,G as h5,b as icon,S as image,K as jsonlToMessages,V as list,Y as messagesToJsonl,E as modal,h as normalizePath,q as objectToValueMap,I as resetIdCounter,D as row,B as slider,w as tabs,p as text,N as textButton,k as textField,C as updateComponents,x as updateDataModel,Q as updatesToValueMap,M as valueMapToObject,c as valueToValueMap,T as video};
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
`)}function
|
|
3
|
-
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var M={};function ue(e,t=""){let n=[];for(let[r,o]of Object.entries(e)){let a=t?`${t}/${r}`:`/${r}`;n.push(l(a,o));}return n}function l(e,t){if(t==null)return {key:e,valueString:""};if(typeof t=="string")return {key:e,valueString:t};if(typeof t=="number")return {key:e,valueNumber:t};if(typeof t=="boolean")return {key:e,valueBoolean:t};if(Array.isArray(t))return {key:e,valueMap:t.map((n,r)=>l(String(r),n))};if(typeof t=="object"){let n=[];for(let[r,o]of Object.entries(t))n.push(l(r,o));return {key:e,valueMap:n}}return {key:e,valueString:String(t)}}function P(e,t={}){let n=e.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[r,o]of Object.entries(t)){let a=new RegExp(`^/${r}(/|$)`);a.test(n)&&(n=n.replace(a,`/${o}$1`));}return n}function me(e,t="",n=M){let r=[];for(let o of e){let a=o.path.startsWith("/")?o.path:`${t}/${o.path}`,i=P(a,n);if(o.value!==null&&typeof o.value=="object"&&!Array.isArray(o.value)){let p=T(o.value,i);r.push(...p);}else r.push(l(i,o.value));}return r}function T(e,t){let n=[];for(let[r,o]of Object.entries(e)){let a=`${t}/${r}`;if(o!==null&&typeof o=="object"&&!Array.isArray(o)){let i=T(o,a);n.push(...i);}else n.push(l(a,o));}return n}function D(e){let t={};for(let n of e){let r=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?t[r]=n.valueString:n.valueNumber!==void 0?t[r]=n.valueNumber:n.valueBoolean!==void 0?t[r]=n.valueBoolean:n.valueMap!==void 0&&(t[r]=D(n.valueMap));}return t}var we=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function j(e,t={}){let n=[],r=[];if("createSurface"in e){let{createSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),o.catalogId||n.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):_e(o.components,n,r,t);}else if("updateDataModel"in e){let{updateDataModel:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),o.op&&!["add","replace","remove"].includes(o.op)&&n.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),o.op==="remove"&&o.value!==void 0&&r.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),o.op!=="remove"&&o.value===void 0&&o.op==="add"&&n.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:n.length===0,errors:n,warnings:r}}function $(e,t={}){return j(e,t)}function fe(e,t={}){let n=[],r=[];for(let o=0;o<e.length;o++){let a=e[o];if(!a)continue;let i=$(a,t);for(let p of i.errors)n.push({...p,path:`messages[${o}].${p.path??""}`});for(let p of i.warnings)r.push({...p,path:`messages[${o}].${p.path??""}`});}return {valid:n.length===0,errors:n,warnings:r}}function _e(e,t,n,r){let o=new Set,a=false;for(let i=0;i<e.length;i++){let p=e[i];if(!p)continue;let x=`updateComponents.components[${i}]`;p.id?(o.has(p.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${p.id}`,path:`${x}.id`}),o.add(p.id),p.id==="root"&&(a=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${x}.id`}),p.component?r.strict&&!we.includes(p.component)&&r.allowedComponents&&!r.allowedComponents.includes(p.component)&&n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${p.component}`,path:`${x}.component`}):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${x}.component`});}!a&&r.strict&&n.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}var he={title:"A2UI (Agent to UI) Client-to-Server Event Schema",description:"Describes a JSON payload for a client-to-server event message.",type:"object",minProperties:1,maxProperties:1,properties:{userAction:{type:"object",description:"Reports a user-initiated action from a component.",properties:{name:{type:"string",description:"The name of the action, taken from the component's action.name property."},surfaceId:{type:"string",description:"The id of the surface where the event originated."},sourceComponentId:{type:"string",description:"The id of the component that triggered the event."},timestamp:{type:"string",format:"date-time",description:"An ISO 8601 timestamp of when the event occurred."},context:{type:"object",description:"A JSON object containing the key-value pairs from the component's action.context, after resolving all data bindings.",additionalProperties:true}},required:["name","surfaceId","sourceComponentId","timestamp","context"]},error:{description:"Reports a client-side error.",oneOf:[{type:"object",title:"Validation Failed Error",properties:{code:{const:"VALIDATION_FAILED"},surfaceId:{type:"string",description:"The id of the surface where the error occurred."},path:{type:"string",description:"The JSON pointer to the field that failed validation (e.g. '/components/0/text')."},message:{type:"string",description:"A short one-sentence description of why validation failed."}},required:["code","path","message","surfaceId"]},{type:"object",title:"Generic Error",properties:{code:{not:{const:"VALIDATION_FAILED"}},message:{type:"string",description:"A short one-sentence description of why the error occurred."},surfaceId:{type:"string",description:"The id of the surface where the error occurred."}},required:["code","surfaceId","message"],additionalProperties:true}]}},oneOf:[{required:["userAction"]},{required:["clientUiCapabilities"]},{required:["error"]}]};var ge={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/common_types.json",title:"A2UI Common Types",description:"Common type definitions used across A2UI schemas.",$defs:{stringOrPath:{description:"Represents a value that can be either a literal string or a path to a value in the data model.",oneOf:[{type:"string"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},numberOrPath:{description:"Represents a value that can be either a literal number or a path to a value in the data model.",oneOf:[{type:"number"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},booleanOrPath:{description:"Represents a value that can be either a literal boolean or a path to a value in the data model.",oneOf:[{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},stringArrayOrPath:{description:"Represents a value that can be either a literal array of strings or a path to a value in the data model.",oneOf:[{type:"array",items:{type:"string"}},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},id:{type:"string",description:"The unique identifier for this component."},ComponentCommon:{type:"object",properties:{id:{$ref:"#/$defs/id"},weight:{type:"number",description:"The relative weight of this component within a Row or Column. This is similar to the CSS 'flex-grow' property."}},required:["id"]},contextValue:{description:"A value that can be a string, number, boolean, or a path to a value.",oneOf:[{type:"string"},{type:"number"},{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},childrenProperty:{oneOf:[{type:"array",items:{type:"string"},description:"A static list of child component IDs."},{type:"object",description:"A template for generating a dynamic list of children from a data model list. The `componentId` is the component to use as a template.",properties:{componentId:{$ref:"#/$defs/id"},path:{type:"string",description:"The path to the list of component property objects in the data model."}},required:["componentId","path"],additionalProperties:false}]}}};var ye={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/server_to_client.json",title:"A2UI Message Schema",description:"Describes a JSON payload for an A2UI (Agent to UI) message, which is used to dynamically construct and update user interfaces.",type:"object",oneOf:[{$ref:"#/$defs/CreateSurfaceMessage"},{$ref:"#/$defs/UpdateComponentsMessage"},{$ref:"#/$defs/UpdateDataModelMessage"},{$ref:"#/$defs/DeleteSurfaceMessage"}],$defs:{CreateSurfaceMessage:{properties:{createSurface:{type:"object",description:"Signals the client to create a new surface and begin rendering it. When this message is sent, the client will expect 'updateComponents' and/or 'updateDataModel' messages for the same surfaceId that define the component tree.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be rendered."},catalogId:{title:"Catalog ID",description:"A string that uniquely identifies this catalog. It is recommended to prefix this with an internet domain that you own, to avoid conflicts e.g. mycompany.com:somecatalog'.",type:"string"}},required:["surfaceId","catalogId"],additionalProperties:false}},required:["createSurface"],additionalProperties:false},UpdateComponentsMessage:{properties:{updateComponents:{type:"object",description:"Updates a surface with a new set of components. This message can be sent multiple times to update the component tree of an existing surface. One of the components in one of the components lists MUST have an 'id' of 'root' to serve as the root of the component tree. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be updated."},components:{type:"array",description:"A list containing all UI components for the surface.",minItems:1,items:{$ref:"standard_catalog_definition.json#/$defs/anyComponent"}}},required:["surfaceId","components"],additionalProperties:false}},required:["updateComponents"],additionalProperties:false},UpdateDataModelMessage:{properties:{updateDataModel:{type:"object",description:"Updates the data model for an existing surface. This message can be sent multiple times to update the data model. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface this data model update applies to."},path:{type:"string",description:"An optional path to a location within the data model (e.g., '/user/name'). If omitted, or set to '/', refers to the entire data model."},op:{type:"string",description:"The operation to perform on the data model. Defaults to 'replace' if omitted.",enum:["add","replace","remove"]},value:{description:"The data to be updated in the data model. Required for 'add' and 'replace' operations. Not allowed for 'remove' operation.",additionalProperties:true}},required:["surfaceId"],additionalProperties:false}},required:["updateDataModel"],additionalProperties:false},DeleteSurfaceMessage:{properties:{deleteSurface:{type:"object",description:"Signals the client to delete the surface identified by 'surfaceId'. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be deleted."}},required:["surfaceId"],additionalProperties:false}},required:["deleteSurface"],additionalProperties:false}}};var Ce={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/standard_catalog_definition.json",title:"A2UI Component Catalog",description:"Definitions for the standard catalog of A2UI components.",$defs:{Theme:{type:"object",description:"Theming information for the UI.",properties:{font:{type:"string",description:"The primary font for the UI."},primaryColor:{type:"string",description:"The primary UI color as a hexadecimal code (e.g., '#00BFFF').",pattern:"^#[0-9a-fA-F]{6}$"}},additionalProperties:false},anyComponent:{oneOf:[{$ref:"#/$defs/Text"},{$ref:"#/$defs/Image"},{$ref:"#/$defs/Icon"},{$ref:"#/$defs/Video"},{$ref:"#/$defs/AudioPlayer"},{$ref:"#/$defs/Row"},{$ref:"#/$defs/Column"},{$ref:"#/$defs/List"},{$ref:"#/$defs/Card"},{$ref:"#/$defs/Tabs"},{$ref:"#/$defs/Divider"},{$ref:"#/$defs/Modal"},{$ref:"#/$defs/Button"},{$ref:"#/$defs/CheckBox"},{$ref:"#/$defs/TextField"},{$ref:"#/$defs/DateTimeInput"},{$ref:"#/$defs/ChoicePicker"},{$ref:"#/$defs/Slider"}],discriminator:{propertyName:"component"}},Text:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Text"},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text content to display. While simple Markdown formatting is supported (i.e. without HTML, images, or links), utilizing dedicated UI components is generally preferred for a richer and more structured presentation."},usageHint:{type:"string",description:"A hint for the base text style.",enum:["h1","h2","h3","h4","h5","caption","body"]}},required:["component","text"]}],unevaluatedProperties:false},Image:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Image"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the image to display."},fit:{type:"string",description:"Specifies how the image should be resized to fit its container. This corresponds to the CSS 'object-fit' property.",enum:["contain","cover","fill","none","scale-down"]},usageHint:{type:"string",description:"A hint for the image size and style.",enum:["icon","avatar","smallFeature","mediumFeature","largeFeature","header"]}},required:["component","url"]}],unevaluatedProperties:false},Icon:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Icon"},name:{description:"The name of the icon to display.",oneOf:[{type:"string",enum:["accountCircle","add","arrowBack","arrowForward","attachFile","calendarToday","call","camera","check","close","delete","download","edit","event","error","fastForward","favorite","favoriteOff","folder","help","home","info","locationOn","lock","lockOpen","mail","menu","moreVert","moreHoriz","notificationsOff","notifications","pause","payment","person","phone","photo","play","print","refresh","rewind","search","send","settings","share","shoppingCart","skipNext","skipPrevious","star","starHalf","starOff","stop","upload","visibility","visibilityOff","volumeDown","volumeMute","volumeOff","volumeUp","warning"]},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]}},required:["component","name"]}],unevaluatedProperties:false},Video:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Video"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the video to display."}},required:["component","url"]}],unevaluatedProperties:false},AudioPlayer:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"AudioPlayer"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the audio to be played."},description:{description:"A description of the audio, such as a title or summary.",$ref:"common_types.json#/$defs/stringOrPath"}},required:["component","url"]}],unevaluatedProperties:false},Row:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children horizontally. To create a grid layout, nest Columns within this Row.",properties:{component:{const:"Row"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (horizontally). Use 'spaceBetween' to push items to the edges, or 'start'/'end'/'center' to pack them together.",enum:["center","end","spaceAround","spaceBetween","spaceEvenly","start","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (vertically). This is similar to the CSS 'align-items' property, but uses camelCase values (e.g., 'start').",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Column:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children vertically. To create a grid layout, nest Rows within this Column.",properties:{component:{const:"Column"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (vertically). Use 'spaceBetween' to push items to the edges (e.g. header at top, footer at bottom), or 'start'/'end'/'center' to pack them together.",enum:["start","center","end","spaceBetween","spaceAround","spaceEvenly","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (horizontally). This is similar to the CSS 'align-items' property.",enum:["center","end","start","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},List:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"List"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list.",$ref:"common_types.json#/$defs/childrenProperty"},direction:{type:"string",description:"The direction in which the list items are laid out.",enum:["vertical","horizontal"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis.",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Card:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Card"},child:{type:"string",description:"The ID of the single child component to be rendered inside the card. To display multiple elements, you MUST wrap them in a layout component (like Column or Row) and pass that container's ID here. Do NOT pass multiple IDs or a non-existent ID. Do NOT define the child component inline."}},required:["component","child"]}],unevaluatedProperties:false},Tabs:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Tabs"},tabItems:{type:"array",description:"An array of objects, where each object defines a tab with a title and a child component.",items:{type:"object",properties:{title:{description:"The tab title.",$ref:"common_types.json#/$defs/stringOrPath"},child:{type:"string",description:"The ID of the child component. Do NOT define the component inline."}},required:["title","child"],additionalProperties:false}}},required:["component","tabItems"]}],unevaluatedProperties:false},Divider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Divider"},axis:{type:"string",description:"The orientation of the divider.",enum:["horizontal","vertical"]}},required:["component"]}],unevaluatedProperties:false},Modal:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Modal"},entryPointChild:{type:"string",description:"The ID of the component that opens the modal when interacted with (e.g., a button). Do NOT define the component inline."},contentChild:{type:"string",description:"The ID of the component to be displayed inside the modal. Do NOT define the component inline."}},required:["component","entryPointChild","contentChild"]}],unevaluatedProperties:false},Button:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Button"},child:{type:"string",description:"The ID of the child component. Use a 'Text' component for a labeled button. Only use an 'Icon' if the requirements explicitly ask for an icon-only button. Do NOT define the child component inline."},primary:{type:"boolean",description:"Indicates if this button should be styled as the primary action."},action:{type:"object",description:"The client-side action to be dispatched when the button is clicked. It includes the action's name and an optional context payload.",properties:{name:{type:"string"},context:{type:"object",description:"A JSON object containing the key-value pairs for the action context. Values can be literals or paths. Use literal values unless the value must be dynamically bound to the data model. Do NOT use paths for static IDs.",additionalProperties:{$ref:"common_types.json#/$defs/contextValue"}}},required:["name"],additionalProperties:false}},required:["component","child","action"]}],unevaluatedProperties:false},CheckBox:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"CheckBox"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text to display next to the checkbox."},value:{$ref:"common_types.json#/$defs/booleanOrPath",description:"The current state of the checkbox (true for checked, false for unchecked)."}},required:["component","label","value"]}],unevaluatedProperties:false},TextField:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"TextField"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The value of the text field."},usageHint:{type:"string",description:"The type of input field to display.",enum:["longText","number","shortText","obscured"]},validationRegexp:{type:"string",description:"A regular expression used for client-side validation of the input."}},required:["component","label"]}],unevaluatedProperties:false},DateTimeInput:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"DateTimeInput"},value:{$ref:"common_types.json#/$defs/stringOrPath",description:"The selected date and/or time value in ISO 8601 format. If not yet set, initialize with an empty string."},enableDate:{type:"boolean",description:"If true, allows the user to select a date."},enableTime:{type:"boolean",description:"If true, allows the user to select a time."},outputFormat:{type:"string",description:"The desired format for the output string after a date or time is selected."},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."}},required:["component","value"]}],unevaluatedProperties:false},ChoicePicker:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A component that allows selecting one or more options from a list.",properties:{component:{const:"ChoicePicker"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the group of options."},usageHint:{type:"string",description:"A hint for how the choice picker should be displayed and behave.",enum:["multipleSelection","mutuallyExclusive"]},options:{type:"array",description:"The list of available options to choose from.",items:{type:"object",properties:{label:{description:"The text to display for this option.",$ref:"common_types.json#/$defs/stringOrPath"},value:{type:"string",description:"The stable value associated with this option."}},required:["label","value"],additionalProperties:false}},value:{$ref:"common_types.json#/$defs/stringArrayOrPath",description:"The list of currently selected values. This should be bound to a string array in the data model."}},required:["component","options","value","usageHint"]}],unevaluatedProperties:false},Slider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Slider"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the slider."},min:{type:"number",description:"The minimum value of the slider."},max:{type:"number",description:"The maximum value of the slider."},value:{$ref:"common_types.json#/$defs/numberOrPath",description:"The current value of the slider."}},required:["component","value"]}],unevaluatedProperties:false}}};var y=class{constructor(){S(this,"ajv");S(this,"serverToClientValidator");S(this,"clientToServerValidator");this.ajv=new ke__default.default({allErrors:true,strict:false}),qe__default.default(this.ajv),this.ajv.addSchema(ge,"common_types.json"),this.ajv.addSchema(Ce,"standard_catalog_definition.json"),this.serverToClientValidator=this.ajv.compile(ye),this.clientToServerValidator=this.ajv.compile(he);}validateServerToClientMessage(t){return this.serverToClientValidator(t)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.serverToClientValidator.errors||[])}}validateClientToServerMessage(t){return this.clientToServerValidator(t)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.clientToServerValidator.errors||[])}}validateMessages(t){let n=[];for(let r=0;r<t.length;r++){let o=this.validateServerToClientMessage(t[r]);o.valid||n.push(...o.errors.map(a=>({...a,path:`/messages/${r}${a.path}`})));}return {valid:n.length===0,errors:n}}formatErrors(t){return t.map(n=>({path:n.instancePath||"/",message:n.message||"Validation failed",keyword:n.keyword,expected:n.params,actual:void 0}))}},V=null;function C(){return V||(V=new y),V}function Ie(e){return C().validateServerToClientMessage(e)}function xe(e){return C().validateClientToServerMessage(e)}function Se(e){return C().validateMessages(e)}function A(e){return typeof e=="object"&&e!==null&&"path"in e}function Fe(e){if(!A(e))return e}function Be(e){if(A(e))return e.path}function Le(e){return {path:e}}function Oe(e,t){let n={...e};for(let r of Object.keys(t)){let o=t[r],a=n[r];o!==void 0&&typeof o=="object"&&o!==null&&!Array.isArray(o)&&typeof a=="object"&&a!==null&&!Array.isArray(a)?n[r]=Oe(a,o):o!==void 0&&(n[r]=o);}return n}function He(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return (e==="x"?t:t&3|8).toString(16)})}var d={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},w=0;function I(e="surface"){return w++,`${e}-${Date.now()}-${w}`}function Te(){w=0;}function u(e,t,n){let r=n??I();return t.find(i=>i.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[m(r),f(r,t)],surfaceId:r}}function be(e,t,n,r){let o=r??I();return {messages:[m(o),f(o,t),g(o,n)],surfaceId:o}}function ve(e){return O(e)}function Me(e,t){return u(e,t,d.CHAT)}function Pe(e,t){return u(e,t,d.RECOMMENDATION)}function De(e,t){return u(e,t,d.INPUT_FORM)}function je(e,t){return u(e,t,d.ORCHESTRATION)}function $e(e,t){return u(e,t,d.STATUS)}
|
|
4
|
-
exports.A2UISchemaValidator=y;exports.A2UI_EXTENSION_URI=U;exports.A2UI_MIME_TYPE=E;exports.DEFAULT_PATH_MAPPINGS=M;exports.STANDARD_CATALOG_ID=h;exports.SURFACE_IDS=d;exports.audioPlayer=B;exports.body=pe;exports.button=v;exports.caption=se;exports.card=W;exports.checkbox=X;exports.choicePicker=Z;exports.column=H;exports.createA2UISurface=u;exports.createA2UISurfaceWithData=be;exports.createChatSurface=Me;exports.createDeleteSurfaceMessage=ve;exports.createInputFormSurface=De;exports.createOrchestrationSurface=je;exports.createRecommendationSurface=Pe;exports.createStatusSurface=$e;exports.createSurface=m;exports.createV09Messages=ce;exports.dateTimeInput=Q;exports.deepMerge=Oe;exports.deleteSurface=O;exports.divider=J;exports.flattenObjectToValueMap=T;exports.generateId=s;exports.generateSurfaceId=I;exports.getIdCounter=N;exports.getLiteralValue=Fe;exports.getPathValue=Be;exports.getSchemaValidator=C;exports.h1=ne;exports.h2=oe;exports.h3=re;exports.h4=ae;exports.h5=ie;exports.icon=q;exports.image=k;exports.isPathBinding=A;exports.isV09Message=_;exports.jsonlToMessages=le;exports.list=G;exports.messagesToJsonl=de;exports.modal=Y;exports.normalizePath=P;exports.objectToValueMap=ue;exports.path=Le;exports.resetIdCounter=R;exports.resetSurfaceIdCounter=Te;exports.row=L;exports.slider=ee;exports.tabs=z;exports.text=c;exports.textButton=te;exports.textField=K;exports.updateComponents=f;exports.updateDataModel=g;exports.updatesToValueMap=me;exports.uuid=He;exports.validateClientMessage=xe;exports.validateMessage=$;exports.validateMessages=fe;exports.validateMessagesWithSchema=Se;exports.validateV09Message=j;exports.validateWithSchema=Ie;exports.valueMapToObject=D;exports.valueToValueMap=l;exports.video=F;
|
|
1
|
+
'use strict';function A(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}var g="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";var E="https://a2ui.dev/specification/0.9",N="application/json+a2ui";var O=0;function s(e="comp"){return `${e}_${Date.now()}_${O++}`}function R(){O=0;}function _(){return O}function c(e,t={}){let{id:o=s("text"),weight:a,usageHint:n,classes:r}=t;return {id:o,component:"Text",text:e,...a!==void 0&&{weight:a},...n&&{usageHint:n},...r&&r.length>0&&{classes:r}}}function U(e,t={}){let{id:o=s("image"),weight:a,fit:n,usageHint:r}=t;return {id:o,component:"Image",url:e,...a!==void 0&&{weight:a},...n&&{fit:n},...r&&{usageHint:r}}}function w(e,t={}){let{id:o=s("icon"),weight:a}=t;return {id:o,component:"Icon",name:e,...a!==void 0&&{weight:a}}}function k(e,t={}){let{id:o=s("video"),weight:a}=t;return {id:o,component:"Video",url:e,...a!==void 0&&{weight:a}}}function j(e,t={}){let{id:o=s("audio"),weight:a,description:n}=t;return {id:o,component:"AudioPlayer",url:e,...a!==void 0&&{weight:a},...n&&{description:n}}}function F(e,t={}){let{id:o=s("row"),weight:a,alignment:n,distribution:r}=t;return {id:o,component:"Row",children:e,...a!==void 0&&{weight:a},...n&&{alignment:n},...r&&{distribution:r}}}function B(e,t={}){let{id:o=s("column"),weight:a,alignment:n,distribution:r,classes:i}=t;return {id:o,component:"Column",children:e,...a!==void 0&&{weight:a},...n&&{alignment:n},...r&&{distribution:r},...i&&i.length>0&&{classes:i}}}function L(e,t={}){let{id:o=s("list"),weight:a,direction:n,alignment:r}=t;return {id:o,component:"List",children:e,...a!==void 0&&{weight:a},...n&&{direction:n},...r&&{alignment:r}}}function H(e,t={}){let{id:o=s("card"),weight:a,classes:n}=t;return {id:o,component:"Card",child:e,...a!==void 0&&{weight:a},...n&&n.length>0&&{classes:n}}}function $(e,t={}){let{id:o=s("tabs"),weight:a}=t;return {id:o,component:"Tabs",tabItems:e.map(n=>({title:n.title,child:n.childId})),...a!==void 0&&{weight:a}}}function G(e={}){let{id:t=s("divider"),weight:o,axis:a}=e;return {id:t,component:"Divider",...o!==void 0&&{weight:o},...a&&{axis:a}}}function W(e,t,o={}){let{id:a=s("modal"),weight:n}=o;return {id:a,component:"Modal",entryPointChild:e,contentChild:t,...n!==void 0&&{weight:n}}}function M(e,t,o={}){let{id:a=s("button"),weight:n,primary:r}=o;return {id:a,component:"Button",child:e,action:t,...n!==void 0&&{weight:n},...r!==void 0&&{primary:r}}}function q(e,t,o={}){let{id:a=s("checkbox"),weight:n}=o;return {id:a,component:"CheckBox",label:e,value:t,...n!==void 0&&{weight:n}}}function Y(e,t,o={}){let{id:a=s("textfield"),weight:n,usageHint:r,validationRegexp:i}=o;return {id:a,component:"TextField",label:e,...t!==void 0&&{text:t},...n!==void 0&&{weight:n},...r&&{usageHint:r},...i&&{validationRegexp:i}}}function z(e,t={}){let{id:o=s("datetime"),weight:a,enableDate:n,enableTime:r,outputFormat:i,label:p}=t;return {id:o,component:"DateTimeInput",value:e,...a!==void 0&&{weight:a},...n!==void 0&&{enableDate:n},...r!==void 0&&{enableTime:r},...i&&{outputFormat:i},...p&&{label:p}}}function J(e,t,o,a={}){let{id:n=s("choice"),weight:r,label:i}=a;return {id:n,component:"ChoicePicker",options:e,value:t,usageHint:o,...r!==void 0&&{weight:r},...i&&{label:i}}}function X(e,t={}){let{id:o=s("slider"),weight:a,label:n,min:r,max:i}=t;return {id:o,component:"Slider",value:e,...a!==void 0&&{weight:a},...n&&{label:n},...r!==void 0&&{min:r},...i!==void 0&&{max:i}}}function K(e,t,o={}){let a=o.textId??s("btn_text"),n=c(e,{id:a}),r=M(a,t,o);return [n,r]}function Q(e,t={}){return c(e,{...t,usageHint:"h1"})}function Z(e,t={}){return c(e,{...t,usageHint:"h2"})}function ee(e,t={}){return c(e,{...t,usageHint:"h3"})}function te(e,t={}){return c(e,{...t,usageHint:"h4"})}function ne(e,t={}){return c(e,{...t,usageHint:"h5"})}function oe(e,t={}){return c(e,{...t,usageHint:"caption"})}function ae(e,t={}){return c(e,{...t,usageHint:"body"})}function m(e,t=g){return {createSurface:{surfaceId:e,catalogId:t}}}function f(e,t){return {updateComponents:{surfaceId:e,components:t}}}function C(e,t,o,a="replace"){return {updateDataModel:{surfaceId:e,...o&&{path:o},op:a,...a!=="remove"&&{value:t}}}}function h(e){return {deleteSurface:{surfaceId:e}}}function re(e){let{surfaceId:t,catalogId:o=g,components:a,dataModel:n}=e,r=[m(t,o),f(t,a)];return n&&r.push(C(t,n)),r}function ie(e){return e.map(t=>JSON.stringify(t)).join(`
|
|
2
|
+
`)}function se(e){return e.split(`
|
|
3
|
+
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var y={};function pe(e,t=""){let o=[];for(let[a,n]of Object.entries(e)){let r=t?`${t}/${a}`:`/${a}`;o.push(d(r,n));}return o}function d(e,t){if(t==null)return {key:e,valueString:""};if(typeof t=="string")return {key:e,valueString:t};if(typeof t=="number")return {key:e,valueNumber:t};if(typeof t=="boolean")return {key:e,valueBoolean:t};if(Array.isArray(t))return {key:e,valueMap:t.map((o,a)=>d(String(a),o))};if(typeof t=="object"){let o=[];for(let[a,n]of Object.entries(t))o.push(d(a,n));return {key:e,valueMap:o}}return {key:e,valueString:String(t)}}function T(e,t={}){let o=e.replace(/\./g,"/");o.startsWith("/")||(o=`/${o}`);for(let[a,n]of Object.entries(t)){let r=new RegExp(`^/${a}(/|$)`);r.test(o)&&(o=o.replace(r,`/${n}$1`));}return o}function ce(e,t="",o=y){let a=[];for(let n of e){let r=n.path.startsWith("/")?n.path:`${t}/${n.path}`,i=T(r,o);if(n.value!==null&&typeof n.value=="object"&&!Array.isArray(n.value)){let p=S(n.value,i);a.push(...p);}else a.push(d(i,n.value));}return a}function S(e,t){let o=[];for(let[a,n]of Object.entries(e)){let r=`${t}/${a}`;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=S(n,r);o.push(...i);}else o.push(d(r,n));}return o}function D(e){let t={};for(let o of e){let a=o.key.startsWith("/")?o.key.slice(1):o.key;o.valueString!==void 0?t[a]=o.valueString:o.valueNumber!==void 0?t[a]=o.valueNumber:o.valueBoolean!==void 0?t[a]=o.valueBoolean:o.valueMap!==void 0&&(t[a]=D(o.valueMap));}return t}var Se=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function V(e,t={}){let o=[],a=[];if("createSurface"in e){let{createSurface:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),n.catalogId||o.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!n.components||!Array.isArray(n.components)?o.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):Oe(n.components,o,a,t);}else if("updateDataModel"in e){let{updateDataModel:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),n.op&&!["add","replace","remove"].includes(n.op)&&o.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),n.op==="remove"&&n.value!==void 0&&a.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),n.op!=="remove"&&n.value===void 0&&n.op==="add"&&o.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in e){let{deleteSurface:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else o.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:o.length===0,errors:o,warnings:a}}function b(e,t={}){return V(e,t)}function ue(e,t={}){let o=[],a=[];for(let n=0;n<e.length;n++){let r=e[n];if(!r)continue;let i=b(r,t);for(let p of i.errors)o.push({...p,path:`messages[${n}].${p.path??""}`});for(let p of i.warnings)a.push({...p,path:`messages[${n}].${p.path??""}`});}return {valid:o.length===0,errors:o,warnings:a}}function Oe(e,t,o,a){let n=new Set,r=false;for(let i=0;i<e.length;i++){let p=e[i];if(!p)continue;let I=`updateComponents.components[${i}]`;p.id?(n.has(p.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${p.id}`,path:`${I}.id`}),n.add(p.id),p.id==="root"&&(r=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${I}.id`}),p.component?a.strict&&!Se.includes(p.component)&&a.allowedComponents&&!a.allowedComponents.includes(p.component)&&o.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${p.component}`,path:`${I}.component`}):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${I}.component`});}!r&&a.strict&&o.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}function v(e){return typeof e=="object"&&e!==null&&"path"in e}function Me(e){if(!v(e))return e}function ye(e){if(v(e))return e.path}function Te(e){return {path:e}}function de(e,t){let o={...e};for(let a of Object.keys(t)){let n=t[a],r=o[a];n!==void 0&&typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?o[a]=de(r,n):n!==void 0&&(o[a]=n);}return o}function De(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return (e==="x"?t:t&3|8).toString(16)})}var u={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},P=0;function x(e="surface"){return P++,`${e}-${Date.now()}-${P}`}function le(){P=0;}function l(e,t,o){let a=o??x();return t.find(i=>i.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[m(a),f(a,t)],surfaceId:a}}function me(e,t,o,a){let n=a??x();return {messages:[m(n),f(n,t),C(n,o)],surfaceId:n}}function fe(e){return h(e)}function ge(e,t){return l(e,t,u.CHAT)}function Ce(e,t){return l(e,t,u.RECOMMENDATION)}function xe(e,t){return l(e,t,u.INPUT_FORM)}function Ie(e,t){return l(e,t,u.ORCHESTRATION)}function he(e,t){return l(e,t,u.STATUS)}exports.A2UI_EXTENSION_URI=E;exports.A2UI_MIME_TYPE=N;exports.DEFAULT_PATH_MAPPINGS=y;exports.STANDARD_CATALOG_ID=g;exports.SURFACE_IDS=u;exports.audioPlayer=j;exports.body=ae;exports.button=M;exports.caption=oe;exports.card=H;exports.checkbox=q;exports.choicePicker=J;exports.column=B;exports.createA2UISurface=l;exports.createA2UISurfaceWithData=me;exports.createChatSurface=ge;exports.createDeleteSurfaceMessage=fe;exports.createInputFormSurface=xe;exports.createOrchestrationSurface=Ie;exports.createRecommendationSurface=Ce;exports.createStatusSurface=he;exports.createSurface=m;exports.createV09Messages=re;exports.dateTimeInput=z;exports.deepMerge=de;exports.deleteSurface=h;exports.divider=G;exports.flattenObjectToValueMap=S;exports.generateId=s;exports.generateSurfaceId=x;exports.getIdCounter=_;exports.getLiteralValue=Me;exports.getPathValue=ye;exports.h1=Q;exports.h2=Z;exports.h3=ee;exports.h4=te;exports.h5=ne;exports.icon=w;exports.image=U;exports.isPathBinding=v;exports.isV09Message=A;exports.jsonlToMessages=se;exports.list=L;exports.messagesToJsonl=ie;exports.modal=W;exports.normalizePath=T;exports.objectToValueMap=pe;exports.path=Te;exports.resetIdCounter=R;exports.resetSurfaceIdCounter=le;exports.row=F;exports.slider=X;exports.tabs=$;exports.text=c;exports.textButton=K;exports.textField=Y;exports.updateComponents=f;exports.updateDataModel=C;exports.updatesToValueMap=ce;exports.uuid=De;exports.validateMessage=b;exports.validateMessages=ue;exports.validateV09Message=V;exports.valueMapToObject=D;exports.valueToValueMap=d;exports.video=k;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { B as BooleanOrPath, C as ContextValue, N as NumberOrPath, a as StringArrayOrPath, S as StringOrPath } from './primitives-DLbBDhLq.cjs';
|
|
2
2
|
export { A2UI_EXTENSION_URI, A2UI_MIME_TYPE, Action, AnyComponent, AudioPlayerComponent, ButtonComponent, CardComponent, CheckBoxComponent, ChildrenProperty, ChoicePickerComponent, ClientErrorMessage, ClientToServerMessage, ColumnComponent, ComponentCommon, ComponentInstance, ComponentType, CreateSurfaceMessage, DataArray, DataChangeEvent, DataObject, DataValue, DateTimeInputComponent, DeleteSurfaceMessage, DividerComponent, GenericError, IconComponent, ImageComponent, ListComponent, ModalComponent, RowComponent, STANDARD_CATALOG_ID, ServerToClientMessageV09 as ServerToClientMessage, ServerToClientMessageV09, SliderComponent, StandardIconName, TabsComponent, TextComponent, TextFieldComponent, Theme, UpdateComponentsMessage, UpdateDataModelMessage, UserActionEvent, ValidationFailedError, VideoComponent, isV09Message } from './types/index.cjs';
|
|
3
3
|
export { AudioPlayerOptions, ButtonOptions, CardOptions, CheckBoxOptions, ChoicePickerOptions, ComponentOptions, DEFAULT_PATH_MAPPINGS, DateTimeInputOptions, DividerOptions, IconOptions, ImageOptions, LayoutOptions, ListOptions, ModalOptions, PathMappings, SliderOptions, TabItem, TabsOptions, TextFieldOptions, TextOptions, UpdateDataItem, VideoOptions, audioPlayer, body, button, caption, card, checkbox, choicePicker, column, createSurface, createV09Messages, dateTimeInput, deleteSurface, divider, flattenObjectToValueMap, generateId, getIdCounter, h1, h2, h3, h4, h5, icon, image, jsonlToMessages, list, messagesToJsonl, modal, normalizePath, objectToValueMap, resetIdCounter, row, slider, tabs, text, textButton, textField, updateComponents, updateDataModel, updatesToValueMap, valueMapToObject, valueToValueMap, video } from './builders/index.cjs';
|
|
4
|
-
export {
|
|
4
|
+
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages, validateV09Message } from './validators/index.cjs';
|
|
5
5
|
export { deepMerge, getLiteralValue, getPathValue, isPathBinding, path, uuid } from './utils/index.cjs';
|
|
6
6
|
export { SURFACE_IDS, SurfaceConfig, SurfaceIdType, SurfaceResult, createA2UISurface, createA2UISurfaceWithData, createChatSurface, createDeleteSurfaceMessage, createInputFormSurface, createOrchestrationSurface, createRecommendationSurface, createStatusSurface, generateSurfaceId, resetSurfaceIdCounter } from './surface/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { B as BooleanOrPath, C as ContextValue, N as NumberOrPath, a as StringArrayOrPath, S as StringOrPath } from './primitives-DLbBDhLq.js';
|
|
2
2
|
export { A2UI_EXTENSION_URI, A2UI_MIME_TYPE, Action, AnyComponent, AudioPlayerComponent, ButtonComponent, CardComponent, CheckBoxComponent, ChildrenProperty, ChoicePickerComponent, ClientErrorMessage, ClientToServerMessage, ColumnComponent, ComponentCommon, ComponentInstance, ComponentType, CreateSurfaceMessage, DataArray, DataChangeEvent, DataObject, DataValue, DateTimeInputComponent, DeleteSurfaceMessage, DividerComponent, GenericError, IconComponent, ImageComponent, ListComponent, ModalComponent, RowComponent, STANDARD_CATALOG_ID, ServerToClientMessageV09 as ServerToClientMessage, ServerToClientMessageV09, SliderComponent, StandardIconName, TabsComponent, TextComponent, TextFieldComponent, Theme, UpdateComponentsMessage, UpdateDataModelMessage, UserActionEvent, ValidationFailedError, VideoComponent, isV09Message } from './types/index.js';
|
|
3
3
|
export { AudioPlayerOptions, ButtonOptions, CardOptions, CheckBoxOptions, ChoicePickerOptions, ComponentOptions, DEFAULT_PATH_MAPPINGS, DateTimeInputOptions, DividerOptions, IconOptions, ImageOptions, LayoutOptions, ListOptions, ModalOptions, PathMappings, SliderOptions, TabItem, TabsOptions, TextFieldOptions, TextOptions, UpdateDataItem, VideoOptions, audioPlayer, body, button, caption, card, checkbox, choicePicker, column, createSurface, createV09Messages, dateTimeInput, deleteSurface, divider, flattenObjectToValueMap, generateId, getIdCounter, h1, h2, h3, h4, h5, icon, image, jsonlToMessages, list, messagesToJsonl, modal, normalizePath, objectToValueMap, resetIdCounter, row, slider, tabs, text, textButton, textField, updateComponents, updateDataModel, updatesToValueMap, valueMapToObject, valueToValueMap, video } from './builders/index.js';
|
|
4
|
-
export {
|
|
4
|
+
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages, validateV09Message } from './validators/index.js';
|
|
5
5
|
export { deepMerge, getLiteralValue, getPathValue, isPathBinding, path, uuid } from './utils/index.js';
|
|
6
6
|
export { SURFACE_IDS, SurfaceConfig, SurfaceIdType, SurfaceResult, createA2UISurface, createA2UISurfaceWithData, createChatSurface, createDeleteSurfaceMessage, createInputFormSurface, createOrchestrationSurface, createRecommendationSurface, createStatusSurface, generateSurfaceId, resetSurfaceIdCounter } from './surface/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
`)}function
|
|
3
|
-
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var M={};function ue(e,t=""){let n=[];for(let[r,o]of Object.entries(e)){let a=t?`${t}/${r}`:`/${r}`;n.push(l(a,o));}return n}function l(e,t){if(t==null)return {key:e,valueString:""};if(typeof t=="string")return {key:e,valueString:t};if(typeof t=="number")return {key:e,valueNumber:t};if(typeof t=="boolean")return {key:e,valueBoolean:t};if(Array.isArray(t))return {key:e,valueMap:t.map((n,r)=>l(String(r),n))};if(typeof t=="object"){let n=[];for(let[r,o]of Object.entries(t))n.push(l(r,o));return {key:e,valueMap:n}}return {key:e,valueString:String(t)}}function P(e,t={}){let n=e.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[r,o]of Object.entries(t)){let a=new RegExp(`^/${r}(/|$)`);a.test(n)&&(n=n.replace(a,`/${o}$1`));}return n}function me(e,t="",n=M){let r=[];for(let o of e){let a=o.path.startsWith("/")?o.path:`${t}/${o.path}`,i=P(a,n);if(o.value!==null&&typeof o.value=="object"&&!Array.isArray(o.value)){let p=T(o.value,i);r.push(...p);}else r.push(l(i,o.value));}return r}function T(e,t){let n=[];for(let[r,o]of Object.entries(e)){let a=`${t}/${r}`;if(o!==null&&typeof o=="object"&&!Array.isArray(o)){let i=T(o,a);n.push(...i);}else n.push(l(a,o));}return n}function D(e){let t={};for(let n of e){let r=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?t[r]=n.valueString:n.valueNumber!==void 0?t[r]=n.valueNumber:n.valueBoolean!==void 0?t[r]=n.valueBoolean:n.valueMap!==void 0&&(t[r]=D(n.valueMap));}return t}var we=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function j(e,t={}){let n=[],r=[];if("createSurface"in e){let{createSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),o.catalogId||n.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):_e(o.components,n,r,t);}else if("updateDataModel"in e){let{updateDataModel:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),o.op&&!["add","replace","remove"].includes(o.op)&&n.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),o.op==="remove"&&o.value!==void 0&&r.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),o.op!=="remove"&&o.value===void 0&&o.op==="add"&&n.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:n.length===0,errors:n,warnings:r}}function $(e,t={}){return j(e,t)}function fe(e,t={}){let n=[],r=[];for(let o=0;o<e.length;o++){let a=e[o];if(!a)continue;let i=$(a,t);for(let p of i.errors)n.push({...p,path:`messages[${o}].${p.path??""}`});for(let p of i.warnings)r.push({...p,path:`messages[${o}].${p.path??""}`});}return {valid:n.length===0,errors:n,warnings:r}}function _e(e,t,n,r){let o=new Set,a=false;for(let i=0;i<e.length;i++){let p=e[i];if(!p)continue;let x=`updateComponents.components[${i}]`;p.id?(o.has(p.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${p.id}`,path:`${x}.id`}),o.add(p.id),p.id==="root"&&(a=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${x}.id`}),p.component?r.strict&&!we.includes(p.component)&&r.allowedComponents&&!r.allowedComponents.includes(p.component)&&n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${p.component}`,path:`${x}.component`}):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${x}.component`});}!a&&r.strict&&n.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}var he={title:"A2UI (Agent to UI) Client-to-Server Event Schema",description:"Describes a JSON payload for a client-to-server event message.",type:"object",minProperties:1,maxProperties:1,properties:{userAction:{type:"object",description:"Reports a user-initiated action from a component.",properties:{name:{type:"string",description:"The name of the action, taken from the component's action.name property."},surfaceId:{type:"string",description:"The id of the surface where the event originated."},sourceComponentId:{type:"string",description:"The id of the component that triggered the event."},timestamp:{type:"string",format:"date-time",description:"An ISO 8601 timestamp of when the event occurred."},context:{type:"object",description:"A JSON object containing the key-value pairs from the component's action.context, after resolving all data bindings.",additionalProperties:true}},required:["name","surfaceId","sourceComponentId","timestamp","context"]},error:{description:"Reports a client-side error.",oneOf:[{type:"object",title:"Validation Failed Error",properties:{code:{const:"VALIDATION_FAILED"},surfaceId:{type:"string",description:"The id of the surface where the error occurred."},path:{type:"string",description:"The JSON pointer to the field that failed validation (e.g. '/components/0/text')."},message:{type:"string",description:"A short one-sentence description of why validation failed."}},required:["code","path","message","surfaceId"]},{type:"object",title:"Generic Error",properties:{code:{not:{const:"VALIDATION_FAILED"}},message:{type:"string",description:"A short one-sentence description of why the error occurred."},surfaceId:{type:"string",description:"The id of the surface where the error occurred."}},required:["code","surfaceId","message"],additionalProperties:true}]}},oneOf:[{required:["userAction"]},{required:["clientUiCapabilities"]},{required:["error"]}]};var ge={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/common_types.json",title:"A2UI Common Types",description:"Common type definitions used across A2UI schemas.",$defs:{stringOrPath:{description:"Represents a value that can be either a literal string or a path to a value in the data model.",oneOf:[{type:"string"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},numberOrPath:{description:"Represents a value that can be either a literal number or a path to a value in the data model.",oneOf:[{type:"number"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},booleanOrPath:{description:"Represents a value that can be either a literal boolean or a path to a value in the data model.",oneOf:[{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},stringArrayOrPath:{description:"Represents a value that can be either a literal array of strings or a path to a value in the data model.",oneOf:[{type:"array",items:{type:"string"}},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},id:{type:"string",description:"The unique identifier for this component."},ComponentCommon:{type:"object",properties:{id:{$ref:"#/$defs/id"},weight:{type:"number",description:"The relative weight of this component within a Row or Column. This is similar to the CSS 'flex-grow' property."}},required:["id"]},contextValue:{description:"A value that can be a string, number, boolean, or a path to a value.",oneOf:[{type:"string"},{type:"number"},{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},childrenProperty:{oneOf:[{type:"array",items:{type:"string"},description:"A static list of child component IDs."},{type:"object",description:"A template for generating a dynamic list of children from a data model list. The `componentId` is the component to use as a template.",properties:{componentId:{$ref:"#/$defs/id"},path:{type:"string",description:"The path to the list of component property objects in the data model."}},required:["componentId","path"],additionalProperties:false}]}}};var ye={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/server_to_client.json",title:"A2UI Message Schema",description:"Describes a JSON payload for an A2UI (Agent to UI) message, which is used to dynamically construct and update user interfaces.",type:"object",oneOf:[{$ref:"#/$defs/CreateSurfaceMessage"},{$ref:"#/$defs/UpdateComponentsMessage"},{$ref:"#/$defs/UpdateDataModelMessage"},{$ref:"#/$defs/DeleteSurfaceMessage"}],$defs:{CreateSurfaceMessage:{properties:{createSurface:{type:"object",description:"Signals the client to create a new surface and begin rendering it. When this message is sent, the client will expect 'updateComponents' and/or 'updateDataModel' messages for the same surfaceId that define the component tree.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be rendered."},catalogId:{title:"Catalog ID",description:"A string that uniquely identifies this catalog. It is recommended to prefix this with an internet domain that you own, to avoid conflicts e.g. mycompany.com:somecatalog'.",type:"string"}},required:["surfaceId","catalogId"],additionalProperties:false}},required:["createSurface"],additionalProperties:false},UpdateComponentsMessage:{properties:{updateComponents:{type:"object",description:"Updates a surface with a new set of components. This message can be sent multiple times to update the component tree of an existing surface. One of the components in one of the components lists MUST have an 'id' of 'root' to serve as the root of the component tree. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be updated."},components:{type:"array",description:"A list containing all UI components for the surface.",minItems:1,items:{$ref:"standard_catalog_definition.json#/$defs/anyComponent"}}},required:["surfaceId","components"],additionalProperties:false}},required:["updateComponents"],additionalProperties:false},UpdateDataModelMessage:{properties:{updateDataModel:{type:"object",description:"Updates the data model for an existing surface. This message can be sent multiple times to update the data model. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface this data model update applies to."},path:{type:"string",description:"An optional path to a location within the data model (e.g., '/user/name'). If omitted, or set to '/', refers to the entire data model."},op:{type:"string",description:"The operation to perform on the data model. Defaults to 'replace' if omitted.",enum:["add","replace","remove"]},value:{description:"The data to be updated in the data model. Required for 'add' and 'replace' operations. Not allowed for 'remove' operation.",additionalProperties:true}},required:["surfaceId"],additionalProperties:false}},required:["updateDataModel"],additionalProperties:false},DeleteSurfaceMessage:{properties:{deleteSurface:{type:"object",description:"Signals the client to delete the surface identified by 'surfaceId'. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be deleted."}},required:["surfaceId"],additionalProperties:false}},required:["deleteSurface"],additionalProperties:false}}};var Ce={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/standard_catalog_definition.json",title:"A2UI Component Catalog",description:"Definitions for the standard catalog of A2UI components.",$defs:{Theme:{type:"object",description:"Theming information for the UI.",properties:{font:{type:"string",description:"The primary font for the UI."},primaryColor:{type:"string",description:"The primary UI color as a hexadecimal code (e.g., '#00BFFF').",pattern:"^#[0-9a-fA-F]{6}$"}},additionalProperties:false},anyComponent:{oneOf:[{$ref:"#/$defs/Text"},{$ref:"#/$defs/Image"},{$ref:"#/$defs/Icon"},{$ref:"#/$defs/Video"},{$ref:"#/$defs/AudioPlayer"},{$ref:"#/$defs/Row"},{$ref:"#/$defs/Column"},{$ref:"#/$defs/List"},{$ref:"#/$defs/Card"},{$ref:"#/$defs/Tabs"},{$ref:"#/$defs/Divider"},{$ref:"#/$defs/Modal"},{$ref:"#/$defs/Button"},{$ref:"#/$defs/CheckBox"},{$ref:"#/$defs/TextField"},{$ref:"#/$defs/DateTimeInput"},{$ref:"#/$defs/ChoicePicker"},{$ref:"#/$defs/Slider"}],discriminator:{propertyName:"component"}},Text:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Text"},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text content to display. While simple Markdown formatting is supported (i.e. without HTML, images, or links), utilizing dedicated UI components is generally preferred for a richer and more structured presentation."},usageHint:{type:"string",description:"A hint for the base text style.",enum:["h1","h2","h3","h4","h5","caption","body"]}},required:["component","text"]}],unevaluatedProperties:false},Image:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Image"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the image to display."},fit:{type:"string",description:"Specifies how the image should be resized to fit its container. This corresponds to the CSS 'object-fit' property.",enum:["contain","cover","fill","none","scale-down"]},usageHint:{type:"string",description:"A hint for the image size and style.",enum:["icon","avatar","smallFeature","mediumFeature","largeFeature","header"]}},required:["component","url"]}],unevaluatedProperties:false},Icon:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Icon"},name:{description:"The name of the icon to display.",oneOf:[{type:"string",enum:["accountCircle","add","arrowBack","arrowForward","attachFile","calendarToday","call","camera","check","close","delete","download","edit","event","error","fastForward","favorite","favoriteOff","folder","help","home","info","locationOn","lock","lockOpen","mail","menu","moreVert","moreHoriz","notificationsOff","notifications","pause","payment","person","phone","photo","play","print","refresh","rewind","search","send","settings","share","shoppingCart","skipNext","skipPrevious","star","starHalf","starOff","stop","upload","visibility","visibilityOff","volumeDown","volumeMute","volumeOff","volumeUp","warning"]},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]}},required:["component","name"]}],unevaluatedProperties:false},Video:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Video"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the video to display."}},required:["component","url"]}],unevaluatedProperties:false},AudioPlayer:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"AudioPlayer"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the audio to be played."},description:{description:"A description of the audio, such as a title or summary.",$ref:"common_types.json#/$defs/stringOrPath"}},required:["component","url"]}],unevaluatedProperties:false},Row:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children horizontally. To create a grid layout, nest Columns within this Row.",properties:{component:{const:"Row"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (horizontally). Use 'spaceBetween' to push items to the edges, or 'start'/'end'/'center' to pack them together.",enum:["center","end","spaceAround","spaceBetween","spaceEvenly","start","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (vertically). This is similar to the CSS 'align-items' property, but uses camelCase values (e.g., 'start').",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Column:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children vertically. To create a grid layout, nest Rows within this Column.",properties:{component:{const:"Column"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (vertically). Use 'spaceBetween' to push items to the edges (e.g. header at top, footer at bottom), or 'start'/'end'/'center' to pack them together.",enum:["start","center","end","spaceBetween","spaceAround","spaceEvenly","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (horizontally). This is similar to the CSS 'align-items' property.",enum:["center","end","start","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},List:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"List"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list.",$ref:"common_types.json#/$defs/childrenProperty"},direction:{type:"string",description:"The direction in which the list items are laid out.",enum:["vertical","horizontal"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis.",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Card:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Card"},child:{type:"string",description:"The ID of the single child component to be rendered inside the card. To display multiple elements, you MUST wrap them in a layout component (like Column or Row) and pass that container's ID here. Do NOT pass multiple IDs or a non-existent ID. Do NOT define the child component inline."}},required:["component","child"]}],unevaluatedProperties:false},Tabs:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Tabs"},tabItems:{type:"array",description:"An array of objects, where each object defines a tab with a title and a child component.",items:{type:"object",properties:{title:{description:"The tab title.",$ref:"common_types.json#/$defs/stringOrPath"},child:{type:"string",description:"The ID of the child component. Do NOT define the component inline."}},required:["title","child"],additionalProperties:false}}},required:["component","tabItems"]}],unevaluatedProperties:false},Divider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Divider"},axis:{type:"string",description:"The orientation of the divider.",enum:["horizontal","vertical"]}},required:["component"]}],unevaluatedProperties:false},Modal:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Modal"},entryPointChild:{type:"string",description:"The ID of the component that opens the modal when interacted with (e.g., a button). Do NOT define the component inline."},contentChild:{type:"string",description:"The ID of the component to be displayed inside the modal. Do NOT define the component inline."}},required:["component","entryPointChild","contentChild"]}],unevaluatedProperties:false},Button:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Button"},child:{type:"string",description:"The ID of the child component. Use a 'Text' component for a labeled button. Only use an 'Icon' if the requirements explicitly ask for an icon-only button. Do NOT define the child component inline."},primary:{type:"boolean",description:"Indicates if this button should be styled as the primary action."},action:{type:"object",description:"The client-side action to be dispatched when the button is clicked. It includes the action's name and an optional context payload.",properties:{name:{type:"string"},context:{type:"object",description:"A JSON object containing the key-value pairs for the action context. Values can be literals or paths. Use literal values unless the value must be dynamically bound to the data model. Do NOT use paths for static IDs.",additionalProperties:{$ref:"common_types.json#/$defs/contextValue"}}},required:["name"],additionalProperties:false}},required:["component","child","action"]}],unevaluatedProperties:false},CheckBox:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"CheckBox"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text to display next to the checkbox."},value:{$ref:"common_types.json#/$defs/booleanOrPath",description:"The current state of the checkbox (true for checked, false for unchecked)."}},required:["component","label","value"]}],unevaluatedProperties:false},TextField:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"TextField"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The value of the text field."},usageHint:{type:"string",description:"The type of input field to display.",enum:["longText","number","shortText","obscured"]},validationRegexp:{type:"string",description:"A regular expression used for client-side validation of the input."}},required:["component","label"]}],unevaluatedProperties:false},DateTimeInput:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"DateTimeInput"},value:{$ref:"common_types.json#/$defs/stringOrPath",description:"The selected date and/or time value in ISO 8601 format. If not yet set, initialize with an empty string."},enableDate:{type:"boolean",description:"If true, allows the user to select a date."},enableTime:{type:"boolean",description:"If true, allows the user to select a time."},outputFormat:{type:"string",description:"The desired format for the output string after a date or time is selected."},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."}},required:["component","value"]}],unevaluatedProperties:false},ChoicePicker:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A component that allows selecting one or more options from a list.",properties:{component:{const:"ChoicePicker"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the group of options."},usageHint:{type:"string",description:"A hint for how the choice picker should be displayed and behave.",enum:["multipleSelection","mutuallyExclusive"]},options:{type:"array",description:"The list of available options to choose from.",items:{type:"object",properties:{label:{description:"The text to display for this option.",$ref:"common_types.json#/$defs/stringOrPath"},value:{type:"string",description:"The stable value associated with this option."}},required:["label","value"],additionalProperties:false}},value:{$ref:"common_types.json#/$defs/stringArrayOrPath",description:"The list of currently selected values. This should be bound to a string array in the data model."}},required:["component","options","value","usageHint"]}],unevaluatedProperties:false},Slider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Slider"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the slider."},min:{type:"number",description:"The minimum value of the slider."},max:{type:"number",description:"The maximum value of the slider."},value:{$ref:"common_types.json#/$defs/numberOrPath",description:"The current value of the slider."}},required:["component","value"]}],unevaluatedProperties:false}}};var y=class{constructor(){S(this,"ajv");S(this,"serverToClientValidator");S(this,"clientToServerValidator");this.ajv=new ke({allErrors:true,strict:false}),qe(this.ajv),this.ajv.addSchema(ge,"common_types.json"),this.ajv.addSchema(Ce,"standard_catalog_definition.json"),this.serverToClientValidator=this.ajv.compile(ye),this.clientToServerValidator=this.ajv.compile(he);}validateServerToClientMessage(t){return this.serverToClientValidator(t)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.serverToClientValidator.errors||[])}}validateClientToServerMessage(t){return this.clientToServerValidator(t)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.clientToServerValidator.errors||[])}}validateMessages(t){let n=[];for(let r=0;r<t.length;r++){let o=this.validateServerToClientMessage(t[r]);o.valid||n.push(...o.errors.map(a=>({...a,path:`/messages/${r}${a.path}`})));}return {valid:n.length===0,errors:n}}formatErrors(t){return t.map(n=>({path:n.instancePath||"/",message:n.message||"Validation failed",keyword:n.keyword,expected:n.params,actual:void 0}))}},V=null;function C(){return V||(V=new y),V}function Ie(e){return C().validateServerToClientMessage(e)}function xe(e){return C().validateClientToServerMessage(e)}function Se(e){return C().validateMessages(e)}function A(e){return typeof e=="object"&&e!==null&&"path"in e}function Fe(e){if(!A(e))return e}function Be(e){if(A(e))return e.path}function Le(e){return {path:e}}function Oe(e,t){let n={...e};for(let r of Object.keys(t)){let o=t[r],a=n[r];o!==void 0&&typeof o=="object"&&o!==null&&!Array.isArray(o)&&typeof a=="object"&&a!==null&&!Array.isArray(a)?n[r]=Oe(a,o):o!==void 0&&(n[r]=o);}return n}function He(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return (e==="x"?t:t&3|8).toString(16)})}var d={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},w=0;function I(e="surface"){return w++,`${e}-${Date.now()}-${w}`}function Te(){w=0;}function u(e,t,n){let r=n??I();return t.find(i=>i.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[m(r),f(r,t)],surfaceId:r}}function be(e,t,n,r){let o=r??I();return {messages:[m(o),f(o,t),g(o,n)],surfaceId:o}}function ve(e){return O(e)}function Me(e,t){return u(e,t,d.CHAT)}function Pe(e,t){return u(e,t,d.RECOMMENDATION)}function De(e,t){return u(e,t,d.INPUT_FORM)}function je(e,t){return u(e,t,d.ORCHESTRATION)}function $e(e,t){return u(e,t,d.STATUS)}
|
|
4
|
-
export{y as A2UISchemaValidator,U as A2UI_EXTENSION_URI,E as A2UI_MIME_TYPE,M as DEFAULT_PATH_MAPPINGS,h as STANDARD_CATALOG_ID,d as SURFACE_IDS,B as audioPlayer,pe as body,v as button,se as caption,W as card,X as checkbox,Z as choicePicker,H as column,u as createA2UISurface,be as createA2UISurfaceWithData,Me as createChatSurface,ve as createDeleteSurfaceMessage,De as createInputFormSurface,je as createOrchestrationSurface,Pe as createRecommendationSurface,$e as createStatusSurface,m as createSurface,ce as createV09Messages,Q as dateTimeInput,Oe as deepMerge,O as deleteSurface,J as divider,T as flattenObjectToValueMap,s as generateId,I as generateSurfaceId,N as getIdCounter,Fe as getLiteralValue,Be as getPathValue,C as getSchemaValidator,ne as h1,oe as h2,re as h3,ae as h4,ie as h5,q as icon,k as image,A as isPathBinding,_ as isV09Message,le as jsonlToMessages,G as list,de as messagesToJsonl,Y as modal,P as normalizePath,ue as objectToValueMap,Le as path,R as resetIdCounter,Te as resetSurfaceIdCounter,L as row,ee as slider,z as tabs,c as text,te as textButton,K as textField,f as updateComponents,g as updateDataModel,me as updatesToValueMap,He as uuid,xe as validateClientMessage,$ as validateMessage,fe as validateMessages,Se as validateMessagesWithSchema,j as validateV09Message,Ie as validateWithSchema,D as valueMapToObject,l as valueToValueMap,F as video};
|
|
1
|
+
function A(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}var g="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";var E="https://a2ui.dev/specification/0.9",N="application/json+a2ui";var O=0;function s(e="comp"){return `${e}_${Date.now()}_${O++}`}function R(){O=0;}function _(){return O}function c(e,t={}){let{id:o=s("text"),weight:a,usageHint:n,classes:r}=t;return {id:o,component:"Text",text:e,...a!==void 0&&{weight:a},...n&&{usageHint:n},...r&&r.length>0&&{classes:r}}}function U(e,t={}){let{id:o=s("image"),weight:a,fit:n,usageHint:r}=t;return {id:o,component:"Image",url:e,...a!==void 0&&{weight:a},...n&&{fit:n},...r&&{usageHint:r}}}function w(e,t={}){let{id:o=s("icon"),weight:a}=t;return {id:o,component:"Icon",name:e,...a!==void 0&&{weight:a}}}function k(e,t={}){let{id:o=s("video"),weight:a}=t;return {id:o,component:"Video",url:e,...a!==void 0&&{weight:a}}}function j(e,t={}){let{id:o=s("audio"),weight:a,description:n}=t;return {id:o,component:"AudioPlayer",url:e,...a!==void 0&&{weight:a},...n&&{description:n}}}function F(e,t={}){let{id:o=s("row"),weight:a,alignment:n,distribution:r}=t;return {id:o,component:"Row",children:e,...a!==void 0&&{weight:a},...n&&{alignment:n},...r&&{distribution:r}}}function B(e,t={}){let{id:o=s("column"),weight:a,alignment:n,distribution:r,classes:i}=t;return {id:o,component:"Column",children:e,...a!==void 0&&{weight:a},...n&&{alignment:n},...r&&{distribution:r},...i&&i.length>0&&{classes:i}}}function L(e,t={}){let{id:o=s("list"),weight:a,direction:n,alignment:r}=t;return {id:o,component:"List",children:e,...a!==void 0&&{weight:a},...n&&{direction:n},...r&&{alignment:r}}}function H(e,t={}){let{id:o=s("card"),weight:a,classes:n}=t;return {id:o,component:"Card",child:e,...a!==void 0&&{weight:a},...n&&n.length>0&&{classes:n}}}function $(e,t={}){let{id:o=s("tabs"),weight:a}=t;return {id:o,component:"Tabs",tabItems:e.map(n=>({title:n.title,child:n.childId})),...a!==void 0&&{weight:a}}}function G(e={}){let{id:t=s("divider"),weight:o,axis:a}=e;return {id:t,component:"Divider",...o!==void 0&&{weight:o},...a&&{axis:a}}}function W(e,t,o={}){let{id:a=s("modal"),weight:n}=o;return {id:a,component:"Modal",entryPointChild:e,contentChild:t,...n!==void 0&&{weight:n}}}function M(e,t,o={}){let{id:a=s("button"),weight:n,primary:r}=o;return {id:a,component:"Button",child:e,action:t,...n!==void 0&&{weight:n},...r!==void 0&&{primary:r}}}function q(e,t,o={}){let{id:a=s("checkbox"),weight:n}=o;return {id:a,component:"CheckBox",label:e,value:t,...n!==void 0&&{weight:n}}}function Y(e,t,o={}){let{id:a=s("textfield"),weight:n,usageHint:r,validationRegexp:i}=o;return {id:a,component:"TextField",label:e,...t!==void 0&&{text:t},...n!==void 0&&{weight:n},...r&&{usageHint:r},...i&&{validationRegexp:i}}}function z(e,t={}){let{id:o=s("datetime"),weight:a,enableDate:n,enableTime:r,outputFormat:i,label:p}=t;return {id:o,component:"DateTimeInput",value:e,...a!==void 0&&{weight:a},...n!==void 0&&{enableDate:n},...r!==void 0&&{enableTime:r},...i&&{outputFormat:i},...p&&{label:p}}}function J(e,t,o,a={}){let{id:n=s("choice"),weight:r,label:i}=a;return {id:n,component:"ChoicePicker",options:e,value:t,usageHint:o,...r!==void 0&&{weight:r},...i&&{label:i}}}function X(e,t={}){let{id:o=s("slider"),weight:a,label:n,min:r,max:i}=t;return {id:o,component:"Slider",value:e,...a!==void 0&&{weight:a},...n&&{label:n},...r!==void 0&&{min:r},...i!==void 0&&{max:i}}}function K(e,t,o={}){let a=o.textId??s("btn_text"),n=c(e,{id:a}),r=M(a,t,o);return [n,r]}function Q(e,t={}){return c(e,{...t,usageHint:"h1"})}function Z(e,t={}){return c(e,{...t,usageHint:"h2"})}function ee(e,t={}){return c(e,{...t,usageHint:"h3"})}function te(e,t={}){return c(e,{...t,usageHint:"h4"})}function ne(e,t={}){return c(e,{...t,usageHint:"h5"})}function oe(e,t={}){return c(e,{...t,usageHint:"caption"})}function ae(e,t={}){return c(e,{...t,usageHint:"body"})}function m(e,t=g){return {createSurface:{surfaceId:e,catalogId:t}}}function f(e,t){return {updateComponents:{surfaceId:e,components:t}}}function C(e,t,o,a="replace"){return {updateDataModel:{surfaceId:e,...o&&{path:o},op:a,...a!=="remove"&&{value:t}}}}function h(e){return {deleteSurface:{surfaceId:e}}}function re(e){let{surfaceId:t,catalogId:o=g,components:a,dataModel:n}=e,r=[m(t,o),f(t,a)];return n&&r.push(C(t,n)),r}function ie(e){return e.map(t=>JSON.stringify(t)).join(`
|
|
2
|
+
`)}function se(e){return e.split(`
|
|
3
|
+
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var y={};function pe(e,t=""){let o=[];for(let[a,n]of Object.entries(e)){let r=t?`${t}/${a}`:`/${a}`;o.push(d(r,n));}return o}function d(e,t){if(t==null)return {key:e,valueString:""};if(typeof t=="string")return {key:e,valueString:t};if(typeof t=="number")return {key:e,valueNumber:t};if(typeof t=="boolean")return {key:e,valueBoolean:t};if(Array.isArray(t))return {key:e,valueMap:t.map((o,a)=>d(String(a),o))};if(typeof t=="object"){let o=[];for(let[a,n]of Object.entries(t))o.push(d(a,n));return {key:e,valueMap:o}}return {key:e,valueString:String(t)}}function T(e,t={}){let o=e.replace(/\./g,"/");o.startsWith("/")||(o=`/${o}`);for(let[a,n]of Object.entries(t)){let r=new RegExp(`^/${a}(/|$)`);r.test(o)&&(o=o.replace(r,`/${n}$1`));}return o}function ce(e,t="",o=y){let a=[];for(let n of e){let r=n.path.startsWith("/")?n.path:`${t}/${n.path}`,i=T(r,o);if(n.value!==null&&typeof n.value=="object"&&!Array.isArray(n.value)){let p=S(n.value,i);a.push(...p);}else a.push(d(i,n.value));}return a}function S(e,t){let o=[];for(let[a,n]of Object.entries(e)){let r=`${t}/${a}`;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=S(n,r);o.push(...i);}else o.push(d(r,n));}return o}function D(e){let t={};for(let o of e){let a=o.key.startsWith("/")?o.key.slice(1):o.key;o.valueString!==void 0?t[a]=o.valueString:o.valueNumber!==void 0?t[a]=o.valueNumber:o.valueBoolean!==void 0?t[a]=o.valueBoolean:o.valueMap!==void 0&&(t[a]=D(o.valueMap));}return t}var Se=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function V(e,t={}){let o=[],a=[];if("createSurface"in e){let{createSurface:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),n.catalogId||o.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!n.components||!Array.isArray(n.components)?o.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):Oe(n.components,o,a,t);}else if("updateDataModel"in e){let{updateDataModel:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),n.op&&!["add","replace","remove"].includes(n.op)&&o.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),n.op==="remove"&&n.value!==void 0&&a.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),n.op!=="remove"&&n.value===void 0&&n.op==="add"&&o.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in e){let{deleteSurface:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else o.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:o.length===0,errors:o,warnings:a}}function b(e,t={}){return V(e,t)}function ue(e,t={}){let o=[],a=[];for(let n=0;n<e.length;n++){let r=e[n];if(!r)continue;let i=b(r,t);for(let p of i.errors)o.push({...p,path:`messages[${n}].${p.path??""}`});for(let p of i.warnings)a.push({...p,path:`messages[${n}].${p.path??""}`});}return {valid:o.length===0,errors:o,warnings:a}}function Oe(e,t,o,a){let n=new Set,r=false;for(let i=0;i<e.length;i++){let p=e[i];if(!p)continue;let I=`updateComponents.components[${i}]`;p.id?(n.has(p.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${p.id}`,path:`${I}.id`}),n.add(p.id),p.id==="root"&&(r=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${I}.id`}),p.component?a.strict&&!Se.includes(p.component)&&a.allowedComponents&&!a.allowedComponents.includes(p.component)&&o.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${p.component}`,path:`${I}.component`}):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${I}.component`});}!r&&a.strict&&o.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}function v(e){return typeof e=="object"&&e!==null&&"path"in e}function Me(e){if(!v(e))return e}function ye(e){if(v(e))return e.path}function Te(e){return {path:e}}function de(e,t){let o={...e};for(let a of Object.keys(t)){let n=t[a],r=o[a];n!==void 0&&typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?o[a]=de(r,n):n!==void 0&&(o[a]=n);}return o}function De(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return (e==="x"?t:t&3|8).toString(16)})}var u={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},P=0;function x(e="surface"){return P++,`${e}-${Date.now()}-${P}`}function le(){P=0;}function l(e,t,o){let a=o??x();return t.find(i=>i.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[m(a),f(a,t)],surfaceId:a}}function me(e,t,o,a){let n=a??x();return {messages:[m(n),f(n,t),C(n,o)],surfaceId:n}}function fe(e){return h(e)}function ge(e,t){return l(e,t,u.CHAT)}function Ce(e,t){return l(e,t,u.RECOMMENDATION)}function xe(e,t){return l(e,t,u.INPUT_FORM)}function Ie(e,t){return l(e,t,u.ORCHESTRATION)}function he(e,t){return l(e,t,u.STATUS)}export{E as A2UI_EXTENSION_URI,N as A2UI_MIME_TYPE,y as DEFAULT_PATH_MAPPINGS,g as STANDARD_CATALOG_ID,u as SURFACE_IDS,j as audioPlayer,ae as body,M as button,oe as caption,H as card,q as checkbox,J as choicePicker,B as column,l as createA2UISurface,me as createA2UISurfaceWithData,ge as createChatSurface,fe as createDeleteSurfaceMessage,xe as createInputFormSurface,Ie as createOrchestrationSurface,Ce as createRecommendationSurface,he as createStatusSurface,m as createSurface,re as createV09Messages,z as dateTimeInput,de as deepMerge,h as deleteSurface,G as divider,S as flattenObjectToValueMap,s as generateId,x as generateSurfaceId,_ as getIdCounter,Me as getLiteralValue,ye as getPathValue,Q as h1,Z as h2,ee as h3,te as h4,ne as h5,w as icon,U as image,v as isPathBinding,A as isV09Message,se as jsonlToMessages,L as list,ie as messagesToJsonl,W as modal,T as normalizePath,pe as objectToValueMap,Te as path,R as resetIdCounter,le as resetSurfaceIdCounter,F as row,X as slider,$ as tabs,c as text,K as textButton,Y as textField,f as updateComponents,C as updateDataModel,ce as updatesToValueMap,De as uuid,b as validateMessage,ue as validateMessages,V as validateV09Message,D as valueMapToObject,d as valueToValueMap,k as video};
|
package/dist/types/index.d.cts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
'use strict';var w=require('ajv/dist/2020'),x=require('ajv-formats');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var w__default=/*#__PURE__*/_interopDefault(w);var x__default=/*#__PURE__*/_interopDefault(x);var b=Object.defineProperty;var $=(o,n,e)=>n in o?b(o,n,{enumerable:true,configurable:true,writable:true,value:e}):o[n]=e;var p=(o,n,e)=>$(o,typeof n!="symbol"?n+"":n,e);var I=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function f(o,n={}){let e=[],r=[];if("createSurface"in o){let{createSurface:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),t.catalogId||e.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in o){let{updateComponents:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!t.components||!Array.isArray(t.components)?e.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):T(t.components,e,r,n);}else if("updateDataModel"in o){let{updateDataModel:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),t.op&&!["add","replace","remove"].includes(t.op)&&e.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),t.op==="remove"&&t.value!==void 0&&r.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),t.op!=="remove"&&t.value===void 0&&t.op==="add"&&e.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in o){let{deleteSurface:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else e.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:e.length===0,errors:e,warnings:r}}function h(o,n={}){return f(o,n)}function C(o,n={}){let e=[],r=[];for(let t=0;t<o.length;t++){let a=o[t];if(!a)continue;let s=h(a,n);for(let i of s.errors)e.push({...i,path:`messages[${t}].${i.path??""}`});for(let i of s.warnings)r.push({...i,path:`messages[${t}].${i.path??""}`});}return {valid:e.length===0,errors:e,warnings:r}}function T(o,n,e,r){let t=new Set,a=false;for(let s=0;s<o.length;s++){let i=o[s];if(!i)continue;let d=`updateComponents.components[${s}]`;i.id?(t.has(i.id)&&n.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${i.id}`,path:`${d}.id`}),t.add(i.id),i.id==="root"&&(a=true)):n.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${d}.id`}),i.component?r.strict&&!I.includes(i.component)&&r.allowedComponents&&!r.allowedComponents.includes(i.component)&&e.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${i.component}`,path:`${d}.component`}):n.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${d}.component`});}!a&&r.strict&&e.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}var u={title:"A2UI (Agent to UI) Client-to-Server Event Schema",description:"Describes a JSON payload for a client-to-server event message.",type:"object",minProperties:1,maxProperties:1,properties:{userAction:{type:"object",description:"Reports a user-initiated action from a component.",properties:{name:{type:"string",description:"The name of the action, taken from the component's action.name property."},surfaceId:{type:"string",description:"The id of the surface where the event originated."},sourceComponentId:{type:"string",description:"The id of the component that triggered the event."},timestamp:{type:"string",format:"date-time",description:"An ISO 8601 timestamp of when the event occurred."},context:{type:"object",description:"A JSON object containing the key-value pairs from the component's action.context, after resolving all data bindings.",additionalProperties:true}},required:["name","surfaceId","sourceComponentId","timestamp","context"]},error:{description:"Reports a client-side error.",oneOf:[{type:"object",title:"Validation Failed Error",properties:{code:{const:"VALIDATION_FAILED"},surfaceId:{type:"string",description:"The id of the surface where the error occurred."},path:{type:"string",description:"The JSON pointer to the field that failed validation (e.g. '/components/0/text')."},message:{type:"string",description:"A short one-sentence description of why validation failed."}},required:["code","path","message","surfaceId"]},{type:"object",title:"Generic Error",properties:{code:{not:{const:"VALIDATION_FAILED"}},message:{type:"string",description:"A short one-sentence description of why the error occurred."},surfaceId:{type:"string",description:"The id of the surface where the error occurred."}},required:["code","surfaceId","message"],additionalProperties:true}]}},oneOf:[{required:["userAction"]},{required:["clientUiCapabilities"]},{required:["error"]}]};var y={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/common_types.json",title:"A2UI Common Types",description:"Common type definitions used across A2UI schemas.",$defs:{stringOrPath:{description:"Represents a value that can be either a literal string or a path to a value in the data model.",oneOf:[{type:"string"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},numberOrPath:{description:"Represents a value that can be either a literal number or a path to a value in the data model.",oneOf:[{type:"number"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},booleanOrPath:{description:"Represents a value that can be either a literal boolean or a path to a value in the data model.",oneOf:[{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},stringArrayOrPath:{description:"Represents a value that can be either a literal array of strings or a path to a value in the data model.",oneOf:[{type:"array",items:{type:"string"}},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},id:{type:"string",description:"The unique identifier for this component."},ComponentCommon:{type:"object",properties:{id:{$ref:"#/$defs/id"},weight:{type:"number",description:"The relative weight of this component within a Row or Column. This is similar to the CSS 'flex-grow' property."}},required:["id"]},contextValue:{description:"A value that can be a string, number, boolean, or a path to a value.",oneOf:[{type:"string"},{type:"number"},{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},childrenProperty:{oneOf:[{type:"array",items:{type:"string"},description:"A static list of child component IDs."},{type:"object",description:"A template for generating a dynamic list of children from a data model list. The `componentId` is the component to use as a template.",properties:{componentId:{$ref:"#/$defs/id"},path:{type:"string",description:"The path to the list of component property objects in the data model."}},required:["componentId","path"],additionalProperties:false}]}}};var g={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/server_to_client.json",title:"A2UI Message Schema",description:"Describes a JSON payload for an A2UI (Agent to UI) message, which is used to dynamically construct and update user interfaces.",type:"object",oneOf:[{$ref:"#/$defs/CreateSurfaceMessage"},{$ref:"#/$defs/UpdateComponentsMessage"},{$ref:"#/$defs/UpdateDataModelMessage"},{$ref:"#/$defs/DeleteSurfaceMessage"}],$defs:{CreateSurfaceMessage:{properties:{createSurface:{type:"object",description:"Signals the client to create a new surface and begin rendering it. When this message is sent, the client will expect 'updateComponents' and/or 'updateDataModel' messages for the same surfaceId that define the component tree.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be rendered."},catalogId:{title:"Catalog ID",description:"A string that uniquely identifies this catalog. It is recommended to prefix this with an internet domain that you own, to avoid conflicts e.g. mycompany.com:somecatalog'.",type:"string"}},required:["surfaceId","catalogId"],additionalProperties:false}},required:["createSurface"],additionalProperties:false},UpdateComponentsMessage:{properties:{updateComponents:{type:"object",description:"Updates a surface with a new set of components. This message can be sent multiple times to update the component tree of an existing surface. One of the components in one of the components lists MUST have an 'id' of 'root' to serve as the root of the component tree. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be updated."},components:{type:"array",description:"A list containing all UI components for the surface.",minItems:1,items:{$ref:"standard_catalog_definition.json#/$defs/anyComponent"}}},required:["surfaceId","components"],additionalProperties:false}},required:["updateComponents"],additionalProperties:false},UpdateDataModelMessage:{properties:{updateDataModel:{type:"object",description:"Updates the data model for an existing surface. This message can be sent multiple times to update the data model. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface this data model update applies to."},path:{type:"string",description:"An optional path to a location within the data model (e.g., '/user/name'). If omitted, or set to '/', refers to the entire data model."},op:{type:"string",description:"The operation to perform on the data model. Defaults to 'replace' if omitted.",enum:["add","replace","remove"]},value:{description:"The data to be updated in the data model. Required for 'add' and 'replace' operations. Not allowed for 'remove' operation.",additionalProperties:true}},required:["surfaceId"],additionalProperties:false}},required:["updateDataModel"],additionalProperties:false},DeleteSurfaceMessage:{properties:{deleteSurface:{type:"object",description:"Signals the client to delete the surface identified by 'surfaceId'. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be deleted."}},required:["surfaceId"],additionalProperties:false}},required:["deleteSurface"],additionalProperties:false}}};var v={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/standard_catalog_definition.json",title:"A2UI Component Catalog",description:"Definitions for the standard catalog of A2UI components.",$defs:{Theme:{type:"object",description:"Theming information for the UI.",properties:{font:{type:"string",description:"The primary font for the UI."},primaryColor:{type:"string",description:"The primary UI color as a hexadecimal code (e.g., '#00BFFF').",pattern:"^#[0-9a-fA-F]{6}$"}},additionalProperties:false},anyComponent:{oneOf:[{$ref:"#/$defs/Text"},{$ref:"#/$defs/Image"},{$ref:"#/$defs/Icon"},{$ref:"#/$defs/Video"},{$ref:"#/$defs/AudioPlayer"},{$ref:"#/$defs/Row"},{$ref:"#/$defs/Column"},{$ref:"#/$defs/List"},{$ref:"#/$defs/Card"},{$ref:"#/$defs/Tabs"},{$ref:"#/$defs/Divider"},{$ref:"#/$defs/Modal"},{$ref:"#/$defs/Button"},{$ref:"#/$defs/CheckBox"},{$ref:"#/$defs/TextField"},{$ref:"#/$defs/DateTimeInput"},{$ref:"#/$defs/ChoicePicker"},{$ref:"#/$defs/Slider"}],discriminator:{propertyName:"component"}},Text:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Text"},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text content to display. While simple Markdown formatting is supported (i.e. without HTML, images, or links), utilizing dedicated UI components is generally preferred for a richer and more structured presentation."},usageHint:{type:"string",description:"A hint for the base text style.",enum:["h1","h2","h3","h4","h5","caption","body"]}},required:["component","text"]}],unevaluatedProperties:false},Image:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Image"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the image to display."},fit:{type:"string",description:"Specifies how the image should be resized to fit its container. This corresponds to the CSS 'object-fit' property.",enum:["contain","cover","fill","none","scale-down"]},usageHint:{type:"string",description:"A hint for the image size and style.",enum:["icon","avatar","smallFeature","mediumFeature","largeFeature","header"]}},required:["component","url"]}],unevaluatedProperties:false},Icon:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Icon"},name:{description:"The name of the icon to display.",oneOf:[{type:"string",enum:["accountCircle","add","arrowBack","arrowForward","attachFile","calendarToday","call","camera","check","close","delete","download","edit","event","error","fastForward","favorite","favoriteOff","folder","help","home","info","locationOn","lock","lockOpen","mail","menu","moreVert","moreHoriz","notificationsOff","notifications","pause","payment","person","phone","photo","play","print","refresh","rewind","search","send","settings","share","shoppingCart","skipNext","skipPrevious","star","starHalf","starOff","stop","upload","visibility","visibilityOff","volumeDown","volumeMute","volumeOff","volumeUp","warning"]},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]}},required:["component","name"]}],unevaluatedProperties:false},Video:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Video"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the video to display."}},required:["component","url"]}],unevaluatedProperties:false},AudioPlayer:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"AudioPlayer"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the audio to be played."},description:{description:"A description of the audio, such as a title or summary.",$ref:"common_types.json#/$defs/stringOrPath"}},required:["component","url"]}],unevaluatedProperties:false},Row:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children horizontally. To create a grid layout, nest Columns within this Row.",properties:{component:{const:"Row"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (horizontally). Use 'spaceBetween' to push items to the edges, or 'start'/'end'/'center' to pack them together.",enum:["center","end","spaceAround","spaceBetween","spaceEvenly","start","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (vertically). This is similar to the CSS 'align-items' property, but uses camelCase values (e.g., 'start').",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Column:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children vertically. To create a grid layout, nest Rows within this Column.",properties:{component:{const:"Column"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (vertically). Use 'spaceBetween' to push items to the edges (e.g. header at top, footer at bottom), or 'start'/'end'/'center' to pack them together.",enum:["start","center","end","spaceBetween","spaceAround","spaceEvenly","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (horizontally). This is similar to the CSS 'align-items' property.",enum:["center","end","start","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},List:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"List"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list.",$ref:"common_types.json#/$defs/childrenProperty"},direction:{type:"string",description:"The direction in which the list items are laid out.",enum:["vertical","horizontal"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis.",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Card:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Card"},child:{type:"string",description:"The ID of the single child component to be rendered inside the card. To display multiple elements, you MUST wrap them in a layout component (like Column or Row) and pass that container's ID here. Do NOT pass multiple IDs or a non-existent ID. Do NOT define the child component inline."}},required:["component","child"]}],unevaluatedProperties:false},Tabs:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Tabs"},tabItems:{type:"array",description:"An array of objects, where each object defines a tab with a title and a child component.",items:{type:"object",properties:{title:{description:"The tab title.",$ref:"common_types.json#/$defs/stringOrPath"},child:{type:"string",description:"The ID of the child component. Do NOT define the component inline."}},required:["title","child"],additionalProperties:false}}},required:["component","tabItems"]}],unevaluatedProperties:false},Divider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Divider"},axis:{type:"string",description:"The orientation of the divider.",enum:["horizontal","vertical"]}},required:["component"]}],unevaluatedProperties:false},Modal:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Modal"},entryPointChild:{type:"string",description:"The ID of the component that opens the modal when interacted with (e.g., a button). Do NOT define the component inline."},contentChild:{type:"string",description:"The ID of the component to be displayed inside the modal. Do NOT define the component inline."}},required:["component","entryPointChild","contentChild"]}],unevaluatedProperties:false},Button:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Button"},child:{type:"string",description:"The ID of the child component. Use a 'Text' component for a labeled button. Only use an 'Icon' if the requirements explicitly ask for an icon-only button. Do NOT define the child component inline."},primary:{type:"boolean",description:"Indicates if this button should be styled as the primary action."},action:{type:"object",description:"The client-side action to be dispatched when the button is clicked. It includes the action's name and an optional context payload.",properties:{name:{type:"string"},context:{type:"object",description:"A JSON object containing the key-value pairs for the action context. Values can be literals or paths. Use literal values unless the value must be dynamically bound to the data model. Do NOT use paths for static IDs.",additionalProperties:{$ref:"common_types.json#/$defs/contextValue"}}},required:["name"],additionalProperties:false}},required:["component","child","action"]}],unevaluatedProperties:false},CheckBox:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"CheckBox"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text to display next to the checkbox."},value:{$ref:"common_types.json#/$defs/booleanOrPath",description:"The current state of the checkbox (true for checked, false for unchecked)."}},required:["component","label","value"]}],unevaluatedProperties:false},TextField:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"TextField"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The value of the text field."},usageHint:{type:"string",description:"The type of input field to display.",enum:["longText","number","shortText","obscured"]},validationRegexp:{type:"string",description:"A regular expression used for client-side validation of the input."}},required:["component","label"]}],unevaluatedProperties:false},DateTimeInput:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"DateTimeInput"},value:{$ref:"common_types.json#/$defs/stringOrPath",description:"The selected date and/or time value in ISO 8601 format. If not yet set, initialize with an empty string."},enableDate:{type:"boolean",description:"If true, allows the user to select a date."},enableTime:{type:"boolean",description:"If true, allows the user to select a time."},outputFormat:{type:"string",description:"The desired format for the output string after a date or time is selected."},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."}},required:["component","value"]}],unevaluatedProperties:false},ChoicePicker:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A component that allows selecting one or more options from a list.",properties:{component:{const:"ChoicePicker"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the group of options."},usageHint:{type:"string",description:"A hint for how the choice picker should be displayed and behave.",enum:["multipleSelection","mutuallyExclusive"]},options:{type:"array",description:"The list of available options to choose from.",items:{type:"object",properties:{label:{description:"The text to display for this option.",$ref:"common_types.json#/$defs/stringOrPath"},value:{type:"string",description:"The stable value associated with this option."}},required:["label","value"],additionalProperties:false}},value:{$ref:"common_types.json#/$defs/stringArrayOrPath",description:"The list of currently selected values. This should be bound to a string array in the data model."}},required:["component","options","value","usageHint"]}],unevaluatedProperties:false},Slider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Slider"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the slider."},min:{type:"number",description:"The minimum value of the slider."},max:{type:"number",description:"The maximum value of the slider."},value:{$ref:"common_types.json#/$defs/numberOrPath",description:"The current value of the slider."}},required:["component","value"]}],unevaluatedProperties:false}}};var c=class{constructor(){p(this,"ajv");p(this,"serverToClientValidator");p(this,"clientToServerValidator");this.ajv=new w__default.default({allErrors:true,strict:false}),x__default.default(this.ajv),this.ajv.addSchema(y,"common_types.json"),this.ajv.addSchema(v,"standard_catalog_definition.json"),this.serverToClientValidator=this.ajv.compile(g),this.clientToServerValidator=this.ajv.compile(u);}validateServerToClientMessage(n){return this.serverToClientValidator(n)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.serverToClientValidator.errors||[])}}validateClientToServerMessage(n){return this.clientToServerValidator(n)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.clientToServerValidator.errors||[])}}validateMessages(n){let e=[];for(let r=0;r<n.length;r++){let t=this.validateServerToClientMessage(n[r]);t.valid||e.push(...t.errors.map(a=>({...a,path:`/messages/${r}${a.path}`})));}return {valid:e.length===0,errors:e}}formatErrors(n){return n.map(e=>({path:e.instancePath||"/",message:e.message||"Validation failed",keyword:e.keyword,expected:e.params,actual:void 0}))}},m=null;function l(){return m||(m=new c),m}function _(o){return l().validateServerToClientMessage(o)}function D(o){return l().validateClientToServerMessage(o)}function M(o){return l().validateMessages(o)}
|
|
2
|
-
exports.A2UISchemaValidator=c;exports.getSchemaValidator=l;exports.validateClientMessage=D;exports.validateMessage=h;exports.validateMessages=C;exports.validateMessagesWithSchema=M;exports.validateV09Message=f;exports.validateWithSchema=_;
|
|
1
|
+
'use strict';var u=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function p(t,i={}){let a=[],n=[];if("createSurface"in t){let{createSurface:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),e.catalogId||a.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in t){let{updateComponents:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!e.components||!Array.isArray(e.components)?a.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):f(e.components,a,n,i);}else if("updateDataModel"in t){let{updateDataModel:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),e.op&&!["add","replace","remove"].includes(e.op)&&a.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),e.op==="remove"&&e.value!==void 0&&n.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),e.op!=="remove"&&e.value===void 0&&e.op==="add"&&a.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in t){let{deleteSurface:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else a.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:a.length===0,errors:a,warnings:n}}function c(t,i={}){return p(t,i)}function l(t,i={}){let a=[],n=[];for(let e=0;e<t.length;e++){let r=t[e];if(!r)continue;let s=c(r,i);for(let o of s.errors)a.push({...o,path:`messages[${e}].${o.path??""}`});for(let o of s.warnings)n.push({...o,path:`messages[${e}].${o.path??""}`});}return {valid:a.length===0,errors:a,warnings:n}}function f(t,i,a,n){let e=new Set,r=false;for(let s=0;s<t.length;s++){let o=t[s];if(!o)continue;let d=`updateComponents.components[${s}]`;o.id?(e.has(o.id)&&i.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${o.id}`,path:`${d}.id`}),e.add(o.id),o.id==="root"&&(r=true)):i.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${d}.id`}),o.component?n.strict&&!u.includes(o.component)&&n.allowedComponents&&!n.allowedComponents.includes(o.component)&&a.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${o.component}`,path:`${d}.component`}):i.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${d}.component`});}!r&&n.strict&&a.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}exports.validateMessage=c;exports.validateMessages=l;exports.validateV09Message=p;
|
|
@@ -62,75 +62,4 @@ declare function validateMessage(message: ServerToClientMessageV09, options?: Va
|
|
|
62
62
|
*/
|
|
63
63
|
declare function validateMessages(messages: ServerToClientMessageV09[], options?: ValidationOptions): ValidationResult;
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
* Schema Validator
|
|
67
|
-
*
|
|
68
|
-
* 基于官方 A2UI v0.9 JSON Schema 的验证器
|
|
69
|
-
*/
|
|
70
|
-
/**
|
|
71
|
-
* Schema 验证结果
|
|
72
|
-
*/
|
|
73
|
-
interface SchemaValidationResult {
|
|
74
|
-
/** 是否有效 */
|
|
75
|
-
valid: boolean;
|
|
76
|
-
/** 验证错误列表 */
|
|
77
|
-
errors: SchemaValidationError[];
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Schema 验证错误
|
|
81
|
-
*/
|
|
82
|
-
interface SchemaValidationError {
|
|
83
|
-
/** JSON Pointer 路径 */
|
|
84
|
-
path: string;
|
|
85
|
-
/** 错误消息 */
|
|
86
|
-
message: string;
|
|
87
|
-
/** 错误关键字 */
|
|
88
|
-
keyword: string;
|
|
89
|
-
/** 期望的值/类型 */
|
|
90
|
-
expected?: unknown;
|
|
91
|
-
/** 实际的值 */
|
|
92
|
-
actual?: unknown;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* A2UI Schema 验证器类
|
|
96
|
-
*/
|
|
97
|
-
declare class A2UISchemaValidator {
|
|
98
|
-
private ajv;
|
|
99
|
-
private serverToClientValidator;
|
|
100
|
-
private clientToServerValidator;
|
|
101
|
-
constructor();
|
|
102
|
-
/**
|
|
103
|
-
* 验证服务器到客户端消息
|
|
104
|
-
*/
|
|
105
|
-
validateServerToClientMessage(message: unknown): SchemaValidationResult;
|
|
106
|
-
/**
|
|
107
|
-
* 验证客户端到服务器消息
|
|
108
|
-
*/
|
|
109
|
-
validateClientToServerMessage(message: unknown): SchemaValidationResult;
|
|
110
|
-
/**
|
|
111
|
-
* 验证消息数组
|
|
112
|
-
*/
|
|
113
|
-
validateMessages(messages: unknown[]): SchemaValidationResult;
|
|
114
|
-
/**
|
|
115
|
-
* 格式化 AJV 错误
|
|
116
|
-
*/
|
|
117
|
-
private formatErrors;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 获取默认验证器实例
|
|
121
|
-
*/
|
|
122
|
-
declare function getSchemaValidator(): A2UISchemaValidator;
|
|
123
|
-
/**
|
|
124
|
-
* 验证服务器到客户端消息(使用官方 JSON Schema)
|
|
125
|
-
*/
|
|
126
|
-
declare function validateWithSchema(message: unknown): SchemaValidationResult;
|
|
127
|
-
/**
|
|
128
|
-
* 验证客户端到服务器消息(使用官方 JSON Schema)
|
|
129
|
-
*/
|
|
130
|
-
declare function validateClientMessage(message: unknown): SchemaValidationResult;
|
|
131
|
-
/**
|
|
132
|
-
* 验证消息数组(使用官方 JSON Schema)
|
|
133
|
-
*/
|
|
134
|
-
declare function validateMessagesWithSchema(messages: unknown[]): SchemaValidationResult;
|
|
135
|
-
|
|
136
|
-
export { A2UISchemaValidator, type SchemaValidationError, type SchemaValidationResult, type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, getSchemaValidator, validateClientMessage, validateMessage, validateMessages, validateMessagesWithSchema, validateV09Message, validateWithSchema };
|
|
65
|
+
export { type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, validateMessage, validateMessages, validateV09Message };
|
|
@@ -62,75 +62,4 @@ declare function validateMessage(message: ServerToClientMessageV09, options?: Va
|
|
|
62
62
|
*/
|
|
63
63
|
declare function validateMessages(messages: ServerToClientMessageV09[], options?: ValidationOptions): ValidationResult;
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
* Schema Validator
|
|
67
|
-
*
|
|
68
|
-
* 基于官方 A2UI v0.9 JSON Schema 的验证器
|
|
69
|
-
*/
|
|
70
|
-
/**
|
|
71
|
-
* Schema 验证结果
|
|
72
|
-
*/
|
|
73
|
-
interface SchemaValidationResult {
|
|
74
|
-
/** 是否有效 */
|
|
75
|
-
valid: boolean;
|
|
76
|
-
/** 验证错误列表 */
|
|
77
|
-
errors: SchemaValidationError[];
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Schema 验证错误
|
|
81
|
-
*/
|
|
82
|
-
interface SchemaValidationError {
|
|
83
|
-
/** JSON Pointer 路径 */
|
|
84
|
-
path: string;
|
|
85
|
-
/** 错误消息 */
|
|
86
|
-
message: string;
|
|
87
|
-
/** 错误关键字 */
|
|
88
|
-
keyword: string;
|
|
89
|
-
/** 期望的值/类型 */
|
|
90
|
-
expected?: unknown;
|
|
91
|
-
/** 实际的值 */
|
|
92
|
-
actual?: unknown;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* A2UI Schema 验证器类
|
|
96
|
-
*/
|
|
97
|
-
declare class A2UISchemaValidator {
|
|
98
|
-
private ajv;
|
|
99
|
-
private serverToClientValidator;
|
|
100
|
-
private clientToServerValidator;
|
|
101
|
-
constructor();
|
|
102
|
-
/**
|
|
103
|
-
* 验证服务器到客户端消息
|
|
104
|
-
*/
|
|
105
|
-
validateServerToClientMessage(message: unknown): SchemaValidationResult;
|
|
106
|
-
/**
|
|
107
|
-
* 验证客户端到服务器消息
|
|
108
|
-
*/
|
|
109
|
-
validateClientToServerMessage(message: unknown): SchemaValidationResult;
|
|
110
|
-
/**
|
|
111
|
-
* 验证消息数组
|
|
112
|
-
*/
|
|
113
|
-
validateMessages(messages: unknown[]): SchemaValidationResult;
|
|
114
|
-
/**
|
|
115
|
-
* 格式化 AJV 错误
|
|
116
|
-
*/
|
|
117
|
-
private formatErrors;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 获取默认验证器实例
|
|
121
|
-
*/
|
|
122
|
-
declare function getSchemaValidator(): A2UISchemaValidator;
|
|
123
|
-
/**
|
|
124
|
-
* 验证服务器到客户端消息(使用官方 JSON Schema)
|
|
125
|
-
*/
|
|
126
|
-
declare function validateWithSchema(message: unknown): SchemaValidationResult;
|
|
127
|
-
/**
|
|
128
|
-
* 验证客户端到服务器消息(使用官方 JSON Schema)
|
|
129
|
-
*/
|
|
130
|
-
declare function validateClientMessage(message: unknown): SchemaValidationResult;
|
|
131
|
-
/**
|
|
132
|
-
* 验证消息数组(使用官方 JSON Schema)
|
|
133
|
-
*/
|
|
134
|
-
declare function validateMessagesWithSchema(messages: unknown[]): SchemaValidationResult;
|
|
135
|
-
|
|
136
|
-
export { A2UISchemaValidator, type SchemaValidationError, type SchemaValidationResult, type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, getSchemaValidator, validateClientMessage, validateMessage, validateMessages, validateMessagesWithSchema, validateV09Message, validateWithSchema };
|
|
65
|
+
export { type ValidationError, type ValidationOptions, type ValidationResult, type ValidationWarning, validateMessage, validateMessages, validateV09Message };
|
package/dist/validators/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import w from'ajv/dist/2020';import x from'ajv-formats';var b=Object.defineProperty;var $=(o,n,e)=>n in o?b(o,n,{enumerable:true,configurable:true,writable:true,value:e}):o[n]=e;var p=(o,n,e)=>$(o,typeof n!="symbol"?n+"":n,e);var I=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function f(o,n={}){let e=[],r=[];if("createSurface"in o){let{createSurface:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),t.catalogId||e.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in o){let{updateComponents:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!t.components||!Array.isArray(t.components)?e.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):T(t.components,e,r,n);}else if("updateDataModel"in o){let{updateDataModel:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),t.op&&!["add","replace","remove"].includes(t.op)&&e.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),t.op==="remove"&&t.value!==void 0&&r.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),t.op!=="remove"&&t.value===void 0&&t.op==="add"&&e.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in o){let{deleteSurface:t}=o;t.surfaceId||e.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else e.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:e.length===0,errors:e,warnings:r}}function h(o,n={}){return f(o,n)}function C(o,n={}){let e=[],r=[];for(let t=0;t<o.length;t++){let a=o[t];if(!a)continue;let s=h(a,n);for(let i of s.errors)e.push({...i,path:`messages[${t}].${i.path??""}`});for(let i of s.warnings)r.push({...i,path:`messages[${t}].${i.path??""}`});}return {valid:e.length===0,errors:e,warnings:r}}function T(o,n,e,r){let t=new Set,a=false;for(let s=0;s<o.length;s++){let i=o[s];if(!i)continue;let d=`updateComponents.components[${s}]`;i.id?(t.has(i.id)&&n.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${i.id}`,path:`${d}.id`}),t.add(i.id),i.id==="root"&&(a=true)):n.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${d}.id`}),i.component?r.strict&&!I.includes(i.component)&&r.allowedComponents&&!r.allowedComponents.includes(i.component)&&e.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${i.component}`,path:`${d}.component`}):n.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${d}.component`});}!a&&r.strict&&e.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}var u={title:"A2UI (Agent to UI) Client-to-Server Event Schema",description:"Describes a JSON payload for a client-to-server event message.",type:"object",minProperties:1,maxProperties:1,properties:{userAction:{type:"object",description:"Reports a user-initiated action from a component.",properties:{name:{type:"string",description:"The name of the action, taken from the component's action.name property."},surfaceId:{type:"string",description:"The id of the surface where the event originated."},sourceComponentId:{type:"string",description:"The id of the component that triggered the event."},timestamp:{type:"string",format:"date-time",description:"An ISO 8601 timestamp of when the event occurred."},context:{type:"object",description:"A JSON object containing the key-value pairs from the component's action.context, after resolving all data bindings.",additionalProperties:true}},required:["name","surfaceId","sourceComponentId","timestamp","context"]},error:{description:"Reports a client-side error.",oneOf:[{type:"object",title:"Validation Failed Error",properties:{code:{const:"VALIDATION_FAILED"},surfaceId:{type:"string",description:"The id of the surface where the error occurred."},path:{type:"string",description:"The JSON pointer to the field that failed validation (e.g. '/components/0/text')."},message:{type:"string",description:"A short one-sentence description of why validation failed."}},required:["code","path","message","surfaceId"]},{type:"object",title:"Generic Error",properties:{code:{not:{const:"VALIDATION_FAILED"}},message:{type:"string",description:"A short one-sentence description of why the error occurred."},surfaceId:{type:"string",description:"The id of the surface where the error occurred."}},required:["code","surfaceId","message"],additionalProperties:true}]}},oneOf:[{required:["userAction"]},{required:["clientUiCapabilities"]},{required:["error"]}]};var y={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/common_types.json",title:"A2UI Common Types",description:"Common type definitions used across A2UI schemas.",$defs:{stringOrPath:{description:"Represents a value that can be either a literal string or a path to a value in the data model.",oneOf:[{type:"string"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},numberOrPath:{description:"Represents a value that can be either a literal number or a path to a value in the data model.",oneOf:[{type:"number"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},booleanOrPath:{description:"Represents a value that can be either a literal boolean or a path to a value in the data model.",oneOf:[{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},stringArrayOrPath:{description:"Represents a value that can be either a literal array of strings or a path to a value in the data model.",oneOf:[{type:"array",items:{type:"string"}},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},id:{type:"string",description:"The unique identifier for this component."},ComponentCommon:{type:"object",properties:{id:{$ref:"#/$defs/id"},weight:{type:"number",description:"The relative weight of this component within a Row or Column. This is similar to the CSS 'flex-grow' property."}},required:["id"]},contextValue:{description:"A value that can be a string, number, boolean, or a path to a value.",oneOf:[{type:"string"},{type:"number"},{type:"boolean"},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]},childrenProperty:{oneOf:[{type:"array",items:{type:"string"},description:"A static list of child component IDs."},{type:"object",description:"A template for generating a dynamic list of children from a data model list. The `componentId` is the component to use as a template.",properties:{componentId:{$ref:"#/$defs/id"},path:{type:"string",description:"The path to the list of component property objects in the data model."}},required:["componentId","path"],additionalProperties:false}]}}};var g={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/server_to_client.json",title:"A2UI Message Schema",description:"Describes a JSON payload for an A2UI (Agent to UI) message, which is used to dynamically construct and update user interfaces.",type:"object",oneOf:[{$ref:"#/$defs/CreateSurfaceMessage"},{$ref:"#/$defs/UpdateComponentsMessage"},{$ref:"#/$defs/UpdateDataModelMessage"},{$ref:"#/$defs/DeleteSurfaceMessage"}],$defs:{CreateSurfaceMessage:{properties:{createSurface:{type:"object",description:"Signals the client to create a new surface and begin rendering it. When this message is sent, the client will expect 'updateComponents' and/or 'updateDataModel' messages for the same surfaceId that define the component tree.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be rendered."},catalogId:{title:"Catalog ID",description:"A string that uniquely identifies this catalog. It is recommended to prefix this with an internet domain that you own, to avoid conflicts e.g. mycompany.com:somecatalog'.",type:"string"}},required:["surfaceId","catalogId"],additionalProperties:false}},required:["createSurface"],additionalProperties:false},UpdateComponentsMessage:{properties:{updateComponents:{type:"object",description:"Updates a surface with a new set of components. This message can be sent multiple times to update the component tree of an existing surface. One of the components in one of the components lists MUST have an 'id' of 'root' to serve as the root of the component tree. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be updated."},components:{type:"array",description:"A list containing all UI components for the surface.",minItems:1,items:{$ref:"standard_catalog_definition.json#/$defs/anyComponent"}}},required:["surfaceId","components"],additionalProperties:false}},required:["updateComponents"],additionalProperties:false},UpdateDataModelMessage:{properties:{updateDataModel:{type:"object",description:"Updates the data model for an existing surface. This message can be sent multiple times to update the data model. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface this data model update applies to."},path:{type:"string",description:"An optional path to a location within the data model (e.g., '/user/name'). If omitted, or set to '/', refers to the entire data model."},op:{type:"string",description:"The operation to perform on the data model. Defaults to 'replace' if omitted.",enum:["add","replace","remove"]},value:{description:"The data to be updated in the data model. Required for 'add' and 'replace' operations. Not allowed for 'remove' operation.",additionalProperties:true}},required:["surfaceId"],additionalProperties:false}},required:["updateDataModel"],additionalProperties:false},DeleteSurfaceMessage:{properties:{deleteSurface:{type:"object",description:"Signals the client to delete the surface identified by 'surfaceId'. The createSurface message MUST have been previously sent with the 'catalogId' that is in this message.",properties:{surfaceId:{type:"string",description:"The unique identifier for the UI surface to be deleted."}},required:["surfaceId"],additionalProperties:false}},required:["deleteSurface"],additionalProperties:false}}};var v={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://a2ui.dev/specification/0.9/standard_catalog_definition.json",title:"A2UI Component Catalog",description:"Definitions for the standard catalog of A2UI components.",$defs:{Theme:{type:"object",description:"Theming information for the UI.",properties:{font:{type:"string",description:"The primary font for the UI."},primaryColor:{type:"string",description:"The primary UI color as a hexadecimal code (e.g., '#00BFFF').",pattern:"^#[0-9a-fA-F]{6}$"}},additionalProperties:false},anyComponent:{oneOf:[{$ref:"#/$defs/Text"},{$ref:"#/$defs/Image"},{$ref:"#/$defs/Icon"},{$ref:"#/$defs/Video"},{$ref:"#/$defs/AudioPlayer"},{$ref:"#/$defs/Row"},{$ref:"#/$defs/Column"},{$ref:"#/$defs/List"},{$ref:"#/$defs/Card"},{$ref:"#/$defs/Tabs"},{$ref:"#/$defs/Divider"},{$ref:"#/$defs/Modal"},{$ref:"#/$defs/Button"},{$ref:"#/$defs/CheckBox"},{$ref:"#/$defs/TextField"},{$ref:"#/$defs/DateTimeInput"},{$ref:"#/$defs/ChoicePicker"},{$ref:"#/$defs/Slider"}],discriminator:{propertyName:"component"}},Text:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Text"},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text content to display. While simple Markdown formatting is supported (i.e. without HTML, images, or links), utilizing dedicated UI components is generally preferred for a richer and more structured presentation."},usageHint:{type:"string",description:"A hint for the base text style.",enum:["h1","h2","h3","h4","h5","caption","body"]}},required:["component","text"]}],unevaluatedProperties:false},Image:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Image"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the image to display."},fit:{type:"string",description:"Specifies how the image should be resized to fit its container. This corresponds to the CSS 'object-fit' property.",enum:["contain","cover","fill","none","scale-down"]},usageHint:{type:"string",description:"A hint for the image size and style.",enum:["icon","avatar","smallFeature","mediumFeature","largeFeature","header"]}},required:["component","url"]}],unevaluatedProperties:false},Icon:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Icon"},name:{description:"The name of the icon to display.",oneOf:[{type:"string",enum:["accountCircle","add","arrowBack","arrowForward","attachFile","calendarToday","call","camera","check","close","delete","download","edit","event","error","fastForward","favorite","favoriteOff","folder","help","home","info","locationOn","lock","lockOpen","mail","menu","moreVert","moreHoriz","notificationsOff","notifications","pause","payment","person","phone","photo","play","print","refresh","rewind","search","send","settings","share","shoppingCart","skipNext","skipPrevious","star","starHalf","starOff","stop","upload","visibility","visibilityOff","volumeDown","volumeMute","volumeOff","volumeUp","warning"]},{type:"object",properties:{path:{type:"string"}},required:["path"],additionalProperties:false}]}},required:["component","name"]}],unevaluatedProperties:false},Video:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Video"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the video to display."}},required:["component","url"]}],unevaluatedProperties:false},AudioPlayer:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"AudioPlayer"},url:{$ref:"common_types.json#/$defs/stringOrPath",description:"The URL of the audio to be played."},description:{description:"A description of the audio, such as a title or summary.",$ref:"common_types.json#/$defs/stringOrPath"}},required:["component","url"]}],unevaluatedProperties:false},Row:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children horizontally. To create a grid layout, nest Columns within this Row.",properties:{component:{const:"Row"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (horizontally). Use 'spaceBetween' to push items to the edges, or 'start'/'end'/'center' to pack them together.",enum:["center","end","spaceAround","spaceBetween","spaceEvenly","start","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (vertically). This is similar to the CSS 'align-items' property, but uses camelCase values (e.g., 'start').",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Column:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A layout component that arranges its children vertically. To create a grid layout, nest Rows within this Column.",properties:{component:{const:"Column"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list. Children cannot be defined inline, they must be referred to by ID.",$ref:"common_types.json#/$defs/childrenProperty"},distribution:{type:"string",description:"Defines the arrangement of children along the main axis (vertically). Use 'spaceBetween' to push items to the edges (e.g. header at top, footer at bottom), or 'start'/'end'/'center' to pack them together.",enum:["start","center","end","spaceBetween","spaceAround","spaceEvenly","stretch"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis (horizontally). This is similar to the CSS 'align-items' property.",enum:["center","end","start","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},List:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"List"},children:{description:"Defines the children. Use an array of strings for a fixed set of children, or a template object to generate children from a data list.",$ref:"common_types.json#/$defs/childrenProperty"},direction:{type:"string",description:"The direction in which the list items are laid out.",enum:["vertical","horizontal"]},alignment:{type:"string",description:"Defines the alignment of children along the cross axis.",enum:["start","center","end","stretch"]}},required:["component","children"]}],unevaluatedProperties:false},Card:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Card"},child:{type:"string",description:"The ID of the single child component to be rendered inside the card. To display multiple elements, you MUST wrap them in a layout component (like Column or Row) and pass that container's ID here. Do NOT pass multiple IDs or a non-existent ID. Do NOT define the child component inline."}},required:["component","child"]}],unevaluatedProperties:false},Tabs:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Tabs"},tabItems:{type:"array",description:"An array of objects, where each object defines a tab with a title and a child component.",items:{type:"object",properties:{title:{description:"The tab title.",$ref:"common_types.json#/$defs/stringOrPath"},child:{type:"string",description:"The ID of the child component. Do NOT define the component inline."}},required:["title","child"],additionalProperties:false}}},required:["component","tabItems"]}],unevaluatedProperties:false},Divider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Divider"},axis:{type:"string",description:"The orientation of the divider.",enum:["horizontal","vertical"]}},required:["component"]}],unevaluatedProperties:false},Modal:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Modal"},entryPointChild:{type:"string",description:"The ID of the component that opens the modal when interacted with (e.g., a button). Do NOT define the component inline."},contentChild:{type:"string",description:"The ID of the component to be displayed inside the modal. Do NOT define the component inline."}},required:["component","entryPointChild","contentChild"]}],unevaluatedProperties:false},Button:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Button"},child:{type:"string",description:"The ID of the child component. Use a 'Text' component for a labeled button. Only use an 'Icon' if the requirements explicitly ask for an icon-only button. Do NOT define the child component inline."},primary:{type:"boolean",description:"Indicates if this button should be styled as the primary action."},action:{type:"object",description:"The client-side action to be dispatched when the button is clicked. It includes the action's name and an optional context payload.",properties:{name:{type:"string"},context:{type:"object",description:"A JSON object containing the key-value pairs for the action context. Values can be literals or paths. Use literal values unless the value must be dynamically bound to the data model. Do NOT use paths for static IDs.",additionalProperties:{$ref:"common_types.json#/$defs/contextValue"}}},required:["name"],additionalProperties:false}},required:["component","child","action"]}],unevaluatedProperties:false},CheckBox:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"CheckBox"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text to display next to the checkbox."},value:{$ref:"common_types.json#/$defs/booleanOrPath",description:"The current state of the checkbox (true for checked, false for unchecked)."}},required:["component","label","value"]}],unevaluatedProperties:false},TextField:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"TextField"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."},text:{$ref:"common_types.json#/$defs/stringOrPath",description:"The value of the text field."},usageHint:{type:"string",description:"The type of input field to display.",enum:["longText","number","shortText","obscured"]},validationRegexp:{type:"string",description:"A regular expression used for client-side validation of the input."}},required:["component","label"]}],unevaluatedProperties:false},DateTimeInput:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"DateTimeInput"},value:{$ref:"common_types.json#/$defs/stringOrPath",description:"The selected date and/or time value in ISO 8601 format. If not yet set, initialize with an empty string."},enableDate:{type:"boolean",description:"If true, allows the user to select a date."},enableTime:{type:"boolean",description:"If true, allows the user to select a time."},outputFormat:{type:"string",description:"The desired format for the output string after a date or time is selected."},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The text label for the input field."}},required:["component","value"]}],unevaluatedProperties:false},ChoicePicker:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",description:"A component that allows selecting one or more options from a list.",properties:{component:{const:"ChoicePicker"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the group of options."},usageHint:{type:"string",description:"A hint for how the choice picker should be displayed and behave.",enum:["multipleSelection","mutuallyExclusive"]},options:{type:"array",description:"The list of available options to choose from.",items:{type:"object",properties:{label:{description:"The text to display for this option.",$ref:"common_types.json#/$defs/stringOrPath"},value:{type:"string",description:"The stable value associated with this option."}},required:["label","value"],additionalProperties:false}},value:{$ref:"common_types.json#/$defs/stringArrayOrPath",description:"The list of currently selected values. This should be bound to a string array in the data model."}},required:["component","options","value","usageHint"]}],unevaluatedProperties:false},Slider:{type:"object",allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{type:"object",properties:{component:{const:"Slider"},label:{$ref:"common_types.json#/$defs/stringOrPath",description:"The label for the slider."},min:{type:"number",description:"The minimum value of the slider."},max:{type:"number",description:"The maximum value of the slider."},value:{$ref:"common_types.json#/$defs/numberOrPath",description:"The current value of the slider."}},required:["component","value"]}],unevaluatedProperties:false}}};var c=class{constructor(){p(this,"ajv");p(this,"serverToClientValidator");p(this,"clientToServerValidator");this.ajv=new w({allErrors:true,strict:false}),x(this.ajv),this.ajv.addSchema(y,"common_types.json"),this.ajv.addSchema(v,"standard_catalog_definition.json"),this.serverToClientValidator=this.ajv.compile(g),this.clientToServerValidator=this.ajv.compile(u);}validateServerToClientMessage(n){return this.serverToClientValidator(n)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.serverToClientValidator.errors||[])}}validateClientToServerMessage(n){return this.clientToServerValidator(n)?{valid:true,errors:[]}:{valid:false,errors:this.formatErrors(this.clientToServerValidator.errors||[])}}validateMessages(n){let e=[];for(let r=0;r<n.length;r++){let t=this.validateServerToClientMessage(n[r]);t.valid||e.push(...t.errors.map(a=>({...a,path:`/messages/${r}${a.path}`})));}return {valid:e.length===0,errors:e}}formatErrors(n){return n.map(e=>({path:e.instancePath||"/",message:e.message||"Validation failed",keyword:e.keyword,expected:e.params,actual:void 0}))}},m=null;function l(){return m||(m=new c),m}function _(o){return l().validateServerToClientMessage(o)}function D(o){return l().validateClientToServerMessage(o)}function M(o){return l().validateMessages(o)}
|
|
2
|
-
export{c as A2UISchemaValidator,l as getSchemaValidator,D as validateClientMessage,h as validateMessage,C as validateMessages,M as validateMessagesWithSchema,f as validateV09Message,_ as validateWithSchema};
|
|
1
|
+
var u=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function p(t,i={}){let a=[],n=[];if("createSurface"in t){let{createSurface:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),e.catalogId||a.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in t){let{updateComponents:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!e.components||!Array.isArray(e.components)?a.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):f(e.components,a,n,i);}else if("updateDataModel"in t){let{updateDataModel:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),e.op&&!["add","replace","remove"].includes(e.op)&&a.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),e.op==="remove"&&e.value!==void 0&&n.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),e.op!=="remove"&&e.value===void 0&&e.op==="add"&&a.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in t){let{deleteSurface:e}=t;e.surfaceId||a.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else a.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:a.length===0,errors:a,warnings:n}}function c(t,i={}){return p(t,i)}function l(t,i={}){let a=[],n=[];for(let e=0;e<t.length;e++){let r=t[e];if(!r)continue;let s=c(r,i);for(let o of s.errors)a.push({...o,path:`messages[${e}].${o.path??""}`});for(let o of s.warnings)n.push({...o,path:`messages[${e}].${o.path??""}`});}return {valid:a.length===0,errors:a,warnings:n}}function f(t,i,a,n){let e=new Set,r=false;for(let s=0;s<t.length;s++){let o=t[s];if(!o)continue;let d=`updateComponents.components[${s}]`;o.id?(e.has(o.id)&&i.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${o.id}`,path:`${d}.id`}),e.add(o.id),o.id==="root"&&(r=true)):i.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${d}.id`}),o.component?n.strict&&!u.includes(o.component)&&n.allowedComponents&&!n.allowedComponents.includes(o.component)&&a.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${o.component}`,path:`${d}.component`}):i.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${d}.component`});}!r&&n.strict&&a.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}export{c as validateMessage,l as validateMessages,p as validateV09Message};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhama/a2ui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A2UI Protocol Core Library - Framework-agnostic TypeScript types and builders for A2UI protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -118,9 +118,5 @@
|
|
|
118
118
|
"engines": {
|
|
119
119
|
"node": ">=18.0.0",
|
|
120
120
|
"pnpm": ">=8.0.0"
|
|
121
|
-
},
|
|
122
|
-
"dependencies": {
|
|
123
|
-
"ajv": "^8.17.1",
|
|
124
|
-
"ajv-formats": "^3.0.1"
|
|
125
121
|
}
|
|
126
122
|
}
|