Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-labs/breadboard

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-labs/breadboard - npm Package Compare versions

Comparing version 0.28.0 to 0.29.0

dist/src/inspector/module.d.ts

71

dist/kits.min.js

@@ -11,3 +11,3 @@ /**

* SPDX-License-Identifier: Apache-2.0
*/const a=async t=>{let e;try{e=await fetch(t)}catch(r){e=await fetch(t,{credentials:"include"})}return await(e?.json())};class u{name="DefaultGraphProvider";#n=Promise.resolve();ready(){return this.#n}isSupported(){return!0}extendedCapabilities(){return{modify:!1,connect:!1,disconnect:!1,refresh:!1,watch:!1,preview:!1}}canProvide(t){return("http:"===t.protocol||"https:"===t.protocol||"file:"===t.protocol&&""===t.hostname)&&{load:!0,save:!1,delete:!1}}async load(t){if("file:"===t.protocol){return(async t=>{if(void 0===globalThis.process)throw new Error("Unable to use `path` when not running in node");let e;if("function"==typeof require){const{readFile:t}=require("node:fs/promises");e=t}else{const{readFile:t}=await import("node:fs/promises");e=t}return JSON.parse(await e(t,"utf-8"))})(decodeURIComponent(t.pathname))}return"http:"===t.protocol||"https:"===t.protocol?a(t.href):null}async save(t,e){throw new Error("Save not implemented for DefaultGraphProvider")}async delete(t){throw new Error("Delete not implemented for DefaultGraphProvider")}async connect(t){throw new Error("Connect not implemented for DefaultGraphProvider")}async disconnect(t){throw new Error("Disconnect not implemented for DefaultGraphProvider")}async refresh(t){throw new Error("Refresh not implemented for DefaultGraphProvider")}async createBlank(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async preview(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async create(t,e){throw new Error("Create not implemented for DefaultGraphProvider")}async createURL(t,e){throw new Error("createURL not implemented for DefaultGraphProvider")}parseURL(t){throw new Error("parseURL not implemented for DefaultGraphProvider")}async restore(){throw new Error("restore is not implemented for DefaultGraphProvider")}items(){throw new Error("items is not implemented for DefaultGraphProvider")}startingURL(){return null}watch(){throw new Error("watch is not implemented for DefaultGraphProvider")}}
*/const a=async t=>{let e;try{e=await fetch(t)}catch(r){e=await fetch(t,{credentials:"include"})}return await(e?.json())};class u{url=new URL("undefined"!=typeof window?window.location.href:"https://breadboard-ai.github.io/");projects=Promise.resolve([]);kits=[];secrets=new Map;extensions=[];capabilities={connect:!1,disconnect:!1,preview:!1,watch:!1,refresh:!1};name="DefaultBoardServer";user={username:"board-builder",apiKey:"",secrets:new Map};users=[this.user];#n=Promise.resolve();ready(){return this.#n}isSupported(){return!0}extendedCapabilities(){return{modify:!1,...this.capabilities}}getAccess(t,e){throw new Error("Method not implemented.")}canProvide(t){return("http:"===t.protocol||"https:"===t.protocol||"file:"===t.protocol&&""===t.hostname)&&{load:!0,save:!1,delete:!1}}async load(t){if("file:"===t.protocol){return(async t=>{if(void 0===globalThis.process)throw new Error("Unable to use `path` when not running in node");let e;if("function"==typeof require){const{readFile:t}=require("node:fs/promises");e=t}else{const{readFile:t}=await import("node:fs/promises");e=t}return JSON.parse(await e(t,"utf-8"))})(decodeURIComponent(t.pathname))}return"http:"===t.protocol||"https:"===t.protocol?a(t.href):null}async save(t,e){throw new Error("Save not implemented for DefaultGraphProvider")}async delete(t){throw new Error("Delete not implemented for DefaultGraphProvider")}async connect(t){throw new Error("Connect not implemented for DefaultGraphProvider")}async disconnect(t){throw new Error("Disconnect not implemented for DefaultGraphProvider")}async refresh(t){throw new Error("Refresh not implemented for DefaultGraphProvider")}async createBlank(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async preview(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async create(t,e){throw new Error("Create not implemented for DefaultGraphProvider")}async createURL(t,e){throw new Error("createURL not implemented for DefaultGraphProvider")}parseURL(t){throw new Error("parseURL not implemented for DefaultGraphProvider")}async restore(){throw new Error("restore is not implemented for DefaultGraphProvider")}items(){throw new Error("items is not implemented for DefaultGraphProvider")}startingURL(){return null}watch(){throw new Error("watch is not implemented for DefaultGraphProvider")}}
/**

@@ -32,3 +32,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const m=Symbol(),g=Symbol(),y=[function(t,e,r){if(void 0!==t.anyOf){for(let s=0;s<t.anyOf.length;s++){const n=t.anyOf[s],i=P(t,n);if(void 0===e.anyOf){const t=[],o={...r,details:t};r.pathA.push("anyOf",s);const a=v(i,e,o).isSubSchema;if(r.pathA.pop(),r.pathA.pop(),!a)return r.details.push(...k(t,s,n)),g}else{let t=!1;for(const r of e.anyOf)if(v(i,P(e,r)).isSubSchema){t=!0;break}if(!t)return r.details.push({pathA:[...r.pathA,"anyOf",s],pathB:[...r.pathB,"anyOf"]}),g}}return m}if(void 0!==e.anyOf){for(const r of e.anyOf)if(v(t,P(e,r)).isSubSchema)return m;return r.details.push({pathA:[...r.pathA],pathB:[...r.pathB,"anyOf"]}),g}return!0},function(t,e,r){if(t.type===e.type)return!0;const s=S(t),n=S(e);s.has("integer")&&n.has("number")&&(s.delete("integer"),s.add("number"));if(!O(s,n))return r.details.push({pathA:[...r.pathA,"type"],pathB:[...r.pathB,"type"]}),!1;return!0},function(t,e,r){if(void 0===e.enum)return!0;if(void 0===t.enum||0===t.enum.length&&e.enum.length>0||!O(E(t.enum),E(e.enum)))return r.details.push({pathA:[...r.pathA,"enum"],pathB:[...r.pathB,"enum"]}),!1;return!0},function(t,e,r){if(void 0===e.minLength&&void 0===e.maxLength)return!0;let s=!0;const n=t.minLength??0,i=e.minLength??0;n<i&&(s=!1,r.details.push({pathA:[...r.pathA,"minLength"],pathB:[...r.pathB,"minLength"]}));const o=t.maxLength??Number.MAX_VALUE,a=e.maxLength??Number.MAX_VALUE;o>a&&(s=!1,r.details.push({pathA:[...r.pathA,"maxLength"],pathB:[...r.pathB,"maxLength"]}));return s},function(t,e,r){if(void 0===e.pattern)return!0;if(t.pattern!==e.pattern)return r.details.push({pathA:[...r.pathA,"pattern"],pathB:[...r.pathB,"pattern"]}),!1;return!0},function(t,e,r){if(void 0===e.format)return!0;if(t.format!==e.format)return r.details.push({pathA:[...r.pathA,"format"],pathB:[...r.pathB,"format"]}),!1;return!0},function(t,e,r){if(void 0===e.minimum&&void 0===e.maximum)return!0;const s=t.minimum??0,n=e.minimum??0;if(s<n)return r.details.push({pathA:[...r.pathA,"minimum"],pathB:[...r.pathB,"minimum"]}),!1;const i=t.maximum??Number.MAX_VALUE,o=e.maximum??Number.MAX_VALUE;if(i>o)return r.details.push({pathA:[...r.pathA,"maximum"],pathB:[...r.pathB,"maximum"]}),!1;return!0},function(t,e,r){if(void 0===e.items)return!0;if(Array.isArray(t.items)||Array.isArray(e.items))return!0;r.pathA.push("items"),r.pathB.push("items");const s=v(t.items??b,e.items,r).isSubSchema;return r.pathA.pop(),r.pathB.pop(),s},function(t,e,r){if(void 0===t.properties)return!0;for(const[s,n]of Object.entries(t.properties)){const t=e.properties?.[s];if(void 0!==t){r.pathA.push("properties",s),r.pathB.push("properties",s);const{isSubSchema:e}=v(n,t,r);if(r.pathA.pop(),r.pathB.pop(),!e)return!1}else{if(!0===e.additionalProperties||void 0===e.additionalProperties)continue;if(!1===e.additionalProperties)return r.details.push({pathA:[...r.pathA,"properties",s],pathB:[...r.pathB,"additionalProperties"]}),!1;{r.pathA.push("properties",s),r.pathB.push("additionalProperties");const{isSubSchema:t}=v(n,e.additionalProperties,r);if(r.pathA.pop(),r.pathB.pop(),!t)return!1}}}return!0},function(t,e,r){const s=e.additionalProperties??!0;if(!0===s)return!0;const n=t.additionalProperties??!0;if(!1===n)return!0;if(!1===s)return r.details.push({pathA:[...r.pathA,"additionalProperties"],pathB:[...r.pathB,"additionalProperties"]}),!1;r.pathA.push("additionalProperties"),r.pathB.push("additionalProperties");const i=v(!0===n?{}:n,s,r).isSubSchema;return r.pathA.pop(),r.pathB.pop(),i},function(t,e,r){if("boolean"==typeof t.required||"boolean"==typeof e.required)return!0;if(void 0===e.required||0===e.required.length)return!0;const s=new Set(t.required??[]);let n=!0;for(let t=0;t<e.required.length;t++){const i=e.required[t];s.has(i)||(n=!1,r.details.push({pathA:[...r.pathA,"required"],pathB:[...r.pathB,"required",t]}))}return n}],w=new Set(["string","number","integer","object","array","boolean","null"]),b={type:[...w]};function v(t,e,r={pathA:[],pathB:[],details:[]}){let s=!1;for(const n of y){const i=n(t,e,r);if(!0===i);else if(!1===i)s=!0;else{if(i===m)break;if(i===g){s=!0;break}}}return s?{isSubSchema:!1,details:r.details}:{isSubSchema:!0}}function S(t){return void 0===t.type?w:E(t.type)}function P(t,e){return 1===Object.keys(t).length?e:{...t,anyOf:void 0,...e}}function k(t,e,r){return t.map((t=>{const{pathA:s,pathB:n}=t;return"anyOf"===s[0]&&s[1]===e&&void 0===r[s[2]]?{pathA:s.slice(2),pathB:n}:t}))}function E(t){return new Set(void 0===t?[]:Array.isArray(t)?t:[t])}function O(t,e){if(t.size>e.size)return!1;for(const r of t)if(!e.has(r))return!1;return!0}
*/const m=Symbol(),g=Symbol(),y=[function(t,e,r){if(void 0!==t.anyOf){for(let s=0;s<t.anyOf.length;s++){const n=t.anyOf[s],i=P(t,n);if(void 0===e.anyOf){const t=[],o={...r,details:t};r.pathA.push("anyOf",s);const a=v(i,e,o).isSubSchema;if(r.pathA.pop(),r.pathA.pop(),!a)return r.details.push(...k(t,s,n)),g}else{let t=!1;for(const r of e.anyOf)if(v(i,P(e,r)).isSubSchema){t=!0;break}if(!t)return r.details.push({pathA:[...r.pathA,"anyOf",s],pathB:[...r.pathB,"anyOf"]}),g}}return m}if(void 0!==e.anyOf){for(const r of e.anyOf)if(v(t,P(e,r)).isSubSchema)return m;return r.details.push({pathA:[...r.pathA],pathB:[...r.pathB,"anyOf"]}),g}return!0},function(t,e,r){if(t.type===e.type)return!0;const s=S(t),n=S(e);s.has("integer")&&n.has("number")&&(s.delete("integer"),s.add("number"));if(!E(s,n))return r.details.push({pathA:[...r.pathA,"type"],pathB:[...r.pathB,"type"]}),!1;return!0},function(t,e,r){if(void 0===e.enum)return!0;if(void 0===t.enum||0===t.enum.length&&e.enum.length>0||!E(O(t.enum),O(e.enum)))return r.details.push({pathA:[...r.pathA,"enum"],pathB:[...r.pathB,"enum"]}),!1;return!0},function(t,e,r){if(void 0===e.minLength&&void 0===e.maxLength)return!0;let s=!0;const n=t.minLength??0,i=e.minLength??0;n<i&&(s=!1,r.details.push({pathA:[...r.pathA,"minLength"],pathB:[...r.pathB,"minLength"]}));const o=t.maxLength??Number.MAX_VALUE,a=e.maxLength??Number.MAX_VALUE;o>a&&(s=!1,r.details.push({pathA:[...r.pathA,"maxLength"],pathB:[...r.pathB,"maxLength"]}));return s},function(t,e,r){if(void 0===e.pattern)return!0;if(t.pattern!==e.pattern)return r.details.push({pathA:[...r.pathA,"pattern"],pathB:[...r.pathB,"pattern"]}),!1;return!0},function(t,e,r){if(void 0===e.format)return!0;if(t.format!==e.format)return r.details.push({pathA:[...r.pathA,"format"],pathB:[...r.pathB,"format"]}),!1;return!0},function(t,e,r){if(void 0===e.minimum&&void 0===e.maximum)return!0;const s=t.minimum??0,n=e.minimum??0;if(s<n)return r.details.push({pathA:[...r.pathA,"minimum"],pathB:[...r.pathB,"minimum"]}),!1;const i=t.maximum??Number.MAX_VALUE,o=e.maximum??Number.MAX_VALUE;if(i>o)return r.details.push({pathA:[...r.pathA,"maximum"],pathB:[...r.pathB,"maximum"]}),!1;return!0},function(t,e,r){if(void 0===e.items)return!0;if(Array.isArray(t.items)||Array.isArray(e.items))return!0;r.pathA.push("items"),r.pathB.push("items");const s=v(t.items??b,e.items,r).isSubSchema;return r.pathA.pop(),r.pathB.pop(),s},function(t,e,r){if(void 0===t.properties)return!0;for(const[s,n]of Object.entries(t.properties)){const t=e.properties?.[s];if(void 0!==t){r.pathA.push("properties",s),r.pathB.push("properties",s);const{isSubSchema:e}=v(n,t,r);if(r.pathA.pop(),r.pathB.pop(),!e)return!1}else{if(!0===e.additionalProperties||void 0===e.additionalProperties)continue;if(!1===e.additionalProperties)return r.details.push({pathA:[...r.pathA,"properties",s],pathB:[...r.pathB,"additionalProperties"]}),!1;{r.pathA.push("properties",s),r.pathB.push("additionalProperties");const{isSubSchema:t}=v(n,e.additionalProperties,r);if(r.pathA.pop(),r.pathB.pop(),!t)return!1}}}return!0},function(t,e,r){const s=e.additionalProperties??!0;if(!0===s)return!0;const n=t.additionalProperties??!0;if(!1===n)return!0;if(!1===s)return r.details.push({pathA:[...r.pathA,"additionalProperties"],pathB:[...r.pathB,"additionalProperties"]}),!1;r.pathA.push("additionalProperties"),r.pathB.push("additionalProperties");const i=v(!0===n?{}:n,s,r).isSubSchema;return r.pathA.pop(),r.pathB.pop(),i},function(t,e,r){if("boolean"==typeof t.required||"boolean"==typeof e.required)return!0;if(void 0===e.required||0===e.required.length)return!0;const s=new Set(t.required??[]);let n=!0;for(let t=0;t<e.required.length;t++){const i=e.required[t];s.has(i)||(n=!1,r.details.push({pathA:[...r.pathA,"required"],pathB:[...r.pathB,"required",t]}))}return n}],w=new Set(["string","number","integer","object","array","boolean","null"]),b={type:[...w]};function v(t,e,r={pathA:[],pathB:[],details:[]}){let s=!1;for(const n of y){const i=n(t,e,r);if(!0===i);else if(!1===i)s=!0;else{if(i===m)break;if(i===g){s=!0;break}}}return s?{isSubSchema:!1,details:r.details}:{isSubSchema:!0}}function S(t){return void 0===t.type?w:O(t.type)}function P(t,e){return 1===Object.keys(t).length?e:{...t,anyOf:void 0,...e}}function k(t,e,r){return t.map((t=>{const{pathA:s,pathB:n}=t;return"anyOf"===s[0]&&s[1]===e&&void 0===r[s[2]]?{pathA:s.slice(2),pathB:n}:t}))}function O(t){return new Set(void 0===t?[]:Array.isArray(t)?t:[t])}function E(t,e){if(t.size>e.size)return!1;for(const r of t)if(!e.has(r))return!1;return!0}
/**

@@ -38,3 +38,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/var A;!function(t){t[t.In=0]="In",t[t.Out=1]="Out"}(A||(A={}));const x={type:"object",title:"Schema",behavior:["json-schema","ports-spec","config"]},I={type:"string"},$=t=>{const e=t.type;return e===h.Star||e===h.Control},j=(t,e,r=!1)=>e?e.reduce(((e,s)=>{if(!r&&$(s))return e;const n=t===A.In?s.in:s.out;return e[n]||(e[n]=I),e}),{}):{},N=(t,r,s=!1)=>r?(new e).addProperties(j(t,r,s)).setAdditionalProperties(!0).build():{},C=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).addProperty("schema",x).build();let i=!1;const o=t.outgoing?.filter((t=>{const e=$(t);return e&&(i=!0),!e})),a=r([N(A.Out,o,!0),s]);return t.asType&&(i||(a.additionalProperties=!1)),{inputSchema:n,outputSchema:a}},q=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).setAdditionalProperties(!1).build(),i=(new e).addProperty("schema",x),o=r([i.addProperties(j(A.In,t.incoming,!0)).setAdditionalProperties(!0).build(),s]);if(t.asType){!!t.incoming?.find((t=>"*"===t.out))||(o.additionalProperties=!1)}return{inputSchema:o,outputSchema:n}},B=(t,e)=>t.properties?.[e]?.title||e,M=(t,e,r,s)=>t?e?p.Connected:s?p.Indeterminate:p.Dangling:r?s?p.Indeterminate:p.Missing:p.Ready,R={deprecated:!1,transient:!1,config:!1,"google-drive-query":!1,"google-drive-file-id":!1,bubble:!0,board:!0,stream:!0,error:!0,"llm-content":!0,"json-schema":!0,"ports-spec":!0,image:!0,code:!0},L=(t,e,r,s,n,i)=>{let o=!1;const a=e.map((e=>"*"===e.out?(o=!0,"*"):t===A.In?e.in:e.out)),u=!1===r.additionalProperties,c=Object.keys(r.properties||{});s&&c.push("$error");const h=c.includes("*"),p=r.required||[],d=Object.keys(i||{}),l=[...new Set([...a,...c,...d,"*",""])];return l.sort(),l.map((s=>{const l="*"===s||""===s,f=d.includes(s),m=a.includes(s),g=c.includes(s)||l,y=p.includes(s),w=r.properties?.[s]||I;return w.behavior?.includes("deprecated")&&!m?null:{name:s,title:B(r,s),configured:f,value:i?.[s],star:l,get edges(){return m?e.filter((e=>!("*"!==e.out||!l)||(t===A.In?e.in===s:e.out===s))):[]},status:M(m||f,!u||g||h,n&&y,o),schema:w,type:new F(w),kind:t===A.In?"input":"output"}})).filter(Boolean)};class F{schema;constructor(t){this.schema=t}hasBehavior(t){return!!this.schema.behavior?.includes(t)}canConnect(t){return this.analyzeCanConnect(t).canConnect}analyzeCanConnect(t){const e=v(this.schema,t.schema);if(!e.isSubSchema)return{canConnect:!1,details:e.details.map((t=>({message:"Incompatible schema",detail:{outputPath:t.pathA,inputPath:t.pathB}})))};const r=new Set(this.schema.behavior);for(const e of t.schema.behavior??[])if(R[e]&&!r.has(e))return{canConnect:!1,details:[{message:"Incompatible behaviors",detail:{outputPath:["behavior"],inputPath:["behavior"]}}]};return{canConnect:!0}}}const U=(t,e)=>{const r=Object.keys(t.properties||{}),s=t.required||[];return r.sort(),r.map((r=>{const n=t.properties?.[r]||I;return{name:r,title:B(t,r),configured:!1,star:!1,edges:[],value:null,status:M(!1,!0,s.includes(r),!1),schema:n,type:new F(n),kind:e}}))},D=(t,e)=>{const r=t.filter((t=>f(t.type))),s=[...new Set(r.map((t=>t.type)))];return 0===s.length?[]:[{descriptor:{title:"Custom Types",description:"Custom nodes found in the graph",url:""},nodeTypes:s.map((t=>new V(t,e)))}]},T=t=>Object.entries(t).sort().map((([t,e])=>new G(t,e))),z=async(t,e)=>{if(!e||"function"==typeof e||!e.describe)return _();try{const t=await e.describe();return{inputs:{fixed:!1===t.inputSchema.additionalProperties,ports:U(t.inputSchema,"input")},outputs:{fixed:!1===t.outputSchema.additionalProperties,ports:U(t.outputSchema,"output")}}}catch(e){return console.warn(`Error describing node type ${t}:`,e),_()}};
*/var A;!function(t){t[t.In=0]="In",t[t.Out=1]="Out"}(A||(A={}));const I={type:"object",title:"Schema",behavior:["json-schema","ports-spec","config"]},x={type:"string"},j=t=>{const e=t.type;return e===h.Star||e===h.Control},$=(t,e,r=!1)=>e?e.reduce(((e,s)=>{if(!r&&j(s))return e;const n=t===A.In?s.in:s.out;return e[n]||(e[n]=x),e}),{}):{},N=(t,r,s=!1)=>r?(new e).addProperties($(t,r,s)).setAdditionalProperties(!0).build():{},C=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).addProperty("schema",I).build();let i=!1;const o=t.outgoing?.filter((t=>{const e=j(t);return e&&(i=!0),!e})),a=r([N(A.Out,o,!0),s]);return t.asType&&(i||(a.additionalProperties=!1)),{inputSchema:n,outputSchema:a}},q=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).setAdditionalProperties(!1).build(),i=(new e).addProperty("schema",I),o=r([i.addProperties($(A.In,t.incoming,!0)).setAdditionalProperties(!0).build(),s]);if(t.asType){!!t.incoming?.find((t=>"*"===t.out))||(o.additionalProperties=!1)}return{inputSchema:o,outputSchema:n}},B=(t,e)=>t.properties?.[e]?.title||e,M=(t,e,r,s)=>t?e?p.Connected:s?p.Indeterminate:p.Dangling:r?s?p.Indeterminate:p.Missing:p.Ready,R={deprecated:!1,transient:!1,config:!1,"google-drive-query":!1,"google-drive-file-id":!1,bubble:!0,board:!0,stream:!0,error:!0,"llm-content":!0,"json-schema":!0,"ports-spec":!0,image:!0,code:!0,module:!0},L=(t,e,r,s,n,i)=>{let o=!1;const a=e.map((e=>"*"===e.out?(o=!0,"*"):t===A.In?e.in:e.out)),u=!1===r.additionalProperties,c=Object.keys(r.properties||{});s&&c.push("$error");const h=c.includes("*"),p=r.required||[],d=Object.keys(i||{}),l=[...new Set([...a,...c,...d,"*",""])];return l.sort(),l.map((s=>{const l="*"===s||""===s,f=d.includes(s),m=a.includes(s),g=c.includes(s)||l,y=p.includes(s),w=r.properties?.[s]||x;return w.behavior?.includes("deprecated")&&!m?null:{name:s,title:B(r,s),configured:f,value:i?.[s],star:l,get edges(){return m?e.filter((e=>!("*"!==e.out||!l)||(t===A.In?e.in===s:e.out===s))):[]},status:M(m||f,!u||g||h,n&&y,o),schema:w,type:new U(w),kind:t===A.In?"input":"output"}})).filter(Boolean)};class U{schema;constructor(t){this.schema=t}hasBehavior(t){return!!this.schema.behavior?.includes(t)}canConnect(t){return this.analyzeCanConnect(t).canConnect}analyzeCanConnect(t){const e=v(this.schema,t.schema);if(!e.isSubSchema)return{canConnect:!1,details:e.details.map((t=>({message:"Incompatible schema",detail:{outputPath:t.pathA,inputPath:t.pathB}})))};const r=new Set(this.schema.behavior);for(const e of t.schema.behavior??[])if(R[e]&&!r.has(e))return{canConnect:!1,details:[{message:"Incompatible behaviors",detail:{outputPath:["behavior"],inputPath:["behavior"]}}]};return{canConnect:!0}}}const F=(t,e)=>{const r=Object.keys(t.properties||{}),s=t.required||[];return r.sort(),r.map((r=>{const n=t.properties?.[r]||x;return{name:r,title:B(t,r),configured:!1,star:!1,edges:[],value:null,status:M(!1,!0,s.includes(r),!1),schema:n,type:new U(n),kind:e}}))},D=(t,e)=>{const r=t.filter((t=>f(t.type))),s=[...new Set(r.map((t=>t.type)))];return 0===s.length?[]:[{descriptor:{title:"Custom Types",description:"Custom nodes found in the graph",url:""},nodeTypes:s.map((t=>new V(t,e)))}]},T=(t,e)=>Object.entries(t).sort().map((([t,r])=>f(t)?new V(t,e):new G(t,r))),z=async(t,e)=>{if(!e||"function"==typeof e||!e.describe)return _();try{const t=await e.describe();return{inputs:{fixed:!1===t.inputSchema.additionalProperties,ports:F(t.inputSchema,"input")},outputs:{fixed:!1===t.outputSchema.additionalProperties,ports:F(t.outputSchema,"output")}}}catch(e){return console.warn(`Error describing node type ${t}:`,e),_()}};
/**

@@ -44,3 +44,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class G{#u;#c;constructor(t,e){this.#u=t,this.#c=e}async metadata(){return"metadata"in this.#c&&this.#c.metadata||{}}type(){return this.#u}async ports(){return z(this.#u,this.#c)}}class W extends G{constructor(t,e,r){super(t,{invoke:async()=>{},describe:async()=>e({}),metadata:r})}}const _=()=>({inputs:{ports:[],fixed:!1},outputs:{ports:[],fixed:!1}});function H(t){const e=new URL(t);return e.pathname.split("/").pop()||e.host}class V{#u;#h=null;#p=null;constructor(t,e){this.#u=t,this.#p=Dt(t,e)}async#d(){const t=await this.#p;return t&&"metadata"in t&&t.metadata?t.metadata:{title:H(this.#u)}}async metadata(){return this.#h??=await this.#d(),this.#h}type(){return this.#u}async ports(){const t=await this.#p;return z(this.#u,t)}}
*/class G{#u;#c;constructor(t,e){this.#u=t,this.#c=e}async metadata(){return"metadata"in this.#c&&this.#c.metadata||{}}type(){return this.#u}async ports(){return z(this.#u,this.#c)}}class W extends G{constructor(t,e,r){super(t,{invoke:async()=>{},describe:async()=>e({}),metadata:r})}}const _=()=>({inputs:{ports:[],fixed:!1},outputs:{ports:[],fixed:!1}});function H(t){const e=new URL(t);return e.pathname.split("/").pop()||e.host}class V{#u;#h=null;#p=null;constructor(t,e){this.#u=t,this.#p=Gt(t,e)}async#d(){const t=await this.#p;return t&&"metadata"in t&&t.metadata?t.metadata:{title:H(this.#u)}}async metadata(){return this.#h??=await this.#d(),this.#h}type(){return this.#u}async ports(){const t=await this.#p;return z(this.#u,t)}}
/**

@@ -70,3 +70,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const Z=(t,e)=>e instanceof Map?{$type:"Map",value:Array.from(e.entries())}:e,tt=(t,e)=>{const{$type:r}=e||{};return"Map"==r&&e.value?new Map(e.value):e},et=(t,e)=>{const r=e;return JSON.stringify({state:r,type:t},Z)},rt=t=>{const{state:e,type:r}=JSON.parse(t,tt);return{state:Y.fromObject(e),type:r}};
*/const Z=(t,e)=>e instanceof Map?{$type:"Map",value:Array.from(e.entries())}:e,tt=(t,e)=>{const{$type:r}=e||{};return"Map"==r&&e.value?new Map(e.value):e},et=(t,e)=>{const r=e;return JSON.stringify({state:r,type:t},Z)},rt=t=>{const{state:e,type:r}=JSON.parse(t,tt);return{state:Y.fromObject(e),type:r}},st=t=>{const{descriptor:e,inputs:r,missingInputs:s,current:n,opportunities:i,newOpportunities:o,state:a,outputs:u,partialOutputs:c}=t,h=new X;h.constants=structuredClone(a.constants),h.state=structuredClone(a.state);const p=new Y(e,r,[...s],n,[...i],[...o],h,c);return p.outputs=u,p};
/**

@@ -77,3 +77,3 @@ * @license

*/
class st{#u;#v;#S;#P;#k;constructor(t,e,r,s,n){this.#v=t,this.#u=e,this.#S=r,this.#P=s,this.#k=n}get invocationId(){return this.#P}get path(){return this.#k}get type(){return this.#u}get node(){return this.#v.descriptor}get inputArguments(){return this.#v.inputs}set inputs(t){this.#v.outputs={...t,...this.#v.partialOutputs}}get outputs(){const{schema:t,...e}=this.#v.inputs;return e}get state(){return this.#v}save(){return et(this.#u,this.#v)}get runState(){return this.#S}get timestamp(){return J()}isAtExitNode(){return 0===this.#v.newOpportunities.length&&0===this.#v.opportunities.length}static load(t){const{state:e,type:r}=rt(t);return new st(e,r,void 0,0,[])}}class nt extends st{constructor(t,e,r,s){super(t,"input",e,r,s)}get outputs(){throw new Error('Outputs are not available in the "input" stage')}}class it extends st{constructor(t,e,r){super(t,"output",void 0,e,r)}get inputArguments(){throw new Error('Input arguments are not available in the "output" stage')}set inputs(t){throw new Error('Setting inputs is not available in the "output" stage')}}
class nt{#u;#v;#S;#P;#k;constructor(t,e,r,s,n){this.#v=t,this.#u=e,this.#S=r,this.#P=s,this.#k=n}get invocationId(){return this.#P}get path(){return this.#k}get type(){return this.#u}get node(){return this.#v.descriptor}get inputArguments(){return this.#v.inputs}set inputs(t){this.#v.outputs={...t,...this.#v.partialOutputs}}get outputs(){const{schema:t,...e}=this.#v.inputs;return e}get state(){return this.#v}save(){return et(this.#u,this.#v)}get runState(){return this.#S}get timestamp(){return J()}isAtExitNode(){return 0===this.#v.newOpportunities.length&&0===this.#v.opportunities.length}static load(t){const{state:e,type:r}=rt(t);return new nt(e,r,void 0,0,[])}}class it extends nt{constructor(t,e,r,s){super(t,"input",e,r,s)}get outputs(){throw new Error('Outputs are not available in the "input" stage')}}class ot extends nt{constructor(t,e,r){super(t,"output",void 0,e,r)}get inputArguments(){throw new Error('Input arguments are not available in the "output" stage')}set inputs(t){throw new Error('Setting inputs is not available in the "output" stage')}}
/**

@@ -83,3 +83,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const ot=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},at=async(t,e,r,s,n,i=[])=>{if(!e.requestInput)return;const o=s.outputs??{},a=new ct(o,s.inputs,n);if(await(e.state?.lifecycle().supplyPartialOutputs(o,n)),i.length>0){const t=i[i.length-1];if(t.state){const e=rt(t.state).state;e.partialOutputs=o,t.state=et("nodestart",e)}}s.outputs=await a.read(ut(t,e,r,i))},ut=(t,e,r,s)=>async(n,i,o,a)=>{if(o)throw new Error(ot(n,t,o));if(void 0!==i.default)return"type"in i&&"string"!==i.type?JSON.parse(i.default):i.default;const u=await(e.requestInput?.(n,i,r,a,s));if(e?.signal?.aborted)throw e.signal.throwIfAborted();if(void 0===u)throw new Error(ot(n,t,o));return u};class ct{#E;#O;#k;constructor(t,e,r){this.#E=t,this.#O=e,this.#k=r}async read(t){if(!("schema"in this.#O))return this.#E;const e=this.#O.schema;if(!e.properties)return this.#E;const r=Object.entries(e.properties),s={};for(const[n,i]of r){if(n in this.#E){s[n]=this.#E[n];continue}const r=e.required?.includes(n)??!1,o=await t(n,i,r,this.#k);s[n]=o}return{...this.#E,...s}}}class ht{#A;#x=new Map;constructor(t){const{inputs:e,...r}=t;this.#A=r,this.#x=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,i,o)=>{const a=this.#x.get(r);if(void 0!==a)return a;const u={id:n.id,type:n.type},c={...e,descriptor:u,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new nt(c,o,-1,i));const h=c.outputs;let p=h&&h[r];return void 0===p&&(p=await(this.#A.requestInput?.(r,s,u,i,o))),pt(s)||this.#x.set(r,p),p}}}const pt=t=>t.behavior?.includes("transient")??!1,dt=async(t,e,r,s)=>{if(!r.provideOutput)return!1;const n=e.configuration?.schema,i=n?.behavior?.includes("bubble");return!!i&&(await r.provideOutput(t,e,s),!0)},lt=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const i={...e,descriptor:s,inputs:r};await t(new it(i,-1,n))},ft=(t,e)=>{const r=t.path;return{kind:"board",url:new URL(r,e).href}},mt=async(t,e,r)=>(gt(t,e,r),Promise.resolve(t)),gt=(t,e,r)=>{for(const n in t){const o=t[n];if((s=o)&&"board"===s.kind&&o.path){const s=r?new URL(r):i(e);t[n]=ft(o,s)}}var s;return t};class yt{static computeMissingInputs(t,e,r,s){const n=((t,e="default")=>!!t.metadata?.tags&&t.metadata.tags.some((t=>{const r=t;if("string"==typeof r)return"start"===r;if("start"!==r.type)return!1;const s=r.label??"default";return e===s})))(r,s)?[]:[...new Set(t.filter((t=>!!t.in&&!t.optional)).map((t=>t.in||"")))];const i=new Set;return Object.keys(e).forEach((t=>i.add(t))),r.configuration&&Object.keys(r.configuration).forEach((t=>i.add(t))),n.filter((t=>!i.has(t)))}}
*/const at=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},ut=async(t,e,r,s,n,i=[])=>{if(!e.requestInput)return;const o=s.outputs??{},a=new ht(o,s.inputs,n);if(await(e.state?.lifecycle().supplyPartialOutputs(o,n)),i.length>0){const t=i[i.length-1];if(t.state){const e=rt(t.state).state;e.partialOutputs=o,t.state=et("nodestart",e)}}s.outputs=await a.read(ct(t,e,r,i))},ct=(t,e,r,s)=>async(n,i,o,a)=>{if(o)throw new Error(at(n,t,o));if(void 0!==i.default)return"type"in i&&"string"!==i.type?JSON.parse(i.default):i.default;const u=await(e.requestInput?.(n,i,r,a,s));if(e?.signal?.aborted)throw e.signal.throwIfAborted();if(void 0===u)throw new Error(at(n,t,o));return u};class ht{#O;#E;#k;constructor(t,e,r){this.#O=t,this.#E=e,this.#k=r}async read(t){if(!("schema"in this.#E))return this.#O;const e=this.#E.schema;if(!e.properties)return this.#O;const r=Object.entries(e.properties),s={};for(const[n,i]of r){if(n in this.#O){s[n]=this.#O[n];continue}const r=e.required?.includes(n)??!1,o=await t(n,i,r,this.#k);s[n]=o}return{...this.#O,...s}}}class pt{#A;#I=new Map;constructor(t){const{inputs:e,...r}=t;this.#A=r,this.#I=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,i,o)=>{const a=this.#I.get(r);if(void 0!==a)return a;const u={id:n.id,type:n.type},c={...e,descriptor:u,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new it(c,o,-1,i));const h=c.outputs;let p=h&&h[r];return void 0===p&&(p=await(this.#A.requestInput?.(r,s,u,i,o))),dt(s)||this.#I.set(r,p),p}}}const dt=t=>t.behavior?.includes("transient")??!1,lt=async(t,e,r,s)=>{if(!r.provideOutput)return!1;const n=e.configuration?.schema,i=n?.behavior?.includes("bubble");return!!i&&(await r.provideOutput(t,e,s),!0)},ft=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const i={...e,descriptor:s,inputs:r};await t(new ot(i,-1,n))},mt=(t,e)=>{const r=t.path;return{kind:"board",url:new URL(r,e).href}},gt=async(t,e,r)=>(yt(t,e,r),Promise.resolve(t)),yt=(t,e,r)=>{for(const n in t){const o=t[n];if((s=o)&&"board"===s.kind&&o.path){const s=r?new URL(r):i(e);t[n]=mt(o,s)}}var s;return t};class wt{static computeMissingInputs(t,e,r,s){const n=((t,e="default")=>!!t.metadata?.tags&&t.metadata.tags.some((t=>{const r=t;if("string"==typeof r)return"start"===r;if("start"!==r.type)return!1;const s=r.label??"default";return e===s})))(r,s)?[]:[...new Set(t.filter((t=>!!t.in&&!t.optional)).map((t=>t.in||"")))];const i=new Set;return Object.keys(e).forEach((t=>i.add(t))),r.configuration&&Object.keys(r.configuration).forEach((t=>i.add(t))),n.filter((t=>!i.has(t)))}}
/**

@@ -89,3 +89,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class wt{graph;#I;constructor(t,e){this.graph=t,this.#I=e}async next(){if(!this.#I.skip){const{inputs:t,descriptor:e}=this.#I;let{outputs:r,newOpportunities:s}=this.#I;if(this.#I.state.useInputs(e.id,this.#I.inputs),r&&r.$error){const n=r.$error;r.$error={descriptor:e,...n,inputs:{...t,...n.inputs}},s=s.filter((t=>"$error"===t.out))}if(r??={},this.#I.opportunities.push(...s),this.#I.state.wireOutputs(s,r),r.$error){if(0===s.length)throw new Error("Uncaught exception in node handler. Catch by wiring up the $error output.",{cause:r.$error});console.warn("Error in node handler, passing to the wired $error output.",r.$error,s)}}if(0===this.#I.opportunities.length)return{done:!0,value:null};const t=this.#I.opportunities.shift(),{heads:e,nodes:r,tails:s}=this.graph,n=t.to,i=r.get(n);if(!i)throw new Error(`No node found for id "${n}"`);const o=e.get(n)||[],a=this.#I.state.getAvailableInputs(n),u=yt.computeMissingInputs(o,a,i),c=s.get(n)||[],h={...i.configuration,...a};return this.#I=new Y(i,h,u,t,this.#I.opportunities,c,this.#I.state),{done:!1,value:this.#I}}}
*/class bt{graph;#x;constructor(t,e){this.graph=t,this.#x=e}async next(){if(!this.#x.skip){const{inputs:t,descriptor:e}=this.#x;let{outputs:r,newOpportunities:s}=this.#x;if(this.#x.state.useInputs(e.id,this.#x.inputs),r&&r.$error){const n=r.$error;r.$error={descriptor:e,...n,inputs:{...t,...n.inputs}},s=s.filter((t=>"$error"===t.out))}if(r??={},this.#x.opportunities.push(...s),this.#x.state.wireOutputs(s,r),r.$error){if(0===s.length)throw new Error("Uncaught exception in node handler. Catch by wiring up the $error output.",{cause:r.$error});console.warn("Error in node handler, passing to the wired $error output.",r.$error,s)}}if(0===this.#x.opportunities.length)return{done:!0,value:null};const t=this.#x.opportunities.shift(),{heads:e,nodes:r,tails:s}=this.graph,n=t.to,i=r.get(n);if(!i)throw new Error(`No node found for id "${n}"`);const o=e.get(n)||[],a=this.#x.state.getAvailableInputs(n),u=wt.computeMissingInputs(o,a,i),c=s.get(n)||[],h={...i.configuration,...a};return this.#x=new Y(i,h,u,t,this.#x.opportunities,c,this.#x.state),{done:!1,value:this.#x}}}
/**

@@ -95,3 +95,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class bt{start;tails=new Map;heads=new Map;nodes=new Map;entries=[];#$(t){return!this.heads.has(t)||0===this.heads.get(t)?.length}#j(){const t=new Set,e=this.start??"default";let r=!1;return this.nodes.forEach((s=>{s.metadata?.tags?.forEach((n=>{let i=n;if("string"==typeof i&&"start"===i&&(i={type:"start",label:"default"}),"start"===i.type){const n=i.label??"default";r=!0,n===e&&t.add(s.id)}}))})),t.size>0?Array.from(t):r?[]:Array.from(this.nodes.keys()).filter((t=>this.#$(t)))}constructor(t,e){e&&(this.start=e),this.tails=t.edges.reduce(((t,e)=>{const r=e.from;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.heads=t.edges.reduce(((t,e)=>{const r=e.to;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.nodes=t.nodes.reduce(((t,e)=>(t.set(e.id,e),t)),new Map),this.entries=this.#j()}}
*/class vt{start;tails=new Map;heads=new Map;nodes=new Map;entries=[];#j(t){return!this.heads.has(t)||0===this.heads.get(t)?.length}#$(){const t=new Set,e=this.start??"default";let r=!1;return this.nodes.forEach((s=>{s.metadata?.tags?.forEach((n=>{let i=n;if("string"==typeof i&&"start"===i&&(i={type:"start",label:"default"}),"start"===i.type){const n=i.label??"default";r=!0,n===e&&t.add(s.id)}}))})),t.size>0?Array.from(t):r?[]:Array.from(this.nodes.keys()).filter((t=>this.#j(t)))}constructor(t,e){e&&(this.start=e),this.tails=t.edges.reduce(((t,e)=>{const r=e.from;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.heads=t.edges.reduce(((t,e)=>{const r=e.to;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.nodes=t.nodes.reduce(((t,e)=>(t.set(e.id,e),t)),new Map),this.entries=this.#$()}}
/**

@@ -101,3 +101,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class vt{graph;previousResult;constructor(t,e,r){this.graph=new bt(t,r),this.previousResult=e}[Symbol.asyncIterator](){return this.start()}start(){if(this.previousResult)return new wt(this.graph,this.previousResult);const{entries:t}=this.graph;if(0===t.length)throw new Error("No entry node found in graph.");const e=t.map((t=>({from:"$entry",to:t}))),r=new Y({id:"$empty",type:"$empty"},{},[],{from:"$entry",to:t[0]},e,[],new X);return new wt(this.graph,r)}}
*/class St{graph;previousResult;constructor(t,e,r){this.graph=new vt(t,r),this.previousResult=e}[Symbol.asyncIterator](){return this.start()}start(){if(this.previousResult)return new bt(this.graph,this.previousResult);const{entries:t}=this.graph;if(0===t.length)throw new Error("No entry node found in graph.");const e=t.map((t=>({from:"$entry",to:t}))),r=new Y({id:"$empty",type:"$empty"},{},[],{from:"$entry",to:t[0]},e,[],new X);return new bt(this.graph,r)}}
/**

@@ -107,3 +107,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const St=()=>{};class Pt{#N=[];#C=St;#q;#B;abort=St;constructor(){this.#M()}#M(){this.#q=new Promise(((t,e)=>{this.#C=t,this.abort=e}))}#R(t){this.#N.push(t),1==this.#N.length&&(this.#C(),this.#M())}async write(t){return new Promise((e=>{this.#R({value:t,receipt:e})}))}async read(){this.#B&&this.#B(),0===this.#N.length&&await this.#q;const t=this.#N.shift();if(!t)throw new Error("asyncGen queue should never be empty.");return this.#B=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#R({value:void 0,receipt:St})}}class kt{#L;#F=!0;#N=new Pt;constructor(t){this.#L=t}async#U(t){return this.#N.write(t)}async next(){return this.#F&&(this.#F=!1,this.#L(this.#U.bind(this)).then((()=>{this.#N.close()})).catch((t=>{this.#N.abort(t)}))),this.#N.read()}}const Et=t=>({[Symbol.asyncIterator]:()=>new kt(t)});
*/const Pt=()=>{};class kt{#N=[];#C=Pt;#q;#B;abort=Pt;constructor(){this.#M()}#M(){this.#q=new Promise(((t,e)=>{this.#C=t,this.abort=e}))}#R(t){this.#N.push(t),1==this.#N.length&&(this.#C(),this.#M())}async write(t){return new Promise((e=>{this.#R({value:t,receipt:e})}))}async read(){this.#B&&this.#B(),0===this.#N.length&&await this.#q;const t=this.#N.shift();if(!t)throw new Error("asyncGen queue should never be empty.");return this.#B=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#R({value:void 0,receipt:Pt})}}class Ot{#L;#U=!0;#N=new kt;constructor(t){this.#L=t}async#F(t){return this.#N.write(t)}async next(){return this.#U&&(this.#U=!1,this.#L(this.#F.bind(this)).then((()=>{this.#N.close()})).catch((t=>{this.#N.abort(t)}))),this.#N.read()}}const Et=t=>({[Symbol.asyncIterator]:()=>new Ot(t)});
/**

@@ -113,3 +113,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class Ot{#D;#T;#l;#A;constructor(t,e,r){const{inputs:s,...n}=t;this.#D=new ht(t),this.#T=r,this.#l=e,this.#A=n}async invokeNode(t,e){const{inputs:r,descriptor:n}=t,{kits:i=[],base:o=s,state:a}=this.#A;let u;const c=await Mt(n.type,this.#A),h={...this.#A,descriptor:n,board:this.#l,outerGraph:this.#l,base:o,kits:i,requestInput:this.#D.createHandler(this.#T,t),provideOutput:lt(this.#T,t,this.#A),invocationPath:e,state:a};return u=await qt(c,gt(r,this.#A,this.#l.url),h),u}}
*/class At{#D;#T;#l;#A;constructor(t,e,r){const{inputs:s,...n}=t;this.#D=new pt(t),this.#T=r,this.#l=e,this.#A=n}async invokeNode(t,e){const{inputs:r,descriptor:n}=t,{kits:i=[],base:o=s,state:a}=this.#A;let u;const c=await Ut(n.type,this.#A),h={...this.#A,descriptor:n,board:this.#l,outerGraph:this.#l,base:o,kits:i,requestInput:this.#D.createHandler(this.#T,t),provideOutput:ft(this.#T,t,this.#A),invocationPath:e,state:a};return u=await Rt(c,yt(r,this.#A,this.#l.url),h),u}}
/**

@@ -125,3 +125,3 @@ * @license

*/
async function At(t,e,r={},s){const n={...e,...t.args},{probe:i}=r;try{let e={};const o=r.invocationPath||[],a=r.state?.lifecycle();for await(const u of async function*(t,e={},r){const{inputs:s,start:n,...i}=e,{probe:o,state:a,invocationPath:u=[]}=i,c=a?.lifecycle();yield*Et((async s=>{const h=new Ot(e,t,s);c?.dispatchGraphStart(t.url,u);let p=0;const d=a?.reanimation();if(d){const t=d.enter(u);switch(t.mode()){case"replay":{const{result:e,invocationId:r,path:n}=t.replay();return void await s(new it(e,r,n))}case"resume":{const{result:e,invocationPath:s}=t.resume();let n;r=e,p=s[s.length-1],await(c?.dispatchNodeStart(e,s));const i=e.descriptor.type;"input"!==i&&"output"!==i?(n=await h.invokeNode(e,s),e.outputs=n,r=e):n=e.outputs,c?.dispatchNodeEnd(n,s),await(o?.report?.({type:"nodeend",data:{node:e.descriptor,inputs:e.inputs,outputs:n,path:s,timestamp:J()}}))}}}const l=()=>[...u,p],f=new vt(t,r,n);r||await(o?.report?.({type:"graphstart",data:{graph:t,path:u,timestamp:J()}}));for await(const e of f){i?.signal?.throwIfAborted(),p++;const{inputs:r,descriptor:n,missingInputs:a}=e;if(c?.dispatchEdge(e.current),await(o?.report?.({type:"edge",data:{edge:e.current,to:l(),from:c?.pathFor(e.current.from),timestamp:J(),value:r}})),e.skip){c?.dispatchSkip(),await(o?.report?.({type:"skip",data:{node:n,inputs:r,missingInputs:a,path:l(),timestamp:J()}}));continue}let u;await(c?.dispatchNodeStart(e,l())),await(o?.report?.({type:"nodestart",data:{node:n,inputs:r,path:l(),timestamp:J()},state:c?.state()})),"input"===n.type?(await s(new nt(e,c?.state(),p,l())),await at(t,i,n,e,l(),c?.state()),u=e.outputs?await mt(e.outputs,i,t.url):void 0):"output"===n.type?(await dt(r,n,i,l())||await s(new it(e,p,l())),u=e.outputs):u=await h.invokeNode(e,l()),c?.dispatchNodeEnd(u,l()),await(o?.report?.({type:"nodeend",data:{node:n,inputs:r,outputs:u,path:l(),timestamp:J()}})),e.outputs=u}c?.dispatchGraphEnd(),await(o?.report?.({type:"graphend",data:{path:u,timestamp:J()}}))}))}(t,r,s))if("input"===u.type)u.inputs=n;else if("output"===u.type){e=u.outputs,await(i?.report?.({type:"nodeend",data:{node:u.node,inputs:u.inputs,outputs:e,path:[...o,u.invocationId],timestamp:J()}})),a?.dispatchNodeEnd(e,[...o,u.invocationId]),a?.dispatchGraphEnd(),await(i?.report?.({type:"graphend",data:{path:o,timestamp:J()}}));break}return e}catch(t){if(t.cause)return{$error:t.cause};throw t}}
async function It(t,e,r={},s){const n={...e,...t.args},{probe:i}=r;try{let e={};const o=r.invocationPath||[],a=r.state?.lifecycle();for await(const u of async function*(t,e={},r){const{inputs:s,start:n,stopAfter:i,...o}=e,{probe:a,state:u,invocationPath:c=[]}=o,h=u?.lifecycle();yield*Et((async s=>{const p=new At(e,t,s);h?.dispatchGraphStart(t.url,c);let d=0,l=!1;const f=u?.reanimation();if(f){const e=f.enter(c);switch(e.mode()){case"replay":{const{result:t,invocationId:r,path:n}=e.replay();return void await s(new ot(t,r,n))}case"resume":{const{result:n,invocationPath:u}=e.resume();let c;r=n,d=u[u.length-1],await(h?.dispatchNodeStart(n,u));const f=n.descriptor.type,m=n.descriptor,g=Object.keys(n.outputs||{}).length>0;"input"===f?g?c=n.outputs:(await s(new it(n,h?.state(),d,u)),await ut(t,o,m,n,u,h?.state()),c=n.outputs?await gt(n.outputs,o,t.url):void 0):"output"===m.type?(g||await lt(n.inputs,m,o,u)||await s(new ot(n,d,u)),c=n.outputs):(c=await p.invokeNode(n,u),n.outputs=c,r=n),h?.dispatchNodeEnd(c,u),await(a?.report?.({type:"nodeend",data:{node:n.descriptor,inputs:n.inputs,outputs:c,path:u,timestamp:J(),newOpportunities:structuredClone(n.newOpportunities)}})),i===n.descriptor.id&&(l=!0)}}}const m=()=>[...c,d],g=new St(t,r,n);r||await(a?.report?.({type:"graphstart",data:{graph:t,path:c,timestamp:J()}}));for await(const e of g){o?.signal?.throwIfAborted(),d++;const{inputs:r,descriptor:n,missingInputs:u}=e;if(h?.dispatchEdge(e.current),await(a?.report?.({type:"edge",data:{edge:e.current,to:m(),from:h?.pathFor(e.current.from),timestamp:J(),value:r}})),e.skip){h?.dispatchSkip(),await(a?.report?.({type:"skip",data:{node:n,inputs:r,missingInputs:u,path:m(),timestamp:J()}}));continue}if(await(h?.dispatchNodeStart(e,m())),await(a?.report?.({type:"nodestart",data:{node:n,inputs:r,path:m(),timestamp:J()},result:st(e)})),l)return;let c;"input"===n.type?(await s(new it(e,h?.state(),d,m())),await ut(t,o,n,e,m(),h?.state()),c=e.outputs?await gt(e.outputs,o,t.url):void 0):"output"===n.type?(await lt(r,n,o,m())||await s(new ot(e,d,m())),c=e.outputs):c=await p.invokeNode(e,m()),h?.dispatchNodeEnd(c,m()),await(a?.report?.({type:"nodeend",data:{node:n,inputs:r,outputs:c,path:m(),timestamp:J(),newOpportunities:e.newOpportunities}})),e.outputs=c,i==n.id&&(l=!0)}h?.dispatchGraphEnd(),await(a?.report?.({type:"graphend",data:{path:c,timestamp:J()}}))}))}(t,r,s))if("input"===u.type)u.inputs=n;else if("output"===u.type){e=u.outputs,await(i?.report?.({type:"nodeend",data:{node:u.node,inputs:u.inputs,outputs:e,path:[...o,u.invocationId],timestamp:J(),newOpportunities:u.state.newOpportunities}})),a?.dispatchNodeEnd(e,[...o,u.invocationId]),a?.dispatchGraphEnd(),await(i?.report?.({type:"graphend",data:{path:o,timestamp:J()}}));break}return e}catch(t){if(t.cause)return{$error:t.cause};throw t}}
/**

@@ -131,3 +131,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/var xt;class It{#z;#G;#W;#_;#l;#x;#H=null;constructor(t,e){this.#l=t,this.#z=(t=>{t=t||"";try{return new URL(t)}catch{return}})(t.url),this.#_=e||{};const r=new Q(this),s=new l(r);s.populate(t),this.#x={edges:s,nodes:r}}raw(){return this.#l}metadata(){return this.#l.metadata}nodesByType(t){return this.#x.nodes.byType(t)}async#V(t){const{kits:e}=this.#_,r=this.#_.loader||c();let s;try{s=await Mt(t,{kits:e,loader:r})}catch(e){console.warn(`Error getting describer for node type ${t}`,e)}if(s&&"describe"in s&&s.describe)return s.describe}async describeType(t,e={}){if("input"===t)return C(e);if("output"===t)return q(e);const{kits:r}=this.#_,s=await this.#V(t),n={inputSchema:N(A.In,e?.incoming),outputSchema:N(A.Out,e?.outgoing)};if(!s)return n;const i=this.#_.loader||c(),o={outerGraph:this.#l,loader:i,kits:r,wires:{incoming:Object.fromEntries((e?.incoming??[]).map((t=>[t.in,{outputPort:{describe:async()=>(await t.outPort()).type.schema}}]))),outgoing:Object.fromEntries((e?.outgoing??[]).map((t=>[t.out,{inputPort:{describe:async()=>(await t.inPort()).type.schema}}])))}};this.#z&&(o.base=this.#z);try{return s(e?.inputs||void 0,n.inputSchema,n.outputSchema,o)}catch(e){return console.warn(`Error describing node type ${t}`,e),n}}nodeById(t){return this.#x.nodes.get(t)}nodes(){return this.#x.nodes.nodes()}edges(){return this.#x.edges.edges()}hasEdge(t){return this.#x.edges.hasByValue(t)}kits(){return this.#G??=((t,e)=>{const{kits:r=[]}=t;return[{descriptor:{title:"Built-in Kit",description:"A kit containing built-in Breadboard nodes",url:""},nodeTypes:[new W("input",C,{title:"Input",description:"The input node. Use it to request inputs for your board.",help:{url:"https://breadboard-ai.github.io/breadboard/docs/reference/kits/built-in/#the-input-node"}}),new W("output",q,{title:"Output",description:"The output node. Use it to provide outputs from your board.",help:{url:"https://breadboard-ai.github.io/breadboard/docs/reference/kits/built-in/#the-output-node"}})]},...D(e,t),...r.map((t=>({descriptor:{title:t.title,description:t.description,url:t.url,tags:t.tags||[]},nodeTypes:T(t.handlers)})))]})({kits:this.#_.kits,loader:this.#_.loader},this.#l.nodes)}typeForNode(t){const e=this.nodeById(t);if(e)return this.typeById(e.descriptor.type)}typeById(t){const e=this.kits();this.#W??=new Map(e.flatMap((t=>t.nodeTypes.map((t=>[t.type(),t])))));const r=this.#W.get(t);return r||(f(t)?(s=t,n=this.#_,new V(s,n)):void 0);var s,n}incomingForNode(t){return this.#l.edges.filter((e=>e.to===t)).map((t=>this.#x.edges.getOrCreate(t)))}outgoingForNode(t){return this.#l.edges.filter((e=>e.from===t)).map((t=>this.#x.edges.getOrCreate(t)))}entries(t){return this.#x.nodes.nodes().filter((e=>e.isEntry(t)))}async#K(){const t=(await Promise.all(this.nodesByType("input").filter((t=>t.isEntry())).map((t=>C({inputs:t.configuration(),incoming:t.incoming(),outgoing:t.outgoing(),asType:!0}))))).map((t=>t.outputSchema)),e=(await Promise.all(this.nodesByType("output").filter((t=>t.isExit())).map((t=>q({inputs:t.configuration(),incoming:t.incoming(),outgoing:t.outgoing(),asType:!0}))))).map((t=>t.inputSchema.behavior?.includes("bubble")?null:t.inputSchema)).filter(Boolean);return{inputSchema:r(t,((t,e)=>{!1!==e.additionalProperties?t.additionalProperties=!0:"additionalProperties"in t||(t.additionalProperties=!1)})),outputSchema:((t,e)=>{const r=Object.entries(t.properties||{});if(0==r.length)return t;const s=r.findIndex((([t])=>t===e));return-1==s?t:(r.splice(s,1),{...t,properties:Object.fromEntries(r)})})(r(e),"schema")}}async#Q(t){const e=this.#l.metadata?.describer;if(!e)return{success:!1};try{const r=this.#z,{loader:s}=this.#_;if(!s)return{success:!1};const n=await s.load(e,{base:r,board:this.#l,outerGraph:this.#l});if(!n)return console.warn(`Could not load custom describer graph ${e}`),{success:!1};const{inputSchema:i,outputSchema:o}=await this.#K(),a=await At(n,{...t,$inputSchema:i,$outputSchema:o},{base:r,kits:this.#_.kits,loader:s});return"$error"in a?(console.warn("Error while invoking graph's custom describer",a.$error),{success:!1}):a.inputSchema&&a.outputSchema?{success:!0,result:a}:(console.warn("Custom describer did not return input/output schemas",a),{success:!1})}catch(t){return console.warn("Error while invoking graph's custom describer",t),{success:!1}}}async describe(t){const e=await this.#Q(t||{});return e.success?e.result:this.#K()}get nodeStore(){return this.#x.nodes}get edgeStore(){return this.#x.edges}updateGraph(t){this.#l=t}resetGraph(t){this.#l=t;const e=new Q(this),r=new l(e);r.populate(t),this.#x={edges:r,nodes:e},this.#H=null}#J(){const t=this.#l.graphs;return t?Object.fromEntries(Object.entries(t).map((([t,e])=>[t,new xt(e,this.#_)]))):{}}graphs(){return this.#H??=this.#J()}}xt=It;
*/class xt{#z;#h;constructor({code:t,metadata:e}){this.#z=t,this.#h=e}code(){return this.#z??""}metadata(){return this.#h??{}}}class jt{#G={};get(t){return this.#G[t]}add(t,e){this.#G[t]=new xt(e)}remove(t){this.#G[t]&&delete this.#G[t]}modules(){return this.#G??{}}populate(t){if(t.modules)for(const[e,r]of Object.entries(t.modules))this.add(e,r)}}
/**

@@ -137,4 +137,9 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/var $t;class Nt{#W;#_;#H;#V;#l;#I;#K=null;constructor(t,e){this.#l=t,this.#W=(t=>{t=t||"";try{return new URL(t)}catch{return}})(t.url),this.#V=e||{};const r=new Q(this),s=new l(r);s.populate(t);const n=new jt;n.populate(t),this.#I={edges:s,nodes:r,modules:n}}raw(){return this.#l}metadata(){return this.#l.metadata}nodesByType(t){return this.#I.nodes.byType(t)}async#Q(t){const{kits:e}=this.#V,r=this.#V.loader||c();let s;try{s=await Ut(t,{kits:e,loader:r})}catch(e){console.warn(`Error getting describer for node type ${t}`,e)}if(s&&"describe"in s&&s.describe)return s.describe}async describeType(t,e={}){if("input"===t)return C(e);if("output"===t)return q(e);const{kits:r}=this.#V,s=await this.#Q(t),n={inputSchema:N(A.In,e?.incoming),outputSchema:N(A.Out,e?.outgoing)};if(!s)return n;const i=this.#V.loader||c(),o={outerGraph:this.#l,loader:i,kits:r,wires:{incoming:Object.fromEntries((e?.incoming??[]).map((t=>[t.in,{outputPort:{describe:async()=>(await t.outPort()).type.schema}}]))),outgoing:Object.fromEntries((e?.outgoing??[]).map((t=>[t.out,{inputPort:{describe:async()=>(await t.inPort()).type.schema}}])))}};this.#W&&(o.base=this.#W);try{return s(e?.inputs||void 0,n.inputSchema,n.outputSchema,o)}catch(e){return console.warn(`Error describing node type ${t}`,e),n}}nodeById(t){return this.#I.nodes.get(t)}nodes(){return this.#I.nodes.nodes()}moduleById(t){return this.#I.modules.get(t)}modules(){return this.#I.modules.modules()}edges(){return this.#I.edges.edges()}hasEdge(t){return this.#I.edges.hasByValue(t)}kits(){return this.#_??=((t,e)=>{const{kits:r=[]}=t;return[{descriptor:{title:"Built-in Kit",description:"A kit containing built-in Breadboard nodes",url:""},nodeTypes:[new W("input",C,{title:"Input",description:"The input node. Use it to request inputs for your board.",help:{url:"https://breadboard-ai.github.io/breadboard/docs/reference/kits/built-in/#the-input-node"}}),new W("output",q,{title:"Output",description:"The output node. Use it to provide outputs from your board.",help:{url:"https://breadboard-ai.github.io/breadboard/docs/reference/kits/built-in/#the-output-node"}})]},...D(e,t),...r.map((e=>({descriptor:{title:e.title,description:e.description,url:e.url,tags:e.tags||[]},nodeTypes:T(e.handlers,t)})))]})({kits:this.#V.kits,loader:this.#V.loader},this.#l.nodes)}typeForNode(t){const e=this.nodeById(t);if(e)return this.typeById(e.descriptor.type)}typeById(t){const e=this.kits();this.#H??=new Map(e.flatMap((t=>t.nodeTypes.map((t=>[t.type(),t])))));const r=this.#H.get(t);return r||(f(t)?(s=t,n=this.#V,new V(s,n)):void 0);var s,n}incomingForNode(t){return this.#l.edges.filter((e=>e.to===t)).map((t=>this.#I.edges.getOrCreate(t)))}outgoingForNode(t){return this.#l.edges.filter((e=>e.from===t)).map((t=>this.#I.edges.getOrCreate(t)))}entries(t){return this.#I.nodes.nodes().filter((e=>e.isEntry(t)))}async#J(){const t=(await Promise.all(this.nodesByType("input").filter((t=>t.isEntry())).map((t=>C({inputs:t.configuration(),incoming:t.incoming(),outgoing:t.outgoing(),asType:!0}))))).map((t=>t.outputSchema)),e=(await Promise.all(this.nodesByType("output").filter((t=>t.isExit())).map((t=>q({inputs:t.configuration(),incoming:t.incoming(),outgoing:t.outgoing(),asType:!0}))))).map((t=>t.inputSchema.behavior?.includes("bubble")?null:t.inputSchema)).filter(Boolean);return{inputSchema:r(t,((t,e)=>{!1!==e.additionalProperties?t.additionalProperties=!0:"additionalProperties"in t||(t.additionalProperties=!1)})),outputSchema:((t,e)=>{const r=Object.entries(t.properties||{});if(0==r.length)return t;const s=r.findIndex((([t])=>t===e));return-1==s?t:(r.splice(s,1),{...t,properties:Object.fromEntries(r)})})(r(e),"schema")}}async#X(t){const e=this.#l.metadata?.describer;if(!e)return{success:!1};try{const r=this.#W,{loader:s}=this.#V;if(!s)return{success:!1};const n=await s.load(e,{base:r,board:this.#l,outerGraph:this.#l});if(!n)return console.warn(`Could not load custom describer graph ${e}`),{success:!1};const{inputSchema:i,outputSchema:o}=await this.#J(),a=await It(n,{...t,$inputSchema:i,$outputSchema:o},{base:r,kits:this.#V.kits,loader:s});return"$error"in a?(console.warn("Error while invoking graph's custom describer",a.$error),{success:!1}):a.inputSchema&&a.outputSchema?{success:!0,result:a}:(console.warn("Custom describer did not return input/output schemas",a),{success:!1})}catch(t){return console.warn("Error while invoking graph's custom describer",t),{success:!1}}}async describe(t){const e=await this.#X(t||{});return e.success?e.result:this.#J()}get nodeStore(){return this.#I.nodes}get edgeStore(){return this.#I.edges}get moduleStore(){return this.#I.modules}updateGraph(t){this.#l=t}resetGraph(t){this.#l=t;const e=new Q(this),r=new l(e);r.populate(t);const s=new jt;s.populate(t),this.#I={edges:r,nodes:e,modules:s},this.#K=null}#Y(){const t=this.#l.graphs;return t?Object.fromEntries(Object.entries(t).map((([t,e])=>[t,new $t(e,this.#V)]))):{}}graphs(){return this.#K??=this.#Y()}}$t=Nt;
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const $t=(t,e)=>((t,e)=>new It(t,e))(t,e);
const Ct=(t,e)=>((t,e)=>new Nt(t,e))(t,e);
/**

@@ -144,3 +149,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/function jt(t,e){return 31*t+e|0}function Nt(t){let e=5381,r=t.length;for(;r;)e=33*e^t.charCodeAt(--r);return e>>>0}
*/function qt(t,e){return 31*t+e|0}function Bt(t){let e=5381,r=t.length;for(;r;)e=33*e^t.charCodeAt(--r);return e>>>0}
/**

@@ -150,3 +155,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class Ct{fn;delay;lastCall=0;cachedResult=null;inFlight=null;constructor(t,e=5e3){this.fn=t,this.delay=e}async call(t,...e){const r=Date.now();return this.inFlight?null!==this.cachedResult?this.cachedResult:this.inFlight:null!==this.cachedResult&&r-this.lastCall<this.delay?this.cachedResult:(this.lastCall=r,this.inFlight=this.fn.apply(t,e),this.inFlight.then((t=>{this.cachedResult=t,this.inFlight=null})).catch((()=>{this.inFlight=null})),this.cachedResult||this.inFlight)}getCachedResult(){return this.cachedResult}clearCache(){this.cachedResult=null,this.lastCall=0}setDelay(t){this.delay=t}}
*/class Mt{fn;delay;lastCall=0;cachedResult=null;inFlight=null;constructor(t,e=5e3){this.fn=t,this.delay=e}async call(t,...e){const r=Date.now();return this.inFlight?null!==this.cachedResult?this.cachedResult:this.inFlight:null!==this.cachedResult&&r-this.lastCall<this.delay?this.cachedResult:(this.lastCall=r,this.inFlight=this.fn.apply(t,e),this.inFlight.then((t=>{this.cachedResult=t,this.inFlight=null})).catch((()=>{this.inFlight=null})),this.cachedResult||this.inFlight)}getCachedResult(){return this.cachedResult}clearCache(){this.cachedResult=null,this.lastCall=0}setDelay(t){this.delay=t}}
/**

@@ -156,3 +161,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const qt=async(t,e,r)=>{const s=(t=>{if("invoke"in t&&t.invoke)return t.invoke;if(t instanceof Function)return t;throw new Error("Invalid handler")})(t);return new Promise((t=>{s(e,r).then(t).catch((e=>{t({$error:{error:e}})}))}))},Bt=t=>t.reduce(((t,e)=>({...e.handlers,...t})),{});async function Mt(t,e){const r=Bt(e.kits??[])[t];if(r)return r;const s=await Dt(t,e);if(s)return s;throw new Error(`No handler for node type "${t}"`)}const Rt=1e4,Lt=5e3,Ft=new Map,Ut=new Map;async function Dt(t,e){let r;return Ft.has(t)?r=Ft.get(t):(r=new Ct(Tt,Rt),Ft.set(t,r)),r.call({},t,e)}async function Tt(t,e){const{base:r=s}=e;if(!(f(t)?new URL(t,r):void 0))return;const{loader:n}=e;if(!n)throw new Error(`Cannot load graph for type "${t}" without a loader.`);const i=await n.load(t,e);if(!i)throw new Error(`Cannot load graph for type "${t}"`);return{invoke:async(t,e)=>{const r=e.board?.url&&new URL(e.board?.url),s=r?{...e,base:r}:{...e};return await At(i,t,s)},describe:async(e,r,s,n)=>{if(!n)return{inputSchema:{},outputSchema:{}};const o=function(t){let e=0;const r=new WeakSet,s=[t];for(;s.length;){const t=s.pop();if(t&&"object"==typeof t){if(r.has(t))continue;if(r.add(t),Array.isArray(t)){s.push(t.length);for(let e=t.length-1;e>=0;e--)s.push(t[e])}else for(const r in t){const n=t[r];e=jt(e,Nt(r)),s.push(n)}}else e=jt(e,Nt(String(t)))}return e>>>0}(e);let a=Ut.get(t);return a&&a.hash===o||(a={throttler:new Ct(zt,Lt),hash:o},Ut.set(t,a)),a.throttler.call({},e,i,n)},metadata:(o={title:i.title,description:i.description,url:i.url,icon:i.metadata?.icon,help:i.metadata?.help},Object.fromEntries(Object.entries(o).filter((([,t])=>!!t))))};var o}async function zt(t,e,r){const s=$t(e,r);return await s.describe(t)}
*/const Rt=async(t,e,r)=>{const s=(t=>{if("invoke"in t&&t.invoke)return t.invoke;if(t instanceof Function)return t;throw new Error("Invalid handler")})(t);return new Promise((t=>{s(e,r).then(t).catch((e=>{t({$error:{error:e}})}))}))},Lt=t=>t.reduce(((t,e)=>({...e.handlers,...t})),{});async function Ut(t,e){if(f(t)){const r=await Gt(t,e);if(r)return r}const r=Lt(e.kits??[])[t];if(r)return r;throw new Error(`No handler for node type "${t}"`)}const Ft=1e4,Dt=5e3,Tt=new Map,zt=new Map;async function Gt(t,e){let r;return Tt.has(t)?r=Tt.get(t):(r=new Mt(Wt,Ft),Tt.set(t,r)),r.call({},t,e)}async function Wt(t,e){const{base:r=s}=e;if(!(f(t)?new URL(t,r):void 0))return;const{loader:n}=e;if(!n)throw new Error(`Cannot load graph for type "${t}" without a loader.`);const i=await n.load(t,e);if(!i)throw new Error(`Cannot load graph for type "${t}"`);return{invoke:async(t,e)=>{const r=e.board?.url&&new URL(e.board?.url),s=r?{...e,base:r}:{...e};return await It(i,t,s)},describe:async(e,r,s,n)=>{if(!n)return{inputSchema:{},outputSchema:{}};const o=function(t){let e=0;const r=new WeakSet,s=[t];for(;s.length;){const t=s.pop();if(t&&"object"==typeof t){if(r.has(t))continue;if(r.add(t),Array.isArray(t)){s.push(t.length);for(let e=t.length-1;e>=0;e--)s.push(t[e])}else for(const r in t){const n=t[r];e=qt(e,Bt(r)),s.push(n)}}else e=qt(e,Bt(String(t)))}return e>>>0}(e);let a=zt.get(t);return a&&a.hash===o||(a={throttler:new Mt(_t,Dt),hash:o},zt.set(t,a)),a.throttler.call({},e,i,n)},metadata:(o={title:i.title,description:i.description,url:i.url,icon:i.metadata?.icon,help:i.metadata?.help},Object.fromEntries(Object.entries(o).filter((([,t])=>!!t))))};var o}async function _t(t,e,r){const s=Ct(e,r);return await s.describe(t)}
/**

@@ -168,3 +173,3 @@ * @license

*/
class Gt{}
class Ht{}
/**

@@ -174,3 +179,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const Wt=new class{#a=new Map;vendId(t,e){let r=this.#a.get(t)||0;return r++,this.#a.set(t,r),`${e}-${r}`}}
*/const Vt=new class{#a=new Map;vendId(t,e){let r=this.#a.get(t)||0;return r++,this.#a.set(t,r),`${e}-${r}`}}
/**

@@ -180,3 +185,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/;class _t extends Gt{id;type;outgoing=[];incoming=[];configuration={};metadata;#c;#X;constructor(t,e,r={}){super(),this.#X=e,"string"==typeof t?this.type=t:(this.type="fn",this.#c=t);const{$id:s,$metadata:n,...i}=r;this.id=s??Wt.vendId(e,this.type),n&&(this.metadata=n),this.configuration=i}addIncomingEdge(t,e,r,s,n){if(t.#X!==this.#X)throw new Error("Can't connect nodes from different scopes");const i={to:this,from:t,out:e,in:r,schema:n};s&&(i.constant=!0),this.incoming.push(i),t.outgoing.push(i)}#Y(t){const e=this.#c??t.getHandler(this.type);return e&&"describe"in e&&e.describe?e.describe:void 0}async invoke(t,e){const r=e??this.#X,s=this.#c??r.getHandler(this.type);let n;const i=s&&"invoke"in s&&s.invoke?s.invoke:"function"==typeof s?s:void 0;if(i)n=await i(t,this);else{if(!s||"function"==typeof s||!s.graph)throw new Error(`Can't find handler for ${this.id}`);{const e=s.graph.getPinnedNodes();if(1!==e.length)throw new Error("Expected exactly one graph");n=await r.invokeOneRound(t,e[0])}}return n}async describe(t=this.#X,e,r,s){const n=this.#Y(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#X.serialize(t,this)}async serializeNode(){const t={id:this.id,type:this.type,configuration:this.configuration};return this.metadata&&(t.metadata=this.metadata),[t]}}
*/;class Kt extends Ht{id;type;outgoing=[];incoming=[];configuration={};metadata;#c;#Z;constructor(t,e,r={}){super(),this.#Z=e,"string"==typeof t?this.type=t:(this.type="fn",this.#c=t);const{$id:s,$metadata:n,...i}=r;this.id=s??Vt.vendId(e,this.type),n&&(this.metadata=n),this.configuration=i}addIncomingEdge(t,e,r,s,n){if(t.#Z!==this.#Z)throw new Error("Can't connect nodes from different scopes");const i={to:this,from:t,out:e,in:r,schema:n};s&&(i.constant=!0),this.incoming.push(i),t.outgoing.push(i)}#tt(t){const e=this.#c??t.getHandler(this.type);return e&&"describe"in e&&e.describe?e.describe:void 0}async invoke(t,e){const r=e??this.#Z,s=this.#c??r.getHandler(this.type);let n;const i=s&&"invoke"in s&&s.invoke?s.invoke:"function"==typeof s?s:void 0;if(i)n=await i(t,this);else{if(!s||"function"==typeof s||!s.graph)throw new Error(`Can't find handler for ${this.id}`);{const e=s.graph.getPinnedNodes();if(1!==e.length)throw new Error("Expected exactly one graph");n=await r.invokeOneRound(t,e[0])}}return n}async describe(t=this.#Z,e,r,s){const n=this.#tt(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#Z.serialize(t,this)}async serializeNode(){const t={id:this.id,type:this.type,configuration:this.configuration};return this.metadata&&(t.metadata=this.metadata),[t]}}
/**

@@ -186,3 +191,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class Ht{queue=[];inputs=new Map;constants=new Map;controlWires=new Map;haveRun=new Set;queueUp(t){this.queue.includes(t)||this.queue.push(t)}next(){if(!this.queue.length)throw new Error("No nodes in queue");return this.queue.shift()}done(){return 0===this.queue.length}missingInputs(t){if(0===t.incoming.length&&this.haveRun.has(t))return[];const e=new Set(t.incoming.map((t=>t.in))),r=new Set([...Object.keys(t.configuration),...Object.keys(this.constants.get(t)??{})]);for(const[e,s]of(this.inputs.get(t)??new Map).entries())s.length&&r.add(e);this.controlWires.get(t)?.length&&r.add("");const s=[...e].filter((t=>!r.has(t)));return!!s.length&&s}shiftInputs(t){const e={...t.configuration,...this.constants.get(t)},r=this.inputs.get(t)??new Map;for(const[t,s]of r.entries())s.length>0&&(e[t]=s.shift());return this.haveRun.add(t),this.controlWires.delete(t),e}processResult(t,e){const r={nodes:[],unused:[]},s=new Set(Object.keys(e));for(const n of t.outgoing){const t=this.distributeResults(n,e);t.forEach((t=>s.delete(t)));const i=this.missingInputs(n.to);i||this.queueUp(n.to),r.nodes.push({node:n.to,received:t,missing:i})}return r.unused=[...s],r}distributeResults(t,e){const r="*"===t.out?e:""===t.out?{}:void 0!==e[t.out]?{[t.in]:e[t.out]}:{};t.constant&&this.constants.set(t.to,{...this.constants.get(t.to),...r}),this.inputs.has(t.to)||this.inputs.set(t.to,new Map);const s=this.inputs.get(t.to);for(const t of Object.keys(r))s?.has(t)||s?.set(t,[]),s?.get(t)?.push(r[t]);return""===t.in&&this.controlWires.set(t.to,[...this.controlWires.get(t.to)??[],t.from]),Object.keys(r)}}
*/class Qt{queue=[];inputs=new Map;constants=new Map;controlWires=new Map;haveRun=new Set;queueUp(t){this.queue.includes(t)||this.queue.push(t)}next(){if(!this.queue.length)throw new Error("No nodes in queue");return this.queue.shift()}done(){return 0===this.queue.length}missingInputs(t){if(0===t.incoming.length&&this.haveRun.has(t))return[];const e=new Set(t.incoming.map((t=>t.in))),r=new Set([...Object.keys(t.configuration),...Object.keys(this.constants.get(t)??{})]);for(const[e,s]of(this.inputs.get(t)??new Map).entries())s.length&&r.add(e);this.controlWires.get(t)?.length&&r.add("");const s=[...e].filter((t=>!r.has(t)));return!!s.length&&s}shiftInputs(t){const e={...t.configuration,...this.constants.get(t)},r=this.inputs.get(t)??new Map;for(const[t,s]of r.entries())s.length>0&&(e[t]=s.shift());return this.haveRun.add(t),this.controlWires.delete(t),e}processResult(t,e){const r={nodes:[],unused:[]},s=new Set(Object.keys(e));for(const n of t.outgoing){const t=this.distributeResults(n,e);t.forEach((t=>s.delete(t)));const i=this.missingInputs(n.to);i||this.queueUp(n.to),r.nodes.push({node:n.to,received:t,missing:i})}return r.unused=[...s],r}distributeResults(t,e){const r="*"===t.out?e:""===t.out?{}:void 0!==e[t.out]?{[t.in]:e[t.out]}:{};t.constant&&this.constants.set(t.to,{...this.constants.get(t.to),...r}),this.inputs.has(t.to)||this.inputs.set(t.to,new Map);const s=this.inputs.get(t.to);for(const t of Object.keys(r))s?.has(t)||s?.set(t,[]),s?.get(t)?.push(r[t]);return""===t.in&&this.controlWires.set(t.to,[...this.controlWires.get(t.to)??[],t.from]),Object.keys(r)}}
/**

@@ -192,3 +197,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class Vt{parentLexicalScope;parentDynamicScope;#Z={};#tt=[];#et=[];constructor(t={}){this.parentLexicalScope=t.lexicalScope,this.parentDynamicScope=t.dynamicScope}addHandlers(t){Object.entries(t).forEach((([t,e])=>this.#Z[t]=e))}getHandler(t){return this.#Z[t]||this.parentDynamicScope?.getHandler(t)||this.parentLexicalScope?.getHandler(t)}pin(t){this.#tt.push(t)}compactPins(){const t=new Set,e=[];for(const r of this.#tt){if(t.has(r))continue;e.push(r);this.#rt(r).forEach((e=>t.add(e)))}this.#tt=e}getPinnedNodes(){return this.#tt}addCallbacks(t){this.#et.push(t)}#st(){return[...this.#et,...this.parentDynamicScope?this.parentDynamicScope.#st():[]]}async invoke(t,e=new Ht){try{!1!==t&&(t?t instanceof Array?t:[t]:this.#tt).flatMap((t=>this.#rt(t).filter((t=>!1===e?.missingInputs(t))))).forEach((t=>e?.queueUp(t)));const r=this.#st();for(;!e.done();){for(const t of r)if(await(t.stop?.(this,e)))return;const t=e.next(),s=e.shiftInputs(t);let n;for(const e of r)n??=await(e.before?.(this,t,s));const i=n??await t.invoke(s,this).catch((t=>({$error:{type:"error",error:t}}))),o=e.processResult(t,i);for(const e of r)await(e.after?.(this,t,s,i,o));if(o.unused.includes("$error"))throw i.$error.error}}finally{for(const t of this.#et)await(t.done?.())}}invokeOneRound(t={},e=void 0,r){let s;"$state"in t&&(r=t.$state,delete t.$state);const n=new Promise((t=>{s=t})),i=new Vt({dynamicScope:this});let o;i.addHandlers({input:async()=>t,output:async t=>(s?.(await t),s=void 0,t)});const a=new Map;let u;i.addCallbacks({stop:(t,e)=>(s||(u=e),!s),after:(t,e,r,s,n)=>{o=e;for(const{node:t,missing:e}of n.nodes)e?a.set(t.id,e.join(", ")):a.delete(t.id)},done:()=>{s?.({$error:{type:"error",error:new Error(`Output node never reached. Last node was ${o?.id}.\n\nThese nodes had inputs missing:\n${Array.from(a,(([t,e])=>` ${t}: ${e}`)).join("\n")}`)}})}});const c=i.invoke(void 0!==e?e:this.#tt,r);return Promise.all([n,c]).then((([t])=>({...t,...u?{$state:u}:{}})))}async serialize(t,e){const r=(e?[e]:this.#tt).flatMap((t=>this.#rt(t))),s={},n=await Promise.all(r.map((async t=>{const[e,r]=await t.serializeNode();if(r&&(s[e.id]=r),("input"===e.type||"output"===e.type)&&!e.configuration?.schema){const r=await this.#nt(t);Object.entries(r.properties??{}).length>0&&(e.configuration={...e.configuration,schema:r})}return e}))),i=r.flatMap((t=>t.outgoing.map((t=>({from:t.from.id,to:t.to.id,out:t.out,in:t.in,...t.constant?{constant:!0}:{}})))));return{...t,edges:i,nodes:n,graphs:s}}#rt(t){const e=new Set,r=[t];for(;r.length;){const t=r.shift();e.has(t)||(e.add(t),t.incoming.forEach((t=>r.push(t.from))),t.outgoing.forEach((t=>r.push(t.to))))}return[...e]}async#it(t){const e=Object.fromEntries(t.incoming.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}]))),r=Object.fromEntries(t.outgoing.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}])));return await t.describe(this,t.configuration,{properties:e},{properties:r})}async#nt(t){const e={},r=new Set;let s;if("input"===t.type){const n=new Set;for(const s of t.outgoing)"*"!==s.out&&""!==s.out&&(n.add(s.to),r.add(s.out),s.schema&&(e[s.out]=s.schema));for(const r of n){const s=await this.#it(r),n=s?.inputSchema?.properties;if(n)for(const s of r.incoming)s.from===t&&n[s.in]&&(e[s.out]={...n[s.in],...e[s.out]})}s=(t=>Object.entries(t).map((([t,e])=>{const r=e;if(!r.$optional)return t;delete r.$optional})).filter(Boolean))(e)}else{if("output"!==t.type)throw new Error("Can't yet derive schema for non-input/output nodes");{const s=new Set;for(const n of t.incoming)"*"!==n.out&&""!==n.out&&(s.add(n.from),r.add(n.in),n.schema&&(e[n.in]=n.schema));for(const r of s){const s=await this.#it(r),n=s?.outputSchema?.properties;if(n)for(const s of r.outgoing)s.to===t&&n[s.out]&&(e[s.in]={...n[s.out],...e[s.in]})}}}for(const t of r)e[t]?(e[t].type||="string",e[t].title||=t):e[t]={type:"string",title:t};const n={type:"object",properties:e};return s&&(n.required=s),n}}
*/class Jt{parentLexicalScope;parentDynamicScope;#et={};#rt=[];#st=[];constructor(t={}){this.parentLexicalScope=t.lexicalScope,this.parentDynamicScope=t.dynamicScope}addHandlers(t){Object.entries(t).forEach((([t,e])=>this.#et[t]=e))}getHandler(t){return this.#et[t]||this.parentDynamicScope?.getHandler(t)||this.parentLexicalScope?.getHandler(t)}pin(t){this.#rt.push(t)}compactPins(){const t=new Set,e=[];for(const r of this.#rt){if(t.has(r))continue;e.push(r);this.#nt(r).forEach((e=>t.add(e)))}this.#rt=e}getPinnedNodes(){return this.#rt}addCallbacks(t){this.#st.push(t)}#it(){return[...this.#st,...this.parentDynamicScope?this.parentDynamicScope.#it():[]]}async invoke(t,e=new Qt){try{!1!==t&&(t?t instanceof Array?t:[t]:this.#rt).flatMap((t=>this.#nt(t).filter((t=>!1===e?.missingInputs(t))))).forEach((t=>e?.queueUp(t)));const r=this.#it();for(;!e.done();){for(const t of r)if(await(t.stop?.(this,e)))return;const t=e.next(),s=e.shiftInputs(t);let n;for(const e of r)n??=await(e.before?.(this,t,s));const i=n??await t.invoke(s,this).catch((t=>({$error:{type:"error",error:t}}))),o=e.processResult(t,i);for(const e of r)await(e.after?.(this,t,s,i,o));if(o.unused.includes("$error"))throw i.$error.error}}finally{for(const t of this.#st)await(t.done?.())}}invokeOneRound(t={},e=void 0,r){let s;"$state"in t&&(r=t.$state,delete t.$state);const n=new Promise((t=>{s=t})),i=new Jt({dynamicScope:this});let o;i.addHandlers({input:async()=>t,output:async t=>(s?.(await t),s=void 0,t)});const a=new Map;let u;i.addCallbacks({stop:(t,e)=>(s||(u=e),!s),after:(t,e,r,s,n)=>{o=e;for(const{node:t,missing:e}of n.nodes)e?a.set(t.id,e.join(", ")):a.delete(t.id)},done:()=>{s?.({$error:{type:"error",error:new Error(`Output node never reached. Last node was ${o?.id}.\n\nThese nodes had inputs missing:\n${Array.from(a,(([t,e])=>` ${t}: ${e}`)).join("\n")}`)}})}});const c=i.invoke(void 0!==e?e:this.#rt,r);return Promise.all([n,c]).then((([t])=>({...t,...u?{$state:u}:{}})))}async serialize(t,e){const r=(e?[e]:this.#rt).flatMap((t=>this.#nt(t))),s={},n=await Promise.all(r.map((async t=>{const[e,r]=await t.serializeNode();if(r&&(s[e.id]=r),("input"===e.type||"output"===e.type)&&!e.configuration?.schema){const r=await this.#ot(t);Object.entries(r.properties??{}).length>0&&(e.configuration={...e.configuration,schema:r})}return e}))),i=r.flatMap((t=>t.outgoing.map((t=>({from:t.from.id,to:t.to.id,out:t.out,in:t.in,...t.constant?{constant:!0}:{}})))));return{...t,edges:i,nodes:n,graphs:s}}#nt(t){const e=new Set,r=[t];for(;r.length;){const t=r.shift();e.has(t)||(e.add(t),t.incoming.forEach((t=>r.push(t.from))),t.outgoing.forEach((t=>r.push(t.to))))}return[...e]}async#at(t){const e=Object.fromEntries(t.incoming.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}]))),r=Object.fromEntries(t.outgoing.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}])));return await t.describe(this,t.configuration,{properties:e},{properties:r})}async#ot(t){const e={},r=new Set;let s;if("input"===t.type){const n=new Set;for(const s of t.outgoing)"*"!==s.out&&""!==s.out&&(n.add(s.to),r.add(s.out),s.schema&&(e[s.out]=s.schema));for(const r of n){const s=await this.#at(r),n=s?.inputSchema?.properties;if(n)for(const s of r.incoming)s.from===t&&n[s.in]&&(e[s.out]={...n[s.in],...e[s.out]})}s=(t=>Object.entries(t).map((([t,e])=>{const r=e;if(!r.$optional)return t;delete r.$optional})).filter(Boolean))(e)}else{if("output"!==t.type)throw new Error("Can't yet derive schema for non-input/output nodes");{const s=new Set;for(const n of t.incoming)"*"!==n.out&&""!==n.out&&(s.add(n.from),r.add(n.in),n.schema&&(e[n.in]=n.schema));for(const r of s){const s=await this.#at(r),n=s?.outputSchema?.properties;if(n)for(const s of r.outgoing)s.to===t&&n[s.out]&&(e[s.in]={...n[s.out],...e[s.in]})}}}for(const t of r)e[t]?(e[t].type||="string",e[t].title||=t):e[t]={type:"string",title:t};const n={type:"object",properties:e};return s&&(n.required=s),n}}
/**

@@ -198,3 +203,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class Kt extends Vt{#ot;#at=[];parentLambdaNode;constructor(t={}){super(t),this.#ot=t.serialize??!1,this.parentLambdaNode=t.parentLambda}async serialize(t,e){return super.serialize(t,e&&"function"==typeof e.unProxy?e.unProxy():e)}serializing(){return this.#ot}asScopeFor(t){return(...e)=>{const r=Xt(this);try{return t(...e)}finally{Xt(r)}}}addClosureEdge(t){this.#at.push(t)}getClosureEdges(){return this.#at}}let Qt;function Jt(){return Qt||(Qt=new Kt),Qt}function Xt(t){const e=Jt();return Qt=t,e}
*/class Xt extends Jt{#ut;#ct=[];parentLambdaNode;constructor(t={}){super(t),this.#ut=t.serialize??!1,this.parentLambdaNode=t.parentLambda}async serialize(t,e){return super.serialize(t,e&&"function"==typeof e.unProxy?e.unProxy():e)}serializing(){return this.#ut}asScopeFor(t){return(...e)=>{const r=te(this);try{return t(...e)}finally{te(r)}}}addClosureEdge(t){this.#ct.push(t)}getClosureEdges(){return this.#ct}}let Yt;function Zt(){return Yt||(Yt=new Xt),Yt}function te(t){const e=Zt();return Yt=t,e}
/**

@@ -204,3 +209,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class Yt{}
*/class ee{}
/**

@@ -210,3 +215,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const Zt=Symbol("IsValue");function te(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[Zt]}const ee=t=>{if("array"===t.type){t.items??={};const r=(e=t.items,Array.isArray(e)?t.items[0]:t.items);return r.type??="object",r}var e;return t};class re extends Yt{#ut;#X;#ct;#ht;#pt;constructor(t,e,r,s=!1,n={}){super(),this.#ut=t,this.#X=e,this.#ct="string"==typeof r?{[r]:r}:r,this[Zt]=this,this.#ht=s,this.#pt=n}then(t,e){if(1!==Object.keys(this.#ct).length)throw Error("Can't `await` for multiple values");return this.#ut.then((e=>e&&t&&this.#X.asScopeFor(t)(e[Object.keys(this.#ct)[0]])),e&&this.#X.asScopeFor(e))}asNodeInput(){return[this.#ut.unProxy(),this.#ct,this.#ht,this.#pt]}to(t,e){const r=ne(t)?t.unProxy():new se(t,this.#X,e);return r.addInputsFromNode(this.#ut,this.#ct,this.#ht,this.#pt),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#ct).map((([t,e])=>[e,t])));te(t)?(e=t.#dt(e),this.#ut.addInputsFromNode(t.#ut,e,t.#ht,t.#pt)):ne(t)?this.#ut.addInputsFromNode(t.unProxy(),e):this.#ut.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#ct).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#ct)[0]]:t}}else e=this.#dt(t);return new re(this.#ut,this.#X,e,this.#ht,this.#pt)}memoize(){return new re(this.#ut,this.#X,this.#ct,!0,this.#pt)}invoke(t){return new se("invoke",this.#X,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#pt.type,this}isString(){return this.#pt.type="string",this}isNumber(){return this.#pt.type="number",this}isBoolean(){return this.#pt.type="boolean",this}isArray(){return this.#pt.type="array",this}isObject(){return this.#pt.type="object",this}title(t){return this.#pt.title=t,this}description(t){return this.#pt.description=t,this}format(t){return ee(this.#pt).format=t,this}examples(...t){return this.#pt.examples=t,this}default(t){return this.#pt.default=t,this}optional(){return this.#pt.$optional=!0,this}behavior(...t){const e=ee(this.#pt);return e.behavior??=[],e.behavior.push(...t),this}#dt(t){const e={...this.#ct};return Object.entries(t).forEach((([t,r])=>{this.#ct[r]?(e[t]=this.#ct[r],delete this.#ct[r]):e[t]=r})),e}}
*/const re=Symbol("IsValue");function se(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[re]}const ne=t=>{if("array"===t.type){t.items??={};const r=(e=t.items,Array.isArray(e)?t.items[0]:t.items);return r.type??="object",r}var e;return t};class ie extends ee{#ht;#Z;#pt;#dt;#lt;constructor(t,e,r,s=!1,n={}){super(),this.#ht=t,this.#Z=e,this.#pt="string"==typeof r?{[r]:r}:r,this[re]=this,this.#dt=s,this.#lt=n}then(t,e){if(1!==Object.keys(this.#pt).length)throw Error("Can't `await` for multiple values");return this.#ht.then((e=>e&&t&&this.#Z.asScopeFor(t)(e[Object.keys(this.#pt)[0]])),e&&this.#Z.asScopeFor(e))}asNodeInput(){return[this.#ht.unProxy(),this.#pt,this.#dt,this.#lt]}to(t,e){const r=ae(t)?t.unProxy():new oe(t,this.#Z,e);return r.addInputsFromNode(this.#ht,this.#pt,this.#dt,this.#lt),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#pt).map((([t,e])=>[e,t])));se(t)?(e=t.#ft(e),this.#ht.addInputsFromNode(t.#ht,e,t.#dt,t.#lt)):ae(t)?this.#ht.addInputsFromNode(t.unProxy(),e):this.#ht.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#pt).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#pt)[0]]:t}}else e=this.#ft(t);return new ie(this.#ht,this.#Z,e,this.#dt,this.#lt)}memoize(){return new ie(this.#ht,this.#Z,this.#pt,!0,this.#lt)}invoke(t){return new oe("invoke",this.#Z,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#lt.type,this}isString(){return this.#lt.type="string",this}isNumber(){return this.#lt.type="number",this}isBoolean(){return this.#lt.type="boolean",this}isArray(){return this.#lt.type="array",this}isObject(){return this.#lt.type="object",this}title(t){return this.#lt.title=t,this}description(t){return this.#lt.description=t,this}format(t){return ne(this.#lt).format=t,this}examples(...t){return this.#lt.examples=t,this}default(t){return this.#lt.default=t,this}optional(){return this.#lt.$optional=!0,this}behavior(...t){const e=ne(this.#lt);return e.behavior??=[],e.behavior.push(...t),this}#ft(t){const e={...this.#pt};return Object.entries(t).forEach((([t,r])=>{this.#pt[r]?(e[t]=this.#pt[r],delete this.#pt[r]):e[t]=r})),e}}
/**

@@ -216,3 +221,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class se extends _t{#lt;#ft;#mt;#X;#c;constructor(t,e,r={}){const s=!ne(r)&&!(r instanceof Gt)&&!oe(r)&&!te(r)&&r.$id;if(super(t,e,s?{$id:s}:{}),this.#X=e,"string"!=typeof t&&(this.#c=t),ne(r))this.addInputsFromNode(r.unProxy());else if(r instanceof Gt)this.addInputsFromNode(r);else if(oe(r))this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()});else if(te(r))this.addInputsFromNode(...r.asNodeInput());else{void 0!==r.$id&&delete r.$id;const t=r.$metadata;void 0!==t&&(this.metadata=t,delete r.$metadata),this.addInputsAsValues(r)}this[this.#gt()]=this,this.#lt=new Promise(((t,e)=>{this.#ft=t,this.#mt=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{oe(s)&&(s=s.getBoardCapabilityAsValue()),te(s)?r.push(s.as(t).asNodeInput()):s instanceof Gt||ne(s)?r.push([ne(s)?s.unProxy():s,{[t]:t},!1,void 0]):e[t]=s})),this.configuration={...this.configuration,...e},r.forEach((t=>this.unProxy().addInputsFromNode(...t)))}addInputsFromNode(t,e={"*":""},r,s){const n=Object.entries(e);0===n.length?this.addIncomingEdge(t,"","",r):n.forEach((([e,n])=>{e.startsWith("*-")&&(e="*",n=""),this.unProxy().addIncomingEdge(ne(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const i=t.#X;if(i!==this.#X){for(let t=this.#X;t!==i;t=t.parentLexicalScope)if(!t)throw new Error("Only wires from parent scopes allowed");if("*"===e||""===e)throw new Error("Can't use * or empty wires from parent scopes");this.#X.addClosureEdge({scope:i,from:t,to:this,out:e,in:r})}else super.addIncomingEdge(t,e,r,s,n)}async invoke(t,e){const r=new Kt({dynamicScope:e,lexicalScope:this.#X});return r.asScopeFor((async()=>{try{const e=this.#c??r.getHandler(this.type);let s;const n=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(n)s=await n(t,this);else{if(!e||"function"==typeof e||!e.graph)throw new Error(`Can't find handler for ${this.id}`);{const n=e.graph.getPinnedNodes();if(1!==n.length)throw new Error("Expected exactly one graph");s=await r.invokeOneRound(t,n[0])}}for(const[t,e]of Object.entries(s))e instanceof se?s[t]=(await e)[t]:te(e)?s[t]=await e:oe(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#ft&&(this.#ft(s),this.#ft=this.#mt=void 0),s}catch(t){throw this.#mt&&(this.#mt(t),this.#ft=this.#mt=void 0),t}}))()}async serializeNode(){for(const[t,e]of Object.entries(this.configuration))e instanceof Promise&&(this.configuration[t]=await e);if("fn"!==this.type)return super.serializeNode();const t=new Kt({lexicalScope:this.#X,serialize:!0}),e=this.#c??t.getHandler(this.type);if(e&&"function"!=typeof e&&e.graph){const r={id:this.id,type:"invoke",configuration:{...this.configuration,path:"#"+this.id}},s=e.graph.getPinnedNodes();if(1!==s.length)throw new Error("Expected exactly one graph");return[r,await t.serialize({},s[0])]}{const t=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(!t)throw new Error(`Handler for ${this.type} in ${this.id} not found`);const r=this.id.replace(/-/g,"_"),[s,n]=((t,e)=>{let r=e.toString();const s=/(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*\{/;if(/(?:async\s*)?(\w+|\([^)]*\))\s*=>\s*/.test(r))r=`const ${t} = ${r};`;else{const e=s.exec(r);if(null===e)throw new Error("Unexpected serialization: "+r);t=e[1]||t}return[r,t]})(r,t);return[{id:this.id,type:"runJavascript",configuration:{...this.configuration,code:s,name:n,raw:!0},metadata:this.metadata}]}}asProxy(){return new Proxy(this,{get(t,e,r){if("string"==typeof e){const r=new re(t,t.#X,e);let s=t[e];return s=s&&"function"==typeof s?s.bind(t):(t=>r.invoke(t)).bind(r),new Proxy(s,{get(t,e,s){const n=Reflect.get(r,e,r);return"function"==typeof n?n.bind(r):n},ownKeys:t=>Reflect.ownKeys(r).filter((t=>"string"==typeof t))})}return Reflect.get(t,e,r)},ownKeys:t=>[t.#gt()]})}unProxy(){return this}then(t,e){if(this.#X.serializing())throw new Error(`Can't \`await\` on ${this.id} in board declaration. Did you mean to use \`code\` instead of \`board\`?`);try{return this.#X.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#X.asScopeFor(e));throw t})),this.#lt.then(t&&this.#X.asScopeFor(t),e&&this.#X.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#X.asScopeFor(e));throw t}}to(t,e){const r=ne(t)?t.unProxy():new se(t,this.#X,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof _t?this.addInputsFromNode(t):te(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new re(this,this.#X,t)}keys(){return[this.#gt()]}#gt(){return"*-"+this.id}}function ne(t){return"function"==typeof t.unProxy}
*/class oe extends Kt{#mt;#gt;#yt;#Z;#c;constructor(t,e,r={}){const s=!ae(r)&&!(r instanceof Ht)&&!ce(r)&&!se(r)&&r.$id;if(super(t,e,s?{$id:s}:{}),this.#Z=e,"string"!=typeof t&&(this.#c=t),ae(r))this.addInputsFromNode(r.unProxy());else if(r instanceof Ht)this.addInputsFromNode(r);else if(ce(r))this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()});else if(se(r))this.addInputsFromNode(...r.asNodeInput());else{void 0!==r.$id&&delete r.$id;const t=r.$metadata;void 0!==t&&(this.metadata=t,delete r.$metadata),this.addInputsAsValues(r)}this[this.#wt()]=this,this.#mt=new Promise(((t,e)=>{this.#gt=t,this.#yt=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{ce(s)&&(s=s.getBoardCapabilityAsValue()),se(s)?r.push(s.as(t).asNodeInput()):s instanceof Ht||ae(s)?r.push([ae(s)?s.unProxy():s,{[t]:t},!1,void 0]):e[t]=s})),this.configuration={...this.configuration,...e},r.forEach((t=>this.unProxy().addInputsFromNode(...t)))}addInputsFromNode(t,e={"*":""},r,s){const n=Object.entries(e);0===n.length?this.addIncomingEdge(t,"","",r):n.forEach((([e,n])=>{e.startsWith("*-")&&(e="*",n=""),this.unProxy().addIncomingEdge(ae(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const i=t.#Z;if(i!==this.#Z){for(let t=this.#Z;t!==i;t=t.parentLexicalScope)if(!t)throw new Error("Only wires from parent scopes allowed");if("*"===e||""===e)throw new Error("Can't use * or empty wires from parent scopes");this.#Z.addClosureEdge({scope:i,from:t,to:this,out:e,in:r})}else super.addIncomingEdge(t,e,r,s,n)}async invoke(t,e){const r=new Xt({dynamicScope:e,lexicalScope:this.#Z});return r.asScopeFor((async()=>{try{const e=this.#c??r.getHandler(this.type);let s;const n=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(n)s=await n(t,this);else{if(!e||"function"==typeof e||!e.graph)throw new Error(`Can't find handler for ${this.id}`);{const n=e.graph.getPinnedNodes();if(1!==n.length)throw new Error("Expected exactly one graph");s=await r.invokeOneRound(t,n[0])}}for(const[t,e]of Object.entries(s))e instanceof oe?s[t]=(await e)[t]:se(e)?s[t]=await e:ce(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#gt&&(this.#gt(s),this.#gt=this.#yt=void 0),s}catch(t){throw this.#yt&&(this.#yt(t),this.#gt=this.#yt=void 0),t}}))()}async serializeNode(){for(const[t,e]of Object.entries(this.configuration))e instanceof Promise&&(this.configuration[t]=await e);if("fn"!==this.type)return super.serializeNode();const t=new Xt({lexicalScope:this.#Z,serialize:!0}),e=this.#c??t.getHandler(this.type);if(e&&"function"!=typeof e&&e.graph){const r={id:this.id,type:"invoke",configuration:{...this.configuration,path:"#"+this.id}},s=e.graph.getPinnedNodes();if(1!==s.length)throw new Error("Expected exactly one graph");return[r,await t.serialize({},s[0])]}{const t=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(!t)throw new Error(`Handler for ${this.type} in ${this.id} not found`);const r=this.id.replace(/-/g,"_"),[s,n]=((t,e)=>{let r=e.toString();const s=/(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*\{/;if(/(?:async\s*)?(\w+|\([^)]*\))\s*=>\s*/.test(r))r=`const ${t} = ${r};`;else{const e=s.exec(r);if(null===e)throw new Error("Unexpected serialization: "+r);t=e[1]||t}return[r,t]})(r,t);return[{id:this.id,type:"runJavascript",configuration:{...this.configuration,code:s,name:n,raw:!0},metadata:this.metadata}]}}asProxy(){return new Proxy(this,{get(t,e,r){if("string"==typeof e){const r=new ie(t,t.#Z,e);let s=t[e];return s=s&&"function"==typeof s?s.bind(t):(t=>r.invoke(t)).bind(r),new Proxy(s,{get(t,e,s){const n=Reflect.get(r,e,r);return"function"==typeof n?n.bind(r):n},ownKeys:t=>Reflect.ownKeys(r).filter((t=>"string"==typeof t))})}return Reflect.get(t,e,r)},ownKeys:t=>[t.#wt()]})}unProxy(){return this}then(t,e){if(this.#Z.serializing())throw new Error(`Can't \`await\` on ${this.id} in board declaration. Did you mean to use \`code\` instead of \`board\`?`);try{return this.#Z.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#Z.asScopeFor(e));throw t})),this.#mt.then(t&&this.#Z.asScopeFor(t),e&&this.#Z.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#Z.asScopeFor(e));throw t}}to(t,e){const r=ae(t)?t.unProxy():new oe(t,this.#Z,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof Kt?this.addInputsFromNode(t):se(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new ie(this,this.#Z,t)}keys(){return[this.#wt()]}#wt(){return"*-"+this.id}}function ae(t){return"function"==typeof t.unProxy}
/**

@@ -222,3 +227,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/function ie(t,e){return t&&function(t,e){Jt().addHandlers({[t]:e})}
*/function ue(t,e){return t&&function(t,e){Zt().addHandlers({[t]:e})}
/**

@@ -228,3 +233,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/(t,e),r=>new se(t??e,Jt(),r).asProxy()}function oe(t){return"function"==typeof t&&"function"==typeof t.getBoardCapabilityAsValue}
*/(t,e),r=>new oe(t??e,Zt(),r).asProxy()}function ce(t){return"function"==typeof t&&"function"==typeof t.getBoardCapabilityAsValue}
/**

@@ -234,3 +239,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const ae=async()=>{throw new Error("Reserved word handler should never be invoked")};ie("input",ae),ie("output",ae);
*/const he=async()=>{throw new Error("Reserved word handler should never be invoked")};ue("input",he),ue("output",he);
/**

@@ -241,3 +246,3 @@ * @license

*/
class ue{graph;handlers;constructor(t){this.graph=t}populateDescriptor(t){const{title:e,description:r,version:s}=this.graph;return{title:e,description:r,version:s,...t}}async#yt(t,e=[]){this.graph.url=t,this.handlers=e?.reduce(((t,e)=>({...t,...e.handlers})),{})}handlerForNode(t){if(!this.graph)throw new Error("Builder was not yet initialized.");const{nodes:e}=this.graph,r=e.find((e=>e.id===t));if(!r)throw new Error(`Node ${t} not found in graph.`);return{metadata:r.configuration?.$metadata,describe:async()=>{const e={inputSchema:{type:"object"},outputSchema:{type:"object"}};if(null!=this.graph.graphs&&t in this.graph.graphs){const r=this.graph.graphs[t];return null==r?e:await $t(r).describe()}if("invoke"===r.type){const{$board:t}=r.configuration;if(t)return await $t(t).describe()}return e},invoke:async(t,e)=>{const s=r.configuration;s&&(t={...s,...t});const n={...this.handlers,...Bt(e?.kits||[])},i=n?.[r.type];if(!i)throw new Error(`No handler found for node "${r.type}".`);const o=this.graph,a=o.url?new URL(o.url):new URL(import.meta.url);return qt(i,t,{...e,outerGraph:o,base:a})}}}static async create(t,e,r){const s=new ue(t);return await s.#yt(e,r),s}}
class pe{graph;handlers;constructor(t){this.graph=t}populateDescriptor(t){const{title:e,description:r,version:s}=this.graph;return{title:e,description:r,version:s,...t}}async#bt(t,e=[]){this.graph.url=t,this.handlers=e?.reduce(((t,e)=>({...t,...e.handlers})),{})}handlerForNode(t){if(!this.graph)throw new Error("Builder was not yet initialized.");const{nodes:e}=this.graph,r=e.find((e=>e.id===t));if(!r)throw new Error(`Node ${t} not found in graph.`);return{metadata:r.configuration?.$metadata,describe:async()=>{const e={inputSchema:{type:"object"},outputSchema:{type:"object"}};if(null!=this.graph.graphs&&t in this.graph.graphs){const r=this.graph.graphs[t];return null==r?e:await Ct(r).describe()}if("invoke"===r.type){const{$board:t}=r.configuration;if(t)return await Ct(t).describe()}return e},invoke:async(t,e)=>{const s=r.configuration;s&&(t={...s,...t});const n={...this.handlers,...Lt(e?.kits||[])},i=n?.[r.type];if(!i)throw new Error(`No handler found for node "${r.type}".`);const o=this.graph,a=o.url?new URL(o.url):new URL(import.meta.url);return Rt(i,t,{...e,outerGraph:o,base:a})}}}static async create(t,e,r){const s=new pe(t);return await s.#bt(e,r),s}}
/**

@@ -247,3 +252,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class ce{url;title;description;version;namespacePrefix;tags;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n="",tags:i=[]}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n,this.tags=i}#wt(t){return Object.keys(t).reduce(((e,r)=>(e[`${this.namespacePrefix}${r}`]=t[r],e)),{})}build(t){if(!this.url)throw new Error("Builder was not yet initialized.");const e=this.url,r=this.namespacePrefix,{title:s,description:n,version:i,tags:o}=this,a=this.#wt(t),u=Object.keys(t);return class{title=s;description=n;version=i;url=e;tags=o;get handlers(){return a}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n||"tags"===n?s[n]:u.includes(n)?(s={})=>{const i=t.getConfigWithLambda(s),{$id:o,...a}=i;return t.create(e,`${r}${n}`,{...a},o)}:void 0});return e}}}static wrap(t,e){const r=Object.entries(e).reduce(((t,e)=>{const[r,s]=e;return t[r]={invoke:async t=>{let e=[];s&&s.length>0&&(e=s.toString().match(/\((.+?)\)/)?.[1].split(",")??[],s.length>1&&0===e.length&&"___args"in t&&Array.isArray(t.___args)&&(e=["___args"]));for(const r of e)if(r.trim()in t==!1)throw new Error(`Missing input: ${r.trim()}. Valid inputs are: ${Object.keys(t).join(", ")}`);const r=e.filter((t=>0==t.startsWith("___"))).map((e=>t[e.trim()])),n=e[e.length-1];null!=n&&n.startsWith("___")&&r.push(...t[n]);const i=await s(...r);return"object"!=typeof i||Array.isArray(i)?{result:i}:{...i}}},t}),{});return new ce(t).build(r)}}
*/class de{url;title;description;version;namespacePrefix;tags;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n="",tags:i=[]}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n,this.tags=i}#vt(t){return Object.keys(t).reduce(((e,r)=>(e[`${this.namespacePrefix}${r}`]=t[r],e)),{})}build(t){if(!this.url)throw new Error("Builder was not yet initialized.");const e=this.url,r=this.namespacePrefix,{title:s,description:n,version:i,tags:o}=this,a=this.#vt(t),u=Object.keys(t);return class{title=s;description=n;version=i;url=e;tags=o;get handlers(){return a}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n||"tags"===n?s[n]:u.includes(n)?(s={})=>{const i=t.getConfigWithLambda(s),{$id:o,...a}=i;return t.create(e,`${r}${n}`,{...a},o)}:void 0});return e}}}static wrap(t,e){const r=Object.entries(e).reduce(((t,e)=>{const[r,s]=e;return t[r]={invoke:async t=>{let e=[];s&&s.length>0&&(e=s.toString().match(/\((.+?)\)/)?.[1].split(",")??[],s.length>1&&0===e.length&&"___args"in t&&Array.isArray(t.___args)&&(e=["___args"]));for(const r of e)if(r.trim()in t==!1)throw new Error(`Missing input: ${r.trim()}. Valid inputs are: ${Object.keys(t).join(", ")}`);const r=e.filter((t=>0==t.startsWith("___"))).map((e=>t[e.trim()])),n=e[e.length-1];null!=n&&n.startsWith("___")&&r.push(...t[n]);const i=await s(...r);return"object"!=typeof i||Array.isArray(i)?{result:i}:{...i}}},t}),{});return new de(t).build(r)}}
/**

@@ -253,3 +258,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class he{#bt;#u;#l;metadata;constructor(t,e,r){this.#bt=t,this.#u=e,this.#l=((t,e,r)=>{if(r.edges&&r.nodes){const s=new URL(t);return s.searchParams.set("graph",e),{...r,url:s.href}}throw new Error("Invalid graph descriptor")})(t,e,r),this.describe=this.describe.bind(this),this.invoke=this.invoke.bind(this);const{title:s,description:n,metadata:i}=this.#l;this.metadata={title:s,description:n},i?.deprecated&&(this.metadata.deprecated=i.deprecated),i?.icon&&(this.metadata.icon=i.icon),i?.help&&(this.metadata.help=i.help),i?.tags&&(this.metadata.tags=i.tags)}async describe(t,e,r,s){return await $t(this.#l,{kits:s?.kits,loader:s?.loader}).describe(t)}async invoke(t,e){return await At(this.#l,t,e)}}const pe=t=>{const{title:e,description:r,version:s,url:n}=t;return{title:e,description:r,version:s,url:n,handlers:(i=new URL(n),o=t.nodes,Object.fromEntries(Object.entries(o).map((([t,e])=>[t,new he(i,t,e)]))))};var i,o},de=async t=>{if("https:"===t.protocol||"http:"===t.protocol){if(!t.pathname.endsWith(".kit.json")){const e=await import(t.href);if(null==e.default)throw new Error(`Module ${t} does not have a default export.`);const r=Object.getOwnPropertyNames(e.default.prototype);if(0==r.includes("constructor")||0==r.includes("handlers"))throw new Error(`Module default export '${t}' does not look like a Kit (either no constructor or no handler).`);return new(0,e.default)({create:()=>{throw Error("Node instantiation can't (yet) happen during runtime")}})}{const e=await a(t);if((t=>{if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.title&&"string"==typeof e.description&&"string"==typeof e.version&&"string"==typeof e.url&&"object"==typeof e.nodes})(e))return pe(e)}}else if("file:"===t.protocol)throw new Error("File protocol is not yet supported");throw new Error(`Unable to load kit from "${t}"`)};export{ue as GraphToKitAdapter,ce as KitBuilder,e as SchemaBuilder,pe as fromManifest,de as load};
*/class le{#St;#u;#l;metadata;constructor(t,e,r){this.#St=t,this.#u=e,this.#l=((t,e,r)=>{if(r.edges&&r.nodes){const s=new URL(t);return s.searchParams.set("graph",e),{...r,url:s.href}}throw new Error("Invalid graph descriptor")})(t,e,r),this.describe=this.describe.bind(this),this.invoke=this.invoke.bind(this);const{title:s,description:n,metadata:i}=this.#l;this.metadata={title:s,description:n},i?.deprecated&&(this.metadata.deprecated=i.deprecated),i?.icon&&(this.metadata.icon=i.icon),i?.help&&(this.metadata.help=i.help),i?.tags&&(this.metadata.tags=i.tags)}async describe(t,e,r,s){return await Ct(this.#l,{kits:s?.kits,loader:s?.loader}).describe(t)}async invoke(t,e){return await It(this.#l,t,e)}}const fe=t=>{const{title:e,description:r,version:s,url:n}=t;return{title:e,description:r,version:s,url:n,handlers:(i=new URL(n),o=t.nodes,Object.fromEntries(Object.entries(o).map((([t,e])=>[t,new le(i,t,e)]))))};var i,o},me=async t=>{if("https:"===t.protocol||"http:"===t.protocol){if(!t.pathname.endsWith(".kit.json")){const e=await import(t.href);if(null==e.default)throw new Error(`Module ${t} does not have a default export.`);const r=Object.getOwnPropertyNames(e.default.prototype);if(0==r.includes("constructor")||0==r.includes("handlers"))throw new Error(`Module default export '${t}' does not look like a Kit (either no constructor or no handler).`);return new(0,e.default)({create:()=>{throw Error("Node instantiation can't (yet) happen during runtime")}})}{const e=await a(t);if((t=>{if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.title&&"string"==typeof e.description&&"string"==typeof e.version&&"string"==typeof e.url&&"object"==typeof e.nodes})(e))return fe(e)}}else if("file:"===t.protocol)throw new Error("File protocol is not yet supported");throw new Error(`Unable to load kit from "${t}"`)};export{pe as GraphToKitAdapter,de as KitBuilder,e as SchemaBuilder,fe as fromManifest,me as load};
//# sourceMappingURL=kits.min.js.map

@@ -6,3 +6,3 @@ /**

*/
import { GraphDescriptor } from "../types.js";
import { GraphDescriptor, NodeIdentifier } from "../types.js";
import { ChangeEventType, ErrorRejection, GraphChangeEvent, GraphChangeRejectEvent, NoChangeRejection } from "./types.js";

@@ -17,4 +17,5 @@ /**

changeType: ChangeEventType;
affectedNodes: NodeIdentifier[];
static eventName: string;
constructor(graph: GraphDescriptor, version: number, visualOnly: boolean, changeType: ChangeEventType);
constructor(graph: GraphDescriptor, version: number, visualOnly: boolean, changeType: ChangeEventType, affectedNodes: NodeIdentifier[]);
}

@@ -21,0 +22,0 @@ /**

@@ -14,4 +14,5 @@ /**

changeType;
affectedNodes;
static eventName = "graphchange";
constructor(graph, version, visualOnly, changeType) {
constructor(graph, version, visualOnly, changeType, affectedNodes) {
super(ChangeEvent.eventName, {

@@ -26,2 +27,3 @@ bubbles: false,

this.changeType = changeType;
this.affectedNodes = affectedNodes;
}

@@ -28,0 +30,0 @@ }

@@ -63,3 +63,3 @@ /**

this.#inspector.resetGraph(graph);
this.#eventTarget.dispatchEvent(new ChangeEvent(this.#graph, this.#version, false, "history"));
this.#eventTarget.dispatchEvent(new ChangeEvent(this.#graph, this.#version, false, "history", []));
},

@@ -73,7 +73,7 @@ });

}
#updateGraph(visualOnly) {
#updateGraph(visualOnly, affectedNodes) {
if (this.#parent) {
this.#graph = { ...this.#graph };
// Update parent version.
this.#parent.#updateGraph(visualOnly);
this.#parent.#updateGraph(visualOnly, []);
}

@@ -97,3 +97,3 @@ else {

this.#inspector.updateGraph(this.#graph);
this.#eventTarget.dispatchEvent(new ChangeEvent(this.#graph, this.#version, visualOnly, "edit"));
this.#eventTarget.dispatchEvent(new ChangeEvent(this.#graph, this.#version, visualOnly, "edit", affectedNodes));
}

@@ -168,2 +168,4 @@ #rollbackGraph(checkpoint, error) {

let visualOnly = true;
// Collect affected nodes
const affectedNodes = [];
for (const edit of edits) {

@@ -176,2 +178,3 @@ const result = await this.#singleEdit(edit, context);

}
affectedNodes.push(result.affectedNodes);
if (!result.noChange) {

@@ -193,3 +196,4 @@ noChange = false;

this.#history.addEdit(this.#graph, checkpoint, label, this.#version);
!dryRun && this.#updateGraph(visualOnly);
!dryRun &&
this.#updateGraph(visualOnly, [...new Set(affectedNodes.flat())]);
return { success: true, log };

@@ -215,3 +219,3 @@ }

this.#graphs[id] = editable;
this.#updateGraph(false);
this.#updateGraph(false, []);
return editable;

@@ -232,4 +236,4 @@ }

delete this.#graphs[id];
this.#updateGraph(false);
return { success: true };
this.#updateGraph(false, []);
return { success: true, affectedNodes: [] };
}

@@ -247,3 +251,3 @@ replaceGraph(id, graph) {

this.#graphs[id] = editable;
this.#updateGraph(false);
this.#updateGraph(false, []);
return editable;

@@ -250,0 +254,0 @@ }

@@ -68,3 +68,3 @@ /**

}
return { success: true };
return { success: true, affectedNodes: [edge.from, edge.to] };
}

@@ -86,5 +86,5 @@ async do(spec, context) {

graph.edges.push(edge);
return { success: true };
return { success: true, affectedNodes: [edge.from, edge.to] };
}
}
//# sourceMappingURL=add-edge.js.map

@@ -22,3 +22,3 @@ /**

}
return { success: true };
return { success: true, affectedNodes: [] };
}

@@ -37,5 +37,5 @@ async do(spec, context) {

store.nodeStore.add(node);
return { success: true };
return { success: true, affectedNodes: [node.id] };
}
}
//# sourceMappingURL=add-node.js.map

@@ -15,3 +15,3 @@ /**

}
return { success: true };
return { success: true, affectedNodes: [] };
}

@@ -46,5 +46,5 @@ async do(spec, context) {

}
return { success: true };
return { success: true, affectedNodes: [id] };
}
}
//# sourceMappingURL=change-configuration.js.map

@@ -13,3 +13,3 @@ /**

if (edgesEqual(from, to)) {
return { success: true };
return { success: true, affectedNodes: [] };
}

@@ -24,3 +24,3 @@ const canRemoveOp = new RemoveEdge();

return canAdd;
return { success: true };
return { success: true, affectedNodes: [] };
}

@@ -39,3 +39,3 @@ async do(spec, context) {

if (edgesEqual(from, to)) {
return { success: true, noChange: true };
return { success: true, noChange: true, affectedNodes: [] };
}

@@ -53,5 +53,5 @@ const fixedUpEdge = fixUpStarEdge(from);

}
return { success: true };
return { success: true, affectedNodes: [edge.from, edge.to] };
}
}
//# sourceMappingURL=change-edge.js.map

@@ -15,5 +15,5 @@ /**

graph.metadata = metadata;
return { success: true, visualOnly };
return { success: true, visualOnly, affectedNodes: [] };
}
}
//# sourceMappingURL=change-graph-metadata.js.map

@@ -15,3 +15,3 @@ /**

}
return { success: true };
return { success: true, affectedNodes: [] };
}

@@ -48,5 +48,6 @@ #isVisualOnly(incoming, existing) {

}
return { success: true, visualOnly };
const affectedNodes = visualOnly ? [] : [id];
return { success: true, visualOnly, affectedNodes };
}
}
//# sourceMappingURL=change-metadata.js.map

@@ -16,3 +16,3 @@ /**

}
return { success: true };
return { success: true, affectedNodes: [spec.from, spec.to] };
}

@@ -34,5 +34,5 @@ async do(spec, context) {

store.edgeStore.remove(foundEdge);
return { success: true };
return { success: true, affectedNodes: [edge.from, edge.to] };
}
}
//# sourceMappingURL=remove-edge.js.map

@@ -15,3 +15,3 @@ /**

}
return { success: true };
return { success: true, affectedNodes: [id] };
}

@@ -39,5 +39,5 @@ async do(spec, context) {

store.nodeStore.remove(id);
return { success: true };
return { success: true, affectedNodes: [id] };
}
}
//# sourceMappingURL=remove-node.js.map

@@ -15,2 +15,3 @@ /**

changeType: ChangeEventType;
affectedNodes: NodeIdentifier[];
};

@@ -223,2 +224,3 @@ export type ErrorRejection = {

success: true;
affectedNodes: NodeIdentifier[];
/**

@@ -225,0 +227,0 @@ * Indicates that the edit was successful, and

@@ -58,2 +58,8 @@ /**

export async function getHandler(type, context) {
if (graphUrlLike(type)) {
const graphHandler = await getGraphHandler(type, context);
if (graphHandler) {
return graphHandler;
}
}
const handlers = handlersFromKits(context.kits ?? []);

@@ -64,6 +70,2 @@ const kitHandler = handlers[type];

}
const graphHandler = await getGraphHandler(type, context);
if (graphHandler) {
return graphHandler;
}
throw new Error(`No handler for node type "${type}"`);

@@ -70,0 +72,0 @@ }

@@ -6,4 +6,4 @@ /**

*/
import { EdgeResponse, ErrorResponse, GraphEndProbeData, GraphStartProbeData, InputResponse, InputValues, NodeEndResponse, NodeStartResponse, OutputResponse, SkipProbeMessage } from "../types.js";
import { HarnessRunResult, RunEdgeEvent, RunEndEvent, RunErrorEvent, RunGraphEndEvent, RunGraphStartEvent, RunInputEvent, RunLifecycleEvent, RunNextEvent, RunNodeEndEvent, RunNodeStartEvent, RunOutputEvent, RunSecretEvent, RunSkipEvent } from "./types.js";
import { ErrorResponse, GraphEndProbeData, GraphStartProbeData, InputResponse, InputValues, NodeEndResponse, NodeStartResponse, OutputResponse, SkipProbeMessage, TraversalResult } from "../types.js";
import { HarnessRunResult, RunEndEvent, RunErrorEvent, RunGraphEndEvent, RunGraphStartEvent, RunInputEvent, RunLifecycleEvent, RunNextEvent, RunNodeEndEvent, RunNodeStartEvent, RunOutputEvent, RunSecretEvent, RunSkipEvent } from "./types.js";
import { SecretResult } from "./types.js";

@@ -56,8 +56,2 @@ import { End } from "../remote/types.js";

}
export declare class EdgeEvent extends Event implements RunEdgeEvent {
data: EdgeResponse;
static readonly eventName = "edge";
readonly running = true;
constructor(data: EdgeResponse);
}
export declare class GraphStartEvent extends Event implements RunGraphStartEvent {

@@ -77,5 +71,6 @@ data: GraphStartProbeData;

data: NodeStartResponse;
result?: TraversalResult | undefined;
static readonly eventName = "nodestart";
readonly running = true;
constructor(data: NodeStartResponse);
constructor(data: NodeStartResponse, result?: TraversalResult | undefined);
}

@@ -82,0 +77,0 @@ export declare class NodeEndEvent extends Event implements RunNodeEndEvent {

@@ -75,11 +75,2 @@ /**

}
export class EdgeEvent extends Event {
data;
static eventName = "edge";
running = true;
constructor(data) {
super(EdgeEvent.eventName, { ...opts });
this.data = data;
}
}
export class GraphStartEvent extends Event {

@@ -105,7 +96,9 @@ data;

data;
result;
static eventName = "nodestart";
running = true;
constructor(data) {
constructor(data, result) {
super(NodeStartEvent.eventName, { ...opts });
this.data = data;
this.result = result;
}

@@ -112,0 +105,0 @@ }

@@ -7,3 +7,3 @@ /**

import { run } from "./run.js";
import { EndEvent, InputEvent, GraphEndEvent, GraphStartEvent, NodeEndEvent, NodeStartEvent, OutputEvent, RunnerErrorEvent, SecretEvent, SkipEvent, PauseEvent, ResumeEvent, StartEvent, EdgeEvent, NextEvent, } from "./events.js";
import { EndEvent, InputEvent, GraphEndEvent, GraphStartEvent, NodeEndEvent, NodeStartEvent, OutputEvent, RunnerErrorEvent, SecretEvent, SkipEvent, PauseEvent, ResumeEvent, StartEvent, NextEvent, } from "./events.js";
import { timestamp } from "../timestamp.js";

@@ -126,6 +126,2 @@ export class LocalRunner extends EventTarget {

}
case "edge": {
this.dispatchEvent(new EdgeEvent(data));
break;
}
case "graphstart": {

@@ -140,3 +136,3 @@ this.dispatchEvent(new GraphStartEvent(data));

case "nodestart": {
this.dispatchEvent(new NodeStartEvent(data));
this.dispatchEvent(new NodeStartEvent(data, result.value.result));
break;

@@ -143,0 +139,0 @@ }

@@ -9,3 +9,2 @@ /**

import { createLoader } from "../loader/index.js";
import { saveRunnerState } from "../serialization.js";
import { timestamp } from "../timestamp.js";

@@ -16,9 +15,2 @@ import { Diagnostics } from "./diagnostics.js";

const fromProbe = (probe) => {
const loadStateIfAny = () => {
if (probe.type === "nodestart") {
return probe.state;
}
return undefined;
};
const state = loadStateIfAny();
const data = structuredClone(probe.data);

@@ -28,3 +20,3 @@ return {

data,
state,
result: probe.type === "nodestart" ? probe.result : undefined,
reply: async () => {

@@ -38,15 +30,2 @@ // Do nothing

const bubbled = invocationId == -1;
const saveState = async () => {
const runState = result.runState;
if (runState) {
return runState;
}
return [
{
url: undefined,
path: [invocationId],
state: saveRunnerState(type, result.state),
},
];
};
if (type === "input") {

@@ -60,3 +39,2 @@ const { inputArguments, path } = result;

},
saveState,
};

@@ -72,3 +50,2 @@ }

},
saveState,
};

@@ -130,3 +107,3 @@ }

const store = config.store || createDefaultDataStore();
const { base, signal, inputs, state, start } = config;
const { base, signal, inputs, state, start, stopAfter } = config;
try {

@@ -150,2 +127,3 @@ let last;

start,
stopAfter,
})) {

@@ -152,0 +130,0 @@ last = maybeSaveResult(data, last);

import { serverStreamEventDecoder } from "../remote/http.js";
import { EndEvent, InputEvent, GraphEndEvent, GraphStartEvent, NodeEndEvent, NodeStartEvent, OutputEvent, RunnerErrorEvent, SkipEvent, PauseEvent, ResumeEvent, StartEvent, EdgeEvent, } from "./events.js";
import { EndEvent, InputEvent, GraphEndEvent, GraphStartEvent, NodeEndEvent, NodeStartEvent, OutputEvent, RunnerErrorEvent, SkipEvent, PauseEvent, ResumeEvent, StartEvent, } from "./events.js";
import { timestamp } from "../timestamp.js";

@@ -210,6 +210,2 @@ import { chunkRepairTransform } from "../remote/chunk-repair.js";

}
case "edge": {
this.dispatchEvent(new EdgeEvent(data));
break;
}
case "graphstart": {

@@ -216,0 +212,0 @@ this.dispatchEvent(new GraphStartEvent(data));

@@ -13,3 +13,3 @@ /**

import type { ManagedRunState } from "../run/types.js";
import type { GraphDescriptor, ErrorResponse, InputResponse, InputValues, Kit, OutputResponse, OutputValues, SkipProbeMessage, GraphStartProbeData, GraphEndProbeData, NodeEndResponse, NodeStartResponse, Schema, EdgeResponse } from "../types.js";
import type { GraphDescriptor, ErrorResponse, InputResponse, InputValues, Kit, OutputResponse, OutputValues, SkipProbeMessage, GraphStartProbeData, GraphEndProbeData, NodeEndResponse, NodeStartResponse, Schema, NodeIdentifier, TraversalResult } from "../types.js";
import { TypedEventTargetType, TypedEventTarget } from "../utils/typed-event-target.js";

@@ -179,2 +179,8 @@ /**

start?: StartLabel;
/**
* The id of the node to stop the run after. In combination with `state`, can
* be used to run parts of the board.
* If not specified, runs the whole board.
*/
stopAfter?: NodeIdentifier;
};

@@ -191,3 +197,2 @@ export type RunEventMap = {

skip: RunSkipEvent;
edge: RunEdgeEvent;
graphstart: RunGraphStartEvent;

@@ -233,6 +238,2 @@ graphend: RunGraphEndEvent;

};
export type RunEdgeEvent = Event & {
data: EdgeResponse;
running: true;
};
export type RunGraphStartEvent = Event & {

@@ -248,2 +249,3 @@ data: GraphStartProbeData;

data: NodeStartResponse;
result?: TraversalResult;
running: true;

@@ -250,0 +252,0 @@ };

@@ -60,2 +60,6 @@ /**

export { runGraph } from "./run/run-graph.js";
/**
* Conversion helpers
*/
export { sequenceEntryToHarnessRunResult } from "./inspector/run/conversions.js";
//# sourceMappingURL=index.d.ts.map

@@ -43,2 +43,6 @@ /**

export { runGraph } from "./run/run-graph.js";
/**
* Conversion helpers
*/
export { sequenceEntryToHarnessRunResult } from "./inspector/run/conversions.js";
//# sourceMappingURL=index.js.map

@@ -16,2 +16,3 @@ /**

import { graphUrlLike } from "../utils/graph-url-like.js";
import { ModuleCache } from "./module.js";
export const inspectableGraph = (graph, options) => {

@@ -44,3 +45,5 @@ return new Graph(graph, options);

edges.populate(graph);
this.#cache = { edges, nodes };
const modules = new ModuleCache();
modules.populate(graph);
this.#cache = { edges, nodes, modules };
}

@@ -133,2 +136,8 @@ raw() {

}
moduleById(id) {
return this.#cache.modules.get(id);
}
modules() {
return this.#cache.modules.modules();
}
edges() {

@@ -268,2 +277,5 @@ return this.#cache.edges.edges();

}
get moduleStore() {
return this.#cache.modules;
}
updateGraph(graph) {

@@ -277,3 +289,5 @@ this.#graph = graph;

edges.populate(graph);
this.#cache = { edges, nodes };
const modules = new ModuleCache();
modules.populate(graph);
this.#cache = { edges, nodes, modules };
this.#graphs = null;

@@ -280,0 +294,0 @@ }

@@ -68,3 +68,3 @@ /**

descriptor,
nodeTypes: collectNodeTypes(kit.handlers),
nodeTypes: collectNodeTypes(kit.handlers, context),
};

@@ -77,6 +77,11 @@ }),

};
const collectNodeTypes = (handlers) => {
const collectNodeTypes = (handlers, context) => {
return Object.entries(handlers)
.sort()
.map(([type, handler]) => new KitNodeType(type, handler));
.map(([type, handler]) => {
if (graphUrlLike(type)) {
return new CustomNodeType(type, context);
}
return new KitNodeType(type, handler);
});
};

@@ -83,0 +88,0 @@ const portsFromHandler = async (type, handler) => {

@@ -44,2 +44,3 @@ /**

code: true,
module: true,
};

@@ -46,0 +47,0 @@ export const collectPorts = (type, edges, schema, addErrorPort, allowRequired, values) => {

@@ -6,2 +6,5 @@ /**

*/
import { InspectableRunSequenceEntry } from "../types.js";
import { HarnessRunResult } from "../../harness/types.js";
export { eventsAsHarnessRunResults, sequenceEntryToHarnessRunResult };
export declare const eventIdFromEntryId: (entryId?: string) => string;

@@ -11,2 +14,4 @@ export declare const entryIdFromEventId: (eventId?: string) => string | null;

export declare const pathFromId: (id: string) => number[];
declare function sequenceEntryToHarnessRunResult(entry: InspectableRunSequenceEntry, trimPath?: (path: number[]) => number[]): HarnessRunResult | null;
declare function eventsAsHarnessRunResults(events: InspectableRunSequenceEntry[]): AsyncGenerator<HarnessRunResult>;
//# sourceMappingURL=conversions.d.ts.map

@@ -6,2 +6,3 @@ /**

*/
export { eventsAsHarnessRunResults, sequenceEntryToHarnessRunResult };
export const eventIdFromEntryId = (entryId) => {

@@ -19,2 +20,222 @@ return `e-${entryId || "0"}`;

};
function sequenceEntryToHarnessRunResult(entry, trimPath = (path) => path) {
const [type, data] = entry;
switch (type) {
case "graphstart": {
const { graphStart, path, graph: inspectableGraph, edges } = data;
const graph = inspectableGraph?.raw();
return {
type,
data: { timestamp: graphStart, path: trimPath(path), graph, edges },
async reply() { },
};
}
case "nodestart": {
const { path } = data;
const { node, inputs, start: timestamp, traversalResult, } = data.event;
return {
type,
data: {
node: node.descriptor,
inputs,
path: trimPath(path),
timestamp,
},
result: traversalResult,
async reply() { },
};
}
case "nodeend": {
const { path } = data;
const { node, inputs, outputs, end: timestamp, traversalResult, } = data.event;
return {
type,
data: {
node: node.descriptor,
inputs,
outputs: outputs || {},
path: trimPath(path),
timestamp: timestamp || 0,
newOpportunities: traversalResult?.newOpportunities || [],
},
async reply() { },
};
}
case "graphend": {
const { path } = data;
const { graphEnd: timestamp } = data;
return {
type,
data: { path: trimPath(path), timestamp: timestamp || 0 },
async reply() { },
};
}
case "error": {
const { graphStart: timestamp } = data;
return {
type,
data: { error: "TODO: Store actual error object", timestamp },
async reply() { },
};
}
case "input": {
const { path } = data;
const { node, inputs: inputArguments, bubbled, start: timestamp, } = data.event;
return {
type,
data: {
node: node.descriptor,
inputArguments,
bubbled,
path: trimPath(path),
timestamp,
},
async reply() { },
};
}
case "output": {
const { path } = data;
const { node, outputs, bubbled, start: timestamp, } = data.event;
return {
type,
data: {
node: node.descriptor,
outputs: outputs || {},
bubbled,
path: trimPath(path),
timestamp,
},
async reply() { },
};
}
case "secret": {
return null;
}
default: {
throw new Error("Unknown event type: " + type);
}
}
}
// TODO: Use sequenceEntryToHarnessRunResult
async function* eventsAsHarnessRunResults(events) {
const first = events[0];
let endPath = [];
if (first[0] !== "graphstart") {
throw new Error("Expected a graphstart event at the beginning of the timeline");
}
else {
endPath = first[1].path;
}
for await (const result of events) {
const [type, data] = result;
switch (type) {
case "graphstart": {
const { graphStart, path, graph: inspectableGraph, edges } = data;
const graph = inspectableGraph?.raw();
yield {
type,
data: { timestamp: graphStart, path: trimPath(path), graph, edges },
async reply() { },
};
break;
}
case "nodestart": {
const { path } = data;
const { node, inputs, start: timestamp, traversalResult, } = data.event;
yield {
type,
data: {
node: node.descriptor,
inputs,
path: trimPath(path),
timestamp,
},
result: traversalResult,
async reply() { },
};
break;
}
case "nodeend": {
const { path } = data;
const { node, inputs, outputs, end: timestamp, traversalResult, } = data.event;
yield {
type,
data: {
node: node.descriptor,
inputs,
outputs: outputs || {},
path: trimPath(path),
timestamp: timestamp || 0,
newOpportunities: traversalResult?.newOpportunities || [],
},
async reply() { },
};
break;
}
case "graphend": {
const { path } = data;
const { graphEnd: timestamp } = data;
yield {
type,
data: { path: trimPath(path), timestamp: timestamp || 0 },
async reply() { },
};
if (path.join(".") === endPath.join(".")) {
return;
}
break;
}
case "error": {
const { graphStart: timestamp } = data;
yield {
type,
data: { error: "TODO: Store actual error object", timestamp },
async reply() { },
};
break;
}
case "input": {
const { path } = data;
const { node, inputs: inputArguments, bubbled, start: timestamp, } = data.event;
yield {
type,
data: {
node: node.descriptor,
inputArguments,
bubbled,
path: trimPath(path),
timestamp,
},
async reply() { },
};
break;
}
case "output": {
const { path } = data;
const { node, outputs, bubbled, start: timestamp, } = data.event;
yield {
type,
data: {
node: node.descriptor,
outputs: outputs || {},
bubbled,
path: trimPath(path),
timestamp,
},
async reply() { },
};
break;
}
case "secret": {
break;
}
default: {
throw new Error("Unknown event type: " + type);
}
}
}
function trimPath(path) {
return path.slice(endPath.length);
}
}
//# sourceMappingURL=conversions.js.map

@@ -7,5 +7,7 @@ /**

import { HarnessRunResult } from "../../harness/types.js";
import { NodeConfiguration } from "../../types.js";
import { RunSerializer } from "./serializer.js";
import { EventIdentifier, GraphDescriptorStore, InspectableRunEdge, InspectableRunEvent, InspectableRunNodeEvent, RunObserverOptions, RunSerializationOptions } from "../types.js";
import { SerializedDataStoreGroup } from "../../data/types.js";
import { ReanimationState } from "../../run/types.js";
export declare class EventManager {

@@ -20,4 +22,6 @@ #private;

serializer(): RunSerializer;
replay(): AsyncGenerator<HarnessRunResult, void, any>;
getEventById(id: EventIdentifier): InspectableRunEvent | null;
reanimationStateAt(id: EventIdentifier, nodeConfig: NodeConfiguration): Promise<ReanimationState>;
}
//# sourceMappingURL=event-manager.d.ts.map

@@ -10,3 +10,4 @@ /**

import { RunSerializer } from "./serializer.js";
import { entryIdFromEventId, eventIdFromEntryId, idFromPath, pathFromId, } from "./conversions.js";
import { entryIdFromEventId, eventIdFromEntryId, eventsAsHarnessRunResults, idFromPath, pathFromId, } from "./conversions.js";
import { LifecycleManager } from "../../run/lifecycle.js";
const shouldSkipEvent = (options, node, isTopLevel) => {

@@ -82,3 +83,3 @@ // Never skip input or output events.

}
#addNodestart(data) {
#addNodestart(data, result) {
const { node, timestamp, inputs, path } = data;

@@ -89,3 +90,3 @@ const entry = this.#pathRegistry.create(path);

}
const event = new RunNodeEvent(entry, node.id, timestamp, inputs);
const event = new RunNodeEvent(entry, node.id, timestamp, inputs, result);
event.hidden = shouldSkipEvent(this.#options, node, entry.path.length === 1);

@@ -198,3 +199,3 @@ entry.event = event;

case "nodestart":
return this.#addNodestart(result.data);
return this.#addNodestart(result.data, result.result);
case "input":

@@ -227,2 +228,5 @@ return this.#addInput(result.data);

}
async *replay() {
yield* eventsAsHarnessRunResults(this.#sequence);
}
getEventById(id) {

@@ -236,3 +240,39 @@ const entryId = entryIdFromEventId(id);

}
async reanimationStateAt(id, nodeConfig) {
const manager = new LifecycleManager();
for (const [index, entry] of this.#sequence.entries()) {
const [type, data] = entry;
switch (type) {
case "graphstart": {
// TODO: Figure out if I need to do anything about the URL here.
manager.dispatchGraphStart("", data.path);
break;
}
case "nodestart": {
const event = data.event;
const traversalResult = event.traversalResult;
if (!traversalResult) {
console.warn(`No traversal result for ${data.event?.id}`);
}
else {
manager.dispatchNodeStart(traversalResult, data.path);
}
if (event.id === id) {
const reanimationState = manager.reanimationState();
reanimationState.history = this.#sequence.slice(0, index + 1);
reanimationState.nodeConfig = nodeConfig;
return reanimationState;
}
break;
}
case "nodeend": {
// const event = data.event as RunNodeEvent;
// manager.dispatchNodeEnd(event.outputs!, data.path);
break;
}
}
}
throw new Error(`The event identifier "${id}" was not found in event sequence`);
}
}
//# sourceMappingURL=event-manager.js.map

@@ -7,3 +7,3 @@ /**

import { HarnessRunResult } from "../../harness/types.js";
import { GraphstartTimelineEntry, InspectableRunLoadResult, NodestartTimelineEntry, SerializedRunLoadingOptions } from "../types.js";
import { InspectableRunLoadResult, SerializedRunLoadingOptions } from "../types.js";
import { DataStore } from "../../data/types.js";

@@ -14,7 +14,4 @@ export declare const errorResult: (error: string) => HarnessRunResult;

constructor(store: DataStore, o: unknown, options: SerializedRunLoadingOptions);
loadGraphStart(result: GraphstartTimelineEntry): HarnessRunResult;
loadNodestart(result: NodestartTimelineEntry): HarnessRunResult;
replay(): AsyncGenerator<HarnessRunResult, void, unknown>;
load(): Promise<InspectableRunLoadResult>;
}
//# sourceMappingURL=loader.d.ts.map

@@ -7,5 +7,3 @@ /**

import { replaceSecrets } from "./serializer.js";
import { inspectableGraph } from "../graph.js";
import { remapData } from "../../data/inflate-deflate.js";
import { asyncGen } from "../../utils/async-gen.js";
import { PastRun } from "./past-run.js";

@@ -27,3 +25,2 @@ export const errorResult = (error) => {

#store;
#graphs = new Map();
#options;

@@ -35,6 +32,2 @@ constructor(store, o, options) {

}
#asHarnessRunResult(entry) {
const [type, data] = entry;
return { type, data };
}
async #inflateData(timeline, serializedData) {

@@ -47,67 +40,2 @@ return await Promise.all(timeline.map(async (entry) => {

}
loadGraphStart(result) {
const [, data] = result;
const { index, timestamp, path } = data;
let { graph } = data;
if (graph !== null) {
this.#graphs.set(index, inspectableGraph(graph, this.#options ?? {}));
}
else {
graph = this.#graphs.get(index)?.raw() || null;
}
return {
type: "graphstart",
data: { timestamp, path, graph },
};
}
loadNodestart(result) {
const [, data] = result;
const { graph: graphIndex, id: node, timestamp, inputs, path } = data;
const graph = this.#graphs.get(graphIndex);
if (!graph) {
throw new Error(`Unknown graph index ${graphIndex} while loading nodestart`);
}
const descriptor = graph.nodeById(node);
if (!descriptor) {
throw new Error(`Unknown node id ${node} while loading nodestart`);
}
return {
type: "nodestart",
data: { timestamp, path, inputs, node: descriptor.descriptor },
};
}
async *replay() {
const run = this.#run;
if (run.$schema !== "tbd") {
yield errorResult(`Specified "$schema": "${run.$schema}" is not valid`);
}
yield* asyncGen(async (next) => {
try {
const secretReplacer = this.#options?.secretReplacer;
let timeline = secretReplacer
? replaceSecrets(run, secretReplacer).timeline
: run.timeline;
timeline = run.data
? await this.#inflateData(timeline, run.data)
: timeline;
for (const result of timeline) {
const [type] = result;
switch (type) {
case "graphstart":
await next(this.loadGraphStart(result));
continue;
case "nodestart":
await next(this.loadNodestart(result));
continue;
default:
await next(this.#asHarnessRunResult(result));
}
}
}
catch (e) {
const error = e;
next(errorResult(`Loading run failed with the error ${error.message}`));
}
});
}
async load() {

@@ -114,0 +42,0 @@ const run = this.#run;

@@ -6,3 +6,3 @@ /**

*/
import { entryIdFromEventId, pathFromId } from "./conversions.js";
import { entryIdFromEventId, eventsAsHarnessRunResults, pathFromId, } from "./conversions.js";
/**

@@ -56,121 +56,5 @@ * Meant to be a very lightweight wrapper around the

const timeline = sequence.slice(start);
const first = timeline[0];
let endPath = [];
if (first[0] !== "graphstart") {
throw new Error("Expected a graphstart event at the beginning of the timeline");
}
else {
endPath = first[1].path;
}
for await (const result of timeline) {
const [type, data] = result;
switch (type) {
case "graphstart": {
const { graphStart, path, graph: inspectableGraph, edges } = data;
const graph = inspectableGraph?.raw();
yield {
type,
data: { timestamp: graphStart, path: trimPath(path), graph, edges },
async reply() { },
};
break;
}
case "nodestart": {
const { path } = data;
const { node, inputs, start: timestamp, } = data.event;
yield {
type,
data: {
node: node.descriptor,
inputs,
path: trimPath(path),
timestamp,
},
async reply() { },
};
break;
}
case "nodeend": {
const { path } = data;
const { node, inputs, outputs, end: timestamp, } = data.event;
yield {
type,
data: {
node: node.descriptor,
inputs,
outputs: outputs || {},
path: trimPath(path),
timestamp: timestamp || 0,
},
async reply() { },
};
break;
}
case "graphend": {
const { path } = data;
const { graphEnd: timestamp } = data;
yield {
type,
data: { path: trimPath(path), timestamp: timestamp || 0 },
async reply() { },
};
if (path.join(".") === endPath.join(".")) {
return;
}
break;
}
case "error": {
const { graphStart: timestamp } = data;
yield {
type,
data: { error: "TODO: Store actual error object", timestamp },
async reply() { },
};
break;
}
case "input": {
const { path } = data;
const { node, inputs: inputArguments, bubbled, start: timestamp, } = data.event;
yield {
type,
data: {
node: node.descriptor,
inputArguments,
bubbled,
path: trimPath(path),
timestamp,
},
async reply() { },
};
break;
}
case "output": {
const { path } = data;
const { node, outputs, bubbled, start: timestamp, } = data.event;
yield {
type,
data: {
node: node.descriptor,
outputs: outputs || {},
bubbled,
path: trimPath(path),
timestamp,
},
async reply() { },
};
break;
}
case "secret": {
break;
}
default: {
throw new Error("Unknown event type: " + type);
}
}
}
function trimPath(path) {
return path.slice(endPath.length);
}
yield* eventsAsHarnessRunResults(timeline);
}
}
//# sourceMappingURL=nested-run.js.map

@@ -7,3 +7,3 @@ /**

import type { HarnessRunResult } from "../../harness/types.js";
import type { InputValues, NodeIdentifier, OutputValues } from "../../types.js";
import type { InputValues, NodeIdentifier, OutputValues, TraversalResult } from "../../types.js";
import type { EventIdentifier, InspectableGraph, InspectableNode, InspectableRun, InspectableRunNodeEvent, PathRegistryEntry } from "../types.js";

@@ -20,3 +20,7 @@ export declare class RunNodeEvent implements InspectableRunNodeEvent {

hidden: boolean;
constructor(entry: PathRegistryEntry, id: NodeIdentifier, start: number, inputs: InputValues);
/**
* The TraversalResult associated with with this event
*/
traversalResult?: TraversalResult;
constructor(entry: PathRegistryEntry, id: NodeIdentifier, start: number, inputs: InputValues, traversalResult?: TraversalResult);
get id(): EventIdentifier;

@@ -23,0 +27,0 @@ get graph(): InspectableGraph;

@@ -30,3 +30,7 @@ /**

#node = null;
constructor(entry, id, start, inputs) {
/**
* The TraversalResult associated with with this event
*/
traversalResult;
constructor(entry, id, start, inputs, traversalResult) {
if (!entry.parent) {

@@ -48,2 +52,3 @@ throw new Error(`RunNodeEvent has no parent entry. This is a bug in Inspector API machinery. Node Id: ${id}`);

this.hidden = false;
this.traversalResult = traversalResult;
}

@@ -50,0 +55,0 @@ get id() {

@@ -7,4 +7,4 @@ /**

import { HarnessRunResult } from "../../harness/types.js";
import { GraphDescriptor } from "../../types.js";
import { EventIdentifier, GraphUUID, GraphDescriptorStore, InspectableRun, InspectableRunEvent, InspectableRunLoadResult, InspectableRunObserver, RunObserverOptions, RunSerializationOptions, SerializedRun, SerializedRunLoadingOptions, InspectableRunNodeEvent, InspectableRunInputs, InspectableRunEdge } from "../types.js";
import { GraphDescriptor, NodeConfiguration, NodeIdentifier } from "../../types.js";
import { EventIdentifier, GraphUUID, GraphDescriptorStore, InspectableRun, InspectableRunEvent, InspectableRunLoadResult, InspectableRunObserver, RunObserverOptions, RunSerializationOptions, SerializedRun, SerializedRunLoadingOptions, InspectableRunNodeEvent, InspectableRunInputs, InspectableRunEdge, InspectableRunSequenceEntry } from "../types.js";
export declare class RunObserver implements InspectableRunObserver {

@@ -16,2 +16,4 @@ #private;

load(o: unknown, options?: SerializedRunLoadingOptions): Promise<InspectableRunLoadResult>;
append(history: InspectableRunSequenceEntry[]): Promise<void>;
replay(stopAt: NodeIdentifier[]): Promise<void>;
}

@@ -35,3 +37,4 @@ export declare class Run implements InspectableRun {

replay(): AsyncGenerator<HarnessRunResult>;
reanimationStateAt(id: EventIdentifier, nodeConfig: NodeConfiguration): Promise<import("../../index.js").ReanimationState>;
}
//# sourceMappingURL=run.d.ts.map

@@ -8,2 +8,3 @@ /**

import { RunLoader } from "./loader.js";
import { eventsAsHarnessRunResults } from "./conversions.js";
const isInput = (event) => {

@@ -42,7 +43,9 @@ return (event.type === "node" &&

run.dataStoreKey = `${url}-${timestamp}`;
if (!this.#options.skipDataStore) {
// Ensure that we release old blobs if we've encountered this
// run before.
this.#options.dataStore?.releaseGroup(run.dataStoreKey);
this.#options.dataStore?.createGroup(run.dataStoreKey);
const { dataStore, skipDataStore } = this.#options;
if (!skipDataStore && dataStore) {
// If a group with this key already exists, let's just
// keep adding to it. Otherwise, let create a new one.
if (!dataStore.has(run.dataStoreKey)) {
this.#options.dataStore?.createGroup(run.dataStoreKey);
}
}

@@ -149,2 +152,21 @@ }

}
async append(history) {
for await (const result of eventsAsHarnessRunResults(history)) {
await this.observe(result);
}
}
async replay(stopAt) {
const lastRun = this.#runs.at(0);
if (!lastRun)
return;
for await (const result of lastRun.replay()) {
await this.observe(result);
const { type, data } = result;
if (type === "nodestart" &&
data.path.length === 1 &&
stopAt.includes(data.node.id)) {
break;
}
}
}
}

@@ -219,6 +241,9 @@ export class Run {

}
replay() {
throw new Error("Runs can't yet be replayed.");
async *replay() {
yield* this.#events.replay();
}
async reanimationStateAt(id, nodeConfig) {
return this.#events.reanimationStateAt(id, nodeConfig);
}
}
//# sourceMappingURL=run.js.map

@@ -130,3 +130,7 @@ /**

outputs: event.outputs,
node: { type: event.node.descriptor.type },
node: {
type: event.node.descriptor.type,
id: event.node.descriptor.id,
},
newOpportunities: event.traversalResult?.newOpportunities || [],
},

@@ -133,0 +137,0 @@ ];

@@ -6,8 +6,9 @@ /**

*/
import { GraphIdentifier, GraphMetadata, NodeMetadata, StartLabel } from "@breadboard-ai/types";
import { GraphIdentifier, GraphMetadata, Module, ModuleCode, ModuleIdentifier, ModuleMetadata, NodeMetadata, StartLabel } from "@breadboard-ai/types";
import { HarnessRunResult, SecretResult } from "../harness/types.js";
import { GraphLoader } from "../loader/types.js";
import { BehaviorSchema, Edge, EdgeResponse, ErrorResponse, GraphDescriptor, InputValues, Kit, KitDescriptor, NodeConfiguration, NodeDescriberResult, NodeDescriptor, NodeHandlerMetadata, NodeIdentifier, NodeTypeIdentifier, NodeValue, OutputValues, Schema } from "../types.js";
import { BehaviorSchema, Edge, ErrorResponse, GraphDescriptor, InputValues, Kit, KitDescriptor, NodeConfiguration, NodeDescriberResult, NodeDescriptor, NodeHandlerMetadata, NodeIdentifier, NodeTypeIdentifier, NodeValue, OutputValues, Schema, TraversalResult } from "../types.js";
import { DataStore, RunStore, SerializedDataStoreGroup } from "../data/types.js";
import { SequenceEntry } from "./run/serializer.js";
import { ReanimationState } from "../run/types.js";
export type GraphVersion = number;

@@ -251,2 +252,10 @@ export type GraphURL = string;

graphs(): InspectableSubgraphs;
/**
* Returns a module by name.
*/
moduleById(id: ModuleIdentifier): InspectableModule | undefined;
/**
* Returns the modules that are embedded in this graph.
*/
modules(): InspectableModules;
};

@@ -464,2 +473,13 @@ /**

};
export type InspectableModule = {
/**
* Returns the metadata, associated with this node type.
*/
metadata(): ModuleMetadata;
/**
*
*/
code(): ModuleCode;
};
export type InspectableModules = Record<ModuleIdentifier, InspectableModule>;
/**

@@ -500,2 +520,8 @@ * Represents a simple listener for edits to the graph.

};
export type InspectableModuleCache = {
get(id: string): InspectableModule | undefined;
add(id: string, module: Module): void;
remove(id: ModuleIdentifier): void;
modules(): InspectableModules;
};
/**

@@ -508,2 +534,3 @@ * A backing store for `InspectableGraph` instances, representing a stable

edges: InspectableEdgeCache;
modules: InspectableModuleCache;
};

@@ -591,2 +618,14 @@ /**

load(o: unknown, options?: SerializedRunLoadingOptions): Promise<InspectableRunLoadResult>;
/**
* Appends previously observed events to runs and creates
* new runs if needed.
* @param history -- inspectable run events to append
*/
append(history: InspectableRunSequenceEntry[]): Promise<void>;
/**
* Replays the current run as a new run, stopping at the first encountered in
* a given list of nodes.
* If no run exists, does nothing.
*/
replay(stopAt: NodeIdentifier[]): Promise<void>;
};

@@ -695,2 +734,6 @@ /**

runs: InspectableRun[];
/**
* The TraversalResult associated with with this event
*/
traversalResult?: TraversalResult;
};

@@ -761,3 +804,6 @@ /**

export type InspectableRunEvent = InspectableRunNodeEvent | InspectableRunSecretEvent | InspectableRunErrorEvent | InspectableRunEdgeEvent;
export type InspectableRunEdge = EdgeResponse;
export type InspectableRunEdge = {
edge: Edge;
value: NodeValue;
};
/**

@@ -830,2 +876,9 @@ * Represents a single run of a graph.

replay(): AsyncGenerator<HarnessRunResult>;
/**
* Return the ReanimationState at a given event Id. Useful for starting
* a run from a given point in the run.
* Optional, since not all InspectableRun implemenations can offer this
* capability.
*/
reanimationStateAt?(id: EventIdentifier, nodeConfig: NodeConfiguration | undefined): Promise<ReanimationState>;
};

@@ -844,5 +897,6 @@ /**

export type SequenceView = {
sequence: SequenceEntry[];
sequence: InspectableRunSequenceEntry[];
start: number;
};
export type InspectableRunSequenceEntry = SequenceEntry;
export type PathRegistryEntry = {

@@ -849,0 +903,0 @@ path: number[];

@@ -96,3 +96,6 @@ /**

// Assume that this is a URL to a JS file.
const module = await import(/* @vite-ignore */ url.href);
const module = await import(
/* @vite-ignore */
/* webpackIgnore: true */
url.href);
if (module.default == undefined) {

@@ -99,0 +102,0 @@ throw new Error(`Module ${url} does not have a default export.`);

@@ -7,11 +7,20 @@ /**

import { GraphDescriptor } from "@breadboard-ai/types";
import { GraphProvider, GraphProviderCapabilities, GraphProviderExtendedCapabilities, GraphProviderStore } from "./types.js";
import { BoardServer, BoardServerCapabilities, BoardServerProject, GraphProviderCapabilities, GraphProviderExtendedCapabilities, GraphProviderStore, Permission, User } from "./types.js";
export declare const loadFromFile: (path: string) => Promise<any>;
export declare const loadWithFetch: (url: string | URL) => Promise<any>;
export declare class DefaultGraphProvider implements GraphProvider {
export declare class DefaultBoardServer implements BoardServer {
#private;
url: URL;
projects: Promise<BoardServerProject[]>;
kits: never[];
secrets: Map<any, any>;
extensions: never[];
capabilities: BoardServerCapabilities;
name: string;
user: User;
users: User[];
ready(): Promise<void>;
isSupported(): boolean;
extendedCapabilities(): GraphProviderExtendedCapabilities;
getAccess(_url: URL, _user: User): Promise<Permission>;
canProvide(url: URL): false | GraphProviderCapabilities;

@@ -18,0 +27,0 @@ load(url: URL): Promise<GraphDescriptor | null>;

@@ -20,3 +20,6 @@ /**

else {
const { readFile } = await import(/* vite-ignore */ "node:fs/promises");
const { readFile } = await import(
/* vite-ignore */
/* webpackIgnore: true */
"node:fs/promises");
readFileFn = readFile;

@@ -41,4 +44,20 @@ }

};
export class DefaultGraphProvider {
name = "DefaultGraphProvider";
export class DefaultBoardServer {
url = new URL(typeof window !== "undefined"
? window.location.href
: "https://breadboard-ai.github.io/");
projects = Promise.resolve([]);
kits = [];
secrets = new Map();
extensions = [];
capabilities = {
connect: false,
disconnect: false,
preview: false,
watch: false,
refresh: false,
};
name = "DefaultBoardServer";
user = { username: "board-builder", apiKey: "", secrets: new Map() };
users = [this.user];
#ready = Promise.resolve();

@@ -54,9 +73,8 @@ ready() {

modify: false,
connect: false,
disconnect: false,
refresh: false,
watch: false,
preview: false,
...this.capabilities,
};
}
getAccess(_url, _user) {
throw new Error("Method not implemented.");
}
canProvide(url) {

@@ -63,0 +81,0 @@ if (url.protocol === "http:" || url.protocol === "https:") {

@@ -6,4 +6,4 @@ /**

*/
import { GraphLoader, GraphProvider } from "./types.js";
export declare const createLoader: (graphProviders?: GraphProvider[], opts?: {
import { GraphLoader, BoardServer } from "./types.js";
export declare const createLoader: (boardServers?: BoardServer[], opts?: {
disableDefaultProvider?: boolean;

@@ -10,0 +10,0 @@ }) => GraphLoader;

@@ -7,11 +7,11 @@ /**

import { Loader } from "./loader.js";
import { DefaultGraphProvider } from "./default.js";
export const createLoader = (graphProviders, opts) => {
const providers = [...(graphProviders ?? [])];
import { DefaultBoardServer } from "./default.js";
export const createLoader = (boardServers, opts) => {
const servers = [...(boardServers ?? [])];
if (!opts?.disableDefaultProvider) {
providers.push(new DefaultGraphProvider());
servers.push(new DefaultBoardServer());
}
return new Loader(providers);
return new Loader(servers);
};
export { SENTINEL_BASE_URL } from "./loader.js";
//# sourceMappingURL=index.js.map

@@ -135,2 +135,3 @@ /**

error?: string;
url?: string;
}>;

@@ -137,0 +138,0 @@ /**

@@ -32,3 +32,3 @@ /**

if (type == "nodestart") {
response.push(message.state);
response.push(message.result);
}

@@ -35,0 +35,0 @@ await responses.write(response);

@@ -11,4 +11,4 @@ /**

*/
export declare const atob: (str: string) => string;
export declare const btoa: (str: string) => string;
export declare const atob: typeof globalThis.atob;
export declare const btoa: typeof globalThis.btoa;
/**

@@ -15,0 +15,0 @@ * All tunnels defined for a particular node (the tunnel entry).

@@ -11,3 +11,3 @@ /**

import { PatchedReadableStream } from "../stream.js";
import { EdgeProbeMessage, ErrorResponse, GraphDescriptor, GraphEndProbeMessage, GraphStartProbeMessage, InputResponse, InputValues, Kit, NodeDescriptor, NodeEndProbeMessage, NodeStartProbeMessage, OutputResponse, OutputValues, SkipProbeMessage } from "../types.js";
import { EdgeProbeMessage, ErrorResponse, GraphDescriptor, GraphEndProbeMessage, GraphStartProbeMessage, InputResponse, InputValues, Kit, NodeDescriptor, NodeEndProbeMessage, NodeStartProbeMessage, OutputResponse, OutputValues, SkipProbeMessage, TraversalResult } from "../types.js";
/**

@@ -160,3 +160,2 @@ * Sent by the client to request loading a board. This is an optional request

};
export type RunStateFunction = () => Promise<RunState>;
type ClientRunResultFromMessage<ResponseMessage> = ResponseMessage extends [

@@ -169,3 +168,3 @@ string,

data: ResponseMessage[1];
saveState?: RunStateFunction;
result?: TraversalResult;
} & ReplyFunction : never;

@@ -172,0 +171,0 @@ export type AnyClientRunResult = ClientRunResultFromMessage<RemoteMessage>;

@@ -38,2 +38,3 @@ /**

timestamp: timestamp(),
newOpportunities: result.state.newOpportunities,
},

@@ -40,0 +41,0 @@ });

@@ -30,2 +30,5 @@ /**

this.#inputs = undefined;
if (this.#resumeFrom.nodeConfig) {
result.inputs = { ...result.inputs, ...this.#resumeFrom.nodeConfig };
}
const replayOutputs = entry.outputs ? [entry.outputs] : [];

@@ -32,0 +35,0 @@ // Always return the new instance:

@@ -13,2 +13,3 @@ /**

import { NodeInvoker } from "./node-invoker.js";
import { cloneState } from "../serialization.js";
/**

@@ -21,3 +22,3 @@ * Runs a graph in "run" mode. See

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { inputs, start, ...context } = args;
const { inputs, start, stopAfter, ...context } = args;
const { probe, state, invocationPath = [] } = context;

@@ -29,2 +30,3 @@ const lifecycle = state?.lifecycle();

let invocationId = 0;
let prepareToStopAtStartNode = false;
const reanimation = state?.reanimation();

@@ -52,3 +54,28 @@ if (reanimation) {

const type = result.descriptor.type;
if (!(type === "input" || type === "output")) {
const descriptor = result.descriptor;
const outputHasValues = Object.keys(result.outputs || {}).length > 0;
if (type === "input") {
if (outputHasValues) {
outputs = result.outputs;
}
else {
await next(new InputStageResult(result, lifecycle?.state(), invocationId, invocationPath));
await bubbleUpInputsIfNeeded(graph, context, descriptor, result, invocationPath, lifecycle?.state());
outputs = result.outputs
? await resolveBoardCapabilities(result.outputs, context, graph.url)
: undefined;
}
}
else if (descriptor.type === "output") {
if (outputHasValues) {
outputs = result.outputs;
}
else {
if (!(await bubbleUpOutputsIfNeeded(result.inputs, descriptor, context, invocationPath))) {
await next(new OutputStageResult(result, invocationId, invocationPath));
}
outputs = result.outputs;
}
}
else {
outputs = await nodeInvoker.invokeNode(result, invocationPath);

@@ -58,5 +85,2 @@ result.outputs = outputs;

}
else {
outputs = result.outputs;
}
lifecycle?.dispatchNodeEnd(outputs, invocationPath);

@@ -71,4 +95,8 @@ await probe?.report?.({

timestamp: timestamp(),
newOpportunities: structuredClone(result.newOpportunities),
},
});
if (stopAfter === result.descriptor.id) {
prepareToStopAtStartNode = true;
}
}

@@ -123,4 +151,7 @@ }

},
state: lifecycle?.state(),
result: cloneState(result),
});
if (prepareToStopAtStartNode) {
return;
}
let outputs = undefined;

@@ -152,5 +183,9 @@ if (descriptor.type === "input") {

timestamp: timestamp(),
newOpportunities: result.newOpportunities,
},
});
result.outputs = outputs;
if (stopAfter == descriptor.id) {
prepareToStopAtStartNode = true;
}
}

@@ -157,0 +192,0 @@ lifecycle?.dispatchGraphEnd();

@@ -6,3 +6,4 @@ /**

*/
import type { Edge, NodeIdentifier, OutputValues, TraversalResult } from "../types.js";
import { InspectableRunSequenceEntry } from "../inspector/types.js";
import type { Edge, NodeConfiguration, NodeIdentifier, OutputValues, TraversalResult } from "../types.js";
/**

@@ -79,2 +80,11 @@ * Sequential number of the invocation of a node.

visits?: ReanimationStateVisits;
/**
* A run that consists of the events that preceded the point at which
* the reanimation state was captured.
*/
history?: InspectableRunSequenceEntry[];
/**
* Node configuration that overrides what's in the current state
*/
nodeConfig?: NodeConfiguration;
};

@@ -81,0 +91,0 @@ export type ReanimationMode =

@@ -21,2 +21,3 @@ /**

};
export declare const cloneState: (result: TraversalResult) => TraversalResult;
//# sourceMappingURL=serialization.d.ts.map

@@ -7,2 +7,3 @@ /**

import { MachineResult } from "./traversal/result.js";
import { MachineEdgeState } from "./traversal/state.js";
export const replacer = (key, value) => {

@@ -28,2 +29,11 @@ if (!(value instanceof Map))

};
export const cloneState = (result) => {
const { descriptor, inputs, missingInputs, current, opportunities, newOpportunities, state, outputs, partialOutputs, } = result;
const clonedValueState = new MachineEdgeState();
clonedValueState.constants = structuredClone(state.constants);
clonedValueState.state = structuredClone(state.state);
const clone = new MachineResult(descriptor, inputs, [...missingInputs], current, [...opportunities], [...newOpportunities], clonedValueState, partialOutputs);
clone.outputs = outputs;
return clone;
};
//# sourceMappingURL=serialization.js.map

@@ -85,3 +85,7 @@ /**

*/
| "google-drive-file-id";
| "google-drive-file-id"
/**
* Indicates that the string is a Module.
*/
| "module";
export type Schema = {

@@ -388,3 +392,6 @@ title?: string;

timestamp: number;
edges?: EdgeResponse[];
edges?: {
edge: Edge;
value: NodeValue;
}[];
};

@@ -416,3 +423,3 @@ export type GraphStartProbeMessage = {

data: NodeStartResponse;
state?: RunState;
result?: TraversalResult;
};

@@ -469,2 +476,3 @@ export type NodeEndProbeMessage = {

timestamp: number;
newOpportunities: Edge[];
};

@@ -621,2 +629,8 @@ export type EdgeResponse = {

start?: StartLabel;
/**
* The id of the node to stop the run after. In combination with `state`, can
* be used to run parts of the board.
* If not specified, runs the whole board.
*/
stopAfter?: NodeIdentifier;
};

@@ -623,0 +637,0 @@ export interface BreadboardNode<Inputs, Outputs> {

@@ -6,3 +6,3 @@ {

},
"version": "0.28.0",
"version": "0.29.0",
"description": "A library for rapid generative AI application prototyping",

@@ -164,3 +164,3 @@ "main": "./dist/src/index.js",

"@ava/typescript": "^4.0.0",
"@definitelytyped/dtslint": "^0.2.23",
"@definitelytyped/dtslint": "^0.2.25",
"@google-labs/tsconfig": "^0.0.1",

@@ -174,3 +174,3 @@ "@rollup/plugin-node-resolve": "^15.3.0",

"jsonschema": "^1.4.1",
"rollup": "^4.24.0",
"rollup": "^4.24.3",
"rollup-plugin-dts": "^6.1.1",

@@ -184,6 +184,6 @@ "@rollup/plugin-json": "^6.1.0",

"dependencies": {
"@breadboard-ai/types": "0.1.2",
"@google-labs/breadboard-schema": "^1.8.1",
"@breadboard-ai/types": "0.2.0",
"@google-labs/breadboard-schema": "^1.9.0",
"json-schema": "^0.4.0"
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc