@zhama/a2ui-core 0.4.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/README.md +60 -141
- package/dist/builders/index.cjs +2 -2
- package/dist/builders/index.d.cts +16 -3
- package/dist/builders/index.d.ts +16 -3
- package/dist/builders/index.js +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/{primitives-nmkVz-tB.d.cts → primitives-DLbBDhLq.d.cts} +1 -35
- package/dist/{primitives-nmkVz-tB.d.ts → primitives-DLbBDhLq.d.ts} +1 -35
- package/dist/surface/index.cjs +2 -2
- package/dist/surface/index.d.cts +1 -1
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +2 -2
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.d.cts +67 -34
- package/dist/types/index.d.ts +67 -34
- package/dist/types/index.js +2 -2
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/validators/index.cjs +1 -1
- package/dist/validators/index.d.cts +8 -12
- package/dist/validators/index.d.ts +8 -12
- package/dist/validators/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function
|
|
2
|
-
`)}function
|
|
3
|
-
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var
|
|
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};
|
|
@@ -36,40 +36,6 @@ type BooleanOrPath = boolean | {
|
|
|
36
36
|
type StringArrayOrPath = string[] | {
|
|
37
37
|
path: string;
|
|
38
38
|
};
|
|
39
|
-
/**
|
|
40
|
-
* v0.8 格式的字符串值(带有 literalString/path 区分)
|
|
41
|
-
*/
|
|
42
|
-
interface StringValue {
|
|
43
|
-
path?: string;
|
|
44
|
-
literalString?: string;
|
|
45
|
-
/** @deprecated 使用 literalString */
|
|
46
|
-
literal?: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* v0.8 格式的数值(带有 literalNumber/path 区分)
|
|
50
|
-
*/
|
|
51
|
-
interface NumberValue {
|
|
52
|
-
path?: string;
|
|
53
|
-
literalNumber?: number;
|
|
54
|
-
/** @deprecated 使用 literalNumber */
|
|
55
|
-
literal?: number;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* v0.8 格式的布尔值(带有 literalBoolean/path 区分)
|
|
59
|
-
*/
|
|
60
|
-
interface BooleanValue {
|
|
61
|
-
path?: string;
|
|
62
|
-
literalBoolean?: boolean;
|
|
63
|
-
/** @deprecated 使用 literalBoolean */
|
|
64
|
-
literal?: boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* v0.8 格式的字符串数组值
|
|
68
|
-
*/
|
|
69
|
-
interface StringArrayValue {
|
|
70
|
-
path?: string;
|
|
71
|
-
literalArray?: string[];
|
|
72
|
-
}
|
|
73
39
|
/**
|
|
74
40
|
* Context value - 用于 Action context 中的值
|
|
75
41
|
*/
|
|
@@ -77,4 +43,4 @@ type ContextValue = string | number | boolean | {
|
|
|
77
43
|
path: string;
|
|
78
44
|
};
|
|
79
45
|
|
|
80
|
-
export type { BooleanOrPath as B, ContextValue as C, NumberOrPath as N, StringOrPath as S, StringArrayOrPath as a
|
|
46
|
+
export type { BooleanOrPath as B, ContextValue as C, NumberOrPath as N, StringOrPath as S, StringArrayOrPath as a };
|
|
@@ -36,40 +36,6 @@ type BooleanOrPath = boolean | {
|
|
|
36
36
|
type StringArrayOrPath = string[] | {
|
|
37
37
|
path: string;
|
|
38
38
|
};
|
|
39
|
-
/**
|
|
40
|
-
* v0.8 格式的字符串值(带有 literalString/path 区分)
|
|
41
|
-
*/
|
|
42
|
-
interface StringValue {
|
|
43
|
-
path?: string;
|
|
44
|
-
literalString?: string;
|
|
45
|
-
/** @deprecated 使用 literalString */
|
|
46
|
-
literal?: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* v0.8 格式的数值(带有 literalNumber/path 区分)
|
|
50
|
-
*/
|
|
51
|
-
interface NumberValue {
|
|
52
|
-
path?: string;
|
|
53
|
-
literalNumber?: number;
|
|
54
|
-
/** @deprecated 使用 literalNumber */
|
|
55
|
-
literal?: number;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* v0.8 格式的布尔值(带有 literalBoolean/path 区分)
|
|
59
|
-
*/
|
|
60
|
-
interface BooleanValue {
|
|
61
|
-
path?: string;
|
|
62
|
-
literalBoolean?: boolean;
|
|
63
|
-
/** @deprecated 使用 literalBoolean */
|
|
64
|
-
literal?: boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* v0.8 格式的字符串数组值
|
|
68
|
-
*/
|
|
69
|
-
interface StringArrayValue {
|
|
70
|
-
path?: string;
|
|
71
|
-
literalArray?: string[];
|
|
72
|
-
}
|
|
73
39
|
/**
|
|
74
40
|
* Context value - 用于 Action context 中的值
|
|
75
41
|
*/
|
|
@@ -77,4 +43,4 @@ type ContextValue = string | number | boolean | {
|
|
|
77
43
|
path: string;
|
|
78
44
|
};
|
|
79
45
|
|
|
80
|
-
export type { BooleanOrPath as B, ContextValue as C, NumberOrPath as N, StringOrPath as S, StringArrayOrPath as a
|
|
46
|
+
export type { BooleanOrPath as B, ContextValue as C, NumberOrPath as N, StringOrPath as S, StringArrayOrPath as a };
|
package/dist/surface/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
exports.SURFACE_IDS=
|
|
1
|
+
'use strict';var n={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},c=0;function i(e="surface"){return c++,`${e}-${Date.now()}-${c}`}function C(){c=0;}var p="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function u(e,t=p){return {createSurface:{surfaceId:e,catalogId:t}}}function g(e,t){return {updateComponents:{surfaceId:e,components:t}}}function f(e,t,a,r="replace"){return {updateDataModel:{surfaceId:e,...a,op:r,...r!=="remove"&&{value:t}}}}function d(e){return {deleteSurface:{surfaceId:e}}}function o(e,t,a){let r=a??i();return t.find(l=>l.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[u(r),g(r,t)],surfaceId:r}}function S(e,t,a,r){let s=r??i();return {messages:[u(s),g(s,t),f(s,a)],surfaceId:s}}function M(e){return d(e)}function I(e,t){return o(e,t,n.CHAT)}function T(e,t){return o(e,t,n.RECOMMENDATION)}function x(e,t){return o(e,t,n.INPUT_FORM)}function D(e,t){return o(e,t,n.ORCHESTRATION)}function A(e,t){return o(e,t,n.STATUS)}
|
|
2
|
+
exports.SURFACE_IDS=n;exports.createA2UISurface=o;exports.createA2UISurfaceWithData=S;exports.createChatSurface=I;exports.createDeleteSurfaceMessage=M;exports.createInputFormSurface=x;exports.createOrchestrationSurface=D;exports.createRecommendationSurface=T;exports.createStatusSurface=A;exports.generateSurfaceId=i;exports.resetSurfaceIdCounter=C;
|
package/dist/surface/index.d.cts
CHANGED
package/dist/surface/index.d.ts
CHANGED
package/dist/surface/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
1
|
+
var n={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},c=0;function i(e="surface"){return c++,`${e}-${Date.now()}-${c}`}function C(){c=0;}var p="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function u(e,t=p){return {createSurface:{surfaceId:e,catalogId:t}}}function g(e,t){return {updateComponents:{surfaceId:e,components:t}}}function f(e,t,a,r="replace"){return {updateDataModel:{surfaceId:e,...a,op:r,...r!=="remove"&&{value:t}}}}function d(e){return {deleteSurface:{surfaceId:e}}}function o(e,t,a){let r=a??i();return t.find(l=>l.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[u(r),g(r,t)],surfaceId:r}}function S(e,t,a,r){let s=r??i();return {messages:[u(s),g(s,t),f(s,a)],surfaceId:s}}function M(e){return d(e)}function I(e,t){return o(e,t,n.CHAT)}function T(e,t){return o(e,t,n.RECOMMENDATION)}function x(e,t){return o(e,t,n.INPUT_FORM)}function D(e,t){return o(e,t,n.ORCHESTRATION)}function A(e,t){return o(e,t,n.STATUS)}
|
|
2
|
+
export{n as SURFACE_IDS,o as createA2UISurface,S as createA2UISurfaceWithData,I as createChatSurface,M as createDeleteSurfaceMessage,x as createInputFormSurface,D as createOrchestrationSurface,T as createRecommendationSurface,A as createStatusSurface,i as generateSurfaceId,C as resetSurfaceIdCounter};
|
package/dist/types/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';function t(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}
|
|
2
|
-
exports.A2UI_EXTENSION_URI=r;exports.
|
|
1
|
+
'use strict';function t(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}var n="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";var r="https://a2ui.dev/specification/0.9",a="application/json+a2ui";
|
|
2
|
+
exports.A2UI_EXTENSION_URI=r;exports.A2UI_MIME_TYPE=a;exports.STANDARD_CATALOG_ID=n;exports.isV09Message=t;
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StringOrPath, N as NumberOrPath, B as BooleanOrPath, a as StringArrayOrPath } from '../primitives-
|
|
2
|
-
export {
|
|
1
|
+
import { S as StringOrPath, N as NumberOrPath, B as BooleanOrPath, a as StringArrayOrPath } from '../primitives-DLbBDhLq.cjs';
|
|
2
|
+
export { C as ContextValue } from '../primitives-DLbBDhLq.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A2UI Component Types
|
|
@@ -24,25 +24,6 @@ interface Action {
|
|
|
24
24
|
*/
|
|
25
25
|
context?: Record<string, StringOrPath | NumberOrPath | BooleanOrPath>;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
* v0.8 格式的 Action 上下文项
|
|
29
|
-
*/
|
|
30
|
-
interface ActionContextItem {
|
|
31
|
-
key: string;
|
|
32
|
-
value: {
|
|
33
|
-
path?: string;
|
|
34
|
-
literalString?: string;
|
|
35
|
-
literalNumber?: number;
|
|
36
|
-
literalBoolean?: boolean;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* v0.8 格式的 Action
|
|
41
|
-
*/
|
|
42
|
-
interface ActionV08 {
|
|
43
|
-
name: string;
|
|
44
|
-
context?: ActionContextItem[];
|
|
45
|
-
}
|
|
46
27
|
/**
|
|
47
28
|
* 组件公共属性
|
|
48
29
|
*/
|
|
@@ -55,6 +36,11 @@ interface ComponentCommon {
|
|
|
55
36
|
* 在 Row 或 Column 中的相对权重(类似 CSS flex-grow)
|
|
56
37
|
*/
|
|
57
38
|
weight?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 额外的 CSS 类名(A2UI 工具类或自定义类)
|
|
41
|
+
* @example ['a2-overflow-y-auto', 'a2-max-h-20']
|
|
42
|
+
*/
|
|
43
|
+
classes?: string[];
|
|
58
44
|
}
|
|
59
45
|
/**
|
|
60
46
|
* Text 组件 - 显示文本内容
|
|
@@ -547,18 +533,19 @@ type ServerToClientMessage = ServerToClientMessageV08 | ServerToClientMessageV09
|
|
|
547
533
|
* 判断是否为 v0.9 消息
|
|
548
534
|
*/
|
|
549
535
|
declare function isV09Message(message: ServerToClientMessage): message is ServerToClientMessageV09;
|
|
550
|
-
/**
|
|
551
|
-
* 判断是否为 v0.8 消息
|
|
552
|
-
*/
|
|
553
|
-
declare function isV08Message(message: ServerToClientMessage): message is ServerToClientMessageV08;
|
|
554
536
|
/**
|
|
555
537
|
* 用户操作事件
|
|
538
|
+
* @see https://a2ui.dev/specification/0.9/client_to_server.json
|
|
556
539
|
*/
|
|
557
540
|
interface UserActionEvent {
|
|
558
541
|
/**
|
|
559
|
-
*
|
|
542
|
+
* 操作名称(来自组件的 action.name)
|
|
543
|
+
*/
|
|
544
|
+
name: string;
|
|
545
|
+
/**
|
|
546
|
+
* 触发操作的 Surface ID
|
|
560
547
|
*/
|
|
561
|
-
|
|
548
|
+
surfaceId: string;
|
|
562
549
|
/**
|
|
563
550
|
* 触发组件的 ID
|
|
564
551
|
*/
|
|
@@ -568,9 +555,9 @@ interface UserActionEvent {
|
|
|
568
555
|
*/
|
|
569
556
|
timestamp: string;
|
|
570
557
|
/**
|
|
571
|
-
*
|
|
558
|
+
* 操作上下文(解析数据绑定后的键值对)
|
|
572
559
|
*/
|
|
573
|
-
context
|
|
560
|
+
context: Record<string, unknown>;
|
|
574
561
|
}
|
|
575
562
|
/**
|
|
576
563
|
* 数据变更事件
|
|
@@ -593,6 +580,54 @@ interface DataChangeEvent {
|
|
|
593
580
|
*/
|
|
594
581
|
sourceComponentId: string;
|
|
595
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* 验证失败错误
|
|
585
|
+
* @see https://a2ui.dev/specification/0.9/client_to_server.json
|
|
586
|
+
*/
|
|
587
|
+
interface ValidationFailedError {
|
|
588
|
+
/**
|
|
589
|
+
* 错误代码
|
|
590
|
+
*/
|
|
591
|
+
code: 'VALIDATION_FAILED';
|
|
592
|
+
/**
|
|
593
|
+
* 发生错误的 Surface ID
|
|
594
|
+
*/
|
|
595
|
+
surfaceId: string;
|
|
596
|
+
/**
|
|
597
|
+
* 验证失败的字段路径(JSON Pointer 格式)
|
|
598
|
+
* @example "/components/0/text"
|
|
599
|
+
*/
|
|
600
|
+
path: string;
|
|
601
|
+
/**
|
|
602
|
+
* 错误描述
|
|
603
|
+
*/
|
|
604
|
+
message: string;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* 通用错误
|
|
608
|
+
*/
|
|
609
|
+
interface GenericError {
|
|
610
|
+
/**
|
|
611
|
+
* 错误代码(非 VALIDATION_FAILED)
|
|
612
|
+
*/
|
|
613
|
+
code: string;
|
|
614
|
+
/**
|
|
615
|
+
* 发生错误的 Surface ID
|
|
616
|
+
*/
|
|
617
|
+
surfaceId: string;
|
|
618
|
+
/**
|
|
619
|
+
* 错误描述
|
|
620
|
+
*/
|
|
621
|
+
message: string;
|
|
622
|
+
/**
|
|
623
|
+
* 其他附加信息
|
|
624
|
+
*/
|
|
625
|
+
[key: string]: unknown;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* 客户端错误消息
|
|
629
|
+
*/
|
|
630
|
+
type ClientErrorMessage = ValidationFailedError | GenericError;
|
|
596
631
|
/**
|
|
597
632
|
* 客户端到服务器消息
|
|
598
633
|
*/
|
|
@@ -600,6 +635,8 @@ type ClientToServerMessage = {
|
|
|
600
635
|
userAction: UserActionEvent;
|
|
601
636
|
} | {
|
|
602
637
|
dataChange: DataChangeEvent;
|
|
638
|
+
} | {
|
|
639
|
+
error: ClientErrorMessage;
|
|
603
640
|
};
|
|
604
641
|
/**
|
|
605
642
|
* 数据模型值类型
|
|
@@ -619,10 +656,6 @@ type DataArray = DataValue[];
|
|
|
619
656
|
* A2UI 标准 Catalog ID
|
|
620
657
|
*/
|
|
621
658
|
declare const STANDARD_CATALOG_ID = "https://a2ui.dev/specification/0.9/standard_catalog_definition.json";
|
|
622
|
-
/**
|
|
623
|
-
* A2UI 扩展 URI (v0.8)
|
|
624
|
-
*/
|
|
625
|
-
declare const A2UI_EXTENSION_URI_V08 = "https://a2ui.org/a2a-extension/a2ui/v0.8";
|
|
626
659
|
/**
|
|
627
660
|
* A2UI 扩展 URI (v0.9)
|
|
628
661
|
*/
|
|
@@ -632,4 +665,4 @@ declare const A2UI_EXTENSION_URI = "https://a2ui.dev/specification/0.9";
|
|
|
632
665
|
*/
|
|
633
666
|
declare const A2UI_MIME_TYPE = "application/json+a2ui";
|
|
634
667
|
|
|
635
|
-
export { A2UI_EXTENSION_URI,
|
|
668
|
+
export { A2UI_EXTENSION_URI, A2UI_MIME_TYPE, type Action, type AnyComponent, type AudioPlayerComponent, BooleanOrPath, type ButtonComponent, type CardComponent, type CheckBoxComponent, type ChildrenProperty, type ChoicePickerComponent, type ClientErrorMessage, type ClientToServerMessage, type ColumnComponent, type ComponentCommon, type ComponentInstance, type ComponentType, type CreateSurfaceMessage, type DataArray, type DataChangeEvent, type DataObject, type DataValue, type DateTimeInputComponent, type DeleteSurfaceMessage, type DividerComponent, type GenericError, type IconComponent, type ImageComponent, type ListComponent, type ModalComponent, NumberOrPath, type RowComponent, STANDARD_CATALOG_ID, type ServerToClientMessageV09, type SliderComponent, type StandardIconName, StringArrayOrPath, StringOrPath, type TabsComponent, type TextComponent, type TextFieldComponent, type Theme, type UpdateComponentsMessage, type UpdateDataModelMessage, type UserActionEvent, type ValidationFailedError, type VideoComponent, isV09Message };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StringOrPath, N as NumberOrPath, B as BooleanOrPath, a as StringArrayOrPath } from '../primitives-
|
|
2
|
-
export {
|
|
1
|
+
import { S as StringOrPath, N as NumberOrPath, B as BooleanOrPath, a as StringArrayOrPath } from '../primitives-DLbBDhLq.js';
|
|
2
|
+
export { C as ContextValue } from '../primitives-DLbBDhLq.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A2UI Component Types
|
|
@@ -24,25 +24,6 @@ interface Action {
|
|
|
24
24
|
*/
|
|
25
25
|
context?: Record<string, StringOrPath | NumberOrPath | BooleanOrPath>;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
* v0.8 格式的 Action 上下文项
|
|
29
|
-
*/
|
|
30
|
-
interface ActionContextItem {
|
|
31
|
-
key: string;
|
|
32
|
-
value: {
|
|
33
|
-
path?: string;
|
|
34
|
-
literalString?: string;
|
|
35
|
-
literalNumber?: number;
|
|
36
|
-
literalBoolean?: boolean;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* v0.8 格式的 Action
|
|
41
|
-
*/
|
|
42
|
-
interface ActionV08 {
|
|
43
|
-
name: string;
|
|
44
|
-
context?: ActionContextItem[];
|
|
45
|
-
}
|
|
46
27
|
/**
|
|
47
28
|
* 组件公共属性
|
|
48
29
|
*/
|
|
@@ -55,6 +36,11 @@ interface ComponentCommon {
|
|
|
55
36
|
* 在 Row 或 Column 中的相对权重(类似 CSS flex-grow)
|
|
56
37
|
*/
|
|
57
38
|
weight?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 额外的 CSS 类名(A2UI 工具类或自定义类)
|
|
41
|
+
* @example ['a2-overflow-y-auto', 'a2-max-h-20']
|
|
42
|
+
*/
|
|
43
|
+
classes?: string[];
|
|
58
44
|
}
|
|
59
45
|
/**
|
|
60
46
|
* Text 组件 - 显示文本内容
|
|
@@ -547,18 +533,19 @@ type ServerToClientMessage = ServerToClientMessageV08 | ServerToClientMessageV09
|
|
|
547
533
|
* 判断是否为 v0.9 消息
|
|
548
534
|
*/
|
|
549
535
|
declare function isV09Message(message: ServerToClientMessage): message is ServerToClientMessageV09;
|
|
550
|
-
/**
|
|
551
|
-
* 判断是否为 v0.8 消息
|
|
552
|
-
*/
|
|
553
|
-
declare function isV08Message(message: ServerToClientMessage): message is ServerToClientMessageV08;
|
|
554
536
|
/**
|
|
555
537
|
* 用户操作事件
|
|
538
|
+
* @see https://a2ui.dev/specification/0.9/client_to_server.json
|
|
556
539
|
*/
|
|
557
540
|
interface UserActionEvent {
|
|
558
541
|
/**
|
|
559
|
-
*
|
|
542
|
+
* 操作名称(来自组件的 action.name)
|
|
543
|
+
*/
|
|
544
|
+
name: string;
|
|
545
|
+
/**
|
|
546
|
+
* 触发操作的 Surface ID
|
|
560
547
|
*/
|
|
561
|
-
|
|
548
|
+
surfaceId: string;
|
|
562
549
|
/**
|
|
563
550
|
* 触发组件的 ID
|
|
564
551
|
*/
|
|
@@ -568,9 +555,9 @@ interface UserActionEvent {
|
|
|
568
555
|
*/
|
|
569
556
|
timestamp: string;
|
|
570
557
|
/**
|
|
571
|
-
*
|
|
558
|
+
* 操作上下文(解析数据绑定后的键值对)
|
|
572
559
|
*/
|
|
573
|
-
context
|
|
560
|
+
context: Record<string, unknown>;
|
|
574
561
|
}
|
|
575
562
|
/**
|
|
576
563
|
* 数据变更事件
|
|
@@ -593,6 +580,54 @@ interface DataChangeEvent {
|
|
|
593
580
|
*/
|
|
594
581
|
sourceComponentId: string;
|
|
595
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* 验证失败错误
|
|
585
|
+
* @see https://a2ui.dev/specification/0.9/client_to_server.json
|
|
586
|
+
*/
|
|
587
|
+
interface ValidationFailedError {
|
|
588
|
+
/**
|
|
589
|
+
* 错误代码
|
|
590
|
+
*/
|
|
591
|
+
code: 'VALIDATION_FAILED';
|
|
592
|
+
/**
|
|
593
|
+
* 发生错误的 Surface ID
|
|
594
|
+
*/
|
|
595
|
+
surfaceId: string;
|
|
596
|
+
/**
|
|
597
|
+
* 验证失败的字段路径(JSON Pointer 格式)
|
|
598
|
+
* @example "/components/0/text"
|
|
599
|
+
*/
|
|
600
|
+
path: string;
|
|
601
|
+
/**
|
|
602
|
+
* 错误描述
|
|
603
|
+
*/
|
|
604
|
+
message: string;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* 通用错误
|
|
608
|
+
*/
|
|
609
|
+
interface GenericError {
|
|
610
|
+
/**
|
|
611
|
+
* 错误代码(非 VALIDATION_FAILED)
|
|
612
|
+
*/
|
|
613
|
+
code: string;
|
|
614
|
+
/**
|
|
615
|
+
* 发生错误的 Surface ID
|
|
616
|
+
*/
|
|
617
|
+
surfaceId: string;
|
|
618
|
+
/**
|
|
619
|
+
* 错误描述
|
|
620
|
+
*/
|
|
621
|
+
message: string;
|
|
622
|
+
/**
|
|
623
|
+
* 其他附加信息
|
|
624
|
+
*/
|
|
625
|
+
[key: string]: unknown;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* 客户端错误消息
|
|
629
|
+
*/
|
|
630
|
+
type ClientErrorMessage = ValidationFailedError | GenericError;
|
|
596
631
|
/**
|
|
597
632
|
* 客户端到服务器消息
|
|
598
633
|
*/
|
|
@@ -600,6 +635,8 @@ type ClientToServerMessage = {
|
|
|
600
635
|
userAction: UserActionEvent;
|
|
601
636
|
} | {
|
|
602
637
|
dataChange: DataChangeEvent;
|
|
638
|
+
} | {
|
|
639
|
+
error: ClientErrorMessage;
|
|
603
640
|
};
|
|
604
641
|
/**
|
|
605
642
|
* 数据模型值类型
|
|
@@ -619,10 +656,6 @@ type DataArray = DataValue[];
|
|
|
619
656
|
* A2UI 标准 Catalog ID
|
|
620
657
|
*/
|
|
621
658
|
declare const STANDARD_CATALOG_ID = "https://a2ui.dev/specification/0.9/standard_catalog_definition.json";
|
|
622
|
-
/**
|
|
623
|
-
* A2UI 扩展 URI (v0.8)
|
|
624
|
-
*/
|
|
625
|
-
declare const A2UI_EXTENSION_URI_V08 = "https://a2ui.org/a2a-extension/a2ui/v0.8";
|
|
626
659
|
/**
|
|
627
660
|
* A2UI 扩展 URI (v0.9)
|
|
628
661
|
*/
|
|
@@ -632,4 +665,4 @@ declare const A2UI_EXTENSION_URI = "https://a2ui.dev/specification/0.9";
|
|
|
632
665
|
*/
|
|
633
666
|
declare const A2UI_MIME_TYPE = "application/json+a2ui";
|
|
634
667
|
|
|
635
|
-
export { A2UI_EXTENSION_URI,
|
|
668
|
+
export { A2UI_EXTENSION_URI, A2UI_MIME_TYPE, type Action, type AnyComponent, type AudioPlayerComponent, BooleanOrPath, type ButtonComponent, type CardComponent, type CheckBoxComponent, type ChildrenProperty, type ChoicePickerComponent, type ClientErrorMessage, type ClientToServerMessage, type ColumnComponent, type ComponentCommon, type ComponentInstance, type ComponentType, type CreateSurfaceMessage, type DataArray, type DataChangeEvent, type DataObject, type DataValue, type DateTimeInputComponent, type DeleteSurfaceMessage, type DividerComponent, type GenericError, type IconComponent, type ImageComponent, type ListComponent, type ModalComponent, NumberOrPath, type RowComponent, STANDARD_CATALOG_ID, type ServerToClientMessageV09, type SliderComponent, type StandardIconName, StringArrayOrPath, StringOrPath, type TabsComponent, type TextComponent, type TextFieldComponent, type Theme, type UpdateComponentsMessage, type UpdateDataModelMessage, type UserActionEvent, type ValidationFailedError, type VideoComponent, isV09Message };
|
package/dist/types/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}
|
|
2
|
-
export{r as A2UI_EXTENSION_URI,
|
|
1
|
+
function t(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}var n="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";var r="https://a2ui.dev/specification/0.9",a="application/json+a2ui";
|
|
2
|
+
export{r as A2UI_EXTENSION_URI,a as A2UI_MIME_TYPE,n as STANDARD_CATALOG_ID,t as isV09Message};
|
package/dist/utils/index.d.cts
CHANGED
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
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;
|