buckyos 0.7.183 → 0.7.185
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/cli/dist/cli.mjs +115 -28
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/aiws.ts +93 -21
- package/cli/modules/aiws_place.ts +3 -1
- package/cli/modules/pikg_protocol.ts +1 -1
- package/cli/version.ts +1 -1
- package/dist/aiworkspace_client.d.ts +19 -5
- package/dist/aiworkspace_client.d.ts.map +1 -1
- package/dist/{aiws_bind-82bace11.js → aiws_bind-0654c24e.js} +2 -2
- package/dist/aiws_bind-0654c24e.js.map +1 -0
- package/dist/{aiws_bind-3b874f77.mjs → aiws_bind-0885ff99.mjs} +7 -5
- package/dist/aiws_bind-0885ff99.mjs.map +1 -0
- package/dist/aiws_ext.cjs +1 -1
- package/dist/aiws_ext.mjs +1 -1
- package/dist/{aiws_write-c2de498e.mjs → aiws_write-675664eb.mjs} +5 -3
- package/dist/{aiws_write-c2de498e.mjs.map → aiws_write-675664eb.mjs.map} +1 -1
- package/dist/{aiws_write-89b5cc2a.js → aiws_write-b0333ca1.js} +3 -3
- package/dist/{aiws_write-89b5cc2a.js.map → aiws_write-b0333ca1.js.map} +1 -1
- package/dist/aiws_write.d.ts +5 -1
- package/dist/aiws_write.d.ts.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +4 -4
- package/dist/{content_objid-dff803ff.js → content_objid-252bd154.js} +2 -2
- package/dist/{content_objid-dff803ff.js.map → content_objid-252bd154.js.map} +1 -1
- package/dist/{content_objid-a2cafba9.mjs → content_objid-39f4f273.mjs} +2 -2
- package/dist/{content_objid-a2cafba9.mjs.map → content_objid-39f4f273.mjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -4
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +3 -3
- package/package.json +1 -1
- package/dist/aiws_bind-3b874f77.mjs.map +0 -1
- package/dist/aiws_bind-82bace11.js.map +0 -1
package/dist/aiws_ext.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./aiws_bind-82bace11.js");require("./object_url-8fb5a7bf.js"),require("./ndn_types-5b138882.js");const t="component.json",o="composition.json",s="aiws-manifest.json",i=".aiws-build.json",n="aiws-template/1";class r extends Error{constructor(e){super(e.filter((e=>"error"===e.severity)).map((e=>`${e.file?`${e.file}: `:""}${e.message}`)).join("; ")||"invalid control source"),this.name="AiwsSourceError",this.diagnostics=e}}const a=new TextEncoder,c=new TextDecoder;function l(e,t){return`${e.replace(/\/+$/,"")}/${t}`}function d(e){return e.replace(/[/\\\u0000-\u001f]/g," ").replace(/^\.+/,"").trim().slice(0,80)||"Workspace"}async function f(e){const t=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(t),(e=>e.toString(16).padStart(2,"0"))).join("")}async function p(e){const t=[];for(const[o,s]of e)t.push([o,await f(s)]);return t.sort(((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0)),`sha256:${await f(a.encode(JSON.stringify(t)))}`}function m(e){return JSON.stringify([...e].sort(((e,t)=>e.name.localeCompare(t.name))).map((e=>[e.name,e.obj_id??e.etag??""])))}const u=4194304;function h(e){let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)}async function y(e,t,o=[]){let s=e.reduce(((e,t)=>e+t.bytes.length),0);const i=new Map;if(s>u){if(!t)throw new r([{file:"",severity:"error",message:"a control's inline files are limited to 4194304 bytes per build"}]);for(const o of[...e].sort(((e,t)=>t.bytes.length-e.bytes.length))){if(s<=u)break;i.set(o.name,await t(o.name,o.bytes)),s-=o.bytes.length}}const n=[...o];for(const r of e){const e=i.get(r.name);n.push(e?{name:r.name,obj_id:e}:{name:r.name,base64:h(r.bytes)})}return n.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function g(e,t,o){var s;const i=[],n=[];for(const a of t)if(null==(s=a.obj_id)?void 0:s.startsWith("cyfile:"))i.push({name:a.name,obj_id:a.obj_id});else{if(!a.node_id)throw new r([{file:a.name,severity:"error",message:"the file service did not name this file"}]);n.push({name:a.name,bytes:new Uint8Array(await(await e.readFile(a.node_id)).arrayBuffer())})}return y(n,o,i)}const b=["manifest_version","ident","kind","title","description","host_api","accepts","allow_no_source","default_size","config_schema","bindings","entry","assets","catalog","agent","deps","events","actions","on_bind","on_init_control"],v=["type","enum","default","required","title","description","minimum","maximum","minLength","maxLength","properties","items"],$=/^[a-z0-9][a-z0-9._-]{0,63}$/,_=/^did:[a-z0-9]+:[^/#\s]+$/,w=/^[a-z][a-z0-9_]{0,31}$/,k=/^did:[a-z0-9]+:[^/#\s]+#[a-z0-9][a-z0-9._-]{0,63}$/,j="needs manifest_version 2 (raise it in component.json)",x="needs manifest_version 3 (raise it in component.json)",S="needs manifest_version 4 (raise it in component.json)",O="needs manifest_version 5 (raise it in component.json)",A=["string","number","boolean","object","entity"],N=["text","value","metric","bar","list","badge"],E=["kind","text","label","bind","by","format","limit"],I=["open_source","activate_editor","open_definition"],z=["text","number","select","boolean","color"];function J(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function q(e){return e.length>0&&a.encode(e).length<=255&&!e.includes("\0")&&e.split("/").every((e=>e.length>0&&!e.startsWith(".")))}function T(e){const t=J(e)?e.properties:void 0;return J(t)?t:{}}function C(e,t,o,s){for(const i of e.matchAll(/\{\{([^}]*)\}\}/g)){const e=i[1].trim();e.startsWith("config.")?e.slice(7)in o||s(`${t}: {{${e}}} names no property of config_schema`):s(`${t}: only {{config.<key>}} may be used here`)}}function W(e,t,o){if(e&&"object"==typeof e&&!Array.isArray(e))for(const[s,i]of Object.entries(e))if(v.includes(s)){if("properties"===s&&i&&"object"==typeof i)for(const[e,s]of Object.entries(i))W(s,`${t}/properties/${e}`,o);"items"===s&&W(i,`${t}/items`,o)}else o.push(`${t}/${s}: keyword ${s} is outside the supported subset`);else o.push(`${t}: a schema is an object`)}function D(e,t={},o="declarative.json"){const s=[],i=(e,t)=>s.push({file:o,severity:"error",message:e,...t?{code:t}:{}}),n=e=>s.push({file:o,severity:"warning",message:e});let r;try{const t=JSON.parse(e);if(!J(t))return i("a declarative definition is a JSON object"),s;r=t}catch(f){return i(f instanceof Error?f.message:String(f)),s}const a=J(t.bindings)?t.bindings:{},c=T(t.configSchema),l=(e,t)=>{if("string"==typeof e)C(e,t,c,i);else if(Array.isArray(e))e.forEach(((e,o)=>l(e,`${t}[${o}]`)));else if(J(e))for(const[o,s]of Object.entries(e))l(s,`${t}.${o}`)},d=(e,o)=>{void 0!==e&&(Array.isArray(e)?e.forEach(((e,s)=>{const r=`${o}[${s}]`;if(J(e))if("button"!==e.kind){"string"==typeof e.kind&&N.includes(e.kind)||i(`${r}.kind ${JSON.stringify(e.kind)}: one of ${[...N,"button"].join(", ")}`);for(const t of Object.keys(e))E.includes(t)||n(`${r}: key ${t} is ignored by the interpreter`);if(void 0===e.format||["text","number","percent","currency"].includes(e.format)||i(`${r}.format ${JSON.stringify(e.format)}: text, number, percent or currency`),"string"==typeof e.bind&&e.bind.includes(".")){const t=e.bind.slice(0,e.bind.indexOf("."));"props"===t||t in a||n(`${r}.bind ${JSON.stringify(e.bind)}: ${t} is not a declared binding, so it reads the field ${JSON.stringify(e.bind)} of the main source`)}}else((e,o)=>{void 0!==t.manifestVersion&&t.manifestVersion<3&&i(`${o}: a button ${x}`);for(const t of Object.keys(e))["kind","label","emit","params"].includes(t)||n(`${o}: key ${t} is ignored by the interpreter`);"string"==typeof e.label&&e.label||i(`${o}.label: the button's text (required)`),"string"==typeof e.emit&&e.emit?t.events&&!t.events.includes(e.emit)&&i(`${o}.emit ${e.emit}: not an event of component.json`,"EVENT_UNDECLARED"):i(`${o}.emit: the event the button raises (required)`),void 0!==e.params&&(J(e.params)?l(e.params,`${o}.params`):i(`${o}.params must be an object`))})(e,r);else i(`${r} must be an object`)})):i(`${o} must be an array`))};for(const[p,m]of Object.entries(r))"layout"===p?"stack"!==m&&"row"!==m&&i("layout: stack or row"):"items"===p?d(m,"items"):"view"===p?d(J(m)?m.items:void 0,"view.items"):"accent"===p?"string"!=typeof m&&i("accent must be a colour string"):"actions"===p?(Array.isArray(m)?m:[]).forEach(((e,t)=>{const o=J(e)?e:{};"string"==typeof o.command&&I.includes(o.command)||i(`actions[${t}].command: one of ${I.join(", ")}`),"string"==typeof o.id&&"string"==typeof o.label||i(`actions[${t}] needs id and label`)})):"inspector"===p?(Array.isArray(m)?m:[]).forEach(((e,t)=>{const o=J(e)?e:{};"string"==typeof o.kind&&z.includes(o.kind)||i(`inspector[${t}].kind: one of ${z.join(", ")}`),"string"==typeof o.key&&"string"==typeof o.label||i(`inspector[${t}] needs key and label`)})):n(`key ${p} is not part of the declarative vocabulary`);return void 0===r.items&&void 0===r.view&&n("no items: the control draws nothing"),s}function B(e,t,s=o,i={}){const n=[],r=(e,t)=>n.push({file:s,severity:"error",message:e,...t?{code:t}:{}});let c;try{const t=JSON.parse(e);if(!t||"object"!=typeof t||Array.isArray(t))return r("a composition is a JSON object { layout, slots, chrome?, events? }"),n;c=t}catch(g){return r(g instanceof Error?g.message:String(g)),n}const l=T(t),d=(e,t)=>C(e,t,l,r),f=(e,t,o)=>{"number"==typeof e&&e>=0&&e<=o||("string"==typeof e&&/^\s*\{\{.*\}\}\s*$/.test(e)?d(e,t):r(`${t}: a number in [0, ${o}] or {{config.<key>}}`))},p=void 0!==i.manifestVersion&&i.manifestVersion<4;for(const o of Object.keys(c))["layout","slots","chrome","events","projections","media"].includes(o)?"projections"!==o&&"media"!==o||!p||r(`${o} ${S}`):r(`unknown key ${o} (a composition says layout, slots, chrome, events, projections and media)`);const m=c.layout;let u="stack";if(m&&"object"==typeof m){"stack"===m.algorithm||"fixed"===m.algorithm||"grid"===m.algorithm?u=m.algorithm:r(`layout.algorithm ${JSON.stringify(m.algorithm)}: stack, fixed or grid (the algorithms the host ships)`);for(const[e,t]of Object.entries(m))if("algorithm"!==e)if("direction"!==e&&"spacing"!==e||"stack"===u)if("columns"!==e&&"gap"!==e||"grid"===u)if("direction"===e)"column"!==t&&"row"!==t&&r("layout.direction: column or row");else if("spacing"===e)f(t,"layout.spacing",2e3);else if("columns"===e)(!Number.isInteger(t)||t<1||t>12)&&r("layout.columns: an integer in [1, 12]");else if("gap"===e)f(t,"layout.gap",2e3);else if("padding"===e)if(t&&"object"==typeof t&&!Array.isArray(t))for(const[o,s]of Object.entries(t))["t","r","b","l"].includes(o)||r(`layout.padding.${o}: t, r, b or l`),f(s,`layout.padding.${o}`,2e3);else f(t,"layout.padding",2e3);else r(`layout: unknown key ${e}`);else r(`layout.${e} belongs to the grid layout`);else r(`layout.${e} belongs to the stack layout`);"grid"===u&&void 0===m.columns&&r("layout.columns (1…12) required: the cells of a grid row")}else r("layout { algorithm: stack | fixed | grid } required");const h=c.slots&&"object"==typeof c.slots&&!Array.isArray(c.slots)?c.slots:null;if(h){Object.keys(h).length>16&&r("at most 16 slots");for(const[e,t]of Object.entries(h)){const o=`slots.${e}`;if(w.test(e)||r(`${o}: a slot name is [a-z][a-z0-9_]{0,31}`),!t||"object"!=typeof t||Array.isArray(t)){r(`${o} must be an object`);continue}const s=t;for(const[e,t]of Object.entries(s))if("accepts"===e){if(!Array.isArray(t)||0===t.length||t.length>32){r(`${o}.accepts: 1…32 entries (cell:<ident>, a view type, container)`);continue}for(const e of t)"string"==typeof e&&e.startsWith("cell:")?(!k.test(e.slice(5))||a.encode(e.slice(5)).length>128)&&r(`${o}.accepts ${JSON.stringify(e)}: cell:<author_did>#<name>`):"container"===e||"string"==typeof e&&$.test(e)||r(`${o}.accepts ${JSON.stringify(e)}: cell:<ident>, a view type or container`)}else if("min"===e)(!Number.isInteger(t)||t<0||t>64)&&r(`${o}.min: an integer in [0, 64]`);else if("max"===e)(!Number.isInteger(t)||t<1||t>1e3)&&r(`${o}.max: an integer in [1, 1000]`);else if("placement"===e)"stack"!==t&&"top"!==t&&"bottom"!==t&&"free"!==t?r(`${o}.placement: stack, top, bottom or free`):"fixed"===u&&"free"!==t?r(`${o}.placement: a fixed layout keeps every child where it is (free)`):"grid"===u&&"stack"!==t&&r(`${o}.placement: a grid fills its cells with the slots' children in slot order (stack)`);else if("title"===e)("string"!=typeof t||t.length>256)&&r(`${o}.title: at most 256 characters`);else if("visible"===e){if(p){r(`${o}.visible ${S}`);continue}const e=t;!J(e)||"first_open"!==e.from||Object.keys(e).some((e=>"from"!==e&&"for_ms"!==e))?r(`${o}.visible: { from: "first_open", for_ms }`):"string"==typeof e.for_ms?d(e.for_ms,`${o}.visible.for_ms`):(!Number.isInteger(e.for_ms)||e.for_ms<1||e.for_ms>316224e5)&&r(`${o}.visible.for_ms: milliseconds (≤ a year) or {{config.<key>}}`)}else r(`${o}: unknown key ${e}`);Number.isInteger(s.min)&&Number.isInteger(s.max)&&s.min>s.max&&r(`${o}: min exceeds max`)}}else r("slots { <name>: { accepts?, min?, max?, placement? } } required");const y=c.chrome;if(void 0!==y)if(!y||"object"!=typeof y||Array.isArray(y))r("chrome must be an object");else for(const[o,a]of Object.entries(y)){const e=`chrome.${o}`;if("background"===o||"border"===o)"string"==typeof a&&a.length<=64?d(a,e):r(`${e}: a colour (≤ 64 characters) or {{config.<key>}}`);else if("radius"===o)f(a,e,200);else if("empty"===o)"string"==typeof a&&a.length<=1e3?d(a,e):r(`${e}: a text of at most 1000 characters`);else if("title"===o){const t=a;if(!t||"object"!=typeof t||Array.isArray(t)){r(`${e}: { text, slot? }`);continue}for(const[e,o]of Object.entries(t))"text"===e?"string"==typeof o&&o.length<=256?d(o,"chrome.title.text"):r("chrome.title.text: at most 256 characters"):"slot"===e?"string"==typeof o&&h&&o in h||r(`chrome.title.slot ${JSON.stringify(o)}: a slot of this composition`):r(`chrome.title: unknown key ${e}`);"string"!=typeof t.text&&r("chrome.title.text required")}else r(`chrome: unknown key ${o} (background, radius, border, title, empty)`)}if(void 0!==c.events)if(void 0!==i.manifestVersion&&i.manifestVersion<3&&r(`events ${x}`),J(c.events)){Object.keys(c.events).length>16&&r("events: at most 16");for(const[e,t]of Object.entries(c.events)){const o=`events.${e}`;if(w.test(e)||r(`${o}: an event name is [a-z][a-z0-9_]{0,31}`),!J(t)){r(`${o} must be an object { from: { slot, event }, title?, description? }`);continue}for(const[e,i]of Object.entries(t))if("title"===e)("string"!=typeof i||i.length>256)&&r(`${o}.title: at most 256 characters`);else if("description"===e)("string"!=typeof i||i.length>4e3)&&r(`${o}.description: at most 4000 characters`);else if("on"===e){const e=Array.isArray(i)?i:[i];p?r(`${o}.on ${S}`):(0===e.length||e.length>4||e.some((e=>!J(e)||!["write","wish","open","notify"].includes(String(e.kind)))))&&r(`${o}.on: a handler (write, wish, open, notify) or 1…4 of them`)}else"from"!==e&&r(`${o}: unknown key ${e} (from, title, description, on)`);const s=t.from;if(!J(s)){r(`${o}.from { slot, event } required: the child event it re-raises`);continue}if(void 0!==s.projection){if(p){r(`${o}.from.projection ${S}`);continue}const e=J(c.projections)?c.projections:{};"string"==typeof s.projection&&s.projection in e||r(`${o}.from.projection ${JSON.stringify(s.projection)}: a projection of this composition`),void 0===s.role||"string"==typeof s.role&&w.test(s.role)||r(`${o}.from.role: a role name of its template`);for(const t of Object.keys(s))"projection"!==t&&"role"!==t&&r(`${o}.from: unknown key ${t} (projection, role)`);continue}for(const e of Object.keys(s))"slot"!==e&&"event"!==e&&r(`${o}.from: unknown key ${e} (slot, event)`);const n="string"==typeof s.event&&w.test(s.event)?s.event:void 0;n||r(`${o}.from.event: an event name [a-z][a-z0-9_]{0,31}`);const a="string"==typeof s.slot&&h?h[s.slot]:void 0;if(!J(a)){r(`${o}.from.slot ${JSON.stringify(s.slot)}: a slot of this composition`);continue}if(!n)continue;const l=(Array.isArray(a.accepts)?a.accepts:[]).filter((e=>"string"==typeof e&&e.startsWith("cell:"))).map((e=>e.slice(5)));if(0===l.length){r(`${o}: slot ${s.slot} accepts no cell:<ident>, so no control there declares ${n}`,"EVENT_UNDECLARED");continue}l.map((e=>{var t;return null==(t=i.cellEvents)?void 0:t.call(i,e)})).every((e=>void 0!==e&&!e.includes(n)))&&r(`${o}: no control slot ${s.slot} accepts (${l.join(", ")}) declares the event ${n}`,"EVENT_UNDECLARED")}}else r("events must be an object { <name>: { from: { slot, event }, title?, description? } }");if(void 0!==c.projections&&!p)if(!J(c.projections)||Object.keys(c.projections).length>8)r("projections: at most 8 of name → { source, template, layout }");else for(const[o,a]of Object.entries(c.projections)){const e=`projections.${o}`;if(w.test(o)||r(`${e}: a projection name is [a-z][a-z0-9_]{0,31}`),!J(a)){r(`${e} must be an object`);continue}for(const o of Object.keys(a))["source","mark","template","layout","placement","max_items"].includes(o)||r(`${e}: unknown key ${o} (source, mark, template, layout, placement, max_items)`);const t=a.source,s=J(t)?t.kind:void 0;(!J(t)||!["records","members","counts","viewer"].includes(String(s))||"viewer"!==s&&"string"!=typeof t.binding||"counts"===s&&"string"!=typeof t.field)&&r(`${e}.source: { kind: records | members | counts | viewer, binding (a binding name), field? (counts) }`);const i=J(a.template)&&Array.isArray(a.template.nodes)?a.template.nodes:null;!i||0===i.length||i.length>32?r(`${e}.template: { nodes: [1…32 of { id, view: label | shape | asset, box?, config?, when?, role? }] }`):i.forEach(((t,o)=>{J(t)&&"string"==typeof t.id&&w.test(t.id)?["label","shape","asset"].includes(String(t.view))||r(`${e}.template.nodes[${o}].view: label, shape or asset`):r(`${e}.template.nodes[${o}].id: a name [a-z][a-z0-9_]{0,31}`)}));const n=a.layout;!J(n)||"list"!==n.algorithm&&"grid"!==n.algorithm||!J(n.item)||void 0===n.item.h?r(`${e}.layout: { algorithm: list | grid, columns? (grid), gap?, item: { w?, h } }`):"grid"===n.algorithm&&void 0===n.columns&&r(`${e}.layout.columns required (grid)`),void 0===a.placement||["top","stack","bottom"].includes(String(a.placement))||r(`${e}.placement: top, stack or bottom`)}if(void 0!==c.media&&!p){const e=c.media;(!J(e)||"string"!=typeof e.slot||!h||!(e.slot in h)||"string"!=typeof e.anchor||Object.keys(l).length>0&&!(e.anchor in l))&&r("media: { slot (a slot of this composition), anchor (a config property), loop? (a config property) }")}return n}function L(o,s,i,n){const r=[],c=t,l=e=>r.push({file:c,severity:"error",message:e});let d;try{const e=JSON.parse(o);if(!e||"object"!=typeof e||Array.isArray(e))return l("must be a JSON object"),r;d=e}catch(E){return l(E instanceof Error?E.message:String(E)),r}for(const e of Object.keys(d))b.includes(e)||l(`unknown key ${e}`);const f=d.manifest_version,p="number"==typeof f&&Number.isInteger(f)&&f>=1?f:0;void 0!==d.actions&&(p>0&&p<4?l(`actions ${S}`):!Array.isArray(d.actions)||d.actions.length>16?l("actions: at most 16 of { id, title, icon?, modes?, needs?, run }"):d.actions.forEach(((e,t)=>{if(J(e)&&"string"==typeof e.id&&w.test(e.id)&&"string"==typeof e.title&&e.title){const o=Array.isArray(e.run)?e.run:[e.run];(0===o.length||o.length>4||o.some((e=>!J(e)||!["write","wish","open","notify","config","forward"].includes(String(e.kind)))))&&l(`actions[${t}].run: a handler (write, wish, open, notify, config, forward) or 1…4 of them`)}else l(`actions[${t}]: { id, title, run } (id a name [a-z][a-z0-9_]{0,31})`)}))),p?p>5&&l(`manifest_version ${f} is newer than this client reads (5)`):l("manifest_version (1…5) required");const m=p>0&&p<3,u=d.ident;let h="";u&&"object"==typeof u?("string"==typeof u.author_did&&_.test(u.author_did)||l("ident.author_did must be a DID (did:<method>:<id>)"),"string"==typeof u.name&&$.test(u.name)||l("ident.name must be [a-z0-9][a-z0-9._-]{0,63}"),"string"==typeof u.author_did&&"string"==typeof u.name&&(h=`${u.author_did}#${u.name}`,a.encode(h).length>128&&l("an identity is at most 128 bytes"))):l("ident { author_did, name } required");const y="composite"===d.kind;if("declarative"===d.kind||"html"===d.kind||y||l("kind must be declarative, html or composite"),y&&1===p&&l(`kind composite ${j}`),y)for(const e of["accepts","allow_no_source"])void 0!==d[e]&&l(`${e}: a composite is a container of Blocks, not a Cell showing data`);if(("string"!=typeof d.title||!d.title||d.title.length>256)&&l("title: 1…256 characters"),void 0!==d.config_schema){const e=[];W(d.config_schema,"config_schema",e),e.forEach(l)}if(void 0!==d.bindings)if(d.bindings&&"object"==typeof d.bindings)for(const[e,t]of Object.entries(d.bindings))if(w.test(e)&&"props"!==e||l(`binding name ${e}: [a-z][a-z0-9_]{0,31}, not props`),J(t)){for(const o of Object.keys(t))["accepts","required","many","schema_id","title","description"].includes(o)||l(`binding ${e}: unknown key ${o}`);void 0!==t.many&&"boolean"!=typeof t.many&&l(`binding ${e}.many: true or false`),void 0!==t.schema_id&&("string"!=typeof t.schema_id||!t.schema_id||t.schema_id.length>128)&&l(`binding ${e}.schema_id: a schema id such as buckyos.todo@1`)}else l(`binding ${e} must be an object`);else l("bindings must be an object");if(void 0!==d.on_bind||void 0!==d.on_init_control)if(p>0&&p<5)l(`on_bind / on_init_control ${O}`);else if("html"===d.kind){for(const[e,t]of[["on_bind","bind"],["on_init_control","init_control"]])void 0!==d[e]&&"script"!==d[e]&&l(`${e}: an HTML control writes "script" (its behavior.js handles aiws.on('${t}'))`);"number"==typeof d.host_api&&d.host_api>=5||l("on_bind / on_init_control \"script\": aiws.on('bind') / aiws.on('init_control') need host_api 5")}else if("composite"!==d.kind)l('on_bind / on_init_control: declared steps are for a composite, "script" for an HTML control');else{const t=Array.isArray(d.actions)?d.actions.filter(J).map((e=>String(e.id))):[];e.checkBindSteps(d.on_bind,d.on_init_control,J(d.bindings)?d.bindings:{},t).forEach(l)}if(void 0!==d.deps)if(!Array.isArray(d.deps)||d.deps.length>32)l("deps: at most 32 identities <author_did>#<name>");else if(d.deps.length>0&&1===p)l(`deps ${j}`);else{const e=new Set;for(const t of d.deps)"string"==typeof t&&k.test(t)?t===h?l("deps: a control cannot depend on itself"):e.has(t)&&l(`deps lists ${t} twice`):l(`deps: ${JSON.stringify(t)} is not an identity <author_did>#<name>`),e.add(String(t))}let g=[];if(void 0!==d.events){if(y)l("events: a composite declares its events in composition.json (events.<name>.from re-raises an event of a child)");else if(m)l(`events ${x}`);else{const e=[];!function(e,t){if(J(e)){Object.keys(e).length>16&&t.push("events: at most 16");for(const[o,s]of Object.entries(e)){const e=`events.${o}`;if(w.test(o)||t.push(`${e}: an event name is [a-z][a-z0-9_]{0,31}`),J(s)){for(const[o,i]of Object.entries(s))"title"===o?("string"!=typeof i||i.length>256)&&t.push(`${e}.title: at most 256 characters`):"description"===o?("string"!=typeof i||i.length>4e3)&&t.push(`${e}.description: at most 4000 characters`):"params"!==o&&t.push(`${e}: unknown key ${o} (title, description, params)`);if(void 0!==s.params)if(J(s.params)){Object.keys(s.params).length>16&&t.push(`${e}.params: at most 16`);for(const[o,i]of Object.entries(s.params)){const s=`${e}.params.${o}`;if(w.test(o)||t.push(`${s}: a param name is [a-z][a-z0-9_]{0,31}`),J(i)){for(const[e,o]of Object.entries(i))"type"===e?"string"==typeof o&&A.includes(o)||t.push(`${s}.type: ${A.join(", ")}`):"required"===e?"boolean"!=typeof o&&t.push(`${s}.required must be a boolean`):"description"===e?("string"!=typeof o||o.length>1e3)&&t.push(`${s}.description: at most 1000 characters`):t.push(`${s}: unknown key ${e} (type, required, description)`);void 0===i.type&&t.push(`${s}.type required`)}else t.push(`${s} must be an object { type, required?, description? }`)}}else t.push(`${e}.params must be an object { <param>: { type, required?, description? } }`)}else t.push(`${e} must be an object { title?, description?, params? }`)}}else t.push("events must be an object { <name>: { title?, description?, params? } }")}(d.events,e),e.forEach(l)}!y&&J(d.events)&&(g=Object.keys(d.events))}const v=e=>"string"==typeof e&&s.includes(e),N=new Set([c]);if("html"===d.kind){const e=d.entry;if(e&&"object"==typeof e&&"string"==typeof e.html)for(const[t,o]of Object.entries(e))v(o)?N.add(String(o)):l(`entry.${t} ${JSON.stringify(o)} is not in the directory`);else l("entry must be { html, css?, js? }");void 0===d.host_api||[2,3,4,5,6].includes(d.host_api)?(5===d.host_api||6===d.host_api)&&p<5?l(`host_api ${d.host_api} ${O}`):4===d.host_api&&p<4?l(`host_api 4 ${S}`):3===d.host_api&&m&&l(`host_api 3 ${x}`):l("host_api: the HTML Block host speaks API 2, 3, 4, 5 and 6"),g.length>0&&!("number"==typeof d.host_api&&d.host_api>=3)&&r.push({file:c,severity:"warning",message:"events: an HTML control raises them with aiws.emit, which is host API 3 (set host_api to 3 or later)"})}else if("declarative"===d.kind||y){if(v(d.entry)){N.add(String(d.entry));const e=null==i?void 0:i(String(d.entry)),t=p||void 0;void 0!==e&&y?r.push(...B(e,d.config_schema,String(d.entry),{manifestVersion:t,cellEvents:n})):void 0!==e&&r.push(...D(e,{bindings:d.bindings,events:g,configSchema:d.config_schema,manifestVersion:t},String(d.entry)))}else l(`entry ${JSON.stringify(d.entry)} is not in the directory`);y&&void 0!==d.host_api&&l("host_api: a composite runs no code of its own (its layout and chrome are the host's)"),y||void 0===d.host_api||1===d.host_api||l("host_api: the declarative interpreter is version 1")}for(const e of Array.isArray(d.assets)?d.assets:[])v(e)?N.add(String(e)):l(`asset ${JSON.stringify(e)} is not in the directory`);void 0!==d.agent&&(v(d.agent)?N.add(String(d.agent)):l(`agent ${JSON.stringify(d.agent)} is not in the directory`));for(const e of s)q(e)?N.has(e)||r.push({file:e,severity:"warning",message:"not named by component.json: kept in the source snapshot only"}):r.push({file:e,severity:"error",message:"a file of a source directory: a relative path whose parts do not start with '.'"});return r}function M(e){if(!e||"object"!=typeof e)throw new r([{file:s,severity:"error",message:"must be a JSON object"}]);const t=e,o=t.manifest_version;if("number"!=typeof o||o<1)throw new r([{file:s,severity:"error",message:"manifest_version required"}]);if(o>5)throw new r([{file:s,severity:"error",message:`manifest_version ${o} needs a newer client (this one reads 5)`}]);if("aiws"!==t.purpose)throw new r([{file:s,severity:"error",message:"purpose must be aiws"}]);if(!Array.isArray(t.controls))throw new r([{file:s,severity:"error",message:"controls must be an array"}]);return{manifest_version:o,purpose:"aiws",host_api:t.host_api??{},controls:t.controls,workspace_templates:Array.isArray(t.workspace_templates)?t.workspace_templates:[]}}const F=/^[a-z0-9][a-z0-9-]{0,63}$/;function V(e){return`templates/${e}/`}async function R(e,t){const o=V(t),s=[];for(const[i,n]of e)i.startsWith(o)&&s.push([i.slice(o.length),n]);return p(s)}function P(e,t){if(!J(e))return["a template is an object { id, title, snapshot, digest, requires, description?, params?, reset? }"];const o=[];for(const i of Object.keys(e))["id","title","description","snapshot","digest","requires","params","reset"].includes(i)||o.push(`unknown key ${i}`);"string"==typeof e.id&&F.test(e.id)?e.snapshot!==`${V(e.id)}snapshot.json`&&o.push(`snapshot must be ${V(e.id)}snapshot.json`):o.push("id: [a-z0-9][a-z0-9-]{0,63}"),("string"!=typeof e.title||!e.title||e.title.length>256)&&o.push("title: 1…256 characters"),void 0!==e.description&&("string"!=typeof e.description||e.description.length>4e3)&&o.push("description: at most 4000 characters"),"string"==typeof e.digest&&/^sha256:[0-9a-f]{64}$/.test(e.digest)||o.push("digest: sha256:<64 hex digits>");const s=e.requires;if(J(s)){for(const e of Object.keys(s))"host_api"!==e&&"controls"!==e&&o.push(`requires: unknown key ${e}`);if(void 0!==s.host_api)if(J(s.host_api))for(const[e,t]of Object.entries(s.host_api))("html"!==e&&"declarative"!==e||!Number.isInteger(t)||t<1)&&o.push(`requires.host_api.${e}: html or declarative, a positive integer`);else o.push("requires.host_api must be an object { html?, declarative? }");if(!Array.isArray(s.controls)||s.controls.length>256)o.push("requires.controls: at most 256 identities");else{const e=new Set;for(const i of s.controls)"string"==typeof i&&t.has(i)?e.has(i)&&o.push(`requires.controls lists ${i} twice`):o.push(`requires.controls: ${JSON.stringify(i)} is not a control of this manifest`),e.add(i)}}else o.push("requires { host_api?, controls } required");if(void 0!==e.params)if(!J(e.params)||Object.keys(e.params).length>32)o.push("params: an object of at most 32 { type, title?, default? }");else for(const[i,n]of Object.entries(e.params)){const e=`params.${i}`;if(w.test(i)||o.push(`${e}: a param name is [a-z][a-z0-9_]{0,31}`),J(n)){for(const[t,s]of Object.entries(n))"type"===t?"string"!==s&&"number"!==s&&"boolean"!==s&&o.push(`${e}.type: string, number or boolean`):"title"===t?("string"!=typeof s||s.length>256)&&o.push(`${e}.title: at most 256 characters`):"default"===t?["string","number","boolean"].includes(typeof s)||o.push(`${e}.default: a string, number or boolean`):o.push(`${e}: unknown key ${t} (type, title, default)`);void 0===n.type&&o.push(`${e}.type required`)}else o.push(`${e} must be an object { type, title?, default? }`)}if(void 0!==e.reset){const t=J(e.reset)?e.reset.tables:void 0;!J(e.reset)||Object.keys(e.reset).some((e=>"tables"!==e))?o.push("reset: { tables }"):void 0!==t&&(!Array.isArray(t)||t.length>64||new Set(t).size!==t.length||t.some((e=>"string"!=typeof e||!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(e))))&&o.push("reset.tables: at most 64 distinct table ids")}return o}async function U(e,t,o){const s=/[*?[\]\\]/.test(o)?void 0:o;return(await e.list("string"==typeof t?t:{ref:t},{limit:s?10:1e3,...s?{filter:{name_glob:s}}:{}},["base","ident"])).entries.find((e=>e.name===o))}async function G(e,t){const o=t.split("/").filter(Boolean);if(0===o.length)throw new Error(`not a folder path: ${t}`);let s=(await e.stat(`/${o[0]}`)).ref;for(const i of o.slice(1)){const o=await U(e,s,i);if(o&&"dir"!==o.target.kind)throw new r([{file:i,severity:"error",message:`${i} in ${t} is not a folder`}]);s=o?o.target.ref:(await e.mkdir({ref:s},i)).ref}return s}async function H(e,t){const o=t.split("/").filter(Boolean);if(0===o.length)return null;let s=(await e.stat(`/${o[0]}`)).ref;for(const i of o.slice(1)){const t=await U(e,s,i);if(!t||"dir"!==t.target.kind)return null;s=t.target.ref}return s}async function K(e,o){const s=await H(e,o);return null!==s&&void 0!==await U(e,s,t)}async function X(e,t,o,s){const i="string"==typeof t?await G(e,t):t;await e.uploadFile(i,o,s,{overwrite:!0})}const Y=e=>new Promise((t=>setTimeout(t,e)));async function Q(e,t){const o=[],s=[],i=async(t,n,r)=>{var a,c,l;let d;do{const f=await e.list("string"==typeof t?t:{ref:t},{limit:500,...d?{cursor:d}:{}},["base","ident"]);for(const e of f.entries){if(e.name.startsWith("."))continue;const t=`${n}${e.name}`;if("dir"===e.target.kind){r>=8?s.push({file:t,severity:"error",message:"sub-folders nest at most 8 levels"}):await i(e.target.ref,`${t}/`,r+1);continue}if("file"!==e.target.kind){s.push({file:t,severity:"error",message:"only files and folders belong to a control source"});continue}const d=e.target.ref,f="object"===d.type?d.obj_id:"string"==typeof(null==(a=e.target.attrs)?void 0:a.obj_id)?e.target.attrs.obj_id:void 0;o.push({name:t,...f?{obj_id:f}:{},..."live"===d.type?{node_id:d.node_id}:{},..."string"==typeof(null==(c=e.target.attrs)?void 0:c.etag)?{etag:e.target.attrs.etag}:{},..."number"==typeof(null==(l=e.target.attrs)?void 0:l.size)?{size:e.target.attrs.size}:{}})}d=f.truncated?f.next_cursor:void 0}while(d)};if(await i(t,"",0),0===o.length&&s.push({file:"",severity:"error",message:`${t} holds no files`}),o.length>64&&s.push({file:"",severity:"error",message:"a control holds at most 64 files"}),s.some((e=>"error"===e.severity)))throw new r(s);return o.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function Z(e,t,o,s){const i=o.lastIndexOf("/");await X(e,i<0?t:l(t,o.slice(0,i)),i<0?o:o.slice(i+1),s)}async function ee(e,t){const o=[];for(const s of t){if(!s.node_id)throw new r([{file:s.name,severity:"error",message:"the file service did not name this file"}]);o.push([s.name,new Uint8Array(await(await e.readFile(s.node_id)).arrayBuffer())])}return p(o)}async function te(e,t){try{const o=await U(e,t,i),s="live"===(null==o?void 0:o.target.ref.type)?o.target.ref.node_id:void 0;if(!s)return null;const n=await e.readFile(s);return await n.json()}catch{return null}}async function oe(e,t,o){await X(e,t,i,a.encode(`${JSON.stringify(o,null,2)}\n`))}exports.AIWS_BUILD_STATE_FILE=i,exports.AIWS_COMPONENT_FILE=t,exports.AIWS_COMPOSITION_FILE=o,exports.AIWS_DECLARATIVE_API_VERSION=1,exports.AIWS_HTML_API_VERSION=6,exports.AIWS_MANIFEST_FILE=s,exports.AIWS_MANIFEST_VERSION=5,exports.AIWS_MAX_INLINE_BYTES=u,exports.AIWS_MAX_SOURCE_FILES=64,exports.AIWS_TEMPLATE_FORMAT=n,exports.AiwsSourceError=r,exports.aiwsContentDigest=p,exports.aiwsTemplateDigest=R,exports.buildControl=async function(e,t,o,s,i={}){const n=await Q(t,s),r=await te(t,s),a=r&&r.workspace_id===o?{def_rev:r.def_rev,dir_rev:r.dir_rev}:void 0,c=await e.extBuild(o,{files:await g(t,n,i.upload),...i.folderId?{folder_id:i.folderId}:{},...a?{expect:a}:{},...i.force?{force:!0}:{},...i.dryRun?{dry_run:!0}:{},...i.migration?{migration:i.migration}:{}});return i.dryRun||"string"!=typeof c.def_entity_id||"number"!=typeof c.def_rev||await oe(t,s,{workspace_id:o,def_entity_id:c.def_entity_id,def_rev:c.def_rev,dir_rev:Number(c.dir_rev??0),ident:String(c.ident??""),at:(new Date).toISOString()}),{...c,files:n}},exports.buildFiles=g,exports.checkComponent=L,exports.checkComposition=B,exports.checkDeclarative=D,exports.collectSources=Q,exports.compatManifest=M,exports.controlSkeleton=function(e){const s=e.title??e.name;if("composite"===e.kind){const i="fixed"===e.algorithm,n=e.slots??{items:{placement:i?"free":"stack",title:"Items"}},r={layout:i?{algorithm:"fixed",padding:12}:{algorithm:"stack",direction:"column",spacing:"{{config.gap}}",padding:12},slots:n,chrome:{background:"{{config.background}}",radius:12,title:{text:"{{config.title}}"},empty:"Drop Blocks here"}},a={manifest_version:5,ident:{author_did:e.authorDid,name:e.name},kind:"composite",title:s,description:`${s}: a panel of Blocks`,default_size:{w:320,h:360},config_schema:{type:"object",properties:{title:{type:"string",title:"Title",default:s},background:{type:"string",title:"Background",default:"#f6f7fb"},gap:{type:"integer",title:"Gap (px)",default:8,minimum:0,maximum:64}}},entry:o,deps:e.deps??[],catalog:{group:"custom",description:`${s}`},agent:"AGENT.md"},c=Object.keys(n).map((e=>`\`${e}\``)).join(", ");return{[t]:`${JSON.stringify(a,null,2)}\n`,[o]:`${JSON.stringify(r,null,2)}\n`,"AGENT.md":`# ${s}\n\nA composite: an instance is a \`buckyos.container { kind: "composite", def_ref }\`; put Blocks under it with \`slot\` set to one of ${c}. Config: \`title\`, \`background\`, \`gap\`.\n`}}const i={manifest_version:5,ident:{author_did:e.authorDid,name:e.name},kind:e.kind??"declarative",title:s,description:`${s}: a control of this Workspace`,accepts:["buckyos.table-source","buckyos.record"],allow_no_source:!0,default_size:{w:260,h:140},config_schema:{type:"object",properties:{label:{type:"string",title:"Label",default:s}}},bindings:{data:{accepts:["buckyos.table-source"],title:"Data",description:"The table this control summarizes"}},catalog:{group:"custom",description:`${s}`},agent:"AGENT.md"},n=`# ${s}\n\nBind \`data\` to a table. Config: \`label\` (text).\n`;if("html"===e.kind){const e={clicked:{title:"Clicked",description:"Raised when someone clicks the button (in run mode)",params:{count:{type:"number",description:"Rows of the bound table"}}}};return{[t]:`${JSON.stringify({...i,host_api:6,events:e,entry:{html:"view.html",css:"style.css",js:"behavior.js"}},null,2)}\n`,"view.html":'<div class="card"><div class="label" id="label"></div><div class="value" id="value">—</div><button id="go" type="button">Go</button></div>\n',"style.css":".card{font:14px system-ui;padding:12px}.label{opacity:.7}.value{font-size:28px;font-weight:600}\n","behavior.js":["document.getElementById('label').textContent = (aiws.context.config || {}).label || ''","var count = 0","if (aiws.bindings.data) aiws.input('data').rows().then(function (rows) { count = rows.length; document.getElementById('value').textContent = String(count) })","// the public event of component.json: an instance binds handlers to it in its `on` (host API 3)","document.getElementById('go').addEventListener('click', function () { aiws.emit('clicked', { count: count }) })",""].join("\n"),"AGENT.md":`${n}Event: \`clicked\` (\`count\`), raised by its button; bind handlers to it in the instance's \`on\`.\n`}}return{[t]:`${JSON.stringify({...i,entry:"declarative.json"},null,2)}\n`,"declarative.json":`${JSON.stringify({layout:"stack",items:[{kind:"metric",label:s,bind:"data.count",format:"number"},{kind:"text",text:"Rows of the bound table"}]},null,2)}\n`,"AGENT.md":n}},exports.createControlSource=async function(e,o,s){const i=await G(e,o),n=await e.list({ref:i},{limit:500},["base"]).catch((()=>null));if(null==n?void 0:n.entries.some((e=>e.name===t)))throw new r([{file:t,severity:"error",message:`${o} already holds a control`}]);for(const[t,r]of Object.entries(s))await X(e,i,t,a.encode(r));return i},exports.ensureFolder=G,exports.exportBundle=async function(e,t,o,i){const n=await e.extExport(t,o,"package"),r=new Map;r.set(s,a.encode(`${JSON.stringify(n.manifest,null,2)}\n`));for(const s of n.files)r.set(s.path,void 0!==s.text?a.encode(s.text):await i(t,String(s.obj_id)));return{manifest:M(n.manifest),files:r,controls:n.controls}},exports.findFolder=H,exports.folderName=d,exports.hasControlSource=K,exports.homeControlDir=function(e,t,o){return`/home/${e}/AI Workspace/${d(t)}/controls/${o}`},exports.homeExportDir=function(e,t){return`/home/${e}/AI Workspace/exports/${t}`},exports.isSourcePath=q,exports.joinPath=l,exports.packBuildFiles=y,exports.pullControl=async function(e,t,o,s,i,n){const r=(await e.extExport(o,[s],"pull")).controls[0];await G(t,i);for(const l of r.files)await Z(t,i,l.name,void 0!==l.text?a.encode(l.text):await n(o,String(l.obj_id)));const c={workspace_id:o,def_entity_id:r.entity_id,def_rev:r.def_rev,dir_rev:r.dir_rev,ident:r.ident,at:(new Date).toISOString()};return await oe(t,i,c),{files:r.files.map((e=>e.name)),state:c}},exports.readBuildState=te,exports.slotCells=function(e){const t=new Set;for(const o of Object.values(e.slots??{}))for(const e of o.accepts??[])e.startsWith("cell:")&&t.add(e.slice(5));return[...t].sort()},exports.sourceStateKey=function(e){return`aiws:src:${e}`},exports.sourcesDigest=ee,exports.sourcesKey=m,exports.templateDir=V,exports.unbuiltChanges=async function(e,t,o,s,i){var n;if(!(await K(t,i)))return null;const r=await ee(t,await Q(t,i)),a=await e.extExport(o,[s],"pull"),c=String((null==(n=a.controls[0])?void 0:n.digest)??"");return{changed:r!==c,home:r,built:c}},exports.verifyBundle=async function(e){var o,i;const a=e.get(s);if(!a)throw new r([{file:s,severity:"error",message:"missing"}]);let l;try{l=JSON.parse(c.decode(a))}catch(g){throw new r([{file:s,severity:"error",message:String(g)}])}const d=M(l),f=[],m=d.workspace_templates;m.length>0&&d.manifest_version<3&&f.push({file:s,severity:"error",message:`Workspace templates need manifest_version 3 (raise it in ${s})`}),m.length>32&&f.push({file:s,severity:"error",message:"at most 32 Workspace templates"}),0===d.controls.length&&0===m.length&&f.push({file:s,severity:"error",message:"lists no control"});const u=new Map;for(const s of d.controls){const o="string"==typeof s.dir?e.get(`${s.dir}${t}`):void 0;try{const e=o?JSON.parse(c.decode(o)):void 0;J(e)&&u.set(s.ident,J(e.events)?Object.keys(e.events):[])}catch{}}const h=new Set;for(const n of d.controls){if("string"!=typeof n.dir||!/^controls\/[a-z0-9][a-z0-9._-]{0,70}\/$/.test(n.dir)||h.has(n.dir)){f.push({file:s,severity:"error",message:`control ${n.ident}: bad or repeated dir`});continue}h.add(n.dir);const r=[...e].filter((([e])=>e.startsWith(n.dir))).map((([e,t])=>[e.slice(n.dir.length),t]));await p(r)!==n.digest&&f.push({file:n.dir,severity:"error",message:"the files do not match the manifest digest"});const a=r.find((([e])=>e===t));if(!a){f.push({file:`${n.dir}${t}`,severity:"error",message:"missing"});continue}const l=e=>{const t=r.find((([t])=>t===e));return t?c.decode(t[1]):void 0};for(const e of L(c.decode(a[1]),r.map((([e])=>e)),l,(e=>u.get(e))))f.push({...e,file:`${n.dir}${e.file}`});try{const e=JSON.parse(c.decode(a[1]));`${null==(o=e.ident)?void 0:o.author_did}#${null==(i=e.ident)?void 0:i.name}`===n.ident&&e.kind===n.kind||f.push({file:n.dir,severity:"error",message:"ident and kind must match its component.json"}),JSON.stringify([...e.deps??[]].sort())!==JSON.stringify([...n.deps??[]].sort())&&f.push({file:n.dir,severity:"error",message:"deps must match its component.json"})}catch{}}const y=new Set(d.controls.map((e=>e.ident)));for(const t of d.controls)for(const e of t.deps??[])y.has(e)||f.push({file:s,severity:"error",message:`${t.ident} depends on ${e}, which the bundle does not carry`});for(const[t,r]of m.entries()){const o=J(r)&&"string"==typeof r.id?`template ${r.id}`:`workspace_templates[${t}]`;for(const e of P(r,y))f.push({file:s,severity:"error",message:`${o}: ${e}`});if(!J(r)||"string"!=typeof r.id||!F.test(r.id))continue;const i=V(r.id);if(h.has(i)){f.push({file:s,severity:"error",message:`${o} is listed twice`});continue}h.add(i);const a=e.get(`${i}snapshot.json`);let l;try{l=a?JSON.parse(c.decode(a)).format:void 0}catch{l=void 0}a?l!==n&&f.push({file:`${i}snapshot.json`,severity:"error",message:`not a template snapshot (format ${n})`}):f.push({file:`${i}snapshot.json`,severity:"error",message:"missing"}),await R(e,r.id)!==r.digest&&f.push({file:i,severity:"error",message:"the files do not match the template digest"})}for(const t of e.keys())t===s||[...h].some((e=>t.startsWith(e)))||f.push({file:t,severity:"error",message:"belongs to no control or template of the manifest"});return{manifest:d,diagnostics:f}},exports.watchControl=async function(e,t,o,s={}){var i,n;let r,a="",c=Promise.resolve();const l=()=>{c=c.then((async()=>{let s;try{s=await Q(e,t)}catch{return}const i=m(s);i!==a&&(a=i,await o(s))})).catch((()=>{}))};for(l();!(null==(i=s.signal)?void 0:i.aborted);){const o=await e.list(t,{limit:1},["base"]),i=e.watch({tokens:o.watch_token?[o.watch_token]:[],signal:s.signal});try{for await(const e of i)r&&clearTimeout(r),r=setTimeout(l,s.debounceMs??500)}catch{if(null==(n=s.signal)?void 0:n.aborted)break;await Y(2e3)}finally{i.close()}}r&&clearTimeout(r),await c},exports.writeBuildState=oe,exports.writeHomeFile=X,exports.writeSourceFile=Z;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./aiws_bind-0654c24e.js");require("./object_url-8fb5a7bf.js"),require("./ndn_types-5b138882.js");const t="component.json",o="composition.json",s="aiws-manifest.json",i=".aiws-build.json",n="aiws-template/1";class r extends Error{constructor(e){super(e.filter((e=>"error"===e.severity)).map((e=>`${e.file?`${e.file}: `:""}${e.message}`)).join("; ")||"invalid control source"),this.name="AiwsSourceError",this.diagnostics=e}}const a=new TextEncoder,c=new TextDecoder;function l(e,t){return`${e.replace(/\/+$/,"")}/${t}`}function d(e){return e.replace(/[/\\\u0000-\u001f]/g," ").replace(/^\.+/,"").trim().slice(0,80)||"Workspace"}async function f(e){const t=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(t),(e=>e.toString(16).padStart(2,"0"))).join("")}async function p(e){const t=[];for(const[o,s]of e)t.push([o,await f(s)]);return t.sort(((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0)),`sha256:${await f(a.encode(JSON.stringify(t)))}`}function m(e){return JSON.stringify([...e].sort(((e,t)=>e.name.localeCompare(t.name))).map((e=>[e.name,e.obj_id??e.etag??""])))}const u=4194304;function h(e){let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)}async function y(e,t,o=[]){let s=e.reduce(((e,t)=>e+t.bytes.length),0);const i=new Map;if(s>u){if(!t)throw new r([{file:"",severity:"error",message:"a control's inline files are limited to 4194304 bytes per build"}]);for(const o of[...e].sort(((e,t)=>t.bytes.length-e.bytes.length))){if(s<=u)break;i.set(o.name,await t(o.name,o.bytes)),s-=o.bytes.length}}const n=[...o];for(const r of e){const e=i.get(r.name);n.push(e?{name:r.name,obj_id:e}:{name:r.name,base64:h(r.bytes)})}return n.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function g(e,t,o){var s;const i=[],n=[];for(const a of t)if(null==(s=a.obj_id)?void 0:s.startsWith("cyfile:"))i.push({name:a.name,obj_id:a.obj_id});else{if(!a.node_id)throw new r([{file:a.name,severity:"error",message:"the file service did not name this file"}]);n.push({name:a.name,bytes:new Uint8Array(await(await e.readFile(a.node_id)).arrayBuffer())})}return y(n,o,i)}const b=["manifest_version","ident","kind","title","description","host_api","accepts","allow_no_source","default_size","config_schema","bindings","entry","assets","catalog","agent","deps","events","actions","on_bind","on_init_control"],v=["type","enum","default","required","title","description","minimum","maximum","minLength","maxLength","properties","items"],$=/^[a-z0-9][a-z0-9._-]{0,63}$/,_=/^did:[a-z0-9]+:[^/#\s]+$/,w=/^[a-z][a-z0-9_]{0,31}$/,k=/^did:[a-z0-9]+:[^/#\s]+#[a-z0-9][a-z0-9._-]{0,63}$/,j="needs manifest_version 2 (raise it in component.json)",x="needs manifest_version 3 (raise it in component.json)",S="needs manifest_version 4 (raise it in component.json)",O="needs manifest_version 5 (raise it in component.json)",A=["string","number","boolean","object","entity"],N=["text","value","metric","bar","list","badge"],E=["kind","text","label","bind","by","format","limit"],I=["open_source","activate_editor","open_definition"],z=["text","number","select","boolean","color"];function J(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function q(e){return e.length>0&&a.encode(e).length<=255&&!e.includes("\0")&&e.split("/").every((e=>e.length>0&&!e.startsWith(".")))}function T(e){const t=J(e)?e.properties:void 0;return J(t)?t:{}}function C(e,t,o,s){for(const i of e.matchAll(/\{\{([^}]*)\}\}/g)){const e=i[1].trim();e.startsWith("config.")?e.slice(7)in o||s(`${t}: {{${e}}} names no property of config_schema`):s(`${t}: only {{config.<key>}} may be used here`)}}function W(e,t,o){if(e&&"object"==typeof e&&!Array.isArray(e))for(const[s,i]of Object.entries(e))if(v.includes(s)){if("properties"===s&&i&&"object"==typeof i)for(const[e,s]of Object.entries(i))W(s,`${t}/properties/${e}`,o);"items"===s&&W(i,`${t}/items`,o)}else o.push(`${t}/${s}: keyword ${s} is outside the supported subset`);else o.push(`${t}: a schema is an object`)}function D(e,t={},o="declarative.json"){const s=[],i=(e,t)=>s.push({file:o,severity:"error",message:e,...t?{code:t}:{}}),n=e=>s.push({file:o,severity:"warning",message:e});let r;try{const t=JSON.parse(e);if(!J(t))return i("a declarative definition is a JSON object"),s;r=t}catch(f){return i(f instanceof Error?f.message:String(f)),s}const a=J(t.bindings)?t.bindings:{},c=T(t.configSchema),l=(e,t)=>{if("string"==typeof e)C(e,t,c,i);else if(Array.isArray(e))e.forEach(((e,o)=>l(e,`${t}[${o}]`)));else if(J(e))for(const[o,s]of Object.entries(e))l(s,`${t}.${o}`)},d=(e,o)=>{void 0!==e&&(Array.isArray(e)?e.forEach(((e,s)=>{const r=`${o}[${s}]`;if(J(e))if("button"!==e.kind){"string"==typeof e.kind&&N.includes(e.kind)||i(`${r}.kind ${JSON.stringify(e.kind)}: one of ${[...N,"button"].join(", ")}`);for(const t of Object.keys(e))E.includes(t)||n(`${r}: key ${t} is ignored by the interpreter`);if(void 0===e.format||["text","number","percent","currency"].includes(e.format)||i(`${r}.format ${JSON.stringify(e.format)}: text, number, percent or currency`),"string"==typeof e.bind&&e.bind.includes(".")){const t=e.bind.slice(0,e.bind.indexOf("."));"props"===t||t in a||n(`${r}.bind ${JSON.stringify(e.bind)}: ${t} is not a declared binding, so it reads the field ${JSON.stringify(e.bind)} of the main source`)}}else((e,o)=>{void 0!==t.manifestVersion&&t.manifestVersion<3&&i(`${o}: a button ${x}`);for(const t of Object.keys(e))["kind","label","emit","params"].includes(t)||n(`${o}: key ${t} is ignored by the interpreter`);"string"==typeof e.label&&e.label||i(`${o}.label: the button's text (required)`),"string"==typeof e.emit&&e.emit?t.events&&!t.events.includes(e.emit)&&i(`${o}.emit ${e.emit}: not an event of component.json`,"EVENT_UNDECLARED"):i(`${o}.emit: the event the button raises (required)`),void 0!==e.params&&(J(e.params)?l(e.params,`${o}.params`):i(`${o}.params must be an object`))})(e,r);else i(`${r} must be an object`)})):i(`${o} must be an array`))};for(const[p,m]of Object.entries(r))"layout"===p?"stack"!==m&&"row"!==m&&i("layout: stack or row"):"items"===p?d(m,"items"):"view"===p?d(J(m)?m.items:void 0,"view.items"):"accent"===p?"string"!=typeof m&&i("accent must be a colour string"):"actions"===p?(Array.isArray(m)?m:[]).forEach(((e,t)=>{const o=J(e)?e:{};"string"==typeof o.command&&I.includes(o.command)||i(`actions[${t}].command: one of ${I.join(", ")}`),"string"==typeof o.id&&"string"==typeof o.label||i(`actions[${t}] needs id and label`)})):"inspector"===p?(Array.isArray(m)?m:[]).forEach(((e,t)=>{const o=J(e)?e:{};"string"==typeof o.kind&&z.includes(o.kind)||i(`inspector[${t}].kind: one of ${z.join(", ")}`),"string"==typeof o.key&&"string"==typeof o.label||i(`inspector[${t}] needs key and label`)})):n(`key ${p} is not part of the declarative vocabulary`);return void 0===r.items&&void 0===r.view&&n("no items: the control draws nothing"),s}function B(e,t,s=o,i={}){const n=[],r=(e,t)=>n.push({file:s,severity:"error",message:e,...t?{code:t}:{}});let c;try{const t=JSON.parse(e);if(!t||"object"!=typeof t||Array.isArray(t))return r("a composition is a JSON object { layout, slots, chrome?, events? }"),n;c=t}catch(g){return r(g instanceof Error?g.message:String(g)),n}const l=T(t),d=(e,t)=>C(e,t,l,r),f=(e,t,o)=>{"number"==typeof e&&e>=0&&e<=o||("string"==typeof e&&/^\s*\{\{.*\}\}\s*$/.test(e)?d(e,t):r(`${t}: a number in [0, ${o}] or {{config.<key>}}`))},p=void 0!==i.manifestVersion&&i.manifestVersion<4;for(const o of Object.keys(c))["layout","slots","chrome","events","projections","media"].includes(o)?"projections"!==o&&"media"!==o||!p||r(`${o} ${S}`):r(`unknown key ${o} (a composition says layout, slots, chrome, events, projections and media)`);const m=c.layout;let u="stack";if(m&&"object"==typeof m){"stack"===m.algorithm||"fixed"===m.algorithm||"grid"===m.algorithm?u=m.algorithm:r(`layout.algorithm ${JSON.stringify(m.algorithm)}: stack, fixed or grid (the algorithms the host ships)`);for(const[e,t]of Object.entries(m))if("algorithm"!==e)if("direction"!==e&&"spacing"!==e||"stack"===u)if("columns"!==e&&"gap"!==e||"grid"===u)if("direction"===e)"column"!==t&&"row"!==t&&r("layout.direction: column or row");else if("spacing"===e)f(t,"layout.spacing",2e3);else if("columns"===e)(!Number.isInteger(t)||t<1||t>12)&&r("layout.columns: an integer in [1, 12]");else if("gap"===e)f(t,"layout.gap",2e3);else if("padding"===e)if(t&&"object"==typeof t&&!Array.isArray(t))for(const[o,s]of Object.entries(t))["t","r","b","l"].includes(o)||r(`layout.padding.${o}: t, r, b or l`),f(s,`layout.padding.${o}`,2e3);else f(t,"layout.padding",2e3);else r(`layout: unknown key ${e}`);else r(`layout.${e} belongs to the grid layout`);else r(`layout.${e} belongs to the stack layout`);"grid"===u&&void 0===m.columns&&r("layout.columns (1…12) required: the cells of a grid row")}else r("layout { algorithm: stack | fixed | grid } required");const h=c.slots&&"object"==typeof c.slots&&!Array.isArray(c.slots)?c.slots:null;if(h){Object.keys(h).length>16&&r("at most 16 slots");for(const[e,t]of Object.entries(h)){const o=`slots.${e}`;if(w.test(e)||r(`${o}: a slot name is [a-z][a-z0-9_]{0,31}`),!t||"object"!=typeof t||Array.isArray(t)){r(`${o} must be an object`);continue}const s=t;for(const[e,t]of Object.entries(s))if("accepts"===e){if(!Array.isArray(t)||0===t.length||t.length>32){r(`${o}.accepts: 1…32 entries (cell:<ident>, a view type, container)`);continue}for(const e of t)"string"==typeof e&&e.startsWith("cell:")?(!k.test(e.slice(5))||a.encode(e.slice(5)).length>128)&&r(`${o}.accepts ${JSON.stringify(e)}: cell:<author_did>#<name>`):"container"===e||"string"==typeof e&&$.test(e)||r(`${o}.accepts ${JSON.stringify(e)}: cell:<ident>, a view type or container`)}else if("min"===e)(!Number.isInteger(t)||t<0||t>64)&&r(`${o}.min: an integer in [0, 64]`);else if("max"===e)(!Number.isInteger(t)||t<1||t>1e3)&&r(`${o}.max: an integer in [1, 1000]`);else if("placement"===e)"stack"!==t&&"top"!==t&&"bottom"!==t&&"free"!==t?r(`${o}.placement: stack, top, bottom or free`):"fixed"===u&&"free"!==t?r(`${o}.placement: a fixed layout keeps every child where it is (free)`):"grid"===u&&"stack"!==t&&r(`${o}.placement: a grid fills its cells with the slots' children in slot order (stack)`);else if("title"===e)("string"!=typeof t||t.length>256)&&r(`${o}.title: at most 256 characters`);else if("visible"===e){if(p){r(`${o}.visible ${S}`);continue}const e=t;!J(e)||"first_open"!==e.from||Object.keys(e).some((e=>"from"!==e&&"for_ms"!==e))?r(`${o}.visible: { from: "first_open", for_ms }`):"string"==typeof e.for_ms?d(e.for_ms,`${o}.visible.for_ms`):(!Number.isInteger(e.for_ms)||e.for_ms<1||e.for_ms>316224e5)&&r(`${o}.visible.for_ms: milliseconds (≤ a year) or {{config.<key>}}`)}else r(`${o}: unknown key ${e}`);Number.isInteger(s.min)&&Number.isInteger(s.max)&&s.min>s.max&&r(`${o}: min exceeds max`)}}else r("slots { <name>: { accepts?, min?, max?, placement? } } required");const y=c.chrome;if(void 0!==y)if(!y||"object"!=typeof y||Array.isArray(y))r("chrome must be an object");else for(const[o,a]of Object.entries(y)){const e=`chrome.${o}`;if("background"===o||"border"===o)"string"==typeof a&&a.length<=64?d(a,e):r(`${e}: a colour (≤ 64 characters) or {{config.<key>}}`);else if("radius"===o)f(a,e,200);else if("empty"===o)"string"==typeof a&&a.length<=1e3?d(a,e):r(`${e}: a text of at most 1000 characters`);else if("title"===o){const t=a;if(!t||"object"!=typeof t||Array.isArray(t)){r(`${e}: { text, slot? }`);continue}for(const[e,o]of Object.entries(t))"text"===e?"string"==typeof o&&o.length<=256?d(o,"chrome.title.text"):r("chrome.title.text: at most 256 characters"):"slot"===e?"string"==typeof o&&h&&o in h||r(`chrome.title.slot ${JSON.stringify(o)}: a slot of this composition`):r(`chrome.title: unknown key ${e}`);"string"!=typeof t.text&&r("chrome.title.text required")}else r(`chrome: unknown key ${o} (background, radius, border, title, empty)`)}if(void 0!==c.events)if(void 0!==i.manifestVersion&&i.manifestVersion<3&&r(`events ${x}`),J(c.events)){Object.keys(c.events).length>16&&r("events: at most 16");for(const[e,t]of Object.entries(c.events)){const o=`events.${e}`;if(w.test(e)||r(`${o}: an event name is [a-z][a-z0-9_]{0,31}`),!J(t)){r(`${o} must be an object { from: { slot, event }, title?, description? }`);continue}for(const[e,i]of Object.entries(t))if("title"===e)("string"!=typeof i||i.length>256)&&r(`${o}.title: at most 256 characters`);else if("description"===e)("string"!=typeof i||i.length>4e3)&&r(`${o}.description: at most 4000 characters`);else if("on"===e){const e=Array.isArray(i)?i:[i];p?r(`${o}.on ${S}`):(0===e.length||e.length>4||e.some((e=>!J(e)||!["write","wish","open","notify"].includes(String(e.kind)))))&&r(`${o}.on: a handler (write, wish, open, notify) or 1…4 of them`)}else"from"!==e&&r(`${o}: unknown key ${e} (from, title, description, on)`);const s=t.from;if(!J(s)){r(`${o}.from { slot, event } required: the child event it re-raises`);continue}if(void 0!==s.projection){if(p){r(`${o}.from.projection ${S}`);continue}const e=J(c.projections)?c.projections:{};"string"==typeof s.projection&&s.projection in e||r(`${o}.from.projection ${JSON.stringify(s.projection)}: a projection of this composition`),void 0===s.role||"string"==typeof s.role&&w.test(s.role)||r(`${o}.from.role: a role name of its template`);for(const t of Object.keys(s))"projection"!==t&&"role"!==t&&r(`${o}.from: unknown key ${t} (projection, role)`);continue}for(const e of Object.keys(s))"slot"!==e&&"event"!==e&&r(`${o}.from: unknown key ${e} (slot, event)`);const n="string"==typeof s.event&&w.test(s.event)?s.event:void 0;n||r(`${o}.from.event: an event name [a-z][a-z0-9_]{0,31}`);const a="string"==typeof s.slot&&h?h[s.slot]:void 0;if(!J(a)){r(`${o}.from.slot ${JSON.stringify(s.slot)}: a slot of this composition`);continue}if(!n)continue;const l=(Array.isArray(a.accepts)?a.accepts:[]).filter((e=>"string"==typeof e&&e.startsWith("cell:"))).map((e=>e.slice(5)));if(0===l.length){r(`${o}: slot ${s.slot} accepts no cell:<ident>, so no control there declares ${n}`,"EVENT_UNDECLARED");continue}l.map((e=>{var t;return null==(t=i.cellEvents)?void 0:t.call(i,e)})).every((e=>void 0!==e&&!e.includes(n)))&&r(`${o}: no control slot ${s.slot} accepts (${l.join(", ")}) declares the event ${n}`,"EVENT_UNDECLARED")}}else r("events must be an object { <name>: { from: { slot, event }, title?, description? } }");if(void 0!==c.projections&&!p)if(!J(c.projections)||Object.keys(c.projections).length>8)r("projections: at most 8 of name → { source, template, layout }");else for(const[o,a]of Object.entries(c.projections)){const e=`projections.${o}`;if(w.test(o)||r(`${e}: a projection name is [a-z][a-z0-9_]{0,31}`),!J(a)){r(`${e} must be an object`);continue}for(const o of Object.keys(a))["source","mark","template","layout","placement","max_items"].includes(o)||r(`${e}: unknown key ${o} (source, mark, template, layout, placement, max_items)`);const t=a.source,s=J(t)?t.kind:void 0;(!J(t)||!["records","members","counts","viewer"].includes(String(s))||"viewer"!==s&&"string"!=typeof t.binding||"counts"===s&&"string"!=typeof t.field)&&r(`${e}.source: { kind: records | members | counts | viewer, binding (a binding name), field? (counts) }`);const i=J(a.template)&&Array.isArray(a.template.nodes)?a.template.nodes:null;!i||0===i.length||i.length>32?r(`${e}.template: { nodes: [1…32 of { id, view: label | shape | asset, box?, config?, when?, role? }] }`):i.forEach(((t,o)=>{J(t)&&"string"==typeof t.id&&w.test(t.id)?["label","shape","asset"].includes(String(t.view))||r(`${e}.template.nodes[${o}].view: label, shape or asset`):r(`${e}.template.nodes[${o}].id: a name [a-z][a-z0-9_]{0,31}`)}));const n=a.layout;!J(n)||"list"!==n.algorithm&&"grid"!==n.algorithm||!J(n.item)||void 0===n.item.h?r(`${e}.layout: { algorithm: list | grid, columns? (grid), gap?, item: { w?, h } }`):"grid"===n.algorithm&&void 0===n.columns&&r(`${e}.layout.columns required (grid)`),void 0===a.placement||["top","stack","bottom"].includes(String(a.placement))||r(`${e}.placement: top, stack or bottom`)}if(void 0!==c.media&&!p){const e=c.media;(!J(e)||"string"!=typeof e.slot||!h||!(e.slot in h)||"string"!=typeof e.anchor||Object.keys(l).length>0&&!(e.anchor in l))&&r("media: { slot (a slot of this composition), anchor (a config property), loop? (a config property) }")}return n}function L(o,s,i,n){const r=[],c=t,l=e=>r.push({file:c,severity:"error",message:e});let d;try{const e=JSON.parse(o);if(!e||"object"!=typeof e||Array.isArray(e))return l("must be a JSON object"),r;d=e}catch(E){return l(E instanceof Error?E.message:String(E)),r}for(const e of Object.keys(d))b.includes(e)||l(`unknown key ${e}`);const f=d.manifest_version,p="number"==typeof f&&Number.isInteger(f)&&f>=1?f:0;void 0!==d.actions&&(p>0&&p<4?l(`actions ${S}`):!Array.isArray(d.actions)||d.actions.length>16?l("actions: at most 16 of { id, title, icon?, modes?, needs?, run }"):d.actions.forEach(((e,t)=>{if(J(e)&&"string"==typeof e.id&&w.test(e.id)&&"string"==typeof e.title&&e.title){const o=Array.isArray(e.run)?e.run:[e.run];(0===o.length||o.length>4||o.some((e=>!J(e)||!["write","wish","open","notify","config","forward"].includes(String(e.kind)))))&&l(`actions[${t}].run: a handler (write, wish, open, notify, config, forward) or 1…4 of them`)}else l(`actions[${t}]: { id, title, run } (id a name [a-z][a-z0-9_]{0,31})`)}))),p?p>5&&l(`manifest_version ${f} is newer than this client reads (5)`):l("manifest_version (1…5) required");const m=p>0&&p<3,u=d.ident;let h="";u&&"object"==typeof u?("string"==typeof u.author_did&&_.test(u.author_did)||l("ident.author_did must be a DID (did:<method>:<id>)"),"string"==typeof u.name&&$.test(u.name)||l("ident.name must be [a-z0-9][a-z0-9._-]{0,63}"),"string"==typeof u.author_did&&"string"==typeof u.name&&(h=`${u.author_did}#${u.name}`,a.encode(h).length>128&&l("an identity is at most 128 bytes"))):l("ident { author_did, name } required");const y="composite"===d.kind;if("declarative"===d.kind||"html"===d.kind||y||l("kind must be declarative, html or composite"),y&&1===p&&l(`kind composite ${j}`),y)for(const e of["accepts","allow_no_source"])void 0!==d[e]&&l(`${e}: a composite is a container of Blocks, not a Cell showing data`);if(("string"!=typeof d.title||!d.title||d.title.length>256)&&l("title: 1…256 characters"),void 0!==d.config_schema){const e=[];W(d.config_schema,"config_schema",e),e.forEach(l)}if(void 0!==d.bindings)if(d.bindings&&"object"==typeof d.bindings)for(const[e,t]of Object.entries(d.bindings))if(w.test(e)&&"props"!==e||l(`binding name ${e}: [a-z][a-z0-9_]{0,31}, not props`),J(t)){for(const o of Object.keys(t))["accepts","required","many","schema_id","title","description"].includes(o)||l(`binding ${e}: unknown key ${o}`);void 0!==t.many&&"boolean"!=typeof t.many&&l(`binding ${e}.many: true or false`),void 0!==t.schema_id&&("string"!=typeof t.schema_id||!t.schema_id||t.schema_id.length>128)&&l(`binding ${e}.schema_id: a schema id such as buckyos.todo@1`)}else l(`binding ${e} must be an object`);else l("bindings must be an object");if(void 0!==d.on_bind||void 0!==d.on_init_control)if(p>0&&p<5)l(`on_bind / on_init_control ${O}`);else if("html"===d.kind){for(const[e,t]of[["on_bind","bind"],["on_init_control","init_control"]])void 0!==d[e]&&"script"!==d[e]&&l(`${e}: an HTML control writes "script" (its behavior.js handles aiws.on('${t}'))`);"number"==typeof d.host_api&&d.host_api>=5||l("on_bind / on_init_control \"script\": aiws.on('bind') / aiws.on('init_control') need host_api 5")}else if("composite"!==d.kind)l('on_bind / on_init_control: declared steps are for a composite, "script" for an HTML control');else{const t=Array.isArray(d.actions)?d.actions.filter(J).map((e=>String(e.id))):[];e.checkBindSteps(d.on_bind,d.on_init_control,J(d.bindings)?d.bindings:{},t).forEach(l)}if(void 0!==d.deps)if(!Array.isArray(d.deps)||d.deps.length>32)l("deps: at most 32 identities <author_did>#<name>");else if(d.deps.length>0&&1===p)l(`deps ${j}`);else{const e=new Set;for(const t of d.deps)"string"==typeof t&&k.test(t)?t===h?l("deps: a control cannot depend on itself"):e.has(t)&&l(`deps lists ${t} twice`):l(`deps: ${JSON.stringify(t)} is not an identity <author_did>#<name>`),e.add(String(t))}let g=[];if(void 0!==d.events){if(y)l("events: a composite declares its events in composition.json (events.<name>.from re-raises an event of a child)");else if(m)l(`events ${x}`);else{const e=[];!function(e,t){if(J(e)){Object.keys(e).length>16&&t.push("events: at most 16");for(const[o,s]of Object.entries(e)){const e=`events.${o}`;if(w.test(o)||t.push(`${e}: an event name is [a-z][a-z0-9_]{0,31}`),J(s)){for(const[o,i]of Object.entries(s))"title"===o?("string"!=typeof i||i.length>256)&&t.push(`${e}.title: at most 256 characters`):"description"===o?("string"!=typeof i||i.length>4e3)&&t.push(`${e}.description: at most 4000 characters`):"params"!==o&&t.push(`${e}: unknown key ${o} (title, description, params)`);if(void 0!==s.params)if(J(s.params)){Object.keys(s.params).length>16&&t.push(`${e}.params: at most 16`);for(const[o,i]of Object.entries(s.params)){const s=`${e}.params.${o}`;if(w.test(o)||t.push(`${s}: a param name is [a-z][a-z0-9_]{0,31}`),J(i)){for(const[e,o]of Object.entries(i))"type"===e?"string"==typeof o&&A.includes(o)||t.push(`${s}.type: ${A.join(", ")}`):"required"===e?"boolean"!=typeof o&&t.push(`${s}.required must be a boolean`):"description"===e?("string"!=typeof o||o.length>1e3)&&t.push(`${s}.description: at most 1000 characters`):t.push(`${s}: unknown key ${e} (type, required, description)`);void 0===i.type&&t.push(`${s}.type required`)}else t.push(`${s} must be an object { type, required?, description? }`)}}else t.push(`${e}.params must be an object { <param>: { type, required?, description? } }`)}else t.push(`${e} must be an object { title?, description?, params? }`)}}else t.push("events must be an object { <name>: { title?, description?, params? } }")}(d.events,e),e.forEach(l)}!y&&J(d.events)&&(g=Object.keys(d.events))}const v=e=>"string"==typeof e&&s.includes(e),N=new Set([c]);if("html"===d.kind){const e=d.entry;if(e&&"object"==typeof e&&"string"==typeof e.html)for(const[t,o]of Object.entries(e))v(o)?N.add(String(o)):l(`entry.${t} ${JSON.stringify(o)} is not in the directory`);else l("entry must be { html, css?, js? }");void 0===d.host_api||[2,3,4,5,6].includes(d.host_api)?(5===d.host_api||6===d.host_api)&&p<5?l(`host_api ${d.host_api} ${O}`):4===d.host_api&&p<4?l(`host_api 4 ${S}`):3===d.host_api&&m&&l(`host_api 3 ${x}`):l("host_api: the HTML Block host speaks API 2, 3, 4, 5 and 6"),g.length>0&&!("number"==typeof d.host_api&&d.host_api>=3)&&r.push({file:c,severity:"warning",message:"events: an HTML control raises them with aiws.emit, which is host API 3 (set host_api to 3 or later)"})}else if("declarative"===d.kind||y){if(v(d.entry)){N.add(String(d.entry));const e=null==i?void 0:i(String(d.entry)),t=p||void 0;void 0!==e&&y?r.push(...B(e,d.config_schema,String(d.entry),{manifestVersion:t,cellEvents:n})):void 0!==e&&r.push(...D(e,{bindings:d.bindings,events:g,configSchema:d.config_schema,manifestVersion:t},String(d.entry)))}else l(`entry ${JSON.stringify(d.entry)} is not in the directory`);y&&void 0!==d.host_api&&l("host_api: a composite runs no code of its own (its layout and chrome are the host's)"),y||void 0===d.host_api||1===d.host_api||l("host_api: the declarative interpreter is version 1")}for(const e of Array.isArray(d.assets)?d.assets:[])v(e)?N.add(String(e)):l(`asset ${JSON.stringify(e)} is not in the directory`);void 0!==d.agent&&(v(d.agent)?N.add(String(d.agent)):l(`agent ${JSON.stringify(d.agent)} is not in the directory`));for(const e of s)q(e)?N.has(e)||r.push({file:e,severity:"warning",message:"not named by component.json: kept in the source snapshot only"}):r.push({file:e,severity:"error",message:"a file of a source directory: a relative path whose parts do not start with '.'"});return r}function M(e){if(!e||"object"!=typeof e)throw new r([{file:s,severity:"error",message:"must be a JSON object"}]);const t=e,o=t.manifest_version;if("number"!=typeof o||o<1)throw new r([{file:s,severity:"error",message:"manifest_version required"}]);if(o>5)throw new r([{file:s,severity:"error",message:`manifest_version ${o} needs a newer client (this one reads 5)`}]);if("aiws"!==t.purpose)throw new r([{file:s,severity:"error",message:"purpose must be aiws"}]);if(!Array.isArray(t.controls))throw new r([{file:s,severity:"error",message:"controls must be an array"}]);return{manifest_version:o,purpose:"aiws",host_api:t.host_api??{},controls:t.controls,workspace_templates:Array.isArray(t.workspace_templates)?t.workspace_templates:[]}}const F=/^[a-z0-9][a-z0-9-]{0,63}$/;function V(e){return`templates/${e}/`}async function R(e,t){const o=V(t),s=[];for(const[i,n]of e)i.startsWith(o)&&s.push([i.slice(o.length),n]);return p(s)}function P(e,t){if(!J(e))return["a template is an object { id, title, snapshot, digest, requires, description?, params?, reset? }"];const o=[];for(const i of Object.keys(e))["id","title","description","snapshot","digest","requires","params","reset"].includes(i)||o.push(`unknown key ${i}`);"string"==typeof e.id&&F.test(e.id)?e.snapshot!==`${V(e.id)}snapshot.json`&&o.push(`snapshot must be ${V(e.id)}snapshot.json`):o.push("id: [a-z0-9][a-z0-9-]{0,63}"),("string"!=typeof e.title||!e.title||e.title.length>256)&&o.push("title: 1…256 characters"),void 0!==e.description&&("string"!=typeof e.description||e.description.length>4e3)&&o.push("description: at most 4000 characters"),"string"==typeof e.digest&&/^sha256:[0-9a-f]{64}$/.test(e.digest)||o.push("digest: sha256:<64 hex digits>");const s=e.requires;if(J(s)){for(const e of Object.keys(s))"host_api"!==e&&"controls"!==e&&o.push(`requires: unknown key ${e}`);if(void 0!==s.host_api)if(J(s.host_api))for(const[e,t]of Object.entries(s.host_api))("html"!==e&&"declarative"!==e||!Number.isInteger(t)||t<1)&&o.push(`requires.host_api.${e}: html or declarative, a positive integer`);else o.push("requires.host_api must be an object { html?, declarative? }");if(!Array.isArray(s.controls)||s.controls.length>256)o.push("requires.controls: at most 256 identities");else{const e=new Set;for(const i of s.controls)"string"==typeof i&&t.has(i)?e.has(i)&&o.push(`requires.controls lists ${i} twice`):o.push(`requires.controls: ${JSON.stringify(i)} is not a control of this manifest`),e.add(i)}}else o.push("requires { host_api?, controls } required");if(void 0!==e.params)if(!J(e.params)||Object.keys(e.params).length>32)o.push("params: an object of at most 32 { type, title?, default? }");else for(const[i,n]of Object.entries(e.params)){const e=`params.${i}`;if(w.test(i)||o.push(`${e}: a param name is [a-z][a-z0-9_]{0,31}`),J(n)){for(const[t,s]of Object.entries(n))"type"===t?"string"!==s&&"number"!==s&&"boolean"!==s&&o.push(`${e}.type: string, number or boolean`):"title"===t?("string"!=typeof s||s.length>256)&&o.push(`${e}.title: at most 256 characters`):"default"===t?["string","number","boolean"].includes(typeof s)||o.push(`${e}.default: a string, number or boolean`):o.push(`${e}: unknown key ${t} (type, title, default)`);void 0===n.type&&o.push(`${e}.type required`)}else o.push(`${e} must be an object { type, title?, default? }`)}if(void 0!==e.reset){const t=J(e.reset)?e.reset.tables:void 0;!J(e.reset)||Object.keys(e.reset).some((e=>"tables"!==e))?o.push("reset: { tables }"):void 0!==t&&(!Array.isArray(t)||t.length>64||new Set(t).size!==t.length||t.some((e=>"string"!=typeof e||!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(e))))&&o.push("reset.tables: at most 64 distinct table ids")}return o}async function U(e,t,o){const s=/[*?[\]\\]/.test(o)?void 0:o;return(await e.list("string"==typeof t?t:{ref:t},{limit:s?10:1e3,...s?{filter:{name_glob:s}}:{}},["base","ident"])).entries.find((e=>e.name===o))}async function G(e,t){const o=t.split("/").filter(Boolean);if(0===o.length)throw new Error(`not a folder path: ${t}`);let s=(await e.stat(`/${o[0]}`)).ref;for(const i of o.slice(1)){const o=await U(e,s,i);if(o&&"dir"!==o.target.kind)throw new r([{file:i,severity:"error",message:`${i} in ${t} is not a folder`}]);s=o?o.target.ref:(await e.mkdir({ref:s},i)).ref}return s}async function H(e,t){const o=t.split("/").filter(Boolean);if(0===o.length)return null;let s=(await e.stat(`/${o[0]}`)).ref;for(const i of o.slice(1)){const t=await U(e,s,i);if(!t||"dir"!==t.target.kind)return null;s=t.target.ref}return s}async function K(e,o){const s=await H(e,o);return null!==s&&void 0!==await U(e,s,t)}async function X(e,t,o,s){const i="string"==typeof t?await G(e,t):t;await e.uploadFile(i,o,s,{overwrite:!0})}const Y=e=>new Promise((t=>setTimeout(t,e)));async function Q(e,t){const o=[],s=[],i=async(t,n,r)=>{var a,c,l;let d;do{const f=await e.list("string"==typeof t?t:{ref:t},{limit:500,...d?{cursor:d}:{}},["base","ident"]);for(const e of f.entries){if(e.name.startsWith("."))continue;const t=`${n}${e.name}`;if("dir"===e.target.kind){r>=8?s.push({file:t,severity:"error",message:"sub-folders nest at most 8 levels"}):await i(e.target.ref,`${t}/`,r+1);continue}if("file"!==e.target.kind){s.push({file:t,severity:"error",message:"only files and folders belong to a control source"});continue}const d=e.target.ref,f="object"===d.type?d.obj_id:"string"==typeof(null==(a=e.target.attrs)?void 0:a.obj_id)?e.target.attrs.obj_id:void 0;o.push({name:t,...f?{obj_id:f}:{},..."live"===d.type?{node_id:d.node_id}:{},..."string"==typeof(null==(c=e.target.attrs)?void 0:c.etag)?{etag:e.target.attrs.etag}:{},..."number"==typeof(null==(l=e.target.attrs)?void 0:l.size)?{size:e.target.attrs.size}:{}})}d=f.truncated?f.next_cursor:void 0}while(d)};if(await i(t,"",0),0===o.length&&s.push({file:"",severity:"error",message:`${t} holds no files`}),o.length>64&&s.push({file:"",severity:"error",message:"a control holds at most 64 files"}),s.some((e=>"error"===e.severity)))throw new r(s);return o.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function Z(e,t,o,s){const i=o.lastIndexOf("/");await X(e,i<0?t:l(t,o.slice(0,i)),i<0?o:o.slice(i+1),s)}async function ee(e,t){const o=[];for(const s of t){if(!s.node_id)throw new r([{file:s.name,severity:"error",message:"the file service did not name this file"}]);o.push([s.name,new Uint8Array(await(await e.readFile(s.node_id)).arrayBuffer())])}return p(o)}async function te(e,t){try{const o=await U(e,t,i),s="live"===(null==o?void 0:o.target.ref.type)?o.target.ref.node_id:void 0;if(!s)return null;const n=await e.readFile(s);return await n.json()}catch{return null}}async function oe(e,t,o){await X(e,t,i,a.encode(`${JSON.stringify(o,null,2)}\n`))}exports.AIWS_BUILD_STATE_FILE=i,exports.AIWS_COMPONENT_FILE=t,exports.AIWS_COMPOSITION_FILE=o,exports.AIWS_DECLARATIVE_API_VERSION=1,exports.AIWS_HTML_API_VERSION=6,exports.AIWS_MANIFEST_FILE=s,exports.AIWS_MANIFEST_VERSION=5,exports.AIWS_MAX_INLINE_BYTES=u,exports.AIWS_MAX_SOURCE_FILES=64,exports.AIWS_TEMPLATE_FORMAT=n,exports.AiwsSourceError=r,exports.aiwsContentDigest=p,exports.aiwsTemplateDigest=R,exports.buildControl=async function(e,t,o,s,i={}){const n=await Q(t,s),r=await te(t,s),a=r&&r.workspace_id===o?{def_rev:r.def_rev,dir_rev:r.dir_rev}:void 0,c=await e.extBuild(o,{files:await g(t,n,i.upload),...i.folderId?{folder_id:i.folderId}:{},...a?{expect:a}:{},...i.force?{force:!0}:{},...i.dryRun?{dry_run:!0}:{},...i.migration?{migration:i.migration}:{}});return i.dryRun||"string"!=typeof c.def_entity_id||"number"!=typeof c.def_rev||await oe(t,s,{workspace_id:o,def_entity_id:c.def_entity_id,def_rev:c.def_rev,dir_rev:Number(c.dir_rev??0),ident:String(c.ident??""),at:(new Date).toISOString()}),{...c,files:n}},exports.buildFiles=g,exports.checkComponent=L,exports.checkComposition=B,exports.checkDeclarative=D,exports.collectSources=Q,exports.compatManifest=M,exports.controlSkeleton=function(e){const s=e.title??e.name;if("composite"===e.kind){const i="fixed"===e.algorithm,n=e.slots??{items:{placement:i?"free":"stack",title:"Items"}},r={layout:i?{algorithm:"fixed",padding:12}:{algorithm:"stack",direction:"column",spacing:"{{config.gap}}",padding:12},slots:n,chrome:{background:"{{config.background}}",radius:12,title:{text:"{{config.title}}"},empty:"Drop Blocks here"}},a={manifest_version:5,ident:{author_did:e.authorDid,name:e.name},kind:"composite",title:s,description:`${s}: a panel of Blocks`,default_size:{w:320,h:360},config_schema:{type:"object",properties:{title:{type:"string",title:"Title",default:s},background:{type:"string",title:"Background",default:"#f6f7fb"},gap:{type:"integer",title:"Gap (px)",default:8,minimum:0,maximum:64}}},entry:o,deps:e.deps??[],catalog:{group:"custom",description:`${s}`},agent:"AGENT.md"},c=Object.keys(n).map((e=>`\`${e}\``)).join(", ");return{[t]:`${JSON.stringify(a,null,2)}\n`,[o]:`${JSON.stringify(r,null,2)}\n`,"AGENT.md":`# ${s}\n\nA composite: an instance is a \`buckyos.container { kind: "composite", def_ref }\`; put Blocks under it with \`slot\` set to one of ${c}. Config: \`title\`, \`background\`, \`gap\`.\n`}}const i={manifest_version:5,ident:{author_did:e.authorDid,name:e.name},kind:e.kind??"declarative",title:s,description:`${s}: a control of this Workspace`,accepts:["buckyos.table-source","buckyos.record"],allow_no_source:!0,default_size:{w:260,h:140},config_schema:{type:"object",properties:{label:{type:"string",title:"Label",default:s}}},bindings:{data:{accepts:["buckyos.table-source"],title:"Data",description:"The table this control summarizes"}},catalog:{group:"custom",description:`${s}`},agent:"AGENT.md"},n=`# ${s}\n\nBind \`data\` to a table. Config: \`label\` (text).\n`;if("html"===e.kind){const e={clicked:{title:"Clicked",description:"Raised when someone clicks the button (in run mode)",params:{count:{type:"number",description:"Rows of the bound table"}}}};return{[t]:`${JSON.stringify({...i,host_api:6,events:e,entry:{html:"view.html",css:"style.css",js:"behavior.js"}},null,2)}\n`,"view.html":'<div class="card"><div class="label" id="label"></div><div class="value" id="value">—</div><button id="go" type="button">Go</button></div>\n',"style.css":".card{font:14px system-ui;padding:12px}.label{opacity:.7}.value{font-size:28px;font-weight:600}\n","behavior.js":["document.getElementById('label').textContent = (aiws.context.config || {}).label || ''","var count = 0","if (aiws.bindings.data) aiws.input('data').rows().then(function (rows) { count = rows.length; document.getElementById('value').textContent = String(count) })","// the public event of component.json: an instance binds handlers to it in its `on` (host API 3)","document.getElementById('go').addEventListener('click', function () { aiws.emit('clicked', { count: count }) })",""].join("\n"),"AGENT.md":`${n}Event: \`clicked\` (\`count\`), raised by its button; bind handlers to it in the instance's \`on\`.\n`}}return{[t]:`${JSON.stringify({...i,entry:"declarative.json"},null,2)}\n`,"declarative.json":`${JSON.stringify({layout:"stack",items:[{kind:"metric",label:s,bind:"data.count",format:"number"},{kind:"text",text:"Rows of the bound table"}]},null,2)}\n`,"AGENT.md":n}},exports.createControlSource=async function(e,o,s){const i=await G(e,o),n=await e.list({ref:i},{limit:500},["base"]).catch((()=>null));if(null==n?void 0:n.entries.some((e=>e.name===t)))throw new r([{file:t,severity:"error",message:`${o} already holds a control`}]);for(const[t,r]of Object.entries(s))await X(e,i,t,a.encode(r));return i},exports.ensureFolder=G,exports.exportBundle=async function(e,t,o,i){const n=await e.extExport(t,o,"package"),r=new Map;r.set(s,a.encode(`${JSON.stringify(n.manifest,null,2)}\n`));for(const s of n.files)r.set(s.path,void 0!==s.text?a.encode(s.text):await i(t,String(s.obj_id)));return{manifest:M(n.manifest),files:r,controls:n.controls}},exports.findFolder=H,exports.folderName=d,exports.hasControlSource=K,exports.homeControlDir=function(e,t,o){return`/home/${e}/AI Workspace/${d(t)}/controls/${o}`},exports.homeExportDir=function(e,t){return`/home/${e}/AI Workspace/exports/${t}`},exports.isSourcePath=q,exports.joinPath=l,exports.packBuildFiles=y,exports.pullControl=async function(e,t,o,s,i,n){const r=(await e.extExport(o,[s],"pull")).controls[0];await G(t,i);for(const l of r.files)await Z(t,i,l.name,void 0!==l.text?a.encode(l.text):await n(o,String(l.obj_id)));const c={workspace_id:o,def_entity_id:r.entity_id,def_rev:r.def_rev,dir_rev:r.dir_rev,ident:r.ident,at:(new Date).toISOString()};return await oe(t,i,c),{files:r.files.map((e=>e.name)),state:c}},exports.readBuildState=te,exports.slotCells=function(e){const t=new Set;for(const o of Object.values(e.slots??{}))for(const e of o.accepts??[])e.startsWith("cell:")&&t.add(e.slice(5));return[...t].sort()},exports.sourceStateKey=function(e){return`aiws:src:${e}`},exports.sourcesDigest=ee,exports.sourcesKey=m,exports.templateDir=V,exports.unbuiltChanges=async function(e,t,o,s,i){var n;if(!(await K(t,i)))return null;const r=await ee(t,await Q(t,i)),a=await e.extExport(o,[s],"pull"),c=String((null==(n=a.controls[0])?void 0:n.digest)??"");return{changed:r!==c,home:r,built:c}},exports.verifyBundle=async function(e){var o,i;const a=e.get(s);if(!a)throw new r([{file:s,severity:"error",message:"missing"}]);let l;try{l=JSON.parse(c.decode(a))}catch(g){throw new r([{file:s,severity:"error",message:String(g)}])}const d=M(l),f=[],m=d.workspace_templates;m.length>0&&d.manifest_version<3&&f.push({file:s,severity:"error",message:`Workspace templates need manifest_version 3 (raise it in ${s})`}),m.length>32&&f.push({file:s,severity:"error",message:"at most 32 Workspace templates"}),0===d.controls.length&&0===m.length&&f.push({file:s,severity:"error",message:"lists no control"});const u=new Map;for(const s of d.controls){const o="string"==typeof s.dir?e.get(`${s.dir}${t}`):void 0;try{const e=o?JSON.parse(c.decode(o)):void 0;J(e)&&u.set(s.ident,J(e.events)?Object.keys(e.events):[])}catch{}}const h=new Set;for(const n of d.controls){if("string"!=typeof n.dir||!/^controls\/[a-z0-9][a-z0-9._-]{0,70}\/$/.test(n.dir)||h.has(n.dir)){f.push({file:s,severity:"error",message:`control ${n.ident}: bad or repeated dir`});continue}h.add(n.dir);const r=[...e].filter((([e])=>e.startsWith(n.dir))).map((([e,t])=>[e.slice(n.dir.length),t]));await p(r)!==n.digest&&f.push({file:n.dir,severity:"error",message:"the files do not match the manifest digest"});const a=r.find((([e])=>e===t));if(!a){f.push({file:`${n.dir}${t}`,severity:"error",message:"missing"});continue}const l=e=>{const t=r.find((([t])=>t===e));return t?c.decode(t[1]):void 0};for(const e of L(c.decode(a[1]),r.map((([e])=>e)),l,(e=>u.get(e))))f.push({...e,file:`${n.dir}${e.file}`});try{const e=JSON.parse(c.decode(a[1]));`${null==(o=e.ident)?void 0:o.author_did}#${null==(i=e.ident)?void 0:i.name}`===n.ident&&e.kind===n.kind||f.push({file:n.dir,severity:"error",message:"ident and kind must match its component.json"}),JSON.stringify([...e.deps??[]].sort())!==JSON.stringify([...n.deps??[]].sort())&&f.push({file:n.dir,severity:"error",message:"deps must match its component.json"})}catch{}}const y=new Set(d.controls.map((e=>e.ident)));for(const t of d.controls)for(const e of t.deps??[])y.has(e)||f.push({file:s,severity:"error",message:`${t.ident} depends on ${e}, which the bundle does not carry`});for(const[t,r]of m.entries()){const o=J(r)&&"string"==typeof r.id?`template ${r.id}`:`workspace_templates[${t}]`;for(const e of P(r,y))f.push({file:s,severity:"error",message:`${o}: ${e}`});if(!J(r)||"string"!=typeof r.id||!F.test(r.id))continue;const i=V(r.id);if(h.has(i)){f.push({file:s,severity:"error",message:`${o} is listed twice`});continue}h.add(i);const a=e.get(`${i}snapshot.json`);let l;try{l=a?JSON.parse(c.decode(a)).format:void 0}catch{l=void 0}a?l!==n&&f.push({file:`${i}snapshot.json`,severity:"error",message:`not a template snapshot (format ${n})`}):f.push({file:`${i}snapshot.json`,severity:"error",message:"missing"}),await R(e,r.id)!==r.digest&&f.push({file:i,severity:"error",message:"the files do not match the template digest"})}for(const t of e.keys())t===s||[...h].some((e=>t.startsWith(e)))||f.push({file:t,severity:"error",message:"belongs to no control or template of the manifest"});return{manifest:d,diagnostics:f}},exports.watchControl=async function(e,t,o,s={}){var i,n;let r,a="",c=Promise.resolve();const l=()=>{c=c.then((async()=>{let s;try{s=await Q(e,t)}catch{return}const i=m(s);i!==a&&(a=i,await o(s))})).catch((()=>{}))};for(l();!(null==(i=s.signal)?void 0:i.aborted);){const o=await e.list(t,{limit:1},["base"]),i=e.watch({tokens:o.watch_token?[o.watch_token]:[],signal:s.signal});try{for await(const e of i)r&&clearTimeout(r),r=setTimeout(l,s.debounceMs??500)}catch{if(null==(n=s.signal)?void 0:n.aborted)break;await Y(2e3)}finally{i.close()}}r&&clearTimeout(r),await c},exports.writeBuildState=oe,exports.writeHomeFile=X,exports.writeSourceFile=Z;
|
|
2
2
|
//# sourceMappingURL=aiws_ext.cjs.map
|
package/dist/aiws_ext.mjs
CHANGED
|
@@ -39,7 +39,7 @@ import { R as RPCError, k as kRPCClient } from "./krpc_client-673448e5.mjs";
|
|
|
39
39
|
import { s as DID, N as NODE_IDENTITY_SCHEMA_V2, e as isBuckyOSLocalNodeIdentityConfig, l as parseBuckyOSOwnerDocument, t as canonicalize, u as signJwtEdDSA, F as FileObject, A as ACTION_TYPE_DOWNLOAD, v as ACTION_TYPE_INSTALLED, w as ACTION_TYPE_LIKED, x as ACTION_TYPE_PURCHASED, y as ACTION_TYPE_SHARED, z as ACTION_TYPE_UNLIKED, B as ACTION_TYPE_VIEWED, C as BaseContentObject, E as CYFS_CONTENT_TYPE_NAMED_OBJECT_JSON, G as CYFS_CONTENT_TYPE_NAMED_OBJECT_JWT, H as ChunkId, I as ChunkType, J as DEFAULT_HASH_METHOD, K as DirObject, L as HashMethod, M as InclusionProof, O as KnownStandardObject, P as MSG_OBJECT_RESERVED_KEYS, Q as MSG_REACTION_KEY_MAX_BYTES, R as MSG_SESSION_ID_MAX_CHARS, S as NamedObjectBase, T as NdnError, U as OBJ_TYPE_ACTION, V as OBJ_TYPE_CHUNK_LIST, W as OBJ_TYPE_DIR, X as OBJ_TYPE_FILE, Y as OBJ_TYPE_INCLUSION_PROOF, Z as OBJ_TYPE_LIST, _ as OBJ_TYPE_MSG, $ as OBJ_TYPE_OBJMAP, a0 as OBJ_TYPE_PACK, a1 as OBJ_TYPE_PATH, a2 as OBJ_TYPE_PKG, a3 as OBJ_TYPE_RECEIPT, a4 as OBJ_TYPE_RELATION, a5 as ObjId, a6 as PathObject, a7 as RELATION_TYPE_PART_OF, a8 as RELATION_TYPE_SAME, a9 as RelationObject, aa as SimpleChunkList, ab as SimpleMapItem, ac as SimpleObjectMap, ad as actionObjectFromJson, ae as base32Decode, af as base32Encode, ag as buildNamedObjectByJson, ah as buildNamedObjectByJwt, ai as buildObjId, aj as bytesToHex$2, ak as calcPkgMetaObjId, al as canonicalizeJson, am as decodeMsgObjectJwt, an as extractObjIdByPath, ao as hexToBytes$1, ap as isCyfsNamedObjectContentType, aq as isValidMsgSessionId, ar as loadNamedObj, as as loadNamedObjAndVerify, at as loadNamedObjectFromObjStr, au as msgJwtKidDid, av as msgObjectFromJsonChecked, aw as namedObjectEncodingFromContentType, ax as normalizePackageMetaForObjId, ay as randomMsgNonce, az as receiptObjFromJson, aA as sha256Bytes, aB as sha256Utf8, aC as toCanonicalJsonString, aD as validateMsgObject, aE as varintDecode, aF as varintEncode, aG as verifyMsgObjectJwt, aH as verifyNamedObject, aI as verifyNamedObjectFromJwt, aJ as verifyNamedObjectFromStr } from "./ndn_types-0fac2499.mjs";
|
|
40
40
|
import { s as sniffMagic, m as mediaTypeFromExtension, e as extensionOf, a as stripMediaTypeParams, h as heifImageSize, i as isoBoxes } from "./content_mime-e42d5f8d.mjs";
|
|
41
41
|
import { g as getBrowserIdentityRaw, c as clearBrowserUserInfo, s as saveBrowserIdentity, a as saveBrowserUserInfo, b as getBrowserUserInfo, d as clearBrowserIdentity, h as hashPassword, e as saveLocalAccountInfo, f as cleanLocalAccountInfo } from "./account-7a7bde6f.mjs";
|
|
42
|
-
import { i as AiWorkspaceClient, A as AIWORKSPACE_SERVICE_NAME, Y as newRecordId, _ as insertRecordOp, Z as setValuesOps, $ as deleteRecordsOp, V as orderKeyBetween, g as commitOverLimit, M as AIWS_PROTOCOL_VERSION, a as AiwsFailure, h as commitWithParts } from "./aiws_bind-
|
|
42
|
+
import { i as AiWorkspaceClient, A as AIWORKSPACE_SERVICE_NAME, Y as newRecordId, _ as insertRecordOp, Z as setValuesOps, $ as deleteRecordsOp, V as orderKeyBetween, g as commitOverLimit, M as AIWS_PROTOCOL_VERSION, a as AiwsFailure, h as commitWithParts } from "./aiws_bind-0885ff99.mjs";
|
|
43
43
|
import { a as objEventKey } from "./object_url-376c5222.mjs";
|
|
44
44
|
function ensureSSOEnvironment() {
|
|
45
45
|
if (typeof window === "undefined" || typeof window.location === "undefined") {
|
|
@@ -31521,7 +31521,7 @@ function newId(label, prefix) {
|
|
|
31521
31521
|
}
|
|
31522
31522
|
function fieldAdd(table, def, opts = {}) {
|
|
31523
31523
|
const fields = fieldsOf(table);
|
|
31524
|
-
const { options, field_id, ...rest } = def;
|
|
31524
|
+
const { options, field_id, default: fallback, ...rest } = def;
|
|
31525
31525
|
const field = { field_id: field_id ?? newId(def.name, "f"), ...rest };
|
|
31526
31526
|
if (options) {
|
|
31527
31527
|
const used = /* @__PURE__ */ new Set();
|
|
@@ -31536,6 +31536,8 @@ function fieldAdd(table, def, opts = {}) {
|
|
|
31536
31536
|
}
|
|
31537
31537
|
const last = fields.map((f2) => f2.order_key).filter((k) => typeof k === "string" && k.length > 0).sort().pop();
|
|
31538
31538
|
const op = { op: "table.add_field", source_id: table.entity_id, field, ...last ? { order_key: orderKeyBetween(last, null) } : {} };
|
|
31539
|
+
if (fallback !== void 0 && fallback !== null)
|
|
31540
|
+
field.default = cellValue(field, fallback);
|
|
31539
31541
|
if (opts.backfill !== void 0)
|
|
31540
31542
|
op.backfill = cellValue(field, opts.backfill);
|
|
31541
31543
|
return op;
|
|
@@ -32266,4 +32268,4 @@ export {
|
|
|
32266
32268
|
NOTIFY_CHOICE_CONTROL_ID as y,
|
|
32267
32269
|
NOTIFY_TEXT_CONTROL_ID as z
|
|
32268
32270
|
};
|
|
32269
|
-
//# sourceMappingURL=aiws_write-
|
|
32271
|
+
//# sourceMappingURL=aiws_write-675664eb.mjs.map
|