promptgun 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -6
- package/build/index.d.ts +698 -26
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/package.json +4 -2
package/build/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=Object.create,e=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.getPrototypeOf,i={}.hasOwnProperty,o=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),a=(o,a,l)=>(l=null!=o?t(s(o)):{},((t,s,o,a)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let o of n(s))!i.call(t,o)&&void 0!==o&&e(t,o,{get:()=>s[o],enumerable:!(a=r(s,o))||a.enumerable});return t})(!a&&o&&o.t?l:e(l,"default",{value:o,enumerable:!0}),o)),l=o((t=>{"use strict";Object.defineProperty(t,"t",{value:!0}),t.Flux=void 0;var e=class t{generator;upstream;handleCancel;i=!1;constructor(t,e,n){let s=this;this.generator=async function*(){try{yield*t}catch(t){throw yield r,t}finally{s.i=!0}}(),this.upstream=e,this.handleCancel=n}[Symbol.asyncIterator](){return this}async next(...t){let e=await this.generator.next(t);return e.value!==r?e:await this.next(t)}return(t){return this.generator.return(t)}throw(t){return this.generator.throw(t)}async cancel(t){if(!this.closed){if(void 0!==this.upstream)return this.upstream.cancel(t);void 0!==this.handleCancel?this.handleCancel(t):await this.throw(t)}}async then(t,e){try{let e=await this.asList();return null!=t?await t(e):e}catch(t){if(null!=e)return e(t);throw t}}async catch(t){try{return this.asList()}catch(e){if(null!=t)return t(e);throw e}}async finally(t){let e=await this.asList();return t?.(),e}get[Symbol.toStringTag](){return"Flux"}subscribe(t){let e=void 0!==t?this.doOnEach(t):this,r=()=>{e.next().then((t=>{t.done||r()})).catch((t=>{console.error(t)}))};return r(),{unsubscribe:()=>this.return()}}filter(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)e(t)&&(yield t)}),this)}untilExcl(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r){if(e(t))break;yield t}}),this)}doOnEach(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)e(t),yield t}),this)}doAfterLast(e){let r=this,n=[];return t.constructFromGeneratorFunction((async function*(){for await(let t of r)n.push(t),yield t;await e(n)}),this)}map(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)yield e(t)}),this)}take(e){let r=this;return t.constructFromGeneratorFunction((async function*(){let t=0;for await(let n of r){if(t>=e){r.cancel();break}t++,yield n}}),this)}flatMap(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r){let r=e(t);if(Array.isArray(r))for(let t of r)yield t;else yield await r}}),this)}transform(e){let r=e(this);return t.constructFromGeneratorFunction((async function*(){for await(let t of r)yield t}),this)}async reduce(t,e){let r=e;for await(let e of this)r=t(r,e);return r}async asList(){let t=[];for await(let e of this)t.push(e);return t}async whenComplete(){for await(let t of this);}static create(e){let r,n=[],s=[],i=!1,o=()=>{for(i=!0;s.length>0;)s.shift().resolve({done:!0,value:void 0})};return e((t=>{if(i)throw Error("Cannot push to a completed generator");s.length>0?s.shift().resolve({done:!1,value:t}):n.push(t)}),o),t.fromGenerator({[Symbol.asyncIterator](){return this},next(...t){if(r){let t=r.value;return r=void 0,Promise.reject(t)}if(n.length>0){let t=n.shift();return Promise.resolve({done:!1,value:t})}return i?Promise.resolve({done:!0,value:void 0}):new Promise(((t,e)=>{s.push({resolve:t,reject:e})}))},return:()=>(o(),Promise.resolve({done:!0,value:void 0})),throw:t=>(r=t,s.length>0&&s.shift()?.reject(),Promise.reject(t))})}static fromArray(e){return t.fromGeneratorFunction((async function*(){for(let t of e)yield t}))}static constructFromGeneratorFunction(e,r,n){return new t(e(),r,n)}static fromGeneratorFunction(e,r){return t.constructFromGeneratorFunction(e,void 0,r)}static fromGenerator(e,r){return new t(e,void 0,r)}static fromReadableStream(e,r){return t.fromGeneratorFunction((async function*(){let t=e.getReader();try{let e;for(;!(e=await t.read()).done;)yield e.value}finally{await t.cancel()}}),r)}get closed(){return this.i}};t.Flux=e;var r={}})),u=o((t=>{"use strict";Object.defineProperty(t,"t",{value:!0}),t.Flux=void 0;var e=l();Object.defineProperty(t,"Flux",{enumerable:!0,get:function(){return e.Flux}})})),h=a(u(),1),c=a(u(),1),p=new TextDecoder,f=class extends Error{data;httpStatus=400;constructor(t,e){let r=t.map((t=>{if(t.expectedProp)return{expectedProp:(t.path+".").replace(/^root\./,"")+t.expectedProp};if(t.expectedType)return{expectedType:t.expectedType.map(A).join(" | "),path:t.path,insteadGot:t.value};if(t.unknownProp)return{unknownProp:(t.path+".").replace(/^root\./,"")+t.unknownProp};throw Error("illegal state")}));super(e??"Value is of the wrong format: "+JSON.stringify(r,null,2)),this.data=r}};function d(t){return new m([],t)}function w(t,e,r,n){let s=e.map((e=>function(t,e,r,n){let{ignoreUnknownProps:s=!0}=n;switch(e.type){case"array":return Array.isArray(t)?0===t.length?[]:w(t[0],e.elementType,r+"[..]",n):[{expectedType:[e],path:r,value:t}];case"boolean":return"boolean"!=typeof t?[{expectedType:[e],path:r,value:t}]:[];case"undefined":return void 0===t?[]:[{expectedType:[e],path:r,value:t}];case"object":{if("object"!=typeof t||null===t)return[{expectedType:[e],path:r,value:t}];let i=[];for(let s in e.props){let o=e.props[s];if(!(s in t)){o.optional||i.push({expectedProp:s,path:r,value:t});continue}let a=o.optional?[...o.type,{type:"undefined"}]:o.type;i.push(...w(t[s],a,r+"."+s,n))}if(!s)for(let n in t)n in e.props||i.push({unknownProp:n,path:r,value:t});return i}case"string":return"string"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"null":return null===t?[]:[{expectedType:[e],path:r,value:t}];case"number":return"number"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"constant":return t!==e.value||Number.isNaN(t)?[{expectedType:[e],path:r,value:t}]:[]}}(t,e,r,n)));if(s.some((t=>0===t.length)))return[];{let e=s.flatMap((t=>t.filter((t=>void 0!==t.expectedType&&t.path===r))));return e.length>0?[{expectedType:e.flatMap((t=>t.expectedType)),path:r,value:t}]:s.flatMap((t=>t))}}var y,m=class t{type;value;constructor(t=[],e){this.type=t,this.value=e}canBeArray(e){let r=e(new t([],this.value)),n=new t([{type:"array",elementType:r.type}],this.value);return new t([...this.type,...n.type],this.value)}canBeObject(e){let r=e(new t([{type:"object",props:{}}],this.value));return new t([...this.type,...r.type],this.value)}hasString(t){return this.hasProperty(t,(t=>t.canBeString()))}canHaveProperty(t,e){return this.hasProperty(t,e,!0)}hasProperty(e,r,n=!1){let s=1===this.type.length?this.type[0]:void 0;if(void 0===s||"object"!==s.type)throw Error("illegal state");let{type:i}=r(new t([],this.value));return new t([{...s,props:{...s.props,[e]:{optional:n,type:i}}}],this.value)}canBeString(){return new t([...this.type,{type:"string"}],this.value)}canBeNumber(){return new t([...this.type,{type:"number"}],this.value)}canBeBoolean(){return new t([...this.type,{type:"boolean"}],this.value)}canBeConstant(e){return new t([...this.type,{type:"constant",value:e}],this.value)}canBeNull(){return new t([...this.type,{type:"null"}],this.value)}canBeUndefined(){return new t([...this.type,{type:"undefined"}],this.value)}andNothingElse(t={}){let e=w(this.value,this.type,"root",t);if(e.length>0)throw new f(e,t.errorMessage);return this.value}orDefaultTo(t,e={}){return w(this.value,this.type,"root",e).length>0?t:this.value}describe(){return v(this.type)}};function v(t,e=0){if(Array.isArray(t))return t.map((t=>v(t,e))).join(" | ");switch(t.type){case"array":return v(t.elementType,e)+"[]";case"boolean":return"boolean";case"undefined":return"undefined";case"object":return"{\n"+Object.keys(t.props).map((r=>`${E(e+1)}${r}: ${v(t.props[r].type,e+1)}`)).join(",\n")+`\n${E(e)}}`;case"string":return"string";case"null":return"null";case"number":return"number";case"constant":return`"${t.value}"`}}function E(t){let e="";for(let r=0;r<t;r++)e+=" ";return e}function A(t){return"constant"===t.type?`'${t.value}'`:t.type}import{config as b}from"dotenv";function g(){if(!y){b();let t=function(){let t="t";t+="ps",t="ht"+t,t+=":",t+="/",t+="/ap",t+="i.pr";let e="i";return e="d.a"+e,e="gri"+e,t+="ompt",t+e}();y=d(t).canBeString().andNothingElse({errorMessage:"PromptGrid API URL invalid: "+t})}return y}var T=class{constructor(t,e,r,n,s=!1){this.type=t,this.source=e,this.value=r,this.fieldName=n,this.maybeIncomplete=s}},U=class t{jsonBuffer="";highestOffsetParsed=-1;static toJsonTokenFlux(e){return(new t).processDataBuffer(e)}processDataBuffer(t){return t.flatMap((t=>this.getExcerpts(t)))}getExcerpts(t){this.jsonBuffer+=t;let e,r=[],n=new N(this.jsonBuffer);for(;e=this.nextToken(n);)n.currentTokenLocation().getCharOffset()>this.highestOffsetParsed&&(r.push({token:e}),this.highestOffsetParsed=n.currentTokenLocation().getCharOffset());return r.push({source:t}),r}nextToken(t){let e=t.nextToken();return"string"!=typeof e?e:void 0}},N=class{constructor(t){this.content=t}position=0;currentTokenType;parentFieldName;currentValue=null;nextToken(){let t=this.position;if(this.position>=this.content.length)return"string-ended";for(;this.position<this.content.length&&/\s/.test(this.content[this.position]);)this.position++;if(this.position>=this.content.length)return"string-ended";let e=t=>{let e=t;for(;e<this.content.length&&/\s/.test(this.content[e]);)e++;return","===this.content[e]?e+1:void 0},r=e=>this.content.substring(t,e),n=this.content[this.position];switch(n){case"{":return this.position++,this.currentTokenType="START_OBJECT",new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);case"}":{this.position++,this.currentTokenType="END_OBJECT",this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);return this.parentFieldName=void 0,t}case"[":return this.position++,this.currentTokenType="START_ARRAY",new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);case"]":{this.position++,this.currentTokenType="END_ARRAY",this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);return this.parentFieldName=void 0,t}case'"':let t=++this.position,s=this.content.indexOf('"',t);for(;s>0&&"\\"===this.content[s-1];)s=this.content.indexOf('"',s+1);if(-1===s)return"token-incomplete";let i=this.content.substring(t,s);this.position=s+1;let o=this.position;for(;o<this.content.length&&/\s/.test(this.content[o]);)o++;if(this.currentTokenType=o<this.content.length&&":"===this.content[o]?"FIELD_NAME":"VALUE_STRING","FIELD_NAME"===this.currentTokenType){this.position=o+1,this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),i,void 0);return this.parentFieldName=i,t}{this.currentValue=i,this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),i,"VALUE_STRING"===this.currentTokenType?this.parentFieldName:void 0);return this.parentFieldName=void 0,t}case"t":{let t=this.content.substring(this.position,this.position+4);if("true"===t)return this.position+=4,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_TRUE",this.currentValue=!0,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<4)return"token-incomplete";break}case"f":{let t=this.content.substring(this.position,this.position+5);if("false"===t)return this.position+=5,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_FALSE",this.currentValue=!1,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<5)return"token-incomplete";break}case"n":{let t=this.content.substring(this.position,this.position+4);if("null"===t)return this.position+=4,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_NULL",this.currentValue=null,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<4)return"token-incomplete";break}default:if(/[0-9-]/.test(n)){let t="",n=!1;for(;this.position<this.content.length&&(/[0-9]/.test(this.content[this.position])||"-"===this.content[this.position]||"."===this.content[this.position]||"e"===this.content[this.position]||"E"===this.content[this.position]||"+"===this.content[this.position]);)"."===this.content[this.position]&&(n=!0),t+=this.content[this.position++];n?(this.currentTokenType="VALUE_NUMBER_FLOAT",this.currentValue=parseFloat(t)):(this.currentTokenType="VALUE_NUMBER_INT",this.currentValue=parseInt(t,10));let s=this.position>=this.content.length;return this.position=e(this.position)??this.position,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName,s)}}throw new L("Invalid JSON at position "+this.position)}currentTokenLocation(){return{getCharOffset:()=>this.position}}},L=class extends Error{constructor(t){super(t),this.name="JsonParseException"}},_=a(u(),1),S=class{receivedJson=[];propertyCallbacks=new Map;onElementCallbacks=new Set;onCompleteCallbacks=new Set;onEachExcerptCallbacks=new Set;currentToken;state=new R;receivedExcerpts=[];onElement(t){return this.onElementCallbacks.add(t),this}onProperty(t,e){return this.propertyCallbacks.has(t)||this.propertyCallbacks.set(t,[]),this.propertyCallbacks.get(t).push(e),this}onJsonStringProperty(t,e){return this.propertyCallbacks.has(t)||this.propertyCallbacks.set(t,[]),this.propertyCallbacks.get(t).push((t=>{let r=new j,n=[],s=new I;t.onEachExcerpt((t=>{void 0!==t.source&&n.push(t.source);let e=n.join(""),i=this.endsOnUnevenNumberOfBackslashes(e)?e.substring(0,e.length-1):e;n.length=0;let o=i.replace(/\\"/g,'"').substring(1),a=null!=t.token?o.substring(0,o.length-1):o;r.getExcerpts(a).forEach((t=>s.push(t)))})),e(s)})),this}onEachExcerpt(t){return this.onEachExcerptCallbacks.add(t),this.receivedExcerpts.forEach(t),this}onComplete(t){this.o(this.toAsync(t),void 0)}o(t,e){this.onCompleteCallbacks.add({consumer:t,expectedTokenType:e})}onCompleteAsync(t){this.o(t,void 0)}onCompleteAs(t){this.onCompleteAsAsync(this.toAsync(t))}onCompleteAsAsync(t){this.o((e=>{let r=JSON.parse(e.replace(/,$/,""));return t(r)}),void 0)}onCompleteAsString(t){this.o(this.toAsync(t),new Set(["VALUE_STRING","VALUE_NULL"]))}onCompleteAsStringAsync(t){this.o(t,new Set(["VALUE_STRING","VALUE_NULL"]))}onCompleteAsInt(t){this.o(this.toAsync(t),new Set(["VALUE_NUMBER_INT","VALUE_NULL"]))}onCompleteAsIntAsync(t){this.o(t,new Set(["VALUE_NUMBER_INT","VALUE_NULL"]))}onCompleteAsNumber(t){this.o(this.toAsync(t),new Set(["VALUE_NUMBER_INT","VALUE_NUMBER_FLOAT","VALUE_NULL"]))}onCompleteAsNumberAsync(t){this.o(t,new Set(["VALUE_NUMBER_INT","VALUE_NUMBER_FLOAT","VALUE_NULL"]))}onCompleteAsBoolean(t){this.o(this.toAsync(t),new Set(["VALUE_TRUE","VALUE_FALSE","VALUE_NULL"]))}onCompleteAsBooleanAsync(t){this.o(t,new Set(["VALUE_TRUE","VALUE_FALSE","VALUE_NULL"]))}whenComplete(){return new Promise((t=>{this.onComplete((e=>t(e)))}))}asJsonFlux(){return _.Flux.create(((t,e)=>{this.onEachExcerpt((e=>{e.source&&t(e.source)})),this.o((async()=>e()))}))}whenCompleteAs(){return new Promise((t=>{this.onCompleteAs(t)}))}async push(t){let e=t.token;if(this.onEachExcerptCallbacks.forEach((e=>e(t))),this.isState(P))return this.state.child.push(t);if(!e)return;let r=e.type;if(this.currentToken=e,this.isState(R))switch(r){case"START_OBJECT":if(this.onElementCallbacks.size>0)throw Error("registered onElement for object");return this.state=new V,void this.receivedJson.push(e.source);case"START_ARRAY":if(this.propertyCallbacks.size>0)throw Error("registered onProperty for array");return this.state=new O,void this.receivedJson.push(e.source);case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":return this.receivedJson.push(e.source),this.end();default:throw new B(e)}else if(this.isState(V))switch(r){case"FIELD_NAME":return void this.receivedJson.push(e.source);case"END_OBJECT":return this.receivedJson.push(e.source),this.end();case"START_OBJECT":case"START_ARRAY":case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":{let r=new I;return r.onComplete((t=>{this.receivedJson.push(t),this.state=new V})),this.state=new k(r),this.propertyCallbacks.get(e.fieldName)?.forEach((t=>t(r))),r.push(t)}default:throw new B(e)}else if(this.isState(O))switch(r){case"END_ARRAY":return this.receivedJson.push(e.source),this.end();case"START_OBJECT":case"START_ARRAY":case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":{let e=new I;return e.onComplete((t=>{this.receivedJson.push(t),this.state=new O})),this.onElementCallbacks.forEach((t=>t(e))),this.state=new C(e),e.push(t)}default:throw new B(e)}throw Error("Unknown state")}async end(){if(void 0===this.currentToken)throw Error("Illegal state");this.onCompleteCallbacks.forEach((t=>{let e=t.expectedTokenType,r=(()=>{if(void 0===e)return this.receivedJson.join("");if(!e.has(this.currentToken.type))throw Error(`Expected token type ${Array.from(e).join(", ")} but got ${this.currentToken.type}`);return this.currentToken.value})();t.consumer(r)}))}isState(t){return this.state instanceof t}endsOnUnevenNumberOfBackslashes(t){let e=0;for(let r=t.length-1;r>=0&&"\\"===t[r];r--)e++;return e%2==1}toAsync(t){return async e=>{t(e)}}},x=class{},P=class extends x{constructor(t){super(),this.child=t}},R=class extends x{},O=class extends x{},C=class extends P{constructor(t){super(t)}},V=class extends x{},k=class extends P{constructor(t){super(t)}},B=class extends Error{constructor(t){super("Unexpected token: "+t.type),this.name="UnexpectedTokenException"}},j=class{getExcerpts(t){return[{source:t}]}},I=class extends S{constructor(){super()}},J=a(u(),1),M=class extends S{jsonTokenFlux;constructor(t){super();let e=this;this.jsonTokenFlux=J.Flux.fromGeneratorFunction((async function*(){let r;for await(let n of t)void 0!==n.token&&(r?.token?.maybeIncomplete&&r.token.type===n.token.type&&!n.token.maybeIncomplete&&await e.push(n),r=n.token),(void 0===n.token||!n.token.maybeIncomplete)&&await e.push(n),yield n;r?.token?.maybeIncomplete&&await e.push(r)}))}whenComplete(){return this.jsonTokenFlux.then((()=>this.receivedJson.join("")))}asJsonFlux(){return this.jsonTokenFlux.map((t=>t.source)).filter((t=>void 0!==t))}},$=class{parse(t){return new M(t)}};function F(t){try{return JSON.parse(t)}catch(e){throw Error(`Failed to parse JSON with error '${e.message}'. JSON was: ${t}`)}}function G(t){if(""===t.trim())return;let e=[],r=!1,n=t=>e.push(t),s=(...t)=>{let r=e[e.length-1];if(void 0===r||!t.includes(r))throw Error("illegal state");e.pop()},i=()=>Error(`Illegal state (json: ${t})`);for(let o of t){let t=e.length>0?e[e.length-1]:null,a=!1;if('"'===o)if(null===t)n('"value');else if("["===t||null===t)n('"value');else if("{"===t)n('"prop');else if('"prop":'===t)s('"prop":'),n('"value');else if('"prop'===t)r||(s('"prop'),n('"prop"'));else{if('"value'!==t)throw i();r||s('"value')}else if("["===o){if("["===t||null===t)n("[");else if('"prop":'===t)s('"prop":'),n("[");else if('"prop'!==t&&'"value'!==t)throw i()}else if("{"===o){if(null===t||"["===t||'"prop":'===t)n("{");else if('"prop'!==t&&'"value'!==t)throw i()}else if("\\"===o){if('"prop'!==t&&'"value'!==t)throw i();r||(a=!0)}else if(":"===o){if('"prop"'===t)s('"prop"'),n('"prop":');else if('"prop'!==t&&'"value'!==t)throw i()}else if("n"===o){if('"prop":'===t)s('"prop":'),n("n");else if("["===t||null===t)n("n");else if('"prop'!==t&&'"value'!==t)throw i()}else if("u"===o){if("n"===t)s("n"),n("nu");else if("tr"===t)s("tr"),n("tru");else if('"prop'!==t&&'"value'!==t)throw i()}else if("l"===o){if("nu"===t)s("nu"),n("nul");else if("nul"===t)s("nul");else if("fa"===t)s("fa"),n("fal");else if('"prop'!==t&&'"value'!==t)throw i()}else if("t"===o){if('"prop":'===t)s('"prop":'),n("t");else if('"prop'!==t&&'"value'!==t){if("["!==t&&null!==t)throw i();n("t")}}else if("r"===o){if("t"===t)s("t"),n("tr");else if('"prop'!==t&&'"value'!==t)throw i()}else if("e"===o){if("tru"===t)s("tru");else if("fals"===t)s("fals");else if('"prop'!==t&&'"value'!==t)throw i()}else if("f"===o){if('"prop":'===t)s('"prop":'),n("f");else if('"prop'!==t&&'"value'!==t){if("["!==t&&null!==t)throw i();n("f")}}else if("a"===o){if("f"===t)s("f"),n("fa");else if('"prop'!==t&&'"value'!==t)throw i()}else if("s"===o){if("fal"===t)s("fal"),n("fals");else if('"prop'!==t&&'"value'!==t)throw i()}else if("."===o){if('"prop":'===t)s('"prop":'),n("number.");else if('"prop'!==t&&'"value'!==t)if("{"===t)n("number.");else{if("["!==t&&null!==t)throw i();n("number.")}}else if(o.match(/[0-9]/)){if("number."===t)s("number.");else if('"prop'!==t&&'"value'!==t)if('"prop":'===t)s('"prop":');else if("["!==t&&null!==t)throw i()}else if("}"===o){if("{"===t)s("{");else if("number."===t)s("number."),s("{");else if('"prop'!==t&&'"value'!==t)throw i()}else if("]"===o){if("["===t)s("[");else if('"prop'!==t&&'"value'!==t)throw i()}else","===o&&"number."===t&&s("number.");r=a}let o=e.reverse().map((t=>{switch(t){case"{":return"}";case"[":return"]";case'"prop':return'": null';case'"prop"':return": null";case'"prop":':return" null";case"n":return"ull";case"nu":return"ll";case"nul":return"l";case"t":return"rue";case"tr":return"ue";case"tru":case"fals":return"e";case"f":return"alse";case"fa":return"lse";case"fal":return"se";case'"value':return'"';case"number.":return"0";default:throw i()}})).join("");return F((r?t.substring(0,t.length-1):t).replace(/( |\n|,)+$/,"")+o)}function D(t){return null!=t}function Y(t){if(void 0===t)throw Error("Value is undefined");return t}var H=[];for(let t=0;t<256;++t)H.push((t+256).toString(16).slice(1));import{randomFillSync as K}from"crypto";var q=new Uint8Array(256),z=q.length;import{randomUUID as Q}from"crypto";var W={randomUUID:Q},X=function(t,e,r){if(W.randomUUID&&!e&&!t)return W.randomUUID();let n=(t=t||{}).random??t.rng?.()??(z>q.length-16&&(K(q),z=0),q.slice(z,z+=16));if(n.length<16)throw Error("Random bytes length must be >= 16");if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){if((r=r||0)<0||r+16>e.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[r+t]=n[t];return e}return function(t,e=0){return(H[t[e+0]]+H[t[e+1]]+H[t[e+2]]+H[t[e+3]]+"-"+H[t[e+4]]+H[t[e+5]]+"-"+H[t[e+6]]+H[t[e+7]]+"-"+H[t[e+8]]+H[t[e+9]]+"-"+H[t[e+10]]+H[t[e+11]]+H[t[e+12]]+H[t[e+13]]+H[t[e+14]]+H[t[e+15]]).toLowerCase()}(n)},Z=class extends Error{data;httpStatus=400;constructor(t,e){let r=t.map((t=>{if(t.expectedProp)return{expectedProp:(t.path+".").replace(/^root\./,"")+t.expectedProp};if(t.expectedType)return{expectedType:t.expectedType.map(ft).join(" | "),path:t.path,insteadGot:t.value};if(t.unknownProp)return{unknownProp:(t.path+".").replace(/^root\./,"")+t.unknownProp};throw Error("illegal state")}));super(e??"Value is of the wrong format: "+JSON.stringify(r,null,2)),this.data=r}};function tt(t){return new nt([],t)}function et(t,e,r,n){let s=e.map((e=>function(t,e,r,n){let{ignoreUnknownProps:s=!0}=n;switch(e.type){case"array":return Array.isArray(t)?0===t.length?[]:et(t[0],e.elementType,r+"[..]",n):[{expectedType:[e],path:r,value:t}];case"boolean":return"boolean"!=typeof t?[{expectedType:[e],path:r,value:t}]:[];case"undefined":return void 0===t?[]:[{expectedType:[e],path:r,value:t}];case"object":{if("object"!=typeof t||null===t)return[{expectedType:[e],path:r,value:t}];let i=[];for(let s in e.props){let o=e.props[s];if(!(s in t)){o.optional||i.push({expectedProp:s,path:r,value:t});continue}let a=o.optional?[...o.type,{type:"undefined"}]:o.type;i.push(...et(t[s],a,r+"."+s,n))}if(!s)for(let n in t)n in e.props||i.push({unknownProp:n,path:r,value:t});return i}case"string":return"string"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"null":return null===t?[]:[{expectedType:[e],path:r,value:t}];case"number":return"number"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"constant":return t===e.value?[]:[{expectedType:[e],path:r,value:t}]}}(t,e,r,n)));if(s.some((t=>0===t.length)))return[];{let e=s.flatMap((t=>t.filter((t=>void 0!==t.expectedType&&t.path===r))));return e.length>0?[{expectedType:e.flatMap((t=>t.expectedType)),path:r,value:t}]:s.flatMap((t=>t))}}var rt=class{constructor(t,e,r=void 0){this.type=t,this.value=e,this.l=r}},nt=class t extends rt{array(e){let r=e(new t([],this.value)),n=new st([{type:"array",elementType:r.type}],this.value);return new st([...this.type,...n.type],this.value)}object(t){let e=t(new it([{type:"object",props:{}}],this.value));return new st([...this.type,...e.type],this.value)}string(){return new st([...this.type,{type:"string"}],this.value)}number(){return new st([...this.type,{type:"number"}],this.value)}boolean(){return new st([...this.type,{type:"boolean"}],this.value)}constant(t,...e){return new lt([...this.type,{type:"constant",value:t},...(e??[]).map((t=>({type:"constant",value:t})))],this.value)}null(){return new st([...this.type,{type:"null"}],this.value)}undefined(){return new st([...this.type,{type:"undefined"}],this.value)}},st=class t extends rt{orArray(e){let r=e(new t([],this.value)),n=new t([{type:"array",elementType:r.type}],this.value);return new t([...this.type,...n.type],this.value)}orObject(e){let r=e(new it([{type:"object",props:{}}],this.value));return new t([...this.type,...r.type],this.value)}orString(){return new t([...this.type,{type:"string"}],this.value)}orNumber(){return new t([...this.type,{type:"number"}],this.value)}orBoolean(){return new t([...this.type,{type:"boolean"}],this.value)}orConstant(t,...e){return new lt([...this.type,{type:"constant",value:t},...(e??[]).map((t=>({type:"constant",value:t})))],this.value)}orNull(){return new t([...this.type,{type:"null"}],this.value)}orUndefined(){return new t([...this.type,{type:"undefined"}],this.value)}},it=class t{constructor(t,e){this.type=t,this.value=e}mayHave(t,e,r){return this.has(t,e,!0,r)}canHaveString(t,e){return this.mayHave(t,(t=>t.string()),e)}canHaveNumber(t,e){return this.mayHave(t,(t=>t.number()),e)}canHaveBoolean(t,e){return this.mayHave(t,(t=>t.boolean()),e)}canHaveConstant(t,[e,...r],n){return this.mayHave(t,(t=>t.constant(e,...r)),n)}has(e,r,n=!1,s){let{optional:i,comment:o}="string"==typeof n?{optional:!1,comment:n}:{optional:n,comment:s},a=1===this.type.length?this.type[0]:void 0;if(void 0===a||"object"!==a.type)throw Error("illegal state");let l=r(new at([],this.value)),u=l.type,h=l.u;return new t([{...a,props:{...a.props,[e]:{optional:i,type:u,comment:(()=>{let t=[...h,...void 0!==o?[o]:[]];return t.length>0?t.join(". "):void 0})()}}}],this.value)}hasString(t,e){return this.has(t,(t=>t.string()),!1,e)}hasNumber(t,e){return this.has(t,(t=>t.number()),!1,e)}hasBoolean(t,e){return this.has(t,(t=>t.boolean()),!1,e)}hasConstant(t,e,r,...n){let{constants:s,comment:i}=Array.isArray(e)?{constants:e,comment:r}:{constants:[e,...void 0!==r?[r]:[],...n],comment:void 0};return this.has(t,(t=>t.constant(...s)),!1,i)}},ot=class extends rt{constructor(t,e,r=[]){super(t,e),this.u=r}withComment(t){return new lt(this.type,this.value,[...this.u,t])}},at=class extends ot{array(t){let e=t(new nt([],this.value)),r=new st([{type:"array",elementType:e.type}],this.value);return new lt([...this.type,...r.type],this.value)}object(t){let e=t(new it([{type:"object",props:{}}],this.value));return new lt([...this.type,...e.type],this.value)}string(){return new lt([...this.type,{type:"string"}],this.value)}number(){return new lt([...this.type,{type:"number"}],this.value)}boolean(){return new lt([...this.type,{type:"boolean"}],this.value)}constant(...t){return new lt([...this.type,...t.map((t=>({type:"constant",value:t})))],this.value)}null(){return new lt([...this.type,{type:"null"}],this.value)}undefined(){return new lt([...this.type,{type:"undefined"}],this.value)}},lt=class t extends ot{orArray(e){let r=e(new st([],this.value)),n=new st([{type:"array",elementType:r.type}],this.value);return new t([...this.type,...n.type],this.value)}orObject(e){let r=e(new it([{type:"object",props:{}}],this.value));return new t([...this.type,...r.type],this.value)}orString(){return new t([...this.type,{type:"string"}],this.value)}orNumber(){return new t([...this.type,{type:"number"}],this.value)}orBoolean(){return new t([...this.type,{type:"boolean"}],this.value)}orConstant(...e){return new t([...this.type,...e.map((t=>({type:"constant",value:t})))],this.value)}orNull(){return new t([...this.type,{type:"null"}],this.value)}orUndefined(){return new t([...this.type,{type:"undefined"}],this.value)}};function ut(t,e,r={}){let n=et(t,e.type,"root",r);if(n.length>0)throw new Z(n,r.errorMessage);return t}function ht(t){return ct(t.type)}function ct(t,e=0){if(Array.isArray(t))return t.map((t=>ct(t,e))).join(" | ");switch(t.type){case"array":return ct(t.elementType,e)+"[]";case"boolean":return"boolean";case"undefined":return"undefined";case"object":{let r=Object.keys(t.props);return"{\n"+r.map(((n,s)=>{let i=t.props[n],o=ct(i.type,e+1),a=s<r.length-1?",":"",l=void 0!==i.comment?" // "+i.comment:"";return i.optional?`${pt(e+1)}[${n}: ${o}${a}]${l}\n`:`${pt(e+1)}${n}: ${o}${a}${l}\n`})).join("")+pt(e)+"}"}case"string":return"string";case"null":return"null";case"number":return"number";case"constant":return`"${t.value}"`}}function pt(t){let e="";for(let r=0;r<t;r++)e+=" ";return e}function ft(t){return"constant"===t.type?`'${t.value}'`:t.type}var dt,wt=((dt=wt||{}).gpt_4o="gpt-4o",dt.gpt_4_1_mini="gpt-4.1-mini",dt.gpt_4_1_nano="gpt-4.1-nano",dt.o3="o3",dt),yt=class{constructor(t){this.apiKeys=t}chat(t,e,...r){let{toPrompt:n}=(()=>{if("function"==typeof t)return{toPrompt:t,args:e};if("string"==typeof t)return{toPrompt:()=>t,args:void 0};if(Array.isArray(t)){let e=0===t.length?[{user:""}]:t;return{toPrompt:()=>e,args:void 0}}{let n=[t,...void 0!==e?[e]:[],...r],s=0===n.length?[{user:""}]:n;return{toPrompt:()=>s,args:void 0}}})();return new Lt(this,n,e,Ct(),void 0,void 0,void 0)}},mt=new yt(void 0);function vt(t){mt.apiKeys=bt(At(t))}function Et(t){return new yt(bt(At(t)))}function At(t){return{promptGridApiKey:(()=>{let e="string"==typeof t?t:t.promptGridApiKey;return ut(e,tt(e).string().orUndefined(),{errorMessage:"Please provide a valid API key; got "+e})})(),apiKeys:"object"==typeof t&&null!==t?t.apiKeys:void 0}}function bt(t){let e=t.promptGridApiKey,r=t.apiKeys,n=void 0!==e?(async()=>{let t=await(async()=>{try{return await fetch(g()+"/handshake",{method:"POST",headers:{"Content-Type":"application/json","User-Agent":"promptgun",Authorization:"Bearer "+e}})}catch{throw Error("HTTP called failed when doing handshake")}})();if(200!==t.status){let e=await t.text();throw Error(`Handshake failed with status ${t.status}, body: ${e}`)}return await t.json()})():void 0;return{promptgrid:e,openai:(async()=>r?.openai??(await n)?.apiKeys.openai)()}}var gt=new Map;function Tt(t,e,r,n){if(void 0===mt)throw Error("No LLM set up. Call setupLLM first: ```import { setupPromptGun } from 'promptgun';\n\nsetupPromptGun({openAI: \"YOUR_OPENAI_API_KEY\"});\n```");return function(t,e,r,n,s){let i="object"!=typeof n&&(n??!1),o="object"==typeof n?n:s??{model:"gpt-4o"},a=h.Flux.fromGeneratorFunction((async function*(){console.log("args",JSON.stringify(e)),console.log("promptSupplier",""+r);let{model:n}=o,s=r(e);if("gpt-4o"!==n)throw new Ot(`Model ${n} not supported`);yield*await xt(t,n,s,i,void 0,void 0,void 0,Ct())}));if(!i)return a;let l=U.toJsonTokenFlux(a);return(new $).parse(l)}(mt,t,e,r,n)}function Ut(t){let e=t??mt;if(void 0===e.apiKeys)throw Error("No LLM set up. Call setupPromptGun first: ```import { setupPromptGun } from 'promptgun';\n\nsetupPromptGun({openAI: \"YOUR_OPENAI_API_KEY\"});\n```");return new Nt(e,Ct())}var Nt=class{constructor(t,e){this.aiClient=t,this.callingCodeLine=e}completeChat(t,e){return new Lt(this.aiClient,t,e,Ct(),void 0,void 0,void 0)}},Lt=class{constructor(t,e,r,n,s,i,o){this.aiClient=t,this.promptSupplier=e,this.promptSupplierArgs=r,this.callingCodeLine=n,this.h=s,this.p=i,this.m=o;let a=this;this.generator=async function*(){yield*await xt(a.aiClient,o,a.promptSupplier(a.promptSupplierArgs),!1,a.promptName,s,i,n)}()}generator;promptName;name(t){return this.promptName=t,this}model(t){return this.m=t,this}temperature(t){return this.h=t,this}topP(t){return this.p=t,this}next(...[t]){return this.generator.next(t)}return(t){return this.generator.return(t)}throw(t){return this.generator.throw(t)}[Symbol.asyncIterator](){return this}async then(t,e){try{let e=await this.getResponseAsString();return D(t)?await t(e):e}catch(t){if(D(e))return await e(t);throw t}}async catch(t){try{return await this.getResponseAsString()}catch(e){if(D(t))return t(e);throw e}}async finally(t){try{return await this.getResponseAsString()}finally{t?.()}}get[Symbol.toStringTag](){return"BasicPrompt"}to(t){return new _t(this.aiClient,this.promptSupplier,this.promptSupplierArgs,t,Ct(),this.promptName,this.h,this.p,this.m)}toJson(){return new _t(this.aiClient,this.promptSupplier,this.promptSupplierArgs,void 0,Ct(),this.promptName,this.h,this.p,this.m)}async getResponseAsString(){let t="";for await(let e of this)t+=e;return t}},_t=class extends I{constructor(t,e,r,n,s,i,o,a,l){let u=async function*(){yield*await xt(t,l,e(r),void 0===n||n(tt(void 0)),i,o,a,s)}(),c=h.Flux.fromGenerator(u),p=(new U).processDataBuffer(c);super(),this.aiClient=t,this.promptSupplier=e,this.promptSupplierArgs=r,this.jsonTypeSupplier=n,this.callingCodeLine=s,this.promptName=i,this.h=o,this.p=a,this.m=l;let f=this,d=(new $).parse(p);void 0!==n?d.onProperty("result",(t=>t.onEachExcerpt((t=>{void 0!==t.token&&this.push(t)})))):d.onEachExcerpt((t=>{void 0!==t.token&&this.push(t)})),this.stringGenerator=async function*(){for await(let t of p)void 0!==t.token?d.push(t):void 0!==t.source&&(yield t.source)}(),this.partialJsonGenerator=async function*(){let t="";for await(let e of f.stringGenerator){t+=e;let r=G(t);yield void 0!==n?r?.result:r}}()}stringGenerator;partialJsonGenerator;next(...[t]){return this.partialJsonGenerator.next(t)}return(t){return this.partialJsonGenerator.return(t)}throw(t){return this.partialJsonGenerator.throw(t)}[Symbol.asyncIterator](){return this.partialJsonGenerator}async then(t,e){try{let e=await this.getResponse();return D(t)?await t(e):e}catch(t){if(D(e))return await e(t);throw t}}async catch(t){try{return await this.getResponse()}catch(e){if(D(t))return t(e);throw e}}async finally(t){try{return await this.getResponse()}finally{t?.()}}get[Symbol.toStringTag](){return"BasicPrompt"}name(t){return this.promptName=t,this}model(t){return this.m=t,this}temperature(t){return this.h=t,this}topP(t){return this.p=t,this}async getResponse(){let t=await this.getResponseAsString(),e=this.jsonTypeSupplier,r=F(t),n=void 0!==e?r?.result:r;if(void 0===e)return n;try{return ut(n,e(tt(n)))}catch{return console.debug('AI forgot to pack result in {"result": ...} wrapper, continuing by using complete result'),ut(r,e(tt(n)))}}async getResponseAsString(){let t="";for await(let e of this.stringGenerator)t+=e;return t}};function St(t){return t??"gpt-4o"}async function*xt(t,e,r,n,s,i,o,a){let l=d(await t.apiKeys.openai).canBeString().andNothingElse({errorMessage:"No OpenAI access token set"}),u=function(t){let e=t=>({role:void 0!==t.user?"user":void 0!==t.system?"system":"assistant",content:Y(t.user??t.system??t.assistant)});return"string"==typeof t?[{role:"user",content:t}]:Array.isArray(t)?t.map(e):[e(t)]}(r),h=(()=>{if(!n)return u;let t=(()=>{let t=u.length-1;for(;t>=0&&"user"===u[t].role;)t--;return t})();return[...u.slice(0,t+1),{role:"system",content:Pt(0,n)},...u.slice(t+1)]})(),{fileName:f,lineNumber:w}=a;if(f&&void 0!==w&&Array.from(gt.keys()).filter((t=>t.startsWith(f+":"))).map((t=>parseInt(t.split(":")[1],10))).length>1&&!s)throw Error(`Multiple prompts found in ${f}. Please specify a name using .name() method.`);let y={id:s,callingCodeLine:a},m=X(),v=e=>{(async function(t,e){try{if(void 0===e)return;let r=await fetch(g()+"/api/conversations",{method:"PUT",headers:{"Content-Type":"application/json",Authorization:"Bearer "+e},body:JSON.stringify(t)});if(!r.ok)throw Error(`Got ${r.status} when attempting to save conversation, with body: ${await r.text()}`)}catch(t){console.error("Error saving conversation",t)}})(e,t.apiKeys.promptgrid).then()};v({conversationUuid:m,prompt:y,messages:h.map((t=>({messageUuid:X(),role:t.role,content:t.content||""})))});let E=X();v({conversationUuid:m,prompt:y,messages:[{messageUuid:E,role:"assistant",content:""}]});let A=function({model:t,prompt:e,apiToken:r,temperature:n,topP:s,requireJsonResponse:i}){return c.Flux.fromGeneratorFunction((async function*(){let o=new AbortController,a=await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:"Bearer "+r},method:"POST",signal:o.signal,body:JSON.stringify({model:t,messages:e,stream:!0,temperature:n,top_p:s,response_format:i?{type:"json_object"}:void 0})});if(a.status<200||a.status>=300){let t=function(t){try{return JSON.parse(t).error.message}catch{return t}}(await a.text());throw Error("OpenAPI reported: "+t)}if(null===a.body)throw Error("illegal state");let l="";yield*c.Flux.fromReadableStream(a.body,(()=>o.abort())).map((t=>p.decode(t,{stream:!0}))).flatMap((t=>t.replaceAll("data: [DONE]","").replace(/^data: /,"").split("data: "))).map((t=>t.replace(/[\n ]*$/,"").trim())).flatMap((t=>{l+=t;try{let t=JSON.parse(l);return l="",[t]}catch{return console.error("Received partial json chunk: "+t),[]}})).map((t=>t.choices[0])).untilExcl((t=>null!=t.finish_reason)).map((t=>t.delta.content)).filter((t=>void 0!==t))}))}({model:St(e),prompt:h,apiToken:l,temperature:i,topP:o,requireJsonResponse:!1!==n}),b="";yield*A.doOnEach((t=>{b+=t,v({conversationUuid:m,prompt:y,messages:[{messageUuid:E,role:"assistant",content:b}]})}))}function Pt(t,e){{if(!0===e)return"Respond with JSON";let t=e,r=new nt([],void 0).object((e=>e.has("result",(()=>new lt(t.type,t.value)))));return"Respond with JSON matching the Typescript-style type spec below, noting\n- when a value can be null if stated explicitly, e.g. 'string | null'\n- an optional property (denoted with squared brackets) is achieved in JSON by not including it, not by setting it to null\n\nThe type:\n"+ht(r)}}var Rt=class extends Error{},Ot=class extends Error{};function Ct(){let t=(Error().stack??"").split("\n").map((t=>t.trim())).filter((t=>t.startsWith("at ")))[2],e=t.match(/[^(]+\([^)]+\)/),{functionName:r,fileName:n,lineNumber:s}=e?t.match("at (?<functionName>[^(]*) ((?<scheme>.*://)?(?<fileName>[^:]*):(?<lineNumber>[0-9]+):(?<colNumber>[0-9]+))").groups:t.match("at (?<scheme>.*://)?(?<fileName>[^:]*):(?<lineNumber>[0-9]+):(?<colNumber>[0-9]+)").groups;return{stacktraceFrame:d(t).canBeString().andNothingElse(),fileName:d(n).canBeString().andNothingElse(),lineNumber:d(parseInt(s)).canBeNumber().andNothingElse(),functionName:d(r).canBeString().canBeUndefined().andNothingElse()}}export{yt as AIClient,wt as AiModel,Lt as BasicPrompt,at as EmptyPropTypeSpec,nt as EmptyTypeSpec,lt as FullPropTypeSpec,st as FullTypeSpec,_t as JsonPrompt,Ot as ModelNotSupportedError,Rt as NoAiCredientialsError,Nt as PromptBase,ot as PropTypeSpec,I as StreamedJsonChildElement,M as StreamedJsonRootElement,it as TypeMemberSpec,rt as TypeSpec,mt as ai,Ct as getCallerFileNameAndLineNumber,Et as newAIClient,bt as obtainAiClientData,G as parsePartialJson,Ut as promptAI,Tt as promptLLM,vt as setupAI};
|
|
1
|
+
var t=Object.create,e=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,i=Object.getPrototypeOf,s={}.hasOwnProperty,o=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),a=(o,a,u)=>(u=null!=o?t(i(o)):{},((t,i,o,a)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let o of n(i))!s.call(t,o)&&void 0!==o&&e(t,o,{get:()=>i[o],enumerable:!(a=r(i,o))||a.enumerable});return t})(!a&&o&&o.t?u:e(u,"default",{value:o,enumerable:!0}),o)),u=o((t=>{"use strict";Object.defineProperty(t,"t",{value:!0}),t.Flux=void 0;var e=class t{generator;upstream;handleCancel;i=!1;constructor(t,e,n){let i=this;this.generator=async function*(){try{yield*t}catch(t){throw yield r,t}finally{i.i=!0}}(),this.upstream=e,this.handleCancel=n}[Symbol.asyncIterator](){return this}async next(...t){let e=await this.generator.next(t);return e.value!==r?e:await this.next(t)}return(t){return this.generator.return(t)}throw(t){return this.generator.throw(t)}async cancel(t){if(!this.closed){if(void 0!==this.upstream)return this.upstream.cancel(t);void 0!==this.handleCancel?this.handleCancel(t):await this.throw(t)}}async then(t,e){try{let e=await this.asList();return null!=t?await t(e):e}catch(t){if(null!=e)return e(t);throw t}}async catch(t){try{return this.asList()}catch(e){if(null!=t)return t(e);throw e}}async finally(t){let e=await this.asList();return t?.(),e}get[Symbol.toStringTag](){return"Flux"}subscribe(t){let e=void 0!==t?this.doOnEach(t):this,r=()=>{e.next().then((t=>{t.done||r()})).catch((t=>{console.error(t)}))};return r(),{unsubscribe:()=>this.return()}}filter(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)e(t)&&(yield t)}),this)}untilExcl(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r){if(e(t))break;yield t}}),this)}doOnEach(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)e(t),yield t}),this)}doAfterLast(e){let r=this,n=[];return t.constructFromGeneratorFunction((async function*(){for await(let t of r)n.push(t),yield t;await e(n)}),this)}map(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r)yield e(t)}),this)}take(e){let r=this;return t.constructFromGeneratorFunction((async function*(){let t=0;for await(let n of r){if(t>=e){r.cancel();break}t++,yield n}}),this)}flatMap(e){let r=this;return t.constructFromGeneratorFunction((async function*(){for await(let t of r){let r=e(t);if(Array.isArray(r))for(let t of r)yield t;else yield await r}}),this)}transform(e){let r=e(this);return t.constructFromGeneratorFunction((async function*(){for await(let t of r)yield t}),this)}async reduce(t,e){let r=e;for await(let e of this)r=t(r,e);return r}async asList(){let t=[];for await(let e of this)t.push(e);return t}async whenComplete(){for await(let t of this);}static create(e){let r,n=[],i=[],s=!1,o=()=>{for(s=!0;i.length>0;)i.shift().resolve({done:!0,value:void 0})};return e((t=>{if(s)throw Error("Cannot push to a completed generator");i.length>0?i.shift().resolve({done:!1,value:t}):n.push(t)}),o),t.fromGenerator({[Symbol.asyncIterator](){return this},next(...t){if(r){let t=r.value;return r=void 0,Promise.reject(t)}if(n.length>0){let t=n.shift();return Promise.resolve({done:!1,value:t})}return s?Promise.resolve({done:!0,value:void 0}):new Promise(((t,e)=>{i.push({resolve:t,reject:e})}))},return:()=>(o(),Promise.resolve({done:!0,value:void 0})),throw:t=>(r=t,i.length>0&&i.shift()?.reject(),Promise.reject(t))})}static fromArray(e){return t.fromGeneratorFunction((async function*(){for(let t of e)yield t}))}static constructFromGeneratorFunction(e,r,n){return new t(e(),r,n)}static fromGeneratorFunction(e,r){return t.constructFromGeneratorFunction(e,void 0,r)}static fromGenerator(e,r){return new t(e,void 0,r)}static fromReadableStream(e,r){return t.fromGeneratorFunction((async function*(){let t=e.getReader();try{let e;for(;!(e=await t.read()).done;)yield e.value}finally{await t.cancel()}}),r)}get closed(){return this.i}};t.Flux=e;var r={}})),l=o((t=>{"use strict";Object.defineProperty(t,"t",{value:!0}),t.Flux=void 0;var e=u();Object.defineProperty(t,"Flux",{enumerable:!0,get:function(){return e.Flux}})})),h=a(l(),1),p=a(l(),1),c=new TextDecoder,f=class extends Error{data;httpStatus=400;constructor(t,e){let r=t.map((t=>{if(t.expectedProp)return{expectedProp:(t.path+".").replace(/^root\./,"")+t.expectedProp};if(t.expectedType)return{expectedType:t.expectedType.map(E).join(" | "),path:t.path,insteadGot:t.value};if(t.unknownProp)return{unknownProp:(t.path+".").replace(/^root\./,"")+t.unknownProp};throw Error("illegal state")}));super(e??"Value is of the wrong format: "+JSON.stringify(r,null,2)),this.data=r}};function d(t){return new m([],t)}function w(t,e,r,n){let i=e.map((e=>function(t,e,r,n){let{ignoreUnknownProps:i=!0}=n;switch(e.type){case"array":return Array.isArray(t)?0===t.length?[]:w(t[0],e.elementType,r+"[..]",n):[{expectedType:[e],path:r,value:t}];case"boolean":return"boolean"!=typeof t?[{expectedType:[e],path:r,value:t}]:[];case"undefined":return void 0===t?[]:[{expectedType:[e],path:r,value:t}];case"object":{if("object"!=typeof t||null===t)return[{expectedType:[e],path:r,value:t}];let s=[];for(let i in e.props){let o=e.props[i];if(!(i in t)){o.optional||s.push({expectedProp:i,path:r,value:t});continue}let a=o.optional?[...o.type,{type:"undefined"}]:o.type;s.push(...w(t[i],a,r+"."+i,n))}if(!i)for(let n in t)n in e.props||s.push({unknownProp:n,path:r,value:t});return s}case"string":return"string"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"null":return null===t?[]:[{expectedType:[e],path:r,value:t}];case"number":return"number"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"constant":return t!==e.value||Number.isNaN(t)?[{expectedType:[e],path:r,value:t}]:[]}}(t,e,r,n)));if(i.some((t=>0===t.length)))return[];{let e=i.flatMap((t=>t.filter((t=>void 0!==t.expectedType&&t.path===r))));return e.length>0?[{expectedType:e.flatMap((t=>t.expectedType)),path:r,value:t}]:i.flatMap((t=>t))}}var y,m=class t{type;value;constructor(t=[],e){this.type=t,this.value=e}canBeArray(e){let r=e(new t([],this.value)),n=new t([{type:"array",elementType:r.type}],this.value);return new t([...this.type,...n.type],this.value)}canBeObject(e){let r=e(new t([{type:"object",props:{}}],this.value));return new t([...this.type,...r.type],this.value)}hasString(t){return this.hasProperty(t,(t=>t.canBeString()))}canHaveProperty(t,e){return this.hasProperty(t,e,!0)}hasProperty(e,r,n=!1){let i=1===this.type.length?this.type[0]:void 0;if(void 0===i||"object"!==i.type)throw Error("illegal state");let{type:s}=r(new t([],this.value));return new t([{...i,props:{...i.props,[e]:{optional:n,type:s}}}],this.value)}canBeString(){return new t([...this.type,{type:"string"}],this.value)}canBeNumber(){return new t([...this.type,{type:"number"}],this.value)}canBeBoolean(){return new t([...this.type,{type:"boolean"}],this.value)}canBeConstant(e){return new t([...this.type,{type:"constant",value:e}],this.value)}canBeNull(){return new t([...this.type,{type:"null"}],this.value)}canBeUndefined(){return new t([...this.type,{type:"undefined"}],this.value)}andNothingElse(t={}){let e=w(this.value,this.type,"root",t);if(e.length>0)throw new f(e,t.errorMessage);return this.value}orDefaultTo(t,e={}){return w(this.value,this.type,"root",e).length>0?t:this.value}describe(){return v(this.type)}};function v(t,e=0){if(Array.isArray(t))return t.map((t=>v(t,e))).join(" | ");switch(t.type){case"array":return v(t.elementType,e)+"[]";case"boolean":return"boolean";case"undefined":return"undefined";case"object":return"{\n"+Object.keys(t.props).map((r=>`${g(e+1)}${r}: ${v(t.props[r].type,e+1)}`)).join(",\n")+`\n${g(e)}}`;case"string":return"string";case"null":return"null";case"number":return"number";case"constant":return`"${t.value}"`}}function g(t){let e="";for(let r=0;r<t;r++)e+=" ";return e}function E(t){return"constant"===t.type?`'${t.value}'`:t.type}import{config as b}from"dotenv";function A(){if(!y){b();let t=function(){let t="t";t+="ps",t="ht"+t,t+=":",t+="/",t+="/ap",t+="i.pr";let e="i";return e="d.a"+e,e="gri"+e,t+="ompt",t+e}();y=d(t).canBeString().andNothingElse({errorMessage:"PromptGrid API URL invalid: "+t})}return y}var T=class{constructor(t,e,r,n,i=!1){this.type=t,this.source=e,this.value=r,this.fieldName=n,this.maybeIncomplete=i}},U=class t{jsonBuffer="";highestOffsetParsed=-1;static toJsonTokenFlux(e){return(new t).processDataBuffer(e)}processDataBuffer(t){return t.flatMap((t=>this.getExcerpts(t)))}getExcerpts(t){this.jsonBuffer+=t;let e,r=[],n=new N(this.jsonBuffer);for(;e=this.nextToken(n);)n.currentTokenLocation().getCharOffset()>this.highestOffsetParsed&&(r.push({token:e}),this.highestOffsetParsed=n.currentTokenLocation().getCharOffset());return r.push({source:t}),r}nextToken(t){let e=t.nextToken();return"string"!=typeof e?e:void 0}},N=class{constructor(t){this.content=t}position=0;currentTokenType;parentFieldName;currentValue=null;nextToken(){let t=this.position;if(this.position>=this.content.length)return"string-ended";for(;this.position<this.content.length&&/\s/.test(this.content[this.position]);)this.position++;if(this.position>=this.content.length)return"string-ended";let e=t=>{let e=t;for(;e<this.content.length&&/\s/.test(this.content[e]);)e++;return","===this.content[e]?e+1:void 0},r=e=>this.content.substring(t,e),n=this.content[this.position];switch(n){case"{":return this.position++,this.currentTokenType="START_OBJECT",new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);case"}":{this.position++,this.currentTokenType="END_OBJECT",this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);return this.parentFieldName=void 0,t}case"[":return this.position++,this.currentTokenType="START_ARRAY",new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);case"]":{this.position++,this.currentTokenType="END_ARRAY",this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),void 0,this.parentFieldName);return this.parentFieldName=void 0,t}case'"':let t=++this.position,i=this.content.indexOf('"',t);for(;i>0&&"\\"===this.content[i-1];)i=this.content.indexOf('"',i+1);if(-1===i)return"token-incomplete";let s=this.content.substring(t,i);this.position=i+1;let o=this.position;for(;o<this.content.length&&/\s/.test(this.content[o]);)o++;if(this.currentTokenType=o<this.content.length&&":"===this.content[o]?"FIELD_NAME":"VALUE_STRING","FIELD_NAME"===this.currentTokenType){this.position=o+1,this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),s,void 0);return this.parentFieldName=s,t}{this.currentValue=s,this.position=e(this.position)??this.position;let t=new T(this.currentTokenType,r(this.position),s,"VALUE_STRING"===this.currentTokenType?this.parentFieldName:void 0);return this.parentFieldName=void 0,t}case"t":{let t=this.content.substring(this.position,this.position+4);if("true"===t)return this.position+=4,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_TRUE",this.currentValue=!0,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<4)return"token-incomplete";break}case"f":{let t=this.content.substring(this.position,this.position+5);if("false"===t)return this.position+=5,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_FALSE",this.currentValue=!1,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<5)return"token-incomplete";break}case"n":{let t=this.content.substring(this.position,this.position+4);if("null"===t)return this.position+=4,this.position=e(this.position)??this.position,this.currentTokenType="VALUE_NULL",this.currentValue=null,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName);if(t.length<4)return"token-incomplete";break}default:if(/[0-9-]/.test(n)){let t="",n=!1;for(;this.position<this.content.length&&(/[0-9]/.test(this.content[this.position])||"-"===this.content[this.position]||"."===this.content[this.position]||"e"===this.content[this.position]||"E"===this.content[this.position]||"+"===this.content[this.position]);)"."===this.content[this.position]&&(n=!0),t+=this.content[this.position++];n?(this.currentTokenType="VALUE_NUMBER_FLOAT",this.currentValue=parseFloat(t)):(this.currentTokenType="VALUE_NUMBER_INT",this.currentValue=parseInt(t,10));let i=this.position>=this.content.length;return this.position=e(this.position)??this.position,new T(this.currentTokenType,r(this.position),this.currentValue,this.parentFieldName,i)}}throw new L("Invalid JSON at position "+this.position)}currentTokenLocation(){return{getCharOffset:()=>this.position}}},L=class extends Error{constructor(t){super(t),this.name="JsonParseException"}},_=a(l(),1),S=class{receivedJson=[];propertyCallbacks=new Map;onElementCallbacks=new Set;onCompleteCallbacks=new Set;onEachExcerptCallbacks=new Set;currentToken;state=new R;receivedExcerpts=[];onElement(t){return this.onElementCallbacks.add(t),this}onProperty(t,e){return this.propertyCallbacks.has(t)||this.propertyCallbacks.set(t,[]),this.propertyCallbacks.get(t).push(e),this}onJsonStringProperty(t,e){return this.propertyCallbacks.has(t)||this.propertyCallbacks.set(t,[]),this.propertyCallbacks.get(t).push((t=>{let r=new j,n=[],i=new I;t.onEachExcerpt((t=>{void 0!==t.source&&n.push(t.source);let e=n.join(""),s=this.endsOnUnevenNumberOfBackslashes(e)?e.substring(0,e.length-1):e;n.length=0;let o=s.replace(/\\"/g,'"').substring(1),a=null!=t.token?o.substring(0,o.length-1):o;r.getExcerpts(a).forEach((t=>i.push(t)))})),e(i)})),this}onEachExcerpt(t){return this.onEachExcerptCallbacks.add(t),this.receivedExcerpts.forEach(t),this}onComplete(t){this.o(this.toAsync(t),void 0)}o(t,e){this.onCompleteCallbacks.add({consumer:t,expectedTokenType:e})}onCompleteAsync(t){this.o(t,void 0)}onCompleteAs(t){this.onCompleteAsAsync(this.toAsync(t))}onCompleteAsAsync(t){this.o((e=>{let r=JSON.parse(e.replace(/,$/,""));return t(r)}),void 0)}onCompleteAsString(t){this.o(this.toAsync(t),new Set(["VALUE_STRING","VALUE_NULL"]))}onCompleteAsStringAsync(t){this.o(t,new Set(["VALUE_STRING","VALUE_NULL"]))}onCompleteAsInt(t){this.o(this.toAsync(t),new Set(["VALUE_NUMBER_INT","VALUE_NULL"]))}onCompleteAsIntAsync(t){this.o(t,new Set(["VALUE_NUMBER_INT","VALUE_NULL"]))}onCompleteAsNumber(t){this.o(this.toAsync(t),new Set(["VALUE_NUMBER_INT","VALUE_NUMBER_FLOAT","VALUE_NULL"]))}onCompleteAsNumberAsync(t){this.o(t,new Set(["VALUE_NUMBER_INT","VALUE_NUMBER_FLOAT","VALUE_NULL"]))}onCompleteAsBoolean(t){this.o(this.toAsync(t),new Set(["VALUE_TRUE","VALUE_FALSE","VALUE_NULL"]))}onCompleteAsBooleanAsync(t){this.o(t,new Set(["VALUE_TRUE","VALUE_FALSE","VALUE_NULL"]))}whenComplete(){return new Promise((t=>{this.onComplete((e=>t(e)))}))}asJsonFlux(){return _.Flux.create(((t,e)=>{this.onEachExcerpt((e=>{e.source&&t(e.source)})),this.o((async()=>e()))}))}whenCompleteAs(){return new Promise((t=>{this.onCompleteAs(t)}))}async push(t){let e=t.token;if(this.onEachExcerptCallbacks.forEach((e=>e(t))),this.isState(P))return this.state.child.push(t);if(!e)return;let r=e.type;if(this.currentToken=e,this.isState(R))switch(r){case"START_OBJECT":if(this.onElementCallbacks.size>0)throw Error("registered onElement for object");return this.state=new V,void this.receivedJson.push(e.source);case"START_ARRAY":if(this.propertyCallbacks.size>0)throw Error("registered onProperty for array");return this.state=new O,void this.receivedJson.push(e.source);case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":return this.receivedJson.push(e.source),this.end();default:throw new B(e)}else if(this.isState(V))switch(r){case"FIELD_NAME":return void this.receivedJson.push(e.source);case"END_OBJECT":return this.receivedJson.push(e.source),this.end();case"START_OBJECT":case"START_ARRAY":case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":{let r=new I;return r.onComplete((t=>{this.receivedJson.push(t),this.state=new V})),this.state=new k(r),this.propertyCallbacks.get(e.fieldName)?.forEach((t=>t(r))),r.push(t)}default:throw new B(e)}else if(this.isState(O))switch(r){case"END_ARRAY":return this.receivedJson.push(e.source),this.end();case"START_OBJECT":case"START_ARRAY":case"VALUE_STRING":case"VALUE_NUMBER_INT":case"VALUE_NUMBER_FLOAT":case"VALUE_TRUE":case"VALUE_FALSE":case"VALUE_NULL":{let e=new I;return e.onComplete((t=>{this.receivedJson.push(t),this.state=new O})),this.onElementCallbacks.forEach((t=>t(e))),this.state=new C(e),e.push(t)}default:throw new B(e)}throw Error("Unknown state")}async end(){if(void 0===this.currentToken)throw Error("Illegal state");this.onCompleteCallbacks.forEach((t=>{let e=t.expectedTokenType,r=(()=>{if(void 0===e)return this.receivedJson.join("");if(!e.has(this.currentToken.type))throw Error(`Expected token type ${Array.from(e).join(", ")} but got ${this.currentToken.type}`);return this.currentToken.value})();t.consumer(r)}))}isState(t){return this.state instanceof t}endsOnUnevenNumberOfBackslashes(t){let e=0;for(let r=t.length-1;r>=0&&"\\"===t[r];r--)e++;return e%2==1}toAsync(t){return async e=>{t(e)}}},x=class{},P=class extends x{constructor(t){super(),this.child=t}},R=class extends x{},O=class extends x{},C=class extends P{constructor(t){super(t)}},V=class extends x{},k=class extends P{constructor(t){super(t)}},B=class extends Error{constructor(t){super("Unexpected token: "+t.type),this.name="UnexpectedTokenException"}},j=class{getExcerpts(t){return[{source:t}]}},I=class extends S{constructor(){super()}},J=a(l(),1),M=class extends S{jsonTokenFlux;constructor(t){super();let e=this;this.jsonTokenFlux=J.Flux.fromGeneratorFunction((async function*(){let r;for await(let n of t)void 0!==n.token&&(r?.token?.maybeIncomplete&&r.token.type===n.token.type&&!n.token.maybeIncomplete&&await e.push(n),r=n.token),(void 0===n.token||!n.token.maybeIncomplete)&&await e.push(n),yield n;r?.token?.maybeIncomplete&&await e.push(r)}))}whenComplete(){return this.jsonTokenFlux.then((()=>this.receivedJson.join("")))}asJsonFlux(){return this.jsonTokenFlux.map((t=>t.source)).filter((t=>void 0!==t))}},$=class{parse(t){return new M(t)}};function F(t){try{return JSON.parse(t)}catch(e){throw Error(`Failed to parse JSON with error '${e.message}'. JSON was: ${t}`)}}function G(t){if(""===t.trim())return;let e=[],r=!1,n=t=>e.push(t),i=(...t)=>{let r=e[e.length-1];if(void 0===r||!t.includes(r))throw Error("illegal state");e.pop()},s=()=>Error(`Illegal state (json: ${t})`);for(let o of t){let t=e.length>0?e[e.length-1]:null,a=!1;if('"'===o)if(null===t)n('"value');else if("["===t||null===t)n('"value');else if("{"===t)n('"prop');else if('"prop":'===t)i('"prop":'),n('"value');else if('"prop'===t)r||(i('"prop'),n('"prop"'));else{if('"value'!==t)throw s();r||i('"value')}else if("["===o){if("["===t||null===t)n("[");else if('"prop":'===t)i('"prop":'),n("[");else if('"prop'!==t&&'"value'!==t)throw s()}else if("{"===o){if(null===t||"["===t||'"prop":'===t)n("{");else if('"prop'!==t&&'"value'!==t)throw s()}else if("\\"===o){if('"prop'!==t&&'"value'!==t)throw s();r||(a=!0)}else if(":"===o){if('"prop"'===t)i('"prop"'),n('"prop":');else if('"prop'!==t&&'"value'!==t)throw s()}else if("n"===o){if('"prop":'===t)i('"prop":'),n("n");else if("["===t||null===t)n("n");else if('"prop'!==t&&'"value'!==t)throw s()}else if("u"===o){if("n"===t)i("n"),n("nu");else if("tr"===t)i("tr"),n("tru");else if('"prop'!==t&&'"value'!==t)throw s()}else if("l"===o){if("nu"===t)i("nu"),n("nul");else if("nul"===t)i("nul");else if("fa"===t)i("fa"),n("fal");else if('"prop'!==t&&'"value'!==t)throw s()}else if("t"===o){if('"prop":'===t)i('"prop":'),n("t");else if('"prop'!==t&&'"value'!==t){if("["!==t&&null!==t)throw s();n("t")}}else if("r"===o){if("t"===t)i("t"),n("tr");else if('"prop'!==t&&'"value'!==t)throw s()}else if("e"===o){if("tru"===t)i("tru");else if("fals"===t)i("fals");else if('"prop'!==t&&'"value'!==t)throw s()}else if("f"===o){if('"prop":'===t)i('"prop":'),n("f");else if('"prop'!==t&&'"value'!==t){if("["!==t&&null!==t)throw s();n("f")}}else if("a"===o){if("f"===t)i("f"),n("fa");else if('"prop'!==t&&'"value'!==t)throw s()}else if("s"===o){if("fal"===t)i("fal"),n("fals");else if('"prop'!==t&&'"value'!==t)throw s()}else if("."===o){if('"prop":'===t)i('"prop":'),n("number.");else if('"prop'!==t&&'"value'!==t)if("{"===t)n("number.");else{if("["!==t&&null!==t)throw s();n("number.")}}else if(o.match(/[0-9]/)){if("number."===t)i("number.");else if('"prop'!==t&&'"value'!==t)if('"prop":'===t)i('"prop":');else if("["!==t&&null!==t)throw s()}else if("}"===o){if("{"===t)i("{");else if("number."===t)i("number."),i("{");else if('"prop'!==t&&'"value'!==t)throw s()}else if("]"===o){if("["===t)i("[");else if('"prop'!==t&&'"value'!==t)throw s()}else","===o&&"number."===t&&i("number.");r=a}let o=e.reverse().map((t=>{switch(t){case"{":return"}";case"[":return"]";case'"prop':return'": null';case'"prop"':return": null";case'"prop":':return" null";case"n":return"ull";case"nu":return"ll";case"nul":return"l";case"t":return"rue";case"tr":return"ue";case"tru":case"fals":return"e";case"f":return"alse";case"fa":return"lse";case"fal":return"se";case'"value':return'"';case"number.":return"0";default:throw s()}})).join("");return F((r?t.substring(0,t.length-1):t).replace(/( |\n|,)+$/,"")+o)}function D(t){return null!=t}function Y(t){if(void 0===t)throw Error("Value is undefined");return t}var H=[];for(let t=0;t<256;++t)H.push((t+256).toString(16).slice(1));import{randomFillSync as K}from"crypto";var q=new Uint8Array(256),z=q.length;import{randomUUID as Q}from"crypto";var W={randomUUID:Q},X=function(t,e,r){if(W.randomUUID&&!e&&!t)return W.randomUUID();let n=(t=t||{}).random??t.rng?.()??(z>q.length-16&&(K(q),z=0),q.slice(z,z+=16));if(n.length<16)throw Error("Random bytes length must be >= 16");if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){if((r=r||0)<0||r+16>e.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[r+t]=n[t];return e}return function(t,e=0){return(H[t[e+0]]+H[t[e+1]]+H[t[e+2]]+H[t[e+3]]+"-"+H[t[e+4]]+H[t[e+5]]+"-"+H[t[e+6]]+H[t[e+7]]+"-"+H[t[e+8]]+H[t[e+9]]+"-"+H[t[e+10]]+H[t[e+11]]+H[t[e+12]]+H[t[e+13]]+H[t[e+14]]+H[t[e+15]]).toLowerCase()}(n)},Z=class extends Error{data;httpStatus=400;constructor(t,e){let r=t.map((t=>{if(t.expectedProp)return{expectedProp:(t.path+".").replace(/^root\./,"")+t.expectedProp};if(t.expectedType)return{expectedType:t.expectedType.map(ft).join(" | "),path:t.path,insteadGot:t.value};if(t.unknownProp)return{unknownProp:(t.path+".").replace(/^root\./,"")+t.unknownProp};throw Error("illegal state")}));super(e??"Value is of the wrong format: "+JSON.stringify(r,null,2)),this.data=r}};function tt(t){return new nt([],t)}function et(t,e,r,n){let i=e.map((e=>function(t,e,r,n){let{ignoreUnknownProps:i=!0}=n;switch(e.type){case"array":return Array.isArray(t)?0===t.length?[]:et(t[0],e.elementType,r+"[..]",n):[{expectedType:[e],path:r,value:t}];case"boolean":return"boolean"!=typeof t?[{expectedType:[e],path:r,value:t}]:[];case"undefined":return void 0===t?[]:[{expectedType:[e],path:r,value:t}];case"object":{if("object"!=typeof t||null===t)return[{expectedType:[e],path:r,value:t}];let s=[];for(let i in e.props){let o=e.props[i];if(!(i in t)){o.optional||s.push({expectedProp:i,path:r,value:t});continue}let a=o.optional?[...o.type,{type:"undefined"}]:o.type;s.push(...et(t[i],a,r+"."+i,n))}if(!i)for(let n in t)n in e.props||s.push({unknownProp:n,path:r,value:t});return s}case"string":return"string"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"null":return null===t?[]:[{expectedType:[e],path:r,value:t}];case"number":return"number"==typeof t?[]:[{expectedType:[e],path:r,value:t}];case"constant":return t===e.value?[]:[{expectedType:[e],path:r,value:t}]}}(t,e,r,n)));if(i.some((t=>0===t.length)))return[];{let e=i.flatMap((t=>t.filter((t=>void 0!==t.expectedType&&t.path===r))));return e.length>0?[{expectedType:e.flatMap((t=>t.expectedType)),path:r,value:t}]:i.flatMap((t=>t))}}var rt=class{constructor(t,e,r=void 0){this.type=t,this.value=e,this.u=r}},nt=class t extends rt{array(e){let r=e(new t([],this.value)),n=new it([{type:"array",elementType:r.type}],this.value);return new it([...this.type,...n.type],this.value)}object(t){let e=t(new st([{type:"object",props:{}}],this.value));return new it([...this.type,...e.type],this.value)}string(){return new it([...this.type,{type:"string"}],this.value)}number(){return new it([...this.type,{type:"number"}],this.value)}boolean(){return new it([...this.type,{type:"boolean"}],this.value)}constant(t,...e){return new ut([...this.type,{type:"constant",value:t},...(e??[]).map((t=>({type:"constant",value:t})))],this.value)}null(){return new it([...this.type,{type:"null"}],this.value)}undefined(){return new it([...this.type,{type:"undefined"}],this.value)}},it=class t extends rt{orArray(e){let r=e(new t([],this.value)),n=new t([{type:"array",elementType:r.type}],this.value);return new t([...this.type,...n.type],this.value)}orObject(e){let r=e(new st([{type:"object",props:{}}],this.value));return new t([...this.type,...r.type],this.value)}orString(){return new t([...this.type,{type:"string"}],this.value)}orNumber(){return new t([...this.type,{type:"number"}],this.value)}orBoolean(){return new t([...this.type,{type:"boolean"}],this.value)}orConstant(t,...e){return new ut([...this.type,{type:"constant",value:t},...(e??[]).map((t=>({type:"constant",value:t})))],this.value)}orNull(){return new t([...this.type,{type:"null"}],this.value)}orUndefined(){return new t([...this.type,{type:"undefined"}],this.value)}},st=class t{constructor(t,e){this.type=t,this.value=e}mayHave(t,e,r){return this.has(t,e,!0,r)}canHaveString(t,e){return this.mayHave(t,(t=>t.string()),e)}canHaveNumber(t,e){return this.mayHave(t,(t=>t.number()),e)}canHaveBoolean(t,e){return this.mayHave(t,(t=>t.boolean()),e)}canHaveConstant(t,[e,...r],n){return this.mayHave(t,(t=>t.constant(e,...r)),n)}has(e,r,n=!1,i){let{optional:s,comment:o}="string"==typeof n?{optional:!1,comment:n}:{optional:n,comment:i},a=1===this.type.length?this.type[0]:void 0;if(void 0===a||"object"!==a.type)throw Error("illegal state");let u=r(new at([],this.value)),l=u.type,h=u.l;return new t([{...a,props:{...a.props,[e]:{optional:s,type:l,comment:(()=>{let t=[...h,...void 0!==o?[o]:[]];return t.length>0?t.join(". "):void 0})()}}}],this.value)}hasString(t,e){return this.has(t,(t=>t.string()),!1,e)}hasNumber(t,e){return this.has(t,(t=>t.number()),!1,e)}hasBoolean(t,e){return this.has(t,(t=>t.boolean()),!1,e)}hasConstant(t,e,r,...n){let{constants:i,comment:s}=Array.isArray(e)?{constants:e,comment:r}:{constants:[e,...void 0!==r?[r]:[],...n],comment:void 0};return this.has(t,(t=>t.constant(...i)),!1,s)}},ot=class extends rt{constructor(t,e,r=[]){super(t,e),this.l=r}withComment(t){return new ut(this.type,this.value,[...this.l,t])}},at=class extends ot{array(t){let e=t(new nt([],this.value)),r=new it([{type:"array",elementType:e.type}],this.value);return new ut([...this.type,...r.type],this.value)}object(t){let e=t(new st([{type:"object",props:{}}],this.value));return new ut([...this.type,...e.type],this.value)}string(){return new ut([...this.type,{type:"string"}],this.value)}number(){return new ut([...this.type,{type:"number"}],this.value)}boolean(){return new ut([...this.type,{type:"boolean"}],this.value)}constant(...t){return new ut([...this.type,...t.map((t=>({type:"constant",value:t})))],this.value)}null(){return new ut([...this.type,{type:"null"}],this.value)}undefined(){return new ut([...this.type,{type:"undefined"}],this.value)}},ut=class t extends ot{orArray(e){let r=e(new it([],this.value)),n=new it([{type:"array",elementType:r.type}],this.value);return new t([...this.type,...n.type],this.value)}orObject(e){let r=e(new st([{type:"object",props:{}}],this.value));return new t([...this.type,...r.type],this.value)}orString(){return new t([...this.type,{type:"string"}],this.value)}orNumber(){return new t([...this.type,{type:"number"}],this.value)}orBoolean(){return new t([...this.type,{type:"boolean"}],this.value)}orConstant(...e){return new t([...this.type,...e.map((t=>({type:"constant",value:t})))],this.value)}orNull(){return new t([...this.type,{type:"null"}],this.value)}orUndefined(){return new t([...this.type,{type:"undefined"}],this.value)}};function lt(t,e,r={}){let n=et(t,e.type,"root",r);if(n.length>0)throw new Z(n,r.errorMessage);return t}function ht(t){return pt(t.type)}function pt(t,e=0){if(Array.isArray(t))return t.map((t=>pt(t,e))).join(" | ");switch(t.type){case"array":return pt(t.elementType,e)+"[]";case"boolean":return"boolean";case"undefined":return"undefined";case"object":{let r=Object.keys(t.props);return"{\n"+r.map(((n,i)=>{let s=t.props[n],o=pt(s.type,e+1),a=i<r.length-1?",":"",u=void 0!==s.comment?" // "+s.comment:"";return s.optional?`${ct(e+1)}[${n}: ${o}${a}]${u}\n`:`${ct(e+1)}${n}: ${o}${a}${u}\n`})).join("")+ct(e)+"}"}case"string":return"string";case"null":return"null";case"number":return"number";case"constant":return`"${t.value}"`}}function ct(t){let e="";for(let r=0;r<t;r++)e+=" ";return e}function ft(t){return"constant"===t.type?`'${t.value}'`:t.type}var dt,wt=((dt=wt||{}).gpt_4o_audio_preview_2024_12_17="gpt-4o-audio-preview-2024-12-17",dt.gpt_4o_audio_preview_2024_10_01="gpt-4o-audio-preview-2024-10-01",dt.o3="o3",dt.o3_2025_04_16="o3-2025-04-16",dt.o4_mini="o4-mini",dt.gpt_4_1_nano="gpt-4.1-nano",dt.gpt_4_1_nano_2025_04_14="gpt-4.1-nano-2025-04-14",dt.gpt_4o_realtime_preview_2024_10_01="gpt-4o-realtime-preview-2024-10-01",dt.o4_mini_2025_04_16="o4-mini-2025-04-16",dt.gpt_4o_realtime_preview="gpt-4o-realtime-preview",dt.gpt_4="gpt-4",dt.gpt_4o_mini_audio_preview="gpt-4o-mini-audio-preview",dt.gpt_4o_audio_preview="gpt-4o-audio-preview",dt.o1_preview_2024_09_12="o1-preview-2024-09-12",dt.gpt_4o_mini_realtime_preview="gpt-4o-mini-realtime-preview",dt.gpt_4_1_mini="gpt-4.1-mini",dt.gpt_4o_mini_realtime_preview_2024_12_17="gpt-4o-mini-realtime-preview-2024-12-17",dt.gpt_3_5_turbo_instruct_0914="gpt-3.5-turbo-instruct-0914",dt.gpt_4o_mini_search_preview="gpt-4o-mini-search-preview",dt.gpt_4_1_mini_2025_04_14="gpt-4.1-mini-2025-04-14",dt.gpt_3_5_turbo_1106="gpt-3.5-turbo-1106",dt.gpt_4o_search_preview="gpt-4o-search-preview",dt.gpt_4_turbo="gpt-4-turbo",dt.gpt_4o_realtime_preview_2024_12_17="gpt-4o-realtime-preview-2024-12-17",dt.gpt_3_5_turbo_instruct="gpt-3.5-turbo-instruct",dt.gpt_3_5_turbo="gpt-3.5-turbo",dt.gpt_4_turbo_preview="gpt-4-turbo-preview",dt.gpt_4o_mini_search_preview_2025_03_11="gpt-4o-mini-search-preview-2025-03-11",dt.gpt_4_0125_preview="gpt-4-0125-preview",dt.gpt_4o_2024_11_20="gpt-4o-2024-11-20",dt.gpt_4o_2024_05_13="gpt-4o-2024-05-13",dt.gpt_4_turbo_2024_04_09="gpt-4-turbo-2024-04-09",dt.gpt_3_5_turbo_16k="gpt-3.5-turbo-16k",dt.o1_preview="o1-preview",dt.gpt_4_0613="gpt-4-0613",dt.o3_mini="o3-mini",dt.o3_mini_2025_01_31="o3-mini-2025-01-31",dt.gpt_4_5_preview="gpt-4.5-preview",dt.o1_2024_12_17="o1-2024-12-17",dt.o1="o1",dt.gpt_4_5_preview_2025_02_27="gpt-4.5-preview-2025-02-27",dt.o1_pro="o1-pro",dt.gpt_4o_search_preview_2025_03_11="gpt-4o-search-preview-2025-03-11",dt.o1_pro_2025_03_19="o1-pro-2025-03-19",dt.omni_moderation_2024_09_26="omni-moderation-2024-09-26",dt.gpt_4o="gpt-4o",dt.gpt_4o_mini="gpt-4o-mini",dt.gpt_4o_2024_08_06="gpt-4o-2024-08-06",dt.gpt_4_1="gpt-4.1",dt.gpt_4o_transcribe="gpt-4o-transcribe",dt.gpt_4_1_2025_04_14="gpt-4.1-2025-04-14",dt.gpt_4o_mini_2024_07_18="gpt-4o-mini-2024-07-18",dt.gpt_4o_mini_transcribe="gpt-4o-mini-transcribe",dt.o1_mini="o1-mini",dt.gpt_4o_mini_audio_preview_2024_12_17="gpt-4o-mini-audio-preview-2024-12-17",dt.gpt_3_5_turbo_0125="gpt-3.5-turbo-0125",dt.o1_mini_2024_09_12="o1-mini-2024-09-12",dt.gpt_4_1106_preview="gpt-4-1106-preview",dt.gpt_4o_mini_tts="gpt-4o-mini-tts",dt.omni_moderation_latest="omni-moderation-latest",dt),yt=class{constructor(t){this.apiKeys=t}chat(t,e,...r){let{toPrompt:n}=(()=>{if("function"==typeof t)return{toPrompt:t,args:e};if("string"==typeof t)return{toPrompt:()=>t,args:void 0};if(Array.isArray(t)){let e=0===t.length?[{user:""}]:t;return{toPrompt:()=>e,args:void 0}}{let n=[t,...void 0!==e?[e]:[],...r],i=0===n.length?[{user:""}]:n;return{toPrompt:()=>i,args:void 0}}})();return new Lt(this,n,e,Ct(),void 0,void 0,void 0)}},mt=new yt(void 0);function vt(t){mt.apiKeys=bt(Et(t))}function gt(t){return new yt(bt(Et(t)))}function Et(t){return{promptGridApiKey:(()=>{let e="string"==typeof t?t:t.promptGridApiKey;return lt(e,tt(e).string().orUndefined(),{errorMessage:"Please provide a valid API key; got "+e})})(),apiKeys:"object"==typeof t&&null!==t?t.apiKeys:void 0}}function bt(t){let e=t.promptGridApiKey,r=t.apiKeys,n=void 0!==e?(async()=>{let t=await(async()=>{try{return await fetch(A()+"/handshake",{method:"POST",headers:{"Content-Type":"application/json","User-Agent":"promptgun",Authorization:"Bearer "+e}})}catch{throw Error("HTTP called failed when doing handshake")}})();if(200!==t.status){let e=await t.text();throw Error(`Handshake failed with status ${t.status}, body: ${e}`)}return await t.json()})():void 0;return{promptgrid:e,openai:(async()=>r?.openai??(await n)?.apiKeys.openai)()}}var At=new Map;function Tt(t,e,r,n){if(void 0===mt)throw Error("No LLM set up. Call setupLLM first: ```import { setupPromptGun } from 'promptgun';\n\nsetupPromptGun({openAI: \"YOUR_OPENAI_API_KEY\"});\n```");return function(t,e,r,n,i){let s="object"!=typeof n&&(n??!1),o="object"==typeof n?n:i??{model:"gpt-4o"},a=h.Flux.fromGeneratorFunction((async function*(){console.log("args",JSON.stringify(e)),console.log("promptSupplier",""+r);let{model:n}=o,i=r(e);if("gpt-4o"!==n)throw new Ot(`Model ${n} not supported`);yield*await xt(t,n,i,s,void 0,void 0,void 0,Ct())}));if(!s)return a;let u=U.toJsonTokenFlux(a);return(new $).parse(u)}(mt,t,e,r,n)}function Ut(t){let e=t??mt;if(void 0===e.apiKeys)throw Error("No LLM set up. Call setupPromptGun first: ```import { setupPromptGun } from 'promptgun';\n\nsetupPromptGun({openAI: \"YOUR_OPENAI_API_KEY\"});\n```");return new Nt(e,Ct())}var Nt=class{constructor(t,e){this.aiClient=t,this.callingCodeLine=e}completeChat(t,e){return new Lt(this.aiClient,t,e,Ct(),void 0,void 0,void 0)}},Lt=class{constructor(t,e,r,n,i,s,o){this.aiClient=t,this.promptSupplier=e,this.promptSupplierArgs=r,this.callingCodeLine=n,this.h=i,this.p=s,this.m=o;let a=this;this.generator=async function*(){yield*await xt(a.aiClient,o,a.promptSupplier(a.promptSupplierArgs),!1,a.promptName,i,s,n)}()}generator;promptName;name(t){return this.promptName=t,this}model(t){return this.m=t,this}temperature(t){return this.h=t,this}topP(t){return this.p=t,this}next(...[t]){return this.generator.next(t)}return(t){return this.generator.return(t)}throw(t){return this.generator.throw(t)}[Symbol.asyncIterator](){return this}async then(t,e){try{let e=await this.getResponseAsString();return D(t)?await t(e):e}catch(t){if(D(e))return await e(t);throw t}}async catch(t){try{return await this.getResponseAsString()}catch(e){if(D(t))return t(e);throw e}}async finally(t){try{return await this.getResponseAsString()}finally{t?.()}}get[Symbol.toStringTag](){return"BasicPrompt"}to(t){return new _t(this.aiClient,this.promptSupplier,this.promptSupplierArgs,t,Ct(),this.promptName,this.h,this.p,this.m)}toJson(){return new _t(this.aiClient,this.promptSupplier,this.promptSupplierArgs,void 0,Ct(),this.promptName,this.h,this.p,this.m)}async getResponseAsString(){let t="";for await(let e of this)t+=e;return t}},_t=class extends I{constructor(t,e,r,n,i,s,o,a,u){let l=async function*(){yield*await xt(t,u,e(r),void 0===n||n(tt(void 0)),s,o,a,i)}(),p=h.Flux.fromGenerator(l),c=(new U).processDataBuffer(p);super(),this.aiClient=t,this.promptSupplier=e,this.promptSupplierArgs=r,this.jsonTypeSupplier=n,this.callingCodeLine=i,this.promptName=s,this.h=o,this.p=a,this.m=u;let f=this,d=(new $).parse(c);void 0!==n?d.onProperty("result",(t=>t.onEachExcerpt((t=>{void 0!==t.token&&this.push(t)})))):d.onEachExcerpt((t=>{void 0!==t.token&&this.push(t)})),this.stringGenerator=async function*(){for await(let t of c)void 0!==t.token?d.push(t):void 0!==t.source&&(yield t.source)}(),this.partialJsonGenerator=async function*(){let t="";for await(let e of f.stringGenerator){t+=e;let r=G(t);yield void 0!==n?r?.result:r}}()}stringGenerator;partialJsonGenerator;next(...[t]){return this.partialJsonGenerator.next(t)}return(t){return this.partialJsonGenerator.return(t)}throw(t){return this.partialJsonGenerator.throw(t)}[Symbol.asyncIterator](){return this.partialJsonGenerator}async then(t,e){try{let e=await this.getResponse();return D(t)?await t(e):e}catch(t){if(D(e))return await e(t);throw t}}async catch(t){try{return await this.getResponse()}catch(e){if(D(t))return t(e);throw e}}async finally(t){try{return await this.getResponse()}finally{t?.()}}get[Symbol.toStringTag](){return"BasicPrompt"}name(t){return this.promptName=t,this}model(t){return this.m=t,this}temperature(t){return this.h=t,this}topP(t){return this.p=t,this}async getResponse(){let t=await this.getResponseAsString(),e=this.jsonTypeSupplier,r=F(t),n=void 0!==e?r?.result:r;if(void 0===e)return n;try{return lt(n,e(tt(n)))}catch{return console.debug('AI forgot to pack result in {"result": ...} wrapper, continuing by using complete result'),lt(r,e(tt(n)))}}async getResponseAsString(){let t="";for await(let e of this.stringGenerator)t+=e;return t}};function St(t){return t??"gpt-4o"}async function*xt(t,e,r,n,i,s,o,a){let u=d(await t.apiKeys.openai).canBeString().andNothingElse({errorMessage:"No OpenAI access token set"}),l=function(t){let e=t=>({role:void 0!==t.user?"user":void 0!==t.system?"system":"assistant",content:Y(t.user??t.system??t.assistant)});return"string"==typeof t?[{role:"user",content:t}]:Array.isArray(t)?t.map(e):[e(t)]}(r),h=(()=>{if(!n)return l;let t=(()=>{let t=l.length-1;for(;t>=0&&"user"===l[t].role;)t--;return t})();return[...l.slice(0,t+1),{role:"system",content:Pt(0,n)},...l.slice(t+1)]})(),{fileName:f,lineNumber:w}=a;if(f&&void 0!==w&&Array.from(At.keys()).filter((t=>t.startsWith(f+":"))).map((t=>parseInt(t.split(":")[1],10))).length>1&&!i)throw Error(`Multiple prompts found in ${f}. Please specify a name using .name() method.`);let y={id:i,callingCodeLine:a},m=X(),v=e=>{(async function(t,e){try{if(void 0===e)return;let r=await fetch(A()+"/api/conversations",{method:"PUT",headers:{"Content-Type":"application/json",Authorization:"Bearer "+e},body:JSON.stringify(t)});if(!r.ok)throw Error(`Got ${r.status} when attempting to save conversation, with body: ${await r.text()}`)}catch(t){console.error("Error saving conversation",t)}})(e,t.apiKeys.promptgrid).then()};v({conversationUuid:m,prompt:y,messages:h.map((t=>({messageUuid:X(),role:t.role,content:t.content||""})))});let g=X();v({conversationUuid:m,prompt:y,messages:[{messageUuid:g,role:"assistant",content:""}]});let E=function({model:t,prompt:e,apiToken:r,temperature:n,topP:i,requireJsonResponse:s}){return p.Flux.fromGeneratorFunction((async function*(){let o=new AbortController,a=await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:"Bearer "+r},method:"POST",signal:o.signal,body:JSON.stringify({model:t,messages:e,stream:!0,temperature:n,top_p:i,response_format:s?{type:"json_object"}:void 0})});if(a.status<200||a.status>=300){let t=function(t){try{return JSON.parse(t).error.message}catch{return t}}(await a.text());throw Error("OpenAPI reported: "+t)}if(null===a.body)throw Error("illegal state");let u="";yield*p.Flux.fromReadableStream(a.body,(()=>o.abort())).map((t=>c.decode(t,{stream:!0}))).flatMap((t=>t.replaceAll("data: [DONE]","").replace(/^data: /,"").split("data: "))).map((t=>t.replace(/[\n ]*$/,"").trim())).flatMap((t=>{u+=t;try{let t=JSON.parse(u);return u="",[t]}catch{return console.error("Received partial json chunk: "+t),[]}})).map((t=>t.choices[0])).untilExcl((t=>null!=t.finish_reason)).map((t=>t.delta.content)).filter((t=>void 0!==t))}))}({model:St(e),prompt:h,apiToken:u,temperature:s,topP:o,requireJsonResponse:!1!==n}),b="";yield*E.doOnEach((t=>{b+=t,v({conversationUuid:m,prompt:y,messages:[{messageUuid:g,role:"assistant",content:b}]})}))}function Pt(t,e){{if(!0===e)return"Respond with JSON";let t=e;return"Respond with JSON matching the Typescript-style type spec below, noting\n- when a value can be null if stated explicitly, e.g. 'string | null'\n- an optional property (denoted with squared brackets) is achieved in JSON by not including it, not by setting it to null\n\nThe type:\n"+ht(new nt([],void 0).object((e=>e.has("result",(()=>new ut(t.type,t.value))))))}}var Rt=class extends Error{},Ot=class extends Error{};function Ct(){let t=(Error().stack??"").split("\n").map((t=>t.trim())).filter((t=>t.startsWith("at ")))[2],e=t.match(/[^(]+\([^)]+\)/),{functionName:r,fileName:n,lineNumber:i}=e?t.match("at (?<functionName>[^(]*) ((?<scheme>.*://)?(?<fileName>[^:]*):(?<lineNumber>[0-9]+):(?<colNumber>[0-9]+))").groups:t.match("at (?<scheme>.*://)?(?<fileName>[^:]*):(?<lineNumber>[0-9]+):(?<colNumber>[0-9]+)").groups;return{stacktraceFrame:d(t).canBeString().andNothingElse(),fileName:d(n).canBeString().andNothingElse(),lineNumber:d(parseInt(i)).canBeNumber().andNothingElse(),functionName:d(r).canBeString().canBeUndefined().andNothingElse()}}export{yt as AIClient,wt as AiModel,Lt as BasicPrompt,at as EmptyPropTypeSpec,nt as EmptyTypeSpec,ut as FullPropTypeSpec,it as FullTypeSpec,_t as JsonPrompt,Ot as ModelNotSupportedError,Rt as NoAiCredientialsError,Nt as PromptBase,ot as PropTypeSpec,I as StreamedJsonChildElement,M as StreamedJsonRootElement,st as TypeMemberSpec,rt as TypeSpec,mt as ai,Ct as getCallerFileNameAndLineNumber,gt as newAIClient,bt as obtainAiClientData,G as parsePartialJson,Ut as promptAI,Tt as promptLLM,vt as setupAI};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|