@google-labs/breadboard
Advanced tools
Comparing version 0.25.0 to 0.26.0
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
const t="stream";class e{kind=t;stream;constructor(t){this.stream=t}}const r=e=>{const r=[];return{value:JSON.stringify(e,((e,s)=>(e=>{const r=e;return r&&r.kind&&r.kind===t&&r.stream instanceof ReadableStream})(s)?(r.push(s.stream),{$type:"Stream",id:r.length-1}):s)),streams:r}},s=(t,r)=>{const s=JSON.parse(t,((t,s)=>"object"==typeof s&&null!==s&&"Stream"===s.$type&&"number"==typeof s.id?new e(r(s.id)):s));return s},n=t=>{const e=r(t).value;return s(e,(()=>new ReadableStream))},i=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 s=r(e);t.postMessage(e,s.streams)},close(){t.postMessage(null,[])}})});class a{#t;data;constructor(t,e){this.#t=e,this.data=t}async reply(t){await this.#t.write(t)}}class o{#e;#t;constructor(t,e){this.#e=e.getReader(),this.#t=t.getWriter()}async next(){const{done:t,value:e}=await this.#e.read();return t?(this.#t.close(),{done:t,value:void 0}):{done:!1,value:new a(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 c=(t,e)=>({async start(e){const r=t.getWriter();await r.write(e),r.releaseLock()},[Symbol.asyncIterator]:()=>new o(t,e)}),u=()=>{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{#r;#s;constructor(t,e){this.#r=t,this.#s=e}createServerStream(){const t=this.#r,e=this.#s;return u(),e.header("Content-Type","text/event-stream"),{readableRequests:new ReadableStream({start(e){var r;"object"==typeof(r=t.body)&&null!==r&&Symbol.iterator in r?(e.enqueue(t.body),e.close()):e.error(new Error("Unexpected uniterable body. This is likely a result of processing a GET request. Only POST requests are supported."))}}),writableResponses:new WritableStream({async write(t){const s=r(t);if(e.write(`data: ${s.value}\n\n`),s.streams.length){if(s.streams.length>1)throw new Error("HTTPServerTransport does not support multiple streams at the moment.");const t=s.streams[0];await t.pipeTo(new WritableStream({write(t){const r=["http-stream-chunk",{chunk:t}];e.write(`data: ${JSON.stringify(r)}\n\n`)},close(){e.write(`data: ${JSON.stringify(["http-stream-end",{}])}\n\n`)}}))}},close(){e.end()}})}}}class h{#n;#i;#a;constructor(t,e){this.#n=t,this.#i={...e,method:"POST",headers:{"Content-Type":"application/json"}},this.#a=this.#i.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,n){if(!t)throw new Error("HTTPClientTransport supports only one write per stream instance.");const i=await r.#a(r.#n,{...r.#i,body:JSON.stringify(e)});i.ok||n.error(new Error(`HTTP error: ${i.status}`)),t(i.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 i=n.shift();i&&(s?t.push(i):r.enqueue(i))},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,n){const i=s(r,(e=>{if(0!==e)throw new Error("HTTPClientTransport does not support multiple streams at the moment.");return t.readable})),[a]=Array.isArray(i)?i:[];"http-stream-chunk"===a?e.write(i[1].chunk):"http-stream-end"===a?e.close():n.enqueue(i)}})})())),t=void 0}})}}} | ||
const t="stream";class e{kind=t;stream;constructor(t){this.stream=t}}const r=e=>{const r=[];return{value:JSON.stringify(e,((e,s)=>(e=>{const r=e;return r&&r.kind&&r.kind===t&&r.stream instanceof ReadableStream})(s)?(r.push(s.stream),{$type:"Stream",id:r.length-1}):s)),streams:r}},s=(t,r)=>{const s=JSON.parse(t,((t,s)=>"object"==typeof s&&null!==s&&"Stream"===s.$type&&"number"==typeof s.id?new e(r(s.id)):s));return s},n=t=>{const e=r(t).value;return s(e,(()=>new ReadableStream))},i=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 s=r(e);t.postMessage(e,s.streams)},close(){t.postMessage(null,[])}})});class o{#t;data;constructor(t,e){this.#t=e,this.data=t}async reply(t){await this.#t.write(t)}}class a{#e;#t;constructor(t,e){this.#e=e.getReader(),this.#t=t.getWriter()}async next(){const{done:t,value:e}=await this.#e.read();return t?(this.#t.close(),{done:t,value:void 0}):{done:!1,value:new o(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 c=(t,e)=>({async start(e){const r=t.getWriter();await r.write(e),r.releaseLock()},[Symbol.asyncIterator]:()=>new a(t,e)}),u=()=>{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{#r;#s;constructor(t,e){this.#r=t,this.#s=e}createServerStream(){const t=this.#r,e=this.#s;return u(),e.header("Content-Type","text/event-stream"),{readableRequests:new ReadableStream({start(e){var r;"object"==typeof(r=t.body)&&null!==r&&Symbol.iterator in r?(e.enqueue(t.body),e.close()):e.error(new Error("Unexpected uniterable body. This is likely a result of processing a GET request. Only POST requests are supported."))}}),writableResponses:new WritableStream({async write(t){const s=r(t);if(e.write(`data: ${s.value}\n\n`),s.streams.length){if(s.streams.length>1)throw new Error("HTTPServerTransport does not support multiple streams at the moment.");const t=s.streams[0];await t.pipeTo(new WritableStream({write(t){const r=["http-stream-chunk",{chunk:t}];e.write(`data: ${JSON.stringify(r)}\n\n`)},close(){e.write(`data: ${JSON.stringify(["http-stream-end",{}])}\n\n`)}}))}},close(){e.end()}})}}}class h{#n;#i;#o;constructor(t,e){this.#n=t,this.#i={...e,method:"POST",headers:{"Content-Type":"application/json"}},this.#o=this.#i.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,n){if(!t)throw new Error("HTTPClientTransport supports only one write per stream instance.");const i=await r.#o(r.#n,{...r.#i,body:JSON.stringify(e)});i.ok||n.error(new Error(`HTTP error: ${i.status}`)),t(i.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 i=n.shift();i&&(s?t.push(i):r.enqueue(i))},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,n){const i=s(r,(e=>{if(0!==e)throw new Error("HTTPClientTransport does not support multiple streams at the moment.");return t.readable})),[o]=Array.isArray(i)?i:[];"http-stream-chunk"===o?e.write(i[1].chunk):"http-stream-end"===o?e.close():n.enqueue(i)}})})())),t=void 0}})}}} | ||
/** | ||
@@ -12,3 +12,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const l="port-dispatcher-sendport";class d{#o;#c=new Map;#u=new Map;constructor(t){this.#o=t,this.#o.addEventListener("message",(t=>{const{type:e,id:r,port:s}=t.data;if(e!==l)return;const n=this.#c.get(r);n?(n(s),this.#c.delete(r)):this.#u.set(r,s)}))}receive(t){const e=this.#u.get(t);return e?(this.#u.delete(t),i(e)):(t=>{let e;const r=new Promise((r=>{t().then((t=>{e=i(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.#c.set(t,e)}))))}send(t){const{port1:e,port2:r}=new MessageChannel;return this.#o.postMessage({type:l,id:t,port:r},[r]),i(e)}}class f{#e;#t;constructor(t){this.#e=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.#e,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 w{#p;constructor(t){this.#p=t}createServerStream(){return{readableRequests:this.#p.readable,writableResponses:this.#p.writable}}} | ||
*/const l="port-dispatcher-sendport";class d{#a;#c=new Map;#u=new Map;constructor(t){this.#a=t,this.#a.addEventListener("message",(t=>{const{type:e,id:r,port:s}=t.data;if(e!==l)return;const n=this.#c.get(r);n?(n(s),this.#c.delete(r)):this.#u.set(r,s)}))}receive(t){const e=this.#u.get(t);return e?(this.#u.delete(t),i(e)):(t=>{let e;const r=new Promise((r=>{t().then((t=>{e=i(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.#c.set(t,e)}))))}send(t){const{port1:e,port2:r}=new MessageChannel;return this.#a.postMessage({type:l,id:t,port:r},[r]),i(e)}}class f{#e;#t;constructor(t){this.#e=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.#e,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 w{#p;constructor(t){this.#p=t}createServerStream(){return{readableRequests:this.#p.readable,writableResponses:this.#p.writable}}} | ||
/** | ||
@@ -29,3 +29,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class b{url;title;description;version;namespacePrefix;tags;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n="",tags:i=[]}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n,this.tags=i}#h(t){return Object.keys(t).reduce(((e,r)=>(e[`${this.namespacePrefix}${r}`]=t[r],e)),{})}build(t){if(!this.url)throw new Error("Builder was not yet initialized.");const e=this.url,r=this.namespacePrefix,{title:s,description:n,version:i,tags:a}=this,o=this.#h(t),c=Object.keys(t);return class{title=s;description=n;version=i;url=e;tags=a;get handlers(){return o}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n||"tags"===n?s[n]:c.includes(n)?(s={})=>{const i=t.getConfigWithLambda(s),{$id:a,...o}=i;return t.create(e,`${r}${n}`,{...o},a)}:void 0});return e}}}static wrap(t,e){const r=Object.entries(e).reduce(((t,e)=>{const[r,s]=e;return t[r]={invoke:async t=>{let e=[];s&&s.length>0&&(e=s.toString().match(/\((.+?)\)/)?.[1].split(",")??[],s.length>1&&0===e.length&&"___args"in t&&Array.isArray(t.___args)&&(e=["___args"]));for(const r of e)if(r.trim()in t==!1)throw new Error(`Missing input: ${r.trim()}. Valid inputs are: ${Object.keys(t).join(", ")}`);const r=e.filter((t=>0==t.startsWith("___"))).map((e=>t[e.trim()])),n=e[e.length-1];null!=n&&n.startsWith("___")&&r.push(...t[n]);const i=await s(...r);return"object"!=typeof i||Array.isArray(i)?{result:i}:{...i}}},t}),{});return new b(t).build(r)}} | ||
*/class b{url;title;description;version;namespacePrefix;tags;constructor({title:t,description:e,version:r,url:s,namespacePrefix:n="",tags:i=[]}){this.url=s,this.title=t,this.description=e,this.version=r,this.namespacePrefix=n,this.tags=i}#h(t){return Object.keys(t).reduce(((e,r)=>(e[`${this.namespacePrefix}${r}`]=t[r],e)),{})}build(t){if(!this.url)throw new Error("Builder was not yet initialized.");const e=this.url,r=this.namespacePrefix,{title:s,description:n,version:i,tags:o}=this,a=this.#h(t),c=Object.keys(t);return class{title=s;description=n;version=i;url=e;tags=o;get handlers(){return a}constructor(t){const e=new Proxy(this,{get:(s,n)=>"handlers"===n||"url"===n||"title"===n||"tags"===n?s[n]:c.includes(n)?(s={})=>{const i=t.getConfigWithLambda(s),{$id:o,...a}=i;return t.create(e,`${r}${n}`,{...a},o)}:void 0});return e}}}static wrap(t,e){const r=Object.entries(e).reduce(((t,e)=>{const[r,s]=e;return t[r]={invoke:async t=>{let e=[];s&&s.length>0&&(e=s.toString().match(/\((.+?)\)/)?.[1].split(",")??[],s.length>1&&0===e.length&&"___args"in t&&Array.isArray(t.___args)&&(e=["___args"]));for(const r of e)if(r.trim()in t==!1)throw new Error(`Missing input: ${r.trim()}. Valid inputs are: ${Object.keys(t).join(", ")}`);const r=e.filter((t=>0==t.startsWith("___"))).map((e=>t[e.trim()])),n=e[e.length-1];null!=n&&n.startsWith("___")&&r.push(...t[n]);const i=await s(...r);return"object"!=typeof i||Array.isArray(i)?{result:i}:{...i}}},t}),{});return new b(t).build(r)}} | ||
/** | ||
@@ -35,3 +35,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const v=globalThis.process?t=>Buffer.from(t,"base64").toString("binary"):globalThis.atob,S=globalThis.process?t=>Buffer.from(t,"binary").toString("base64"):globalThis.btoa;class k{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 E=(t,e)=>Object.fromEntries(Object.entries(e).map((([e,r])=>"string"==typeof r?[e,[new k(e,t,r)]]:Array.isArray(r)?[e,r.map((r=>"string"==typeof r?new k(e,t,r):new k(e,t,r.to,r.when)))]:[e,[new k(e,t,r.to,r.when)]]))),O=Math.round(Date.now()/6048e5).toString(36),x=`T-${O}-`,$=`-${O}-T`,P=new RegExp(`(${x}.*?${$})`,"gm"),I=new RegExp(`^${x}(.+?)${$}$`),R=async(t,e,r)=>{const s=JSON.stringify(t),n=s.split(P).filter(Boolean).map((t=>{const e=t.match(I);if(e){const t=e[1].split("~"),[r,s,n]=t;return{nodeType:r,outputName:s,inputs:v(n)}}return{value:t}}));const i=await Promise.all(n.map((async t=>{if("inputs"in t){const s=JSON.parse(t.inputs),{nodeType:n,outputName:i}=t,a=e?await r(n,s):{[i]:"VALUE_BLOCKED"};if(!a)return"";let o=JSON.stringify(a[i]);return o.startsWith('"')&&(o=o.slice(1,-1)),o=JSON.stringify(o),o.slice(1,-1)}return t.value})));return JSON.parse(i.join(""))},N=(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 y(r,t,n),s,(r=>((t,e,r)=>{const s=S(JSON.stringify(r)).replace("=","");return`${x}${t}~${e}~${s}${$}`})(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)=>y(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)=>R(t,r,(async(t,r)=>y(e[t],r,s))))),s)]:[t,r]})));return{url:"tunnel-kit",handlers:n}},j=()=>globalThis.performance.now() | ||
*/const v=globalThis.process?t=>Buffer.from(t,"base64").toString("binary"):globalThis.atob,S=globalThis.process?t=>Buffer.from(t,"binary").toString("base64"):globalThis.btoa;class k{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 E=(t,e)=>Object.fromEntries(Object.entries(e).map((([e,r])=>"string"==typeof r?[e,[new k(e,t,r)]]:Array.isArray(r)?[e,r.map((r=>"string"==typeof r?new k(e,t,r):new k(e,t,r.to,r.when)))]:[e,[new k(e,t,r.to,r.when)]]))),O=Math.round(Date.now()/6048e5).toString(36),x=`T-${O}-`,$=`-${O}-T`,P=new RegExp(`(${x}.*?${$})`,"gm"),I=new RegExp(`^${x}(.+?)${$}$`),N=async(t,e,r)=>{const s=JSON.stringify(t),n=s.split(P).filter(Boolean).map((t=>{const e=t.match(I);if(e){const t=e[1].split("~"),[r,s,n]=t;return{nodeType:r,outputName:s,inputs:v(n)}}return{value:t}}));const i=await Promise.all(n.map((async t=>{if("inputs"in t){const s=JSON.parse(t.inputs),{nodeType:n,outputName:i}=t,o=e?await r(n,s):{[i]:"VALUE_BLOCKED"};if(!o)return"";let a=JSON.stringify(o[i]);return a.startsWith('"')&&(a=a.slice(1,-1)),a=JSON.stringify(a),a.slice(1,-1)}return t.value})));return JSON.parse(i.join(""))},R=(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 y(r,t,n),s,(r=>((t,e,r)=>{const s=S(JSON.stringify(r)).replace("=","");return`${x}${t}~${e}~${s}${$}`})(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)=>y(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)=>N(t,r,(async(t,r)=>y(e[t],r,s))))),s)]:[t,r]})));return{url:"tunnel-kit",handlers:n}},j=()=>globalThis.performance.now() | ||
/** | ||
@@ -46,3 +46,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const D=async(t,e)=>{const r=async e=>{if(A(e)){const r=await t.retrieveAsBlob(e);return{inlineData:{data:await M(r),mimeType:r.type}}}if(Array.isArray(e)){const t=[];for(const s of e)t.push(await r(s));return t}if("object"==typeof e&&null!==e){const t=e,s={};for(const n in e)s[n]=await r(t[n]);return s}return e};return await r(e)},F=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r}; | ||
*/const D=async(t,e)=>{const r=async e=>{if(A(e)){const r=await t.retrieveAsBlob(e);return{inlineData:{data:await M(r),mimeType:r.type}}}if(Array.isArray(e)){const t=[];for(const s of e)t.push(await r(s));return t}if("object"==typeof e&&null!==e){const t=e,s={};for(const n in e)s[n]=await r(t[n]);return s}return e};return await r(e)},F=(t,e=[])=>{const r=e.find((e=>"string"==typeof e?e===t:e.node===t));return"string"==typeof r?{node:r}:r},L=t=>{if(t.$error){const e=t.$error;e.error=e.error instanceof Error?e.error.message:e.error}return t}; | ||
/** | ||
@@ -52,3 +52,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class L{#l;constructor(t){this.#l=t}async serve(t){const{kits:e,store:r}=t,s=this.#l.createServerStream(),n=N((t=>t.proxy?Object.fromEntries(t.proxy.map((t=>{if("string"!=typeof t&&t.tunnel)return[t.node,E(t.node,t.tunnel)]})).filter(Boolean)):{})(t),m(e)),i=n.handlers;for await(const e of c(s.writableResponses,s.readableRequests)){const[s]=e.data;if("end"===s)break;if("proxy"!==s){e.reply(["error",{error:"Expected proxy request.",timestamp:j()}]);continue}const[,{node:n,inputs:a}]=e.data,o=F(n.type,t.proxy)?i[n.type]:void 0;if(o)try{const t=await y(o,a,{descriptor:n,store:r});if(!t){e.reply(["error",{error:"Handler returned nothing.",timestamp:j()}]);continue}const s=r?await D(r,t):t;e.reply(["proxy",{outputs:s}])}catch(t){e.reply(["error",{error:t.message,timestamp:j()}])}else e.reply(["error",{error:"Can't proxy a node of this node type.",timestamp:j()}])}}}class W{#l;constructor(t){this.#l=t}shutdownServer(){const t=this.#l.createClientStream().writableRequests.getWriter();t.write(["end",{timestamp:j()}]),t.close()}async proxy(t,e,r){const s=this.#l.createClientStream(),n=s.writableRequests.getWriter(),i=s.readableResponses.getReader();n.write(["proxy",{node:t,inputs:e}]),n.close();const a=await i.read();if(a.done)throw new Error("Unexpected proxy failure: empty response.");const[o]=a.value;if("proxy"===o){const[,{outputs:t}]=a.value;return t}if("error"===o){const[,{error:t}]=a.value;throw new Error(JSON.stringify(t))}throw new Error(`Unexpected proxy failure: unknown response type "${o}".`)}createProxyKit(t=[]){const e=t.map((t=>"string"==typeof t?t:t.node)),r=Object.fromEntries(e.map((t=>[t,{invoke:async(t,e)=>{const r=e.descriptor;return await this.proxy(r,t,e)}}])));return g(new b({url:"proxy"}).build(r))}} | ||
*/class W{#l;constructor(t){this.#l=t}async serve(t){const{kits:e,store:r}=t,s=this.#l.createServerStream(),n=R((t=>t.proxy?Object.fromEntries(t.proxy.map((t=>{if("string"!=typeof t&&t.tunnel)return[t.node,E(t.node,t.tunnel)]})).filter(Boolean)):{})(t),m(e)),i=n.handlers;for await(const e of c(s.writableResponses,s.readableRequests)){const[s]=e.data;if("end"===s)break;if("proxy"!==s){e.reply(["error",{error:"Expected proxy request.",timestamp:j()}]);continue}const[,{node:n,inputs:o}]=e.data,a=F(n.type,t.proxy)?i[n.type]:void 0;if(a)try{const t=await y(a,o,{descriptor:n,store:r});if(!t){e.reply(["error",{error:"Handler returned nothing.",timestamp:j()}]);continue}const s=r?await D(r,L(t)):t;e.reply(["proxy",{outputs:s}])}catch(t){e.reply(["error",{error:t.message,timestamp:j()}])}else e.reply(["error",{error:"Can't proxy a node of this node type.",timestamp:j()}])}}}class G{#l;constructor(t){this.#l=t}shutdownServer(){const t=this.#l.createClientStream().writableRequests.getWriter();t.write(["end",{timestamp:j()}]),t.close()}async proxy(t,e,r){const s=this.#l.createClientStream(),n=s.writableRequests.getWriter(),i=s.readableResponses.getReader(),o=r.store;e=o?await D(o,e):e,n.write(["proxy",{node:t,inputs:e}]),n.close();const a=await i.read();if(a.done)throw new Error("Unexpected proxy failure: empty response.");const[c]=a.value;if("proxy"===c){const[,{outputs:t}]=a.value;return t}if("error"===c){const[,{error:t}]=a.value;throw new Error(JSON.stringify(t))}throw new Error(`Unexpected proxy failure: unknown response type "${c}".`)}createProxyKit(t=[]){const e=t.map((t=>"string"==typeof t?t:t.node)),r=Object.fromEntries(e.map((t=>[t,{invoke:async(t,e)=>{const r=e.descriptor;return await this.proxy(r,t,e)}}])));return g(new b({url:"proxy"}).build(r))}} | ||
/** | ||
@@ -58,3 +58,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class G{#d;constructor(t){this.#d=t}async report(t){return this.#d(t)}} | ||
*/class B{#d;constructor(t){this.#d=t}async report(t){return this.#d(t)}} | ||
/** | ||
@@ -64,3 +64,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const B=t=>{const e=t;let r;if(e?.cause){const{cause:t}=e;r=t}else r={error:e};return r},H=t=>{if("string"==typeof t)return t;if(t instanceof Error)return t.message;if("message"in t)return t.message;const e=t.error;return"string"==typeof e?e:e instanceof Error?e.message:JSON.stringify(e)}; | ||
*/const H=t=>{const e=t;let r;if(e?.cause){const{cause:t}=e;r=t}else r={error:e};return r},z=t=>{if("string"==typeof t)return t;if(t instanceof Error)return t.message;if("message"in t)return t.message;const e=t.error;return"string"==typeof e?e:e instanceof Error?e.message:JSON.stringify(e)}; | ||
/** | ||
@@ -71,3 +71,3 @@ * @license | ||
*/ | ||
class z{state=new Map;constants=new Map;#f(t,e,r,s){let n=t.get(e);n||(n=new Map,t.set(e,n));let i=n.get(r);i||(i=[],n.set(r,i)),i.push(s)}wireOutputs(t,e){if(0!==t.filter((e=>e.from!=t[0].from)).length)throw new Error("All opportunities must be from the same node");t.forEach((t=>{const r=t.to,s=t.out,n=t.constant?this.constants:this.state;if(s)if("*"===s)for(const t in e){const s=e[t];null!=s&&null!=s&&this.#f(n,r,t,s)}else if(t.in){const i=e[s];null!=i&&null!=i&&this.#f(n,r,t.in,i)}}))}getAvailableInputs(t){const e={};for(const r of[this.constants.get(t),this.state.get(t)])if(r)for(const[t,s]of r.entries())0!==s.length&&(e[t]=s[0]);return e}useInputs(t,e){const r=this.state.get(t);if(r)for(const t in e){const e=r.get(t);e&&e.shift()}}} | ||
class J{state=new Map;constants=new Map;#f(t,e,r,s){let n=t.get(e);n||(n=new Map,t.set(e,n));let i=n.get(r);i||(i=[],n.set(r,i)),i.push(s)}wireOutputs(t,e){if(0!==t.filter((e=>e.from!=t[0].from)).length)throw new Error("All opportunities must be from the same node");t.forEach((t=>{const r=t.to,s=t.out,n=t.constant?this.constants:this.state;if(s)if("*"===s)for(const t in e){const s=e[t];null!=s&&null!=s&&this.#f(n,r,t,s)}else if(t.in){const i=e[s];null!=i&&null!=i&&this.#f(n,r,t.in,i)}}))}getAvailableInputs(t){const e={};for(const r of[this.constants.get(t),this.state.get(t)])if(r)for(const[t,s]of r.entries())0!==s.length&&(e[t]=s[0]);return e}useInputs(t,e){const r=this.state.get(t);if(r)for(const t in e){const e=r.get(t);e&&e.shift()}}} | ||
/** | ||
@@ -77,3 +77,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class J{descriptor;inputs;missingInputs;current;opportunities;newOpportunities;state;outputs;partialOutputs;constructor(t,e,r,s,n,i,a,o){this.descriptor=t,this.inputs=e,this.missingInputs=r,this.current=s,this.opportunities=n,this.newOpportunities=i,this.state=a,this.partialOutputs=o}get skip(){return this.missingInputs.length>0}static fromObject(t){const e=new z;return e.constants=t.state.constants,e.state=t.state.state,new J(t.descriptor,t.inputs,t.missingInputs,t.current,t.opportunities,t.newOpportunities,e,t.partialOutputs)}} | ||
*/class _{descriptor;inputs;missingInputs;current;opportunities;newOpportunities;state;outputs;partialOutputs;constructor(t,e,r,s,n,i,o,a){this.descriptor=t,this.inputs=e,this.missingInputs=r,this.current=s,this.opportunities=n,this.newOpportunities=i,this.state=o,this.partialOutputs=a}get skip(){return this.missingInputs.length>0}static fromObject(t){const e=new J;return e.constants=t.state.constants,e.state=t.state.state,new _(t.descriptor,t.inputs,t.missingInputs,t.current,t.opportunities,t.newOpportunities,e,t.partialOutputs)}} | ||
/** | ||
@@ -83,3 +83,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const _=(t,e)=>e instanceof Map?{$type:"Map",value:Array.from(e.entries())}:e,K=(t,e)=>{const{$type:r}=e||{};return"Map"==r&&e.value?new Map(e.value):e},Q=(t,e)=>{const r=e;return JSON.stringify({state:r,type:t},_)},V=t=>{const{state:e,type:r}=JSON.parse(t,K);return{state:J.fromObject(e),type:r}};class X{root;constructor(t={children:[],data:null}){this.root=t}#w(t,e,r,s){const[n,...i]=s;if(void 0===n)return null;let a=t.children[n];if(!a){if(0!==i.length&&console.warn("Path registry entry not found for",s,"in",r),e)return console.warn("Path registry is read-only. Not adding",r),null;a=t.children[n]={children:[],data:null}}return 0===i.length?a:this.#w(a,e,r,i)}find(t){return this.#w(this.root,!0,t,t)}create(t){return this.#w(this.root,!1,t,t)}} | ||
*/const K=(t,e)=>e instanceof Map?{$type:"Map",value:Array.from(e.entries())}:e,Q=(t,e)=>{const{$type:r}=e||{};return"Map"==r&&e.value?new Map(e.value):e},V=(t,e)=>{const r=e;return JSON.stringify({state:r,type:t},K)},X=t=>{const{state:e,type:r}=JSON.parse(t,Q);return{state:_.fromObject(e),type:r}};class Y{root;constructor(t={children:[],data:null}){this.root=t}#w(t,e,r,s){const[n,...i]=s;if(void 0===n)return null;let o=t.children[n];if(!o){if(0!==i.length&&console.warn("Path registry entry not found for",s,"in",r),e)return console.warn("Path registry is read-only. Not adding",r),null;o=t.children[n]={children:[],data:null}}return 0===i.length?o:this.#w(o,e,r,i)}find(t){return this.#w(this.root,!0,t,t)}create(t){return this.#w(this.root,!1,t,t)}} | ||
/** | ||
@@ -89,3 +89,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Y{#y=new Map;constructor(t=[]){this.#y=new Map(t)}visit(t,e){this.#y.set(t,e)}pathFor(t){return this.#y.get(t)}visited(){return Array.from(this.#y.entries())}} | ||
*/class Z{#y=new Map;constructor(t=[]){this.#y=new Map(t)}visit(t,e){this.#y.set(t,e)}pathFor(t){return this.#y.get(t)}visited(){return Array.from(this.#y.entries())}} | ||
/** | ||
@@ -95,3 +95,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Z{#m;#g;#b;constructor(t){this.#m=[],this.#g=new X,this.#b=new Y(t)}async supplyPartialOutputs(t,e){const r=this.#g.find(e)?.data;if(!r)return void console.warn(`No state found for path ${e}, partialOutputs will be dropped`);const s=V(r.state).state;s.partialOutputs=t,r.state=Q("nodestart",s)}dispatchGraphStart(t,e){const r=this.#g.create(e);r&&(r.data={...r.data,url:t,path:e}),this.#m.push({url:t,path:e})}dispatchSkip(){}dispatchEdge(t){}async dispatchNodeStart(t,e){if(this.#b.visit(t.descriptor.id,e),0===this.#m.length)return;const r=this.#g.create(e),s=Q("nodestart",t),n=this.#m[this.#m.length-1];n&&(n.state=s,n.path=e),r.data={url:void 0,state:s,path:e}}dispatchNodeEnd(t,e){const r=this.#g.find(e);r?.data&&(r.data.outputs=t)}dispatchGraphEnd(){}pathFor(t){return this.#b.pathFor(t)}state(){return this.#m}reanimationState(){return function(t,e){function r(t){return t.join("-")}const s={};return function t(e,s,n){for(const[i,a]of e.children.entries()){if(!a)continue;const e=[...s,i];a.data&&(n[r(s)]=a.data),t(a,e,n)}}(t,[],s),{states:s,visits:e.visited()}}(this.#g.root,this.#b)}} | ||
*/class tt{#m;#g;#b;constructor(t){this.#m=[],this.#g=new Y,this.#b=new Z(t)}async supplyPartialOutputs(t,e){const r=this.#g.find(e)?.data;if(!r)return void console.warn(`No state found for path ${e}, partialOutputs will be dropped`);const s=X(r.state).state;s.partialOutputs=t,r.state=V("nodestart",s)}dispatchGraphStart(t,e){const r=this.#g.create(e);r&&(r.data={...r.data,url:t,path:e}),this.#m.push({url:t,path:e})}dispatchSkip(){}dispatchEdge(t){}async dispatchNodeStart(t,e){if(this.#b.visit(t.descriptor.id,e),0===this.#m.length)return;const r=this.#g.create(e),s=V("nodestart",t),n=this.#m[this.#m.length-1];n&&(n.state=s,n.path=e),r.data={url:void 0,state:s,path:e}}dispatchNodeEnd(t,e){const r=this.#g.find(e);r?.data&&(r.data.outputs=t)}dispatchGraphEnd(){}pathFor(t){return this.#b.pathFor(t)}state(){return this.#m}reanimationState(){return function(t,e){function r(t){return t.join("-")}const s={};return function t(e,s,n){for(const[i,o]of e.children.entries()){if(!o)continue;const e=[...s,i];o.data&&(n[r(s)]=o.data),t(o,e,n)}}(t,[],s),{states:s,visits:e.visited()}}(this.#g.root,this.#b)}} | ||
/** | ||
@@ -101,3 +101,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class tt{#v;#S;constructor(t,e){this.#v=t,this.#S=e}enter(t){const e=t.join("-"),r=this.#v.states,s=r?.[e];if(!s)return new et(void 0);if(!s||!s.state)throw new Error("Cannot reanimate without a state");const n=V(s.state).state;n.outputs={...this.#S,...n.partialOutputs},this.#S=void 0;const i=s.outputs?[s.outputs]:[];return new et({result:n,invocationPath:s.path,replayOutputs:i})}}class et{#k;constructor(t){this.#k=t}mode(){return this.#k?this.#k.replayOutputs.length>0?"replay":"resume":"none"}replay(){if(!this.#k)throw new Error("Cannot replay without a frame");if(0===this.#k.replayOutputs.length)throw new Error("Cannot replay without replayOutputs");const t=this.#k.result;t.inputs=this.#k.replayOutputs.shift();const e=this.#k.invocationPath;return{result:t,invocationId:e[e.length-1],path:e}}resume(){if(!this.#k)throw new Error("Cannot resume without a frame");return{invocationPath:this.#k.invocationPath,result:this.#k.result}}} | ||
*/class et{#v;#S;constructor(t,e){this.#v=t,this.#S=e}enter(t){const e=t.join("-"),r=this.#v.states,s=r?.[e];if(!s)return new rt(void 0);if(!s||!s.state)throw new Error("Cannot reanimate without a state");const n=X(s.state).state;n.outputs={...this.#S,...n.partialOutputs},this.#S=void 0;const i=s.outputs?[s.outputs]:[];return new rt({result:n,invocationPath:s.path,replayOutputs:i})}}class rt{#k;constructor(t){this.#k=t}mode(){return this.#k?this.#k.replayOutputs.length>0?"replay":"resume":"none"}replay(){if(!this.#k)throw new Error("Cannot replay without a frame");if(0===this.#k.replayOutputs.length)throw new Error("Cannot replay without replayOutputs");const t=this.#k.result;t.inputs=this.#k.replayOutputs.shift();const e=this.#k.invocationPath;return{result:t,invocationId:e[e.length-1],path:e}}resume(){if(!this.#k)throw new Error("Cannot resume without a frame");return{invocationPath:this.#k.invocationPath,result:this.#k.result}}} | ||
/** | ||
@@ -107,3 +107,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class rt{#E;#S;#v;constructor(t,e){this.#v=t,this.#E=new Z(t?.visits),this.#S=e}lifecycle(){return this.#E}reanimation(){return new tt(this.#v,this.#S)}} | ||
*/class st{#E;#S;#v;constructor(t,e){this.#v=t,this.#E=new tt(t?.visits),this.#S=e}lifecycle(){return this.#E}reanimation(){return new et(this.#v,this.#S)}} | ||
/** | ||
@@ -113,3 +113,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const st=(t={},e)=>new rt(t,e); | ||
*/const nt=(t={},e)=>new st(t,e); | ||
/** | ||
@@ -119,3 +119,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class nt{#O;#x;#$;#P;#I;constructor(t,e,r,s,n){this.#x=t,this.#O=e,this.#$=r,this.#P=s,this.#I=n}get invocationId(){return this.#P}get path(){return this.#I}get type(){return this.#O}get node(){return this.#x.descriptor}get inputArguments(){return this.#x.inputs}set inputs(t){this.#x.outputs={...t,...this.#x.partialOutputs}}get outputs(){const{schema:t,...e}=this.#x.inputs;return e}get state(){return this.#x}save(){return Q(this.#O,this.#x)}get runState(){return this.#$}get timestamp(){return j()}isAtExitNode(){return 0===this.#x.newOpportunities.length&&0===this.#x.opportunities.length}static load(t){const{state:e,type:r}=V(t);return new nt(e,r,void 0,0,[])}}class it extends nt{constructor(t,e,r,s){super(t,"input",e,r,s)}get outputs(){throw new Error('Outputs are not available in the "input" stage')}}class at extends nt{constructor(t,e,r){super(t,"output",void 0,e,r)}get inputArguments(){throw new Error('Input arguments are not available in the "output" stage')}set inputs(t){throw new Error('Setting inputs is not available in the "output" stage')}} | ||
*/class it{#O;#x;#$;#P;#I;constructor(t,e,r,s,n){this.#x=t,this.#O=e,this.#$=r,this.#P=s,this.#I=n}get invocationId(){return this.#P}get path(){return this.#I}get type(){return this.#O}get node(){return this.#x.descriptor}get inputArguments(){return this.#x.inputs}set inputs(t){this.#x.outputs={...t,...this.#x.partialOutputs}}get outputs(){const{schema:t,...e}=this.#x.inputs;return e}get state(){return this.#x}save(){return V(this.#O,this.#x)}get runState(){return this.#$}get timestamp(){return j()}isAtExitNode(){return 0===this.#x.newOpportunities.length&&0===this.#x.opportunities.length}static load(t){const{state:e,type:r}=X(t);return new it(e,r,void 0,0,[])}}class ot extends it{constructor(t,e,r,s){super(t,"input",e,r,s)}get outputs(){throw new Error('Outputs are not available in the "input" stage')}}class at extends it{constructor(t,e,r){super(t,"output",void 0,e,r)}get inputArguments(){throw new Error('Input arguments are not available in the "output" stage')}set inputs(t){throw new Error('Setting inputs is not available in the "output" stage')}} | ||
/** | ||
@@ -125,3 +125,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const ot=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},ct=async(t,e,r,s,n,i=[])=>{if(!e.requestInput)return;const a=s.outputs??{},o=new pt(a,s.inputs,n);if(await(e.state?.lifecycle().supplyPartialOutputs(a,n)),i.length>0){const t=i[i.length-1];if(t.state){const e=V(t.state).state;e.partialOutputs=a,t.state=Q("nodestart",e)}}s.outputs=await o.read(ut(t,e,r,i))},ut=(t,e,r,s)=>async(n,i,a,o)=>{if(a)throw new Error(ot(n,t,a));if(void 0!==i.default)return"type"in i&&"string"!==i.type?JSON.parse(i.default):i.default;const c=await(e.requestInput?.(n,i,r,o,s));if(e?.signal?.aborted)throw e.signal.throwIfAborted();if(void 0===c)throw new Error(ot(n,t,a));return c};class pt{#R;#S;#I;constructor(t,e,r){this.#R=t,this.#S=e,this.#I=r}async read(t){if(!("schema"in this.#S))return this.#R;const e=this.#S.schema;if(!e.properties)return this.#R;const r=Object.entries(e.properties),s={};for(const[n,i]of r){if(n in this.#R){s[n]=this.#R[n];continue}const r=e.required?.includes(n)??!1,a=await t(n,i,r,this.#I);s[n]=a}return{...this.#R,...s}}}class ht{#N;#j=new Map;constructor(t){const{inputs:e,...r}=t;this.#N=r,this.#j=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,i,a)=>{const o=this.#j.get(r);if(void 0!==o)return o;const c={id:n.id,type:n.type},u={...e,descriptor:c,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new it(u,a,-1,i));const p=u.outputs;let h=p&&p[r];return void 0===h&&(h=await(this.#N.requestInput?.(r,s,c,i,a))),lt(s)||this.#j.set(r,h),h}}}const lt=t=>t.behavior?.includes("transient")??!1,dt=async(t,e,r,s)=>{if(!r.provideOutput)return!1;const n=e.configuration?.schema,i=n?.behavior?.includes("bubble");return!!i&&(await r.provideOutput(t,e,s),!0)},ft=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const i={...e,descriptor:s,inputs:r};await t(new at(i,-1,n))};class wt{name="DefaultGraphProvider";#q=Promise.resolve();ready(){return this.#q}isSupported(){return!0}extendedCapabilities(){return{modify:!1,connect:!1,disconnect:!1,refresh:!1,watch:!1,preview:!1}}canProvide(t){return("http:"===t.protocol||"https:"===t.protocol||"file:"===t.protocol&&""===t.hostname)&&{load:!0,save:!1,delete:!1}}async load(t){if("file:"===t.protocol){return(async t=>{if(void 0===globalThis.process)throw new Error("Unable to use `path` when not running in node");let e;if("function"==typeof require){const{readFile:t}=require("node:fs/promises");e=t}else{const{readFile:t}=await import("node:fs/promises");e=t}return JSON.parse(await e(t,"utf-8"))})(decodeURIComponent(t.pathname))}return"http:"===t.protocol||"https:"===t.protocol?(async t=>{let e;try{e=await fetch(t)}catch(r){e=await fetch(t,{credentials:"include"})}return await(e?.json())})(t.href):null}async save(t,e){throw new Error("Save not implemented for DefaultGraphProvider")}async delete(t){throw new Error("Delete not implemented for DefaultGraphProvider")}async connect(t){throw new Error("Connect not implemented for DefaultGraphProvider")}async disconnect(t){throw new Error("Disconnect not implemented for DefaultGraphProvider")}async refresh(t){throw new Error("Refresh not implemented for DefaultGraphProvider")}async createBlank(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async preview(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async create(t,e){throw new Error("Create not implemented for DefaultGraphProvider")}async createURL(t,e){throw new Error("createURL not implemented for DefaultGraphProvider")}parseURL(t){throw new Error("parseURL not implemented for DefaultGraphProvider")}async restore(){throw new Error("restore is not implemented for DefaultGraphProvider")}items(){throw new Error("items is not implemented for DefaultGraphProvider")}startingURL(){return null}watch(){throw new Error("watch is not implemented for DefaultGraphProvider")}} | ||
*/const ct=(t,e={},r)=>{const s=e.title??e?.url;return`Missing ${r?"required ":""}input "${t}"${s?` for board "${s}".`:"."}`},ut=async(t,e,r,s,n,i=[])=>{if(!e.requestInput)return;const o=s.outputs??{},a=new ht(o,s.inputs,n);if(await(e.state?.lifecycle().supplyPartialOutputs(o,n)),i.length>0){const t=i[i.length-1];if(t.state){const e=X(t.state).state;e.partialOutputs=o,t.state=V("nodestart",e)}}s.outputs=await a.read(pt(t,e,r,i))},pt=(t,e,r,s)=>async(n,i,o,a)=>{if(o)throw new Error(ct(n,t,o));if(void 0!==i.default)return"type"in i&&"string"!==i.type?JSON.parse(i.default):i.default;const c=await(e.requestInput?.(n,i,r,a,s));if(e?.signal?.aborted)throw e.signal.throwIfAborted();if(void 0===c)throw new Error(ct(n,t,o));return c};class ht{#N;#S;#I;constructor(t,e,r){this.#N=t,this.#S=e,this.#I=r}async read(t){if(!("schema"in this.#S))return this.#N;const e=this.#S.schema;if(!e.properties)return this.#N;const r=Object.entries(e.properties),s={};for(const[n,i]of r){if(n in this.#N){s[n]=this.#N[n];continue}const r=e.required?.includes(n)??!1,o=await t(n,i,r,this.#I);s[n]=o}return{...this.#N,...s}}}class lt{#R;#j=new Map;constructor(t){const{inputs:e,...r}=t;this.#R=r,this.#j=new Map(e?Object.entries(e):[])}createHandler(t,e){return async(r,s,n,i,o)=>{const a=this.#j.get(r);if(void 0!==a)return a;const c={id:n.id,type:n.type},u={...e,descriptor:c,inputs:{schema:{type:"object",properties:{[r]:s}}}};await t(new ot(u,o,-1,i));const p=u.outputs;let h=p&&p[r];return void 0===h&&(h=await(this.#R.requestInput?.(r,s,c,i,o))),dt(s)||this.#j.set(r,h),h}}}const dt=t=>t.behavior?.includes("transient")??!1,ft=async(t,e,r,s)=>{if(!r.provideOutput)return!1;const n=e.configuration?.schema,i=n?.behavior?.includes("bubble");return!!i&&(await r.provideOutput(t,e,s),!0)},wt=(t,e,r)=>r.provideOutput?r.provideOutput:async(r,s,n)=>{const i={...e,descriptor:s,inputs:r};await t(new at(i,-1,n))};class yt{name="DefaultGraphProvider";#q=Promise.resolve();ready(){return this.#q}isSupported(){return!0}extendedCapabilities(){return{modify:!1,connect:!1,disconnect:!1,refresh:!1,watch:!1,preview:!1}}canProvide(t){return("http:"===t.protocol||"https:"===t.protocol||"file:"===t.protocol&&""===t.hostname)&&{load:!0,save:!1,delete:!1}}async load(t){if("file:"===t.protocol){return(async t=>{if(void 0===globalThis.process)throw new Error("Unable to use `path` when not running in node");let e;if("function"==typeof require){const{readFile:t}=require("node:fs/promises");e=t}else{const{readFile:t}=await import("node:fs/promises");e=t}return JSON.parse(await e(t,"utf-8"))})(decodeURIComponent(t.pathname))}return"http:"===t.protocol||"https:"===t.protocol?(async t=>{let e;try{e=await fetch(t)}catch(r){e=await fetch(t,{credentials:"include"})}return await(e?.json())})(t.href):null}async save(t,e){throw new Error("Save not implemented for DefaultGraphProvider")}async delete(t){throw new Error("Delete not implemented for DefaultGraphProvider")}async connect(t){throw new Error("Connect not implemented for DefaultGraphProvider")}async disconnect(t){throw new Error("Disconnect not implemented for DefaultGraphProvider")}async refresh(t){throw new Error("Refresh not implemented for DefaultGraphProvider")}async createBlank(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async preview(t){throw new Error("Create Blank not implemented for DefaultGraphProvider")}async create(t,e){throw new Error("Create not implemented for DefaultGraphProvider")}async createURL(t,e){throw new Error("createURL not implemented for DefaultGraphProvider")}parseURL(t){throw new Error("parseURL not implemented for DefaultGraphProvider")}async restore(){throw new Error("restore is not implemented for DefaultGraphProvider")}items(){throw new Error("items is not implemented for DefaultGraphProvider")}startingURL(){return null}watch(){throw new Error("watch is not implemented for DefaultGraphProvider")}} | ||
/** | ||
@@ -131,3 +131,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const yt=new URL("sentinel://sentinel/sentinel"),mt=t=>{const e=new URL(t.href);return e.hash="",e},gt=t=>{if(t.outerGraph?.url)return new URL(t.outerGraph.url);const e=t.board?.url;return e?new URL(e):t.base?t.base:yt};class bt{#T;constructor(t){this.#T=[...t,new wt]}async#A(t){for(const e of this.#T){const r=e.canProvide(t);if(!1!==r&&r.load){const r=await e.load(t);if(null!==r)return r.nodes?.map((t=>{"superWorker"===t.type&&(console.warn("superWorker encountered, converting to specialist"),t.type="specialist")})),r.url=t.href,r}}return console.warn(`Unable to load graph from "${t.href}"`),null}async#C(t){const e=await this.#A(t);return e||null}#M(t,e,r){if(!r)return console.warn(`No subgraphs to load "#${e}" from`),null;const s=r[e];return s?(t&&(s.url=t.href),s):(console.warn(`No subgraph found for hash: #${e}`),null)}async load(t,e){const r=e.outerGraph;if(t.startsWith("#")&&r&&!r.url){const e=this.#M(null,t.substring(1),r.graphs);return e||console.warn(`Unable to load graph from "${t}"`),e}const s=gt(e),n=new URL(t,s);if(!n.hash)return await this.#C(n);if(r){const t=r.url?new URL(r.url):yt;if(i=t,mt(n).href===mt(i).href){const t=n.hash.substring(1);return this.#M(n,t,r.graphs)}}var i;const a=await this.#C(mt(n));return a?this.#M(n,n.hash.substring(1),a.graphs):null}} | ||
*/const mt=new URL("sentinel://sentinel/sentinel"),gt=t=>{const e=new URL(t.href);return e.hash="",e},bt=t=>{if(t.outerGraph?.url)return new URL(t.outerGraph.url);const e=t.board?.url;return e?new URL(e):t.base?t.base:mt};class vt{#T;constructor(t){this.#T=[...t,new yt]}async#A(t){for(const e of this.#T){const r=e.canProvide(t);if(!1!==r&&r.load){const r=await e.load(t);if(null!==r)return r.nodes?.map((t=>{"superWorker"===t.type&&(console.warn("superWorker encountered, converting to specialist"),t.type="specialist")})),r.url=t.href,r}}return console.warn(`Unable to load graph from "${t.href}"`),null}async#C(t){const e=await this.#A(t);return e||null}#M(t,e,r){if(!r)return console.warn(`No subgraphs to load "#${e}" from`),null;const s=r[e];return s?(t&&(s.url=t.href),s):(console.warn(`No subgraph found for hash: #${e}`),null)}async load(t,e){const r=e.outerGraph;if(t.startsWith("#")&&r&&!r.url){const e=this.#M(null,t.substring(1),r.graphs);return e||console.warn(`Unable to load graph from "${t}"`),e}const s=bt(e),n=new URL(t,s);if(!n.hash)return await this.#C(n);if(r){const t=r.url?new URL(r.url):mt;if(i=t,gt(n).href===gt(i).href){const t=n.hash.substring(1);return this.#M(n,t,r.graphs)}}var i;const o=await this.#C(gt(n));return o?this.#M(n,n.hash.substring(1),o.graphs):null}} | ||
/** | ||
@@ -137,3 +137,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const vt=(t,e)=>{const r=t.path;return{kind:"board",url:new URL(r,e).href}},St=async(t,e,r)=>(kt(t,e,r),Promise.resolve(t)),kt=(t,e,r)=>{for(const n in t){const i=t[n];if((s=i)&&"board"===s.kind&&i.path){const s=r?new URL(r):gt(e);t[n]=vt(i,s)}}var s;return t};class Et{static computeMissingInputs(t,e,r,s){const n=((t,e="default")=>!!t.metadata?.tags&&t.metadata.tags.some((t=>{const r=t;if("string"==typeof r)return"start"===r;if("start"!==r.type)return!1;const s=r.label??"default";return e===s})))(r,s)?[]:[...new Set(t.filter((t=>!!t.in&&!t.optional)).map((t=>t.in||"")))];const i=new Set;return Object.keys(e).forEach((t=>i.add(t))),r.configuration&&Object.keys(r.configuration).forEach((t=>i.add(t))),n.filter((t=>!i.has(t)))}} | ||
*/const St=(t,e)=>{const r=t.path;return{kind:"board",url:new URL(r,e).href}},kt=async(t,e,r)=>(Et(t,e,r),Promise.resolve(t)),Et=(t,e,r)=>{for(const n in t){const i=t[n];if((s=i)&&"board"===s.kind&&i.path){const s=r?new URL(r):bt(e);t[n]=St(i,s)}}var s;return t};class Ot{static computeMissingInputs(t,e,r,s){const n=((t,e="default")=>!!t.metadata?.tags&&t.metadata.tags.some((t=>{const r=t;if("string"==typeof r)return"start"===r;if("start"!==r.type)return!1;const s=r.label??"default";return e===s})))(r,s)?[]:[...new Set(t.filter((t=>!!t.in&&!t.optional)).map((t=>t.in||"")))];const i=new Set;return Object.keys(e).forEach((t=>i.add(t))),r.configuration&&Object.keys(r.configuration).forEach((t=>i.add(t))),n.filter((t=>!i.has(t)))}} | ||
/** | ||
@@ -143,3 +143,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Ot{graph;#U;constructor(t,e){this.graph=t,this.#U=e}async next(){if(!this.#U.skip){const{inputs:t,descriptor:e}=this.#U;let{outputs:r,newOpportunities:s}=this.#U;if(this.#U.state.useInputs(e.id,this.#U.inputs),r&&r.$error){const n=r.$error;r.$error={descriptor:e,...n,inputs:{...t,...n.inputs}},s=s.filter((t=>"$error"===t.out))}if(r??={},this.#U.opportunities.push(...s),this.#U.state.wireOutputs(s,r),r.$error){if(0===s.length)throw new Error("Uncaught exception in node handler. Catch by wiring up the $error output.",{cause:r.$error});console.warn("Error in node handler, passing to the wired $error output.",r.$error,s)}}if(0===this.#U.opportunities.length)return{done:!0,value:null};const t=this.#U.opportunities.shift(),{heads:e,nodes:r,tails:s}=this.graph,n=t.to,i=r.get(n);if(!i)throw new Error(`No node found for id "${n}"`);const a=e.get(n)||[],o=this.#U.state.getAvailableInputs(n),c=Et.computeMissingInputs(a,o,i),u=s.get(n)||[],p={...i.configuration,...o};return this.#U=new J(i,p,c,t,this.#U.opportunities,u,this.#U.state),{done:!1,value:this.#U}}} | ||
*/class xt{graph;#U;constructor(t,e){this.graph=t,this.#U=e}async next(){if(!this.#U.skip){const{inputs:t,descriptor:e}=this.#U;let{outputs:r,newOpportunities:s}=this.#U;if(this.#U.state.useInputs(e.id,this.#U.inputs),r&&r.$error){const n=r.$error;r.$error={descriptor:e,...n,inputs:{...t,...n.inputs}},s=s.filter((t=>"$error"===t.out))}if(r??={},this.#U.opportunities.push(...s),this.#U.state.wireOutputs(s,r),r.$error){if(0===s.length)throw new Error("Uncaught exception in node handler. Catch by wiring up the $error output.",{cause:r.$error});console.warn("Error in node handler, passing to the wired $error output.",r.$error,s)}}if(0===this.#U.opportunities.length)return{done:!0,value:null};const t=this.#U.opportunities.shift(),{heads:e,nodes:r,tails:s}=this.graph,n=t.to,i=r.get(n);if(!i)throw new Error(`No node found for id "${n}"`);const o=e.get(n)||[],a=this.#U.state.getAvailableInputs(n),c=Ot.computeMissingInputs(o,a,i),u=s.get(n)||[],p={...i.configuration,...a};return this.#U=new _(i,p,c,t,this.#U.opportunities,u,this.#U.state),{done:!1,value:this.#U}}} | ||
/** | ||
@@ -149,3 +149,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class xt{start;tails=new Map;heads=new Map;nodes=new Map;entries=[];#D(t){return!this.heads.has(t)||0===this.heads.get(t)?.length}#F(){const t=new Set,e=this.start??"default";let r=!1;return this.nodes.forEach((s=>{s.metadata?.tags?.forEach((n=>{const i=n;if("string"==typeof i&&"start"===i)t.add(s.id);else if("start"===i.type){const n=i.label??"default";r=!0,n===e&&t.add(s.id)}}))})),t.size>0?Array.from(t):r?[]:Array.from(this.nodes.keys()).filter((t=>this.#D(t)))}constructor(t,e){e&&(this.start=e),this.tails=t.edges.reduce(((t,e)=>{const r=e.from;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.heads=t.edges.reduce(((t,e)=>{const r=e.to;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.nodes=t.nodes.reduce(((t,e)=>(t.set(e.id,e),t)),new Map),this.entries=this.#F()}} | ||
*/class $t{start;tails=new Map;heads=new Map;nodes=new Map;entries=[];#D(t){return!this.heads.has(t)||0===this.heads.get(t)?.length}#F(){const t=new Set,e=this.start??"default";let r=!1;return this.nodes.forEach((s=>{s.metadata?.tags?.forEach((n=>{const i=n;if("string"==typeof i&&"start"===i)t.add(s.id);else if("start"===i.type){const n=i.label??"default";r=!0,n===e&&t.add(s.id)}}))})),t.size>0?Array.from(t):r?[]:Array.from(this.nodes.keys()).filter((t=>this.#D(t)))}constructor(t,e){e&&(this.start=e),this.tails=t.edges.reduce(((t,e)=>{const r=e.from;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.heads=t.edges.reduce(((t,e)=>{const r=e.to;return t.has(r)?t.get(r)?.push(e):t.set(r,[e]),t}),new Map),this.nodes=t.nodes.reduce(((t,e)=>(t.set(e.id,e),t)),new Map),this.entries=this.#F()}} | ||
/** | ||
@@ -155,3 +155,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class $t{graph;previousResult;constructor(t,e,r){this.graph=new xt(t,r),this.previousResult=e}[Symbol.asyncIterator](){return this.start()}start(){if(this.previousResult)return new Ot(this.graph,this.previousResult);const{entries:t}=this.graph;if(0===t.length)throw new Error("No entry node found in graph.");const e=t.map((t=>({from:"$entry",to:t}))),r=new J({id:"$empty",type:"$empty"},{},[],{from:"$entry",to:t[0]},e,[],new z);return new Ot(this.graph,r)}} | ||
*/class Pt{graph;previousResult;constructor(t,e,r){this.graph=new $t(t,r),this.previousResult=e}[Symbol.asyncIterator](){return this.start()}start(){if(this.previousResult)return new xt(this.graph,this.previousResult);const{entries:t}=this.graph;if(0===t.length)throw new Error("No entry node found in graph.");const e=t.map((t=>({from:"$entry",to:t}))),r=new _({id:"$empty",type:"$empty"},{},[],{from:"$entry",to:t[0]},e,[],new J);return new xt(this.graph,r)}} | ||
/** | ||
@@ -161,3 +161,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Pt=()=>{};class It{#L=[];#W=Pt;#G;#B;abort=Pt;constructor(){this.#H()}#H(){this.#G=new Promise(((t,e)=>{this.#W=t,this.abort=e}))}#z(t){this.#L.push(t),1==this.#L.length&&(this.#W(),this.#H())}async write(t){return new Promise((e=>{this.#z({value:t,receipt:e})}))}async read(){this.#B&&this.#B(),0===this.#L.length&&await this.#G;const t=this.#L.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.#z({value:void 0,receipt:Pt})}}class Rt{#d;#J=!0;#L=new It;constructor(t){this.#d=t}async#_(t){return this.#L.write(t)}async next(){return this.#J&&(this.#J=!1,this.#d(this.#_.bind(this)).then((()=>{this.#L.close()})).catch((t=>{this.#L.abort(t)}))),this.#L.read()}}const Nt=t=>({[Symbol.asyncIterator]:()=>new Rt(t)}); | ||
*/const It=()=>{};class Nt{#L=[];#W=It;#G;#B;abort=It;constructor(){this.#H()}#H(){this.#G=new Promise(((t,e)=>{this.#W=t,this.abort=e}))}#z(t){this.#L.push(t),1==this.#L.length&&(this.#W(),this.#H())}async write(t){return new Promise((e=>{this.#z({value:t,receipt:e})}))}async read(){this.#B&&this.#B(),0===this.#L.length&&await this.#G;const t=this.#L.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.#z({value:void 0,receipt:It})}}class Rt{#d;#J=!0;#L=new Nt;constructor(t){this.#d=t}async#_(t){return this.#L.write(t)}async next(){return this.#J&&(this.#J=!1,this.#d(this.#_.bind(this)).then((()=>{this.#L.close()})).catch((t=>{this.#L.abort(t)}))),this.#L.read()}}const jt=t=>({[Symbol.asyncIterator]:()=>new Rt(t)}); | ||
/** | ||
@@ -167,3 +167,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class jt{#K;#Q;#V;#N;#X;constructor(t,e,r){const{inputs:s,...n}=t;this.#K=new ht(t),this.#Q=r,this.#V=e,this.#N=n,this.#X=m(n.kits??[])}async invokeNode(t,e){const{inputs:r,descriptor:s}=t,{kits:n=[],base:i=yt,state:a}=this.#N;let o;const c=this.#X[s.type];if(!c)throw new Error(`No handler for node type "${s.type}"`);const u={...this.#N,descriptor:s,board:this.#V,outerGraph:this.#V,base:i,kits:n,requestInput:this.#K.createHandler(this.#Q,t),provideOutput:ft(this.#Q,t,this.#N),invocationPath:e,state:a};return o=await y(c,kt(r,this.#N,this.#V.url),u),o}} | ||
*/class qt{#K;#Q;#V;#R;#X;constructor(t,e,r){const{inputs:s,...n}=t;this.#K=new lt(t),this.#Q=r,this.#V=e,this.#R=n,this.#X=m(n.kits??[])}async invokeNode(t,e){const{inputs:r,descriptor:s}=t,{kits:n=[],base:i=mt,state:o}=this.#R;let a;const c=this.#X[s.type];if(!c)throw new Error(`No handler for node type "${s.type}"`);const u={...this.#R,descriptor:s,board:this.#V,outerGraph:this.#V,base:i,kits:n,requestInput:this.#K.createHandler(this.#Q,t),provideOutput:wt(this.#Q,t,this.#R),invocationPath:e,state:o};return a=await y(c,Et(r,this.#R,this.#V.url),u),a}} | ||
/** | ||
@@ -173,3 +173,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/async function*qt(t,e={},r){const{inputs:s,start:n,...i}=e,{probe:a,state:o,invocationPath:c=[]}=i,u=o?.lifecycle();yield*Nt((async s=>{const p=new jt(e,t,s);u?.dispatchGraphStart(t.url,c);let h=0;const l=o?.reanimation();if(l){const t=l.enter(c);switch(t.mode()){case"replay":{const{result:e,invocationId:r,path:n}=t.replay();return void await s(new at(e,r,n))}case"resume":{const{result:e,invocationPath:s}=t.resume();let n;r=e,h=s[s.length-1],await(u?.dispatchNodeStart(e,s));const i=e.descriptor.type;"input"!==i&&"output"!==i?(n=await p.invokeNode(e,s),e.outputs=n,r=e):n=e.outputs,u?.dispatchNodeEnd(n,s),await(a?.report?.({type:"nodeend",data:{node:e.descriptor,inputs:e.inputs,outputs:n,path:s,timestamp:j()}}))}}}const d=()=>[...c,h],f=new $t(t,r,n);r||await(a?.report?.({type:"graphstart",data:{graph:t,path:c,timestamp:j()}}));for await(const e of f){i?.signal?.throwIfAborted(),h++;const{inputs:r,descriptor:n,missingInputs:o}=e;if(e.skip){u?.dispatchSkip(),await(a?.report?.({type:"skip",data:{node:n,inputs:r,missingInputs:o,path:d(),timestamp:j()}}));continue}let c;u?.dispatchEdge(e.current),await(a?.report?.({type:"edge",data:{edge:e.current,to:d(),from:u?.pathFor(e.current.from),timestamp:j(),value:r}})),await(u?.dispatchNodeStart(e,d())),await(a?.report?.({type:"nodestart",data:{node:n,inputs:r,path:d(),timestamp:j()},state:u?.state()})),"input"===n.type?(await s(new it(e,u?.state(),h,d())),await ct(t,i,n,e,d(),u?.state()),c=e.outputs?await St(e.outputs,i,t.url):void 0):"output"===n.type?(await dt(r,n,i,d())||await s(new at(e,h,d())),c=e.outputs):c=await p.invokeNode(e,d()),u?.dispatchNodeEnd(c,d()),await(a?.report?.({type:"nodeend",data:{node:n,inputs:r,outputs:c,path:d(),timestamp:j()}})),e.outputs=c}u?.dispatchGraphEnd(),await(a?.report?.({type:"graphend",data:{path:c,timestamp:j()}}))}))} | ||
*/async function*Tt(t,e={},r){const{inputs:s,start:n,...i}=e,{probe:o,state:a,invocationPath:c=[]}=i,u=a?.lifecycle();yield*jt((async s=>{const p=new qt(e,t,s);u?.dispatchGraphStart(t.url,c);let h=0;const l=a?.reanimation();if(l){const t=l.enter(c);switch(t.mode()){case"replay":{const{result:e,invocationId:r,path:n}=t.replay();return void await s(new at(e,r,n))}case"resume":{const{result:e,invocationPath:s}=t.resume();let n;r=e,h=s[s.length-1],await(u?.dispatchNodeStart(e,s));const i=e.descriptor.type;"input"!==i&&"output"!==i?(n=await p.invokeNode(e,s),e.outputs=n,r=e):n=e.outputs,u?.dispatchNodeEnd(n,s),await(o?.report?.({type:"nodeend",data:{node:e.descriptor,inputs:e.inputs,outputs:n,path:s,timestamp:j()}}))}}}const d=()=>[...c,h],f=new Pt(t,r,n);r||await(o?.report?.({type:"graphstart",data:{graph:t,path:c,timestamp:j()}}));for await(const e of f){i?.signal?.throwIfAborted(),h++;const{inputs:r,descriptor:n,missingInputs:a}=e;if(e.skip){u?.dispatchSkip(),await(o?.report?.({type:"skip",data:{node:n,inputs:r,missingInputs:a,path:d(),timestamp:j()}}));continue}let c;u?.dispatchEdge(e.current),await(o?.report?.({type:"edge",data:{edge:e.current,to:d(),from:u?.pathFor(e.current.from),timestamp:j(),value:r}})),await(u?.dispatchNodeStart(e,d())),await(o?.report?.({type:"nodestart",data:{node:n,inputs:r,path:d(),timestamp:j()},state:u?.state()})),"input"===n.type?(await s(new ot(e,u?.state(),h,d())),await ut(t,i,n,e,d(),u?.state()),c=e.outputs?await kt(e.outputs,i,t.url):void 0):"output"===n.type?(await ft(r,n,i,d())||await s(new at(e,h,d())),c=e.outputs):c=await p.invokeNode(e,d()),u?.dispatchNodeEnd(c,d()),await(o?.report?.({type:"nodeend",data:{node:n,inputs:r,outputs:c,path:d(),timestamp:j()}})),e.outputs=c}u?.dispatchGraphEnd(),await(o?.report?.({type:"graphend",data:{path:c,timestamp:j()}}))}))} | ||
/** | ||
@@ -179,3 +179,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Tt{#l;constructor(t){this.#l=t}async serve(t,e=!1,r={}){const s=this.#l.createServerStream(),i=s.readableRequests.getReader();let a=await i.read();if(a.done)return;const o=s.writableResponses.getWriter(),c={...r,state:st(),probe:e?new G((async t=>{const{type:e,data:r}=t,s=[e,n(r)];"nodestart"==e&&s.push(t.state),await o.write(s)})):void 0};try{for await(const e of qt(t,c))if("input"===e.type){const{node:t,inputArguments:r,timestamp:s,path:n,invocationId:c}=e,u=-1==c;if(await o.write(["input",{node:t,inputArguments:r,timestamp:s,path:n,bubbled:u}]),a=await i.read(),a.done)return void await o.close();{const[t,r]=a.value;"input"===t&&(e.inputs=r.inputs)}}else if("output"===e.type){const{node:t,outputs:r,timestamp:s,path:n,invocationId:i}=e,a=-1==i;await o.write(["output",{node:t,outputs:r,timestamp:s,path:n,bubbled:a}])}await o.write(["end",{timestamp:j()}]),await o.close()}catch(t){const e=B(t);console.error("Run Server error:",e),await o.write(["error",{error:e,timestamp:j()}]),await o.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])}}};class Ct{#l;constructor(t){this.#l=t}async*run(t){const e=this.#l.createClientStream(),r=c(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||{}}} | ||
*/class At{#l;constructor(t){this.#l=t}async serve(t,e=!1,r={}){const s=this.#l.createServerStream(),i=s.readableRequests.getReader();let o=await i.read();if(o.done)return;const a=s.writableResponses.getWriter(),c={...r,state:nt(),probe:e?new B((async t=>{const{type:e,data:r}=t,s=[e,n(r)];"nodestart"==e&&s.push(t.state),await a.write(s)})):void 0};try{for await(const e of Tt(t,c))if("input"===e.type){const{node:t,inputArguments:r,timestamp:s,path:n,invocationId:c}=e,u=-1==c;if(await a.write(["input",{node:t,inputArguments:r,timestamp:s,path:n,bubbled:u}]),o=await i.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,path:n,invocationId:i}=e,o=-1==i;await a.write(["output",{node:t,outputs:r,timestamp:s,path:n,bubbled:o}])}await a.write(["end",{timestamp:j()}]),await a.close()}catch(t){const e=H(t);console.error("Run Server error:",e),await a.write(["error",{error:e,timestamp:j()}]),await a.close()}}}const Ct=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])}}};class Mt{#l;constructor(t){this.#l=t}async*run(t){const e=this.#l.createClientStream(),r=c(e.writableRequests,e.readableResponses),s=["run",{}];t&&s.push(t),await r.start(s);for await(const t of r)yield Ct(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||{}}} | ||
/** | ||
@@ -185,3 +185,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Mt{#l;constructor(t){this.#l=t}async serve(){const t=this.#l.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 Ut{#l;constructor(t){this.#l=t}async load(t){const e=this.#l.createClientStream().writableRequests.getWriter();await e.write({url:t}),await e.close()}} | ||
*/class Ut{#l;constructor(t){this.#l=t}async serve(){const t=this.#l.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 Dt{#l;constructor(t){this.#l=t}async load(t){const e=this.#l.createClientStream().writableRequests.getWriter();await e.write({url:t}),await e.close()}} | ||
/** | ||
@@ -191,3 +191,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Dt=t=>t,Ft=t=>({test:e=>new URL(e).origin===t}) | ||
*/const Ft=t=>t,Lt=t=>({test:e=>new URL(e).origin===t}) | ||
/** | ||
@@ -197,3 +197,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/;class Lt{} | ||
*/;class Wt{} | ||
/** | ||
@@ -203,3 +203,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Wt=new | ||
*/const Gt=new | ||
/** | ||
@@ -210,3 +210,3 @@ * @license | ||
*/ | ||
class{#Y=new Map;vendId(t,e){let r=this.#Y.get(t)||0;return r++,this.#Y.set(t,r),`${e}-${r}`}};class Gt extends Lt{id;type;outgoing=[];incoming=[];configuration={};metadata;#Z;#tt;constructor(t,e,r={}){super(),this.#tt=e,"string"==typeof t?this.type=t:(this.type="fn",this.#Z=t);const{$id:s,$metadata:n,...i}=r;this.id=s??Wt.vendId(e,this.type),n&&(this.metadata=n),this.configuration=i}addIncomingEdge(t,e,r,s,n){if(t.#tt!==this.#tt)throw new Error("Can't connect nodes from different scopes");const i={to:this,from:t,out:e,in:r,schema:n};s&&(i.constant=!0),this.incoming.push(i),t.outgoing.push(i)}#et(t){const e=this.#Z??t.getHandler(this.type);return e&&"describe"in e&&e.describe?e.describe:void 0}async invoke(t,e){const r=e??this.#tt,s=this.#Z??r.getHandler(this.type);let n;const i=s&&"invoke"in s&&s.invoke?s.invoke:"function"==typeof s?s:void 0;if(i)n=await i(t,this);else{if(!s||"function"==typeof s||!s.graph)throw new Error(`Can't find handler for ${this.id}`);{const e=s.graph.getPinnedNodes();if(1!==e.length)throw new Error("Expected exactly one graph");n=await r.invokeOneRound(t,e[0])}}return n}async describe(t=this.#tt,e,r,s){const n=this.#et(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#tt.serialize(t,this)}async serializeNode(){const t={id:this.id,type:this.type,configuration:this.configuration};return this.metadata&&(t.metadata=this.metadata),[t]}} | ||
class{#Y=new Map;vendId(t,e){let r=this.#Y.get(t)||0;return r++,this.#Y.set(t,r),`${e}-${r}`}};class Bt extends Wt{id;type;outgoing=[];incoming=[];configuration={};metadata;#Z;#tt;constructor(t,e,r={}){super(),this.#tt=e,"string"==typeof t?this.type=t:(this.type="fn",this.#Z=t);const{$id:s,$metadata:n,...i}=r;this.id=s??Gt.vendId(e,this.type),n&&(this.metadata=n),this.configuration=i}addIncomingEdge(t,e,r,s,n){if(t.#tt!==this.#tt)throw new Error("Can't connect nodes from different scopes");const i={to:this,from:t,out:e,in:r,schema:n};s&&(i.constant=!0),this.incoming.push(i),t.outgoing.push(i)}#et(t){const e=this.#Z??t.getHandler(this.type);return e&&"describe"in e&&e.describe?e.describe:void 0}async invoke(t,e){const r=e??this.#tt,s=this.#Z??r.getHandler(this.type);let n;const i=s&&"invoke"in s&&s.invoke?s.invoke:"function"==typeof s?s:void 0;if(i)n=await i(t,this);else{if(!s||"function"==typeof s||!s.graph)throw new Error(`Can't find handler for ${this.id}`);{const e=s.graph.getPinnedNodes();if(1!==e.length)throw new Error("Expected exactly one graph");n=await r.invokeOneRound(t,e[0])}}return n}async describe(t=this.#tt,e,r,s){const n=this.#et(t);return n?await n(e,r,s):void 0}async serialize(t){return this.#tt.serialize(t,this)}async serializeNode(){const t={id:this.id,type:this.type,configuration:this.configuration};return this.metadata&&(t.metadata=this.metadata),[t]}} | ||
/** | ||
@@ -216,3 +216,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Bt{queue=[];inputs=new Map;constants=new Map;controlWires=new Map;haveRun=new Set;queueUp(t){this.queue.includes(t)||this.queue.push(t)}next(){if(!this.queue.length)throw new Error("No nodes in queue");return this.queue.shift()}done(){return 0===this.queue.length}missingInputs(t){if(0===t.incoming.length&&this.haveRun.has(t))return[];const e=new Set(t.incoming.map((t=>t.in))),r=new Set([...Object.keys(t.configuration),...Object.keys(this.constants.get(t)??{})]);for(const[e,s]of(this.inputs.get(t)??new Map).entries())s.length&&r.add(e);this.controlWires.get(t)?.length&&r.add("");const s=[...e].filter((t=>!r.has(t)));return!!s.length&&s}shiftInputs(t){const e={...t.configuration,...this.constants.get(t)},r=this.inputs.get(t)??new Map;for(const[t,s]of r.entries())s.length>0&&(e[t]=s.shift());return this.haveRun.add(t),this.controlWires.delete(t),e}processResult(t,e){const r={nodes:[],unused:[]},s=new Set(Object.keys(e));for(const n of t.outgoing){const t=this.distributeResults(n,e);t.forEach((t=>s.delete(t)));const i=this.missingInputs(n.to);i||this.queueUp(n.to),r.nodes.push({node:n.to,received:t,missing:i})}return r.unused=[...s],r}distributeResults(t,e){const r="*"===t.out?e:""===t.out?{}:void 0!==e[t.out]?{[t.in]:e[t.out]}:{};t.constant&&this.constants.set(t.to,{...this.constants.get(t.to),...r}),this.inputs.has(t.to)||this.inputs.set(t.to,new Map);const s=this.inputs.get(t.to);for(const t of Object.keys(r))s?.has(t)||s?.set(t,[]),s?.get(t)?.push(r[t]);return""===t.in&&this.controlWires.set(t.to,[...this.controlWires.get(t.to)??[],t.from]),Object.keys(r)}} | ||
*/class Ht{queue=[];inputs=new Map;constants=new Map;controlWires=new Map;haveRun=new Set;queueUp(t){this.queue.includes(t)||this.queue.push(t)}next(){if(!this.queue.length)throw new Error("No nodes in queue");return this.queue.shift()}done(){return 0===this.queue.length}missingInputs(t){if(0===t.incoming.length&&this.haveRun.has(t))return[];const e=new Set(t.incoming.map((t=>t.in))),r=new Set([...Object.keys(t.configuration),...Object.keys(this.constants.get(t)??{})]);for(const[e,s]of(this.inputs.get(t)??new Map).entries())s.length&&r.add(e);this.controlWires.get(t)?.length&&r.add("");const s=[...e].filter((t=>!r.has(t)));return!!s.length&&s}shiftInputs(t){const e={...t.configuration,...this.constants.get(t)},r=this.inputs.get(t)??new Map;for(const[t,s]of r.entries())s.length>0&&(e[t]=s.shift());return this.haveRun.add(t),this.controlWires.delete(t),e}processResult(t,e){const r={nodes:[],unused:[]},s=new Set(Object.keys(e));for(const n of t.outgoing){const t=this.distributeResults(n,e);t.forEach((t=>s.delete(t)));const i=this.missingInputs(n.to);i||this.queueUp(n.to),r.nodes.push({node:n.to,received:t,missing:i})}return r.unused=[...s],r}distributeResults(t,e){const r="*"===t.out?e:""===t.out?{}:void 0!==e[t.out]?{[t.in]:e[t.out]}:{};t.constant&&this.constants.set(t.to,{...this.constants.get(t.to),...r}),this.inputs.has(t.to)||this.inputs.set(t.to,new Map);const s=this.inputs.get(t.to);for(const t of Object.keys(r))s?.has(t)||s?.set(t,[]),s?.get(t)?.push(r[t]);return""===t.in&&this.controlWires.set(t.to,[...this.controlWires.get(t.to)??[],t.from]),Object.keys(r)}} | ||
/** | ||
@@ -222,3 +222,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Ht{parentLexicalScope;parentDynamicScope;#X={};#rt=[];#st=[];constructor(t={}){this.parentLexicalScope=t.lexicalScope,this.parentDynamicScope=t.dynamicScope}addHandlers(t){Object.entries(t).forEach((([t,e])=>this.#X[t]=e))}getHandler(t){return this.#X[t]||this.parentDynamicScope?.getHandler(t)||this.parentLexicalScope?.getHandler(t)}pin(t){this.#rt.push(t)}compactPins(){const t=new Set,e=[];for(const r of this.#rt){if(t.has(r))continue;e.push(r);this.#nt(r).forEach((e=>t.add(e)))}this.#rt=e}getPinnedNodes(){return this.#rt}addCallbacks(t){this.#st.push(t)}#it(){return[...this.#st,...this.parentDynamicScope?this.parentDynamicScope.#it():[]]}async invoke(t,e=new Bt){try{!1!==t&&(t?t instanceof Array?t:[t]:this.#rt).flatMap((t=>this.#nt(t).filter((t=>!1===e?.missingInputs(t))))).forEach((t=>e?.queueUp(t)));const r=this.#it();for(;!e.done();){for(const t of r)if(await(t.stop?.(this,e)))return;const t=e.next(),s=e.shiftInputs(t);let n;for(const e of r)n??=await(e.before?.(this,t,s));const i=n??await t.invoke(s,this).catch((t=>({$error:{type:"error",error:t}}))),a=e.processResult(t,i);for(const e of r)await(e.after?.(this,t,s,i,a));if(a.unused.includes("$error"))throw i.$error.error}}finally{for(const t of this.#st)await(t.done?.())}}invokeOneRound(t={},e=void 0,r){let s;"$state"in t&&(r=t.$state,delete t.$state);const n=new Promise((t=>{s=t})),i=new Ht({dynamicScope:this});let a;i.addHandlers({input:async()=>t,output:async t=>(s?.(await t),s=void 0,t)});const o=new Map;let c;i.addCallbacks({stop:(t,e)=>(s||(c=e),!s),after:(t,e,r,s,n)=>{a=e;for(const{node:t,missing:e}of n.nodes)e?o.set(t.id,e.join(", ")):o.delete(t.id)},done:()=>{s?.({$error:{type:"error",error:new Error(`Output node never reached. Last node was ${a?.id}.\n\nThese nodes had inputs missing:\n${Array.from(o,(([t,e])=>` ${t}: ${e}`)).join("\n")}`)}})}});const u=i.invoke(void 0!==e?e:this.#rt,r);return Promise.all([n,u]).then((([t])=>({...t,...c?{$state:c}:{}})))}async serialize(t,e){const r=(e?[e]:this.#rt).flatMap((t=>this.#nt(t))),s={},n=await Promise.all(r.map((async t=>{const[e,r]=await t.serializeNode();if(r&&(s[e.id]=r),("input"===e.type||"output"===e.type)&&!e.configuration?.schema){const r=await this.#at(t);Object.entries(r.properties??{}).length>0&&(e.configuration={...e.configuration,schema:r})}return e}))),i=r.flatMap((t=>t.outgoing.map((t=>({from:t.from.id,to:t.to.id,out:t.out,in:t.in,...t.constant?{constant:!0}:{}})))));return{...t,edges:i,nodes:n,graphs:s}}#nt(t){const e=new Set,r=[t];for(;r.length;){const t=r.shift();e.has(t)||(e.add(t),t.incoming.forEach((t=>r.push(t.from))),t.outgoing.forEach((t=>r.push(t.to))))}return[...e]}async#ot(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#at(t){const e={},r=new Set;let s;if("input"===t.type){const n=new Set;for(const s of t.outgoing)"*"!==s.out&&""!==s.out&&(n.add(s.to),r.add(s.out),s.schema&&(e[s.out]=s.schema));for(const r of n){const s=await this.#ot(r),n=s?.inputSchema?.properties;if(n)for(const s of r.incoming)s.from===t&&n[s.in]&&(e[s.out]={...n[s.in],...e[s.out]})}s=(t=>Object.entries(t).map((([t,e])=>{const r=e;if(!r.$optional)return t;delete r.$optional})).filter(Boolean))(e)}else{if("output"!==t.type)throw new Error("Can't yet derive schema for non-input/output nodes");{const s=new Set;for(const n of t.incoming)"*"!==n.out&&""!==n.out&&(s.add(n.from),r.add(n.in),n.schema&&(e[n.in]=n.schema));for(const r of s){const s=await this.#ot(r),n=s?.outputSchema?.properties;if(n)for(const s of r.outgoing)s.to===t&&n[s.out]&&(e[s.in]={...n[s.out],...e[s.in]})}}}for(const t of r)e[t]?(e[t].type||="string",e[t].title||=t):e[t]={type:"string",title:t};const n={type:"object",properties:e};return s&&(n.required=s),n}} | ||
*/class zt{parentLexicalScope;parentDynamicScope;#X={};#rt=[];#st=[];constructor(t={}){this.parentLexicalScope=t.lexicalScope,this.parentDynamicScope=t.dynamicScope}addHandlers(t){Object.entries(t).forEach((([t,e])=>this.#X[t]=e))}getHandler(t){return this.#X[t]||this.parentDynamicScope?.getHandler(t)||this.parentLexicalScope?.getHandler(t)}pin(t){this.#rt.push(t)}compactPins(){const t=new Set,e=[];for(const r of this.#rt){if(t.has(r))continue;e.push(r);this.#nt(r).forEach((e=>t.add(e)))}this.#rt=e}getPinnedNodes(){return this.#rt}addCallbacks(t){this.#st.push(t)}#it(){return[...this.#st,...this.parentDynamicScope?this.parentDynamicScope.#it():[]]}async invoke(t,e=new Ht){try{!1!==t&&(t?t instanceof Array?t:[t]:this.#rt).flatMap((t=>this.#nt(t).filter((t=>!1===e?.missingInputs(t))))).forEach((t=>e?.queueUp(t)));const r=this.#it();for(;!e.done();){for(const t of r)if(await(t.stop?.(this,e)))return;const t=e.next(),s=e.shiftInputs(t);let n;for(const e of r)n??=await(e.before?.(this,t,s));const i=n??await t.invoke(s,this).catch((t=>({$error:{type:"error",error:t}}))),o=e.processResult(t,i);for(const e of r)await(e.after?.(this,t,s,i,o));if(o.unused.includes("$error"))throw i.$error.error}}finally{for(const t of this.#st)await(t.done?.())}}invokeOneRound(t={},e=void 0,r){let s;"$state"in t&&(r=t.$state,delete t.$state);const n=new Promise((t=>{s=t})),i=new zt({dynamicScope:this});let o;i.addHandlers({input:async()=>t,output:async t=>(s?.(await t),s=void 0,t)});const a=new Map;let c;i.addCallbacks({stop:(t,e)=>(s||(c=e),!s),after:(t,e,r,s,n)=>{o=e;for(const{node:t,missing:e}of n.nodes)e?a.set(t.id,e.join(", ")):a.delete(t.id)},done:()=>{s?.({$error:{type:"error",error:new Error(`Output node never reached. Last node was ${o?.id}.\n\nThese nodes had inputs missing:\n${Array.from(a,(([t,e])=>` ${t}: ${e}`)).join("\n")}`)}})}});const u=i.invoke(void 0!==e?e:this.#rt,r);return Promise.all([n,u]).then((([t])=>({...t,...c?{$state:c}:{}})))}async serialize(t,e){const r=(e?[e]:this.#rt).flatMap((t=>this.#nt(t))),s={},n=await Promise.all(r.map((async t=>{const[e,r]=await t.serializeNode();if(r&&(s[e.id]=r),("input"===e.type||"output"===e.type)&&!e.configuration?.schema){const r=await this.#ot(t);Object.entries(r.properties??{}).length>0&&(e.configuration={...e.configuration,schema:r})}return e}))),i=r.flatMap((t=>t.outgoing.map((t=>({from:t.from.id,to:t.to.id,out:t.out,in:t.in,...t.constant?{constant:!0}:{}})))));return{...t,edges:i,nodes:n,graphs:s}}#nt(t){const e=new Set,r=[t];for(;r.length;){const t=r.shift();e.has(t)||(e.add(t),t.incoming.forEach((t=>r.push(t.from))),t.outgoing.forEach((t=>r.push(t.to))))}return[...e]}async#at(t){const e=Object.fromEntries(t.incoming.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}]))),r=Object.fromEntries(t.outgoing.filter((t=>""!==t.out&&"*"!==t.out)).map((t=>[t.out,t.schema??{}])));return await t.describe(this,t.configuration,{properties:e},{properties:r})}async#ot(t){const e={},r=new Set;let s;if("input"===t.type){const n=new Set;for(const s of t.outgoing)"*"!==s.out&&""!==s.out&&(n.add(s.to),r.add(s.out),s.schema&&(e[s.out]=s.schema));for(const r of n){const s=await this.#at(r),n=s?.inputSchema?.properties;if(n)for(const s of r.incoming)s.from===t&&n[s.in]&&(e[s.out]={...n[s.in],...e[s.out]})}s=(t=>Object.entries(t).map((([t,e])=>{const r=e;if(!r.$optional)return t;delete r.$optional})).filter(Boolean))(e)}else{if("output"!==t.type)throw new Error("Can't yet derive schema for non-input/output nodes");{const s=new Set;for(const n of t.incoming)"*"!==n.out&&""!==n.out&&(s.add(n.from),r.add(n.in),n.schema&&(e[n.in]=n.schema));for(const r of s){const s=await this.#at(r),n=s?.outputSchema?.properties;if(n)for(const s of r.outgoing)s.to===t&&n[s.out]&&(e[s.in]={...n[s.out],...e[s.in]})}}}for(const t of r)e[t]?(e[t].type||="string",e[t].title||=t):e[t]={type:"string",title:t};const n={type:"object",properties:e};return s&&(n.required=s),n}} | ||
/** | ||
@@ -228,3 +228,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class zt extends Ht{#ct;#ut=[];parentLambdaNode;constructor(t={}){super(t),this.#ct=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.#ct}asScopeFor(t){return(...e)=>{const r=Kt(this);try{return t(...e)}finally{Kt(r)}}}addClosureEdge(t){this.#ut.push(t)}getClosureEdges(){return this.#ut}}let Jt;function _t(){return Jt||(Jt=new zt),Jt}function Kt(t){const e=_t();return Jt=t,e} | ||
*/class Jt extends zt{#ct;#ut=[];parentLambdaNode;constructor(t={}){super(t),this.#ct=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.#ct}asScopeFor(t){return(...e)=>{const r=Qt(this);try{return t(...e)}finally{Qt(r)}}}addClosureEdge(t){this.#ut.push(t)}getClosureEdges(){return this.#ut}}let _t;function Kt(){return _t||(_t=new Jt),_t}function Qt(t){const e=Kt();return _t=t,e} | ||
/** | ||
@@ -234,3 +234,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class Qt{} | ||
*/class Vt{} | ||
/** | ||
@@ -240,3 +240,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const Vt=Symbol("IsValue");function Xt(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[Vt]}const Yt=t=>{if("array"===t.type){t.items??={};const r=(e=t.items,Array.isArray(e)?t.items[0]:t.items);return r.type??="object",r}var e;return t};class Zt extends Qt{#pt;#tt;#ht;#lt;#dt;constructor(t,e,r,s=!1,n={}){super(),this.#pt=t,this.#tt=e,this.#ht="string"==typeof r?{[r]:r}:r,this[Vt]=this,this.#lt=s,this.#dt=n}then(t,e){if(1!==Object.keys(this.#ht).length)throw Error("Can't `await` for multiple values");return this.#pt.then((e=>e&&t&&this.#tt.asScopeFor(t)(e[Object.keys(this.#ht)[0]])),e&&this.#tt.asScopeFor(e))}asNodeInput(){return[this.#pt.unProxy(),this.#ht,this.#lt,this.#dt]}to(t,e){const r=ee(t)?t.unProxy():new te(t,this.#tt,e);return r.addInputsFromNode(this.#pt,this.#ht,this.#lt,this.#dt),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#ht).map((([t,e])=>[e,t])));Xt(t)?(e=t.#ft(e),this.#pt.addInputsFromNode(t.#pt,e,t.#lt,t.#dt)):ee(t)?this.#pt.addInputsFromNode(t.unProxy(),e):this.#pt.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#ht).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#ht)[0]]:t}}else e=this.#ft(t);return new Zt(this.#pt,this.#tt,e,this.#lt,this.#dt)}memoize(){return new Zt(this.#pt,this.#tt,this.#ht,!0,this.#dt)}invoke(t){return new te("invoke",this.#tt,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#dt.type,this}isString(){return this.#dt.type="string",this}isNumber(){return this.#dt.type="number",this}isBoolean(){return this.#dt.type="boolean",this}isArray(){return this.#dt.type="array",this}isObject(){return this.#dt.type="object",this}title(t){return this.#dt.title=t,this}description(t){return this.#dt.description=t,this}format(t){return Yt(this.#dt).format=t,this}examples(...t){return this.#dt.examples=t,this}default(t){return this.#dt.default=t,this}optional(){return this.#dt.$optional=!0,this}behavior(...t){const e=Yt(this.#dt);return e.behavior??=[],e.behavior.push(...t),this}#ft(t){const e={...this.#ht};return Object.entries(t).forEach((([t,r])=>{this.#ht[r]?(e[t]=this.#ht[r],delete this.#ht[r]):e[t]=r})),e}} | ||
*/const Xt=Symbol("IsValue");function Yt(t){return("object"==typeof t||"function"==typeof t)&&void 0!==t[Xt]}const Zt=t=>{if("array"===t.type){t.items??={};const r=(e=t.items,Array.isArray(e)?t.items[0]:t.items);return r.type??="object",r}var e;return t};class te extends Vt{#pt;#tt;#ht;#lt;#dt;constructor(t,e,r,s=!1,n={}){super(),this.#pt=t,this.#tt=e,this.#ht="string"==typeof r?{[r]:r}:r,this[Xt]=this,this.#lt=s,this.#dt=n}then(t,e){if(1!==Object.keys(this.#ht).length)throw Error("Can't `await` for multiple values");return this.#pt.then((e=>e&&t&&this.#tt.asScopeFor(t)(e[Object.keys(this.#ht)[0]])),e&&this.#tt.asScopeFor(e))}asNodeInput(){return[this.#pt.unProxy(),this.#ht,this.#lt,this.#dt]}to(t,e){const r=re(t)?t.unProxy():new ee(t,this.#tt,e);return r.addInputsFromNode(this.#pt,this.#ht,this.#lt,this.#dt),r.asProxy()}in(t){let e=Object.fromEntries(Object.entries(this.#ht).map((([t,e])=>[e,t])));Yt(t)?(e=t.#ft(e),this.#pt.addInputsFromNode(t.#pt,e,t.#lt,t.#dt)):re(t)?this.#pt.addInputsFromNode(t.unProxy(),e):this.#pt.addInputsAsValues(t)}as(t){let e;if("string"==typeof t){if(1!==Object.keys(this.#ht).length)throw new Error("Can't rename multiple values with a single string");e={[Object.keys(this.#ht)[0]]:t}}else e=this.#ft(t);return new te(this.#pt,this.#tt,e,this.#lt,this.#dt)}memoize(){return new te(this.#pt,this.#tt,this.#ht,!0,this.#dt)}invoke(t){return new ee("invoke",this.#tt,{...t,$board:this}).asProxy()}isUnknown(){return delete this.#dt.type,this}isString(){return this.#dt.type="string",this}isNumber(){return this.#dt.type="number",this}isBoolean(){return this.#dt.type="boolean",this}isArray(){return this.#dt.type="array",this}isObject(){return this.#dt.type="object",this}title(t){return this.#dt.title=t,this}description(t){return this.#dt.description=t,this}format(t){return Zt(this.#dt).format=t,this}examples(...t){return this.#dt.examples=t,this}default(t){return this.#dt.default=t,this}optional(){return this.#dt.$optional=!0,this}behavior(...t){const e=Zt(this.#dt);return e.behavior??=[],e.behavior.push(...t),this}#ft(t){const e={...this.#ht};return Object.entries(t).forEach((([t,r])=>{this.#ht[r]?(e[t]=this.#ht[r],delete this.#ht[r]):e[t]=r})),e}} | ||
/** | ||
@@ -246,3 +246,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/class te extends Gt{#wt;#yt;#mt;#tt;#Z;constructor(t,e,r={}){const s=!ee(r)&&!(r instanceof Lt)&&!se(r)&&!Xt(r)&&r.$id;if(super(t,e,s?{$id:s}:{}),this.#tt=e,"string"!=typeof t&&(this.#Z=t),ee(r))this.addInputsFromNode(r.unProxy());else if(r instanceof Lt)this.addInputsFromNode(r);else if(se(r))this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()});else if(Xt(r))this.addInputsFromNode(...r.asNodeInput());else{void 0!==r.$id&&delete r.$id;const t=r.$metadata;void 0!==t&&(this.metadata=t,delete r.$metadata),this.addInputsAsValues(r)}this[this.#gt()]=this,this.#wt=new Promise(((t,e)=>{this.#yt=t,this.#mt=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{se(s)&&(s=s.getBoardCapabilityAsValue()),Xt(s)?r.push(s.as(t).asNodeInput()):s instanceof Lt||ee(s)?r.push([ee(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(ee(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const i=t.#tt;if(i!==this.#tt){for(let t=this.#tt;t!==i;t=t.parentLexicalScope)if(!t)throw new Error("Only wires from parent scopes allowed");if("*"===e||""===e)throw new Error("Can't use * or empty wires from parent scopes");this.#tt.addClosureEdge({scope:i,from:t,to:this,out:e,in:r})}else super.addIncomingEdge(t,e,r,s,n)}async invoke(t,e){const r=new zt({dynamicScope:e,lexicalScope:this.#tt});return r.asScopeFor((async()=>{try{const e=this.#Z??r.getHandler(this.type);let s;const n=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(n)s=await n(t,this);else{if(!e||"function"==typeof e||!e.graph)throw new Error(`Can't find handler for ${this.id}`);{const n=e.graph.getPinnedNodes();if(1!==n.length)throw new Error("Expected exactly one graph");s=await r.invokeOneRound(t,n[0])}}for(const[t,e]of Object.entries(s))e instanceof te?s[t]=(await e)[t]:Xt(e)?s[t]=await e:se(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#yt&&(this.#yt(s),this.#yt=this.#mt=void 0),s}catch(t){throw this.#mt&&(this.#mt(t),this.#yt=this.#mt=void 0),t}}))()}async serializeNode(){for(const[t,e]of Object.entries(this.configuration))e instanceof Promise&&(this.configuration[t]=await e);if("fn"!==this.type)return super.serializeNode();const t=new zt({lexicalScope:this.#tt,serialize:!0}),e=this.#Z??t.getHandler(this.type);if(e&&"function"!=typeof e&&e.graph){const r={id:this.id,type:"invoke",configuration:{...this.configuration,path:"#"+this.id}},s=e.graph.getPinnedNodes();if(1!==s.length)throw new Error("Expected exactly one graph");return[r,await t.serialize({},s[0])]}{const t=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(!t)throw new Error(`Handler for ${this.type} in ${this.id} not found`);const r=this.id.replace(/-/g,"_"),[s,n]=((t,e)=>{let r=e.toString();const s=/(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*\{/;if(/(?:async\s*)?(\w+|\([^)]*\))\s*=>\s*/.test(r))r=`const ${t} = ${r};`;else{const e=s.exec(r);if(null===e)throw new Error("Unexpected serialization: "+r);t=e[1]||t}return[r,t]})(r,t);return[{id:this.id,type:"runJavascript",configuration:{...this.configuration,code:s,name:n,raw:!0},metadata:this.metadata}]}}asProxy(){return new Proxy(this,{get(t,e,r){if("string"==typeof e){const r=new Zt(t,t.#tt,e);let s=t[e];return s=s&&"function"==typeof s?s.bind(t):(t=>r.invoke(t)).bind(r),new Proxy(s,{get(t,e,s){const n=Reflect.get(r,e,r);return"function"==typeof n?n.bind(r):n},ownKeys:t=>Reflect.ownKeys(r).filter((t=>"string"==typeof t))})}return Reflect.get(t,e,r)},ownKeys:t=>[t.#gt()]})}unProxy(){return this}then(t,e){if(this.#tt.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.#tt.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#tt.asScopeFor(e));throw t})),this.#wt.then(t&&this.#tt.asScopeFor(t),e&&this.#tt.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#tt.asScopeFor(e));throw t}}to(t,e){const r=ee(t)?t.unProxy():new te(t,this.#tt,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof Gt?this.addInputsFromNode(t):Xt(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new Zt(this,this.#tt,t)}keys(){return[this.#gt()]}#gt(){return"*-"+this.id}}function ee(t){return"function"==typeof t.unProxy} | ||
*/class ee extends Bt{#wt;#yt;#mt;#tt;#Z;constructor(t,e,r={}){const s=!re(r)&&!(r instanceof Wt)&&!ne(r)&&!Yt(r)&&r.$id;if(super(t,e,s?{$id:s}:{}),this.#tt=e,"string"!=typeof t&&(this.#Z=t),re(r))this.addInputsFromNode(r.unProxy());else if(r instanceof Wt)this.addInputsFromNode(r);else if(ne(r))this.addInputsAsValues({$board:r.getBoardCapabilityAsValue()});else if(Yt(r))this.addInputsFromNode(...r.asNodeInput());else{void 0!==r.$id&&delete r.$id;const t=r.$metadata;void 0!==t&&(this.metadata=t,delete r.$metadata),this.addInputsAsValues(r)}this[this.#gt()]=this,this.#wt=new Promise(((t,e)=>{this.#yt=t,this.#mt=e}))}addInputsAsValues(t){const e={},r=[];Object.entries(t).forEach((([t,s])=>{ne(s)&&(s=s.getBoardCapabilityAsValue()),Yt(s)?r.push(s.as(t).asNodeInput()):s instanceof Wt||re(s)?r.push([re(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(re(t)?t.unProxy():t,e,n,r,s)}))}addIncomingEdge(t,e,r,s,n){const i=t.#tt;if(i!==this.#tt){for(let t=this.#tt;t!==i;t=t.parentLexicalScope)if(!t)throw new Error("Only wires from parent scopes allowed");if("*"===e||""===e)throw new Error("Can't use * or empty wires from parent scopes");this.#tt.addClosureEdge({scope:i,from:t,to:this,out:e,in:r})}else super.addIncomingEdge(t,e,r,s,n)}async invoke(t,e){const r=new Jt({dynamicScope:e,lexicalScope:this.#tt});return r.asScopeFor((async()=>{try{const e=this.#Z??r.getHandler(this.type);let s;const n=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(n)s=await n(t,this);else{if(!e||"function"==typeof e||!e.graph)throw new Error(`Can't find handler for ${this.id}`);{const n=e.graph.getPinnedNodes();if(1!==n.length)throw new Error("Expected exactly one graph");s=await r.invokeOneRound(t,n[0])}}for(const[t,e]of Object.entries(s))e instanceof ee?s[t]=(await e)[t]:Yt(e)?s[t]=await e:ne(e)&&(s[t]=await e.getBoardCapabilityAsValue());return this.#yt&&(this.#yt(s),this.#yt=this.#mt=void 0),s}catch(t){throw this.#mt&&(this.#mt(t),this.#yt=this.#mt=void 0),t}}))()}async serializeNode(){for(const[t,e]of Object.entries(this.configuration))e instanceof Promise&&(this.configuration[t]=await e);if("fn"!==this.type)return super.serializeNode();const t=new Jt({lexicalScope:this.#tt,serialize:!0}),e=this.#Z??t.getHandler(this.type);if(e&&"function"!=typeof e&&e.graph){const r={id:this.id,type:"invoke",configuration:{...this.configuration,path:"#"+this.id}},s=e.graph.getPinnedNodes();if(1!==s.length)throw new Error("Expected exactly one graph");return[r,await t.serialize({},s[0])]}{const t=e&&"invoke"in e&&e.invoke?e.invoke:"function"==typeof e?e:void 0;if(!t)throw new Error(`Handler for ${this.type} in ${this.id} not found`);const r=this.id.replace(/-/g,"_"),[s,n]=((t,e)=>{let r=e.toString();const s=/(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*\{/;if(/(?:async\s*)?(\w+|\([^)]*\))\s*=>\s*/.test(r))r=`const ${t} = ${r};`;else{const e=s.exec(r);if(null===e)throw new Error("Unexpected serialization: "+r);t=e[1]||t}return[r,t]})(r,t);return[{id:this.id,type:"runJavascript",configuration:{...this.configuration,code:s,name:n,raw:!0},metadata:this.metadata}]}}asProxy(){return new Proxy(this,{get(t,e,r){if("string"==typeof e){const r=new te(t,t.#tt,e);let s=t[e];return s=s&&"function"==typeof s?s.bind(t):(t=>r.invoke(t)).bind(r),new Proxy(s,{get(t,e,s){const n=Reflect.get(r,e,r);return"function"==typeof n?n.bind(r):n},ownKeys:t=>Reflect.ownKeys(r).filter((t=>"string"==typeof t))})}return Reflect.get(t,e,r)},ownKeys:t=>[t.#gt()]})}unProxy(){return this}then(t,e){if(this.#tt.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.#tt.invoke(this).catch((t=>{if(e)return Promise.reject(t).catch(this.#tt.asScopeFor(e));throw t})),this.#wt.then(t&&this.#tt.asScopeFor(t),e&&this.#tt.asScopeFor(e))}catch(t){if(e)return Promise.reject(t).catch(this.#tt.asScopeFor(e));throw t}}to(t,e){const r=re(t)?t.unProxy():new ee(t,this.#tt,e);return r.addInputsFromNode(this,{"*":""}),r.asProxy()}in(t){return t instanceof Bt?this.addInputsFromNode(t):Yt(t)?this.addInputsFromNode(...t.asNodeInput()):this.addInputsAsValues(t),this.asProxy()}as(t){return new te(this,this.#tt,t)}keys(){return[this.#gt()]}#gt(){return"*-"+this.id}}function re(t){return"function"==typeof t.unProxy} | ||
/** | ||
@@ -252,3 +252,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/function re(t,e){return t&&function(t,e){_t().addHandlers({[t]:e})} | ||
*/function se(t,e){return t&&function(t,e){Kt().addHandlers({[t]:e})} | ||
/** | ||
@@ -258,3 +258,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/(t,e),r=>new te(t??e,_t(),r).asProxy()}function se(t){return"function"==typeof t&&"function"==typeof t.getBoardCapabilityAsValue} | ||
*/(t,e),r=>new ee(t??e,Kt(),r).asProxy()}function ne(t){return"function"==typeof t&&"function"==typeof t.getBoardCapabilityAsValue} | ||
/** | ||
@@ -264,3 +264,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const ne=async()=>{throw new Error("Reserved word handler should never be invoked")}; | ||
*/const ie=async()=>{throw new Error("Reserved word handler should never be invoked")}; | ||
/** | ||
@@ -271,3 +271,3 @@ * @license | ||
*/ | ||
var ie,ae;re("input",ne),re("output",ne),function(t){t.Ordinary="ordinary",t.Constant="constant",t.Control="control",t.Star="star"}(ie||(ie={})),function(t){t.Indeterminate="indeterminate",t.Connected="connected",t.Ready="ready",t.Missing="missing",t.Dangling="dangling"}(ae||(ae={})); | ||
var oe,ae;se("input",ie),se("output",ie),function(t){t.Ordinary="ordinary",t.Constant="constant",t.Control="control",t.Star="star"}(oe||(oe={})),function(t){t.Indeterminate="indeterminate",t.Connected="connected",t.Ready="ready",t.Missing="missing",t.Dangling="dangling"}(ae||(ae={})); | ||
/** | ||
@@ -278,3 +278,3 @@ * @license | ||
*/ | ||
class oe{#bt=null;#vt=new Map;createGroup(t){let e=this.#vt.get(t);if(e)throw new Error(`Group with ID already exists: ${t}`);e=new Map,this.#vt.set(t,e),this.#bt=t}async store(t,e){if(e??=this.#bt??void 0,!e)throw new Error("No active group - unable to store blob");const r=this.#vt.get(e);if(!r)throw new Error(`No group in data store with ID: ${e}`);const s=await U(t),n=Date.now().toFixed(3);let i=r.get(n);return i||(i=new Map,r.set(n,i)),i.set(`direct-set-${n}`,new Map([[0,new Map([[0,s]])]])),s}async retrieveAsBlob(t){return async function(t){if(!A(t))throw new Error("Invalid stored data");const{handle:e}=t.storedData,r=await fetch(e);return await r.blob()}(t)}async replaceDataParts(t,e){if("nodeend"!==e.type||"input"!==e.data.node.type)return;const r=this.#vt.get(t);if(!r)throw new Error(`Unable to replace data parts, no group created for ${t}`);const s=e.data.timestamp.toFixed(3);let n=r.get(s);n||(n=new Map,r.set(s,n));for(const[t,r]of Object.entries(e.data.outputs)){if(!(q(r)||(i=r,"object"==typeof i&&i&&Array.isArray(i)&&(i=i.filter((t=>"$metadata"!==t.role)),Array.isArray(i)&&i.every((t=>q(t)))))))continue;const e=q(r)?[r]:r;let s=n.get(t);s||(s=new Map,n.set(t,s));for(let t=0;t<e.length;t++){const r=e[t];if(!T(r))for(let e=0;e<r.parts.length;e++){const n=r.parts[e];if(C(n)){let i=s.get(0);i||(i=new Map,s.set(t,i));let a=i.get(e);a||(a=await U(n)),r.parts[e]=a,i.set(e,a)}else if(A(n)){let i=s.get(0);i||(i=new Map,s.set(t,i));const a=await U(n);r.parts[e]=a,i.set(e,a)}}}}var i}has(t){return this.#vt.has(t)}async serializeGroup(t){const e=this.#vt.get(t);if(!e)return null;let r=[];for(const t of e.values())for(const e of t.values())for(const t of e.values()){r=[...t.values()].map((async t=>{const{handle:e}=t.storedData,r=await fetch(e),s=await r.blob();return{handle:e,inlineData:{mimeType:s.type,data:await M(s)}}}))}return Promise.all(r)}releaseGroup(t){const e=this.#vt.get(t);if(e){for(const t of e.values())for(const e of t.values())for(const t of e.values())for(const e of t.values())URL.revokeObjectURL(e.storedData.handle);this.#vt.delete(t),this.#bt===t&&(this.#bt=null)}}releaseAll(){for(const t of this.#vt.keys())this.releaseGroup(t);this.#bt=null}async drop(){this.releaseAll(),this.#vt.clear()}} | ||
class ce{#bt=null;#vt=new Map;createGroup(t){let e=this.#vt.get(t);if(e)throw new Error(`Group with ID already exists: ${t}`);e=new Map,this.#vt.set(t,e),this.#bt=t}async store(t,e){if(e??=this.#bt??void 0,!e)throw new Error("No active group - unable to store blob");const r=this.#vt.get(e);if(!r)throw new Error(`No group in data store with ID: ${e}`);const s=await U(t),n=Date.now().toFixed(3);let i=r.get(n);return i||(i=new Map,r.set(n,i)),i.set(`direct-set-${n}`,new Map([[0,new Map([[0,s]])]])),s}async retrieveAsBlob(t){return async function(t){if(!A(t))throw new Error("Invalid stored data");const{handle:e}=t.storedData,r=await fetch(e);return await r.blob()}(t)}async replaceDataParts(t,e){if("nodeend"!==e.type||"input"!==e.data.node.type)return;const r=this.#vt.get(t);if(!r)throw new Error(`Unable to replace data parts, no group created for ${t}`);const s=e.data.timestamp.toFixed(3);let n=r.get(s);n||(n=new Map,r.set(s,n));for(const[t,r]of Object.entries(e.data.outputs)){if(!(q(r)||(i=r,"object"==typeof i&&i&&Array.isArray(i)&&(i=i.filter((t=>"$metadata"!==t.role)),Array.isArray(i)&&i.every((t=>q(t)))))))continue;const e=q(r)?[r]:r;let s=n.get(t);s||(s=new Map,n.set(t,s));for(let t=0;t<e.length;t++){const r=e[t];if(!T(r))for(let e=0;e<r.parts.length;e++){const n=r.parts[e];if(C(n)){let i=s.get(0);i||(i=new Map,s.set(t,i));let o=i.get(e);o||(o=await U(n)),r.parts[e]=o,i.set(e,o)}else if(A(n)){let i=s.get(0);i||(i=new Map,s.set(t,i));const o=await U(n);r.parts[e]=o,i.set(e,o)}}}}var i}has(t){return this.#vt.has(t)}async serializeGroup(t){const e=this.#vt.get(t);if(!e)return null;let r=[];for(const t of e.values())for(const e of t.values())for(const t of e.values()){r=[...t.values()].map((async t=>{const{handle:e}=t.storedData,r=await fetch(e),s=await r.blob();return{handle:e,inlineData:{mimeType:s.type,data:await M(s)}}}))}return Promise.all(r)}releaseGroup(t){const e=this.#vt.get(t);if(e){for(const t of e.values())for(const e of t.values())for(const t of e.values())for(const e of t.values())URL.revokeObjectURL(e.storedData.handle);this.#vt.delete(t),this.#bt===t&&(this.#bt=null)}}releaseAll(){for(const t of this.#vt.keys())this.releaseGroup(t);this.#bt=null}async drop(){this.releaseAll(),this.#vt.clear()}} | ||
/** | ||
@@ -284,3 +284,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const ce=()=>new oe,ue=t=>new bt([]); | ||
*/const ue=()=>new ce,pe=t=>new vt([]); | ||
/** | ||
@@ -296,3 +296,3 @@ * @license | ||
*/ | ||
var pe;!function(t){t[t.In=0]="In",t[t.Out=1]="Out"}(pe||(pe={})); | ||
var he;!function(t){t[t.In=0]="In",t[t.Out=1]="Out"}(he||(he={})); | ||
/** | ||
@@ -303,3 +303,3 @@ * @license | ||
*/ | ||
const he=t=>{const e=(()=>{if("nodestart"===t.type)return t.state})(),r=structuredClone(t.data);return{type:t.type,data:r,state:e,reply:async()=>{}}},le=t=>{const{type:e,node:r,timestamp:s,invocationId:n}=t,i=-1==n,a=async()=>{const r=t.runState;return r||[{url:void 0,path:[n],state:Q(e,t.state)}]};if("input"===e){const{inputArguments:n,path:o}=t;return{type:e,data:{node:r,inputArguments:n,path:o,bubbled:i,timestamp:s},reply:async e=>{t.inputs=e.inputs},saveState:a}}if("output"===e){const{outputs:n,path:o}=t;return{type:e,data:{node:r,outputs:n,path:o,timestamp:s,bubbled:i},reply:async()=>{},saveState:a}}throw new Error(`Unknown result type "${e}".`)},de=t=>({type:"end",data:{timestamp:j(),last:t},reply:async()=>{}}),fe=t=>({type:"error",data:{error:t,timestamp:j()},reply:async()=>{}}),we=(t,e)=>{const{type:r,data:s}=t;return"skip"===r?{node:s.node,missing:s.missingInputs}:e},ye=(t,e)=>{const{type:r,node:s}=t;return"output"===r||"input"===r?{node:s,missing:[]}:e},me=async t=>{const e=(t=>t.base?t.base:"window"in globalThis?new URL(self.location.href):yt)(t),r=t.loader||ue(),s=await r.load(t.url,{base:e});if(!s)throw new Error(`Unable to load graph from "${t.url}"`);return s}; | ||
const le=t=>{const e=(()=>{if("nodestart"===t.type)return t.state})(),r=structuredClone(t.data);return{type:t.type,data:r,state:e,reply:async()=>{}}},de=t=>{const{type:e,node:r,timestamp:s,invocationId:n}=t,i=-1==n,o=async()=>{const r=t.runState;return r||[{url:void 0,path:[n],state:V(e,t.state)}]};if("input"===e){const{inputArguments:n,path:a}=t;return{type:e,data:{node:r,inputArguments:n,path:a,bubbled:i,timestamp:s},reply:async e=>{t.inputs=e.inputs},saveState:o}}if("output"===e){const{outputs:n,path:a}=t;return{type:e,data:{node:r,outputs:n,path:a,timestamp:s,bubbled:i},reply:async()=>{},saveState:o}}throw new Error(`Unknown result type "${e}".`)},fe=t=>({type:"end",data:{timestamp:j(),last:t},reply:async()=>{}}),we=t=>({type:"error",data:{error:t,timestamp:j()},reply:async()=>{}}),ye=(t,e)=>{const{type:r,data:s}=t;return"skip"===r?{node:s.node,missing:s.missingInputs}:e},me=(t,e)=>{const{type:r,node:s}=t;return"output"===r||"input"===r?{node:s,missing:[]}:e},ge=async t=>{const e=(t=>t.base?t.base:"window"in globalThis?new URL(self.location.href):mt)(t),r=t.loader||pe(),s=await r.load(t.url,{base:e});if(!s)throw new Error(`Unable to load graph from "${t.url}"`);return s}; | ||
/** | ||
@@ -315,14 +315,8 @@ * @license | ||
*/ | ||
const ge=t=>{const e=new b({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:j()},reply:async t=>{s=t.inputs}}),s}});return g(e)},be=t=>{const e=new URL(t,location.href),r=new Blob([`import "${e}";`],{type:"text/javascript"}),s=URL.createObjectURL(r);return new Worker(s,{type:"module"})}; | ||
const be=t=>{const e=[];for(const r of t)for(const[t,s]of Object.entries(r.handlers))"secrets"===t&&e.push(s);return e},ve=(t,e)=>{const r=(t=>async e=>{const{keys:r}=e;if(!r)return{};let s={};return await t({type:"secret",data:{keys:r,timestamp:j()},reply:async t=>{s=t.inputs}}),s})(t),s=e?(n="secrets",i=[...e,r],async(t,e)=>{for(const r of i){const s=await y(r,t,e);if(s&&!s.$error)return s}throw new Error(`No handler found for type "${n}"`)}):r;var n,i;const o=new b({url:"secret-asking-kit"}).build({secrets:s});return g(o)},Se=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"})};async function*ke(t){if(t.remote){if("worker"!==t.remote.type)throw new Error(`Unsupported harness configuration: ${JSON.stringify(t,null,2)}`);{const e=t.remote&&t.remote.url;if(!e)throw new Error("Worker harness requires a worker URL");yield*async function*(t,e,r){const s=Se(t),n=new d(s),i=new Dt(new f(n.send("load"))),o=new W(new w(n.receive("proxy"))),a=new Mt(new f(n.send("run")));await i.load(e.url),yield*jt((async t=>{const s=[ve(t),...e.kits],n=e.proxy?.[0];let i;n&&"function"!=typeof n&&(i=n.nodes),o.serve({kits:s,proxy:i});for await(const e of a.run(r))await t(e)}))} | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
const ve=async t=>{if(!t.proxy)return t.kits;const e=[];for(const r of t.proxy)if("function"==typeof r){if(!await r())continue;e.push(await r())}else switch(r.location){case"http":{if(!r.url)throw new Error("No node proxy server URL provided.");const t=new W(new h(r.url));e.push(t.createProxyKit(r.nodes));break}default:throw new Error("Only HTTP node proxy server is supported at this time.")}return[...e,...t.kits]};async function*Se(t){if(t.remote){if("worker"!==t.remote.type)throw new Error(`Unsupported harness configuration: ${JSON.stringify(t,null,2)}`);{const e=t.remote&&t.remote.url;if(!e)throw new Error("Worker harness requires a worker URL");yield*async function*(t,e,r){const s=be(t),n=new d(s),i=new Ut(new f(n.send("load"))),a=new L(new w(n.receive("proxy"))),o=new Ct(new f(n.send("run")));await i.load(e.url),yield*Nt((async t=>{const s=[ge(t),...e.kits],n=e.proxy?.[0];let i;n&&"function"!=typeof n&&(i=n.nodes),a.serve({kits:s,proxy:i});for await(const e of o.run(r))await t(e)}))}(e,t)}}else yield*Nt((async e=>{const r=[...t.interactiveSecrets?[ge(e)]:[],...await ve(t)];for await(const s of async function*(t,e){yield*Nt((async r=>{const s=t.runner||await me(t),n=t.loader||ue(),i=t.store||ce(),{base:a,signal:o,inputs:c,state:u,start:p}=t;try{let h;const l=t.diagnostics?new G((async t=>{h=we(t,h),await r(he(t))})):void 0;for await(const t of qt(s,{probe:l,kits:e,loader:n,store:i,base:a,signal:o,inputs:c,state:u,start:p}))h=ye(t,h),await r(le(t));await r(de(h))}catch(t){const e=B(t);console.error("Local Run error:",e),await r(fe(e))}}))}(t,r))await e(s)}))} | ||
*/(e,t)}}else yield*jt((async e=>{const r=((t,e,r)=>!0===t?[ve(r),...e]:"fallback"===t?[ve(r,be(e)),...e]:e)(t.interactiveSecrets,await(async t=>{if(!t.proxy)return t.kits;const e=[];for(const r of t.proxy)if("function"==typeof r){if(!await r())continue;e.push(await r())}else switch(r.location){case"http":{if(!r.url)throw new Error("No node proxy server URL provided.");const t=new G(new h(r.url));e.push(t.createProxyKit(r.nodes));break}default:throw new Error("Only HTTP node proxy server is supported at this time.")}return[...e,...t.kits]})(t),e);for await(const s of async function*(t,e){yield*jt((async r=>{const s=t.runner||await ge(t),n=t.loader||pe(),i=t.store||ue(),{base:o,signal:a,inputs:c,state:u,start:p}=t;try{let h;const l=t.diagnostics?new B((async t=>{h=ye(t,h),await r(le(t))})):void 0;for await(const t of Tt(s,{probe:l,kits:e,loader:n,store:i,base:o,signal:a,inputs:c,state:u,start:p}))h=me(t,h),await r(de(t));await r(fe(h))}catch(t){const e=H(t);console.error("Local Run error:",e),await r(we(e))}}))}(t,r))await e(s)}))} | ||
/** | ||
@@ -332,3 +326,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/function ke(t,...e){const r={...t};for(const t of e)delete r[t];return r}function Ee(t){const e={...t.node};return delete e.configuration,{...t,node:e}}function Oe(t){const e={...t};return delete e.inputs,delete e.outputs,e}class xe{#t;#St;constructor(t,e){this.#t=t,this.#St=e}#kt(t){return"top"===this.#St&&t>1}async writeGraphStart(t){this.#kt(t.path.length+1)||await this.#t.write(["graphstart",ke(t,"graph")])}async writeGraphEnd(t){this.#kt(t.path.length+1)||await this.#t.write(["graphend",t])}async writeNodeStart(t){this.#kt(t.path.length)||await this.#t.write(["nodestart",Ee(ke(t,"inputs"))])}async writeNodeEnd(t){this.#kt(t.path.length)||await this.#t.write(["nodeend",Oe(Ee(t))])}async writeSkip(t){}async writeEdge(t){!0===this.#St&&await this.#t.write(["edge",t])}async writeInput(t,e){await this.#t.write(["input",t,e])}async writeOutput(t){await this.#t.write(["output",t])}async writeError(t){await this.#t.write(["error",{error:H(t.error),timestamp:j()}])}async writeEnd(t){this.#St&&await this.#t.write(["end",t])}} | ||
*/function Ee(t,...e){const r={...t};for(const t of e)delete r[t];return r}function Oe(t){const e={...t.node};return delete e.configuration,{...t,node:e}}function xe(t){const e={...t};return delete e.inputs,delete e.outputs,e}class $e{#t;#St;constructor(t,e){this.#t=t,this.#St=e}#kt(t){return"top"===this.#St&&t>1}async writeGraphStart(t){this.#kt(t.path.length+1)||await this.#t.write(["graphstart",Ee(t,"graph")])}async writeGraphEnd(t){this.#kt(t.path.length+1)||await this.#t.write(["graphend",t])}async writeNodeStart(t){this.#kt(t.path.length)||await this.#t.write(["nodestart",Oe(Ee(t,"inputs"))])}async writeNodeEnd(t){this.#kt(t.path.length)||await this.#t.write(["nodeend",xe(Oe(t))])}async writeSkip(t){}async writeEdge(t){!0===this.#St&&await this.#t.write(["edge",t])}async writeInput(t,e){await this.#t.write(["input",t,e])}async writeOutput(t){await this.#t.write(["output",t])}async writeError(t){await this.#t.write(["error",{error:z(t.error),timestamp:j()}])}async writeEnd(t){this.#St&&await this.#t.write(["end",t])}} | ||
/** | ||
@@ -338,3 +332,3 @@ * @license | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/const $e=async(t,e)=>{const{url:r,kits:s,writer:n,loader:i,dataStore:a,stateStore:o,inputs:c,graph:u}=e,{next:p,inputs:h,diagnostics:l=!1}=t;let d=p?void 0:h;const f=await(o?.load(p)),w=st(f,h),y=Se({runner:u,url:r,kits:s,loader:i,store:a,inputs:c,interactiveSecrets:!1,diagnostics:l,state:w}),m=new xe(n,l);for await(const t of y){const{type:e,data:r,reply:s}=t;switch(e){case"graphstart":await m.writeGraphStart(r);break;case"graphend":await m.writeGraphEnd(r);break;case"nodestart":await m.writeNodeStart(r);break;case"nodeend":await m.writeNodeEnd(r);break;case"skip":await m.writeSkip(r);break;case"edge":await m.writeEdge(r);break;case"input":if(d&&Object.keys(d).length>0){await s({inputs:d}),d=void 0;break}{const t=w.lifecycle().reanimationState(),e=await o.save(t);return await m.writeInput(r,e),void await n.close()}case"output":{const t=await D(a,r.outputs);await m.writeOutput({...r,outputs:t});break}case"error":return await m.writeError(r),void await n.close();case"end":return await m.writeEnd(r),void await n.close();default:console.log("Unknown type",e,r)}}await n.write(["error",{error:"Run completed without signaling end or error.",timestamp:j()}])};export{h as HTTPClientTransport,p as HTTPServerTransport,Ut as InitClient,Mt as InitServer,d as PortDispatcher,W as ProxyClient,L as ProxyServer,Ct as RunClient,Tt as RunServer,f as WorkerClientTransport,w as WorkerServerTransport,Dt as defineConfig,$e as handleRunGraphRequest,Ft as hasOrigin}; | ||
*/const Pe=async(t,e)=>{const{url:r,kits:s,writer:n,loader:i,dataStore:o,stateStore:a,inputs:c,graph:u}=e,{next:p,inputs:h,diagnostics:l=!1}=t;let d=p?void 0:h;const f=await(a?.load(p)),w=nt(f,h),y=ke({runner:u,url:r,kits:s,loader:i,store:o,inputs:c,interactiveSecrets:!1,diagnostics:l,state:w}),m=new $e(n,l);for await(const t of y){const{type:e,data:r,reply:s}=t;switch(e){case"graphstart":await m.writeGraphStart(r);break;case"graphend":await m.writeGraphEnd(r);break;case"nodestart":await m.writeNodeStart(r);break;case"nodeend":await m.writeNodeEnd(r);break;case"skip":await m.writeSkip(r);break;case"edge":await m.writeEdge(r);break;case"input":if(d&&Object.keys(d).length>0){await s({inputs:d}),d=void 0;break}{const t=w.lifecycle().reanimationState(),e=await a.save(t);return await m.writeInput(r,e),void await n.close()}case"output":{const t=await D(o,r.outputs);await m.writeOutput({...r,outputs:t});break}case"error":return await m.writeError(r),void await n.close();case"end":return await m.writeEnd(r),void await n.close();default:console.log("Unknown type",e,r)}}await n.write(["error",{error:"Run completed without signaling end or error.",timestamp:j()}])};export{h as HTTPClientTransport,p as HTTPServerTransport,Dt as InitClient,Ut as InitServer,d as PortDispatcher,G as ProxyClient,W as ProxyServer,Mt as RunClient,At as RunServer,f as WorkerClientTransport,w as WorkerServerTransport,Ft as defineConfig,Pe as handleRunGraphRequest,Lt as hasOrigin}; | ||
//# sourceMappingURL=remote.min.js.map |
@@ -10,3 +10,3 @@ /** | ||
import { runLocally } from "./local.js"; | ||
import { createSecretAskingKit } from "./secrets.js"; | ||
import { configureSecretAsking } from "./secrets.js"; | ||
import { runInWorker } from "./worker.js"; | ||
@@ -46,6 +46,3 @@ const configureKits = async (config) => { | ||
yield* asyncGen(async (next) => { | ||
const secretAskingKit = config.interactiveSecrets | ||
? [createSecretAskingKit(next)] | ||
: []; | ||
const kits = [...secretAskingKit, ...(await configureKits(config))]; | ||
const kits = configureSecretAsking(config.interactiveSecrets, await configureKits(config), next); | ||
for await (const data of runLocally(config, kits)) { | ||
@@ -52,0 +49,0 @@ await next(data); |
@@ -6,5 +6,7 @@ /** | ||
*/ | ||
import { SecretResult } from "./types.js"; | ||
import { ClientRunResult } from "../remote/types.js"; | ||
export declare const createSecretAskingKit: (next: (result: ClientRunResult<SecretResult>) => Promise<void>) => import("../types.js").Kit; | ||
import type { HarnessRunResult, RunConfig, SecretResult } from "./types.js"; | ||
import type { Kit, NodeHandler } from "../types.js"; | ||
import type { ClientRunResult } from "../remote/types.js"; | ||
export declare const configureSecretAsking: (interactiveSecrets: RunConfig["interactiveSecrets"], existingKits: Kit[], next: (data: HarnessRunResult) => Promise<void>) => Kit[]; | ||
export declare const createSecretAskingKit: (next: (result: ClientRunResult<SecretResult>) => Promise<void>, fallback?: NodeHandler[]) => Kit; | ||
//# sourceMappingURL=secrets.d.ts.map |
@@ -8,24 +8,70 @@ /** | ||
import { timestamp } from "../timestamp.js"; | ||
import { asRuntimeKit } from "../index.js"; | ||
export const createSecretAskingKit = (next) => { | ||
import { asRuntimeKit, callHandler } from "../index.js"; | ||
/** | ||
* Get all secret handlers from the given kits. | ||
* This is used to create a fallback list for secret asking. | ||
*/ | ||
const secretHandlersFromKits = (kits) => { | ||
const secretHandlers = []; | ||
for (const kit of kits) { | ||
for (const [key, handler] of Object.entries(kit.handlers)) { | ||
if (key === "secrets") { | ||
secretHandlers.push(handler); | ||
} | ||
} | ||
} | ||
return secretHandlers; | ||
}; | ||
export const configureSecretAsking = (interactiveSecrets, existingKits, next) => { | ||
if (interactiveSecrets === true) { | ||
return [createSecretAskingKit(next), ...existingKits]; | ||
} | ||
else if (interactiveSecrets === "fallback") { | ||
return [ | ||
createSecretAskingKit(next, secretHandlersFromKits(existingKits)), | ||
...existingKits, | ||
]; | ||
} | ||
else { | ||
return existingKits; | ||
} | ||
}; | ||
const interactiveSecretsHandler = (next) => { | ||
return async (inputs) => { | ||
const { keys } = inputs; | ||
if (!keys) | ||
return {}; | ||
let outputs = {}; | ||
await next({ | ||
type: "secret", | ||
data: { keys, timestamp: timestamp() }, | ||
reply: async (value) => { | ||
outputs = value.inputs; | ||
}, | ||
}); | ||
return outputs; | ||
}; | ||
}; | ||
const fallbackHandler = (nodeType, handlers) => { | ||
const handler = async (inputs, context) => { | ||
for (const handler of handlers) { | ||
const outputs = await callHandler(handler, inputs, context); | ||
if (outputs && !outputs["$error"]) { | ||
return outputs; | ||
} | ||
} | ||
throw new Error(`No handler found for type "${nodeType}"`); | ||
}; | ||
return handler; | ||
}; | ||
export const createSecretAskingKit = (next, fallback) => { | ||
const interactive = interactiveSecretsHandler(next); | ||
const secrets = fallback | ||
? fallbackHandler("secrets", [...fallback, interactive]) | ||
: interactive; | ||
const secretAskingKit = new KitBuilder({ | ||
url: "secret-asking-kit", | ||
}).build({ | ||
secrets: async (inputs) => { | ||
const { keys } = inputs; | ||
if (!keys) | ||
return {}; | ||
let outputs = {}; | ||
await next({ | ||
type: "secret", | ||
data: { keys, timestamp: timestamp() }, | ||
reply: async (value) => { | ||
outputs = value.inputs; | ||
}, | ||
}); | ||
return outputs; | ||
}, | ||
}); | ||
}).build({ secrets }); | ||
return asRuntimeKit(secretAskingKit); | ||
}; | ||
//# sourceMappingURL=secrets.js.map |
@@ -159,4 +159,7 @@ /** | ||
* the secrets on its own. | ||
* | ||
* When set to `"fallback"`, the secrets will be asked for interactively | ||
* only if the secrets node is not able to find the secrets on its own. | ||
*/ | ||
interactiveSecrets?: boolean; | ||
interactiveSecrets?: boolean | "fallback"; | ||
/** | ||
@@ -163,0 +166,0 @@ * The data store to use for storing data. |
@@ -197,2 +197,7 @@ /** | ||
/** | ||
* Given the URL of a board, returns the URL of the node proxy server, if | ||
* this provider supports it. If it doesn't, returns `false`. | ||
*/ | ||
canProxy?: (url: URL) => Promise<string | false>; | ||
/** | ||
* Provides a way to watch for changes in the store. | ||
@@ -199,0 +204,0 @@ */ |
@@ -20,3 +20,3 @@ /** | ||
shutdownServer(): void; | ||
proxy(node: NodeDescriptor, inputs: InputValues, _context: NodeHandlerContext): Promise<OutputValues>; | ||
proxy(node: NodeDescriptor, inputs: InputValues, context: NodeHandlerContext): Promise<OutputValues>; | ||
createProxyKit(args?: NodeProxyConfig): import("../types.js").Kit; | ||
@@ -23,0 +23,0 @@ } |
@@ -27,2 +27,10 @@ /** | ||
}; | ||
const makeSerializable = (data) => { | ||
if (data["$error"]) { | ||
const error = data["$error"]; | ||
error.error = | ||
error.error instanceof Error ? error.error.message : error.error; | ||
} | ||
return data; | ||
}; | ||
export class ProxyServer { | ||
@@ -76,3 +84,3 @@ #transport; | ||
const outputs = store | ||
? (await inflateData(store, result)) | ||
? (await inflateData(store, makeSerializable(result))) | ||
: result; | ||
@@ -101,6 +109,10 @@ request.reply(["proxy", { outputs }]); | ||
} | ||
async proxy(node, inputs, _context) { | ||
async proxy(node, inputs, context) { | ||
const stream = this.#transport.createClientStream(); | ||
const writer = stream.writableRequests.getWriter(); | ||
const reader = stream.readableResponses.getReader(); | ||
const store = context.store; | ||
inputs = store | ||
? (await inflateData(store, inputs)) | ||
: inputs; | ||
writer.write(["proxy", { node, inputs }]); | ||
@@ -107,0 +119,0 @@ writer.close(); |
@@ -105,3 +105,3 @@ /** | ||
// adopt bad practices of hard-coding the values. | ||
// Note: the rotation will occasionaly cause errors at the break of the week. | ||
// Note: the rotation will occasionally cause errors at the break of the week. | ||
// TODO: Fix the rotation to be window-based or come up with an even better | ||
@@ -108,0 +108,0 @@ // solution. |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.25.0", | ||
"version": "0.26.0", | ||
"description": "A library for rapid generative AI application prototyping", | ||
@@ -105,5 +105,6 @@ "main": "./dist/src/index.js", | ||
}, | ||
"dependencies": [ | ||
"build:tsc" | ||
], | ||
"files": [ | ||
"src/**/*.ts", | ||
"tests/**/*.ts", | ||
".eslintrc", | ||
@@ -172,3 +173,3 @@ "../../.eslintrc.json" | ||
"jsonschema": "^1.4.1", | ||
"rollup": "^4.21.0", | ||
"rollup": "^4.21.1", | ||
"rollup-plugin-dts": "^6.1.1", | ||
@@ -175,0 +176,0 @@ "@rollup/plugin-json": "^6.1.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is 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
2754372
18826