New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@google-labs/breadboard

Package Overview
Dependencies
Maintainers
1
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.22.0 to 0.23.0

dist/src/data/default-store.d.ts

26

dist/harness.min.js

@@ -56,3 +56,3 @@ /**

* SPDX-License-Identifier: Apache-2.0
*/const v=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},k=async(t,e,r,s,n)=>{if(!e.requestInput)return;const o=await s.outputsPromise??{},i=new S(o,s.inputs,n);s.outputsPromise=i.read($(t,e,r))},$=(t,e,r)=>async(s,n,o,i)=>{if(o)throw new Error(v(s,t,o));if(void 0!==n.default)return"type"in n&&"string"!==n.type?JSON.parse(n.default):n.default;const a=await(e.requestInput?.(s,n,r,i));if(void 0===a)throw new Error(v(s,t,o));return a};class S{#d;#p;#u;constructor(t,e,r){this.#d=t,this.#p=e,this.#u=r}async read(t){if(!("schema"in this.#p))return this.#d;const e=this.#p.schema;if(!e.properties)return this.#d;const r=Object.entries(e.properties),s={};for(const[n,o]of r){if(n in this.#d){s[n]=this.#d[n];continue}const r=e.required?.includes(n)??!1,i=await t(n,o,r,this.#u);s[n]=i}return{...this.#d,...s}}}class E{#h;#l=new Map;constructor(t){const{inputs:e,...r}=t;this.#h=r,this.#l=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,o)=>{const i=this.#l.get(r);if(void 0!==i)return i;const a={id:n.id,type:n.type},c={...e,descriptor:a,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new p(c,void 0,-1,o));const u=await c.outputsPromise;let d=u&&u[r];return void 0===d&&(d=await(this.#h.requestInput?.(r,s,a,o))),P(s)||this.#l.set(r,d),d}}}const P=t=>t.behavior?.includes("transient")??!1,O=async(t,e,r,s)=>{if(!r.provideOutput)return!1;const n=e.configuration?.schema,o=n?.behavior?.includes("bubble");return!!o&&(await r.provideOutput(t,e,s),!0)},x=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const o={...e,descriptor:s,inputs:r};await t(new h(o,-1,n))},j=()=>{};class R{#f=[];#w=j;#m;#y;abort=j;constructor(){this.#g()}#g(){this.#m=new Promise(((t,e)=>{this.#w=t,this.abort=e}))}#b(t){this.#f.push(t),1==this.#f.length&&(this.#w(),this.#g())}async write(t){return new Promise((e=>{this.#b({value:t,receipt:e})}))}async read(){this.#y&&this.#y(),0===this.#f.length&&await this.#m;const t=this.#f.shift();if(!t)throw new Error("asyncGen queue should never be empty.");return this.#y=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#b({value:void 0,receipt:j})}}class I{#v;#k=!0;#f=new R;constructor(t){this.#v=t}async#$(t){return this.#f.write(t)}async next(){return this.#k&&(this.#k=!1,this.#v(this.#$.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}}const N=t=>({[Symbol.asyncIterator]:()=>new I(t)});
*/const v=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},k=async(t,e,r,s,n)=>{if(!e.requestInput)return;const o=await s.outputsPromise??{},i=new S(o,s.inputs,n);s.outputsPromise=i.read($(t,e,r))},$=(t,e,r)=>async(s,n,o,i)=>{if(o)throw new Error(v(s,t,o));if(void 0!==n.default)return"type"in n&&"string"!==n.type?JSON.parse(n.default):n.default;const a=await(e.requestInput?.(s,n,r,i));if(void 0===a)throw new Error(v(s,t,o));return a};class S{#d;#p;#u;constructor(t,e,r){this.#d=t,this.#p=e,this.#u=r}async read(t){if(!("schema"in this.#p))return this.#d;const e=this.#p.schema;if(!e.properties)return this.#d;const r=Object.entries(e.properties),s={};for(const[n,o]of r){if(n in this.#d){s[n]=this.#d[n];continue}const r=e.required?.includes(n)??!1,i=await t(n,o,r,this.#u);s[n]=i}return{...this.#d,...s}}}class E{#h;#l=new Map;constructor(t){const{inputs:e,...r}=t;this.#h=r,this.#l=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,o)=>{const i=this.#l.get(r);if(void 0!==i)return i;const a={id:n.id,type:n.type},c={...e,descriptor:a,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new p(c,void 0,-1,o));const u=await c.outputsPromise;let d=u&&u[r];return void 0===d&&(d=await(this.#h.requestInput?.(r,s,a,o))),P(s)||this.#l.set(r,d),d}}}const P=t=>t.behavior?.includes("transient")??!1,O=async(t,e,r,s)=>{if(!r.provideOutput)return!1;const n=e.configuration?.schema,o=n?.behavior?.includes("bubble");return!!o&&(await r.provideOutput(t,e,s),!0)},x=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const o={...e,descriptor:s,inputs:r};await t(new h(o,-1,n))},j=()=>{};class R{#f=[];#w=j;#m;#y;abort=j;constructor(){this.#g()}#g(){this.#m=new Promise(((t,e)=>{this.#w=t,this.abort=e}))}#b(t){this.#f.push(t),1==this.#f.length&&(this.#w(),this.#g())}async write(t){return new Promise((e=>{this.#b({value:t,receipt:e})}))}async read(){this.#y&&this.#y(),0===this.#f.length&&await this.#m;const t=this.#f.shift();if(!t)throw new Error("asyncGen queue should never be empty.");return this.#y=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#b({value:void 0,receipt:j})}}class N{#v;#k=!0;#f=new R;constructor(t){this.#v=t}async#$(t){return this.#f.write(t)}async next(){return this.#k&&(this.#k=!1,this.#v(this.#$.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}}const I=t=>({[Symbol.asyncIterator]:()=>new N(t)});
/**

@@ -62,3 +62,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class C{#S;#E;constructor(t){this.#S=structuredClone(t)||[]}onGraphStart(){this.#S.push({graph:0,node:0})}onNodeStart(t){this.#S[this.#S.length-1].node++,this.#E=t}onNodeEnd(){}onGraphEnd(){}async state(){const t=structuredClone(this.#S);return this.#E&&(t[t.length-1].state=await c("nodestart",this.#E)),t}}var q="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.5.1/packages/schema/breadboard.schema.json";class A{name="DefaultGraphProvider";#P=Promise.resolve();ready(){return this.#P}isSupported(){return!0}extendedCapabilities(){return{modify:!1,connect:!1,disconnect:!1,refresh:!1,watch:!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?(async t=>{const e=await fetch(t);return await e.json()})(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 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")}}
*/class C{#S;#E;constructor(t){this.#S=structuredClone(t)||[]}onGraphStart(){this.#S.push({graph:0,node:0})}onNodeStart(t){this.#S[this.#S.length-1].node++,this.#E=t}onNodeEnd(){}onGraphEnd(){}async state(){const t=structuredClone(this.#S);return this.#E&&(t[t.length-1].state=await c("nodestart",this.#E)),t}}var A="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.6.0/packages/schema/breadboard.schema.json";class q{name="DefaultGraphProvider";#P=Promise.resolve();ready(){return this.#P}isSupported(){return!0}extendedCapabilities(){return{modify:!1,connect:!1,disconnect:!1,refresh:!1,watch:!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?(async t=>{const e=await fetch(t);return await e.json()})(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 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")}}
/**

@@ -68,3 +68,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const T=new URL("sentinel://sentinel/sentinel"),M=t=>{const e=new URL(t.href);return e.hash="",e},D=t=>{if(t.outerGraph?.url)return new URL(t.outerGraph.url);const e=t.board?.url;return e?new URL(e):t.base?t.base:T};class U{#O;constructor(t){this.#O=[...t,new A]}async#x(t){for(const e of this.#O){const r=e.canProvide(t);if(!1!==r&&r.load){const r=await e.load(t);if(null!==r)return r.nodes?.map((t=>{"superWorker"===t.type&&(console.warn("superWorker encountered, converting to specialist"),t.type="specialist")})),r.url=t.href,r}}return console.warn(`Unable to load graph from "${t.href}"`),null}async#j(t){const e=await this.#x(t);return e||null}#R(t,e,r){if(!r)return console.warn(`No subgraphs to load "#${e}" from`),null;const s=r[e];return s?(t&&(s.url=t.href),s):(console.warn(`No subgraph found for hash: #${e}`),null)}async load(t,e){const r=e.outerGraph;if(t.startsWith("#")&&r&&!r.url){const e=this.#R(null,t.substring(1),r.graphs);return e||console.warn(`Unable to load graph from "${t}"`),e}const s=D(e),n=new URL(t,s);if(!n.hash)return await this.#j(n);if(r){const t=r.url?new URL(r.url):T;if(o=t,M(n).href===M(o).href){const t=n.hash.substring(1);return this.#R(n,t,r.graphs)}}var o;const i=await this.#j(M(n));return i?this.#R(n,n.hash.substring(1),i.graphs):null}}
*/const T=new URL("sentinel://sentinel/sentinel"),M=t=>{const e=new URL(t.href);return e.hash="",e},D=t=>{if(t.outerGraph?.url)return new URL(t.outerGraph.url);const e=t.board?.url;return e?new URL(e):t.base?t.base:T};class U{#O;constructor(t){this.#O=[...t,new q]}async#x(t){for(const e of this.#O){const r=e.canProvide(t);if(!1!==r&&r.load){const r=await e.load(t);if(null!==r)return r.nodes?.map((t=>{"superWorker"===t.type&&(console.warn("superWorker encountered, converting to specialist"),t.type="specialist")})),r.url=t.href,r}}return console.warn(`Unable to load graph from "${t.href}"`),null}async#j(t){const e=await this.#x(t);return e||null}#R(t,e,r){if(!r)return console.warn(`No subgraphs to load "#${e}" from`),null;const s=r[e];return s?(t&&(s.url=t.href),s):(console.warn(`No subgraph found for hash: #${e}`),null)}async load(t,e){const r=e.outerGraph;if(t.startsWith("#")&&r&&!r.url){const e=this.#R(null,t.substring(1),r.graphs);return e||console.warn(`Unable to load graph from "${t}"`),e}const s=D(e),n=new URL(t,s);if(!n.hash)return await this.#j(n);if(r){const t=r.url?new URL(r.url):T;if(o=t,M(n).href===M(o).href){const t=n.hash.substring(1);return this.#R(n,t,r.graphs)}}var o;const i=await this.#j(M(n));return i?this.#R(n,n.hash.substring(1),i.graphs):null}}
/**

@@ -85,3 +85,3 @@ * @license

*/
class _{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#I={};#N=[];constructor({url:t,title:e,description:r,version:s,$schema:n}={$schema:q}){Object.assign(this,{$schema:n??q,url:t,title:e,description:r,version:s})}async*run(t={},e){const{inputs:r,...s}=t,n=s.base||T;yield*N((async r=>{const{probe:i}=s,a=await _.handlersFromBoard(this,s.kits),c={...this.#I,...s.slots};this.#N.forEach((t=>t.addGraph(this)));const d=new o(this,e?.state),f=new E(t),w=s.invocationPath||[],m=new C(s.state);await(i?.report?.({type:"graphstart",data:{graph:this,path:w,timestamp:u()}}));let y=0;m.onGraphStart();const g=()=>[...w,y];for await(const t of d){s?.signal?.throwIfAborted(),y++;const{inputs:e,descriptor:o,missingInputs:d}=t;if(t.skip){await(i?.report?.({type:"skip",data:{node:o,inputs:e,missingInputs:d,path:g(),timestamp:u()}}));continue}let w;if(m.onNodeStart(t),await(i?.report?.({type:"nodestart",data:{node:o,inputs:e,path:g(),timestamp:u()},state:await m.state()})),"input"===o.type)await r(new p(t,await m.state(),y,g())),await k(this,s,o,t,g()),w=t.outputsPromise?B(t.outputsPromise,s,this.url):void 0;else if("output"===o.type)await O(e,o,s,g())||await r(new h(t,y,g())),w=t.outputsPromise;else{const i=a[o.type];if(!i)throw new Error(`No handler for node type "${o.type}"`);const u={...s,descriptor:o,board:this,outerGraph:this,base:n,slots:c,kits:[...s.kits||[],...this.kits],requestInput:f.createHandler(r,t),provideOutput:x(r,t,s),invocationPath:g(),state:await m.state()};w=l(i,z(e,s,this.url),u)}m.onNodeEnd(),await(i?.report?.({type:"nodeend",data:{node:o,inputs:e,outputs:await w,validatorMetadata:this.#N.map((t=>t.getValidatorMetadata(o))),path:g(),timestamp:u()}})),t.outputsPromise=w}m.onGraphEnd(),await(i?.report?.({type:"graphend",data:{path:w,timestamp:u()}}))}))}get validators(){return this.#N}async runOnce(t,e={}){const r={...t,...this.args},{probe:s}=e;if(e.board&&e.descriptor)for(const t of e.board.validators)this.addValidator(t.getSubgraphValidator(e.descriptor,Object.keys(r)));try{let t={};const n=e.invocationPath||[];for await(const o of this.run(e))if("input"===o.type)o.inputs=r;else if("output"===o.type){t=o.outputs,await(s?.report?.({type:"nodeend",data:{node:o.node,inputs:o.inputs,outputs:t,path:[...n,o.invocationId],timestamp:u()}})),await(s?.report?.({type:"graphend",data:{path:n,timestamp:u()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#N.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const n=new y(t).describeGraph(s);return r?((t,e)=>`graph ${e};\n${t}`)(n,e):((t,e)=>`%%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%%\ngraph ${e};\n${t}\nclassDef default stroke:#ffab40,fill:#fff2ccff,color:#000\nclassDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000\nclassDef output stroke:#38761d,fill:#b6d7a8ff,color:#000\nclassDef passthrough stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef slot stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef config stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef secrets stroke:#db4437,fill:#f4cccc,color:#000\nclassDef slotted stroke:#a64d79`)(n,e)})(this,t,e,r)}static async fromGraphDescriptor(t){const e=new _(t);return e.edges=t.edges,e.nodes=t.nodes,e.graphs=t.graphs,e.args=t.args,e}static async load(t,e){const{base:r,slotted:s,outerGraph:n}=e||{},o=L(e.graphProviders),i=await o.load(t,{base:r,outerGraph:n});if(!i)throw new Error(`Unable to load graph from "${t}"`);const a=await _.fromGraphDescriptor(i);return a.#I=s||{},a}static async fromBreadboardCapability(t,e,r){if(!G(t))throw new Error(`Expected a "board" Capability, but got "${JSON.stringify(t)}`);if((t=>{const e=t.board;return!!e&&!!e.edges&&!!e.nodes})(t)){const e=t.board,r=e;return r.runOnce?r:await _.fromGraphDescriptor(e)}if((t=>!!t.url)(t)){if(!e||!r)throw new Error('The "board" Capability is a URL, but no loader and/or context was supplied.');const s=await e.load(t.url,r);if(!s)throw new Error(`Unable to load "board" Capability with the URL of ${t.url}.`);return _.fromGraphDescriptor(s)}if(W(t))throw new Error('Integrity error: somehow, the unresolved path "board" Capability snuck through the processing of inputs');throw new Error('Unsupported type of "board" Capability. Perhaps the supplied board isn\'t actually a GraphDescriptor?')}static async handlersFromBoard(t,e=[]){const r=[new H,...e,...t.kits];return f(r)}}class H{handlers;constructor(){this.handlers={lambda:{describe:async t=>({inputSchema:(new b).setAdditionalProperties(!0).addInputs(t).addProperty("board",{title:"board",description:"The board to run.",type:"object"}).build(),outputSchema:(new b).addProperty("board",{title:"board",description:"The now-runnable board.",type:"object"}).build()}),invoke:async t=>{const{board:e,...r}=t;if(!e||"board"!==e.kind||!e.board)throw new Error('Lambda node requires a BoardCapability as "board" input');const s={...await _.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}}
class _{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#N={};#I=[];constructor({url:t,title:e,description:r,version:s,$schema:n}={$schema:A}){Object.assign(this,{$schema:n??A,url:t,title:e,description:r,version:s})}async*run(t={},e){const{inputs:r,...s}=t,n=s.base||T;yield*I((async r=>{const{probe:i}=s,a=await _.handlersFromBoard(this,s.kits),c={...this.#N,...s.slots};this.#I.forEach((t=>t.addGraph(this)));const d=new o(this,e?.state),f=new E(t),w=s.invocationPath||[],m=new C(s.state);await(i?.report?.({type:"graphstart",data:{graph:this,path:w,timestamp:u()}}));let y=0;m.onGraphStart();const g=()=>[...w,y];for await(const t of d){s?.signal?.throwIfAborted(),y++;const{inputs:e,descriptor:o,missingInputs:d}=t;if(t.skip){await(i?.report?.({type:"skip",data:{node:o,inputs:e,missingInputs:d,path:g(),timestamp:u()}}));continue}let w;if(m.onNodeStart(t),await(i?.report?.({type:"nodestart",data:{node:o,inputs:e,path:g(),timestamp:u()},state:await m.state()})),"input"===o.type)await r(new p(t,await m.state(),y,g())),await k(this,s,o,t,g()),w=t.outputsPromise?B(t.outputsPromise,s,this.url):void 0;else if("output"===o.type)await O(e,o,s,g())||await r(new h(t,y,g())),w=t.outputsPromise;else{const i=a[o.type];if(!i)throw new Error(`No handler for node type "${o.type}"`);const u={...s,descriptor:o,board:this,outerGraph:this,base:n,slots:c,kits:[...s.kits||[],...this.kits],requestInput:f.createHandler(r,t),provideOutput:x(r,t,s),invocationPath:g(),state:await m.state()};w=l(i,z(e,s,this.url),u)}m.onNodeEnd(),await(i?.report?.({type:"nodeend",data:{node:o,inputs:e,outputs:await w,validatorMetadata:this.#I.map((t=>t.getValidatorMetadata(o))),path:g(),timestamp:u()}})),t.outputsPromise=w}m.onGraphEnd(),await(i?.report?.({type:"graphend",data:{path:w,timestamp:u()}}))}))}get validators(){return this.#I}async runOnce(t,e={}){const r={...t,...this.args},{probe:s}=e;if(e.board&&e.descriptor)for(const t of e.board.validators)this.addValidator(t.getSubgraphValidator(e.descriptor,Object.keys(r)));try{let t={};const n=e.invocationPath||[];for await(const o of this.run(e))if("input"===o.type)o.inputs=r;else if("output"===o.type){t=o.outputs,await(s?.report?.({type:"nodeend",data:{node:o.node,inputs:o.inputs,outputs:t,path:[...n,o.invocationId],timestamp:u()}})),await(s?.report?.({type:"graphend",data:{path:n,timestamp:u()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#I.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const n=new y(t).describeGraph(s);return r?((t,e)=>`graph ${e};\n${t}`)(n,e):((t,e)=>`%%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%%\ngraph ${e};\n${t}\nclassDef default stroke:#ffab40,fill:#fff2ccff,color:#000\nclassDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000\nclassDef output stroke:#38761d,fill:#b6d7a8ff,color:#000\nclassDef passthrough stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef slot stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef config stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef secrets stroke:#db4437,fill:#f4cccc,color:#000\nclassDef slotted stroke:#a64d79`)(n,e)})(this,t,e,r)}static async fromGraphDescriptor(t){const e=new _(t);return e.edges=t.edges,e.nodes=t.nodes,e.graphs=t.graphs,e.args=t.args,e}static async load(t,e){const{base:r,slotted:s,outerGraph:n}=e||{},o=L(e.graphProviders),i=await o.load(t,{base:r,outerGraph:n});if(!i)throw new Error(`Unable to load graph from "${t}"`);const a=await _.fromGraphDescriptor(i);return a.#N=s||{},a}static async fromBreadboardCapability(t,e,r){if(!G(t))throw new Error(`Expected a "board" Capability, but got "${JSON.stringify(t)}`);if((t=>{const e=t.board;return!!e&&!!e.edges&&!!e.nodes})(t)){const e=t.board,r=e;return r.runOnce?r:await _.fromGraphDescriptor(e)}if((t=>!!t.url)(t)){if(!e||!r)throw new Error('The "board" Capability is a URL, but no loader and/or context was supplied.');const s=await e.load(t.url,r);if(!s)throw new Error(`Unable to load "board" Capability with the URL of ${t.url}.`);return _.fromGraphDescriptor(s)}if(W(t))throw new Error('Integrity error: somehow, the unresolved path "board" Capability snuck through the processing of inputs');throw new Error('Unsupported type of "board" Capability. Perhaps the supplied board isn\'t actually a GraphDescriptor?')}static async handlersFromBoard(t,e=[]){const r=[new H,...e,...t.kits];return f(r)}}class H{handlers;constructor(){this.handlers={lambda:{describe:async t=>({inputSchema:(new b).setAdditionalProperties(!0).addInputs(t).addProperty("board",{title:"board",description:"The board to run.",type:"object"}).build(),outputSchema:(new b).addProperty("board",{title:"board",description:"The now-runnable board.",type:"object"}).build()}),invoke:async t=>{const{board:e,...r}=t;if(!e||"board"!==e.kind||!e.board)throw new Error('Lambda node requires a BoardCapability as "board" input');const s={...await _.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}}
/**

@@ -96,3 +96,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const V=/^((?<a>.*)(?<dir><-|->))?(?<b>[^(.|?)]*)(?<q>\.|\?)?$/m,K=new J;class Q{#q;#A;constructor(t,e,r,s,n){if(this.#A=t.currentBoardToAddTo(),this.#q={id:n??K.vendId(this.#A,r),type:r},s&&(t=>Object.values(t).length>0)(s)){const t=Object.entries(s).filter((([t,e])=>e instanceof Q));for(const[e,r]of t){if(delete s[e],-1!==e.indexOf("->"))throw Error("Cannot pass output wire in confdig");this.wire(-1===e.indexOf("<-")?`${e}<-.`:e,r)}this.#q.configuration=s}e?.url&&!this.#A.kits.find((t=>t.url===e.url))&&this.#A.kits.push(e),this.#A.addNode(this.#q)}wire(t,e){const{ltr:r,edge:s}=(t=>{const e={ltr:!0},r=t.match(V);if(!r)throw new Error(`Invalid edge spec: ${t}`);const{a:s,b:n,dir:o,q:i}=r?.groups,a="<-"!==o;e.ltr=a;const c="?"===i,u="."===i;return e.edge={},u&&(e.edge.constant=!0),c&&(e.edge.optional=!0),s||n?"*"===s||"*"===n?(e.edge.out="*",e):s?n?(a?(e.edge.out=s,e.edge.in=n):(e.edge.out=n,e.edge.in=s),e):(e.edge.out=s,e.edge.in=s,e):(e.edge.out=n,e.edge.in=n,e):e})(t),[n,o]=r?[this,e]:[e,this],i={from:n.#q.id,to:o.#q.id,...s};return n.#A!==o.#A?o.#A.addEdgeAcrossBoards(i,n.#A,o.#A):this.#A.addEdge(i),this}get id(){return this.#q.id}}
*/const V=/^((?<a>.*)(?<dir><-|->))?(?<b>[^(.|?)]*)(?<q>\.|\?)?$/m,K=new J;class Q{#A;#q;constructor(t,e,r,s,n){if(this.#q=t.currentBoardToAddTo(),this.#A={id:n??K.vendId(this.#q,r),type:r},s&&(t=>Object.values(t).length>0)(s)){const t=Object.entries(s).filter((([t,e])=>e instanceof Q));for(const[e,r]of t){if(delete s[e],-1!==e.indexOf("->"))throw Error("Cannot pass output wire in confdig");this.wire(-1===e.indexOf("<-")?`${e}<-.`:e,r)}this.#A.configuration=s}e?.url&&!this.#q.kits.find((t=>t.url===e.url))&&this.#q.kits.push(e),this.#q.addNode(this.#A)}wire(t,e){const{ltr:r,edge:s}=(t=>{const e={ltr:!0},r=t.match(V);if(!r)throw new Error(`Invalid edge spec: ${t}`);const{a:s,b:n,dir:o,q:i}=r?.groups,a="<-"!==o;e.ltr=a;const c="?"===i,u="."===i;return e.edge={},u&&(e.edge.constant=!0),c&&(e.edge.optional=!0),s||n?"*"===s||"*"===n?(e.edge.out="*",e):s?n?(a?(e.edge.out=s,e.edge.in=n):(e.edge.out=n,e.edge.in=s),e):(e.edge.out=s,e.edge.in=s,e):(e.edge.out=n,e.edge.in=n,e):e})(t),[n,o]=r?[this,e]:[e,this],i={from:n.#A.id,to:o.#A.id,...s};return n.#q!==o.#q?o.#q.addEdgeAcrossBoards(i,n.#q,o.#q):this.#q.addEdge(i),this}get id(){return this.#A.id}}
/**

@@ -138,3 +138,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class vt{url;title;description;version;namespacePrefix;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n=""}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n}#_(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:o}=this,i=this.#_(t),a=Object.keys(t);return class{title=s;description=n;version=o;url=e;get handlers(){return i}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n?s[n]:a.includes(n)?(s={})=>{const o=t.getConfigWithLambda(s),{$id:i,...a}=o;return t.create(e,`${r}${n}`,{...a},i)}: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 o=await s(...r);return"object"!=typeof o||Array.isArray(o)?{result:o}:{...o}}},t}),{});return new vt(t).build(r)}}
*/class vt{url;title;description;version;namespacePrefix;tags;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n="",tags:o=[]}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n,this.tags=o}#_(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:o,tags:i}=this,a=this.#_(t),c=Object.keys(t);return class{title=s;description=n;version=o;url=e;tags=i;get handlers(){return a}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n||"tags"===n?s[n]:c.includes(n)?(s={})=>{const o=t.getConfigWithLambda(s),{$id:i,...a}=o;return t.create(e,`${r}${n}`,{...a},i)}: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 o=await s(...r);return"object"!=typeof o||Array.isArray(o)?{result:o}:{...o}}},t}),{});return new vt(t).build(r)}}
/**

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

* SPDX-License-Identifier: Apache-2.0
*/const kt=globalThis.process?t=>Buffer.from(t,"base64").toString("binary"):globalThis.atob,$t=globalThis.process?t=>Buffer.from(t,"binary").toString("base64"):globalThis.btoa;class St{outputName;from;to;when;constructor(t,e,r,s={}){this.outputName=t,this.from=e,this.to=r,this.when=s}getInputNames(){const t=Object.keys(this.when);return 0===t.length?[this.outputName]:t}matches(t){return Object.entries(this.when).every((([e,r])=>{const s=t[e];return"string"==typeof r?s===r:"string"==typeof s&&r.test(s)}))}}const Et=(t,e)=>Object.fromEntries(Object.entries(e).map((([e,r])=>"string"==typeof r?[e,[new St(e,t,r)]]:Array.isArray(r)?[e,r.map((r=>"string"==typeof r?new St(e,t,r):new St(e,t,r.to,r.when)))]:[e,[new St(e,t,r.to,r.when)]]))),Pt=Math.round(Date.now()/6048e5).toString(36),Ot=`T-${Pt}-`,xt=`-${Pt}-T`,jt=new RegExp(`(${Ot}.*?${xt})`,"gm"),Rt=new RegExp(`^${Ot}(.+?)${xt}$`),It=async(t,e,r)=>{const s=JSON.stringify(t),n=s.split(jt).filter(Boolean).map((t=>{const e=t.match(Rt);if(e){const t=e[1].split("~"),[r,s,n]=t;return{nodeType:r,outputName:s,inputs:kt(n)}}return{value:t}}));const o=await Promise.all(n.map((async t=>{if("inputs"in t){const s=JSON.parse(t.inputs),{nodeType:n,outputName:o}=t,i=e?await r(n,s):{[o]:"VALUE_BLOCKED"};if(!i)return"";let a=JSON.stringify(i[o]);return a.startsWith('"')&&(a=a.slice(1,-1)),a=JSON.stringify(a),a.slice(1,-1)}return t.value})));return JSON.parse(o.join(""))},Nt=(t,e)=>{const r=Object.fromEntries(Object.entries(e).map((([e,r])=>{const s=t[e];return s?[e,async(t,n)=>((t,e,r)=>{if(t)return Object.fromEntries(Object.entries(t).map((([t,s])=>t in e?[t,r(t,s)]:[t,s])))})(await l(r,t,n),s,(r=>((t,e,r)=>{const s=$t(JSON.stringify(r)).replace("=","");return`${Ot}${t}~${e}~${s}${xt}`})(e,r,t)))]:[e,r]}))),s=(t=>Object.entries(t).flatMap((([t,e])=>Object.entries(e).flatMap((([t,e])=>e.map((t=>[t.to,t])))))).reduce(((t,[e,r])=>(t[e]||(t[e]=[]),t[e].push(r),t)),{}))(t),n=Object.fromEntries(Object.entries(r).map((([t,r])=>{const n=s[t];return n?[t,async(t,s)=>l(r,await(async(t,e,r)=>{const s=e.some((e=>e.matches(t)));return Object.fromEntries(await Promise.all(Object.entries(t).map((async([t,e])=>[t,await r(e,s)]))))})(t,n,(async(t,r)=>It(t,r,(async(t,r)=>l(e[t],r,s))))),s)]:[t,r]})));return{url:"tunnel-kit",handlers:n}},Ct=t=>{if("object"!=typeof t||null===t)return!1;return"storedData"in t&&!!t.storedData.handle};async function qt(t){return"Buffer"in globalThis?Buffer.from(await t.arrayBuffer()).toString("base64"):new Promise(((e,r)=>{const s=new FileReader;s.onload=()=>{if("string"!=typeof s.result)return void r("Reader result is not a string");const[,t]=s.result.split(",");e(t)},s.onerror=t=>r(t),s.readAsDataURL(t)}))}
*/const kt=globalThis.process?t=>Buffer.from(t,"base64").toString("binary"):globalThis.atob,$t=globalThis.process?t=>Buffer.from(t,"binary").toString("base64"):globalThis.btoa;class St{outputName;from;to;when;constructor(t,e,r,s={}){this.outputName=t,this.from=e,this.to=r,this.when=s}getInputNames(){const t=Object.keys(this.when);return 0===t.length?[this.outputName]:t}matches(t){return Object.entries(this.when).every((([e,r])=>{const s=t[e];return"string"==typeof r?s===r:"string"==typeof s&&r.test(s)}))}}const Et=(t,e)=>Object.fromEntries(Object.entries(e).map((([e,r])=>"string"==typeof r?[e,[new St(e,t,r)]]:Array.isArray(r)?[e,r.map((r=>"string"==typeof r?new St(e,t,r):new St(e,t,r.to,r.when)))]:[e,[new St(e,t,r.to,r.when)]]))),Pt=Math.round(Date.now()/6048e5).toString(36),Ot=`T-${Pt}-`,xt=`-${Pt}-T`,jt=new RegExp(`(${Ot}.*?${xt})`,"gm"),Rt=new RegExp(`^${Ot}(.+?)${xt}$`),Nt=async(t,e,r)=>{const s=JSON.stringify(t),n=s.split(jt).filter(Boolean).map((t=>{const e=t.match(Rt);if(e){const t=e[1].split("~"),[r,s,n]=t;return{nodeType:r,outputName:s,inputs:kt(n)}}return{value:t}}));const o=await Promise.all(n.map((async t=>{if("inputs"in t){const s=JSON.parse(t.inputs),{nodeType:n,outputName:o}=t,i=e?await r(n,s):{[o]:"VALUE_BLOCKED"};if(!i)return"";let a=JSON.stringify(i[o]);return a.startsWith('"')&&(a=a.slice(1,-1)),a=JSON.stringify(a),a.slice(1,-1)}return t.value})));return JSON.parse(o.join(""))},It=(t,e)=>{const r=Object.fromEntries(Object.entries(e).map((([e,r])=>{const s=t[e];return s?[e,async(t,n)=>((t,e,r)=>{if(t)return Object.fromEntries(Object.entries(t).map((([t,s])=>t in e?[t,r(t,s)]:[t,s])))})(await l(r,t,n),s,(r=>((t,e,r)=>{const s=$t(JSON.stringify(r)).replace("=","");return`${Ot}${t}~${e}~${s}${xt}`})(e,r,t)))]:[e,r]}))),s=(t=>Object.entries(t).flatMap((([t,e])=>Object.entries(e).flatMap((([t,e])=>e.map((t=>[t.to,t])))))).reduce(((t,[e,r])=>(t[e]||(t[e]=[]),t[e].push(r),t)),{}))(t),n=Object.fromEntries(Object.entries(r).map((([t,r])=>{const n=s[t];return n?[t,async(t,s)=>l(r,await(async(t,e,r)=>{const s=e.some((e=>e.matches(t)));return Object.fromEntries(await Promise.all(Object.entries(t).map((async([t,e])=>[t,await r(e,s)]))))})(t,n,(async(t,r)=>Nt(t,r,(async(t,r)=>l(e[t],r,s))))),s)]:[t,r]})));return{url:"tunnel-kit",handlers:n}},Ct=t=>{if("object"!=typeof t||null===t)return!1;return"storedData"in t&&"string"==typeof t.storedData.handle};async function At(t){return"Buffer"in globalThis?Buffer.from(await t.arrayBuffer()).toString("base64"):new Promise(((e,r)=>{const s=new FileReader;s.onload=()=>{if("string"!=typeof s.result)return void r("Reader result is not a string");const[,t]=s.result.split(",");e(t)},s.onerror=t=>r(t),s.readAsDataURL(t)}))}
/**

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

* SPDX-License-Identifier: Apache-2.0
*/const At=async(t,e)=>{const r=async e=>{if(Ct(e)){const r=await t.retrieveAsBlob(e);return{inlineData:{data:await qt(r),mimeType:r.type}}}if(Array.isArray(e)){const t=[];for(const s of e)t.push(await r(s));return t}if("object"==typeof e&&null!==e){const t=e,s={};for(const n in e)s[n]=await r(t[n]);return s}return e};return await r(e)},Tt=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r};
*/const qt=async(t,e)=>{const r=async e=>{if(Ct(e)){const r=await t.retrieveAsBlob(e);return{inlineData:{data:await At(r),mimeType:r.type}}}if(Array.isArray(e)){const t=[];for(const s of e)t.push(await r(s));return t}if("object"==typeof e&&null!==e){const t=e,s={};for(const n in e)s[n]=await r(t[n]);return s}return e};return await r(e)},Tt=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r};
/**

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

* SPDX-License-Identifier: Apache-2.0
*/class Mt{#U;constructor(t){this.#U=t}async serve(t){const{kits:e,store:r}=t,s=this.#U.createServerStream(),n=Nt((t=>t.proxy?Object.fromEntries(t.proxy.map((t=>{if("string"!=typeof t&&t.tunnel)return[t.node,Et(t.node,t.tunnel)]})).filter(Boolean)):{})(t),f(e)),o=n.handlers;for await(const e of ht(s.writableResponses,s.readableRequests)){const[s]=e.data;if("end"===s)break;if("proxy"!==s){e.reply(["error",{error:"Expected proxy request.",timestamp:u()}]);continue}const[,{node:n,inputs:i}]=e.data,a=Tt(n.type,t.proxy)?o[n.type]:void 0;if(a)try{const t=await l(a,i,{descriptor:n,store:r});if(!t){e.reply(["error",{error:"Handler returned nothing.",timestamp:u()}]);continue}const s=r?await At(r,t):t;e.reply(["proxy",{outputs:s}])}catch(t){e.reply(["error",{error:t.message,timestamp:u()}])}else e.reply(["error",{error:"Can't proxy a node of this node type.",timestamp:u()}])}}}class Dt{#U;constructor(t){this.#U=t}shutdownServer(){const t=this.#U.createClientStream().writableRequests.getWriter();t.write(["end",{timestamp:u()}]),t.close()}async proxy(t,e,r){const s=this.#U.createClientStream(),n=s.writableRequests.getWriter(),o=s.readableResponses.getReader();n.write(["proxy",{node:t,inputs:e}]),n.close();const i=await o.read();if(i.done)throw new Error("Unexpected proxy failure: empty response.");const[a]=i.value;if("proxy"===a){const[,{outputs:t}]=i.value;return t}if("error"===a){const[,{error:t}]=i.value;throw new Error(JSON.stringify(t))}throw new Error(`Unexpected proxy failure: unknown response type "${a}".`)}createProxyKit(t=[]){const e=t.map((t=>"string"==typeof t?t:t.node)),r=Object.fromEntries(e.map((t=>[t,{invoke:async(t,e)=>{const r=e.descriptor;return await this.proxy(r,t,e)}}])));return X(new vt({url:"proxy"}).build(r))}}
*/class Mt{#U;constructor(t){this.#U=t}async serve(t){const{kits:e,store:r}=t,s=this.#U.createServerStream(),n=It((t=>t.proxy?Object.fromEntries(t.proxy.map((t=>{if("string"!=typeof t&&t.tunnel)return[t.node,Et(t.node,t.tunnel)]})).filter(Boolean)):{})(t),f(e)),o=n.handlers;for await(const e of ht(s.writableResponses,s.readableRequests)){const[s]=e.data;if("end"===s)break;if("proxy"!==s){e.reply(["error",{error:"Expected proxy request.",timestamp:u()}]);continue}const[,{node:n,inputs:i}]=e.data,a=Tt(n.type,t.proxy)?o[n.type]:void 0;if(a)try{const t=await l(a,i,{descriptor:n,store:r});if(!t){e.reply(["error",{error:"Handler returned nothing.",timestamp:u()}]);continue}const s=r?await qt(r,t):t;e.reply(["proxy",{outputs:s}])}catch(t){e.reply(["error",{error:t.message,timestamp:u()}])}else e.reply(["error",{error:"Can't proxy a node of this node type.",timestamp:u()}])}}}class Dt{#U;constructor(t){this.#U=t}shutdownServer(){const t=this.#U.createClientStream().writableRequests.getWriter();t.write(["end",{timestamp:u()}]),t.close()}async proxy(t,e,r){const s=this.#U.createClientStream(),n=s.writableRequests.getWriter(),o=s.readableResponses.getReader();n.write(["proxy",{node:t,inputs:e}]),n.close();const i=await o.read();if(i.done)throw new Error("Unexpected proxy failure: empty response.");const[a]=i.value;if("proxy"===a){const[,{outputs:t}]=i.value;return t}if("error"===a){const[,{error:t}]=i.value;throw new Error(JSON.stringify(t))}throw new Error(`Unexpected proxy failure: unknown response type "${a}".`)}createProxyKit(t=[]){const e=t.map((t=>"string"==typeof t?t:t.node)),r=Object.fromEntries(e.map((t=>[t,{invoke:async(t,e)=>{const r=e.descriptor;return await this.proxy(r,t,e)}}])));return X(new vt({url:"proxy"}).build(r))}}
/**

@@ -242,3 +242,3 @@ * @license

*/
class de{#ft=1;#wt=new Map;async store(t){const e=URL.createObjectURL(t);let r=this.#wt.get(this.#ft);r||(r=[],this.#wt.set(this.#ft,r)),r.push(e);return{storedData:{handle:e,mimeType:t.type}}}async retrieve(t){const e=await this.retrieveAsBlob(t);return{inlineData:{mimeType:t.storedData.mimeType,data:await qt(e)}}}async retrieveAsBlob(t){if(!Ct(t))throw new Error("Invalid stored data");const{handle:e}=t.storedData,r=await fetch(e);return await r.blob()}async retrieveAsURL(t){if(!Ct(t))throw new Error("Invalid stored data");const{handle:e}=t.storedData;return e}startGroup(){this.#ft}endGroup(){return this.#ft++}async serializeGroup(t){const e=this.#wt.get(t);return e?Promise.all(e.map((async t=>fetch(t).then((async e=>{const r=await e.blob(),s=r.type,n=await qt(r);return{handle:t,inlineData:{mimeType:s,data:n}}}))))):null}releaseGroup(t){const e=this.#wt.get(t);if(e)for(const t of e)URL.revokeObjectURL(t)}}
class de{#ft=1;#wt=new Map;async store(t){const e=URL.createObjectURL(t);let r=this.#wt.get(this.#ft);r||(r=[],this.#wt.set(this.#ft,r)),r.push(e);return{storedData:{handle:e,mimeType:t.type}}}async retrieve(t){const e=await this.retrieveAsBlob(t);return{inlineData:{mimeType:t.storedData.mimeType,data:await At(e)}}}async retrieveAsBlob(t){if(!Ct(t))throw new Error("Invalid stored data");const{handle:e}=t.storedData,r=await fetch(e);return await r.blob()}async retrieveAsURL(t){if(!Ct(t))throw new Error("Invalid stored data");const{handle:e}=t.storedData;return e}startGroup(){this.#ft}endGroup(){return this.#ft++}async serializeGroup(t){const e=this.#wt.get(t);return e?Promise.all(e.map((async t=>fetch(t).then((async e=>{const r=await e.blob(),s=r.type,n=await At(r);return{handle:t,inlineData:{mimeType:s,data:n}}}))))):null}releaseGroup(t){const e=this.#wt.get(t);if(e)for(const t of e)URL.revokeObjectURL(t)}releaseAll(){for(const t of this.#wt.keys())this.releaseGroup(t)}async copyToNewestGroup(t){const e=await this.retrieveAsBlob(t);return await this.store(e)}async drop(){this.releaseAll(),this.#wt.clear()}}
/**

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

* SPDX-License-Identifier: Apache-2.0
*/const le=t=>{const e=(()=>{if("nodestart"===t.type)return t.state})(),r=structuredClone(t.data);return{type:t.type,data:r,state:e,reply:async()=>{}}},fe=t=>{const{type:e,node:r,timestamp:s,invocationId:n}=t,o=-1==n;if("input"===e){const{inputArguments:n,path:i}=t;return{type:e,data:{node:r,inputArguments:n,path:i,bubbled:o,timestamp:s},reply:async e=>{t.inputs=e.inputs}}}if("output"===e){const{outputs:n,path:i}=t;return{type:e,data:{node:r,outputs:n,path:i,timestamp:s,bubbled:o},reply:async()=>{}}}throw new Error(`Unknown result type "${e}".`)},we=()=>({type:"end",data:{timestamp:u()},reply:async()=>{}}),me=t=>({type:"error",data:{error:t,timestamp:u()},reply:async()=>{}}),ye=async t=>{const e=Ut(t),r=t.loader||L(),s=await r.load(t.url,{base:e});if(!s)throw new Error(`Unable to load graph from "${t.url}"`);return Z.fromGraphDescriptor(s)};
*/const le=t=>{const e=(()=>{if("nodestart"===t.type)return t.state})(),r=structuredClone(t.data);return{type:t.type,data:r,state:e,reply:async()=>{}}},fe=t=>{const{type:e,node:r,timestamp:s,invocationId:n}=t,o=-1==n,i=async()=>[{graph:0,node:n,state:await c(e,t.state)}];if("input"===e){const{inputArguments:n,path:a}=t;return{type:e,data:{node:r,inputArguments:n,path:a,bubbled:o,timestamp:s},reply:async e=>{t.inputs=e.inputs},saveState:i}}if("output"===e){const{outputs:n,path:a}=t;return{type:e,data:{node:r,outputs:n,path:a,timestamp:s,bubbled:o},reply:async()=>{},saveState:i}}throw new Error(`Unknown result type "${e}".`)},we=()=>({type:"end",data:{timestamp:u()},reply:async()=>{}}),me=t=>({type:"error",data:{error:t,timestamp:u()},reply:async()=>{}}),ye=async t=>{const e=Ut(t),r=t.loader||L(),s=await r.load(t.url,{base:e});if(!s)throw new Error(`Unable to load graph from "${t.url}"`);return Z.fromGraphDescriptor(s)},ge=t=>{if(t?.state?.[0].state){const e=d.load(t.state[0].state);return t.inputs&&(e.inputs=t.inputs),e}};
/**

@@ -265,3 +265,3 @@ * @license

*/
const ge=t=>{const e=new vt({url:"secret-asking-kit"}).build({secrets:async e=>{const{keys:r}=e;if(!r)return{};let s={};return await t({type:"secret",data:{keys:r,timestamp:u()},reply:async t=>{s=t.inputs}}),s}});return X(e)},be=t=>{const e=new URL(t,location.href),r=new Blob([`import "${e}";`],{type:"text/javascript"}),s=URL.createObjectURL(r);return new Worker(s,{type:"module"})};
const be=t=>{const e=new vt({url:"secret-asking-kit"}).build({secrets:async e=>{const{keys:r}=e;if(!r)return{};let s={};return await t({type:"secret",data:{keys:r,timestamp:u()},reply:async t=>{s=t.inputs}}),s}});return X(e)},ve=t=>{const e=new URL(t,location.href),r=new Blob([`import "${e}";`],{type:"text/javascript"}),s=URL.createObjectURL(r);return new Worker(s,{type:"module"})};
/**

@@ -277,3 +277,3 @@ * @license

*/
const ve=async t=>{if(!t.proxy)return t.kits;const e=[];for(const r of t.proxy)if("function"==typeof r){if(!await r())continue;e.push(await r())}else switch(r.location){case"http":{if(!r.url)throw new Error("No node proxy server URL provided.");const t=new Dt(new he(r.url));e.push(t.createProxyKit(r.nodes));break}default:throw new Error("Only HTTP node proxy server is supported at this time.")}return[...e,...t.kits]};async function*ke(t){if(t.remote){if("worker"!==t.remote.type)throw new Error(`Unsupported harness configuration: ${JSON.stringify(t,null,2)}`);{const e=t.remote&&t.remote.url;if(!e)throw new Error("Worker harness requires a worker URL");yield*async function*(t,e,r){const s=be(t),n=new yt(s),o=new et(new gt(n.send("load"))),i=new Mt(new bt(n.receive("proxy"))),a=new wt(new gt(n.send("run")));await o.load(e.url),yield*N((async t=>{const s=[ge(t),...e.kits],n=e.proxy?.[0];let o;n&&"function"!=typeof n&&(o=n.nodes),i.serve({kits:s,proxy:o});for await(const e of a.run(r))await t(e)}))}(e,t)}}else yield*N((async e=>{const r=[...t.interactiveSecrets?[ge(e)]:[],...await ve(t)];for await(const s of async function*(t,e){yield*N((async r=>{const s=t.runner||await ye(t),n=t.loader||L(),o=t.store||pe();try{const i=t.diagnostics?new rt((async t=>{await r(le(t))})):void 0;for await(const a of s.run({probe:i,kits:e,loader:n,store:o,base:t.base,signal:t.signal,inputs:t.inputs}))await r(fe(a));await r(we())}catch(t){const e=st(t);console.error("Local Run error:",e),await r(me(e))}}))}(t,r))await e(s)}))}export{ge as createSecretAskingKit,be as createWorker,Wt as defineServeConfig,ke as run,Gt as serve};
const ke=async t=>{if(!t.proxy)return t.kits;const e=[];for(const r of t.proxy)if("function"==typeof r){if(!await r())continue;e.push(await r())}else switch(r.location){case"http":{if(!r.url)throw new Error("No node proxy server URL provided.");const t=new Dt(new he(r.url));e.push(t.createProxyKit(r.nodes));break}default:throw new Error("Only HTTP node proxy server is supported at this time.")}return[...e,...t.kits]};async function*$e(t){if(t.remote){if("worker"!==t.remote.type)throw new Error(`Unsupported harness configuration: ${JSON.stringify(t,null,2)}`);{const e=t.remote&&t.remote.url;if(!e)throw new Error("Worker harness requires a worker URL");yield*async function*(t,e,r){const s=ve(t),n=new yt(s),o=new et(new gt(n.send("load"))),i=new Mt(new bt(n.receive("proxy"))),a=new wt(new gt(n.send("run")));await o.load(e.url),yield*I((async t=>{const s=[be(t),...e.kits],n=e.proxy?.[0];let o;n&&"function"!=typeof n&&(o=n.nodes),i.serve({kits:s,proxy:o});for await(const e of a.run(r))await t(e)}))}(e,t)}}else yield*I((async e=>{const r=[...t.interactiveSecrets?[be(e)]:[],...await ke(t)];for await(const s of async function*(t,e){yield*I((async r=>{const s=t.runner||await ye(t),n=t.loader||L(),o=t.store||pe(),i=ge(t.resumeFrom);try{const a=t.diagnostics?new rt((async t=>{await r(le(t))})):void 0;for await(const c of s.run({probe:a,kits:e,loader:n,store:o,base:t.base,signal:t.signal,inputs:t.inputs},i))await r(fe(c));await r(we())}catch(t){const e=st(t);console.error("Local Run error:",e),await r(me(e))}}))}(t,r))await e(s)}))}export{be as createSecretAskingKit,ve as createWorker,Wt as defineServeConfig,$e as run,Gt as serve};
//# sourceMappingURL=harness.min.js.map

@@ -47,3 +47,3 @@ /**

* SPDX-License-Identifier: Apache-2.0
*/;class m{#i;#o;#a;#u;#p;constructor(t,e,r,s,n){this.#o=t,this.#i=e,this.#a=r,this.#u=s,this.#p=n}get invocationId(){return this.#u}get path(){return this.#p}get type(){return this.#i}get node(){return this.#o.descriptor}get inputArguments(){return this.#o.inputs}set inputs(t){this.#o.outputsPromise=Promise.resolve(t)}get outputs(){const{schema:t,...e}=this.#o.inputs;return e}get state(){return this.#o}async save(){return l(this.#i,this.#o)}get runState(){return this.#a}get timestamp(){return f()}isAtExitNode(){return 0===this.#o.newOpportunities.length&&0===this.#o.opportunities.length&&0===this.#o.pendingOutputs.size}static load(t){const{state:e,type:r}=(t=>{const{state:e,type:r}=JSON.parse(t,d);return{state:a.fromObject(e),type:r}})(t);return new m(e,r,void 0,0,[])}}class g extends m{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 y extends m{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 g{#i;#o;#a;#u;#p;constructor(t,e,r,s,n){this.#o=t,this.#i=e,this.#a=r,this.#u=s,this.#p=n}get invocationId(){return this.#u}get path(){return this.#p}get type(){return this.#i}get node(){return this.#o.descriptor}get inputArguments(){return this.#o.inputs}set inputs(t){this.#o.outputsPromise=Promise.resolve(t)}get outputs(){const{schema:t,...e}=this.#o.inputs;return e}get state(){return this.#o}async save(){return l(this.#i,this.#o)}get runState(){return this.#a}get timestamp(){return f()}isAtExitNode(){return 0===this.#o.newOpportunities.length&&0===this.#o.opportunities.length&&0===this.#o.pendingOutputs.size}static load(t){const{state:e,type:r}=(t=>{const{state:e,type:r}=JSON.parse(t,d);return{state:a.fromObject(e),type:r}})(t);return new g(e,r,void 0,0,[])}}class m extends g{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 y extends g{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')}}
/**

@@ -58,3 +58,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class k{#c;#h;#p;constructor(t,e,r){this.#c=t,this.#h=e,this.#p=r}async read(t){if(!("schema"in this.#h))return this.#c;const e=this.#h.schema;if(!e.properties)return this.#c;const r=Object.entries(e.properties),s={};for(const[n,i]of r){if(n in this.#c){s[n]=this.#c[n];continue}const r=e.required?.includes(n)??!1,o=await t(n,i,r,this.#p);s[n]=o}return{...this.#c,...s}}}class O{#d;#l=new Map;constructor(t){const{inputs:e,...r}=t;this.#d=r,this.#l=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,i)=>{const o=this.#l.get(r);if(void 0!==o)return o;const a={id:n.id,type:n.type},u={...e,descriptor:a,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new g(u,void 0,-1,i));const p=await u.outputsPromise;let c=p&&p[r];return void 0===c&&(c=await(this.#d.requestInput?.(r,s,a,i))),E(s)||this.#l.set(r,c),c}}}const E=t=>t.behavior?.includes("transient")??!1,A=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)},x=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const i={...e,descriptor:s,inputs:r};await t(new y(i,-1,n))},I=()=>{};class j{#f=[];#m=I;#g;#y;abort=I;constructor(){this.#w()}#w(){this.#g=new Promise(((t,e)=>{this.#m=t,this.abort=e}))}#b(t){this.#f.push(t),1==this.#f.length&&(this.#m(),this.#w())}async write(t){return new Promise((e=>{this.#b({value:t,receipt:e})}))}async read(){this.#y&&this.#y(),0===this.#f.length&&await this.#g;const t=this.#f.shift();if(!t)throw new Error("asyncGen queue should never be empty.");return this.#y=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#b({value:void 0,receipt:I})}}class N{#v;#P=!0;#f=new j;constructor(t){this.#v=t}async#$(t){return this.#f.write(t)}async next(){return this.#P&&(this.#P=!1,this.#v(this.#$.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}}
*/class k{#c;#h;#p;constructor(t,e,r){this.#c=t,this.#h=e,this.#p=r}async read(t){if(!("schema"in this.#h))return this.#c;const e=this.#h.schema;if(!e.properties)return this.#c;const r=Object.entries(e.properties),s={};for(const[n,i]of r){if(n in this.#c){s[n]=this.#c[n];continue}const r=e.required?.includes(n)??!1,o=await t(n,i,r,this.#p);s[n]=o}return{...this.#c,...s}}}class O{#d;#l=new Map;constructor(t){const{inputs:e,...r}=t;this.#d=r,this.#l=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,i)=>{const o=this.#l.get(r);if(void 0!==o)return o;const a={id:n.id,type:n.type},u={...e,descriptor:a,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new m(u,void 0,-1,i));const p=await u.outputsPromise;let c=p&&p[r];return void 0===c&&(c=await(this.#d.requestInput?.(r,s,a,i))),E(s)||this.#l.set(r,c),c}}}const E=t=>t.behavior?.includes("transient")??!1,A=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)},x=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const i={...e,descriptor:s,inputs:r};await t(new y(i,-1,n))},I=()=>{};class j{#f=[];#g=I;#m;#y;abort=I;constructor(){this.#w()}#w(){this.#m=new Promise(((t,e)=>{this.#g=t,this.abort=e}))}#b(t){this.#f.push(t),1==this.#f.length&&(this.#g(),this.#w())}async write(t){return new Promise((e=>{this.#b({value:t,receipt:e})}))}async read(){this.#y&&this.#y(),0===this.#f.length&&await this.#m;const t=this.#f.shift();if(!t)throw new Error("asyncGen queue should never be empty.");return this.#y=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#b({value:void 0,receipt:I})}}class N{#v;#P=!0;#f=new j;constructor(t){this.#v=t}async#$(t){return this.#f.write(t)}async next(){return this.#P&&(this.#P=!1,this.#v(this.#$.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}}
/**

@@ -65,3 +65,3 @@ * @license

*/
class C{#S;#k;constructor(t){this.#S=structuredClone(t)||[]}onGraphStart(){this.#S.push({graph:0,node:0})}onNodeStart(t){this.#S[this.#S.length-1].node++,this.#k=t}onNodeEnd(){}onGraphEnd(){}async state(){const t=structuredClone(this.#S);return this.#k&&(t[t.length-1].state=await l("nodestart",this.#k)),t}}var B="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.5.1/packages/schema/breadboard.schema.json";
class C{#S;#k;constructor(t){this.#S=structuredClone(t)||[]}onGraphStart(){this.#S.push({graph:0,node:0})}onNodeStart(t){this.#S[this.#S.length-1].node++,this.#k=t}onNodeEnd(){}onGraphEnd(){}async state(){const t=structuredClone(this.#S);return this.#k&&(t[t.length-1].state=await l("nodestart",this.#k)),t}}var q="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.6.0/packages/schema/breadboard.schema.json";
/**

@@ -72,3 +72,3 @@ * @license

*/
const q=async t=>{const e=await fetch(t);return await e.json()};class M{name="DefaultGraphProvider";#O=Promise.resolve();ready(){return this.#O}isSupported(){return!0}extendedCapabilities(){return{modify:!1,connect:!1,disconnect:!1,refresh:!1,watch:!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?q(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 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 B=async t=>{const e=await fetch(t);return await e.json()};class M{name="DefaultGraphProvider";#O=Promise.resolve();ready(){return this.#O}isSupported(){return!0}extendedCapabilities(){return{modify:!1,connect:!1,disconnect:!1,refresh:!1,watch:!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?B(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 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")}}
/**

@@ -94,3 +94,3 @@ * @license

*/
class W{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#j={};#N=[];constructor({url:t,title:e,description:r,version:s,$schema:n}={$schema:B}){Object.assign(this,{$schema:n??B,url:t,title:e,description:r,version:s})}async*run(t={},e){const{inputs:r,...n}=t,i=n.base||R;var o;yield*(o=async r=>{const{probe:o}=n,a=await W.handlersFromBoard(this,n.kits),u={...this.#j,...n.slots};this.#N.forEach((t=>t.addGraph(this)));const p=new c(this,e?.state),h=new O(t),d=n.invocationPath||[],l=new C(n.state);await(o?.report?.({type:"graphstart",data:{graph:this,path:d,timestamp:f()}}));let m=0;l.onGraphStart();const w=()=>[...d,m];for await(const t of p){n?.signal?.throwIfAborted(),m++;const{inputs:e,descriptor:p,missingInputs:c}=t;if(t.skip){await(o?.report?.({type:"skip",data:{node:p,inputs:e,missingInputs:c,path:w(),timestamp:f()}}));continue}let d;if(l.onNodeStart(t),await(o?.report?.({type:"nodestart",data:{node:p,inputs:e,path:w(),timestamp:f()},state:await l.state()})),"input"===p.type)await r(new g(t,await l.state(),m,w())),await $(this,n,p,t,w()),d=t.outputsPromise?_(t.outputsPromise,n,this.url):void 0;else if("output"===p.type)await A(e,p,n,w())||await r(new y(t,m,w())),d=t.outputsPromise;else{const o=a[p.type];if(!o)throw new Error(`No handler for node type "${p.type}"`);const c={...n,descriptor:p,board:this,outerGraph:this,base:i,slots:u,kits:[...n.kits||[],...this.kits],requestInput:h.createHandler(r,t),provideOutput:x(r,t,n),invocationPath:w(),state:await l.state()};d=s(o,V(e,n,this.url),c)}l.onNodeEnd(),await(o?.report?.({type:"nodeend",data:{node:p,inputs:e,outputs:await d,validatorMetadata:this.#N.map((t=>t.getValidatorMetadata(p))),path:w(),timestamp:f()}})),t.outputsPromise=d}l.onGraphEnd(),await(o?.report?.({type:"graphend",data:{path:d,timestamp:f()}}))},{[Symbol.asyncIterator]:()=>new N(o)})}get validators(){return this.#N}async runOnce(t,e={}){const r={...t,...this.args},{probe:s}=e;if(e.board&&e.descriptor)for(const t of e.board.validators)this.addValidator(t.getSubgraphValidator(e.descriptor,Object.keys(r)));try{let t={};const n=e.invocationPath||[];for await(const i of this.run(e))if("input"===i.type)i.inputs=r;else if("output"===i.type){t=i.outputs,await(s?.report?.({type:"nodeend",data:{node:i.node,inputs:i.inputs,outputs:t,path:[...n,i.invocationId],timestamp:f()}})),await(s?.report?.({type:"graphend",data:{path:n,timestamp:f()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#N.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const n=new v(t).describeGraph(s);return r?((t,e)=>`graph ${e};\n${t}`)(n,e):((t,e)=>`%%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%%\ngraph ${e};\n${t}\nclassDef default stroke:#ffab40,fill:#fff2ccff,color:#000\nclassDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000\nclassDef output stroke:#38761d,fill:#b6d7a8ff,color:#000\nclassDef passthrough stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef slot stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef config stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef secrets stroke:#db4437,fill:#f4cccc,color:#000\nclassDef slotted stroke:#a64d79`)(n,e)})(this,t,e,r)}static async fromGraphDescriptor(t){const e=new W(t);return e.edges=t.edges,e.nodes=t.nodes,e.graphs=t.graphs,e.args=t.args,e}static async load(t,e){const{base:r,slotted:s,outerGraph:n}=e||{},i=G(e.graphProviders),o=await i.load(t,{base:r,outerGraph:n});if(!o)throw new Error(`Unable to load graph from "${t}"`);const a=await W.fromGraphDescriptor(o);return a.#j=s||{},a}static async fromBreadboardCapability(t,e,r){if(!F(t))throw new Error(`Expected a "board" Capability, but got "${JSON.stringify(t)}`);if((t=>{const e=t.board;return!!e&&!!e.edges&&!!e.nodes})(t)){const e=t.board,r=e;return r.runOnce?r:await W.fromGraphDescriptor(e)}if((t=>!!t.url)(t)){if(!e||!r)throw new Error('The "board" Capability is a URL, but no loader and/or context was supplied.');const s=await e.load(t.url,r);if(!s)throw new Error(`Unable to load "board" Capability with the URL of ${t.url}.`);return W.fromGraphDescriptor(s)}if(T(t))throw new Error('Integrity error: somehow, the unresolved path "board" Capability snuck through the processing of inputs');throw new Error('Unsupported type of "board" Capability. Perhaps the supplied board isn\'t actually a GraphDescriptor?')}static async handlersFromBoard(t,e=[]){const r=[new H,...e,...t.kits];return n(r)}}class H{handlers;constructor(){this.handlers={lambda:{describe:async t=>({inputSchema:(new e).setAdditionalProperties(!0).addInputs(t).addProperty("board",{title:"board",description:"The board to run.",type:"object"}).build(),outputSchema:(new e).addProperty("board",{title:"board",description:"The now-runnable board.",type:"object"}).build()}),invoke:async t=>{const{board:e,...r}=t;if(!e||"board"!==e.kind||!e.board)throw new Error('Lambda node requires a BoardCapability as "board" input');const s={...await W.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}}
class W{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#j={};#N=[];constructor({url:t,title:e,description:r,version:s,$schema:n}={$schema:q}){Object.assign(this,{$schema:n??q,url:t,title:e,description:r,version:s})}async*run(t={},e){const{inputs:r,...n}=t,i=n.base||R;var o;yield*(o=async r=>{const{probe:o}=n,a=await W.handlersFromBoard(this,n.kits),u={...this.#j,...n.slots};this.#N.forEach((t=>t.addGraph(this)));const p=new c(this,e?.state),h=new O(t),d=n.invocationPath||[],l=new C(n.state);await(o?.report?.({type:"graphstart",data:{graph:this,path:d,timestamp:f()}}));let g=0;l.onGraphStart();const w=()=>[...d,g];for await(const t of p){n?.signal?.throwIfAborted(),g++;const{inputs:e,descriptor:p,missingInputs:c}=t;if(t.skip){await(o?.report?.({type:"skip",data:{node:p,inputs:e,missingInputs:c,path:w(),timestamp:f()}}));continue}let d;if(l.onNodeStart(t),await(o?.report?.({type:"nodestart",data:{node:p,inputs:e,path:w(),timestamp:f()},state:await l.state()})),"input"===p.type)await r(new m(t,await l.state(),g,w())),await $(this,n,p,t,w()),d=t.outputsPromise?_(t.outputsPromise,n,this.url):void 0;else if("output"===p.type)await A(e,p,n,w())||await r(new y(t,g,w())),d=t.outputsPromise;else{const o=a[p.type];if(!o)throw new Error(`No handler for node type "${p.type}"`);const c={...n,descriptor:p,board:this,outerGraph:this,base:i,slots:u,kits:[...n.kits||[],...this.kits],requestInput:h.createHandler(r,t),provideOutput:x(r,t,n),invocationPath:w(),state:await l.state()};d=s(o,V(e,n,this.url),c)}l.onNodeEnd(),await(o?.report?.({type:"nodeend",data:{node:p,inputs:e,outputs:await d,validatorMetadata:this.#N.map((t=>t.getValidatorMetadata(p))),path:w(),timestamp:f()}})),t.outputsPromise=d}l.onGraphEnd(),await(o?.report?.({type:"graphend",data:{path:d,timestamp:f()}}))},{[Symbol.asyncIterator]:()=>new N(o)})}get validators(){return this.#N}async runOnce(t,e={}){const r={...t,...this.args},{probe:s}=e;if(e.board&&e.descriptor)for(const t of e.board.validators)this.addValidator(t.getSubgraphValidator(e.descriptor,Object.keys(r)));try{let t={};const n=e.invocationPath||[];for await(const i of this.run(e))if("input"===i.type)i.inputs=r;else if("output"===i.type){t=i.outputs,await(s?.report?.({type:"nodeend",data:{node:i.node,inputs:i.inputs,outputs:t,path:[...n,i.invocationId],timestamp:f()}})),await(s?.report?.({type:"graphend",data:{path:n,timestamp:f()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#N.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const n=new v(t).describeGraph(s);return r?((t,e)=>`graph ${e};\n${t}`)(n,e):((t,e)=>`%%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%%\ngraph ${e};\n${t}\nclassDef default stroke:#ffab40,fill:#fff2ccff,color:#000\nclassDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000\nclassDef output stroke:#38761d,fill:#b6d7a8ff,color:#000\nclassDef passthrough stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef slot stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef config stroke:#a64d79,fill:#ead1dcff,color:#000\nclassDef secrets stroke:#db4437,fill:#f4cccc,color:#000\nclassDef slotted stroke:#a64d79`)(n,e)})(this,t,e,r)}static async fromGraphDescriptor(t){const e=new W(t);return e.edges=t.edges,e.nodes=t.nodes,e.graphs=t.graphs,e.args=t.args,e}static async load(t,e){const{base:r,slotted:s,outerGraph:n}=e||{},i=G(e.graphProviders),o=await i.load(t,{base:r,outerGraph:n});if(!o)throw new Error(`Unable to load graph from "${t}"`);const a=await W.fromGraphDescriptor(o);return a.#j=s||{},a}static async fromBreadboardCapability(t,e,r){if(!F(t))throw new Error(`Expected a "board" Capability, but got "${JSON.stringify(t)}`);if((t=>{const e=t.board;return!!e&&!!e.edges&&!!e.nodes})(t)){const e=t.board,r=e;return r.runOnce?r:await W.fromGraphDescriptor(e)}if((t=>!!t.url)(t)){if(!e||!r)throw new Error('The "board" Capability is a URL, but no loader and/or context was supplied.');const s=await e.load(t.url,r);if(!s)throw new Error(`Unable to load "board" Capability with the URL of ${t.url}.`);return W.fromGraphDescriptor(s)}if(T(t))throw new Error('Integrity error: somehow, the unresolved path "board" Capability snuck through the processing of inputs');throw new Error('Unsupported type of "board" Capability. Perhaps the supplied board isn\'t actually a GraphDescriptor?')}static async handlersFromBoard(t,e=[]){const r=[new H,...e,...t.kits];return n(r)}}class H{handlers;constructor(){this.handlers={lambda:{describe:async t=>({inputSchema:(new e).setAdditionalProperties(!0).addInputs(t).addProperty("board",{title:"board",description:"The board to run.",type:"object"}).build(),outputSchema:(new e).addProperty("board",{title:"board",description:"The now-runnable board.",type:"object"}).build()}),invoke:async t=>{const{board:e,...r}=t;if(!e||"board"!==e.kind||!e.board)throw new Error('Lambda node requires a BoardCapability as "board" input');const s={...await W.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}}
/**

@@ -116,3 +116,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/;class J extends K{id;type;outgoing=[];incoming=[];configuration={};metadata;#B;#q;constructor(t,e,r={}){super(),this.#q=e,"string"==typeof t?this.type=t:(this.type="fn",this.#B=t);const{$id:s,$metadata:n,...i}=r;this.id=s??Q.vendId(e,this.type),n&&(this.metadata=n),this.configuration=i}addIncomingEdge(t,e,r,s,n){if(t.#q!==this.#q)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)}#M(t){const e=this.#B??t.getHandler(this.type);return e&&"describe"in e&&e.describe?e.describe:void 0}async invoke(t,e){const r=e??this.#q,s=this.#B??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.#q,e,r,s){const n=this.#M(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#q.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 J extends K{id;type;outgoing=[];incoming=[];configuration={};metadata;#q;#B;constructor(t,e,r={}){super(),this.#B=e,"string"==typeof t?this.type=t:(this.type="fn",this.#q=t);const{$id:s,$metadata:n,...i}=r;this.id=s??Q.vendId(e,this.type),n&&(this.metadata=n),this.configuration=i}addIncomingEdge(t,e,r,s,n){if(t.#B!==this.#B)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)}#M(t){const e=this.#q??t.getHandler(this.type);return e&&"describe"in e&&e.describe?e.describe:void 0}async invoke(t,e){const r=e??this.#B,s=this.#q??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.#B,e,r,s){const n=this.#M(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#B.serialize(t,this)}async serializeNode(){const t={id:this.id,type:this.type,configuration:this.configuration};return this.metadata&&(t.metadata=this.metadata),[t]}}
/**

@@ -142,3 +142,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/const nt=Symbol("IsValue");function it(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[nt]}const ot=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 at extends st{#V;#q;#W;#H;#K;constructor(t,e,r,s=!1,n={}){super(),this.#V=t,this.#q=e,this.#W="string"==typeof r?{[r]:r}:r,this[nt]=this,this.#H=s,this.#K=n}then(t,e){if(1!==Object.keys(this.#W).length)throw Error("Can't `await` for multiple values");return this.#V.then((e=>e&&t&&this.#q.asScopeFor(t)(e[Object.keys(this.#W)[0]])),e&&this.#q.asScopeFor(e))}asNodeInput(){return[this.#V.unProxy(),this.#W,this.#H,this.#K]}to(t,e){const r=pt(t)?t.unProxy():new ut(t,this.#q,e);return r.addInputsFromNode(this.#V,this.#W,this.#H,this.#K),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#W).map((([t,e])=>[e,t])));it(t)?(e=t.#Q(e),this.#V.addInputsFromNode(t.#V,e,t.#H,t.#K)):pt(t)?this.#V.addInputsFromNode(t.unProxy(),e):this.#V.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#W).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#W)[0]]:t}}else e=this.#Q(t);return new at(this.#V,this.#q,e,this.#H,this.#K)}memoize(){return new at(this.#V,this.#q,this.#W,!0,this.#K)}invoke(t){return new ut("invoke",this.#q,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#K.type,this}isString(){return this.#K.type="string",this}isNumber(){return this.#K.type="number",this}isBoolean(){return this.#K.type="boolean",this}isArray(){return this.#K.type="array",this}isObject(){return this.#K.type="object",this}title(t){return this.#K.title=t,this}description(t){return this.#K.description=t,this}format(t){return ot(this.#K).format=t,this}examples(...t){return this.#K.examples=t,this}default(t){return this.#K.default=t,this}optional(){return this.#K.$optional=!0,this}behavior(...t){const e=ot(this.#K);return e.behavior??=[],e.behavior.push(...t),this}#Q(t){const e={...this.#W};return Object.entries(t).forEach((([t,r])=>{this.#W[r]?(e[t]=this.#W[r],delete this.#W[r]):e[t]=r})),e}}
*/const nt=Symbol("IsValue");function it(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[nt]}const ot=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 at extends st{#V;#B;#W;#H;#K;constructor(t,e,r,s=!1,n={}){super(),this.#V=t,this.#B=e,this.#W="string"==typeof r?{[r]:r}:r,this[nt]=this,this.#H=s,this.#K=n}then(t,e){if(1!==Object.keys(this.#W).length)throw Error("Can't `await` for multiple values");return this.#V.then((e=>e&&t&&this.#B.asScopeFor(t)(e[Object.keys(this.#W)[0]])),e&&this.#B.asScopeFor(e))}asNodeInput(){return[this.#V.unProxy(),this.#W,this.#H,this.#K]}to(t,e){const r=pt(t)?t.unProxy():new ut(t,this.#B,e);return r.addInputsFromNode(this.#V,this.#W,this.#H,this.#K),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#W).map((([t,e])=>[e,t])));it(t)?(e=t.#Q(e),this.#V.addInputsFromNode(t.#V,e,t.#H,t.#K)):pt(t)?this.#V.addInputsFromNode(t.unProxy(),e):this.#V.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#W).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#W)[0]]:t}}else e=this.#Q(t);return new at(this.#V,this.#B,e,this.#H,this.#K)}memoize(){return new at(this.#V,this.#B,this.#W,!0,this.#K)}invoke(t){return new ut("invoke",this.#B,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#K.type,this}isString(){return this.#K.type="string",this}isNumber(){return this.#K.type="number",this}isBoolean(){return this.#K.type="boolean",this}isArray(){return this.#K.type="array",this}isObject(){return this.#K.type="object",this}title(t){return this.#K.title=t,this}description(t){return this.#K.description=t,this}format(t){return ot(this.#K).format=t,this}examples(...t){return this.#K.examples=t,this}default(t){return this.#K.default=t,this}optional(){return this.#K.$optional=!0,this}behavior(...t){const e=ot(this.#K);return e.behavior??=[],e.behavior.push(...t),this}#Q(t){const e={...this.#W};return Object.entries(t).forEach((([t,r])=>{this.#W[r]?(e[t]=this.#W[r],delete this.#W[r]):e[t]=r})),e}}
/**

@@ -148,3 +148,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class ut extends J{#J;#X;#Y;#q;#B;constructor(t,e,r={}){const s=!pt(r)&&!(r instanceof K)&&!ht(r)&&!it(r)&&r.$id;if(super(t,e,s?{$id:s}:{}),this.#q=e,"string"!=typeof t&&(this.#B=t),pt(r))this.addInputsFromNode(r.unProxy());else if(r instanceof K)this.addInputsFromNode(r);else if(ht(r))this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()});else if(it(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.#Z()]=this,this.#J=new Promise(((t,e)=>{this.#X=t,this.#Y=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{ht(s)&&(s=s.getBoardCapabilityAsValue()),it(s)?r.push(s.as(t).asNodeInput()):s instanceof K||pt(s)?r.push([pt(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(pt(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const i=t.#q;if(i!==this.#q){for(let t=this.#q;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.#q.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 Z({dynamicScope:e,lexicalScope:this.#q});return r.asScopeFor((async()=>{try{const e=this.#B??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 ut?s[t]=(await e)[t]:it(e)?s[t]=await e:ht(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#X&&(this.#X(s),this.#X=this.#Y=void 0),s}catch(t){throw this.#Y&&(this.#Y(t),this.#X=this.#Y=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 Z({lexicalScope:this.#q,serialize:!0}),e=this.#B??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 at(t,t.#q,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.#Z()]})}unProxy(){return this}then(t,e){if(this.#q.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.#q.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#q.asScopeFor(e));throw t})),this.#J.then(t&&this.#q.asScopeFor(t),e&&this.#q.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#q.asScopeFor(e));throw t}}to(t,e){const r=pt(t)?t.unProxy():new ut(t,this.#q,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof J?this.addInputsFromNode(t):it(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new at(this,this.#q,t)}keys(){return[this.#Z()]}#Z(){return"*-"+this.id}}function pt(t){return"function"==typeof t.unProxy}
*/class ut extends J{#J;#X;#Y;#B;#q;constructor(t,e,r={}){const s=!pt(r)&&!(r instanceof K)&&!ht(r)&&!it(r)&&r.$id;if(super(t,e,s?{$id:s}:{}),this.#B=e,"string"!=typeof t&&(this.#q=t),pt(r))this.addInputsFromNode(r.unProxy());else if(r instanceof K)this.addInputsFromNode(r);else if(ht(r))this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()});else if(it(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.#Z()]=this,this.#J=new Promise(((t,e)=>{this.#X=t,this.#Y=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{ht(s)&&(s=s.getBoardCapabilityAsValue()),it(s)?r.push(s.as(t).asNodeInput()):s instanceof K||pt(s)?r.push([pt(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(pt(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const i=t.#B;if(i!==this.#B){for(let t=this.#B;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.#B.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 Z({dynamicScope:e,lexicalScope:this.#B});return r.asScopeFor((async()=>{try{const e=this.#q??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 ut?s[t]=(await e)[t]:it(e)?s[t]=await e:ht(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#X&&(this.#X(s),this.#X=this.#Y=void 0),s}catch(t){throw this.#Y&&(this.#Y(t),this.#X=this.#Y=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 Z({lexicalScope:this.#B,serialize:!0}),e=this.#q??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 at(t,t.#B,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.#Z()]})}unProxy(){return this}then(t,e){if(this.#B.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.#B.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#B.asScopeFor(e));throw t})),this.#J.then(t&&this.#B.asScopeFor(t),e&&this.#B.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#B.asScopeFor(e));throw t}}to(t,e){const r=pt(t)?t.unProxy():new ut(t,this.#B,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof J?this.addInputsFromNode(t):it(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new at(this,this.#B,t)}keys(){return[this.#Z()]}#Z(){return"*-"+this.id}}function pt(t){return"function"==typeof t.unProxy}
/**

@@ -170,3 +170,3 @@ * @license

*/
var lt,ft;ct("input",dt),ct("output",dt),function(t){t.Ordinary="ordinary",t.Constant="constant",t.Control="control",t.Star="star"}(lt||(lt={})),function(t){t.Indeterminate="indeterminate",t.Connected="connected",t.Ready="ready",t.Missing="missing",t.Dangling="dangling"}(ft||(ft={}));class mt{#tt;#et;constructor(t,e){this.#tt=t,this.#et=e}get from(){const t=this.#tt.get(this.#et.from);return console.assert(t,"From node not found when getting from."),t}get out(){return this.#et.out}get to(){const t=this.#tt.get(this.#et.to);return console.assert(t,"To node not found when getting to."),t}get in(){return"*"===this.#et.out?"*":this.#et.in}get type(){return"*"===this.#et.out?lt.Star:""===this.#et.out?lt.Control:this.#et.constant?lt.Constant:lt.Ordinary}async outPort(){return(await this.from.ports()).outputs.ports.find((t=>t.name===this.out))}async inPort(){return(await this.to.ports()).inputs.ports.find((t=>t.name===this.in))}async validate(){const[t,e]=await Promise.all([this.outPort(),this.inPort()]);if(void 0===t||void 0===e)return{status:"unknown"};const r=t.type.analyzeCanConnect(e.type);return r.canConnect?{status:"valid"}:{status:"invalid",errors:r.details}}}class gt{#tt;#C=new Map;constructor(t){this.#tt=t}populate(t){return this.#C=new Map(t.edges.map((t=>[t,new mt(this.#tt,t)])))}get(t){return this.#C.get(t)}getOrCreate(t){let e=this.get(t);return e||(e=new mt(this.#tt,t),this.add(t),e)}add(t){console.assert(!this.#C.has(t),"Edge already exists when adding."),this.#C.set(t,new mt(this.#tt,t))}remove(t){console.assert(this.#C.has(t),"Edge not found when removing."),this.#C.delete(t)}has(t){return this.#C.has(t)}hasByValue(t){t=(t=>"*"===t.out?{...t,in:"*"}:t)(t);return!!this.edges().find((e=>e.from.descriptor.id===t.from&&e.to.descriptor.id===t.to&&e.out===t.out&&e.in===t.in))}edges(){return Array.from(this.#C.values())}}
var lt,ft;ct("input",dt),ct("output",dt),function(t){t.Ordinary="ordinary",t.Constant="constant",t.Control="control",t.Star="star"}(lt||(lt={})),function(t){t.Indeterminate="indeterminate",t.Connected="connected",t.Ready="ready",t.Missing="missing",t.Dangling="dangling"}(ft||(ft={}));class gt{#tt;#et;constructor(t,e){this.#tt=t,this.#et=e}get from(){const t=this.#tt.get(this.#et.from);return console.assert(t,"From node not found when getting from."),t}get out(){return this.#et.out}get to(){const t=this.#tt.get(this.#et.to);return console.assert(t,"To node not found when getting to."),t}get in(){return"*"===this.#et.out?"*":this.#et.in}get type(){return"*"===this.#et.out?lt.Star:""===this.#et.out?lt.Control:this.#et.constant?lt.Constant:lt.Ordinary}async outPort(){return(await this.from.ports()).outputs.ports.find((t=>t.name===this.out))}async inPort(){return(await this.to.ports()).inputs.ports.find((t=>t.name===this.in))}async validate(){const[t,e]=await Promise.all([this.outPort(),this.inPort()]);if(void 0===t||void 0===e)return{status:"unknown"};const r=t.type.analyzeCanConnect(e.type);return r.canConnect?{status:"valid"}:{status:"invalid",errors:r.details}}}class mt{#tt;#C=new Map;constructor(t){this.#tt=t}populate(t){return this.#C=new Map(t.edges.map((t=>[t,new gt(this.#tt,t)])))}get(t){return this.#C.get(t)}getOrCreate(t){let e=this.get(t);return e||(e=new gt(this.#tt,t),this.add(t),e)}add(t){console.assert(!this.#C.has(t),"Edge already exists when adding."),this.#C.set(t,new gt(this.#tt,t))}remove(t){console.assert(this.#C.has(t),"Edge not found when removing."),this.#C.delete(t)}has(t){return this.#C.has(t)}hasByValue(t){t=(t=>"*"===t.out?{...t,in:"*"}:t)(t);return!!this.edges().find((e=>e.from.descriptor.id===t.from&&e.to.descriptor.id===t.to&&e.out===t.out&&e.in===t.in))}edges(){return Array.from(this.#C.values())}}
/**

@@ -181,3 +181,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/var xt;!function(t){t[t.In=0]="In",t[t.Out=1]="Out"}(xt||(xt={}));const It={type:"object",behavior:["json-schema","ports-spec","config"]},jt={type:"string"},Nt=t=>{const e=t.type;return e===lt.Star||e===lt.Control},Ct=(t,e,r=!1)=>e?e.reduce(((e,s)=>{if(!r&&Nt(s))return e;const n=t===xt.In?s.in:s.out;return e[n]||(e[n]=jt),e}),{}):{},Bt=(t,r,s=!1)=>r?(new e).addProperties(Ct(t,r,s)).setAdditionalProperties(!0).build():{},qt=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).addProperty("schema",It).build();let i=!1;const o=t.outgoing?.filter((t=>{const e=Nt(t);return e&&(i=!0),!e})),a=r([Bt(xt.Out,o,!0),s]);return t.asType&&(i||(a.additionalProperties=!1)),{inputSchema:n,outputSchema:a}},Mt=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).setAdditionalProperties(!1).build(),i=(new e).addProperty("schema",It),o=r([i.addProperties(Ct(xt.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}},Rt=(t,e)=>t.properties?.[e]?.title||e,Lt=(t,e,r,s)=>t?e?ft.Connected:s?ft.Indeterminate:ft.Dangling:r?s?ft.Indeterminate:ft.Missing:ft.Ready,Dt={deprecated:!1,transient:!1,config:!1,bubble:!0,board:!0,stream:!0,error:!0,"llm-content":!0,"json-schema":!0,"ports-spec":!0,image:!0,code:!0},Ut=(t,e,r,s,n,i)=>{let o=!1;const a=e.map((e=>"*"===e.out?(o=!0,"*"):t===xt.In?e.in:e.out)),u=!1===r.additionalProperties,p=Object.keys(r.properties||{});s&&p.push("$error");const c=p.includes("*"),h=r.required||[],d=Object.keys(i||{}),l=[...new Set([...a,...p,...d,"*",""])];return l.sort(),l.map((s=>{const l="*"===s||""===s,f=d.includes(s),m=a.includes(s),g=p.includes(s)||l,y=h.includes(s),w=r.properties?.[s]||jt;return w.behavior?.includes("deprecated")&&!m?null:{name:s,title:Rt(r,s),configured:f,value:i?.[s],star:l,get edges(){return m?e.filter((e=>!("*"!==e.out||!l)||(t===xt.In?e.in===s:e.out===s))):[]},status:Lt(m||f,!u||g||c,n&&y,o),schema:w,type:new Gt(w),kind:t===xt.In?"input":"output"}})).filter(Boolean)};class Gt{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=$t(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(Dt[e]&&!r.has(e))return{canConnect:!1,details:[{message:"Incompatible behaviors",detail:{outputPath:["behavior"],inputPath:["behavior"]}}]};return{canConnect:!0}}}const Ft=(t,e)=>{const r=Object.keys(t.properties||{}),s=t.required||[];return r.sort(),r.map((r=>{const n=t.properties?.[r]||jt;return{name:r,title:Rt(t,r),configured:!1,star:!1,edges:[],value:null,status:Lt(!1,!0,s.includes(r),!1),schema:n,type:new Gt(n),kind:e}}))},Tt=t=>Object.entries(t).sort().map((([t,e])=>new zt(t,e)));
*/var xt;!function(t){t[t.In=0]="In",t[t.Out=1]="Out"}(xt||(xt={}));const It={type:"object",behavior:["json-schema","ports-spec","config"]},jt={type:"string"},Nt=t=>{const e=t.type;return e===lt.Star||e===lt.Control},Ct=(t,e,r=!1)=>e?e.reduce(((e,s)=>{if(!r&&Nt(s))return e;const n=t===xt.In?s.in:s.out;return e[n]||(e[n]=jt),e}),{}):{},qt=(t,r,s=!1)=>r?(new e).addProperties(Ct(t,r,s)).setAdditionalProperties(!0).build():{},Bt=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).addProperty("schema",It).build();let i=!1;const o=t.outgoing?.filter((t=>{const e=Nt(t);return e&&(i=!0),!e})),a=r([qt(xt.Out,o,!0),s]);return t.asType&&(i||(a.additionalProperties=!1)),{inputSchema:n,outputSchema:a}},Mt=t=>{const s=t.inputs?.schema||{type:"object"},n=(new e).setAdditionalProperties(!1).build(),i=(new e).addProperty("schema",It),o=r([i.addProperties(Ct(xt.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}},Rt=(t,e)=>t.properties?.[e]?.title||e,Lt=(t,e,r,s)=>t?e?ft.Connected:s?ft.Indeterminate:ft.Dangling:r?s?ft.Indeterminate:ft.Missing:ft.Ready,Dt={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},Ut=(t,e,r,s,n,i)=>{let o=!1;const a=e.map((e=>"*"===e.out?(o=!0,"*"):t===xt.In?e.in:e.out)),u=!1===r.additionalProperties,p=Object.keys(r.properties||{});s&&p.push("$error");const c=p.includes("*"),h=r.required||[],d=Object.keys(i||{}),l=[...new Set([...a,...p,...d,"*",""])];return l.sort(),l.map((s=>{const l="*"===s||""===s,f=d.includes(s),g=a.includes(s),m=p.includes(s)||l,y=h.includes(s),w=r.properties?.[s]||jt;return w.behavior?.includes("deprecated")&&!g?null:{name:s,title:Rt(r,s),configured:f,value:i?.[s],star:l,get edges(){return g?e.filter((e=>!("*"!==e.out||!l)||(t===xt.In?e.in===s:e.out===s))):[]},status:Lt(g||f,!u||m||c,n&&y,o),schema:w,type:new Gt(w),kind:t===xt.In?"input":"output"}})).filter(Boolean)};class Gt{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=$t(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(Dt[e]&&!r.has(e))return{canConnect:!1,details:[{message:"Incompatible behaviors",detail:{outputPath:["behavior"],inputPath:["behavior"]}}]};return{canConnect:!0}}}const Ft=(t,e)=>{const r=Object.keys(t.properties||{}),s=t.required||[];return r.sort(),r.map((r=>{const n=t.properties?.[r]||jt;return{name:r,title:Rt(t,r),configured:!1,star:!1,edges:[],value:null,status:Lt(!1,!0,s.includes(r),!1),schema:n,type:new Gt(n),kind:e}}))},Tt=t=>Object.entries(t).sort().map((([t,e])=>new zt(t,e)));
/**

@@ -187,3 +187,3 @@ * @license

* SPDX-License-Identifier: Apache-2.0
*/class zt{#i;#B;constructor(t,e){this.#i=t,this.#B=e}metadata(){return"metadata"in this.#B&&this.#B.metadata||{}}type(){return this.#i}async ports(){if("function"==typeof this.#B||!this.#B.describe)return Vt();try{const t=await this.#B.describe();return{inputs:{fixed:!1===t.inputSchema.additionalProperties,ports:Ft(t.inputSchema,"input")},outputs:{fixed:!1===t.outputSchema.additionalProperties,ports:Ft(t.outputSchema,"output")}}}catch(t){return console.warn(`Error describing node type ${this.#i}:`,t),Vt()}}}class _t extends zt{constructor(t,e,r){super(t,{invoke:async()=>{},describe:async()=>e({}),metadata:r})}}const Vt=()=>({inputs:{ports:[],fixed:!1},outputs:{ports:[],fixed:!1}})
*/class zt{#i;#q;constructor(t,e){this.#i=t,this.#q=e}metadata(){return"metadata"in this.#q&&this.#q.metadata||{}}type(){return this.#i}async ports(){if("function"==typeof this.#q||!this.#q.describe)return Vt();try{const t=await this.#q.describe();return{inputs:{fixed:!1===t.inputSchema.additionalProperties,ports:Ft(t.inputSchema,"input")},outputs:{fixed:!1===t.outputSchema.additionalProperties,ports:Ft(t.outputSchema,"output")}}}catch(t){return console.warn(`Error describing node type ${this.#i}:`,t),Vt()}}}class _t extends zt{constructor(t,e,r){super(t,{invoke:async()=>{},describe:async()=>e({}),metadata:r})}}const Vt=()=>({inputs:{ports:[],fixed:!1},outputs:{ports:[],fixed:!1}})
/**

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

* SPDX-License-Identifier: Apache-2.0
*/var Kt;class Qt{#ut;#pt;#ct;#ht;#rt;#l;#dt=null;constructor(t,e){this.#rt=t,this.#ut=(t=>{t=t||"";try{return new URL(t)}catch{return}})(t.url),this.#ht=e||{};const r=new Ht(this),s=new gt(r);s.populate(t),this.#l={edges:s,nodes:r}}raw(){return this.#rt}metadata(){return this.#rt.metadata}nodesByType(t){return this.#l.nodes.byType(t)}async describeType(t,e={}){if("input"===t)return qt(e);if("output"===t)return Mt(e);const{kits:r}=this.#ht,s=n(r||[])[t],i={inputSchema:Bt(xt.In,e?.incoming),outputSchema:Bt(xt.Out,e?.outgoing)};if(!s||!("describe"in s)||!s.describe)return i;const o=this.#ht.loader||G(),a={outerGraph:this.#rt,loader:o,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.#ut&&(a.base=this.#ut);try{return s.describe(e?.inputs||void 0,i.inputSchema,i.outputSchema,a)}catch(e){return console.warn(`Error describing node type ${t}`,e),i}}nodeById(t){return this.#l.nodes.get(t)}nodes(){return this.#l.nodes.nodes()}edges(){return this.#l.edges.edges()}hasEdge(t){return this.#l.edges.hasByValue(t)}kits(){return this.#pt??=(t=this.#ht.kits||[],[{descriptor:{title:"Built-in Kit",description:"A kit containing built-in Breadboard nodes",url:""},nodeTypes:[new _t("input",qt,{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 _t("output",Mt,{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"}})]},...t.map((t=>({descriptor:{title:t.title,description:t.description,url:t.url},nodeTypes:Tt(t.handlers)})))]);var t}typeForNode(t){const e=this.nodeById(t);if(e)return this.typeById(e.descriptor.type)}typeById(t){const e=this.kits();return this.#ct??=new Map(e.flatMap((t=>t.nodeTypes.map((t=>[t.type(),t]))))),this.#ct.get(t)}incomingForNode(t){return this.#rt.edges.filter((e=>e.to===t)).map((t=>this.#l.edges.getOrCreate(t)))}outgoingForNode(t){return this.#rt.edges.filter((e=>e.from===t)).map((t=>this.#l.edges.getOrCreate(t)))}entries(){return this.#l.nodes.nodes().filter((t=>t.isEntry()))}async describe(){const t=(await Promise.all(this.nodesByType("input").filter((t=>t.isEntry())).map((t=>qt({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=>Mt({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")}}get nodeStore(){return this.#l.nodes}get edgeStore(){return this.#l.edges}updateGraph(t){this.#rt=t}resetGraph(t){this.#rt=t;const e=new Ht(this),r=new gt(e);r.populate(t),this.#l={edges:r,nodes:e},this.#dt=null}#lt(){const t=this.#rt.graphs;return t?Object.fromEntries(Object.entries(t).map((([t,e])=>[t,new Kt(e,this.#ht)]))):{}}graphs(){return this.#dt??=this.#lt()}}Kt=Qt;
*/var Kt;class Qt{#ut;#pt;#ct;#ht;#rt;#l;#dt=null;constructor(t,e){this.#rt=t,this.#ut=(t=>{t=t||"";try{return new URL(t)}catch{return}})(t.url),this.#ht=e||{};const r=new Ht(this),s=new mt(r);s.populate(t),this.#l={edges:s,nodes:r}}raw(){return this.#rt}metadata(){return this.#rt.metadata}nodesByType(t){return this.#l.nodes.byType(t)}async describeType(t,e={}){if("input"===t)return Bt(e);if("output"===t)return Mt(e);const{kits:r}=this.#ht,s=n(r||[])[t],i={inputSchema:qt(xt.In,e?.incoming),outputSchema:qt(xt.Out,e?.outgoing)};if(!s||!("describe"in s)||!s.describe)return i;const o=this.#ht.loader||G(),a={outerGraph:this.#rt,loader:o,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.#ut&&(a.base=this.#ut);try{return s.describe(e?.inputs||void 0,i.inputSchema,i.outputSchema,a)}catch(e){return console.warn(`Error describing node type ${t}`,e),i}}nodeById(t){return this.#l.nodes.get(t)}nodes(){return this.#l.nodes.nodes()}edges(){return this.#l.edges.edges()}hasEdge(t){return this.#l.edges.hasByValue(t)}kits(){return this.#pt??=(t=this.#ht.kits||[],[{descriptor:{title:"Built-in Kit",description:"A kit containing built-in Breadboard nodes",url:""},nodeTypes:[new _t("input",Bt,{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 _t("output",Mt,{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"}})]},...t.map((t=>({descriptor:{title:t.title,description:t.description,url:t.url,tags:t.tags||[]},nodeTypes:Tt(t.handlers)})))]);var t}typeForNode(t){const e=this.nodeById(t);if(e)return this.typeById(e.descriptor.type)}typeById(t){const e=this.kits();return this.#ct??=new Map(e.flatMap((t=>t.nodeTypes.map((t=>[t.type(),t]))))),this.#ct.get(t)}incomingForNode(t){return this.#rt.edges.filter((e=>e.to===t)).map((t=>this.#l.edges.getOrCreate(t)))}outgoingForNode(t){return this.#rt.edges.filter((e=>e.from===t)).map((t=>this.#l.edges.getOrCreate(t)))}entries(){return this.#l.nodes.nodes().filter((t=>t.isEntry()))}async describe(){const t=(await Promise.all(this.nodesByType("input").filter((t=>t.isEntry())).map((t=>Bt({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=>Mt({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")}}get nodeStore(){return this.#l.nodes}get edgeStore(){return this.#l.edges}updateGraph(t){this.#rt=t}resetGraph(t){this.#rt=t;const e=new Ht(this),r=new mt(e);r.populate(t),this.#l={edges:r,nodes:e},this.#dt=null}#lt(){const t=this.#rt.graphs;return t?Object.fromEntries(Object.entries(t).map((([t,e])=>[t,new Kt(e,this.#ht)]))):{}}graphs(){return this.#dt??=this.#lt()}}Kt=Qt;
/**

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

* SPDX-License-Identifier: Apache-2.0
*/class Yt{url;title;description;version;namespacePrefix;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n=""}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n}#mt(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}=this,o=this.#mt(t),a=Object.keys(t);return class{title=s;description=n;version=i;url=e;get handlers(){return o}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n?s[n]:a.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 Yt(t).build(r)}}
*/class Yt{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}#gt(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.#gt(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 Yt(t).build(r)}}
/**

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

* SPDX-License-Identifier: Apache-2.0
*/class Zt{#gt;#i;#rt;metadata;constructor(t,e,r){this.#gt=t,this.#i=e,this.#rt=((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.#rt;this.metadata={title:s,description:n},i?.deprecated&&(this.metadata.deprecated=i.deprecated),i?.icon&&(this.metadata.icon=i.icon)}async describe(){return await Jt(this.#rt).describe()}async invoke(t,e){const r=await W.fromGraphDescriptor(this.#rt);return await r.runOnce(t,e)}}const te=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 Zt(i,t,e)]))))};var i,o},ee=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 q(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 te(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{Xt as GraphToKitAdapter,Yt as KitBuilder,e as SchemaBuilder,te as fromManifest,ee as load};
*/class Zt{#mt;#i;#rt;metadata;constructor(t,e,r){this.#mt=t,this.#i=e,this.#rt=((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.#rt;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)}async describe(){return await Jt(this.#rt).describe()}async invoke(t,e){const r=await W.fromGraphDescriptor(this.#rt);return await r.runOnce(t,e)}}const te=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 Zt(i,t,e)]))))};var i,o},ee=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 B(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 te(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{Xt as GraphToKitAdapter,Yt as KitBuilder,e as SchemaBuilder,te as fromManifest,ee as load};
//# sourceMappingURL=kits.min.js.map

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

*/
class y{url;title;description;version;namespacePrefix;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n=""}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n}#l(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:a}=this,o=this.#l(t),i=Object.keys(t);return class{title=s;description=n;version=a;url=e;get handlers(){return o}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n?s[n]:i.includes(n)?(s={})=>{const a=t.getConfigWithLambda(s),{$id:o,...i}=a;return t.create(e,`${r}${n}`,{...i},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 a=await s(...r);return"object"!=typeof a||Array.isArray(a)?{result:a}:{...a}}},t}),{});return new y(t).build(r)}}
class y{url;title;description;version;namespacePrefix;tags;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n="",tags:a=[]}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n,this.tags=a}#l(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:a,tags:o}=this,i=this.#l(t),u=Object.keys(t);return class{title=s;description=n;version=a;url=e;tags=o;get handlers(){return i}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 a=t.getConfigWithLambda(s),{$id:o,...i}=a;return t.create(e,`${r}${n}`,{...i},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 a=await s(...r);return"object"!=typeof a||Array.isArray(a)?{result:a}:{...a}}},t}),{});return new y(t).build(r)}}
/**

@@ -39,3 +39,3 @@ * @license

*/
const j=async(t,e)=>{const r=async e=>{if((t=>"object"==typeof t&&null!==t&&("storedData"in t&&!!t.storedData.handle))(e)){const r=await t.retrieveAsBlob(e);return{inlineData:{data:await async function(t){return"Buffer"in globalThis?Buffer.from(await t.arrayBuffer()).toString("base64"):new Promise(((e,r)=>{const s=new FileReader;s.onload=()=>{if("string"!=typeof s.result)return void r("Reader result is not a string");const[,t]=s.result.split(",");e(t)},s.onerror=t=>r(t),s.readAsDataURL(t)}))}(r),mimeType:r.type}}}if(Array.isArray(e)){const t=[];for(const s of e)t.push(await r(s));return t}if("object"==typeof e&&null!==e){const t=e,s={};for(const n in e)s[n]=await r(t[n]);return s}return e};return await r(e)},q=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r};
const j=async(t,e)=>{const r=async e=>{if((t=>"object"==typeof t&&null!==t&&("storedData"in t&&"string"==typeof t.storedData.handle))(e)){const r=await t.retrieveAsBlob(e);return{inlineData:{data:await async function(t){return"Buffer"in globalThis?Buffer.from(await t.arrayBuffer()).toString("base64"):new Promise(((e,r)=>{const s=new FileReader;s.onload=()=>{if("string"!=typeof s.result)return void r("Reader result is not a string");const[,t]=s.result.split(",");e(t)},s.onerror=t=>r(t),s.readAsDataURL(t)}))}(r),mimeType:r.type}}}if(Array.isArray(e)){const t=[];for(const s of e)t.push(await r(s));return t}if("object"==typeof e&&null!==e){const t=e,s={};for(const n in e)s[n]=await r(t[n]);return s}return e};return await r(e)},q=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r};
/**

@@ -42,0 +42,0 @@ * @license

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

*/
import { InlineDataCapabilityPart, StoredDataCapabilityPart } from "./types.js";
import { FunctionCallCapabilityPart, FunctionResponseCapabilityPart, InlineDataCapabilityPart, LLMContent, StoredDataCapabilityPart, TextCapabilityPart } from "./types.js";
import { DataCapability } from "../types.js";
export declare function isTextCapabilityPart(part: unknown): part is TextCapabilityPart;
export declare function isFunctionCallCapabilityPart(part: unknown): part is FunctionCallCapabilityPart;
export declare function isFunctionResponseCapabilityPart(part: unknown): part is FunctionResponseCapabilityPart;
export declare function isLLMContent(nodeValue: unknown): nodeValue is LLMContent;
export declare const isDataCapability: (value: unknown) => value is DataCapability;

@@ -13,3 +17,4 @@ export declare const asBlob: (part: InlineDataCapabilityPart | StoredDataCapabilityPart) => Promise<Blob>;

export declare const isInlineData: (value: unknown) => value is InlineDataCapabilityPart;
export declare const isSerializedData: (value: unknown) => value is InlineDataCapabilityPart;
export declare function asBase64(file: File | Blob): Promise<string>;
//# sourceMappingURL=common.d.ts.map

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

// Helpers for handling DataCapability objects.
export function isTextCapabilityPart(part) {
if (typeof part !== "object" || part === null)
return false;
return "text" in part;
}
export function isFunctionCallCapabilityPart(part) {
if (typeof part !== "object" || part === null)
return false;
return "functionCall" in part;
}
export function isFunctionResponseCapabilityPart(part) {
if (typeof part !== "object" || part === null)
return false;
return "functionResponse" in part;
}
export function isLLMContent(nodeValue) {
if (typeof nodeValue !== "object" || !nodeValue)
return false;
return ("parts" in nodeValue &&
Array.isArray(nodeValue.parts) &&
"role" in nodeValue);
}
export const isDataCapability = (value) => {

@@ -38,3 +60,3 @@ if (typeof value !== "object" || value === null)

return false;
if (!data.storedData.handle)
if (typeof data.storedData.handle !== "string")
return false;

@@ -49,6 +71,18 @@ return true;

return false;
if (!data.inlineData.data)
if (typeof data.inlineData.data !== "string")
return false;
return true;
};
export const isSerializedData = (value) => {
if (typeof value !== "object" || value === null)
return false;
const data = value;
if (!("inlineData" in data))
return false;
if (!("handle" in data))
return false;
if (typeof data.inlineData.data !== "string")
return false;
return true;
};
export async function asBase64(file) {

@@ -55,0 +89,0 @@ if ("Buffer" in globalThis) {

@@ -1,10 +0,6 @@

/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { DataStore } from "./types.js";
export declare const createDataStore: () => DataStore;
export declare const createDefaultDataStore: () => DataStore;
export { inflateData, deflateData } from "./inflate-deflate.js";
export { isDataCapability, asBlob } from "./common.js";
export { isFunctionCallCapabilityPart, isFunctionResponseCapabilityPart, isLLMContent, isTextCapabilityPart, isDataCapability, isInlineData, isStoredData, isSerializedData, asBlob, asBase64, } from "./common.js";
export type { DataStore, FunctionCallCapabilityPart, FunctionResponseCapabilityPart, LLMContent, TextCapabilityPart, StoredDataCapabilityPart, InlineDataCapabilityPart, } from "./types.js";
//# sourceMappingURL=index.d.ts.map

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

*/
import { SimpleDataStore } from "./simple.js";
export const createDataStore = () => {
return new SimpleDataStore();
import { DefaultDataStore } from "./default-store.js";
export const createDefaultDataStore = () => {
return new DefaultDataStore();
};
export { inflateData, deflateData } from "./inflate-deflate.js";
export { isDataCapability, asBlob } from "./common.js";
export { isFunctionCallCapabilityPart, isFunctionResponseCapabilityPart, isLLMContent, isTextCapabilityPart, isDataCapability, isInlineData, isStoredData, isSerializedData, asBlob, asBase64, } from "./common.js";
//# sourceMappingURL=index.js.map

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

*/
export type FunctionCallCapabilityPart = {
functionCall: {
name: string;
args: object;
};
};
export type FunctionResponseCapabilityPart = {
functionResponse: {
name: string;
response: object;
};
};
export type TextCapabilityPart = {
text: string;
};
export type DataPart = InlineDataCapabilityPart | StoredDataCapabilityPart | FunctionCallCapabilityPart | FunctionResponseCapabilityPart | TextCapabilityPart;
export type LLMContent = {
role?: string;
parts: DataPart[];
};
/**

@@ -49,5 +69,8 @@ * Represents inline data, encoded as a base64 string.

releaseGroup(group: number): void;
releaseAll(): void;
serializeGroup(group: number): Promise<SerializedDataStoreGroup | null>;
retrieveAsURL(storedData: StoredDataCapabilityPart): Promise<string>;
copyToNewestGroup(storedData: StoredDataCapabilityPart): Promise<StoredDataCapabilityPart>;
drop(): Promise<void>;
};
//# sourceMappingURL=types.d.ts.map

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

export { serve, defineServeConfig } from "./serve.js";
export { run, type HarnessProxyConfig, type HarnessRemoteConfig, type RunConfig, } from "./run.js";
export { run } from "./run.js";
export type * from "./serve.js";

@@ -11,0 +11,0 @@ export { type KitConfig } from "./kits.js";

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

export { serve, defineServeConfig } from "./serve.js";
export { run, } from "./run.js";
export { run } from "./run.js";
export { createWorker } from "./worker.js";
export { createSecretAskingKit } from "./secrets.js";
//# sourceMappingURL=index.js.map

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

import { Kit } from "../types.js";
import { RunConfig } from "./run.js";
import { HarnessRunResult } from "./types.js";
import { HarnessRunResult, RunConfig } from "./types.js";
export declare function runLocally(config: RunConfig, kits: Kit[]): AsyncGenerator<HarnessRunResult, void, unknown>;
//# sourceMappingURL=local.d.ts.map

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

*/
import { Board, asyncGen, createDataStore } from "../index.js";
import { createDefaultDataStore } from "../data/index.js";
import { Board, RunResult, asyncGen } from "../index.js";
import { createLoader } from "../loader/index.js";
import { saveRunnerState } from "../serialization.js";
import { timestamp } from "../timestamp.js";

@@ -34,2 +36,11 @@ import { Diagnostics } from "./diagnostics.js";

const bubbled = invocationId == -1;
const saveState = async () => {
return [
{
graph: 0,
node: invocationId,
state: await saveRunnerState(type, result.state),
},
];
};
if (type === "input") {

@@ -43,2 +54,3 @@ const { inputArguments, path } = result;

},
saveState,
};

@@ -54,2 +66,3 @@ }

},
saveState,
};

@@ -86,2 +99,12 @@ }

};
const createPreviousRunResult = (resumeFrom) => {
if (resumeFrom?.state?.[0].state) {
const result = RunResult.load(resumeFrom.state[0].state);
if (resumeFrom.inputs) {
result.inputs = resumeFrom.inputs;
}
return result;
}
return undefined;
};
export async function* runLocally(config, kits) {

@@ -91,3 +114,4 @@ yield* asyncGen(async (next) => {

const loader = config.loader || createLoader();
const store = config.store || createDataStore();
const store = config.store || createDefaultDataStore();
const resumeFrom = createPreviousRunResult(config.resumeFrom);
try {

@@ -107,3 +131,3 @@ const probe = config.diagnostics

inputs: config.inputs,
})) {
}, resumeFrom)) {
await next(fromRunnerResult(data));

@@ -110,0 +134,0 @@ }

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

*/
import { BreadboardRunner, DataStore, InputValues, Kit } from "../index.js";
import { NodeProxyConfig } from "../remote/config.js";
import { HarnessRunResult } from "./types.js";
import { GraphLoader } from "../loader/types.js";
export type ProxyLocation = "main" | "worker" | "http" | "python";
export type CustomProxyConfig = () => Promise<Kit>;
export type HarnessProxyConfig = {
location: ProxyLocation;
url?: string;
nodes: NodeProxyConfig;
} | CustomProxyConfig;
export type HarnessRemoteConfig = {
/**
* The type of the remote runtime. Can be "http" or "worker".
* Currently, only "worker" is supported.
*/
type: "http" | "worker";
/**
* The URL of the remote runtime. Specifies the URL of the worker
* script if `type` is "worker", or the URL of the runtime server if
* `type` is "http".
*/
url: string;
} | false;
export type RunConfig = {
/**
* The URL of the board to run.
*/
url: string;
/**
* The base URL relative to which to load the board.
* If ran in a browser, defaults to the current URL.
* Otherwise, defaults to invoking module's URL.
*/
base?: URL;
/**
* The kits to use by the runtime.
*/
kits: Kit[];
/**
* The loader to use when loading boards.
*/
loader?: GraphLoader;
/**
* Specifies the remote environment in which to run the harness.
* In this situation, the harness creates a runtime client, and relies
* on the remote environment to act as the runtime server
* If `remote` is not specified or is "false", this harness runs the board
* itself, acting as a server (there is no need for a client).
*/
remote?: HarnessRemoteConfig;
/**
* Specifies a list of node proxies to use. Each item specifies a proxy
* server and a list of nodes that will be proxied to it.
*/
proxy?: HarnessProxyConfig[];
/**
* Specifies whether to output diagnostics information.
* Defaults to `false`.
*/
diagnostics?: boolean;
/**
* Specifies a runner to use. This can be used instead of loading a board
* from a URL.
*/
runner?: BreadboardRunner;
/**
* The `AbortSignal` that can be used to stop the board run.
*/
signal?: AbortSignal;
/**
* The values that will be supplied to the bubbled inputs during a board run.
* This enables automatically providing some of the values like the model
* name without interrupting the run of the board.
*/
inputs?: InputValues;
/**
* Specifies whether or not secrets are asked for interactively. When `true`,
* the `secret` result will start showing up in the run results whenever
* the secret is asked for. Otherwise, the `secrets` node will try to find
* the secrets on its own.
*/
interactiveSecrets?: boolean;
/**
* The data store to use for storing data.
*/
store?: DataStore;
};
import { HarnessRunResult, RunConfig } from "./types.js";
export declare function run(config: RunConfig): AsyncGenerator<HarnessRunResult, void, unknown>;
//# sourceMappingURL=run.d.ts.map

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

*/
import { asyncGen, } from "../index.js";
import { asyncGen } from "../index.js";
import { HTTPClientTransport } from "../remote/http.js";

@@ -9,0 +9,0 @@ import { ProxyClient } from "../remote/proxy.js";

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

import { SecretResult } from "./types.js";
import { ClientRunResult } from "../remote/run.js";
import { ClientRunResult } from "../remote/types.js";
export declare const createSecretAskingKit: (next: (result: ClientRunResult<SecretResult>) => Promise<void>) => import("../types.js").Kit;
//# sourceMappingURL=secrets.d.ts.map

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

*/
import { ClientTransport, LoadResponse, ServerTransport } from "../remote/protocol.js";
import { AnyClientRunResult, AnyProbeClientRunResult, ClientRunResult } from "../remote/run.js";
import { ErrorResponse, InputResponse, OutputResponse, OutputValues } from "../types.js";
import type { DataStore } from "../data/types.js";
import type { GraphLoader } from "../loader/types.js";
import type { NodeProxyConfig } from "../remote/config.js";
import type { AnyClientRunResult, AnyProbeClientRunResult, ClientRunResult, ClientTransport, LoadResponse, ServerTransport } from "../remote/types.js";
import type { BreadboardRunner, ErrorResponse, InputResponse, InputValues, Kit, OutputResponse, OutputValues, RunStackEntry } from "../types.js";
/**

@@ -65,2 +67,94 @@ * The board has been loaded

export type HarnessRunner = AsyncGenerator<HarnessRunResult, void, unknown>;
export type ProxyLocation = "main" | "worker" | "http" | "python";
export type CustomProxyConfig = () => Promise<Kit>;
export type HarnessProxyConfig = {
location: ProxyLocation;
url?: string;
nodes: NodeProxyConfig;
} | CustomProxyConfig;
export type HarnessRemoteConfig = {
/**
* The type of the remote runtime. Can be "http" or "worker".
* Currently, only "worker" is supported.
*/
type: "http" | "worker";
/**
* The URL of the remote runtime. Specifies the URL of the worker
* script if `type` is "worker", or the URL of the runtime server if
* `type` is "http".
*/
url: string;
} | false;
export type RunConfig = {
/**
* The URL of the board to run.
*/
url: string;
/**
* The base URL relative to which to load the board.
* If ran in a browser, defaults to the current URL.
* Otherwise, defaults to invoking module's URL.
*/
base?: URL;
/**
* The kits to use by the runtime.
*/
kits: Kit[];
/**
* The loader to use when loading boards.
*/
loader?: GraphLoader;
/**
* Specifies the remote environment in which to run the harness.
* In this situation, the harness creates a runtime client, and relies
* on the remote environment to act as the runtime server
* If `remote` is not specified or is "false", this harness runs the board
* itself, acting as a server (there is no need for a client).
*/
remote?: HarnessRemoteConfig;
/**
* Specifies a list of node proxies to use. Each item specifies a proxy
* server and a list of nodes that will be proxied to it.
*/
proxy?: HarnessProxyConfig[];
/**
* Specifies whether to output diagnostics information.
* Defaults to `false`.
*/
diagnostics?: boolean;
/**
* Specifies a runner to use. This can be used instead of loading a board
* from a URL.
*/
runner?: BreadboardRunner;
/**
* The `AbortSignal` that can be used to stop the board run.
*/
signal?: AbortSignal;
/**
* The values that will be supplied to the bubbled inputs during a board run.
* This enables automatically providing some of the values like the model
* name without interrupting the run of the board.
*/
inputs?: InputValues;
/**
* Specifies whether or not secrets are asked for interactively. When `true`,
* the `secret` result will start showing up in the run results whenever
* the secret is asked for. Otherwise, the `secrets` node will try to find
* the secrets on its own.
*/
interactiveSecrets?: boolean;
/**
* The data store to use for storing data.
*/
store?: DataStore;
/**
* The state from which to resume the run.
*/
resumeFrom?: StateToResumeFrom;
};
export type StateToResumeFrom = {
state: RunStackEntry[];
inputs?: InputValues;
};
//# sourceMappingURL=types.d.ts.map

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

*/
import { RunConfig } from "./run.js";
import { ServeConfig } from "./serve.js";
import { RunConfig } from "./types.js";
export declare const baseURL: (config: RunConfig | ServeConfig) => URL;
//# sourceMappingURL=url.d.ts.map

@@ -6,7 +6,6 @@ /**

*/
import type { HarnessRunResult } from "./types.js";
import type { HarnessRunResult, RunConfig } from "./types.js";
import { RunState } from "../index.js";
import { RunConfig } from "./run.js";
export declare const createWorker: (url: string) => Worker;
export declare function runInWorker(workerURL: string, config: RunConfig, state?: RunState): AsyncGenerator<HarnessRunResult, void, unknown>;
//# sourceMappingURL=worker.d.ts.map

@@ -51,3 +51,3 @@ /**

export type * from "./data/types.js";
export { createDataStore, inflateData, deflateData, isDataCapability, asBlob, } from "./data/index.js";
export { asBase64, asBlob, deflateData, inflateData, isDataCapability, isInlineData, isStoredData, isSerializedData, isFunctionCallCapabilityPart, isFunctionResponseCapabilityPart, isLLMContent, isTextCapabilityPart, } from "./data/index.js";
//# sourceMappingURL=index.d.ts.map

@@ -39,3 +39,3 @@ /**

export { formatGraphDescriptor } from "./formatter.js";
export { createDataStore, inflateData, deflateData, isDataCapability, asBlob, } from "./data/index.js";
export { asBase64, asBlob, deflateData, inflateData, isDataCapability, isInlineData, isStoredData, isSerializedData, isFunctionCallCapabilityPart, isFunctionResponseCapabilityPart, isLLMContent, isTextCapabilityPart, } from "./data/index.js";
//# sourceMappingURL=index.js.map

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

url: kit.url,
tags: kit.tags || [],
};

@@ -43,0 +44,0 @@ return {

@@ -31,2 +31,4 @@ /**

config: false,
"google-drive-query": false,
"google-drive-file-id": false,
// TODO(aomarks) Not sure about many of these. Some affect the data type, some

@@ -33,0 +35,0 @@ // only affect formatting?

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

runs(): Run[];
observe(result: HarnessRunResult): InspectableRun[];
observe(result: HarnessRunResult): Promise<InspectableRun[]>;
load(o: unknown, options?: SerializedRunLoadingOptions): Promise<InspectableRunLoadResult>;

@@ -16,0 +16,0 @@ }

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

import { RunLoader } from "./loader.js";
import { asBlob, isInlineData, isLLMContent, isStoredData, } from "../../data/index.js";
const isInput = (event) => {

@@ -25,3 +26,3 @@ return (event.type === "node" &&

}
observe(result) {
async observe(result) {
if (result.type === "graphstart") {

@@ -57,2 +58,3 @@ const { path, timestamp } = result.data;

}
await this.#storeInlineData(result);
const run = this.#runs[0];

@@ -62,2 +64,25 @@ run.addResult(result);

}
async #storeInlineData(result) {
if (result.type !== "nodeend" || result.data.node.type !== "input") {
return;
}
if (!this.#options.store) {
return;
}
for (const value of Object.values(result.data.outputs)) {
if (!isLLMContent(value)) {
continue;
}
for (let i = 0; i < value.parts.length; i++) {
const part = value.parts[i];
if (isInlineData(part)) {
const blob = await asBlob(part);
value.parts[i] = await this.#options.store.store(blob);
}
else if (isStoredData(part)) {
value.parts[i] = await this.#options.store.copyToNewestGroup(part);
}
}
}
}
async load(o, options) {

@@ -64,0 +89,0 @@ if (!this.#options.store) {

@@ -572,3 +572,3 @@ /**

*/
observe(result: HarnessRunResult): InspectableRun[];
observe(result: HarnessRunResult): Promise<InspectableRun[]>;
/**

@@ -575,0 +575,0 @@ * Attempts to load a JSON object as a serialized representation of runs,

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

*/
import { KitDescriptor, KitTag } from "@google-labs/breadboard-schema/graph.js";
import { GenericKit, KitConstructor, NodeHandler, NodeHandlers } from "../types.js";
export type KitBuilderOptions = {
url: string;
title?: string;
description?: string;
version?: string;
export type KitBuilderOptions = KitDescriptor & {
namespacePrefix?: string;

@@ -26,3 +23,4 @@ };

namespacePrefix?: string;
constructor({ title, description, version, url, namespacePrefix, }: KitBuilderOptions);
tags: KitTag[];
constructor({ title, description, version, url, namespacePrefix, tags, }: KitBuilderOptions);
build<Handlers extends NodeHandlers>(handlers: Handlers): KitConstructor<GenericKit<Handlers>>;

@@ -29,0 +27,0 @@ static wrap<F extends Record<string, Function>>(params: KitBuilderOptions, functions: F): KitConstructor<GenericKit<{

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

namespacePrefix;
constructor({ title, description, version, url, namespacePrefix = "", }) {
tags;
constructor({ title, description, version, url, namespacePrefix = "", tags = [], }) {
this.url = url;

@@ -19,2 +20,3 @@ this.title = title;

this.namespacePrefix = namespacePrefix;
this.tags = tags;
}

@@ -32,3 +34,3 @@ #addPrefix(handlers) {

const prefix = this.namespacePrefix;
const { title, description, version } = this;
const { title, description, version, tags } = this;
const prefixedHandlers = this.#addPrefix(handlers);

@@ -41,2 +43,3 @@ const nodes = Object.keys(handlers);

url = url;
tags = tags;
get handlers() {

@@ -48,3 +51,6 @@ return prefixedHandlers;

get(target, prop) {
if (prop === "handlers" || prop === "url" || prop === "title") {
if (prop === "handlers" ||
prop === "url" ||
prop === "title" ||
prop === "tags") {
return target[prop];

@@ -51,0 +57,0 @@ }

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

version: string;
tags?: import("@google-labs/breadboard-schema/graph.js").KitTag[];
namespacePrefix?: string;

@@ -22,0 +23,0 @@ };

@@ -37,2 +37,4 @@ /**

this.metadata.icon = metadata.icon;
if (metadata?.help)
this.metadata.help = metadata.help;
}

@@ -39,0 +41,0 @@ async describe() {

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

*/
import { ClientBidirectionalStream, ClientTransport, ServerBidirectionalStream, ServerTransport } from "./protocol.js";
import { ClientBidirectionalStream, ClientTransport, ServerBidirectionalStream, ServerTransport } from "./types.js";
/**

@@ -9,0 +9,0 @@ * Minimal interface in the shape of express.js's request object.

@@ -10,8 +10,7 @@ /**

export { RunServer, RunClient } from "./run.js";
export type { ClientRunResult } from "./run.js";
export { InitServer, InitClient } from "./init.js";
export { defineConfig, hasOrigin, type ProxyServerConfig } from "./config.js";
export type * from "./protocol.js";
export type * from "./types.js";
export type * from "./config.js";
export type * from "./http.js";
//# sourceMappingURL=index.d.ts.map

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

*/
import { ClientTransport, LoadRequest, LoadResponse, ServerTransport } from "./protocol.js";
import { ClientTransport, LoadRequest, LoadResponse, ServerTransport } from "./types.js";
export declare class InitServer {

@@ -9,0 +9,0 @@ #private;

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

import { NodeProxyConfig, ProxyServerConfig } from "./config.js";
import { AnyProxyRequestMessage, AnyProxyResponseMessage, ClientTransport, ServerTransport } from "./protocol.js";
import { AnyProxyRequestMessage, AnyProxyResponseMessage, ClientTransport, ServerTransport } from "./types.js";
type ProxyServerTransport = ServerTransport<AnyProxyRequestMessage, AnyProxyResponseMessage>;

@@ -11,0 +11,0 @@ export declare class ProxyServer {

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

import { InputValues, NodeHandlerContext, OutputValues, RunState } from "../types.js";
import { AnyProbeMessage, AnyRunRequestMessage, AnyRunResponseMessage, ClientTransport, ServerTransport } from "./protocol.js";
import { AnyClientRunResult, AnyRunRequestMessage, AnyRunResponseMessage, RunClientTransport, ServerTransport } from "./types.js";
type RunServerTransport = ServerTransport<AnyRunRequestMessage, AnyRunResponseMessage>;

@@ -16,18 +16,2 @@ export declare class RunServer {

}
type RunClientTransport = ClientTransport<AnyRunRequestMessage, AnyRunResponseMessage>;
type ReplyFunction = {
reply: (chunk: AnyRunRequestMessage[1]) => Promise<void>;
};
type ClientRunResultFromMessage<ResponseMessage> = ResponseMessage extends [
string,
object,
RunState?
] ? {
type: ResponseMessage[0];
data: ResponseMessage[1];
state?: RunState;
} & ReplyFunction : never;
export type AnyClientRunResult = ClientRunResultFromMessage<AnyRunResponseMessage>;
export type AnyProbeClientRunResult = ClientRunResultFromMessage<AnyProbeMessage>;
export type ClientRunResult<T> = T & ReplyFunction;
export declare class RunClient {

@@ -34,0 +18,0 @@ #private;

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

import { PatchedReadableStream, PortStreams } from "../stream.js";
import { ClientTransport, ServerBidirectionalStream, ServerTransport } from "./protocol.js";
import { ClientTransport, ServerBidirectionalStream, ServerTransport } from "./types.js";
export declare class PortDispatcher {

@@ -10,0 +10,0 @@ #private;

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

*/
| "code";
| "code"
/**
* Indicates that the string is a Google Drive Query. See
* https://developers.google.com/drive/api/guides/search-files.
*/
| "google-drive-query"
/**
* Indicates that the string is a Google Drive File ID.
* https://developers.google.com/drive/api/guides/about-files#characteristics
*/
| "google-drive-file-id";
export type Schema = {

@@ -77,0 +87,0 @@ title?: string;

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

},
"version": "0.22.0",
"version": "0.23.0",
"description": "A library for rapid generative AI application prototyping",

@@ -144,9 +144,10 @@ "main": "./dist/src/index.js",

"@rollup/plugin-terser": "^0.4.4",
"@types/node": "^20.14.9",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"@types/node": "^20.14.12",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"ava": "^5.2.0",
"jsonschema": "^1.4.1",
"rollup": "^4.18.0",
"rollup": "^4.19.0",
"rollup-plugin-dts": "^6.1.1",
"@rollup/plugin-json": "^6.1.0",
"typescript": "^5.5.3"

@@ -158,5 +159,5 @@ },

"dependencies": {
"@google-labs/breadboard-schema": "^1.5.1",
"@google-labs/breadboard-schema": "^1.6.0",
"json-schema": "^0.4.0"
}
}

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

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