@google-labs/breadboard
Advanced tools
Comparing version 0.10.1 to 0.11.0
@@ -56,3 +56,3 @@ /** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const $=async(t,e,r)=>{const s=(t=>{if(t instanceof Function)return t;if(t.invoke)return t.invoke;throw new Error("Invalid handler")})(t);return new Promise((t=>{s(e,r).then(t).catch((e=>{t({$error:{error:e}})}))}))},k=t=>t.reduce(((t,e)=>({...e.handlers,...t})),{}),S=t=>t&&t.replace(/-/g,""),E=(t,e="")=>{if(!t)return"";const r=t.id,s=`${e?`${S(e)}_`:""}${S(r)}`,n=t.type,o=`"${n} <br> id='${r}'"`;switch(n){case"include":return`${s}[[${o}]]:::include`;case"slot":return`${s}((${o})):::slot`;case"passthrough":return`${s}((${o})):::passthrough`;case"input":return`${s}[/${o}/]:::input`;case"secrets":return`${s}(${o}):::secrets`;case"output":return`${s}{{${o}}}:::output`;default:return`${s}[${o}]`}};class O{nodeMap;edges;nodes;idPrefix;subgraphs;constructor(t,e=""){const{edges:r,nodes:s}=t;this.nodeMap=new Map(s.map((t=>[t.id,t]))),this.edges=r,this.nodes=s,this.idPrefix=e,this.subgraphs=t.graphs||{}}handleSlotted(t,e){const r=e?`${S(e)}_`:"";if("include"!==t.type)return"";const s=t.configuration?.slotted;if(!s)return"";return Object.entries(s).map((([e,s])=>this.describeSubgraph(s,e,"slotted",t,`${r}${t.id}`))).join("\n")}handleLambda(t,e){const r=e?`${S(e)}_`:"",s=t.configuration?.board;if(!s)return"";const n=s;if("board"!==n.kind)return"";const o=n.board;return this.describeSubgraph(o,t.id,"lamdba",t,`${r}${t.id}`)}describeSubgraphs(t,e=""){const r=this.nodeMap.get(t.from);if(!r)return"";const s=this.handleLambda(r,e);return`${this.handleSlotted(r,e)}${s}`}describeSubgraph(t,e,r,s,n){const o=new O(t,n).describeGraph(),i=this.idPrefix?`${S(this.idPrefix)}_`:"",a=r&&s?`sg_${S(e)}:::slotted -- "${r}->${r}" --o ${i}${S(s.id)}\n`:"";return`\nsubgraph sg_${S(e)} [${e}]\n${o}\nend\n${a}`}describeGraph(t=!1){return[...this.edges.map((e=>{const r=((t,e,r="")=>{const s=t.from,n=E(e.get(s),r),o=t.to,i=E(e.get(o),r),a=t.in,c=t.out,u=t.optional,d=t.constant;return"*"===c?`${n} -- all --\x3e ${i}`:c&&a?u?`${n} -. "${c}->${a}" .-> ${i}`:d?`${n} -- "${c}->${a}" --o ${i}`:`${n} -- "${c}->${a}" --\x3e ${i}`:`${n} --\x3e ${i}`})(e,this.nodeMap,this.idPrefix);return`${r}${t?"":this.describeSubgraphs(e,this.idPrefix)}`})),...t?"":Object.entries(this.subgraphs).map((([t,e])=>this.describeSubgraph(e,t,void 0,void 0,`${t}${this.idPrefix}`)))].join("\n")}}const x=t=>null==t?"null":Array.isArray(t)?"array":typeof t; | ||
*/const $=async(t,e,r)=>{const s=(t=>{if(t instanceof Function)return t;if(t.invoke)return t.invoke;throw new Error("Invalid handler")})(t);return new Promise((t=>{s(e,r).then(t).catch((e=>{t({$error:{error:e}})}))}))},S=t=>t.reduce(((t,e)=>({...e.handlers,...t})),{}),k=t=>t&&t.replace(/-/g,""),E=(t,e="")=>{if(!t)return"";const r=t.id,s=`${e?`${k(e)}_`:""}${k(r)}`,n=t.type,o=`"${n} <br> id='${r}'"`;switch(n){case"include":return`${s}[[${o}]]:::include`;case"slot":return`${s}((${o})):::slot`;case"passthrough":return`${s}((${o})):::passthrough`;case"input":return`${s}[/${o}/]:::input`;case"secrets":return`${s}(${o}):::secrets`;case"output":return`${s}{{${o}}}:::output`;default:return`${s}[${o}]`}};class O{nodeMap;edges;nodes;idPrefix;subgraphs;constructor(t,e=""){const{edges:r,nodes:s}=t;this.nodeMap=new Map(s.map((t=>[t.id,t]))),this.edges=r,this.nodes=s,this.idPrefix=e,this.subgraphs=t.graphs||{}}handleSlotted(t,e){const r=e?`${k(e)}_`:"";if("include"!==t.type)return"";const s=t.configuration?.slotted;if(!s)return"";return Object.entries(s).map((([e,s])=>this.describeSubgraph(s,e,"slotted",t,`${r}${t.id}`))).join("\n")}handleLambda(t,e){const r=e?`${k(e)}_`:"",s=t.configuration?.board;if(!s)return"";const n=s;if("board"!==n.kind)return"";const o=n.board;return this.describeSubgraph(o,t.id,"lamdba",t,`${r}${t.id}`)}describeSubgraphs(t,e=""){const r=this.nodeMap.get(t.from);if(!r)return"";const s=this.handleLambda(r,e);return`${this.handleSlotted(r,e)}${s}`}describeSubgraph(t,e,r,s,n){const o=new O(t,n).describeGraph(),i=this.idPrefix?`${k(this.idPrefix)}_`:"",a=r&&s?`sg_${k(e)}:::slotted -- "${r}->${r}" --o ${i}${k(s.id)}\n`:"";return`\nsubgraph sg_${k(e)} [${e}]\n${o}\nend\n${a}`}describeGraph(t=!1){return[...this.edges.map((e=>{const r=((t,e,r="")=>{const s=t.from,n=E(e.get(s),r),o=t.to,i=E(e.get(o),r),a=t.in,c=t.out,u=t.optional,d=t.constant;return"*"===c?`${n} -- all --\x3e ${i}`:c&&a?u?`${n} -. "${c}->${a}" .-> ${i}`:d?`${n} -- "${c}->${a}" --o ${i}`:`${n} -- "${c}->${a}" --\x3e ${i}`:`${n} --\x3e ${i}`})(e,this.nodeMap,this.idPrefix);return`${r}${t?"":this.describeSubgraphs(e,this.idPrefix)}`})),...t?"":Object.entries(this.subgraphs).map((([t,e])=>this.describeSubgraph(e,t,void 0,void 0,`${t}${this.idPrefix}`)))].join("\n")}}const x=t=>null==t?"null":Array.isArray(t)?"array":typeof t; | ||
/** | ||
@@ -62,3 +62,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class P{additionalProperties=!1;required=[];properties={};build(){const t={type:"object",properties:this.properties,additionalProperties:this.additionalProperties};return this.required.length>0&&(t.required=this.required),t}setAdditionalProperties(t){return void 0!==t&&(this.additionalProperties=t),this}addInputs(t){return t?(Object.entries(t).forEach((([t,e])=>{this.addProperty(t,{type:x(e)})})),this):this}addProperty(t,e){return this.properties[t]=e,this}addProperties(t){return Object.entries(t).forEach((([t,e])=>{this.addProperty(t,e)})),this}addRequired(t){return t?("string"==typeof t?this.required=[...this.required,t]:Array.isArray(t)&&t.length>0&&(this.required=[...this.required,...t]),this):this}static empty(t=!1){return(new P).setAdditionalProperties(t).build()}} | ||
*/class P{type="object";additionalProperties=!1;required=[];properties={};build(){const t={type:"object",properties:this.properties};return this.additionalProperties||(t.additionalProperties=!1),this.required.length>0&&(t.required=this.required),t}addSchema(t){return"object"===t.type&&(this.addProperties(t.properties),this.addRequired(t.required),this.setAdditionalProperties(t.additionalProperties)),this}setAdditionalProperties(t){return void 0!==t&&(this.additionalProperties=t),this}addInputs(t){return t?(Object.entries(t).forEach((([t,e])=>{this.addProperty(t,{type:x(e)})})),this):this}addProperty(t,e){return this.properties[t]=e,this}addProperties(t){return t?(Object.entries(t).forEach((([t,e])=>{this.addProperty(t,e)})),this):this}addRequired(t){return t?("string"==typeof t?this.required=[...new Set([...this.required,t])]:Array.isArray(t)&&t.length>0&&(this.required=[...new Set([...this.required,...t])]),this.required.sort(),this):this}static empty(t=!1){return(new P).setAdditionalProperties(t).build()}} | ||
/** | ||
@@ -68,13 +68,8 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const N=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},j=async(t,e,r,s)=>{if(!e.requestInput)return;const n=await s.outputsPromise??{},o=new R(n,s.inputs);s.outputsPromise=o.read(I(t,e,r))},I=(t,e,r)=>async(s,n,o)=>{if(o)throw new Error(N(s,t,o));if(void 0!==n.default)return"type"in n&&"string"!==n.type?JSON.parse(n.default):n.default;const i=await(e.requestInput?.(s,n,r));if(void 0===i)throw new Error(N(s,t,o));return i};class R{#d;#p;constructor(t,e){this.#d=t,this.#p=e}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);s[n]=i}return{...this.#d,...s}}}class q{#h;#l=new Map;constructor(t){this.#h=t}createHandler(t,e){return async(r,s,n)=>{const o=this.#l.get(r);if(void 0!==o)return o;const i={id:n.id,type:n.type},a={...e,descriptor:i,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new p(a,void 0,-1));const c=await a.outputsPromise;let u=c&&c[r];return void 0===u&&(u=await(this.#h.requestInput?.(r,s,i))),s.transient||this.#l.set(r,u),u}}} | ||
*/const j=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},N=async(t,e,r,s)=>{if(!e.requestInput)return;const n=await s.outputsPromise??{},o=new R(n,s.inputs);s.outputsPromise=o.read(I(t,e,r))},I=(t,e,r)=>async(s,n,o)=>{if(o)throw new Error(j(s,t,o));if(void 0!==n.default)return"type"in n&&"string"!==n.type?JSON.parse(n.default):n.default;const i=await(e.requestInput?.(s,n,r));if(void 0===i)throw new Error(j(s,t,o));return i};class R{#d;#p;constructor(t,e){this.#d=t,this.#p=e}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);s[n]=i}return{...this.#d,...s}}}class q{#h;#l=new Map;constructor(t){this.#h=t}createHandler(t,e){return async(r,s,n)=>{const o=this.#l.get(r);if(void 0!==o)return o;const i={id:n.id,type:n.type},a={...e,descriptor:i,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new p(a,void 0,-1));const c=await a.outputsPromise;let u=c&&c[r];return void 0===u&&(u=await(this.#h.requestInput?.(r,s,i))),C(s)||this.#l.set(r,u),u}}}const C=t=>t.behavior?.includes("transient")??!1,A=async(t,e,r)=>{if(!r.provideOutput)return!1;const s=e.configuration?.schema,n=s?.behavior?.includes("bubble");return!!n&&(await r.provideOutput(t,e),!0)},T=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s)=>{const n={...e,descriptor:s,inputs:r};await t(new h(n,-1))},M=()=>{};class F{#f=[];#w=M;#m;#y;abort=M;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:M})}}class W{#v;#$=!0;#f=new F;constructor(t){this.#v=t}async#S(t){return this.#f.write(t)}async next(){return this.#$&&(this.#$=!1,this.#v(this.#S.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}}const B=t=>({[Symbol.asyncIterator]:()=>new W(t)}); | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const C=()=>{};class A{#f=[];#w=C;#m;#y;abort=C;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:C})}}class T{#v;#$=!0;#f=new A;constructor(t){this.#v=t}async#k(t){return this.#f.write(t)}async next(){return this.#$&&(this.#$=!1,this.#v(this.#k.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}}const M=t=>({[Symbol.asyncIterator]:()=>new T(t)}); | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class F{#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 W="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.2.0/packages/schema/breadboard.schema.json"; | ||
*/class L{#k;#E;constructor(t){this.#k=structuredClone(t)||[]}onGraphStart(){this.#k.push({graph:0,node:0})}onNodeStart(t){this.#k[this.#k.length-1].node++,this.#E=t}onNodeEnd(){}onGraphEnd(){}async state(){const t=structuredClone(this.#k);return this.#E&&(t[t.length-1].state=await c("nodestart",this.#E)),t}}var U="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.2.0/packages/schema/breadboard.schema.json"; | ||
/** | ||
@@ -85,3 +80,3 @@ * @license | ||
*/ | ||
class B{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#O={};#x=[];#P;constructor({url:t,title:e,description:r,version:s,$schema:n}={$schema:W}){Object.assign(this,{$schema:n??W,url:t,title:e,description:r,version:s})}async*run(t={},e){const r=t.base||new URL(this.url||"",import.meta.url);yield*M((async s=>{const{probe:n}=t,i=await B.handlersFromBoard(this,t.kits),a={...this.#O,...t.slots};this.#x.forEach((t=>t.addGraph(this)));const c=new o(this,e?.state),d=new q(t),l=t.invocationPath||[],f=new F(t.state);await(n?.report?.({type:"graphstart",data:{metadata:this,path:l,timestamp:u()}}));let w=0;f.onGraphStart();const m=()=>[...l,w];for await(const e of c){w++;const{inputs:o,descriptor:c,missingInputs:l}=e;if(e.skip){await(n?.report?.({type:"skip",data:{node:c,inputs:o,missingInputs:l,path:m(),timestamp:u()}}));continue}let y;if(f.onNodeStart(e),await(n?.report?.({type:"nodestart",data:{node:c,inputs:o,path:m(),timestamp:u()},state:await f.state()})),"input"===c.type)await s(new p(e,await f.state(),w)),await j(this,t,c,e),y=e.outputsPromise;else if("output"===c.type)await s(new h(e,w)),y=e.outputsPromise;else{const n=i[c.type];if(!n)throw new Error(`No handler for node type "${c.type}"`);const u={...t,board:this,descriptor:c,outerGraph:this.#P||this,base:r,slots:a,kits:[...t.kits||[],...this.kits],requestInput:d.createHandler(s,e),invocationPath:m(),state:await f.state()};y=$(n,o,u)}f.onNodeEnd(),await(n?.report?.({type:"nodeend",data:{node:c,inputs:o,outputs:await y,validatorMetadata:this.#x.map((t=>t.getValidatorMetadata(c))),path:m(),timestamp:u()}})),e.outputsPromise=y}f.onGraphEnd(),await(n?.report?.({type:"graphend",data:{metadata:this,path:l,timestamp:u()}}))}))}get validators(){return this.#x}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:{metadata:this,path:n,timestamp:u()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#x.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const n=new O(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 B(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=new y({base:r,graphs:n?.graphs}),{isSubgraph:i,graph:a}=await o.load(t),c=await B.fromGraphDescriptor(a);return i&&(c.#P=n),c.#O=s||{},c}static async fromBreadboardCapability(t){if("board"!==t.kind||!t.board)throw new Error(`Expected a "board" Capability, but got ${t}`);const e=t.board;if(!(e.edges&&e.kits&&e.nodes))throw new Error('Supplied "board" Capability argument is not actually a board');let r=t.board;return r.runOnce||(r=await B.fromGraphDescriptor(e)),r}static async handlersFromBoard(t,e=[]){const r=[new L,...e,...t.kits];return k(r)}static runRemote=v}class L{handlers;constructor(){this.handlers={lambda:{describe:async t=>({inputSchema:(new P).setAdditionalProperties(!0).addInputs(t).addProperty("board",{title:"board",description:"The board to run.",type:"object"}).build(),outputSchema:(new P).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 B.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}} | ||
class D{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#O={};#x=[];#P;constructor({url:t,title:e,description:r,version:s,$schema:n}={$schema:U}){Object.assign(this,{$schema:n??U,url:t,title:e,description:r,version:s})}async*run(t={},e){const r=t.base||new URL(this.url||"",import.meta.url);yield*B((async s=>{const{probe:n}=t,i=await D.handlersFromBoard(this,t.kits),a={...this.#O,...t.slots};this.#x.forEach((t=>t.addGraph(this)));const c=new o(this,e?.state),d=new q(t),l=t.invocationPath||[],f=new L(t.state);await(n?.report?.({type:"graphstart",data:{metadata:this,path:l,timestamp:u()}}));let w=0;f.onGraphStart();const m=()=>[...l,w];for await(const e of c){w++;const{inputs:o,descriptor:c,missingInputs:l}=e;if(e.skip){await(n?.report?.({type:"skip",data:{node:c,inputs:o,missingInputs:l,path:m(),timestamp:u()}}));continue}let y;if(f.onNodeStart(e),await(n?.report?.({type:"nodestart",data:{node:c,inputs:o,path:m(),timestamp:u()},state:await f.state()})),"input"===c.type)await s(new p(e,await f.state(),w)),await N(this,t,c,e),y=e.outputsPromise;else if("output"===c.type)await A(o,c,t)||await s(new h(e,w)),y=e.outputsPromise;else{const n=i[c.type];if(!n)throw new Error(`No handler for node type "${c.type}"`);const u={...t,board:this,descriptor:c,outerGraph:this.#P||this,base:r,slots:a,kits:[...t.kits||[],...this.kits],requestInput:d.createHandler(s,e),provideOutput:T(s,e,t),invocationPath:m(),state:await f.state()};y=$(n,o,u)}f.onNodeEnd(),await(n?.report?.({type:"nodeend",data:{node:c,inputs:o,outputs:await y,validatorMetadata:this.#x.map((t=>t.getValidatorMetadata(c))),path:m(),timestamp:u()}})),e.outputsPromise=y}f.onGraphEnd(),await(n?.report?.({type:"graphend",data:{metadata:this,path:l,timestamp:u()}}))}))}get validators(){return this.#x}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:{metadata:this,path:n,timestamp:u()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#x.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const n=new O(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 D(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=new y({base:r,graphs:n?.graphs}),{isSubgraph:i,graph:a}=await o.load(t),c=await D.fromGraphDescriptor(a);return i&&(c.#P=n),c.#O=s||{},c}static async fromBreadboardCapability(t){if("board"!==t.kind||!t.board)throw new Error(`Expected a "board" Capability, but got ${t}`);const e=t.board;if(!(e.edges&&e.kits&&e.nodes))throw new Error('Supplied "board" Capability argument is not actually a board');let r=t.board;return r.runOnce||(r=await D.fromGraphDescriptor(e)),r}static async handlersFromBoard(t,e=[]){const r=[new _,...e,...t.kits];return S(r)}static runRemote=v}class _{handlers;constructor(){this.handlers={lambda:{describe:async t=>({inputSchema:(new P).setAdditionalProperties(!0).addInputs(t).addProperty("board",{title:"board",description:"The board to run.",type:"object"}).build(),outputSchema:(new P).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 D.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}} | ||
/** | ||
@@ -91,3 +86,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class U{#N=new Map;vendId(t,e){let r=this.#N.get(t)||0;return r++,this.#N.set(t,r),`${e}-${r}`}} | ||
*/class z{#j=new Map;vendId(t,e){let r=this.#j.get(t)||0;return r++,this.#j.set(t,r),`${e}-${r}`}} | ||
/** | ||
@@ -97,3 +92,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const D=/^((?<a>.*)(?<dir><-|->))?(?<b>[^(.|?)]*)(?<q>\.|\?)?$/m,_=new U;class z{#j;#I;constructor(t,e,r,s,n){if(this.#I=t.currentBoardToAddTo(),this.#j={id:n??_.vendId(this.#I,r),type:r},s&&(t=>Object.values(t).length>0)(s)){const t=Object.entries(s).filter((([t,e])=>e instanceof z));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.#j.configuration=s}e?.url&&!this.#I.kits.find((t=>t.url===e.url))&&this.#I.kits.push(e),this.#I.addNode(this.#j)}wire(t,e){const{ltr:r,edge:s}=(t=>{const e={ltr:!0},r=t.match(D);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.#j.id,to:o.#j.id,...s};return n.#I!==o.#I?o.#I.addEdgeAcrossBoards(i,n.#I,o.#I):this.#I.addEdge(i),this}get id(){return this.#j.id}} | ||
*/const H=/^((?<a>.*)(?<dir><-|->))?(?<b>[^(.|?)]*)(?<q>\.|\?)?$/m,J=new z;class G{#N;#I;constructor(t,e,r,s,n){if(this.#I=t.currentBoardToAddTo(),this.#N={id:n??J.vendId(this.#I,r),type:r},s&&(t=>Object.values(t).length>0)(s)){const t=Object.entries(s).filter((([t,e])=>e instanceof G));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.#N.configuration=s}e?.url&&!this.#I.kits.find((t=>t.url===e.url))&&this.#I.kits.push(e),this.#I.addNode(this.#N)}wire(t,e){const{ltr:r,edge:s}=(t=>{const e={ltr:!0},r=t.match(H);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.#N.id,to:o.#N.id,...s};return n.#I!==o.#I?o.#I.addEdgeAcrossBoards(i,n.#I,o.#I):this.#I.addEdge(i),this}get id(){return this.#N.id}} | ||
/** | ||
@@ -103,3 +98,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const H=t=>new t({create:()=>{throw Error("Node instantiation can't (yet) happen during runtime")}}),J=(t,e)=>{const r=void 0!==e.nodes&&void 0!==e.edges&&void 0!==e.kits,s=r||"function"==typeof e||e instanceof z||"board"===e.kind&&e.board?{board:r?{kind:"board",board:e}:e}:e;return"function"==typeof s.board&&(s.board=t.lambda(s.board)),s}; | ||
*/const V=t=>new t({create:()=>{throw Error("Node instantiation can't (yet) happen during runtime")}}),K=(t,e)=>{const r=void 0!==e.nodes&&void 0!==e.edges&&void 0!==e.kits,s=r||"function"==typeof e||e instanceof G||"board"===e.kind&&e.board?{board:r?{kind:"board",board:e}:e}:e;return"function"==typeof s.board&&(s.board=t.lambda(s.board)),s}; | ||
/** | ||
@@ -110,3 +105,3 @@ * @license | ||
*/ | ||
class G extends B{#R=[];#q;#C=[];input(t={}){const{$id:e,...r}=t;return new z(this,void 0,"input",{...r},e)}output(t={}){const{$id:e,...r}=t;return new z(this,void 0,"output",{...r},e)}lambda(t,e={}){const{$id:r,...s}=e;let n,o;if("function"==typeof t){n=new G,o=n.input();const e=n.output();n.#q=this.#q??this,n.#q.#R.push(n),t(n,o,e),n.#q.#R.pop()}else n=t;const i=new z(this,void 0,"lambda",{board:{kind:"board",board:n},...s},r);if(o&&n.#C.length>0){for(const{edge:t,from:e,to:r}of n.#C){if(r!==n||!t.constant)throw new Error("Across board wires: Must be constant and from parent to child");const s=`$l-${t.to}-${t.in}`;n.addEdge({...t,from:o.id,out:s});const a={...t,to:i.id,in:s};e===this?this.addEdge(a):this.addEdgeAcrossBoards(a,e,this)}n.#C=[]}return i}addEdge(t){this.edges.push(t)}addNode(t){this.nodes.push(t)}addKit(t){const e=(r=this,new t({create:(...t)=>new z(r,...t),getConfigWithLambda:t=>J(r,t)}));var r;return this.kits.push(e),e}currentBoardToAddTo(){const t=this.#q?this.#q.#R:this.#R;return 0===t.length?this:t[t.length-1]}addEdgeAcrossBoards(t,e,r){if("*"===t.out)throw new Error("Across board wires: * wires not supported");if(!t.constant)throw new Error("Across board wires: Must be constant for now");if(r!==this)throw new Error("Across board wires: Must be invoked on to board");const s=this.#q?this.#q.#R:this.#R;if(e!==this.#q&&!s.includes(e))throw new Error("Across board wires: From must be parent of to");this.#C.push({edge:t,from:e,to:r})}} | ||
class Q extends D{#R=[];#q;#C=[];input(t={}){const{$id:e,...r}=t;return new G(this,void 0,"input",{...r},e)}output(t={}){const{$id:e,...r}=t;return new G(this,void 0,"output",{...r},e)}lambda(t,e={}){const{$id:r,...s}=e;let n,o;if("function"==typeof t){n=new Q,o=n.input();const e=n.output();n.#q=this.#q??this,n.#q.#R.push(n),t(n,o,e),n.#q.#R.pop()}else n=t;const i=new G(this,void 0,"lambda",{board:{kind:"board",board:n},...s},r);if(o&&n.#C.length>0){for(const{edge:t,from:e,to:r}of n.#C){if(r!==n||!t.constant)throw new Error("Across board wires: Must be constant and from parent to child");const s=`$l-${t.to}-${t.in}`;n.addEdge({...t,from:o.id,out:s});const a={...t,to:i.id,in:s};e===this?this.addEdge(a):this.addEdgeAcrossBoards(a,e,this)}n.#C=[]}return i}addEdge(t){this.edges.push(t)}addNode(t){this.nodes.push(t)}addKit(t){const e=(r=this,new t({create:(...t)=>new G(r,...t),getConfigWithLambda:t=>K(r,t)}));var r;return this.kits.push(e),e}currentBoardToAddTo(){const t=this.#q?this.#q.#R:this.#R;return 0===t.length?this:t[t.length-1]}addEdgeAcrossBoards(t,e,r){if("*"===t.out)throw new Error("Across board wires: * wires not supported");if(!t.constant)throw new Error("Across board wires: Must be constant for now");if(r!==this)throw new Error("Across board wires: Must be invoked on to board");const s=this.#q?this.#q.#R:this.#R;if(e!==this.#q&&!s.includes(e))throw new Error("Across board wires: From must be parent of to");this.#C.push({edge:t,from:e,to:r})}} | ||
/** | ||
@@ -116,3 +111,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class V{#A;constructor(t){this.#A=t}async serve(){const t=this.#A.createServerStream().readableRequests.getReader(),e=await t.read();if(e.done)throw new Error("Client closed stream without sending a request.");return e.value.url}}class K{#A;constructor(t){this.#A=t}async load(t){const e=this.#A.createClientStream().writableRequests.getWriter();await e.write({url:t}),await e.close()}} | ||
*/class X{#A;constructor(t){this.#A=t}async serve(){const t=this.#A.createServerStream().readableRequests.getReader(),e=await t.read();if(e.done)throw new Error("Client closed stream without sending a request.");return e.value.url}}class Y{#A;constructor(t){this.#A=t}async load(t){const e=this.#A.createClientStream().writableRequests.getWriter();await e.write({url:t}),await e.close()}} | ||
/** | ||
@@ -122,3 +117,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Q extends EventTarget{#v;constructor(t){super(),this.#v=t}async report(t){return this.#v(t)}} | ||
*/class Z extends EventTarget{#v;constructor(t){super(),this.#v=t}async report(t){return this.#v(t)}} | ||
/** | ||
@@ -128,3 +123,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const X="stream";class Y{kind=X;stream;constructor(t){this.stream=t}}const Z=t=>{const e=[];return{value:JSON.stringify(t,((t,r)=>(t=>{const e=t;return e&&e.kind&&e.kind===X&&e.stream instanceof ReadableStream})(r)?(e.push(r.stream),{$type:"Stream",id:e.length-1}):r)),streams:e}},tt=(t,e)=>{const r=JSON.parse(t,((t,r)=>"object"==typeof r&&null!==r&&"Stream"===r.$type&&"number"==typeof r.id?new Y(e(r.id)):r));return r},et=t=>{const e=Z(t).value;return tt(e,(()=>new ReadableStream))},rt=t=>({readable:new ReadableStream({start(e){t.onmessage=t=>{null!==t.data?e.enqueue(t.data):e.close()}},cancel(){t.onmessage=null}}),writable:new WritableStream({write(e){const r=Z(e);t.postMessage(e,r.streams)},close(){t.postMessage(null,[])}})});class st{#T;data;constructor(t,e){this.#T=e,this.data=t}async reply(t){await this.#T.write(t)}}class nt{#M;#T;constructor(t,e){this.#M=e.getReader(),this.#T=t.getWriter()}async next(){const{done:t,value:e}=await this.#M.read();return t?(this.#T.close(),{done:t,value:void 0}):{done:!1,value:new st(e,this.#T)}}async return(){return this.#T.close(),{done:!0,value:void 0}}async throw(t){return this.#T.abort(t),{done:!0,value:void 0}}}const ot=(t,e)=>({async start(e){const r=t.getWriter();await r.write(e),r.releaseLock()},[Symbol.asyncIterator]:()=>new nt(t,e)});class it{#A;constructor(t){this.#A=t}async serve(t,e=!1,r={}){const s=this.#A.createServerStream(),n=s.readableRequests.getReader();let o=await n.read();if(o.done)return;const i=(t=>{const[e,,r]=t;if(console.log("resumeRun",e,r),!r)return;if(r.length>1)throw new Error("I don't yet know how to resume from nested subgraphs.");const s=d.load(r[0].state);if("input"===e){const[,e]=t;s.inputs=e.inputs}return s})(o.value),a=s.writableResponses.getWriter(),c={...r,probe:e?new Q((async t=>{const{type:e,data:r}=t,s=[e,et(r)];"nodestart"==e&&s.push(t.state),await a.write(s)})):void 0};try{for await(const e of t.run(c,i))if("input"===e.type){const t=e.runState,{node:r,inputArguments:s,timestamp:i}=e;if(await a.write(["input",{node:r,inputArguments:s,timestamp:i},t]),o=await n.read(),o.done)return void await a.close();{const[t,r]=o.value;"input"===t&&(e.inputs=r.inputs)}}else if("output"===e.type){const{node:t,outputs:r,timestamp:s}=e;await a.write(["output",{node:t,outputs:r,timestamp:s}])}await a.write(["end",{timestamp:u()}]),await a.close()}catch(t){const e=t;let r;if(e?.cause){const{cause:t}=e;r=t}else r=e.message;console.error("Run Server error:",r),await a.write(["error",{error:r,timestamp:u()}]),await a.close()}}}const at=t=>{const[e,r,s]=t.data;return{type:e,data:r,state:s,reply:async r=>{if("input"!==e)throw new Error("For now, we cannot reply to messages other than 'input'.");await t.reply([e,r,s])}}};class ct{#A;constructor(t){this.#A=t}async*run(t){const e=this.#A.createClientStream(),r=ot(e.writableRequests,e.readableResponses),s=["run",{}];t&&s.push(t),await r.start(s);for await(const t of r)yield at(t)}async runOnce(t){let e;for await(const r of this.run()){const{type:s,data:n}=r;if("input"===s)r.reply({inputs:t});else if("output"===s){e=n.outputs;break}}return e||{}}} | ||
*/const tt="stream";class et{kind=tt;stream;constructor(t){this.stream=t}}const rt=t=>{const e=[];return{value:JSON.stringify(t,((t,r)=>(t=>{const e=t;return e&&e.kind&&e.kind===tt&&e.stream instanceof ReadableStream})(r)?(e.push(r.stream),{$type:"Stream",id:e.length-1}):r)),streams:e}},st=(t,e)=>{const r=JSON.parse(t,((t,r)=>"object"==typeof r&&null!==r&&"Stream"===r.$type&&"number"==typeof r.id?new et(e(r.id)):r));return r},nt=t=>{const e=rt(t).value;return st(e,(()=>new ReadableStream))},ot=t=>({readable:new ReadableStream({start(e){t.onmessage=t=>{null!==t.data?e.enqueue(t.data):e.close()}},cancel(){t.onmessage=null}}),writable:new WritableStream({write(e){const r=rt(e);t.postMessage(e,r.streams)},close(){t.postMessage(null,[])}})});class it{#T;data;constructor(t,e){this.#T=e,this.data=t}async reply(t){await this.#T.write(t)}}class at{#M;#T;constructor(t,e){this.#M=e.getReader(),this.#T=t.getWriter()}async next(){const{done:t,value:e}=await this.#M.read();return t?(this.#T.close(),{done:t,value:void 0}):{done:!1,value:new it(e,this.#T)}}async return(){return this.#T.close(),{done:!0,value:void 0}}async throw(t){return this.#T.abort(t),{done:!0,value:void 0}}}const ct=(t,e)=>({async start(e){const r=t.getWriter();await r.write(e),r.releaseLock()},[Symbol.asyncIterator]:()=>new at(t,e)});class ut{#A;constructor(t){this.#A=t}async serve(t,e=!1,r={}){const s=this.#A.createServerStream(),n=s.readableRequests.getReader();let o=await n.read();if(o.done)return;const i=(t=>{const[e,,r]=t;if(!r)return;if(r.length>1)throw new Error("I don't yet know how to resume from nested subgraphs.");const s=d.load(r[0].state);if("input"===e){const[,e]=t;s.inputs=e.inputs}return s})(o.value),a=s.writableResponses.getWriter(),c={...r,probe:e?new Z((async t=>{const{type:e,data:r}=t,s=[e,nt(r)];"nodestart"==e&&s.push(t.state),await a.write(s)})):void 0};try{for await(const e of t.run(c,i))if("input"===e.type){const t=e.runState,{node:r,inputArguments:s,timestamp:i}=e;if(await a.write(["input",{node:r,inputArguments:s,timestamp:i},t]),o=await n.read(),o.done)return void await a.close();{const[t,r]=o.value;"input"===t&&(e.inputs=r.inputs)}}else if("output"===e.type){const{node:t,outputs:r,timestamp:s}=e;await a.write(["output",{node:t,outputs:r,timestamp:s}])}await a.write(["end",{timestamp:u()}]),await a.close()}catch(t){const e=t;let r;if(e?.cause){const{cause:t}=e;r=t}else r=e.message;console.error("Run Server error:",r),await a.write(["error",{error:r,timestamp:u()}]),await a.close()}}}const dt=t=>{const[e,r,s]=t.data;return{type:e,data:r,state:s,reply:async r=>{if("input"!==e)throw new Error("For now, we cannot reply to messages other than 'input'.");await t.reply([e,r,s])}}};class pt{#A;constructor(t){this.#A=t}async*run(t){const e=this.#A.createClientStream(),r=ct(e.writableRequests,e.readableResponses),s=["run",{}];t&&s.push(t),await r.start(s);for await(const t of r)yield dt(t)}async runOnce(t){let e;for await(const r of this.run()){const{type:s,data:n}=r;if("input"===s)r.reply({inputs:t});else if("output"===s){e=n.outputs;break}}return e||{}}} | ||
/** | ||
@@ -134,3 +129,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const ut="port-dispatcher-sendport";class dt{#F;#W=new Map;#B=new Map;constructor(t){this.#F=t,this.#F.addEventListener("message",(t=>{const{type:e,id:r,port:s}=t.data;if(e!==ut)return;const n=this.#W.get(r);n?(n(s),this.#W.delete(r)):this.#B.set(r,s)}))}receive(t){const e=this.#B.get(t);return e?(this.#B.delete(t),rt(e)):(t=>{let e;const r=new Promise((r=>{t().then((t=>{e=rt(t),r()}))}));return{readable:new ReadableStream({async start(){await r},pull:t=>e.readable.pipeTo(new WritableStream({write(e){t.enqueue(e)}})),cancel(){e.readable.cancel()}}),writable:new WritableStream({async start(){await r},async write(t){const r=e.writable.getWriter();await r.write(t),r.releaseLock()},async close(){await e.writable.close()},async abort(t){await e.writable.abort(t)}})}})((()=>new Promise((e=>{this.#W.set(t,e)}))))}send(t){const{port1:e,port2:r}=new MessageChannel;return this.#F.postMessage({type:ut,id:t,port:r},[r]),rt(e)}}class pt{#M;#T;constructor(t){this.#M=t.readable.getReader(),this.#T=t.writable.getWriter()}createClientStream(){return{writableRequests:(e=this.#T,new WritableStream({write:async t=>e.write(t)},{highWaterMark:0})),readableResponses:(t=this.#M,new ReadableStream({async pull(e){const{value:r,done:s}=await t.read();s?e.close():e.enqueue(r)}},{highWaterMark:0}))};var t,e}}class ht{#L;constructor(t){this.#L=t}createServerStream(){return{readableRequests:this.#L.readable,writableResponses:this.#L.writable}}} | ||
*/const ht="port-dispatcher-sendport";class lt{#F;#W=new Map;#B=new Map;constructor(t){this.#F=t,this.#F.addEventListener("message",(t=>{const{type:e,id:r,port:s}=t.data;if(e!==ht)return;const n=this.#W.get(r);n?(n(s),this.#W.delete(r)):this.#B.set(r,s)}))}receive(t){const e=this.#B.get(t);return e?(this.#B.delete(t),ot(e)):(t=>{let e;const r=new Promise((r=>{t().then((t=>{e=ot(t),r()}))}));return{readable:new ReadableStream({async start(){await r},pull:t=>e.readable.pipeTo(new WritableStream({write(e){t.enqueue(e)}})),cancel(){e.readable.cancel()}}),writable:new WritableStream({async start(){await r},async write(t){const r=e.writable.getWriter();await r.write(t),r.releaseLock()},async close(){await e.writable.close()},async abort(t){await e.writable.abort(t)}})}})((()=>new Promise((e=>{this.#W.set(t,e)}))))}send(t){const{port1:e,port2:r}=new MessageChannel;return this.#F.postMessage({type:ht,id:t,port:r},[r]),ot(e)}}class ft{#M;#T;constructor(t){this.#M=t.readable.getReader(),this.#T=t.writable.getWriter()}createClientStream(){return{writableRequests:(e=this.#T,new WritableStream({write:async t=>e.write(t)},{highWaterMark:0})),readableResponses:(t=this.#M,new ReadableStream({async pull(e){const{value:r,done:s}=await t.read();s?e.close():e.enqueue(r)}},{highWaterMark:0}))};var t,e}}class wt{#L;constructor(t){this.#L=t}createServerStream(){return{readableRequests:this.#L.readable,writableResponses:this.#L.writable}}} | ||
/** | ||
@@ -140,3 +135,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class lt{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}#U(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.#U(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?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 lt(t).build(r)}} | ||
*/class mt{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}#U(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.#U(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 mt(t).build(r)}} | ||
/** | ||
@@ -146,3 +141,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const ft=globalThis.process?t=>Buffer.from(t,"base64").toString("binary"):globalThis.atob,wt=globalThis.process?t=>Buffer.from(t,"binary").toString("base64"):globalThis.btoa;class mt{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 yt=(t,e)=>Object.fromEntries(Object.entries(e).map((([e,r])=>"string"==typeof r?[e,[new mt(e,t,r)]]:Array.isArray(r)?[e,r.map((r=>"string"==typeof r?new mt(e,t,r):new mt(e,t,r.to,r.when)))]:[e,[new mt(e,t,r.to,r.when)]]))),gt=Math.round(Date.now()/6048e5).toString(36),bt=`T-${gt}-`,vt=`-${gt}-T`,$t=new RegExp(`(${bt}.*?${vt})`,"gm"),kt=new RegExp(`^${bt}(.+?)${vt}$`),St=async(t,e,r)=>{const s=JSON.stringify(t),n=s.split($t).filter(Boolean).map((t=>{const e=t.match(kt);if(e){const t=e[1].split("~"),[r,s,n]=t;return{nodeType:r,outputName:s,inputs:ft(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(""))},Et=(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 $(r,t,n),s,(r=>((t,e,r)=>{const s=wt(JSON.stringify(r)).replace("=","");return`${bt}${t}~${e}~${s}${vt}`})(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)=>$(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)=>St(t,r,(async(t,r)=>$(e[t],r,s))))),s)]:[t,r]})));return{url:"tunnel-kit",handlers:n}},Ot=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r};class xt{#A;constructor(t){this.#A=t}async serve(t){const{kits:e}=t,r=this.#A.createServerStream(),s=Et((t=>t.proxy?Object.fromEntries(t.proxy.map((t=>{if("string"!=typeof t&&t.tunnel)return[t.node,yt(t.node,t.tunnel)]})).filter(Boolean)):{})(t),k(e)),n=s.handlers;for await(const e of ot(r.writableResponses,r.readableRequests)){const[r]=e.data;if("end"===r)break;if("proxy"!==r){e.reply(["error",{error:"Expected proxy request.",timestamp:u()}]);continue}const[,{node:s,inputs:o}]=e.data,i=Ot(s.type,t.proxy)?n[s.type]:void 0;if(i)try{const t=await $(i,o,{descriptor:s});if(!t){e.reply(["error",{error:"Handler returned nothing.",timestamp:u()}]);continue}e.reply(["proxy",{outputs:t}])}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 Pt{#A;constructor(t){this.#A=t}shutdownServer(){const t=this.#A.createClientStream().writableRequests.getWriter();t.write(["end",{timestamp:u()}]),t.close()}async proxy(t,e){const r=this.#A.createClientStream(),s=r.writableRequests.getWriter(),n=r.readableResponses.getReader();s.write(["proxy",{node:t,inputs:e}]),s.close();const o=await n.read();if(o.done)throw new Error("Unexpected proxy failure: empty response.");const[i]=o.value;if("proxy"===i){const[,{outputs:t}]=o.value;return t}if("error"===i){const[,{error:t}]=o.value;throw new Error(JSON.stringify(t))}throw new Error(`Unexpected proxy failure: unknown response type "${i}".`)}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)}}])));return H(new lt({url:"proxy"}).build(r))}} | ||
*/const yt=globalThis.process?t=>Buffer.from(t,"base64").toString("binary"):globalThis.atob,gt=globalThis.process?t=>Buffer.from(t,"binary").toString("base64"):globalThis.btoa;class bt{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 vt=(t,e)=>Object.fromEntries(Object.entries(e).map((([e,r])=>"string"==typeof r?[e,[new bt(e,t,r)]]:Array.isArray(r)?[e,r.map((r=>"string"==typeof r?new bt(e,t,r):new bt(e,t,r.to,r.when)))]:[e,[new bt(e,t,r.to,r.when)]]))),$t=Math.round(Date.now()/6048e5).toString(36),St=`T-${$t}-`,kt=`-${$t}-T`,Et=new RegExp(`(${St}.*?${kt})`,"gm"),Ot=new RegExp(`^${St}(.+?)${kt}$`),xt=async(t,e,r)=>{const s=JSON.stringify(t),n=s.split(Et).filter(Boolean).map((t=>{const e=t.match(Ot);if(e){const t=e[1].split("~"),[r,s,n]=t;return{nodeType:r,outputName:s,inputs:yt(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(""))},Pt=(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 $(r,t,n),s,(r=>((t,e,r)=>{const s=gt(JSON.stringify(r)).replace("=","");return`${St}${t}~${e}~${s}${kt}`})(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)=>$(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)=>xt(t,r,(async(t,r)=>$(e[t],r,s))))),s)]:[t,r]})));return{url:"tunnel-kit",handlers:n}},jt=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r};class Nt{#A;constructor(t){this.#A=t}async serve(t){const{kits:e}=t,r=this.#A.createServerStream(),s=Pt((t=>t.proxy?Object.fromEntries(t.proxy.map((t=>{if("string"!=typeof t&&t.tunnel)return[t.node,vt(t.node,t.tunnel)]})).filter(Boolean)):{})(t),S(e)),n=s.handlers;for await(const e of ct(r.writableResponses,r.readableRequests)){const[r]=e.data;if("end"===r)break;if("proxy"!==r){e.reply(["error",{error:"Expected proxy request.",timestamp:u()}]);continue}const[,{node:s,inputs:o}]=e.data,i=jt(s.type,t.proxy)?n[s.type]:void 0;if(i)try{const t=await $(i,o,{descriptor:s});if(!t){e.reply(["error",{error:"Handler returned nothing.",timestamp:u()}]);continue}e.reply(["proxy",{outputs:t}])}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 It{#A;constructor(t){this.#A=t}shutdownServer(){const t=this.#A.createClientStream().writableRequests.getWriter();t.write(["end",{timestamp:u()}]),t.close()}async proxy(t,e){const r=this.#A.createClientStream(),s=r.writableRequests.getWriter(),n=r.readableResponses.getReader();s.write(["proxy",{node:t,inputs:e}]),s.close();const o=await n.read();if(o.done)throw new Error("Unexpected proxy failure: empty response.");const[i]=o.value;if("proxy"===i){const[,{outputs:t}]=o.value;return t}if("error"===i){const[,{error:t}]=o.value;throw new Error(JSON.stringify(t))}throw new Error(`Unexpected proxy failure: unknown response type "${i}".`)}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)}}])));return V(new mt({url:"proxy"}).build(r))}} | ||
/** | ||
@@ -152,3 +147,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Nt=t=>t.base?t.base:"window"in self?new URL(self.location.href):new URL(import.meta.url);class jt{#D;constructor(t){this.#D=t}client(t){return new pt(this.#D.send(t))}server(t){return new ht(this.#D.receive(t))}}const It=async t=>{if("worker"!==t.transport)throw new Error("Only worker transport is supported at this time.");const e="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:(()=>{throw new Error("Not implemented")})(),r=new jt(new dt(e)),s=((t,e)=>t.map((t=>"proxy"in t?new Pt(e.client("proxy")).createProxyKit(t.proxy):t)))(t.kits,r),n=new it(r.server("run")),o=await(async(t,e)=>{const r=t.url;if(r)return r;const s=new V(e.server("load"));return await s.serve()})(t,r),i=Nt(t),a=await G.load(o,{base:i});return n.serve(a,!!t.diagnostics,{kits:s})},Rt=t=>t; | ||
*/const Rt=t=>t.base?t.base:"window"in self?new URL(self.location.href):new URL(import.meta.url);class qt{#D;constructor(t){this.#D=t}client(t){return new ft(this.#D.send(t))}server(t){return new wt(this.#D.receive(t))}}const Ct=async t=>{if("worker"!==t.transport)throw new Error("Only worker transport is supported at this time.");const e="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:(()=>{throw new Error("Not implemented")})(),r=new qt(new lt(e)),s=((t,e)=>t.map((t=>"proxy"in t?new It(e.client("proxy")).createProxyKit(t.proxy):t)))(t.kits,r),n=new ut(r.server("run")),o=await(async(t,e)=>{const r=t.url;if(r)return r;const s=new X(e.server("load"));return await s.serve()})(t,r),i=Rt(t),a=await Q.load(o,{base:i});return n.serve(a,!!t.diagnostics,{kits:s})},At=t=>t; | ||
/** | ||
@@ -159,3 +154,3 @@ * @license | ||
*/ | ||
class qt{} | ||
class Tt{} | ||
/** | ||
@@ -165,3 +160,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Ct=new U;class At extends qt{id;type;outgoing=[];incoming=[];configuration={};#_;#z;constructor(t,e,r={}){super(),this.#z=e,"string"==typeof t?this.type=t:(this.type="fn",this.#_=t);const{$id:s,...n}=r;this.id=s??Ct.vendId(e,this.type),this.configuration=n}addIncomingEdge(t,e,r,s,n){if(t.#z!==this.#z)throw new Error("Can't connect nodes from different scopes");const o={to:this,from:t,out:e,in:r,schema:n};s&&(o.constant=!0),this.incoming.push(o),t.outgoing.push(o)}#H(t){const e=this.#_??t.getHandler(this.type);return e&&"function"!=typeof e?e.describe:void 0}async invoke(t,e){const r=e??this.#z,s=this.#_??r.getHandler(this.type);let n;const o="function"==typeof s?s:s?.invoke;if(o)n=await o(t,this);else{if(!s||"function"==typeof s||!s.graph)throw new Error(`Can't find handler for ${this.id}`);{const e=s.graph.getPinnedNodes();if(1!==e.length)throw new Error("Expected exactly one graph");n=await r.invokeOneRound(t,e[0])}}return n}async describe(t=this.#z,e,r,s){const n=this.#H(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#z.serialize(t,this)}async serializeNode(){return[{id:this.id,type:this.type,configuration:this.configuration}]}} | ||
*/const Mt=new z;class Ft extends Tt{id;type;outgoing=[];incoming=[];configuration={};metadata;#_;#z;constructor(t,e,r={}){super(),this.#z=e,"string"==typeof t?this.type=t:(this.type="fn",this.#_=t);const{$id:s,$metadata:n,...o}=r;this.id=s??Mt.vendId(e,this.type),n&&(this.metadata=n),this.configuration=o}addIncomingEdge(t,e,r,s,n){if(t.#z!==this.#z)throw new Error("Can't connect nodes from different scopes");const o={to:this,from:t,out:e,in:r,schema:n};s&&(o.constant=!0),this.incoming.push(o),t.outgoing.push(o)}#H(t){const e=this.#_??t.getHandler(this.type);return e&&"function"!=typeof e?e.describe:void 0}async invoke(t,e){const r=e??this.#z,s=this.#_??r.getHandler(this.type);let n;const o="function"==typeof s?s:s?.invoke;if(o)n=await o(t,this);else{if(!s||"function"==typeof s||!s.graph)throw new Error(`Can't find handler for ${this.id}`);{const e=s.graph.getPinnedNodes();if(1!==e.length)throw new Error("Expected exactly one graph");n=await r.invokeOneRound(t,e[0])}}return n}async describe(t=this.#z,e,r,s){const n=this.#H(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#z.serialize(t,this)}async serializeNode(){const t={id:this.id,type:this.type,configuration:this.configuration};return this.metadata&&(t.metadata=this.metadata),[t]}} | ||
/** | ||
@@ -171,3 +166,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Tt{queue=[];inputs=new Map;constants=new Map;controlWires=new Map;haveRun=new Set;queueUp(t){this.queue.includes(t)||this.queue.push(t)}next(){if(!this.queue.length)throw new Error("No nodes in queue");return this.queue.shift()}done(){return 0===this.queue.length}missingInputs(t){if(0===t.incoming.length&&this.haveRun.has(t))return[];const e=new Set(t.incoming.map((t=>t.in))),r=new Set([...Object.keys(t.configuration),...Object.keys(this.constants.get(t)??{})]);for(const[e,s]of(this.inputs.get(t)??new Map).entries())s.length&&r.add(e);this.controlWires.get(t)?.length&&r.add("");const s=[...e].filter((t=>!r.has(t)));return!!s.length&&s}shiftInputs(t){const e={...t.configuration,...this.constants.get(t)},r=this.inputs.get(t)??new Map;for(const[t,s]of r.entries())s.length>0&&(e[t]=s.shift());return this.haveRun.add(t),this.controlWires.delete(t),e}processResult(t,e){const r={nodes:[],unused:[]},s=new Set(Object.keys(e));for(const n of t.outgoing){const t=this.distributeResults(n,e);t.forEach((t=>s.delete(t)));const o=this.missingInputs(n.to);o||this.queueUp(n.to),r.nodes.push({node:n.to,received:t,missing:o})}return r.unused=[...s],r}distributeResults(t,e){const r="*"===t.out?e:""===t.out?{}:void 0!==e[t.out]?{[t.in]:e[t.out]}:{};t.constant&&this.constants.set(t.to,{...this.constants.get(t.to),...r}),this.inputs.has(t.to)||this.inputs.set(t.to,new Map);const s=this.inputs.get(t.to);for(const t of Object.keys(r))s?.has(t)||s?.set(t,[]),s?.get(t)?.push(r[t]);return""===t.in&&this.controlWires.set(t.to,[...this.controlWires.get(t.to)??[],t.from]),Object.keys(r)}} | ||
*/class Wt{queue=[];inputs=new Map;constants=new Map;controlWires=new Map;haveRun=new Set;queueUp(t){this.queue.includes(t)||this.queue.push(t)}next(){if(!this.queue.length)throw new Error("No nodes in queue");return this.queue.shift()}done(){return 0===this.queue.length}missingInputs(t){if(0===t.incoming.length&&this.haveRun.has(t))return[];const e=new Set(t.incoming.map((t=>t.in))),r=new Set([...Object.keys(t.configuration),...Object.keys(this.constants.get(t)??{})]);for(const[e,s]of(this.inputs.get(t)??new Map).entries())s.length&&r.add(e);this.controlWires.get(t)?.length&&r.add("");const s=[...e].filter((t=>!r.has(t)));return!!s.length&&s}shiftInputs(t){const e={...t.configuration,...this.constants.get(t)},r=this.inputs.get(t)??new Map;for(const[t,s]of r.entries())s.length>0&&(e[t]=s.shift());return this.haveRun.add(t),this.controlWires.delete(t),e}processResult(t,e){const r={nodes:[],unused:[]},s=new Set(Object.keys(e));for(const n of t.outgoing){const t=this.distributeResults(n,e);t.forEach((t=>s.delete(t)));const o=this.missingInputs(n.to);o||this.queueUp(n.to),r.nodes.push({node:n.to,received:t,missing:o})}return r.unused=[...s],r}distributeResults(t,e){const r="*"===t.out?e:""===t.out?{}:void 0!==e[t.out]?{[t.in]:e[t.out]}:{};t.constant&&this.constants.set(t.to,{...this.constants.get(t.to),...r}),this.inputs.has(t.to)||this.inputs.set(t.to,new Map);const s=this.inputs.get(t.to);for(const t of Object.keys(r))s?.has(t)||s?.set(t,[]),s?.get(t)?.push(r[t]);return""===t.in&&this.controlWires.set(t.to,[...this.controlWires.get(t.to)??[],t.from]),Object.keys(r)}} | ||
/** | ||
@@ -177,3 +172,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Mt{parentLexicalScope;parentDynamicScope;#J={};#G=[];#V=[];constructor(t={}){this.parentLexicalScope=t.lexicalScope,this.parentDynamicScope=t.dynamicScope}addHandlers(t){Object.entries(t).forEach((([t,e])=>this.#J[t]=e))}getHandler(t){return this.#J[t]||this.parentDynamicScope?.getHandler(t)||this.parentLexicalScope?.getHandler(t)}pin(t){this.#G.push(t)}compactPins(){const t=new Set,e=[];for(const r of this.#G){if(t.has(r))continue;e.push(r);this.#K(r).forEach((e=>t.add(e)))}this.#G=e}getPinnedNodes(){return this.#G}addCallbacks(t){this.#V.push(t)}#Q(){return[...this.#V,...this.parentDynamicScope?this.parentDynamicScope.#Q():[]]}async invoke(t,e=new Tt){try{!1!==t&&(t?t instanceof Array?t:[t]:this.#G).flatMap((t=>this.#K(t).filter((t=>!1===e?.missingInputs(t))))).forEach((t=>e?.queueUp(t)));const r=this.#Q();for(;!e.done();){for(const t of r)if(await(t.stop?.(this,e)))return;const t=e.next(),s=e.shiftInputs(t);let n;for(const e of r)n??=await(e.before?.(this,t,s));const o=n??await t.invoke(s,this).catch((t=>({$error:{type:"error",error:t}}))),i=e.processResult(t,o);for(const e of r)await(e.after?.(this,t,s,o,i));if(i.unused.includes("$error"))throw o.$error.error}}finally{for(const t of this.#V)await(t.done?.())}}invokeOneRound(t={},e=void 0,r){let s;"$state"in t&&(r=t.$state,delete t.$state);const n=new Promise((t=>{s=t})),o=new Mt({dynamicScope:this});let i;o.addHandlers({input:async()=>t,output:async t=>(s?.(await t),s=void 0,t)});const a=new Map;let c;o.addCallbacks({stop:(t,e)=>(s||(c=e),!s),after:(t,e,r,s,n)=>{i=e;for(const{node:t,missing:e}of n.nodes)e?a.set(t.id,e.join(", ")):a.delete(t.id)},done:()=>{s?.({$error:{type:"error",error:new Error(`Output node never reach. Last node was ${i?.id}.\n\nThese nodes had inputs missing:\n${Array.from(a,(([t,e])=>` ${t}: ${e}`)).join("\n")}`)}})}});const u=o.invoke(void 0!==e?e:this.#G,r);return Promise.all([n,u]).then((([t])=>({...t,...c?{$state:c}:{}})))}async serialize(t,e){const r=(e?[e]:this.#G).flatMap((t=>this.#K(t))),s={},n=await Promise.all(r.map((async t=>{const[e,r]=await t.serializeNode();if(r&&(s[e.id]=r),("input"===e.type||"output"===e.type)&&!e.configuration?.schema){const r=await this.#X(t);Object.entries(r.properties??{}).length>0&&(e.configuration={...e.configuration,schema:r})}return e}))),o=r.flatMap((t=>t.outgoing.map((t=>({from:t.from.id,to:t.to.id,out:t.out,in:t.in,...t.constant?{constant:!0}:{}})))));return{...t,edges:o,nodes:n,graphs:s}}#K(t){const e=new Set,r=[t];for(;r.length;){const t=r.shift();e.has(t)||(e.add(t),t.incoming.forEach((t=>r.push(t.from))),t.outgoing.forEach((t=>r.push(t.to))))}return[...e]}async#Y(t){const e=Object.fromEntries(t.incoming.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}]))),r=Object.fromEntries(t.outgoing.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}])));return await t.describe(this,t.configuration,{properties:e},{properties:r})}async#X(t){const e={},r=new Set;if("input"===t.type){const s=new Set;for(const n of t.outgoing)"*"!==n.out&&""!==n.out&&(s.add(n.to),r.add(n.out),n.schema&&(e[n.out]=n.schema));for(const r of s){const s=await this.#Y(r),n=s?.inputSchema?.properties;if(n)for(const s of r.incoming)s.from===t&&n[s.in]&&(e[s.out]={...n[s.in],...e[s.out]})}}else{if("output"!==t.type)throw new Error("Can't yet derive schema for non-input/output nodes");{const s=new Set;for(const n of t.incoming)"*"!==n.out&&""!==n.out&&(s.add(n.from),r.add(n.in),n.schema&&(e[n.in]=n.schema));for(const r of s){const s=await this.#Y(r),n=s?.outputSchema?.properties;if(n)for(const s of r.outgoing)s.to===t&&n[s.out]&&(e[s.in]={...n[s.out],...e[s.in]})}}}for(const t of r)e[t]?(e[t].type||="string",e[t].title||=t):e[t]={type:"string",title:t};const s=(t=>Object.entries(t).map((([t,e])=>{const r=e;if(!r.$optional)return t;delete r.$optional})).filter(Boolean))(e);return{type:"object",properties:e,required:s}}} | ||
*/class Bt{parentLexicalScope;parentDynamicScope;#J={};#G=[];#V=[];constructor(t={}){this.parentLexicalScope=t.lexicalScope,this.parentDynamicScope=t.dynamicScope}addHandlers(t){Object.entries(t).forEach((([t,e])=>this.#J[t]=e))}getHandler(t){return this.#J[t]||this.parentDynamicScope?.getHandler(t)||this.parentLexicalScope?.getHandler(t)}pin(t){this.#G.push(t)}compactPins(){const t=new Set,e=[];for(const r of this.#G){if(t.has(r))continue;e.push(r);this.#K(r).forEach((e=>t.add(e)))}this.#G=e}getPinnedNodes(){return this.#G}addCallbacks(t){this.#V.push(t)}#Q(){return[...this.#V,...this.parentDynamicScope?this.parentDynamicScope.#Q():[]]}async invoke(t,e=new Wt){try{!1!==t&&(t?t instanceof Array?t:[t]:this.#G).flatMap((t=>this.#K(t).filter((t=>!1===e?.missingInputs(t))))).forEach((t=>e?.queueUp(t)));const r=this.#Q();for(;!e.done();){for(const t of r)if(await(t.stop?.(this,e)))return;const t=e.next(),s=e.shiftInputs(t);let n;for(const e of r)n??=await(e.before?.(this,t,s));const o=n??await t.invoke(s,this).catch((t=>({$error:{type:"error",error:t}}))),i=e.processResult(t,o);for(const e of r)await(e.after?.(this,t,s,o,i));if(i.unused.includes("$error"))throw o.$error.error}}finally{for(const t of this.#V)await(t.done?.())}}invokeOneRound(t={},e=void 0,r){let s;"$state"in t&&(r=t.$state,delete t.$state);const n=new Promise((t=>{s=t})),o=new Bt({dynamicScope:this});let i;o.addHandlers({input:async()=>t,output:async t=>(s?.(await t),s=void 0,t)});const a=new Map;let c;o.addCallbacks({stop:(t,e)=>(s||(c=e),!s),after:(t,e,r,s,n)=>{i=e;for(const{node:t,missing:e}of n.nodes)e?a.set(t.id,e.join(", ")):a.delete(t.id)},done:()=>{s?.({$error:{type:"error",error:new Error(`Output node never reached. Last node was ${i?.id}.\n\nThese nodes had inputs missing:\n${Array.from(a,(([t,e])=>` ${t}: ${e}`)).join("\n")}`)}})}});const u=o.invoke(void 0!==e?e:this.#G,r);return Promise.all([n,u]).then((([t])=>({...t,...c?{$state:c}:{}})))}async serialize(t,e){const r=(e?[e]:this.#G).flatMap((t=>this.#K(t))),s={},n=await Promise.all(r.map((async t=>{const[e,r]=await t.serializeNode();if(r&&(s[e.id]=r),("input"===e.type||"output"===e.type)&&!e.configuration?.schema){const r=await this.#X(t);Object.entries(r.properties??{}).length>0&&(e.configuration={...e.configuration,schema:r})}return e}))),o=r.flatMap((t=>t.outgoing.map((t=>({from:t.from.id,to:t.to.id,out:t.out,in:t.in,...t.constant?{constant:!0}:{}})))));return{...t,edges:o,nodes:n,graphs:s}}#K(t){const e=new Set,r=[t];for(;r.length;){const t=r.shift();e.has(t)||(e.add(t),t.incoming.forEach((t=>r.push(t.from))),t.outgoing.forEach((t=>r.push(t.to))))}return[...e]}async#Y(t){const e=Object.fromEntries(t.incoming.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}]))),r=Object.fromEntries(t.outgoing.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}])));return await t.describe(this,t.configuration,{properties:e},{properties:r})}async#X(t){const e={},r=new Set;if("input"===t.type){const s=new Set;for(const n of t.outgoing)"*"!==n.out&&""!==n.out&&(s.add(n.to),r.add(n.out),n.schema&&(e[n.out]=n.schema));for(const r of s){const s=await this.#Y(r),n=s?.inputSchema?.properties;if(n)for(const s of r.incoming)s.from===t&&n[s.in]&&(e[s.out]={...n[s.in],...e[s.out]})}}else{if("output"!==t.type)throw new Error("Can't yet derive schema for non-input/output nodes");{const s=new Set;for(const n of t.incoming)"*"!==n.out&&""!==n.out&&(s.add(n.from),r.add(n.in),n.schema&&(e[n.in]=n.schema));for(const r of s){const s=await this.#Y(r),n=s?.outputSchema?.properties;if(n)for(const s of r.outgoing)s.to===t&&n[s.out]&&(e[s.in]={...n[s.out],...e[s.in]})}}}for(const t of r)e[t]?(e[t].type||="string",e[t].title||=t):e[t]={type:"string",title:t};const s=(t=>Object.entries(t).map((([t,e])=>{const r=e;if(!r.$optional)return t;delete r.$optional})).filter(Boolean))(e);return{type:"object",properties:e,required:s}}} | ||
/** | ||
@@ -183,3 +178,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/let Ft;function Wt(){return Ft||(Ft=new Lt),Ft}function Bt(t){const e=Wt();return Ft=t,e} | ||
*/let Lt;function Ut(){return Lt||(Lt=new _t),Lt}function Dt(t){const e=Ut();return Lt=t,e} | ||
/** | ||
@@ -189,3 +184,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Lt extends Mt{#Z;#tt=[];parentLambdaNode;constructor(t={}){super(t),this.#Z=t.serialize??!1,this.parentLambdaNode=t.parentLambda}async serialize(t,e){return super.serialize(t,e&&"function"==typeof e.unProxy?e.unProxy():e)}serializing(){return this.#Z}asScopeFor(t){return(...e)=>{const r=Bt(this);try{return t(...e)}finally{Bt(r)}}}addClosureEdge(t){this.#tt.push(t)}getClosureEdges(){return this.#tt}} | ||
*/class _t extends Bt{#Z;#tt=[];parentLambdaNode;constructor(t={}){super(t),this.#Z=t.serialize??!1,this.parentLambdaNode=t.parentLambda}async serialize(t,e){return super.serialize(t,e&&"function"==typeof e.unProxy?e.unProxy():e)}serializing(){return this.#Z}asScopeFor(t){return(...e)=>{const r=Dt(this);try{return t(...e)}finally{Dt(r)}}}addClosureEdge(t){this.#tt.push(t)}getClosureEdges(){return this.#tt}} | ||
/** | ||
@@ -195,3 +190,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Ut{} | ||
*/class zt{} | ||
/** | ||
@@ -201,3 +196,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Dt=Symbol("IsValue");function _t(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[Dt]}class zt extends Ut{#et;#z;#rt;#st;#nt;constructor(t,e,r,s=!1,n={}){super(),this.#et=t,this.#z=e,this.#rt="string"==typeof r?{[r]:r}:r,this[Dt]=this,this.#st=s,this.#nt=n}then(t,e){if(1!==Object.keys(this.#rt).length)throw Error("Can't `await` for multiple values");return this.#et.then((e=>e&&t&&this.#z.asScopeFor(t)(e[Object.keys(this.#rt)[0]])),e&&this.#z.asScopeFor(e))}asNodeInput(){return[this.#et.unProxy(),this.#rt,this.#st,this.#nt]}to(t,e){const r=Jt(t)?t.unProxy():new Ht(t,this.#z,e);return r.addInputsFromNode(this.#et,this.#rt,this.#st,this.#nt),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#rt).map((([t,e])=>[e,t])));_t(t)?(e=t.#ot(e),this.#et.addInputsFromNode(t.#et,e,t.#st,t.#nt)):Jt(t)?this.#et.addInputsFromNode(t.unProxy(),e):this.#et.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#rt).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#rt)[0]]:t}}else e=this.#ot(t);return new zt(this.#et,this.#z,e,this.#st,this.#nt)}memoize(){return new zt(this.#et,this.#z,this.#rt,!0,this.#nt)}invoke(t){return new Ht("invoke",this.#z,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#nt.type,this}isString(){return this.#nt.type="string",this}isNumber(){return this.#nt.type="number",this}isBoolean(){return this.#nt.type="boolean",this}isArray(){return this.#nt.type="array",this}isImage(t="image/png"){return this.#nt.type=t,this}isObject(){return this.#nt.type="object",this}title(t){return this.#nt.title=t,this}description(t){return this.#nt.description=t,this}format(t){return this.#nt.format=t,this}examples(...t){return this.#nt.examples=t,this}default(t){return this.#nt.default=t,this}optional(){return this.#nt.$optional=!0,this}transient(){return this.#nt.$optional=!0,this}#ot(t){const e={...this.#rt};return Object.entries(t).forEach((([t,r])=>{this.#rt[r]?(e[t]=this.#rt[r],delete this.#rt[r]):e[t]=r})),e}} | ||
*/const Ht=Symbol("IsValue");function Jt(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[Ht]}class Gt extends zt{#et;#z;#rt;#st;#nt;constructor(t,e,r,s=!1,n={}){super(),this.#et=t,this.#z=e,this.#rt="string"==typeof r?{[r]:r}:r,this[Ht]=this,this.#st=s,this.#nt=n}then(t,e){if(1!==Object.keys(this.#rt).length)throw Error("Can't `await` for multiple values");return this.#et.then((e=>e&&t&&this.#z.asScopeFor(t)(e[Object.keys(this.#rt)[0]])),e&&this.#z.asScopeFor(e))}asNodeInput(){return[this.#et.unProxy(),this.#rt,this.#st,this.#nt]}to(t,e){const r=Kt(t)?t.unProxy():new Vt(t,this.#z,e);return r.addInputsFromNode(this.#et,this.#rt,this.#st,this.#nt),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#rt).map((([t,e])=>[e,t])));Jt(t)?(e=t.#ot(e),this.#et.addInputsFromNode(t.#et,e,t.#st,t.#nt)):Kt(t)?this.#et.addInputsFromNode(t.unProxy(),e):this.#et.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#rt).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#rt)[0]]:t}}else e=this.#ot(t);return new Gt(this.#et,this.#z,e,this.#st,this.#nt)}memoize(){return new Gt(this.#et,this.#z,this.#rt,!0,this.#nt)}invoke(t){return new Vt("invoke",this.#z,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#nt.type,this}isString(){return this.#nt.type="string",this}isNumber(){return this.#nt.type="number",this}isBoolean(){return this.#nt.type="boolean",this}isArray(){return this.#nt.type="array",this}isImage(t="image/png"){return this.#nt.type=t,this}isObject(){return this.#nt.type="object",this}title(t){return this.#nt.title=t,this}description(t){return this.#nt.description=t,this}format(t){return this.#nt.format=t,this}examples(...t){return this.#nt.examples=t,this}default(t){return this.#nt.default=t,this}optional(){return this.#nt.$optional=!0,this}transient(){const t=this.#nt;return t.behavior??=[],t.behavior.push("transient"),this}#ot(t){const e={...this.#rt};return Object.entries(t).forEach((([t,r])=>{this.#rt[r]?(e[t]=this.#rt[r],delete this.#rt[r]):e[t]=r})),e}} | ||
/** | ||
@@ -207,3 +202,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Ht extends At{#it;#at;#ct;#z;#_;constructor(t,e,r={}){const s=!Jt(r)&&!(r instanceof qt)&&!Vt(r)&&!_t(r)&&r.$id;super(t,e,s?{$id:s}:{}),this.#z=e,"string"!=typeof t&&(this.#_=t),Jt(r)?this.addInputsFromNode(r.unProxy()):r instanceof qt?this.addInputsFromNode(r):Vt(r)?this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()}):_t(r)?this.addInputsFromNode(...r.asNodeInput()):(void 0!==r.$id&&delete r.$id,this.addInputsAsValues(r)),this[this.#ut()]=this,this.#it=new Promise(((t,e)=>{this.#at=t,this.#ct=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{Vt(s)&&(s=s.getBoardCapabilityAsValue()),_t(s)?r.push(s.as(t).asNodeInput()):s instanceof qt||Jt(s)?r.push([Jt(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(Jt(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const o=t.#z;if(o!==this.#z){for(let t=this.#z;t!==o;t=t.parentLexicalScope)if(!t)throw new Error("Only wires from parent scopes allowed");if("*"===e||""===e)throw new Error("Can't use * or empty wires from parent scopes");this.#z.addClosureEdge({scope:o,from:t,to:this,out:e,in:r})}else super.addIncomingEdge(t,e,r,s,n)}async invoke(t,e){const r=new Lt({dynamicScope:e,lexicalScope:this.#z});return r.asScopeFor((async()=>{try{const e=this.#_??r.getHandler(this.type);let s;const n="function"==typeof e?e:e?.invoke;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 Ht?s[t]=(await e)[t]:_t(e)?s[t]=await e:Vt(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#at&&(this.#at(s),this.#at=this.#ct=void 0),s}catch(t){throw this.#ct&&(this.#ct(t),this.#at=this.#ct=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 Lt({lexicalScope:this.#z,serialize:!0}),e=this.#_??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 r="function"==typeof e?e:e?.invoke;if(!r)throw new Error(`Handler for ${this.type} in ${this.id} not found`);let s=r.toString(),n=this.id.replace(/-/g,"_");const o=/(?:async\s*)?(\w+|\([^)]*\))\s*=>\s*/,i=/(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*\{/;if(o.test(s))s=s.replace(o,((t,e)=>{const r=s.trim().startsWith("async")?"async ":"",o=e.startsWith("(")?e:`(${e})`;return`${r}function ${n}${o} `}));else{const t=i.exec(s);if(null===t)throw new Error("Unexpected seralization: "+s);n=t[1]||n}const a=await this.describe(t),c={edges:[{from:`${this.id}-input`,to:`${this.id}-run`,out:"*"},{from:`${this.id}-run`,to:`${this.id}-output`,out:"*"}],nodes:[{id:`${this.id}-input`,type:"input",configuration:a?.inputSchema?{schema:a.inputSchema}:{}},{id:`${this.id}-run`,type:"runJavascript",configuration:{...this.configuration,code:s,name:n,raw:!0}},{id:`${this.id}-output`,type:"output",configuration:a?.outputSchema?{schema:a.outputSchema}:{}}]};return[{id:this.id,type:"invoke",configuration:{path:"#"+this.id}},c]}asProxy(){return new Proxy(this,{get(t,e,r){if("string"==typeof e){const r=new zt(t,t.#z,e);let s=t[e];return s=s&&"function"==typeof s?s.bind(t):(t=>r.invoke(t)).bind(r),new Proxy(s,{get(t,e,s){const n=Reflect.get(r,e,r);return"function"==typeof n?n.bind(r):n},ownKeys:t=>Reflect.ownKeys(r).filter((t=>"string"==typeof t))})}return Reflect.get(t,e,r)},ownKeys:t=>[t.#ut()]})}unProxy(){return this}then(t,e){if(this.#z.serializing())throw new Error(`Can't \`await\` on ${this.id} in board declaration. Did you mean to use \`code\` instead of \`board\`?`);try{return this.#z.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#z.asScopeFor(e));throw t})),this.#it.then(t&&this.#z.asScopeFor(t),e&&this.#z.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#z.asScopeFor(e));throw t}}to(t,e){const r=Jt(t)?t.unProxy():new Ht(t,this.#z,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof At?this.addInputsFromNode(t):_t(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new zt(this,this.#z,t)}keys(){return[this.#ut()]}#ut(){return"*-"+this.id}}function Jt(t){return"function"==typeof t.unProxy} | ||
*/class Vt extends Ft{#it;#at;#ct;#z;#_;constructor(t,e,r={}){const s=!Kt(r)&&!(r instanceof Tt)&&!Xt(r)&&!Jt(r)&&r.$id;if(super(t,e,s?{$id:s}:{}),this.#z=e,"string"!=typeof t&&(this.#_=t),Kt(r))this.addInputsFromNode(r.unProxy());else if(r instanceof Tt)this.addInputsFromNode(r);else if(Xt(r))this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()});else if(Jt(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.#ut()]=this,this.#it=new Promise(((t,e)=>{this.#at=t,this.#ct=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{Xt(s)&&(s=s.getBoardCapabilityAsValue()),Jt(s)?r.push(s.as(t).asNodeInput()):s instanceof Tt||Kt(s)?r.push([Kt(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(Kt(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const o=t.#z;if(o!==this.#z){for(let t=this.#z;t!==o;t=t.parentLexicalScope)if(!t)throw new Error("Only wires from parent scopes allowed");if("*"===e||""===e)throw new Error("Can't use * or empty wires from parent scopes");this.#z.addClosureEdge({scope:o,from:t,to:this,out:e,in:r})}else super.addIncomingEdge(t,e,r,s,n)}async invoke(t,e){const r=new _t({dynamicScope:e,lexicalScope:this.#z});return r.asScopeFor((async()=>{try{const e=this.#_??r.getHandler(this.type);let s;const n="function"==typeof e?e:e?.invoke;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 Vt?s[t]=(await e)[t]:Jt(e)?s[t]=await e:Xt(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#at&&(this.#at(s),this.#at=this.#ct=void 0),s}catch(t){throw this.#ct&&(this.#ct(t),this.#at=this.#ct=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 _t({lexicalScope:this.#z,serialize:!0}),e=this.#_??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 r="function"==typeof e?e:e?.invoke;if(!r)throw new Error(`Handler for ${this.type} in ${this.id} not found`);let s=r.toString(),n=this.id.replace(/-/g,"_");const o=/(?:async\s*)?(\w+|\([^)]*\))\s*=>\s*/,i=/(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*\{/;if(o.test(s))s=s.replace(o,((t,e)=>{const r=s.trim().startsWith("async")?"async ":"",o=e.startsWith("(")?e:`(${e})`;return`${r}function ${n}${o} `}));else{const t=i.exec(s);if(null===t)throw new Error("Unexpected seralization: "+s);n=t[1]||n}const a=await this.describe(t),c={edges:[{from:`${this.id}-input`,to:`${this.id}-run`,out:"*"},{from:`${this.id}-run`,to:`${this.id}-output`,out:"*"}],nodes:[{id:`${this.id}-input`,type:"input",configuration:a?.inputSchema?{schema:a.inputSchema}:{}},{id:`${this.id}-run`,type:"runJavascript",configuration:{code:s,name:n,raw:!0}},{id:`${this.id}-output`,type:"output",configuration:a?.outputSchema?{schema:a.outputSchema}:{}}]};return[{id:this.id,type:"invoke",configuration:{...this.configuration,$board:"#"+this.id}},c]}asProxy(){return new Proxy(this,{get(t,e,r){if("string"==typeof e){const r=new Gt(t,t.#z,e);let s=t[e];return s=s&&"function"==typeof s?s.bind(t):(t=>r.invoke(t)).bind(r),new Proxy(s,{get(t,e,s){const n=Reflect.get(r,e,r);return"function"==typeof n?n.bind(r):n},ownKeys:t=>Reflect.ownKeys(r).filter((t=>"string"==typeof t))})}return Reflect.get(t,e,r)},ownKeys:t=>[t.#ut()]})}unProxy(){return this}then(t,e){if(this.#z.serializing())throw new Error(`Can't \`await\` on ${this.id} in board declaration. Did you mean to use \`code\` instead of \`board\`?`);try{return this.#z.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#z.asScopeFor(e));throw t})),this.#it.then(t&&this.#z.asScopeFor(t),e&&this.#z.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#z.asScopeFor(e));throw t}}to(t,e){const r=Kt(t)?t.unProxy():new Vt(t,this.#z,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof Ft?this.addInputsFromNode(t):Jt(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new Gt(this,this.#z,t)}keys(){return[this.#ut()]}#ut(){return"*-"+this.id}}function Kt(t){return"function"==typeof t.unProxy} | ||
/** | ||
@@ -213,3 +208,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/function Gt(t,e){return t&&function(t,e){Wt().addHandlers({[t]:e})} | ||
*/function Qt(t,e){return t&&function(t,e){Ut().addHandlers({[t]:e})} | ||
/** | ||
@@ -219,3 +214,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/(t,e),r=>new Ht(t??e,Wt(),r).asProxy()}function Vt(t){return"function"==typeof t&&"function"==typeof t.getBoardCapabilityAsValue} | ||
*/(t,e),r=>new Vt(t??e,Ut(),r).asProxy()}function Xt(t){return"function"==typeof t&&"function"==typeof t.getBoardCapabilityAsValue} | ||
/** | ||
@@ -225,8 +220,14 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Kt=async()=>{throw new Error("Reserved word handler should never be invoked")};Gt("input",Kt),Gt("output",Kt);class Qt{#dt;#pt;#ht;constructor(t,e){this.#dt=t,this.#pt={...e,method:"POST",headers:{"Content-Type":"application/json"}},this.#ht=this.#pt.fetch??globalThis.fetch.bind(globalThis)}createClientStream(){let t;const e=new Promise((e=>{t=e})),r=this;return{readableResponses:new ReadableStream({async pull(t){const r=(await e).getReader();for(;;){const e=await r.read();if(e.done)break;console.log("%cServer-Sent Event Chunk","background: #009; color: #FFF",e.value),t.enqueue(e.value)}t.close()}}),writableRequests:new WritableStream({async write(e,s){if(!t)throw new Error("HTTPClientTransport supports only one write per stream instance.");const n=await r.#ht(r.#dt,{...r.#pt,body:JSON.stringify(e)});n.ok||s.error(new Error(`HTTP error: ${n.status}`)),t(n.body?.pipeThrough(new TextDecoderStream).pipeThrough((()=>{let t=[];return new TransformStream({transform(e,r){const s=!e.endsWith("\n"),n=e.split("\n").filter(Boolean);for(t.length&&!s&&(r.enqueue(`${t.join("")}${n.shift()}`),t=[]);n.length>1;)r.enqueue(n.shift());const o=n.shift();o&&(s?t.push(o):r.enqueue(o))},flush(){if(t.length)throw new Error("Unexpected end of stream.")}})})()).pipeThrough(new TransformStream({transform(t,e){t.startsWith("data: ")&&e.enqueue(t.slice(6))}})).pipeThrough((()=>{const t=new TransformStream,e=t.writable.getWriter();return new TransformStream({transform(r,s){const n=tt(r,(e=>{if(0!==e)throw new Error("HTTPClientTransport does not support multiple streams at the moment.");return t.readable})),[o]=Array.isArray(n)?n:[];"http-stream-chunk"===o?e.write(n[1].chunk):"http-stream-end"===o?e.close():s.enqueue(n)}})})())),t=void 0}})}}} | ||
*/const Yt=async()=>{throw new Error("Reserved word handler should never be invoked")}; | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
var Zt,te;Qt("input",Yt),Qt("output",Yt),function(t){t[t.In=0]="In",t[t.Out=1]="Out"}(Zt||(Zt={})),function(t){t.Inteterminate="indeterminate",t.Connected="connected",t.Ready="ready",t.Missing="missing",t.Dangling="dangling"}(te||(te={}));class ee{#dt;#pt;#ht;constructor(t,e){this.#dt=t,this.#pt={...e,method:"POST",headers:{"Content-Type":"application/json"}},this.#ht=this.#pt.fetch??globalThis.fetch.bind(globalThis)}createClientStream(){let t;const e=new Promise((e=>{t=e})),r=this;return{readableResponses:new ReadableStream({async pull(t){const r=(await e).getReader();for(;;){const e=await r.read();if(e.done)break;console.log("%cServer-Sent Event Chunk","background: #009; color: #FFF",e.value),t.enqueue(e.value)}t.close()}}),writableRequests:new WritableStream({async write(e,s){if(!t)throw new Error("HTTPClientTransport supports only one write per stream instance.");const n=await r.#ht(r.#dt,{...r.#pt,body:JSON.stringify(e)});n.ok||s.error(new Error(`HTTP error: ${n.status}`)),t(n.body?.pipeThrough(new TextDecoderStream).pipeThrough((()=>{let t=[];return new TransformStream({transform(e,r){const s=!e.endsWith("\n"),n=e.split("\n").filter(Boolean);for(t.length&&!s&&(r.enqueue(`${t.join("")}${n.shift()}`),t=[]);n.length>1;)r.enqueue(n.shift());const o=n.shift();o&&(s?t.push(o):r.enqueue(o))},flush(){if(t.length)throw new Error("Unexpected end of stream.")}})})()).pipeThrough(new TransformStream({transform(t,e){t.startsWith("data: ")&&e.enqueue(t.slice(6))}})).pipeThrough((()=>{const t=new TransformStream,e=t.writable.getWriter();return new TransformStream({transform(r,s){const n=st(r,(e=>{if(0!==e)throw new Error("HTTPClientTransport does not support multiple streams at the moment.");return t.readable})),[o]=Array.isArray(n)?n:[];"http-stream-chunk"===o?e.write(n[1].chunk):"http-stream-end"===o?e.close():s.enqueue(n)}})})())),t=void 0}})}}} | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Xt=t=>{const e=(()=>{if("nodestart"===t.type)return t.state})(),r=structuredClone(t.data);return{type:t.type,data:r,state:e,reply:async()=>{}}},Yt=t=>{const{type:e,node:r,timestamp:s}=t;if("input"===e){const{inputArguments:s}=t;return{type:e,data:{node:r,inputArguments:s},reply:async e=>{t.inputs=e.inputs}}}if("output"===e){const{outputs:n}=t;return{type:e,data:{node:r,outputs:n,timestamp:s},reply:async()=>{}}}throw new Error(`Unknown result type "${e}".`)},Zt=()=>({type:"end",data:{timestamp:u()},reply:async()=>{}}),te=t=>({type:"error",data:{error:t,timestamp:u()},reply:async()=>{}}); | ||
*/const re=t=>{const e=(()=>{if("nodestart"===t.type)return t.state})(),r=structuredClone(t.data);return{type:t.type,data:r,state:e,reply:async()=>{}}},se=t=>{const{type:e,node:r,timestamp:s}=t;if("input"===e){const{inputArguments:s}=t;return{type:e,data:{node:r,inputArguments:s},reply:async e=>{t.inputs=e.inputs}}}if("output"===e){const{outputs:n}=t;return{type:e,data:{node:r,outputs:n,timestamp:s},reply:async()=>{}}}throw new Error(`Unknown result type "${e}".`)},ne=()=>({type:"end",data:{timestamp:u()},reply:async()=>{}}),oe=t=>({type:"error",data:{error:t,timestamp:u()},reply:async()=>{}}); | ||
/** | ||
@@ -237,3 +238,3 @@ * @license | ||
*/ | ||
const ee=t=>{const e=new lt({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 H(e)},re=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 ie=t=>{const e=new mt({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 V(e)},ae=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"})}; | ||
/** | ||
@@ -249,3 +250,3 @@ * @license | ||
*/ | ||
const se=t=>{const e=t.proxy?.[0];if(!e)return t.kits;if("http"!==e.location)throw new Error("Only HTTP node proxy server is supported at this time.");if(!e.url)throw new Error("No node proxy server URL provided.");return[new Pt(new Qt(e.url)).createProxyKit(e.nodes),...t.kits]};async function*ne(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=re(t),n=new dt(s),o=new K(new pt(n.send("load"))),i=new xt(new ht(n.receive("proxy"))),a=new ct(new pt(n.send("run")));await o.load(e.url),yield*M((async t=>{const s=[ee(t),...e.kits],n=e.proxy?.[0]?.nodes;i.serve({kits:s,proxy:n});for await(const e of a.run(r))await t(e)}))}(e,t)}}else yield*M((async e=>{const r=[ee(e),...se(t)];for await(const s of async function*(t,e){yield*M((async r=>{const s=Nt(t),n=await G.load(t.url,{base:s});try{const s=t.diagnostics?new Q((async t=>{await r(Xt(t))})):void 0;for await(const t of n.run({probe:s,kits:e}))await r(Yt(t));await r(Zt())}catch(t){let e=t,s="";for(;e?.cause;)e=e.cause.error??{name:"Unexpected Error",message:JSON.stringify(e.cause,null,2)},e&&"message"in e&&(s+=`\n${e.message}`);console.error(s,e),await r(te(s))}}))}(t,r))await e(s)}))}export{ee as createSecretAskingKit,re as createWorker,Rt as defineServeConfig,ne as run,It as serve}; | ||
const ce=t=>{const e=t.proxy?.[0];if(!e)return t.kits;if("http"!==e.location)throw new Error("Only HTTP node proxy server is supported at this time.");if(!e.url)throw new Error("No node proxy server URL provided.");return[new It(new ee(e.url)).createProxyKit(e.nodes),...t.kits]};async function*ue(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=ae(t),n=new lt(s),o=new Y(new ft(n.send("load"))),i=new Nt(new wt(n.receive("proxy"))),a=new pt(new ft(n.send("run")));await o.load(e.url),yield*B((async t=>{const s=[ie(t),...e.kits],n=e.proxy?.[0]?.nodes;i.serve({kits:s,proxy:n});for await(const e of a.run(r))await t(e)}))}(e,t)}}else yield*B((async e=>{const r=[ie(e),...ce(t)];for await(const s of async function*(t,e){yield*B((async r=>{const s=Rt(t),n=t.runner||await Q.load(t.url,{base:s});try{const s=t.diagnostics?new Z((async t=>{await r(re(t))})):void 0;for await(const t of n.run({probe:s,kits:e}))await r(se(t));await r(ne())}catch(t){let e=t,s="";for(;e?.cause;)e=e.cause.error??{name:"Unexpected Error",message:JSON.stringify(e.cause,null,2)},e&&"message"in e&&(s+=`\n${e.message}`);console.error(s,e),await r(oe(s))}}))}(t,r))await e(s)}))}export{ie as createSecretAskingKit,ae as createWorker,At as defineServeConfig,ue as run,Ct as serve}; | ||
//# sourceMappingURL=harness.min.js.map |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
const t=t=>null==t?"null":Array.isArray(t)?"array":typeof t;class e{additionalProperties=!1;required=[];properties={};build(){const t={type:"object",properties:this.properties,additionalProperties:this.additionalProperties};return this.required.length>0&&(t.required=this.required),t}setAdditionalProperties(t){return void 0!==t&&(this.additionalProperties=t),this}addInputs(e){return e?(Object.entries(e).forEach((([e,r])=>{this.addProperty(e,{type:t(r)})})),this):this}addProperty(t,e){return this.properties[t]=e,this}addProperties(t){return Object.entries(t).forEach((([t,e])=>{this.addProperty(t,e)})),this}addRequired(t){return t?("string"==typeof t?this.required=[...this.required,t]:Array.isArray(t)&&t.length>0&&(this.required=[...this.required,...t]),this):this}static empty(t=!1){return(new e).setAdditionalProperties(t).build()}} | ||
const t=t=>null==t?"null":Array.isArray(t)?"array":typeof t;class e{type="object";additionalProperties=!1;required=[];properties={};build(){const t={type:"object",properties:this.properties};return this.additionalProperties||(t.additionalProperties=!1),this.required.length>0&&(t.required=this.required),t}addSchema(t){return"object"===t.type&&(this.addProperties(t.properties),this.addRequired(t.required),this.setAdditionalProperties(t.additionalProperties)),this}setAdditionalProperties(t){return void 0!==t&&(this.additionalProperties=t),this}addInputs(e){return e?(Object.entries(e).forEach((([e,r])=>{this.addProperty(e,{type:t(r)})})),this):this}addProperty(t,e){return this.properties[t]=e,this}addProperties(t){return t?(Object.entries(t).forEach((([t,e])=>{this.addProperty(t,e)})),this):this}addRequired(t){return t?("string"==typeof t?this.required=[...new Set([...this.required,t])]:Array.isArray(t)&&t.length>0&&(this.required=[...new Set([...this.required,...t])]),this.required.sort(),this):this}static empty(t=!1){return(new e).setAdditionalProperties(t).build()}} | ||
/** | ||
@@ -53,3 +53,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/;class f{#i;#n;#o;#a;constructor(t,e,r,s){this.#n=t,this.#i=e,this.#o=r,this.#a=s}get invocationId(){return this.#a}get type(){return this.#i}get node(){return this.#n.descriptor}get inputArguments(){return this.#n.inputs}set inputs(t){this.#n.outputsPromise=Promise.resolve(t)}get outputs(){return this.#n.inputs}get state(){return this.#n}async save(){return d(this.#i,this.#n)}get runState(){return this.#o}get timestamp(){return l()}isAtExitNode(){return 0===this.#n.newOpportunities.length&&0===this.#n.opportunities.length&&0===this.#n.pendingOutputs.size}static load(t){const{state:e,type:r}=(t=>{const{state:e,type:r}=JSON.parse(t,h);return{state:o.fromObject(e),type:r}})(t);return new f(e,r,void 0,0)}}class g extends f{constructor(t,e,r){super(t,"input",e,r)}get outputs(){throw new Error('Outputs are not available in the "input" stage')}}class w extends f{constructor(t,e){super(t,"output",void 0,e)}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 f{#i;#n;#o;#a;constructor(t,e,r,s){this.#n=t,this.#i=e,this.#o=r,this.#a=s}get invocationId(){return this.#a}get type(){return this.#i}get node(){return this.#n.descriptor}get inputArguments(){return this.#n.inputs}set inputs(t){this.#n.outputsPromise=Promise.resolve(t)}get outputs(){return this.#n.inputs}get state(){return this.#n}async save(){return d(this.#i,this.#n)}get runState(){return this.#o}get timestamp(){return l()}isAtExitNode(){return 0===this.#n.newOpportunities.length&&0===this.#n.opportunities.length&&0===this.#n.pendingOutputs.size}static load(t){const{state:e,type:r}=(t=>{const{state:e,type:r}=JSON.parse(t,h);return{state:o.fromObject(e),type:r}})(t);return new f(e,r,void 0,0)}}class w extends f{constructor(t,e,r){super(t,"input",e,r)}get outputs(){throw new Error('Outputs are not available in the "input" stage')}}class g extends f{constructor(t,e){super(t,"output",void 0,e)}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')}} | ||
/** | ||
@@ -64,3 +64,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ReadableStream.prototype[Symbol.asyncIterator]||(ReadableStream.prototype[Symbol.asyncIterator]=async function*(){const t=this.getReader();try{for(;;){const{done:e,value:r}=await t.read();if(e)return;yield r}}finally{t.releaseLock()}});class P{writable;readable;controller=null;constructor(){this.writable=new WritableStream({write:t=>this.write(t)}),this.readable=new ReadableStream({start:t=>{this.controller=t}})}write(t){(new TextDecoder).decode(t).split("\n").map((t=>t.trim())).filter((t=>t.length>0)).forEach((t=>{try{if("stop"===t)return void this.controller?.close();const e=JSON.parse(t);this.controller?.enqueue(e)}catch(t){console.error(t)}}))}}const k=async(t,e,r)=>{const s=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({inputs:e,state:r})});return s.body?.pipeThrough(new P)};async function*O(t){let e,r;for(;;){const s=await k(t,e,r);if(!s)break;for await(const t of s)r=JSON.stringify(t.state),yield t,e=t.inputs;if(!r)break}} | ||
*/ReadableStream.prototype[Symbol.asyncIterator]||(ReadableStream.prototype[Symbol.asyncIterator]=async function*(){const t=this.getReader();try{for(;;){const{done:e,value:r}=await t.read();if(e)return;yield r}}finally{t.releaseLock()}});class O{writable;readable;controller=null;constructor(){this.writable=new WritableStream({write:t=>this.write(t)}),this.readable=new ReadableStream({start:t=>{this.controller=t}})}write(t){(new TextDecoder).decode(t).split("\n").map((t=>t.trim())).filter((t=>t.length>0)).forEach((t=>{try{if("stop"===t)return void this.controller?.close();const e=JSON.parse(t);this.controller?.enqueue(e)}catch(t){console.error(t)}}))}}const P=async(t,e,r)=>{const s=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({inputs:e,state:r})});return s.body?.pipeThrough(new O)};async function*k(t){let e,r;for(;;){const s=await P(t,e,r);if(!s)break;for await(const t of s)r=JSON.stringify(t.state),yield t,e=t.inputs;if(!r)break}} | ||
/** | ||
@@ -70,3 +70,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const S=t=>t&&t.replace(/-/g,""),E=(t,e="")=>{if(!t)return"";const r=t.id,s=`${e?`${S(e)}_`:""}${S(r)}`,i=t.type,n=`"${i} <br> id='${r}'"`;switch(i){case"include":return`${s}[[${n}]]:::include`;case"slot":return`${s}((${n})):::slot`;case"passthrough":return`${s}((${n})):::passthrough`;case"input":return`${s}[/${n}/]:::input`;case"secrets":return`${s}(${n}):::secrets`;case"output":return`${s}{{${n}}}:::output`;default:return`${s}[${n}]`}};class I{nodeMap;edges;nodes;idPrefix;subgraphs;constructor(t,e=""){const{edges:r,nodes:s}=t;this.nodeMap=new Map(s.map((t=>[t.id,t]))),this.edges=r,this.nodes=s,this.idPrefix=e,this.subgraphs=t.graphs||{}}handleSlotted(t,e){const r=e?`${S(e)}_`:"";if("include"!==t.type)return"";const s=t.configuration?.slotted;if(!s)return"";return Object.entries(s).map((([e,s])=>this.describeSubgraph(s,e,"slotted",t,`${r}${t.id}`))).join("\n")}handleLambda(t,e){const r=e?`${S(e)}_`:"",s=t.configuration?.board;if(!s)return"";const i=s;if("board"!==i.kind)return"";const n=i.board;return this.describeSubgraph(n,t.id,"lamdba",t,`${r}${t.id}`)}describeSubgraphs(t,e=""){const r=this.nodeMap.get(t.from);if(!r)return"";const s=this.handleLambda(r,e);return`${this.handleSlotted(r,e)}${s}`}describeSubgraph(t,e,r,s,i){const n=new I(t,i).describeGraph(),o=this.idPrefix?`${S(this.idPrefix)}_`:"",a=r&&s?`sg_${S(e)}:::slotted -- "${r}->${r}" --o ${o}${S(s.id)}\n`:"";return`\nsubgraph sg_${S(e)} [${e}]\n${n}\nend\n${a}`}describeGraph(t=!1){return[...this.edges.map((e=>{const r=((t,e,r="")=>{const s=t.from,i=E(e.get(s),r),n=t.to,o=E(e.get(n),r),a=t.in,u=t.out,c=t.optional,p=t.constant;return"*"===u?`${i} -- all --\x3e ${o}`:u&&a?c?`${i} -. "${u}->${a}" .-> ${o}`:p?`${i} -- "${u}->${a}" --o ${o}`:`${i} -- "${u}->${a}" --\x3e ${o}`:`${i} --\x3e ${o}`})(e,this.nodeMap,this.idPrefix);return`${r}${t?"":this.describeSubgraphs(e,this.idPrefix)}`})),...t?"":Object.entries(this.subgraphs).map((([t,e])=>this.describeSubgraph(e,t,void 0,void 0,`${t}${this.idPrefix}`)))].join("\n")}}const x=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},q=async(t,e,r,s)=>{if(!e.requestInput)return;const i=await s.outputsPromise??{},n=new M(i,s.inputs);s.outputsPromise=n.read(j(t,e,r))},j=(t,e,r)=>async(s,i,n)=>{if(n)throw new Error(x(s,t,n));if(void 0!==i.default)return"type"in i&&"string"!==i.type?JSON.parse(i.default):i.default;const o=await(e.requestInput?.(s,i,r));if(void 0===o)throw new Error(x(s,t,n));return o}; | ||
*/const S=t=>t&&t.replace(/-/g,""),E=(t,e="")=>{if(!t)return"";const r=t.id,s=`${e?`${S(e)}_`:""}${S(r)}`,i=t.type,n=`"${i} <br> id='${r}'"`;switch(i){case"include":return`${s}[[${n}]]:::include`;case"slot":return`${s}((${n})):::slot`;case"passthrough":return`${s}((${n})):::passthrough`;case"input":return`${s}[/${n}/]:::input`;case"secrets":return`${s}(${n}):::secrets`;case"output":return`${s}{{${n}}}:::output`;default:return`${s}[${n}]`}};class q{nodeMap;edges;nodes;idPrefix;subgraphs;constructor(t,e=""){const{edges:r,nodes:s}=t;this.nodeMap=new Map(s.map((t=>[t.id,t]))),this.edges=r,this.nodes=s,this.idPrefix=e,this.subgraphs=t.graphs||{}}handleSlotted(t,e){const r=e?`${S(e)}_`:"";if("include"!==t.type)return"";const s=t.configuration?.slotted;if(!s)return"";return Object.entries(s).map((([e,s])=>this.describeSubgraph(s,e,"slotted",t,`${r}${t.id}`))).join("\n")}handleLambda(t,e){const r=e?`${S(e)}_`:"",s=t.configuration?.board;if(!s)return"";const i=s;if("board"!==i.kind)return"";const n=i.board;return this.describeSubgraph(n,t.id,"lamdba",t,`${r}${t.id}`)}describeSubgraphs(t,e=""){const r=this.nodeMap.get(t.from);if(!r)return"";const s=this.handleLambda(r,e);return`${this.handleSlotted(r,e)}${s}`}describeSubgraph(t,e,r,s,i){const n=new q(t,i).describeGraph(),o=this.idPrefix?`${S(this.idPrefix)}_`:"",a=r&&s?`sg_${S(e)}:::slotted -- "${r}->${r}" --o ${o}${S(s.id)}\n`:"";return`\nsubgraph sg_${S(e)} [${e}]\n${n}\nend\n${a}`}describeGraph(t=!1){return[...this.edges.map((e=>{const r=((t,e,r="")=>{const s=t.from,i=E(e.get(s),r),n=t.to,o=E(e.get(n),r),a=t.in,u=t.out,c=t.optional,p=t.constant;return"*"===u?`${i} -- all --\x3e ${o}`:u&&a?c?`${i} -. "${u}->${a}" .-> ${o}`:p?`${i} -- "${u}->${a}" --o ${o}`:`${i} -- "${u}->${a}" --\x3e ${o}`:`${i} --\x3e ${o}`})(e,this.nodeMap,this.idPrefix);return`${r}${t?"":this.describeSubgraphs(e,this.idPrefix)}`})),...t?"":Object.entries(this.subgraphs).map((([t,e])=>this.describeSubgraph(e,t,void 0,void 0,`${t}${this.idPrefix}`)))].join("\n")}}const I=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},x=async(t,e,r,s)=>{if(!e.requestInput)return;const i=await s.outputsPromise??{},n=new M(i,s.inputs);s.outputsPromise=n.read(j(t,e,r))},j=(t,e,r)=>async(s,i,n)=>{if(n)throw new Error(I(s,t,n));if(void 0!==i.default)return"type"in i&&"string"!==i.type?JSON.parse(i.default):i.default;const o=await(e.requestInput?.(s,i,r));if(void 0===o)throw new Error(I(s,t,n));return o}; | ||
/** | ||
@@ -76,14 +76,9 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class M{#p;#h;constructor(t,e){this.#p=t,this.#h=e}async read(t){if(!("schema"in this.#h))return this.#p;const e=this.#h.schema;if(!e.properties)return this.#p;const r=Object.entries(e.properties),s={};for(const[i,n]of r){if(i in this.#p){s[i]=this.#p[i];continue}const r=e.required?.includes(i)??!1,o=await t(i,n,r);s[i]=o}return{...this.#p,...s}}}class N{#d;#l=new Map;constructor(t){this.#d=t}createHandler(t,e){return async(r,s,i)=>{const n=this.#l.get(r);if(void 0!==n)return n;const o={id:i.id,type:i.type},a={...e,descriptor:o,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new g(a,void 0,-1));const u=await a.outputsPromise;let c=u&&u[r];return void 0===c&&(c=await(this.#d.requestInput?.(r,s,o))),s.transient||this.#l.set(r,c),c}}} | ||
*/class M{#p;#h;constructor(t,e){this.#p=t,this.#h=e}async read(t){if(!("schema"in this.#h))return this.#p;const e=this.#h.schema;if(!e.properties)return this.#p;const r=Object.entries(e.properties),s={};for(const[i,n]of r){if(i in this.#p){s[i]=this.#p[i];continue}const r=e.required?.includes(i)??!1,o=await t(i,n,r);s[i]=o}return{...this.#p,...s}}}class N{#d;#l=new Map;constructor(t){this.#d=t}createHandler(t,e){return async(r,s,i)=>{const n=this.#l.get(r);if(void 0!==n)return n;const o={id:i.id,type:i.type},a={...e,descriptor:o,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new w(a,void 0,-1));const u=await a.outputsPromise;let c=u&&u[r];return void 0===c&&(c=await(this.#d.requestInput?.(r,s,o))),A(s)||this.#l.set(r,c),c}}}const A=t=>t.behavior?.includes("transient")??!1,R=async(t,e,r)=>{if(!r.provideOutput)return!1;const s=e.configuration?.schema,i=s?.behavior?.includes("bubble");return!!i&&(await r.provideOutput(t,e),!0)},_=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s)=>{const i={...e,descriptor:s,inputs:r};await t(new g(i,-1))},T=()=>{};class G{#f=[];#w=T;#g;#b;abort=T;constructor(){this.#y()}#y(){this.#g=new Promise(((t,e)=>{this.#w=t,this.abort=e}))}#m(t){this.#f.push(t),1==this.#f.length&&(this.#w(),this.#y())}async write(t){return new Promise((e=>{this.#m({value:t,receipt:e})}))}async read(){this.#b&&this.#b(),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.#b=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#m({value:void 0,receipt:T})}}class D{#$;#v=!0;#f=new G;constructor(t){this.#$=t}async#O(t){return this.#f.write(t)}async next(){return this.#v&&(this.#v=!1,this.#$(this.#O.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}} | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const A=()=>{};class R{#f=[];#g=A;#w;#b;abort=A;constructor(){this.#y()}#y(){this.#w=new Promise(((t,e)=>{this.#g=t,this.abort=e}))}#m(t){this.#f.push(t),1==this.#f.length&&(this.#g(),this.#y())}async write(t){return new Promise((e=>{this.#m({value:t,receipt:e})}))}async read(){this.#b&&this.#b(),0===this.#f.length&&await this.#w;const t=this.#f.shift();if(!t)throw new Error("asyncGen queue should never be empty.");return this.#b=t.receipt,t.value?{done:!1,value:t.value}:{done:!0,value:void 0}}close(){this.#m({value:void 0,receipt:A})}}class T{#$;#v=!0;#f=new R;constructor(t){this.#$=t}async#P(t){return this.#f.write(t)}async next(){return this.#v&&(this.#v=!1,this.#$(this.#P.bind(this)).then((()=>{this.#f.close()})).catch((t=>{this.#f.abort(t)}))),this.#f.read()}} | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
class _{#k;#O;constructor(t){this.#k=structuredClone(t)||[]}onGraphStart(){this.#k.push({graph:0,node:0})}onNodeStart(t){this.#k[this.#k.length-1].node++,this.#O=t}onNodeEnd(){}onGraphEnd(){}async state(){const t=structuredClone(this.#k);return this.#O&&(t[t.length-1].state=await d("nodestart",this.#O)),t}}var G="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.2.0/packages/schema/breadboard.schema.json"; | ||
class C{#P;#k;constructor(t){this.#P=structuredClone(t)||[]}onGraphStart(){this.#P.push({graph:0,node:0})}onNodeStart(t){this.#P[this.#P.length-1].node++,this.#k=t}onNodeEnd(){}onGraphEnd(){}async state(){const t=structuredClone(this.#P);return this.#k&&(t[t.length-1].state=await d("nodestart",this.#k)),t}}var L="https://raw.githubusercontent.com/breadboard-ai/breadboard/@google-labs/breadboard-schema@1.2.0/packages/schema/breadboard.schema.json"; | ||
/** | ||
@@ -94,3 +89,3 @@ * @license | ||
*/ | ||
class D{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#S={};#E=[];#I;constructor({url:t,title:e,description:r,version:s,$schema:i}={$schema:G}){Object.assign(this,{$schema:i??G,url:t,title:e,description:r,version:s})}async*run(t={},e){const s=t.base||new URL(this.url||"",import.meta.url);var i;yield*(i=async i=>{const{probe:n}=t,o=await D.handlersFromBoard(this,t.kits),a={...this.#S,...t.slots};this.#E.forEach((t=>t.addGraph(this)));const u=new c(this,e?.state),p=new N(t),h=t.invocationPath||[],d=new _(t.state);await(n?.report?.({type:"graphstart",data:{metadata:this,path:h,timestamp:l()}}));let f=0;d.onGraphStart();const b=()=>[...h,f];for await(const e of u){f++;const{inputs:u,descriptor:c,missingInputs:h}=e;if(e.skip){await(n?.report?.({type:"skip",data:{node:c,inputs:u,missingInputs:h,path:b(),timestamp:l()}}));continue}let y;if(d.onNodeStart(e),await(n?.report?.({type:"nodestart",data:{node:c,inputs:u,path:b(),timestamp:l()},state:await d.state()})),"input"===c.type)await i(new g(e,await d.state(),f)),await q(this,t,c,e),y=e.outputsPromise;else if("output"===c.type)await i(new w(e,f)),y=e.outputsPromise;else{const n=o[c.type];if(!n)throw new Error(`No handler for node type "${c.type}"`);const h={...t,board:this,descriptor:c,outerGraph:this.#I||this,base:s,slots:a,kits:[...t.kits||[],...this.kits],requestInput:p.createHandler(i,e),invocationPath:b(),state:await d.state()};y=r(n,u,h)}d.onNodeEnd(),await(n?.report?.({type:"nodeend",data:{node:c,inputs:u,outputs:await y,validatorMetadata:this.#E.map((t=>t.getValidatorMetadata(c))),path:b(),timestamp:l()}})),e.outputsPromise=y}d.onGraphEnd(),await(n?.report?.({type:"graphend",data:{metadata:this,path:h,timestamp:l()}}))},{[Symbol.asyncIterator]:()=>new T(i)})}get validators(){return this.#E}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 i=e.invocationPath||[];for await(const n of this.run(e))if("input"===n.type)n.inputs=r;else if("output"===n.type){t=n.outputs,await(s?.report?.({type:"nodeend",data:{node:n.node,inputs:n.inputs,outputs:t,path:[...i,n.invocationId],timestamp:l()}})),await(s?.report?.({type:"graphend",data:{metadata:this,path:i,timestamp:l()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#E.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const i=new I(t).describeGraph(s);return r?((t,e)=>`graph ${e};\n${t}`)(i,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`)(i,e)})(this,t,e,r)}static async fromGraphDescriptor(t){const e=new D(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:i}=e||{},n=new v({base:r,graphs:i?.graphs}),{isSubgraph:o,graph:a}=await n.load(t),u=await D.fromGraphDescriptor(a);return o&&(u.#I=i),u.#S=s||{},u}static async fromBreadboardCapability(t){if("board"!==t.kind||!t.board)throw new Error(`Expected a "board" Capability, but got ${t}`);const e=t.board;if(!(e.edges&&e.kits&&e.nodes))throw new Error('Supplied "board" Capability argument is not actually a board');let r=t.board;return r.runOnce||(r=await D.fromGraphDescriptor(e)),r}static async handlersFromBoard(t,e=[]){const r=[new C,...e,...t.kits];return s(r)}static runRemote=O}class C{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 D.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}} | ||
class Q{url;title;description;$schema;version;edges=[];nodes=[];kits=[];graphs;args;#S={};#E=[];#q;constructor({url:t,title:e,description:r,version:s,$schema:i}={$schema:L}){Object.assign(this,{$schema:i??L,url:t,title:e,description:r,version:s})}async*run(t={},e){const s=t.base||new URL(this.url||"",import.meta.url);var i;yield*(i=async i=>{const{probe:n}=t,o=await Q.handlersFromBoard(this,t.kits),a={...this.#S,...t.slots};this.#E.forEach((t=>t.addGraph(this)));const u=new c(this,e?.state),p=new N(t),h=t.invocationPath||[],d=new C(t.state);await(n?.report?.({type:"graphstart",data:{metadata:this,path:h,timestamp:l()}}));let f=0;d.onGraphStart();const b=()=>[...h,f];for await(const e of u){f++;const{inputs:u,descriptor:c,missingInputs:h}=e;if(e.skip){await(n?.report?.({type:"skip",data:{node:c,inputs:u,missingInputs:h,path:b(),timestamp:l()}}));continue}let y;if(d.onNodeStart(e),await(n?.report?.({type:"nodestart",data:{node:c,inputs:u,path:b(),timestamp:l()},state:await d.state()})),"input"===c.type)await i(new w(e,await d.state(),f)),await x(this,t,c,e),y=e.outputsPromise;else if("output"===c.type)await R(u,c,t)||await i(new g(e,f)),y=e.outputsPromise;else{const n=o[c.type];if(!n)throw new Error(`No handler for node type "${c.type}"`);const h={...t,board:this,descriptor:c,outerGraph:this.#q||this,base:s,slots:a,kits:[...t.kits||[],...this.kits],requestInput:p.createHandler(i,e),provideOutput:_(i,e,t),invocationPath:b(),state:await d.state()};y=r(n,u,h)}d.onNodeEnd(),await(n?.report?.({type:"nodeend",data:{node:c,inputs:u,outputs:await y,validatorMetadata:this.#E.map((t=>t.getValidatorMetadata(c))),path:b(),timestamp:l()}})),e.outputsPromise=y}d.onGraphEnd(),await(n?.report?.({type:"graphend",data:{metadata:this,path:h,timestamp:l()}}))},{[Symbol.asyncIterator]:()=>new D(i)})}get validators(){return this.#E}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 i=e.invocationPath||[];for await(const n of this.run(e))if("input"===n.type)n.inputs=r;else if("output"===n.type){t=n.outputs,await(s?.report?.({type:"nodeend",data:{node:n.node,inputs:n.inputs,outputs:t,path:[...i,n.invocationId],timestamp:l()}})),await(s?.report?.({type:"graphend",data:{metadata:this,path:i,timestamp:l()}}));break}return t}catch(t){if(t.cause)return{$error:t.cause};throw t}}addValidator(t){this.#E.push(t)}mermaid(t="TD",e=!1,r=!1){return((t,e="TD",r=!1,s=!1)=>{const i=new q(t).describeGraph(s);return r?((t,e)=>`graph ${e};\n${t}`)(i,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`)(i,e)})(this,t,e,r)}static async fromGraphDescriptor(t){const e=new Q(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:i}=e||{},n=new v({base:r,graphs:i?.graphs}),{isSubgraph:o,graph:a}=await n.load(t),u=await Q.fromGraphDescriptor(a);return o&&(u.#q=i),u.#S=s||{},u}static async fromBreadboardCapability(t){if("board"!==t.kind||!t.board)throw new Error(`Expected a "board" Capability, but got ${t}`);const e=t.board;if(!(e.edges&&e.kits&&e.nodes))throw new Error('Supplied "board" Capability argument is not actually a board');let r=t.board;return r.runOnce||(r=await Q.fromGraphDescriptor(e)),r}static async handlersFromBoard(t,e=[]){const r=[new U,...e,...t.kits];return s(r)}static runRemote=k}class U{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 Q.fromBreadboardCapability(e),args:r};return{board:{...e,board:s}}}}}}} | ||
/** | ||
@@ -100,3 +95,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class L{graph;handlers;runner;constructor(t){this.graph=t}populateDescriptor(t){const{title:e,description:r,version:s}=this.graph;return{title:e,description:r,version:s,...t}}async#x(t,e=[]){const r=await D.fromGraphDescriptor(this.graph);r.url=t,this.handlers=e?.reduce(((t,e)=>({...t,...e.handlers})),{}),this.runner=r}handlerForNode(t){if(!this.graph)throw new Error("Builder was not yet initialized.");const{nodes:e}=this.graph,i=e.find((e=>e.id===t));if(!i)throw new Error(`Node ${t} not found in graph.`);return{invoke:async(t,e)=>{const n=i.configuration;n&&(t={...n,...t});const o={...this.handlers,...s(e?.kits||[])},a=o?.[i.type];if(!a)throw new Error(`No handler found for node "${i.type}".`);const u=this.runner,c=u.url?new URL(u.url):new URL(import.meta.url);return console.log("KIT HANDLER",e),r(a,t,{...e,outerGraph:u,base:c,kits:[...e.kits||[],...u.kits]})}}}static async create(t,e,r){const s=new L(t);return await s.#x(e,r),s}} | ||
*/class B{graph;handlers;runner;constructor(t){this.graph=t}populateDescriptor(t){const{title:e,description:r,version:s}=this.graph;return{title:e,description:r,version:s,...t}}async#I(t,e=[]){const r=await Q.fromGraphDescriptor(this.graph);r.url=t,this.handlers=e?.reduce(((t,e)=>({...t,...e.handlers})),{}),this.runner=r}handlerForNode(t){if(!this.graph)throw new Error("Builder was not yet initialized.");const{nodes:e}=this.graph,i=e.find((e=>e.id===t));if(!i)throw new Error(`Node ${t} not found in graph.`);return{invoke:async(t,e)=>{const n=i.configuration;n&&(t={...n,...t});const o={...this.handlers,...s(e?.kits||[])},a=o?.[i.type];if(!a)throw new Error(`No handler found for node "${i.type}".`);const u=this.runner,c=u.url?new URL(u.url):new URL(import.meta.url);return r(a,t,{...e,outerGraph:u,base:c,kits:[...e.kits||[],...u.kits]})}}}static async create(t,e,r){const s=new B(t);return await s.#I(e,r),s}} | ||
/** | ||
@@ -106,3 +101,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Q{url;title;description;version;namespacePrefix;constructor({title:t,description:e,version:r,url:s,namespacePrefix:i=""}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=i}#q(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:i,version:n}=this,o=this.#q(t),a=Object.keys(t);return class{title=s;description=i;version=n;url=e;get handlers(){return o}constructor(t){const e=new Proxy(this,{get:(s,i)=>"handlers"===i||"url"===i?s[i]:a.includes(i)?(s={})=>{const n=t.getConfigWithLambda(s),{$id:o,...a}=n;return t.create(e,`${r}${i}`,{...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()])),i=e[e.length-1];null!=i&&i.startsWith("___")&&r.push(...t[i]);const n=await s(...r);return"object"!=typeof n||Array.isArray(n)?{result:n}:{...n}}},t}),{});return new Q(t).build(r)}}export{L as GraphToKitAdapter,Q as KitBuilder,e as SchemaBuilder}; | ||
*/class F{url;title;description;version;namespacePrefix;constructor({title:t,description:e,version:r,url:s,namespacePrefix:i=""}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=i}#x(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:i,version:n}=this,o=this.#x(t),a=Object.keys(t);return class{title=s;description=i;version=n;url=e;get handlers(){return o}constructor(t){const e=new Proxy(this,{get:(s,i)=>"handlers"===i||"url"===i||"title"===i?s[i]:a.includes(i)?(s={})=>{const n=t.getConfigWithLambda(s),{$id:o,...a}=n;return t.create(e,`${r}${i}`,{...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()])),i=e[e.length-1];null!=i&&i.startsWith("___")&&r.push(...t[i]);const n=await s(...r);return"object"!=typeof n||Array.isArray(n)?{result:n}:{...n}}},t}),{});return new F(t).build(r)}}export{B as GraphToKitAdapter,F as KitBuilder,e as SchemaBuilder}; | ||
//# 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?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;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)}} | ||
/** | ||
@@ -84,3 +84,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class U{#h;constructor(t){this.#h=t}async serve(t,e=!1,r={}){const s=this.#h.createServerStream(),a=s.readableRequests.getReader();let o=await a.read();if(o.done)return;const i=(t=>{const[e,,r]=t;if(console.log("resumeRun",e,r),!r)return;if(r.length>1)throw new Error("I don't yet know how to resume from nested subgraphs.");const s=B.load(r[0].state);if("input"===e){const[,e]=t;s.inputs=e.inputs}return s})(o.value),u=s.writableResponses.getWriter(),c={...r,probe:e?new M((async t=>{const{type:e,data:r}=t,s=[e,n(r)];"nodestart"==e&&s.push(t.state),await u.write(s)})):void 0};try{for await(const e of t.run(c,i))if("input"===e.type){const t=e.runState,{node:r,inputArguments:s,timestamp:n}=e;if(await u.write(["input",{node:r,inputArguments:s,timestamp:n},t]),o=await a.read(),o.done)return void await u.close();{const[t,r]=o.value;"input"===t&&(e.inputs=r.inputs)}}else if("output"===e.type){const{node:t,outputs:r,timestamp:s}=e;await u.write(["output",{node:t,outputs:r,timestamp:s}])}await u.write(["end",{timestamp:P()}]),await u.close()}catch(t){const e=t;let r;if(e?.cause){const{cause:t}=e;r=t}else r=e.message;console.error("Run Server error:",r),await u.write(["error",{error:r,timestamp:P()}]),await u.close()}}}const H=t=>{const[e,r,s]=t.data;return{type:e,data:r,state:s,reply:async r=>{if("input"!==e)throw new Error("For now, we cannot reply to messages other than 'input'.");await t.reply([e,r,s])}}};class z{#h;constructor(t){this.#h=t}async*run(t){const e=this.#h.createClientStream(),r=u(e.writableRequests,e.readableResponses),s=["run",{}];t&&s.push(t),await r.start(s);for await(const t of r)yield H(t)}async runOnce(t){let e;for await(const r of this.run()){const{type:s,data:n}=r;if("input"===s)r.reply({inputs:t});else if("output"===s){e=n.outputs;break}}return e||{}}} | ||
*/class U{#h;constructor(t){this.#h=t}async serve(t,e=!1,r={}){const s=this.#h.createServerStream(),a=s.readableRequests.getReader();let o=await a.read();if(o.done)return;const i=(t=>{const[e,,r]=t;if(!r)return;if(r.length>1)throw new Error("I don't yet know how to resume from nested subgraphs.");const s=B.load(r[0].state);if("input"===e){const[,e]=t;s.inputs=e.inputs}return s})(o.value),u=s.writableResponses.getWriter(),c={...r,probe:e?new M((async t=>{const{type:e,data:r}=t,s=[e,n(r)];"nodestart"==e&&s.push(t.state),await u.write(s)})):void 0};try{for await(const e of t.run(c,i))if("input"===e.type){const t=e.runState,{node:r,inputArguments:s,timestamp:n}=e;if(await u.write(["input",{node:r,inputArguments:s,timestamp:n},t]),o=await a.read(),o.done)return void await u.close();{const[t,r]=o.value;"input"===t&&(e.inputs=r.inputs)}}else if("output"===e.type){const{node:t,outputs:r,timestamp:s}=e;await u.write(["output",{node:t,outputs:r,timestamp:s}])}await u.write(["end",{timestamp:P()}]),await u.close()}catch(t){const e=t;let r;if(e?.cause){const{cause:t}=e;r=t}else r=e.message;console.error("Run Server error:",r),await u.write(["error",{error:r,timestamp:P()}]),await u.close()}}}const H=t=>{const[e,r,s]=t.data;return{type:e,data:r,state:s,reply:async r=>{if("input"!==e)throw new Error("For now, we cannot reply to messages other than 'input'.");await t.reply([e,r,s])}}};class z{#h;constructor(t){this.#h=t}async*run(t){const e=this.#h.createClientStream(),r=u(e.writableRequests,e.readableResponses),s=["run",{}];t&&s.push(t),await r.start(s);for await(const t of r)yield H(t)}async runOnce(t){let e;for await(const r of this.run()){const{type:s,data:n}=r;if("input"===s)r.reply({inputs:t});else if("output"===s){e=n.outputs;break}}return e||{}}} | ||
/** | ||
@@ -87,0 +87,0 @@ * @license |
@@ -22,2 +22,4 @@ /** | ||
} | ||
export declare const bubbleUpOutputsIfNeeded: (outputs: OutputValues, descriptor: NodeDescriptor, context: NodeHandlerContext) => Promise<boolean>; | ||
export declare const createOutputProvider: (next: (result: RunResult) => Promise<void>, result: TraversalResult, context: NodeHandlerContext) => (outputs: Partial<Record<string, NodeValue>>, descriptor: NodeDescriptor) => Promise<void>; | ||
//# sourceMappingURL=bubble.d.ts.map |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import { InputStageResult } from "./run.js"; | ||
import { InputStageResult, OutputStageResult } from "./run.js"; | ||
export const createErrorMessage = (inputName, metadata = {}, required) => { | ||
@@ -96,4 +96,5 @@ const boardTitle = metadata.title ?? metadata?.url; | ||
} | ||
if (!schema.transient) | ||
if (!isTransient(schema)) { | ||
this.#cache.set(name, value); | ||
} | ||
return value; | ||
@@ -103,2 +104,28 @@ }; | ||
} | ||
const isTransient = (schema) => { | ||
return schema.behavior?.includes("transient") ?? false; | ||
}; | ||
export const bubbleUpOutputsIfNeeded = async (outputs, descriptor, context) => { | ||
if (!context.provideOutput) | ||
return false; | ||
const schema = descriptor.configuration?.schema; | ||
const shouldBubble = schema?.behavior?.includes("bubble"); | ||
if (!shouldBubble) | ||
return false; | ||
await context.provideOutput(outputs, descriptor); | ||
return true; | ||
}; | ||
export const createOutputProvider = (next, result, context) => { | ||
if (context.provideOutput) { | ||
return context.provideOutput; | ||
} | ||
return async (outputs, descriptor) => { | ||
const provideOutputResult = { | ||
...result, | ||
descriptor, | ||
inputs: outputs, | ||
}; | ||
await next(new OutputStageResult(provideOutputResult, -1)); | ||
}; | ||
}; | ||
//# sourceMappingURL=bubble.js.map |
@@ -8,3 +8,3 @@ /** | ||
export { serve, defineServeConfig } from "./serve.js"; | ||
export { run, type HarnessProxyConfig, type HarnessRemoteConfig, } from "./run.js"; | ||
export { run, type HarnessProxyConfig, type HarnessRemoteConfig, type RunConfig, } from "./run.js"; | ||
export type * from "./serve.js"; | ||
@@ -11,0 +11,0 @@ export { type KitConfig } from "./kits.js"; |
@@ -80,3 +80,3 @@ /** | ||
const base = baseURL(config); | ||
const runner = await Board.load(config.url, { base }); | ||
const runner = config.runner || (await Board.load(config.url, { base })); | ||
try { | ||
@@ -83,0 +83,0 @@ const probe = config.diagnostics |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import { Kit } from "../index.js"; | ||
import { BreadboardRunner, Kit } from "../index.js"; | ||
import { NodeProxyConfig } from "../remote/config.js"; | ||
@@ -62,4 +62,9 @@ import { HarnessRunResult } from "./types.js"; | ||
diagnostics?: boolean; | ||
/** | ||
* Specifies a runner to use. This can be used instead of loading a board | ||
* from a URL. | ||
*/ | ||
runner?: BreadboardRunner; | ||
}; | ||
export declare function run(config: RunConfig): AsyncGenerator<HarnessRunResult, void, unknown>; | ||
//# sourceMappingURL=run.d.ts.map |
@@ -8,3 +8,3 @@ /** | ||
import { ClientRunResult } from "../remote/run.js"; | ||
export declare const createSecretAskingKit: (next: (result: ClientRunResult<SecretResult>) => Promise<void>) => import("@google-labs/breadboard").Kit; | ||
export declare const createSecretAskingKit: (next: (result: ClientRunResult<SecretResult>) => Promise<void>) => import("../types.js").Kit; | ||
//# sourceMappingURL=secrets.d.ts.map |
@@ -6,5 +6,5 @@ /** | ||
*/ | ||
import { asRuntimeKit } from "@google-labs/breadboard"; | ||
import { KitBuilder } from "../kits/builder.js"; | ||
import { timestamp } from "../timestamp.js"; | ||
import { asRuntimeKit } from "../index.js"; | ||
export const createSecretAskingKit = (next) => { | ||
@@ -11,0 +11,0 @@ const secretAskingKit = new KitBuilder({ |
@@ -10,3 +10,3 @@ /** | ||
export { Node } from "./node.js"; | ||
export { SchemaBuilder } from "./schema.js"; | ||
export { SchemaBuilder, combineSchemas } from "./schema.js"; | ||
export { RunResult } from "./run.js"; | ||
@@ -27,2 +27,12 @@ export { TraversalMachine } from "./traversal/machine.js"; | ||
export { asyncGen } from "./utils/async-gen.js"; | ||
/** | ||
* The Inspector API. | ||
*/ | ||
export type * from "./inspector/types.js"; | ||
export { inspectableGraph as inspect } from "./inspector/index.js"; | ||
/** | ||
* The Editor API. | ||
*/ | ||
export type * from "./editor/types.js"; | ||
export { editGraph as edit } from "./editor/graph.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -9,3 +9,3 @@ /** | ||
export { Node } from "./node.js"; | ||
export { SchemaBuilder } from "./schema.js"; | ||
export { SchemaBuilder, combineSchemas } from "./schema.js"; | ||
export { RunResult } from "./run.js"; | ||
@@ -27,2 +27,4 @@ export { TraversalMachine } from "./traversal/machine.js"; | ||
export { asyncGen } from "./utils/async-gen.js"; | ||
export { inspectableGraph as inspect } from "./inspector/index.js"; | ||
export { editGraph as edit } from "./editor/graph.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -14,5 +14,5 @@ /** | ||
}; | ||
type FunctionsKeysOnly<T> = ({ | ||
type FunctionsKeysOnly<T> = { | ||
[P in keyof T]: T[P] extends (...args: any[]) => void ? P : never; | ||
})[keyof T]; | ||
}[keyof T]; | ||
type FunctionsOnly<T> = Pick<T, FunctionsKeysOnly<T>>; | ||
@@ -19,0 +19,0 @@ export declare class KitBuilder { |
@@ -44,3 +44,3 @@ /** | ||
get(target, prop) { | ||
if (prop === "handlers" || prop === "url") { | ||
if (prop === "handlers" || prop === "url" || prop === "title") { | ||
return target[prop]; | ||
@@ -69,3 +69,7 @@ } | ||
if (fn && fn.length > 0) { | ||
argNames = fn.toString().match(/\((.+?)\)/)?.[1].split(",") ?? []; | ||
argNames = | ||
fn | ||
.toString() | ||
.match(/\((.+?)\)/)?.[1] | ||
.split(",") ?? []; | ||
/* | ||
@@ -78,3 +82,6 @@ If fn.length is greater than 1 and argNames.length = 0, then we likely have a system function that accepts a splat of arguments.. | ||
*/ | ||
if (fn.length > 1 && argNames.length === 0 && "___args" in inputs && Array.isArray(inputs["___args"])) { | ||
if (fn.length > 1 && | ||
argNames.length === 0 && | ||
"___args" in inputs && | ||
Array.isArray(inputs["___args"])) { | ||
argNames = ["___args"]; | ||
@@ -90,3 +97,3 @@ } | ||
const args = argNames | ||
.filter(argName => argName.startsWith("___") == false) | ||
.filter((argName) => argName.startsWith("___") == false) | ||
.map((argName) => inputs[argName.trim()]); | ||
@@ -105,3 +112,3 @@ const lastArgName = argNames[argNames.length - 1]; | ||
return { ...results }; | ||
} | ||
}, | ||
}; | ||
@@ -108,0 +115,0 @@ return previous; |
@@ -23,3 +23,3 @@ /** | ||
handlerForNode(id: NodeIdentifier): { | ||
invoke: (inputs: InputValues, context: NodeHandlerContext) => Promise<void | Partial<Record<string, import("../types.js").NodeValue>>>; | ||
invoke: (inputs: InputValues, context: NodeHandlerContext) => Promise<void | Partial<Record<string, import("@google-labs/breadboard-schema/graph.js").NodeValue>>>; | ||
}; | ||
@@ -26,0 +26,0 @@ static create(graph: GraphDescriptor, url: string, kits: Kit[]): Promise<GraphToKitAdapter>; |
@@ -62,3 +62,2 @@ /** | ||
const base = board.url ? new URL(board.url) : new URL(import.meta.url); | ||
console.log("KIT HANDLER", context); | ||
return callHandler(handler, inputs, { | ||
@@ -65,0 +64,0 @@ ...context, |
@@ -6,3 +6,2 @@ /** | ||
*/ | ||
import { z } from "zod"; | ||
import { Schema } from "../../types.js"; | ||
@@ -12,21 +11,21 @@ import { InputsMaybeAsValues, NodeProxy } from "./types.js"; | ||
export declare const base: { | ||
input: (<T extends z.ZodType<any, z.ZodTypeDef, any>>(config: { | ||
input: (<T extends Schema>(config: { | ||
schema: T; | ||
$id?: string | undefined; | ||
} & Partial<z.TypeOf<T> extends infer T_1 extends import("./types.js").InputValues ? { [K in keyof T_1]: z.TypeOf<T>[K] | import("./types.js").AbstractValue<z.TypeOf<T>[K]> | NodeProxy<import("./types.js").InputValues, Partial<{ | ||
[key: string]: z.TypeOf<T>[K]; | ||
}>>; } : never> & { | ||
} & Partial<{ [K in keyof T]: T[K] | import("./types.js").AbstractValue<T[K]> | NodeProxy<import("./types.js").InputValues, Partial<{ | ||
[key: string]: T[K]; | ||
}>>; }> & { | ||
[x: string]: unknown; | ||
}) => NodeProxy<Record<string, never>, z.TypeOf<T>>) & ((config?: { | ||
}) => NodeProxy<Record<string, never>, T>) & ((config?: { | ||
schema?: Schema; | ||
$id?: string; | ||
} & InputsMaybeAsValues<InputValues>) => NodeProxy<InputValues, OutputValues>); | ||
output: (<T_2 extends z.ZodType<any, z.ZodTypeDef, any>>(config: { | ||
schema: T_2; | ||
output: (<T_1 extends Schema>(config: { | ||
schema: T_1; | ||
$id?: string | undefined; | ||
} & Partial<z.TypeOf<T_2> extends infer T_3 extends import("./types.js").InputValues ? { [K_1 in keyof T_3]: z.TypeOf<T_2>[K_1] | import("./types.js").AbstractValue<z.TypeOf<T_2>[K_1]> | NodeProxy<import("./types.js").InputValues, Partial<{ | ||
[key: string]: z.TypeOf<T_2>[K_1]; | ||
}>>; } : never> & { | ||
} & Partial<{ [K_1 in keyof T_1]: T_1[K_1] | import("./types.js").AbstractValue<T_1[K_1]> | NodeProxy<import("./types.js").InputValues, Partial<{ | ||
[key: string]: T_1[K_1]; | ||
}>>; }> & { | ||
[x: string]: unknown; | ||
}) => NodeProxy<z.TypeOf<T_2>, Record<string, never>>) & ((config?: { | ||
}) => NodeProxy<T_1, Record<string, never>>) & ((config?: { | ||
schema?: Schema; | ||
@@ -33,0 +32,0 @@ $id?: string; |
@@ -7,3 +7,2 @@ /** | ||
import { addNodeType } from "./kits.js"; | ||
import { convertZodToSchemaInConfig } from "./zod-utils.js"; | ||
const reservedWord = async () => { | ||
@@ -16,5 +15,5 @@ throw new Error("Reserved word handler should never be invoked"); | ||
export const base = { | ||
input: (config) => convertZodToSchemaInConfig(config, inputFactory), | ||
output: (config) => convertZodToSchemaInConfig(config, outputFactory), | ||
input: (config) => inputFactory(config), | ||
output: (config) => outputFactory(config), | ||
}; | ||
//# sourceMappingURL=base.js.map |
@@ -6,3 +6,2 @@ /** | ||
*/ | ||
import { zodToSchema } from "./zod-utils.js"; | ||
import { registerNodeType } from "./kits.js"; | ||
@@ -45,4 +44,4 @@ import { getCurrentContextScope } from "./default-scope.js"; | ||
}; | ||
const inputSchema = options.input && zodToSchema(options.input); | ||
const outputSchema = options.output && zodToSchema(options.output); | ||
const inputSchema = options.input; | ||
const outputSchema = options.output; | ||
const handler = {}; | ||
@@ -49,0 +48,0 @@ if (options.describe) |
@@ -6,6 +6,5 @@ /** | ||
*/ | ||
import { GraphDescriptor, NodeDescriptor } from "@google-labs/breadboard"; | ||
import { InputsMaybeAsValues, NodeProxy, NodeProxyMethods, AbstractValue, BuilderNodeInterface, BuilderNodeConfig } from "./types.js"; | ||
import { InputValues, OutputValues, NodeHandler, NodeTypeIdentifier, NodeValue, Serializeable, KeyMap, AbstractNode, ScopeInterface } from "../runner/types.js"; | ||
import { Schema } from "../../types.js"; | ||
import { GraphDescriptor, NodeDescriptor, Schema } from "../../types.js"; | ||
import { BaseNode } from "../runner/node.js"; | ||
@@ -12,0 +11,0 @@ import { BuilderScope } from "./scope.js"; |
@@ -42,4 +42,10 @@ /** | ||
else { | ||
if (config.$id !== undefined) | ||
if (config.$id !== undefined) { | ||
delete config["$id"]; | ||
} | ||
const metadata = config.$metadata; | ||
if (metadata !== undefined) { | ||
this.metadata = metadata; | ||
delete config["$metadata"]; | ||
} | ||
this.addInputsAsValues(config); | ||
@@ -283,3 +289,2 @@ } | ||
configuration: { | ||
...this.configuration, | ||
code, | ||
@@ -302,3 +307,6 @@ name, | ||
type: "invoke", | ||
configuration: { path: "#" + this.id }, | ||
configuration: { | ||
...this.configuration, | ||
$board: "#" + this.id, | ||
}, | ||
}; | ||
@@ -305,0 +313,0 @@ return [node, invokeGraph]; |
@@ -6,3 +6,2 @@ /** | ||
*/ | ||
import { GraphDescriptor, GraphMetadata } from "@google-labs/breadboard"; | ||
import { BuilderScopeInterface, ClosureEdge } from "./types.js"; | ||
@@ -12,2 +11,3 @@ import { AbstractNode, ScopeConfig } from "../runner/types.js"; | ||
import { BuilderNode } from "./node.js"; | ||
import { GraphMetadata, GraphDescriptor } from "../../types.js"; | ||
/** | ||
@@ -14,0 +14,0 @@ * Adds syntactic sugar to support unproxying and serialization of nodes/graphs. |
@@ -6,3 +6,2 @@ /** | ||
*/ | ||
import { z } from "zod"; | ||
import { BreadboardCapability, NodeDescriberFunction, GraphMetadata, Schema } from "../../types.js"; | ||
@@ -66,38 +65,18 @@ import { NodeValue as BaseNodeValue, OutputValue, NodeTypeIdentifier, NodeHandler, KeyMap, AbstractNode, Serializeable } from "../runner/types.js"; | ||
<I extends InputValues = InputValues, O extends OutputValues = OutputValues>(fn: GraphDeclarationFunction<I, O>): Lambda<I, Required<O>>; | ||
/** | ||
* Same as above, but accepting GraphMetadata as | ||
*/ | ||
/** | ||
* Disable for now, overloading is too confusing | ||
* | ||
<I extends InputValues = InputValues, O extends OutputValues = OutputValues>( | ||
options: { input?: z.Schema<I> } & GraphMetadata, | ||
fn: NodeProxyHandlerFunction<I, O> | ||
): Lambda<I, Required<O>>; | ||
*/ | ||
/** | ||
* Alternative version to above that infers the type of the passed in Zod type. | ||
* | ||
* @param options Object with at least `input`, `output` and `invoke` set | ||
*/ | ||
<IT extends z.ZodType, OT extends z.ZodType>(options: { | ||
input: IT; | ||
output: OT; | ||
invoke: (inputs: z.infer<IT>) => z.infer<OT> | PromiseLike<z.infer<OT>>; | ||
<I extends InputValues = InputValues, O extends OutputValues = OutputValues>(opts: { | ||
input?: Schema; | ||
output?: Schema; | ||
graph?: GraphDeclarationFunction; | ||
invoke?: NodeProxyHandlerFunction; | ||
describe?: NodeDescriberFunction; | ||
name?: string; | ||
} & GraphMetadata): Lambda<z.infer<IT>, Required<z.infer<OT>>>; | ||
/** | ||
* Same as above, but takes handler as a second parameter instead of as invoke | ||
* option. This looks a bit nicer in the code (less indentation). | ||
* | ||
* @param options `input` and `output` schemas | ||
* @param fn Handler function | ||
*/ | ||
<IT extends z.ZodType, OT extends z.ZodType>(options: { | ||
input: IT; | ||
output: OT; | ||
} & GraphMetadata): Lambda<I, Required<O>>; | ||
<I extends InputValues = InputValues, O extends OutputValues = OutputValues>(opts: { | ||
input?: Schema; | ||
output?: Schema; | ||
graph?: GraphDeclarationFunction; | ||
invoke?: NodeProxyHandlerFunction; | ||
describe?: NodeDescriberFunction; | ||
name?: string; | ||
} & GraphMetadata, fn: GraphDeclarationFunction<z.infer<IT>, z.infer<OT>>): Lambda<z.infer<IT>, Required<z.infer<OT>>>; | ||
} & GraphMetadata, fn: GraphDeclarationFunction<I, O>): Lambda<I, Required<O>>; | ||
} | ||
@@ -104,0 +83,0 @@ export type NodeProxyMethods<I extends InputValues, O extends OutputValues> = { |
@@ -159,3 +159,5 @@ /** | ||
transient() { | ||
this.#schema.$optional = true; | ||
const schema = this.#schema; | ||
schema.behavior ??= []; | ||
schema.behavior.push("transient"); | ||
return this; | ||
@@ -162,0 +164,0 @@ } |
@@ -6,5 +6,6 @@ /** | ||
*/ | ||
import { GraphDescriptor, GraphMetadata, NodeDescriptor, Schema, NodeDescriberResult } from "@google-labs/breadboard"; | ||
import { GraphDescriptor, GraphMetadata, NodeDescriptor, Schema, NodeDescriberResult } from "../../types.js"; | ||
import { InputValues, OutputValues, NodeHandler, NodeTypeIdentifier, Serializeable, AbstractNode, EdgeInterface, OptionalIdConfiguration, ScopeInterface } from "./types.js"; | ||
import { Scope } from "./scope.js"; | ||
import { NodeMetadata } from "@google-labs/breadboard-schema/graph.js"; | ||
export declare class BaseNode<I extends InputValues = InputValues, O extends OutputValues = OutputValues> extends AbstractNode<I, O> implements Serializeable { | ||
@@ -17,2 +18,3 @@ #private; | ||
configuration: Partial<I>; | ||
metadata?: NodeMetadata; | ||
constructor(handler: NodeTypeIdentifier | NodeHandler<I, O>, scope: ScopeInterface, config?: Partial<I> & OptionalIdConfiguration); | ||
@@ -19,0 +21,0 @@ addIncomingEdge(from: AbstractNode, out: string, in_: string, constant?: boolean, schema?: Schema): void; |
@@ -17,2 +17,3 @@ /** | ||
configuration = {}; | ||
metadata; | ||
#handler; | ||
@@ -30,4 +31,6 @@ #scope; | ||
} | ||
const { $id, ...rest } = config; | ||
const { $id, $metadata, ...rest } = config; | ||
this.id = $id ?? nodeIdVendor.vendId(scope, this.type); | ||
if ($metadata) | ||
this.metadata = $metadata; | ||
this.configuration = rest; | ||
@@ -99,2 +102,4 @@ } | ||
}; | ||
if (this.metadata) | ||
node.metadata = this.metadata; | ||
return [node]; | ||
@@ -101,0 +106,0 @@ } |
@@ -6,4 +6,4 @@ /** | ||
*/ | ||
import { GraphDescriptor, GraphMetadata } from "@google-labs/breadboard"; | ||
import { InputValues, OutputValues, NodeHandler, NodeHandlers, AbstractNode, ScopeInterface, InvokeCallbacks, ScopeConfig, StateInterface } from "./types.js"; | ||
import { AbstractNode, InputValues, InvokeCallbacks, NodeHandler, NodeHandlers, OutputValues, ScopeConfig, ScopeInterface, StateInterface } from "./types.js"; | ||
import { GraphDescriptor, GraphMetadata } from "../../types.js"; | ||
export declare class Scope implements ScopeInterface { | ||
@@ -10,0 +10,0 @@ #private; |
@@ -164,3 +164,3 @@ /** | ||
type: "error", | ||
error: new Error(`Output node never reach. Last node was ${lastNode?.id}.\n\nThese nodes had inputs missing:\n${Array.from(lastMissingInputs, ([id, missing]) => ` ${id}: ${missing}`).join("\n")}`), | ||
error: new Error(`Output node never reached. Last node was ${lastNode?.id}.\n\nThese nodes had inputs missing:\n${Array.from(lastMissingInputs, ([id, missing]) => ` ${id}: ${missing}`).join("\n")}`), | ||
}, | ||
@@ -167,0 +167,0 @@ }); |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
import { NodeMetadata } from "@google-labs/breadboard-schema/graph.js"; | ||
import { NodeDescriptor, GraphDescriptor, GraphMetadata, NodeDescriberFunction, NodeDescriberResult, NodeValue as OriginalNodeValue, Schema } from "../../types.js"; | ||
@@ -42,2 +43,3 @@ export type NodeValue = OriginalNodeValue | PromiseLike<NodeValue> | unknown; | ||
$id?: string; | ||
$metadata?: NodeMetadata; | ||
}; | ||
@@ -44,0 +46,0 @@ export declare abstract class AbstractNode<I extends InputValues = InputValues, O extends OutputValues = OutputValues> implements Serializeable { |
@@ -15,2 +15,3 @@ /** | ||
export type * from "./config.js"; | ||
export type * from "./http.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -12,3 +12,2 @@ /** | ||
const [type, , state] = request; | ||
console.log("resumeRun", type, state); | ||
// There may not be any state to resume from. | ||
@@ -15,0 +14,0 @@ if (!state) |
@@ -13,3 +13,3 @@ /** | ||
import { SchemaBuilder } from "./schema.js"; | ||
import { RequestedInputsManager, bubbleUpInputsIfNeeded } from "./bubble.js"; | ||
import { RequestedInputsManager, bubbleUpInputsIfNeeded, createOutputProvider, bubbleUpOutputsIfNeeded, } from "./bubble.js"; | ||
import { asyncGen } from "./utils/async-gen.js"; | ||
@@ -148,3 +148,5 @@ import { StackManager } from "./stack.js"; | ||
else if (descriptor.type === "output") { | ||
await next(new OutputStageResult(result, invocationId)); | ||
if (!(await bubbleUpOutputsIfNeeded(inputs, descriptor, context))) { | ||
await next(new OutputStageResult(result, invocationId)); | ||
} | ||
outputsPromise = result.outputsPromise; | ||
@@ -165,2 +167,3 @@ } | ||
requestInput: requestedInputs.createHandler(next, result), | ||
provideOutput: createOutputProvider(next, result, context), | ||
invocationPath: path(), | ||
@@ -167,0 +170,0 @@ state: await stack.state(), |
@@ -11,2 +11,3 @@ /** | ||
export declare class SchemaBuilder { | ||
type: string; | ||
additionalProperties: boolean; | ||
@@ -16,9 +17,18 @@ required: string[]; | ||
build(): Schema; | ||
addSchema(schema: Schema): this; | ||
setAdditionalProperties(additionalProperties?: boolean): this; | ||
addInputs(inputs?: InputValues): this; | ||
addProperty(name: string, schema: Schema): this; | ||
addProperties(properties: SchemaProperties): this; | ||
addProperties(properties?: SchemaProperties): this; | ||
addRequired(required?: string[] | string): this; | ||
static empty(additionalProperties?: boolean): Schema; | ||
} | ||
/** | ||
* Combines multiple schemas into a single schema. This is lossy, since | ||
* the same-named properties will be overriden (last one wins). However, | ||
* it's good enough to communicate the overall shape of the combined schema. | ||
* @param schemas - the schemas to combine | ||
* @returns - the combined schema | ||
*/ | ||
export declare const combineSchemas: (schemas: Schema[]) => Schema; | ||
//# sourceMappingURL=schema.d.ts.map |
@@ -16,2 +16,3 @@ /** | ||
export class SchemaBuilder { | ||
type = "object"; | ||
additionalProperties = false; | ||
@@ -24,4 +25,6 @@ required = []; | ||
properties: this.properties, | ||
additionalProperties: this.additionalProperties, | ||
}; | ||
if (!this.additionalProperties) { | ||
result.additionalProperties = false; | ||
} | ||
if (this.required.length > 0) { | ||
@@ -32,2 +35,10 @@ result.required = this.required; | ||
} | ||
addSchema(schema) { | ||
if (schema.type === "object") { | ||
this.addProperties(schema.properties); | ||
this.addRequired(schema.required); | ||
this.setAdditionalProperties(schema.additionalProperties); | ||
} | ||
return this; | ||
} | ||
setAdditionalProperties(additionalProperties) { | ||
@@ -52,2 +63,4 @@ if (additionalProperties !== undefined) { | ||
addProperties(properties) { | ||
if (!properties) | ||
return this; | ||
Object.entries(properties).forEach(([name, schema]) => { | ||
@@ -62,7 +75,8 @@ this.addProperty(name, schema); | ||
if (typeof required === "string") { | ||
this.required = [...this.required, required]; | ||
this.required = [...new Set([...this.required, required])]; | ||
} | ||
else if (Array.isArray(required) && required.length > 0) { | ||
this.required = [...this.required, ...required]; | ||
this.required = [...new Set([...this.required, ...required])]; | ||
} | ||
this.required.sort(); | ||
return this; | ||
@@ -76,2 +90,34 @@ } | ||
} | ||
/** | ||
* Combines multiple schemas into a single schema. This is lossy, since | ||
* the same-named properties will be overriden (last one wins). However, | ||
* it's good enough to communicate the overall shape of the combined schema. | ||
* @param schemas - the schemas to combine | ||
* @returns - the combined schema | ||
*/ | ||
export const combineSchemas = (schemas) => { | ||
const result = {}; | ||
schemas.forEach((schema) => { | ||
if (schema.type === "object") { | ||
if (schema.properties) { | ||
result.properties = { ...result.properties, ...schema.properties }; | ||
} | ||
if (schema.required) { | ||
result.required = [ | ||
...(result.required ?? []), | ||
...(schema.required ?? []), | ||
]; | ||
} | ||
if (schema.additionalProperties !== undefined) { | ||
result.additionalProperties = schema.additionalProperties; | ||
} | ||
} | ||
}); | ||
result.type = "object"; | ||
if (result.required) { | ||
result.required = [...new Set(result.required)]; | ||
result.required?.sort(); | ||
} | ||
return result; | ||
}; | ||
//# sourceMappingURL=schema.js.map |
@@ -6,2 +6,19 @@ /** | ||
*/ | ||
import type { Capability, Edge, GraphDescriptor, GraphMetadata, InputValues, KitDescriptor, NodeDescriptor, NodeIdentifier, NodeTypeIdentifier, NodeValue, OutputValues } from "@google-labs/breadboard-schema/graph.js"; | ||
export type { Capability, Edge, GraphDescriptor, GraphIdentifier, GraphMetadata, InputIdentifier, InputValues, KitDescriptor, KitReference, NodeConfiguration, NodeDescriptor, NodeIdentifier, NodeTypeIdentifier, NodeValue, OutputIdentifier, OutputValues, SubGraphs, } from "@google-labs/breadboard-schema/graph.js"; | ||
export type BehaviorSchema = | ||
/** | ||
* Indicates that this particular input port value should not be cached by | ||
* the input bubbling machinery. | ||
* Use this when you'd like to continually ask the user for the same input, | ||
* rather that re-using cached answer (default behavior). | ||
*/ | ||
"transient" | ||
/** | ||
* Indicates that the output node should bubble up to the invoking runner, | ||
* if any. | ||
* This is useful for sending outputs to the user from inside of the nested | ||
* graphs. | ||
*/ | ||
| "bubble"; | ||
export type Schema = { | ||
@@ -14,2 +31,8 @@ title?: string; | ||
format?: string; | ||
/** | ||
* Can be used to provide additional hints to the UI or to other parts of | ||
* the system about behavior of this particular input/output or input/output | ||
* port. | ||
*/ | ||
behavior?: BehaviorSchema[]; | ||
transient?: boolean; | ||
@@ -31,5 +54,2 @@ enum?: string[]; | ||
}; | ||
export interface Capability { | ||
readonly kind: string; | ||
} | ||
export type ErrorCapability = Capability & { | ||
@@ -42,166 +62,2 @@ readonly kind: "error"; | ||
/** | ||
* A type representing a valid JSON value. | ||
*/ | ||
export type NodeValue = string | number | boolean | null | undefined | NodeValue[] | Capability | { | ||
[key: string]: NodeValue; | ||
}; | ||
/** | ||
* Unique identifier of a node in a graph. | ||
*/ | ||
export type NodeIdentifier = string; | ||
/** | ||
* Unique identifier of a node's output. | ||
*/ | ||
export type OutputIdentifier = string; | ||
/** | ||
* Unique identifier of a node's input. | ||
*/ | ||
export type InputIdentifier = string; | ||
/** | ||
* Unique identifier of a node's type. | ||
*/ | ||
export type NodeTypeIdentifier = string; | ||
/** | ||
* Represents a node in a graph. | ||
*/ | ||
export type NodeDescriptor = { | ||
/** | ||
* Unique id of the node in graph. | ||
*/ | ||
id: NodeIdentifier; | ||
/** | ||
* Type of the node. Used to look up the handler for the node. | ||
*/ | ||
type: NodeTypeIdentifier; | ||
/** | ||
* Configuration of the node. | ||
*/ | ||
configuration?: NodeConfiguration; | ||
}; | ||
/** | ||
* Represents an edge in a graph. | ||
*/ | ||
export type Edge = { | ||
/** | ||
* The node that the edge is coming from. | ||
*/ | ||
from: NodeIdentifier; | ||
/** | ||
* The node that the edge is going to. | ||
*/ | ||
to: NodeIdentifier; | ||
/** | ||
* The input of the `to` node. If this value is undefined, then | ||
* the then no data is passed as output of the `from` node. | ||
*/ | ||
in?: InputIdentifier; | ||
/** | ||
* The output of the `from` node. If this value is "*", then all outputs | ||
* of the `from` node are passed to the `to` node. If this value is undefined, | ||
* then no data is passed to any inputs of the `to` node. | ||
*/ | ||
out?: OutputIdentifier; | ||
/** | ||
* If true, this edge is optional: the data that passes through it is not | ||
* considered a required input to the node. | ||
*/ | ||
optional?: boolean; | ||
/** | ||
* If true, this edge acts as a constant: the data that passes through it | ||
* remains available even after the node has consumed it. | ||
*/ | ||
constant?: boolean; | ||
}; | ||
/** | ||
* Represents references to a "kit": a collection of `NodeHandlers`. | ||
* The basic permise here is that people can publish kits with interesting | ||
* handlers, and then graphs can specify which ones they use. | ||
* The `@google-labs/core-kit` package is an example of kit. | ||
*/ | ||
export type KitReference = { | ||
/** | ||
* The URL pointing to the location of the kit. | ||
*/ | ||
url: string; | ||
}; | ||
export type KitDescriptor = KitReference & { | ||
/** | ||
* The title of the kit. | ||
*/ | ||
title?: string; | ||
/** | ||
* The description of the kit. | ||
*/ | ||
description?: string; | ||
/** | ||
* Version of the kit. | ||
* [semver](https://semver.org/) format is encouraged. | ||
*/ | ||
version?: string; | ||
}; | ||
/** | ||
* Represents graph metadata. | ||
*/ | ||
export type GraphMetadata = { | ||
/** | ||
* The schema of the graph. | ||
*/ | ||
$schema?: string; | ||
/** | ||
* The URL pointing to the location of the graph. | ||
* This URL is used to resolve relative paths in the graph. | ||
* If not specified, the paths are assumed to be relative to the current | ||
* working directory. | ||
*/ | ||
url?: string; | ||
/** | ||
* The title of the graph. | ||
*/ | ||
title?: string; | ||
/** | ||
* The description of the graph. | ||
*/ | ||
description?: string; | ||
/** | ||
* Version of the graph. | ||
* [semver](https://semver.org/) format is encouraged. | ||
*/ | ||
version?: string; | ||
}; | ||
/** | ||
* Unique identifier of a graph. | ||
*/ | ||
export type GraphIdentifier = string; | ||
/** | ||
* Represents a collection of sub-graphs. | ||
* The key is the identifier of the sub-graph. | ||
* The value is the descriptor of the sub-graph. | ||
*/ | ||
export type SubGraphs = Record<GraphIdentifier, GraphDescriptor>; | ||
/** | ||
* Represents a graph. | ||
*/ | ||
export type GraphDescriptor = GraphMetadata & { | ||
/** | ||
* The collection of all edges in the graph. | ||
*/ | ||
edges: Edge[]; | ||
/** | ||
* The collection of all nodes in the graph. | ||
*/ | ||
nodes: NodeDescriptor[]; | ||
/** | ||
* All the kits (collections of node handlers) that are used by the graph. | ||
*/ | ||
kits?: KitReference[]; | ||
/** | ||
* Sub-graphs that are also described by this graph representation. | ||
*/ | ||
graphs?: SubGraphs; | ||
/** | ||
* Arguments that are passed to the graph, useful to bind values to lambdas. | ||
*/ | ||
args?: InputValues; | ||
}; | ||
/** | ||
* The Map of queues of all outputs that were sent to a given node, | ||
@@ -236,15 +92,2 @@ * and a map of these for all nodes. | ||
/** | ||
* Values that are supplied as inputs to the `NodeHandler`. | ||
*/ | ||
export type InputValues = Record<InputIdentifier, NodeValue>; | ||
/** | ||
* Values that the `NodeHandler` outputs. | ||
*/ | ||
export type OutputValues = Partial<Record<OutputIdentifier, NodeValue>>; | ||
/** | ||
* Values that are supplied as part of the graph. These values are merged with | ||
* the `InputValues` and supplied as inputs to the `NodeHandler`. | ||
*/ | ||
export type NodeConfiguration = Record<string, NodeValue>; | ||
/** | ||
* A function that represents a type of a node in the graph. | ||
@@ -276,2 +119,15 @@ */ | ||
/** | ||
* Context that is supplied to the `NodeDescriberFunction`. | ||
*/ | ||
export type NodeDescriberContext = { | ||
/** | ||
* The base URL of the graph. | ||
*/ | ||
base?: URL; | ||
/** | ||
* The graph in which the node is described. | ||
*/ | ||
outerGraph: GraphDescriptor; | ||
}; | ||
/** | ||
* Asks to describe a node. Can be called in multiple ways: | ||
@@ -285,3 +141,7 @@ * - when called with no arguments, will produce the "default schema". That is, | ||
*/ | ||
export type NodeDescriberFunction = (inputs?: InputValues, inputSchema?: Schema, outputSchema?: Schema) => Promise<NodeDescriberResult>; | ||
export type NodeDescriberFunction = (inputs?: InputValues, inputSchema?: Schema, outputSchema?: Schema, | ||
/** | ||
* The context in which the node is described. | ||
*/ | ||
context?: NodeDescriberContext) => Promise<NodeDescriberResult>; | ||
export type NodeHandler = { | ||
@@ -575,2 +435,10 @@ invoke: NodeHandlerFunction; | ||
readonly requestInput?: (name: string, schema: Schema, node: NodeDescriptor) => Promise<NodeValue>; | ||
/** | ||
* Provide output directly to the user. This will bypass the normal output | ||
* flow and will not be passed as outputs. | ||
* @param output - The values to provide | ||
* @param schema - The schema to use for the output | ||
* @returns - Promise that resolves when the output is provided | ||
*/ | ||
readonly provideOutput?: (outputs: OutputValues, descriptor: NodeDescriptor) => Promise<void>; | ||
readonly invocationPath?: number[]; | ||
@@ -577,0 +445,0 @@ readonly state?: RunState; |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "A library for rapid generative AI application prototyping", | ||
@@ -36,2 +36,5 @@ "main": "./dist/src/index.js", | ||
"command": "tsc -b", | ||
"dependencies": [ | ||
"../schema:build:tsc" | ||
], | ||
"env": { | ||
@@ -118,2 +121,3 @@ "FORCE_COLOR": "1" | ||
"repository": { | ||
"directory": "packages/breadboard", | ||
"type": "git", | ||
@@ -169,6 +173,4 @@ "url": "git+https://github.com/breadboard-ai/breadboard.git" | ||
"dependencies": { | ||
"@google-labs/breadboard-schema": "^1.2.0", | ||
"zod": "^3.22.4", | ||
"zod-to-json-schema": "^3.22.1" | ||
"@google-labs/breadboard-schema": "^1.3.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
1
294
10652
1535149
- Removedzod@^3.22.4
- Removedzod-to-json-schema@^3.22.1
- Removedzod@3.24.1(transitive)
- Removedzod-to-json-schema@3.24.1(transitive)