UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.86 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{au as t,ou as n}from"./control-ui-connection-Bfj9beF_.js";import{m as r,p as i,u as a}from"./config-form-utils-BqrafwiP.js";import{a as o,n as s,r as c,t as l}from"./config-form.array-items-DbVc_YXt.js";import{d as u,f as d,m as f,p,s as m,v as h}from"./config-form.constraints-BF6pi17w.js";function g(e){return Object.keys(e??{}).every(e=>P.has(e))}function _(e){let t=e.filter(e=>e!=null),n=t.length!==e.length;return{enumValues:v(t),nullable:n}}function v(e){let t=[];for(let n of e)t.some(e=>Object.is(e,n))||t.push(n);return t}function y(e){let t=new Set,n=Array.isArray(e.type)?e.type:e.type?[e.type]:[];for(let e of n)e!==`null`&&t.add(e);t.size===0&&(e.properties||e.additionalProperties)&&t.add(`object`);for(let n of e.allOf??[])for(let e of y(n))t.add(e);return t}function b(e){if(e.size===1)return e.values().next().value;if(e.size>1&&[...e].every(e=>e===`number`||e===`integer`))return e.has(`integer`)?`integer`:`number`}function x(e){return e.size>1&&b(e)===void 0}function S(e){return b(y(e))}function C(e){return!!(S(e)||e.items||e.enum||e.anyOf||e.oneOf||e.allOf)}function w(e){if(!T(e,I))return!1;if(e.not===void 0)return!0;if(S(e)!==`object`||!t(e.not))return!1;let r=e.not.required;return n(r)&&r.length>0&&Object.keys(e.not).every(e=>e===`required`||P.has(e))}function T(e,n){return Object.keys(e).every(r=>n.has(r)||r===`propertyNames`&&t(e.propertyNames)&&i(e.propertyNames)&&k({type:`string`,...e.propertyNames},[]).unsupportedPaths.length===0)}function E(e){let t=Array.isArray(e.type)?e.type:e.type?[e.type]:[],n=e.nullable===!0||t.length===0||t.includes(`null`);return e.const!==void 0&&(n&&=e.const===null),e.enum&&(n&&=e.enum.some(e=>e===null)),e.allOf&&(n&&=e.allOf.every(E)),e.anyOf&&(n&&=e.anyOf.some(E)),e.oneOf&&(n&&=e.oneOf.filter(E).length===1),n}function D(e){let t=c(e);if(t.length<=1)return!1;let n=new Set(t.flatMap(e=>Object.keys(e.properties??{})));return t.some(e=>{let t=e.additionalProperties;return!!t&&typeof t==`object`&&Object.keys(t).length>0&&[...n].some(t=>!Object.hasOwn(e.properties??{},t))})}function O(e){return!e||typeof e!=`object`?{schema:null,unsupportedPaths:[`<root>`]}:k(e,[])}function k(e,t,n=!1,r,i){let o=e;if(!n&&!e.anyOf&&!e.oneOf&&!e.allOf&&Array.isArray(e.type)&&new Set(e.type.filter(e=>e!==`null`)).size>1&&(e.type.every(e=>e===`null`||L.has(e))||e.type.every(e=>[`string`,`object`,`null`].includes(e)))){let t=e.type.includes(`object`)?[`string`,...e.type.filter(e=>e!==`string`)]:e.type;o={...e,type:t.includes(`object`)?t:void 0,anyOf:t.map(e=>({type:e}))}}let c=new Set,m=e=>{for(let t of e.unsupportedPaths)c.add(t);return e.schema},h={...o},v=a(t)||`<root>`;if(w(o)||c.add(v),o.anyOf||o.oneOf){let e=N(o,t);return e?{schema:m(e),unsupportedPaths:Array.from(c)}:{schema:o,unsupportedPaths:[v]}}let S=Array.isArray(o.type)?o.type.filter(e=>e!==`null`):[],O=y(o),A=n&&!!r&&o.type===void 0&&O.size===0;A&&r&&O.add(r),n&&r&&O.size>0&&x(new Set([...O,r]))&&c.add(v),(new Set(S).size>1||x(O))&&c.add(v);let j=b(O),M=E(o)&&(i===void 0||i);if(o.allOf){let e=[];for(let n of o.allOf)!n||typeof n!=`object`?c.add(v):C(n)?e.push(m(k(n,t,!0,j,M))):(e.push(n),T(n,F)||c.add(v));h.allOf=e}h.type=j??o.type,h.nullable=M;let P=o.properties!==void 0||o.additionalProperties!==void 0,I=o.items!==void 0||o.additionalItems!==void 0;if(h.enum){let{enumValues:e,nullable:t}=_(h.enum);h.enum=e,h.enumIncludesNull=t&&M,e.length===0&&c.add(v)}o.allOf&&M&&!h.enumIncludesNull&&c.add(v);let R=(e,t,r)=>n&&r!==void 0&&!C(e)?(T(e,F)||c.add(r),e):m(k(e,t,n));if(j===`object`&&(!A||P)){let e=o.properties??{},n=new Set(d(o)),r=u(o);[...f(o)].some(e=>!n.has(e))&&!r&&c.add(v),D(o)&&c.add(v);let i={};for(let[n,r]of Object.entries(e)){let e=[...t,n];i[n]=R(r,e,a(e)||`<root>`)}if(h.properties=i,o.allOf)for(let e of d(o)){let n=p(o,e);n&&m(k(n,[...t,e]))}o.additionalProperties===!0?h.additionalProperties={}:o.additionalProperties===!1?h.additionalProperties=!1:o.additionalProperties&&typeof o.additionalProperties==`object`&&(g(o.additionalProperties)||(h.additionalProperties=R(o.additionalProperties,[...t,`*`])))}else if(j===`array`&&(!A||I)){if(Array.isArray(o.items)){let e=[];for(let n=0;n<o.items.length;n+=1){let r=o.items[n];r?e.push(R(r,[...t,n],v)):c.add(v)}h.items=e,h.additionalItems=o.additionalItems&&typeof o.additionalItems==`object`?R(o.additionalItems,[...t,`*`],v):o.additionalItems}else o.items?h.items=R(o.items,[...t,`*`],v):c.add(v);if(o.allOf)for(let e of s(o)){let n=l(o,e);n&&m(k(n,[...t,e]))}}else(!A||j!==`object`&&j!==`array`)&&j!==`string`&&j!==`number`&&j!==`integer`&&j!==`boolean`&&!h.enum&&!(n&&o.allOf)&&c.add(v);return{schema:h,unsupportedPaths:Array.from(c)}}function A(e){if(r(e)!==`object`)return!1;let t=e.properties?.source,n=e.properties?.provider,i=e.properties?.id;return!t||!n||!i?!1:typeof t.const==`string`&&r(n)===`string`&&r(i)===`string`}function j(e){let t=e.oneOf??e.anyOf;return!!(t?.length&&t.every(A))}function M(e){if(e.length!==2)return;let t=e.findIndex(e=>r(e)===`string`);if(!(t<0))return j(e[1-t])?e[t]:void 0}function N(e,t){if(e.allOf)return null;let n=e.anyOf??e.oneOf;if(!n)return null;let i=[],a=[],o=!1;for(let e of n){if(!e||typeof e!=`object`)return null;if(Array.isArray(e.enum)){let{enumValues:t,nullable:n}=_(e.enum);i.push(...t),o||=n}else if(`const`in e){if(e.const==null){o=!0;continue}i.push(e.const)}else r(e)===`null`?o=!0:a.push(e)}o&&=E(e);let s=M(a)??(i.length===0&&a.length===1?a[0]:void 0);if(s)return k({...e,...s,nullable:o||s.nullable,anyOf:void 0,oneOf:void 0,allOf:void 0},t);if(i.length>0&&a.length>0){let t=a.length===1?a[0]:void 0;if(t?.type!==`boolean`||Object.keys(t).length!==1||i.includes(`true`)||i.includes(`false`)||e.anyOf===void 0&&i.some(e=>typeof e==`boolean`))return a.every(e=>e.type===`string`)&&i.every(e=>typeof e==`string`||typeof e==`boolean`)&&!E(e)?{schema:{...e,nullable:o},unsupportedPaths:[]}:null;a.pop(),i.unshift(!0,!1)}return i.length>0&&a.length===0?{schema:{...e,enum:v(i),nullable:o,enumIncludesNull:o,anyOf:void 0,oneOf:void 0,allOf:void 0},unsupportedPaths:[]}:a.length>0&&i.length===0&&a.every(e=>{let t=r(e);return!!t&&R.has(String(t))})?{schema:{...e,nullable:o},unsupportedPaths:[]}:null}var P,F,I,L,R;function z(){return(z=e((()=>{o(),m(),h(),P=new Set([`$id`,`$schema`,`title`,`description`,`default`,`deprecated`,`nullable`,`enumIncludesNull`,`examples`,`readOnly`,`tags`,`writeOnly`,`x-tags`]),F=new Set([...P,`const`,`required`,`additionalProperties`,`minimum`,`maximum`,`exclusiveMinimum`,`exclusiveMaximum`,`multipleOf`,`minLength`,`maxLength`,`pattern`,`format`,`minItems`,`maxItems`,`uniqueItems`]),I=new Set([...F,`type`,`properties`,`items`,`additionalItems`,`enum`,`anyOf`,`oneOf`,`allOf`,`not`]),L=new Set([`string`,`number`,`integer`,`boolean`]),R=new Set([...L,`object`,`array`])})))()}export{z as n,O as t};