@miso.ai/doggoganger 0.9.1-beta.17 → 0.9.1-beta.19

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.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).doggoganger=e()}(this,(function(){"use strict";function t(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(t=>(t^16*Math.random()>>t/4).toString(16)))}function e(t,e){return null!=e&&e>t?t+Math.floor(Math.random()*(e-t+1)):t}function n(t,n){const r=e(...n),o=[];for(let e=0;r>e;e++)o.push(t());return o}function r(){return Math.random().toString(36).substring(2,10)}function o(t){for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}function s(t){return`https://picsum.photos/seed/${Math.floor(1e3*Math.random())}/${Array.isArray(t)?t.length>1?`${t[0]}/${t[1]}`:""+t[0]:""+t}`}function i(t){const e=new Date(t).toISOString();return e.endsWith("Z")?e.slice(0,-1):e}function a(t,e){return void 0!==e?Math.ceil(t*e):t}function u(){return c()+c()+c()}function c(){return 2*Math.random()-1}function*l(t,e){let n;for(const r of t)n&&(yield*e(n)),n=r;n&&(yield*e(n,!0))}var d=Object.freeze({__proto__:null,formatDatetime:i,gaussRandom:u,id:r,imageUrl:s,iterateWithLastItemSignal:l,randomInt:e,repeat:n,sample:a,shuffle:o,uuid:t}),f=["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","curabitur","vel","hendrerit","libero","eleifend","blandit","nunc","ornare","odio","ut","orci","gravida","imperdiet","nullam","purus","lacinia","a","pretium","quis","congue","praesent","sagittis","laoreet","auctor","mauris","non","velit","eros","dictum","proin","accumsan","sapien","nec","massa","volutpat","venenatis","sed","eu","molestie","lacus","quisque","porttitor","ligula","dui","mollis","tempus","at","magna","vestibulum","turpis","ac","diam","tincidunt","id","condimentum","enim","sodales","in","hac","habitasse","platea","dictumst","aenean","neque","fusce","augue","leo","eget","semper","mattis","tortor","scelerisque","nulla","interdum","tellus","malesuada","rhoncus","porta","sem","aliquet","et","nam","suspendisse","potenti","vivamus","luctus","fringilla","erat","donec","justo","vehicula","ultricies","varius","ante","primis","faucibus","ultrices","posuere","cubilia","curae","etiam","cursus","aliquam","quam","dapibus","nisl","feugiat","egestas","class","aptent","taciti","sociosqu","ad","litora","torquent","per","conubia","nostra","inceptos","himenaeos","phasellus","nibh","pulvinar","vitae","urna","iaculis","lobortis","nisi","viverra","arcu","morbi","pellentesque","metus","commodo","ut","facilisis","felis","tristique","ullamcorper","placerat","aenean","convallis","sollicitudin","integer","rutrum","duis","est","etiam","bibendum","donec","pharetra","vulputate","maecenas","mi","fermentum","consequat","suscipit","aliquam","habitant","senectus","netus","fames","quisque","euismod","curabitur","lectus","elementum","tempor","risus","cras"];function p({decorates:t=[],output:e="string",size:n,min:r,max:o,...s}={}){let i=y(n||[r,o])(g(s));for(const e of t)i=h(e)(i);return h(e)(i)}const m={string:_,array:w,title:v,description:$,multiline:b};function h(t){switch(typeof t){case"string":return m[t]();case"function":return t;case"object":if(Array.isArray(t)){const[e,n={}]=t;return m[e](n)}}throw Error("Unrecognized decorator/output form: "+t)}function*g({words:t=f,fixedStarts:e=0}={}){const n=t.length;for(let r=0;;r++)yield t[e>r?r:Math.floor(Math.random()*n)]}function _({separator:t=" "}={}){return e=>[...e].join(t)}function w(){return t=>[...t]}function b({wordsPerLine:t={avg:10,std:3,min:1}}={}){return e=>{let n=q(t),r="";for(let o of e)r&&(0==n--?(r+="\n",n=q(t)):r+=" "),r+=o;return r}}function y(t=[5,10]){const n="number"==typeof t?t:e(...t);return function*(t){let e=0;for(let r of t){if(e++>=n)break;yield r}}}function v({}={}){return function*(t){for(let e of t)yield z(e)}}function $({wordsPerSentence:t={avg:24,std:5,min:1},punctuation:e="."}={}){return function*(n){let r=0;yield*l(n,(function*(n,o){0===r&&(n=z(n),r=q(t)),(0==--r||o)&&(n+=e),yield n}))}}function z(t){return t[0].toUpperCase()+t.substring(1)}function q(t){if("number"==typeof t)return Math.round(e);let{avg:e,std:n,min:r,max:o}=t;void 0===n&&(n=e/4);let s=u()*n+e;return void 0!==r&&(s=Math.max(r,s)),void 0!==o&&(s=Math.min(o,s)),Math.round(s)}var M=Object.freeze({__proto__:null,array:w,base:g,description:$,limit:y,lorem:p,multiline:b,string:_,title:v});const x="// module\nimport { a, b } from './module';\nimport * as module from './module';\nimport module from './module';\nexport default module;\nexport const a = 0;\nexport * from './module';\nexport * as module from './module';\n\n// variables\nlet a = 10;\nconst b = 20;\n\n// function declaration\nfunction sum(x, y) {\n return x + y;\n}\n\n// generator function\nfunction* iterator() {\n yield 0;\n yield 1;\n}\n\n// arrow function\nconst multiply = (x, y) => x * y;\n\n// class\nclass Person {\n constructor(name, age) {\n this.name = name;\n this.age = age;\n }\n\n greet() {\n console.log('Hello, my name is Miso.');\n }\n}\n\n// primitive\nconst str = 'Hello, world!';\nconst num = 10.99;\n\n// object\nconst person = new Person('John', 30);\nperson.greet();\n\n// object literal\nconst object = {\n name: 'John',\n [x]: 10,\n ...props,\n};\n\n// array literal\nconst arr = [1, 2, 3, 4, 5, ...props];\n\n// regexp literal\nconst regexp = /\\w+/g;\n\n// operators\nconst sum = a + b;\nconst product = a * b;\nconst negation = -a;\nconst max = a > b ? a : b;\n\n// flow control\nlet i = 9;\nfor (const n of arr) {\n if (n > i) {\n console.log(n);\n }\n i++;\n}\n\n// async/await\n(async () => {\n const result = await asyncFunction();\n})();\n\n// try/catch\ntry {\n} catch (e) {\n}\n\n// destructuring\nconst { name, age, ...rest } = person;\nconst [ x, y, ...rest ] = arr;\n\n// template literals\nconsole.log(`The sum of ${a} and ${b} is ${sum(a, b)}.`);";var j=Object.freeze({__proto__:null,javascript:function(){return x},js:function(){return x}});function k({sources:t,citation:e,features:n,blocks:r=[8,12],sampling:o=1}={}){let s=[];[s,n]=function(t=[]){const e=new Set,n=[];for(const r of t)if(r.startsWith("lang-")){let t=r.slice(5);"javascript"===t&&(t="js"),e.add(t)}else n.push(r);return[[...e],n]}(n);let i=function(t,e){const n=[];for(const r of t)1>e&&Math.random()>=e||n.push(r());return n}([()=>O({features:n}),()=>C({sources:t,citation:e,features:n}),...s.map((t=>()=>A({lang:t,features:n}))),...s.length?[]:[()=>A({features:n})],()=>C({sources:t,citation:e,features:n}),()=>D({features:n}),()=>I(),()=>C({sources:t,citation:e,features:n}),()=>S(),()=>O({features:n}),()=>C({sources:t,citation:e,features:n}),()=>T({features:n}),()=>C({sources:t,citation:e,features:n})],o).join("\n\n");if(e&&e.unused&&e.unused.length){const n=[...e.unused];n.sort(((t,e)=>t-e)),i+=n.map((n=>Q(e,t[n]))).join("")}return i}function S(){return"*-_".charAt(e(0,2)).repeat(e(3,6))}function O({level:t=[1,6],size:n=[1,8],content:r}){const o=r||p({size:n});return`${"#".repeat(e(...t))} ${o}`}function A({lang:t,content:n,size:r,fenceChar:o="`"}){return"random"===o&&(o="`~".charAt(e(0,1))),n=n||K({lang:t,size:r}),`${o.repeat(3)}${t||""}\n${n}\n${o.repeat(3)}`}function C({sources:t,citation:e,size:n=[20,50]}){const r=["description",E()];return t&&e&&r.push(R(t,e)),p({size:n,decorates:r})}function D({columns:t=[2,4],rows:n=[2,8]}){t=e(...t),n=e(...n);const r=[...N({size:1},t-1),{size:[3,8]}],o=[p({size:t,output:"array"}),r.map((()=>"---"))];for(let t=0;n-1>t;t++)o.push(r.map((({size:t})=>p({size:t}))));return o.map(G).join("\n")}function I({url:t,imageSize:e=[400,250],...n}={}){return t=t||s(e),`![${W(n)}](${t})`}const F=["ordered","bullet","task"];function T({features:t,type:n="random",count:r=[1,8],size:o=[5,15]}){r="number"==typeof r?r:e(...r);const s="random"===n?F[Math.floor(3*Math.random())]:n,i=[];for(;r>0;){const a=e(1,r);let u=C({features:t,size:o});a>1&&(u+="\n"+T({features:t,type:n,count:a-1,size:o})),i.push(J(s,u)),r-=a}return i.join("\n")}const L={"code-span":()=>["`","`"],"emphasis-1":()=>N(H(1),2),"emphasis-2":()=>N(H(2),2),"emphasis-3":()=>N(H(3),2),strikethrough:()=>["~","~"],link:({url:t="https://miso.ai"}={})=>["[",`](${t})`]};function H(t=[1,3]){return t="number"==typeof t?t:e(...t),"_*".charAt(e(0,1)).repeat(t)}const P=Object.keys(L),U=new Set(P);function E({features:t=P,size:n=[1,3],rest:r=[0,8]}={}){t=t.filter((t=>U.has(t)));const s=o([...t]);let i=s.length-1;const a=()=>"number"==typeof r?r:e(...r);return function*(r){let o,u=a();yield*l(r,(function*(r,c){if(!o&&0===u){const[a,c]=L[0>i?t[e(0,t.length-1)]:s[i--]]();r=`${a}${r}`,u="number"==typeof n?n:e(...n),o=c}if(u--,o){const t=r.length,e=r.charAt(t-1);"."===(l=e)||","===l||"!"===l||"?"===l||":"===l||";"===l?(r=`${r.substring(0,t-1)}${o}${e}`,o=void 0,u=a()):(c||0===u)&&(r=`${r}${o}`,o=void 0,u=a())}var l;yield r}))}}function R(t,{density:n=.667,unused:r,...o}){const s=t.length;return function*(i){for(const a of i)"."===a.charAt(a.length-1)&&Math.random()<n?yield`${a}${Q(o,t[r&&r.length?r.pop():e(0,s-1)])}`:yield a}}function W({size:t=[1,3],content:e}={}){return e||p({size:t})}function B(t,e){return e.split("\n").map((e=>" ".repeat(t)+e)).join("\n")}function J(t,e){const[n,r]=e.split("\n",2),o=`${function(t,e="random"){switch(t){case"ordered":return"1.";case"bullet":return"-";case"task":return`- [${("random"===e?.5>Math.random():e)?"x":" "}]`;default:throw Error("unknown list item type: "+t)}}(t)} ${n}`;return r?o+"\n"+B("ordered"===t?3:2,r):o}function K({lang:t,size:e=[10,30]}){return t&&j[t]?j[t]():p({output:"multiline",size:e})}function G(t){return`| ${t.join(" | ")} |`}function N(t,e){const n=[];for(let r=0;e>r;r++)n.push("function"==typeof t?t():t);return n}function Q({link:t,start:e,end:n},{index:r,url:o}){return t?`[${e}${r}${n}](${o})`:`${e}${r}${n}`}var V=Object.freeze({__proto__:null,atxHeading:O,blockquote:function({size:t=[3,5]}){return p({size:t}).split("\n").map((t=>"> "+t)).join("\n")},codeSpan:function(t){return`\`${W(t)}\``},decorateCitation:R,decorateInlineFeatures:E,emphasis:function({level:t=[1,3],options:n}){t="number"==typeof t?t:e(...t);const r="_*".charAt(e(0,1)).repeat(t);return`${r}${W(n)}${r}`},fencedCodeBlock:A,hr:S,image:I,indent:B,indentedCodeBlock:function({lang:t,content:e,size:n}){return B(4,e=e||K({lang:t,size:n}))},link:function({url:t="https://miso.ai",...e}={}){return`[${W(e)}](${t})`},linkReferenceDefinition:function({label:t,destination:e,title:n}){return`[${t}]: ${e}${void 0!==n?" "+n:""}`},list:T,listItem:J,markdown:k,paragraph:C,setextHeading:function({level:t=[1,2],size:n=[1,8],content:r}){return`${r||p({size:n})}\n${"=-".charAt(e(...t)-1).repeat(3)}`},table:D});const Z=864e5,X=7*Z;function Y({}={}){const t=Date.now()-Z,e=t-8*X;return new Date(e+Math.random()*(t-e)).toISOString()}function tt({size:t=300}={}){return s(t)}function et({size:t=[1,3]}={}){return p({size:t,decorates:["title"],output:"array"})}function nt({size:t=[1,4]}={}){return p({size:t,output:"array"})}function rt({size:t=[2,6]}={}){return p({size:t,decorates:["title"]})}function ot({size:t=[10,20],...e}={}){return p({size:t,decorates:[Object.keys(e).length?["description",e]:"description"]})}function st({paragraphs:t=8,sections:e,paragraph:n,image:r}={}){n={size:[30,60],...n},r={size:[480,270],...r},void 0===e&&(e=Math.floor(t*(1+Math.random())/4));const o=[],s=t/(e=Math.max(1,Math.min(e,t)));let i=0;for(let t=0;e>t;t++){for(t>0&&o.push(`<h4>${rt()}</h4>`);i++<(t+1)*s;)o.push(`<p>${ot(n)}</p>`);o.push(`<div class="image-container"><img src="${tt(r)}"></div>`)}return o.join("")}function it(){return Math.random()>.3?"IN_STOCK":"OUT_OF_STOCK"}function at(){return Math.floor(1e4*Math.random())/100}function ut(){return Math.floor(500*Math.random())/100+1}function ct({sources:t,format:e,citation:n,sampling:r,features:o}){if("markdown"===e){let e=1;return k({sources:t=t.map((({url:t})=>({url:t,index:e++}))),citation:n,sampling:r,features:o})}return p({min:a(50,r),max:a(50,r),decorates:["description"]})}var lt=Object.freeze({__proto__:null,answer:ct,authors:et,availability:it,date:Y,description:ot,html:st,image:tt,price:at,rating:ut,tags:nt,title:rt});function*dt({rows:t,...e}={}){for(let n=0;t>n;n++)yield ft({...e,index:n})}function ft({}={}){const t=r(),e=n(at,[1,2]);return e.sort(),{product_id:t,authors:et(),categories:[],tags:nt(),title:rt(),description:ot(),cover_image:tt(),url:"https://dummy.miso.ai/products/"+t,sale_price:e[0],original_price:e[e.length-1],rating:ut(),availability:it()}}const pt=new Set(["cover_image","url","created_at","updated_at","published_at"]);function*mt({rows:t,...e}={}){for(let n=0;t>n;n++)yield ht({...e,index:n})}function ht({html:t,fl:e=[]}={}){const n={product_id:r(),authors:et(),categories:[],tags:nt(),title:rt({size:[4,10]}),snippet:ot({size:[20,40]}),html:st(t)};for(const t of e)pt.has(t)&&(n[t]=gt(n,t));return n}function gt({product_id:t},e){switch(e){case"cover_image":return tt();case"url":return"/products/"+t;case"created_at":case"updated_at":case"published_at":return Y()}}function*_t({rows:t=5,...e}={}){for(let n=0;t>n;n++)yield wt({...e,index:n})}function wt({}={}){return ot({size:[4,8],punctuation:"?"})}function bt({question:e,parent_question_id:n,source_fl:r=["cover_image","url"],related_resource_fl:s=["cover_image","url"],cite_link:a=!1,cite_start:u="[",cite_end:c="]",timestamp:l=Date.now()},{answerFormat:d="markdown",answerSampling:f,answerLanguages:p=[]}={}){const m=t(),h=i(l),g=void 0!==f?Math.max(0,Math.min(1,f)):void 0,_=p.length?p.map((t=>"lang-"+t)):void 0,w=[...mt({rows:yt(6,8,g),fl:s})].map(vt),b=[...mt({rows:yt(4,6,g),fl:r})].map(vt);return{question:e,question_id:m,...n&&{parent_question_id:n},datetime:h,answer:ct({sources:b,citation:{link:"0"!==a&&!!a,start:u,end:c,unused:o([...Array(b.length).keys()])},format:d,sampling:g,features:_}),sources:b,related_resources:w,followup_questions:[..._t({rows:yt(3,6)})]}}function yt(t,n,r){return e(a(t,r),a(n,r))}function vt({html:t,...e}){return e}var $t=Object.freeze({__proto__:null,answer:bt,articles:mt,fields:lt,lorem:M,md:V,products:dt,questions:_t,utils:d});const zt=[{name:"fetch",duration:1.5,text:"Checking the question and fetching results... "},{name:"verify",duration:1.5,text:"Verifying results... "},{name:"generate",duration:1.5,text:"Generating answer... "}];class qt{constructor(t={}){this._options=t,this._answers=new Map}questions(t,e={}){const n=new Mt(t,{...this._options,...e}),{question_id:r}=n;return this._answers.set(r,n),{question_id:r}}answer(t){const e=this._answers.get(t);if(!e){const e=Error("Question not found: "+t);throw e.status=404,e}return e.get()}related_questions(t){return{related_questions:[..._t(t)]}}}class Mt{constructor(t,{answerFormat:e,answerSampling:n,answerLanguages:r,...o}={}){this._options=Object.freeze(o);const s=this.timestamp=Date.now();this._data=bt({...t,timestamp:s},{answerFormat:e,answerSampling:n,answerLanguages:r})}get question_id(){return this._data.question_id}get(){const t=(Date.now()-this.timestamp)*(this._options.speedRate||1)/1e3,[e,n,r]=this._answer(t),o=this._sources(t,r),s=this._related_resources(t,r),i=this._followup_questions(t,r),{question_id:a,question:u,datetime:c,parent_question_id:l}=this._data;return{answer:n,answer_stage:e,datetime:c,finished:r,parent_question_id:l,question:u,question_id:a,sources:o,related_resources:s,followup_questions:i}}_answer(t){for(const e of zt)if(0>(t-=e.duration))return[e.name,e.text,!1];const{answer:e}=this._data,n=Math.floor(100*t),r=n>=e.length;return["result",r?e:e.slice(0,n),r]}_sources(t,e){const{sources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_related_resources(t,e){const{related_resources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_followup_questions(t,e){const{followup_questions:n}=this._data;if(e||!n)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}}class xt{constructor(t){this._options=t}search({rows:t=5}){return{products:[...dt({rows:t})]}}}class jt{constructor(t){this._options=t}user_to_products({rows:t=5}){return{products:[...dt({rows:t})]}}product_to_products({rows:t=5}){return{products:[...dt({rows:t})]}}}class kt{constructor(t){this._options=t}upload(t){return[]}}class St{constructor(t){this._options=t}upload(t){return[]}ids(){const t=[];for(let e=0;5e3>e;e++)t.push(Ot(e));return{ids:t}}}function Ot(t){return`${10>t?"p_000":100>t?"p_00":1e3>t?"p_0":"p_"}${t}`}class At{constructor(t){this.ask=new qt(t),this.search=new xt(t),this.recommendation=new jt(t),this.interactions=new kt(t),this.products=new St(t)}}return{buildApi:(...t)=>new At(...t),data:$t}}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).doggoganger=e()}(this,function(){"use strict";function t(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(t^16*Math.random()>>t/4).toString(16))}function e(t,e){return null!=e&&e>t?t+Math.floor(Math.random()*(e-t+1)):t}function n(t,n){const r=e(...n),o=[];for(let e=0;r>e;e++)o.push(t());return o}function r(){return Math.random().toString(36).substring(2,10)}function o(t){for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}function s(t){return`https://picsum.photos/seed/${Math.floor(1e3*Math.random())}/${Array.isArray(t)?t.length>1?`${t[0]}/${t[1]}`:""+t[0]:""+t}`}function i(t,e){return void 0!==e?Math.ceil(t*e):t}function a(){return u()+u()+u()}function u(){return 2*Math.random()-1}function*c(t,e){let n;for(const r of t)n&&(yield*e(n)),n=r;n&&(yield*e(n,!0))}function l({html:t,...e}){return e}var d=Object.freeze({__proto__:null,excludeHtml:l,formatDatetime:function(t){const e=new Date(t).toISOString();return e.endsWith("Z")?e.slice(0,-1):e},gaussRandom:a,id:r,imageUrl:s,iterateWithLastItemSignal:c,randomInt:e,repeat:n,rollLatency:function(t,e){return(t+e)/2+a()*(e-t)/6},sample:i,shuffle:o,uuid:t}),f=["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","curabitur","vel","hendrerit","libero","eleifend","blandit","nunc","ornare","odio","ut","orci","gravida","imperdiet","nullam","purus","lacinia","a","pretium","quis","congue","praesent","sagittis","laoreet","auctor","mauris","non","velit","eros","dictum","proin","accumsan","sapien","nec","massa","volutpat","venenatis","sed","eu","molestie","lacus","quisque","porttitor","ligula","dui","mollis","tempus","at","magna","vestibulum","turpis","ac","diam","tincidunt","id","condimentum","enim","sodales","in","hac","habitasse","platea","dictumst","aenean","neque","fusce","augue","leo","eget","semper","mattis","tortor","scelerisque","nulla","interdum","tellus","malesuada","rhoncus","porta","sem","aliquet","et","nam","suspendisse","potenti","vivamus","luctus","fringilla","erat","donec","justo","vehicula","ultricies","varius","ante","primis","faucibus","ultrices","posuere","cubilia","curae","etiam","cursus","aliquam","quam","dapibus","nisl","feugiat","egestas","class","aptent","taciti","sociosqu","ad","litora","torquent","per","conubia","nostra","inceptos","himenaeos","phasellus","nibh","pulvinar","vitae","urna","iaculis","lobortis","nisi","viverra","arcu","morbi","pellentesque","metus","commodo","ut","facilisis","felis","tristique","ullamcorper","placerat","aenean","convallis","sollicitudin","integer","rutrum","duis","est","etiam","bibendum","donec","pharetra","vulputate","maecenas","mi","fermentum","consequat","suscipit","aliquam","habitant","senectus","netus","fames","quisque","euismod","curabitur","lectus","elementum","tempor","risus","cras"];function m({decorates:t=[],output:e="string",size:n,min:r,max:o,...s}={}){let i=v(n||[r,o])(_(s));for(const e of t)i=h(e)(i);return h(e)(i)}const p={string:g,array:w,title:y,description:z,multiline:b};function h(t){switch(typeof t){case"string":return p[t]();case"function":return t;case"object":if(Array.isArray(t)){const[e,n={}]=t;return p[e](n)}}throw Error("Unrecognized decorator/output form: "+t)}function*_({words:t=f,fixedStarts:e=0}={}){const n=t.length;for(let r=0;;r++)yield t[e>r?r:Math.floor(Math.random()*n)]}function g({separator:t=" "}={}){return e=>[...e].join(t)}function w(){return t=>[...t]}function b({wordsPerLine:t={avg:10,std:3,min:1}}={}){return e=>{let n=q(t),r="";for(let o of e)r&&(0===n--?(r+="\n",n=q(t)):r+=" "),r+=o;return r}}function v(t=[5,10]){const n="number"==typeof t?t:e(...t);return function*(t){let e=0;for(let r of t){if(e++>=n)break;yield r}}}function y({}={}){return function*(t){for(let e of t)yield $(e)}}function z({wordsPerSentence:t={avg:24,std:5,min:1},punctuation:e="."}={}){return function*(n){let r=0;yield*c(n,function*(n,o){0===r&&(n=$(n),r=q(t)),(0===--r||o)&&(n+=e),yield n})}}function $(t){return t[0].toUpperCase()+t.substring(1)}function q(t){if("number"==typeof t)return Math.round(e);let{avg:e,std:n,min:r,max:o}=t;void 0===n&&(n=e/4);let s=a()*n+e;return void 0!==r&&(s=Math.max(r,s)),void 0!==o&&(s=Math.min(o,s)),Math.round(s)}var M=Object.freeze({__proto__:null,array:w,base:_,description:z,limit:v,lorem:m,multiline:b,string:g,title:y});const x="// module\nimport { a, b } from './module';\nimport * as module from './module';\nimport module from './module';\nexport default module;\nexport const a = 0;\nexport * from './module';\nexport * as module from './module';\n\n// variables\nlet a = 10;\nconst b = 20;\n\n// function declaration\nfunction sum(x, y) {\n return x + y;\n}\n\n// generator function\nfunction* iterator() {\n yield 0;\n yield 1;\n}\n\n// arrow function\nconst multiply = (x, y) => x * y;\n\n// class\nclass Person {\n constructor(name, age) {\n this.name = name;\n this.age = age;\n }\n\n greet() {\n console.log('Hello, my name is Miso.');\n }\n}\n\n// primitive\nconst str = 'Hello, world!';\nconst num = 10.99;\n\n// object\nconst person = new Person('John', 30);\nperson.greet();\n\n// object literal\nconst object = {\n name: 'John',\n [x]: 10,\n ...props,\n};\n\n// array literal\nconst arr = [1, 2, 3, 4, 5, ...props];\n\n// regexp literal\nconst regexp = /\\w+/g;\n\n// operators\nconst sum = a + b;\nconst product = a * b;\nconst negation = -a;\nconst max = a > b ? a : b;\n\n// flow control\nlet i = 9;\nfor (const n of arr) {\n if (n > i) {\n console.log(n);\n }\n i++;\n}\n\n// async/await\n(async () => {\n const result = await asyncFunction();\n})();\n\n// try/catch\ntry {\n} catch (e) {\n}\n\n// destructuring\nconst { name, age, ...rest } = person;\nconst [ x, y, ...rest ] = arr;\n\n// template literals\nconsole.log(`The sum of ${a} and ${b} is ${sum(a, b)}.`);";const j='<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>Sample Page</title>\n <link rel="stylesheet" href="styles.css">\n</head>\n<body>\n <header>\n <nav>\n <a href="/">Home</a>\n <a href="/about">About</a>\n </nav>\n </header>\n\n <main>\n <h1>Welcome</h1>\n <p>This is a <strong>sample</strong> paragraph with <em>emphasis</em>.</p>\n\n <ul>\n <li>Item 1</li>\n <li>Item 2</li>\n </ul>\n\n <form action="/submit" method="post">\n <label for="name">Name:</label>\n <input type="text" id="name" name="name" required>\n <button type="submit">Submit</button>\n </form>\n\n <table>\n <thead>\n <tr>\n <th>Name</th>\n <th>Value</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>Alpha</td>\n <td>100</td>\n </tr>\n </tbody>\n </table>\n </main>\n\n <footer>\n <p>&copy; 2024 Example</p>\n </footer>\n\n <script src="main.js"><\/script>\n</body>\n</html>';var k=Object.freeze({__proto__:null,html:function(){return j},javascript:function(){return x},js:function(){return x}});function S({sources:t,citation:e,features:n,blocks:r=[8,12],sampling:o=1}={}){let s=[];[s,n]=function(t=[]){const e=new Set,n=[];for(const r of t)if(r.startsWith("lang-")){let t=r.slice(5);"javascript"===t&&(t="js"),e.add(t)}else n.push(r);return[[...e],n]}(n);let i=function(t,e){const n=[];for(const r of t)1>e&&Math.random()>=e||n.push(r());return n}([()=>O({features:n}),()=>C({sources:t,citation:e,features:n}),...s.map(t=>()=>D({lang:t,features:n})),...s.length?[]:[()=>D({features:n})],()=>C({sources:t,citation:e,features:n}),()=>I({features:n}),()=>T(),()=>C({sources:t,citation:e,features:n}),()=>A(),()=>P(),()=>O({features:n}),()=>C({sources:t,citation:e,features:n}),()=>F({features:n}),()=>C({sources:t,citation:e,features:n})],o).join("\n\n");if(e&&e.unused&&e.unused.length){const n=[...e.unused];n.sort((t,e)=>t-e),i+=n.map(n=>Y(e,t[n])).join("")}return i}function A(){return"*-_".charAt(e(0,2)).repeat(e(3,6))}function O({level:t=[1,6],size:n=[1,8],content:r}){const o=r||m({size:n});return`${"#".repeat(e(...t))} ${o}`}function D({lang:t,content:n,size:r,fenceChar:o="`"}){return"random"===o&&(o="`~".charAt(e(0,1))),n=n||K({lang:t,size:r}),`${o.repeat(3)}${t||""}\n${n}\n${o.repeat(3)}`}function C({sources:t,citation:e,size:n=[20,50]}){const r=["description",V()];return t&&e&&r.push(W(t,e)),m({size:n,decorates:r})}function I({columns:t=[2,4],rows:n=[2,8]}){t=e(...t),n=e(...n);const r=[...Q({size:1},t-1),{size:[3,8]}],o=[m({size:t,output:"array"}),r.map(()=>"---")];for(let t=0;n-1>t;t++)o.push(r.map(({size:t})=>m({size:t})));return o.map(G).join("\n")}function T({url:t,imageSize:e=[400,250],...n}={}){return t=t||s(e),`![${B(n)}](${t})`}const H=["ordered","bullet","task"];function F({features:t,type:n="random",count:r=[1,8],size:o=[5,15]}){r="number"==typeof r?r:e(...r);const s="random"===n?H[Math.floor(3*Math.random())]:n,i=[];for(;r>0;){const a=e(1,r);let u=C({features:t,size:o});a>1&&(u+="\n"+F({features:t,type:n,count:a-1,size:o})),i.push(J(s,u)),r-=a}return i.join("\n")}function P({}={}){return'<div><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calculator" viewBox="0 0 16 16"><path d="M12 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM4 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/><path d="M4 2.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-.5.5h-7a.5.5 0 0 1-.5-.5zm0 4a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3-6a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3-6a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm0 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5z"/></svg></div>'}const E={"code-span":()=>["`","`"],"emphasis-1":()=>Q(L(1),2),"emphasis-2":()=>Q(L(2),2),"emphasis-3":()=>Q(L(3),2),strikethrough:()=>["~","~"],link:({url:t="https://miso.ai"}={})=>["[",`](${t})`]};function L(t=[1,3]){return t="number"==typeof t?t:e(...t),"_*".charAt(e(0,1)).repeat(t)}const U=Object.keys(E),R=new Set(U);function V({features:t=U,size:n=[1,3],rest:r=[0,8]}={}){t=t.filter(t=>R.has(t));const s=o([...t]);let i=s.length-1;const a=()=>"number"==typeof r?r:e(...r);return function*(r){let o,u=a();yield*c(r,function*(r,c){if(!o&&0===u){const[a,c]=E[0>i?t[e(0,t.length-1)]:s[i--]]();r=`${a}${r}`,u="number"==typeof n?n:e(...n),o=c}if(u--,o){const t=r.length,e=r.charAt(t-1);"."===(l=e)||","===l||"!"===l||"?"===l||":"===l||";"===l?(r=`${r.substring(0,t-1)}${o}${e}`,o=void 0,u=a()):(c||0===u)&&(r=`${r}${o}`,o=void 0,u=a())}var l;yield r})}}function W(t,{density:n=.667,unused:r,...o}){const s=t.length,i=()=>r&&r.length?r.pop():e(0,s-1);return function*(e){for(const r of e)"."===r.charAt(r.length-1)&&Math.random()<n?yield`${r}${Y(o,t[i()])}`:yield r}}function B({size:t=[1,3],content:e}={}){return e||m({size:t})}function N(t,e){return e.split("\n").map(e=>" ".repeat(t)+e).join("\n")}function J(t,e){const[n,r]=e.split("\n",2),o=`${function(t,e="random"){switch(t){case"ordered":return"1.";case"bullet":return"-";case"task":return`- [${("random"===e?.5>Math.random():e)?"x":" "}]`;default:throw Error("unknown list item type: "+t)}}(t)} ${n}`;return r?o+"\n"+N("ordered"===t?3:2,r):o}function K({lang:t,size:e=[10,30]}){return t&&k[t]?k[t]():m({output:"multiline",size:e})}function G(t){return`| ${t.join(" | ")} |`}function Q(t,e){const n=[];for(let r=0;e>r;r++)n.push("function"==typeof t?t():t);return n}function Y({link:t,start:e,end:n},{index:r,url:o}){return t?`[${e}${r}${n}](${o})`:`${e}${r}${n}`}var Z=Object.freeze({__proto__:null,atxHeading:O,blockquote:function({size:t=[3,5]}){return m({size:t}).split("\n").map(t=>"> "+t).join("\n")},codeSpan:function(t){return`\`${B(t)}\``},decorateCitation:W,decorateInlineFeatures:V,emphasis:function({level:t=[1,3],options:n}){t="number"==typeof t?t:e(...t);const r="_*".charAt(e(0,1)).repeat(t);return`${r}${B(n)}${r}`},fencedCodeBlock:D,hr:A,html:P,image:T,indent:N,indentedCodeBlock:function({lang:t,content:e,size:n}){return N(4,e=e||K({lang:t,size:n}))},link:function({url:t="https://miso.ai",...e}={}){return`[${B(e)}](${t})`},linkReferenceDefinition:function({label:t,destination:e,title:n}){return`[${t}]: ${e}${void 0!==n?" "+n:""}`},list:F,listItem:J,markdown:S,paragraph:C,setextHeading:function({level:t=[1,2],size:n=[1,8],content:r}){return`${r||m({size:n})}\n${"=-".charAt(e(...t)-1).repeat(3)}`},table:I});const X=864e5,tt=7*X;function et({}={}){const t=Date.now()-X,e=t-8*tt;return new Date(e+Math.random()*(t-e)).toISOString()}function nt({size:t=300}={}){return s(t)}function rt({size:t=[1,3]}={}){return m({size:t,decorates:["title"],output:"array"})}function ot({size:t=[1,4]}={}){return m({size:t,output:"array"})}function st({size:t=[2,6]}={}){return m({size:t,decorates:["title"]})}function it({}){const t=Math.random();return m({size:.7>t?1:.9>t?2:3,decorates:["title"]})}function at({size:t=[10,20],...e}={}){return m({size:t,decorates:[Object.keys(e).length?["description",e]:"description"]})}function ut({paragraphs:t=8,sections:e,paragraph:n,image:r}={}){n={size:[30,60],...n},r={size:[480,270],...r},void 0===e&&(e=Math.floor(t*(1+Math.random())/4));const o=[],s=t/(e=Math.max(1,Math.min(e,t)));let i=0;for(let t=0;e>t;t++){for(t>0&&o.push(`<h4>${st()}</h4>`);i++<(t+1)*s;)o.push(`<p>${at(n)}</p>`);o.push(`<div class="image-container"><img src="${nt(r)}"></div>`)}return o.join("")}function ct(){return Math.random()>.3?"IN_STOCK":"OUT_OF_STOCK"}function lt(){return Math.floor(1e4*Math.random())/100}function dt(){return Math.floor(500*Math.random())/100+1}function ft({sources:t,format:e,citation:n,sampling:r,features:o}){if("markdown"===e){let e=1;return S({sources:t=t.map(({url:t})=>({url:t,index:e++})),citation:n,sampling:r,features:o})}return m({min:i(50,r),max:i(50,r),decorates:["description"]})}var mt=Object.freeze({__proto__:null,answer:ft,authors:rt,availability:ct,date:et,description:at,html:ut,image:nt,price:lt,rating:dt,tags:ot,term:it,title:st});function*pt({rows:t,...e}={}){for(let n=0;t>n;n++)yield ht({...e,index:n})}function ht({}={}){const t=r(),e=n(lt,[1,2]);return e.sort(),{product_id:t,authors:rt(),categories:[],tags:ot(),title:st(),description:at(),cover_image:nt(),url:"https://dummy.miso.ai/products/"+t,sale_price:e[0],original_price:e[e.length-1],rating:dt(),availability:ct()}}const _t=new Set(["cover_image","url","created_at","updated_at","published_at"]);function*gt({rows:t,...e}={}){for(let n=0;t>n;n++)yield wt({...e,index:n})}function wt({html:t,fl:e=[]}={}){const n={product_id:r(),authors:rt(),categories:[],tags:ot(),title:st({size:[4,10]}),snippet:at({size:[20,40]}),html:ut(t)};for(const t of e)_t.has(t)&&(n[t]=bt(n,t));return n}function bt({product_id:t},e){switch(e){case"cover_image":return nt();case"url":return"/products/"+t;case"created_at":case"updated_at":case"published_at":return et()}}function*vt({rows:t=5,...e}={}){for(let n=0;t>n;n++)yield yt({...e,index:n})}function yt({}={}){return at({size:[4,8],punctuation:"?"})}function*zt({rows:t,...e}={}){for(let n=0;t>n;n++)yield $t({...e,index:n})}function $t({fl:t=[]}={}){const e=r();return{product_id:e,image_src:nt({size:[1200,400]}),image_alt:st({size:[2,4]}),title:st({size:[4,10]}),url:"/products/"+e,created_at:et(),updated_at:et(),published_at:et()}}const qt=5,Mt=[1e3,5e3],xt=[.75,.25];function jt({facets:t,...e}={}){const n={};for(let r of t)"string"==typeof r&&(r={field:r}),n[r.field]=kt(r,e);return n}function kt(t,{_ctrl:e={},...n}={}){let{field:r,size:o=qt}=t;o=0===e.total?0:Math.max(1,Math.min(o,10));let s=function(){const[t,e]=Mt;return Math.ceil(Math.random()*(e-t)+t)}();const i=new Set,a=[];for(let t=0;o>t;t++)a.push([St(r,i),s]),s=At(s);return a}function St(t,e){if(e.size>50)return it({field:t});for(;;){const n=it({field:t});if(!e.has(n))return e.add(n),n}}function At(t,e,n){const[r,o]=xt,s=Math.random()*(o-r)+r;return Math.ceil(t*s)}const{randomInt:Ot,formatDatetime:Dt,sample:Ct,uuid:It,shuffle:Tt,excludeHtml:Ht}=d;function Ft({_ctrl:t={},question:e,parent_question_id:n,fl:r=["cover_image","url"],source_fl:o=["cover_image","url"],related_resource_fl:s=["cover_image","url"],cite_link:i=!1,cite_start:a="[",cite_end:u="]",rows:c=10,facets:l,timestamp:d=Date.now(),_meta:{page:f=0}={}},{answerFormat:m="markdown",answerSampling:p,answerLanguages:h=[]}={}){const _=It(),g=Dt(d),w=void 0!==p?Math.max(0,Math.min(1,p)):void 0,b=h.length?h.map(t=>"lang-"+t):void 0,v=[...gt({rows:Pt(6,8,w),fl:s})].map(Ht),y=[...zt({rows:Pt(2,12,w)})],z=[...gt({rows:Pt(4,6,w),fl:o})].map(Ht),$=void 0!==t.total?t.total:Ot(1e3,1e4),q=[...gt({rows:Math.min($-f*c,c),fl:r})].map(Ht),M=l?{facet_fields:jt({facets:l,_ctrl:t})}:void 0;return{question:e,question_id:_,...n&&{parent_question_id:n},datetime:g,answer:ft({sources:z,citation:{link:"0"!==i&&!!i,start:a,end:u,unused:Tt([...Array(z.length).keys()])},format:m,sampling:w,features:b}),images:y,sources:z,products:q,total:$,facet_counts:M,related_resources:v,followup_questions:[...vt({rows:Pt(3,6)})]}}function Pt(t,e,n){return Ot(Ct(t,n),Ct(e,n))}function Et({_ctrl:t={},fl:n=["cover_image","url"],rows:r=10,facets:o,_meta:{page:s=0}={}}){const i=void 0!==t.total?t.total:e(1e3,1e4);return{products:[...gt({rows:Math.min(i-s*r,r),fl:n})].map(l),total:i,facet_counts:o?{facet_fields:jt({facets:o,_ctrl:t})}:void 0}}function Lt({q:t,completion_fields:e,rows:n}={}){let r=0;const o={};for(const s of e)o[s]=Ut(s,t,r,n),r+=n;return o}function Ut(t,e,n,r){const o=[];for(let s=0;r>s;s++)o.push(Rt(t,e,n));return o}function Rt(t,n,r){const o=st(),s=e(0,o.length),i=o.substring(0,s),a=o.substring(s);return{text:`${i}${n}${a}`,text_with_markups:`${Vt(i)}${n}${Vt(a)}`,text_with_inverted_markups:`${i}${Vt(n)}${a}`,_field:t,_index:r}}function Vt(t){return t.length>0?`<mark>${t}</mark>`:""}var Wt=Object.freeze({__proto__:null,answer:Ft,articles:gt,completions:Lt,fields:mt,images:zt,lorem:M,md:Z,products:pt,questions:vt,searchResults:Et,utils:d});const Bt=[{name:"fetch",duration:1.5,text:"Checking the question and fetching results... "},{name:"verify",duration:1.5,text:"Verifying results... "},{name:"generate",duration:1.5,text:"Generating answer... "}];class Nt{constructor(t={}){this._options=t,this._answers=new Map}questions(t,e={}){const n=this._createAnswer(0,t,e),{question_id:r}=n;return{question_id:r}}search(e,n={}){const r={miso_id:t(),...Et(e)};return(void 0===e.answer||e.answer)&&(r.question_id=this._createAnswer(1,e,n).question_id),r}autocomplete({q:t,completion_fields:e=["title"],rows:n=5}){return{completions:Lt({q:t,completion_fields:e,rows:n})}}search_autocomplete(t){return this.autocomplete(t)}_createAnswer(t,e,n={}){const r=new Jt(t,e,{...this._options,...n});return this._answers.set(r.question_id,r),r}answer(t){const e=this._answers.get(t);if(!e){const e=Error("Question not found: "+t);throw e.status=404,e}return e.get()}related_questions(e){const n=t();return{related_questions:[...vt(e)],miso_id:n}}trending_questions(t){return this.related_questions(t)}}class Jt{constructor(t,e,{answerFormat:n,answerSampling:r,answerLanguages:o,...s}={}){this._mode=t,this._options=Object.freeze(s);const i=this.timestamp=Date.now();this._data=Ft({...e,timestamp:i},{answerFormat:n,answerSampling:r,answerLanguages:o})}get question_id(){return this._data.question_id}get searchResults(){const{products:t,total:e,facet_counts:n}=this._data;return function(t){if("object"!=typeof t)return t;const e={};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&void 0!==t[n]&&(e[n]=t[n]);return e}({products:t,total:e,facet_counts:n})}get(){const t=(Date.now()-this.timestamp)*(this._options.speedRate||1)/1e3,e=this._question(t),[n,r,o,s]=this._answer(t),i=this._sources(t,o),a=this._related_resources(t,o),u=this._followup_questions(t,o),{question_id:c,datetime:l,parent_question_id:d,images:f}=this._data;switch(this._mode){case 0:return{answer:r,answer_stage:n,datetime:l,finished:o,revision:s,parent_question_id:d,question:e,question_id:c,images:f,sources:i,related_resources:a,followup_questions:u};case 1:return{answer:r,answer_stage:n,datetime:l,finished:o,revision:s,question_id:c,images:f,sources:i};default:throw Error("Unknown mode: "+this._mode)}}_question(t){const{question:e}=this._data;return t>3?e+" [revised]":e}_answer(t){let e=t;for(const n of Bt)if(e-=n.duration,0>e)return[n.name,n.text,!1,t];const{answer:n}=this._data,r=Math.floor(100*e),o=r>=n.length;return["result",o?n:n.slice(0,r),o,t]}_sources(t,e){const{sources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_related_resources(t,e){const{related_resources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_followup_questions(t,e){const{followup_questions:n}=this._data;if(e||!n)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}}class Kt{constructor(t){this._options=t}search({rows:t=5}){return{products:[...pt({rows:t})]}}autocomplete({q:t,completion_fields:e=["title"],rows:n=5}){return{completions:Lt({q:t,completion_fields:e,rows:n})}}}class Gt{constructor(t){this._options=t}user_to_products({rows:t=5}){return{products:[...pt({rows:t})]}}product_to_products({rows:t=5}){return{products:[...pt({rows:t})]}}}class Qt{constructor(t){this._options=t}upload(t){return[]}}class Yt{constructor(t){this._options=t}upload(t){return[]}batchDelete(t){return[]}ids(){const t=[];for(let e=0;5e3>e;e++)t.push(Zt(e));return{ids:t}}}function Zt(t){return`${10>t?"p_000":100>t?"p_00":1e3>t?"p_0":"p_"}${t}`}class Xt{constructor(t){this.ask=new Nt(t),this.search=new Kt(t),this.recommendation=new Gt(t),this.interactions=new Qt(t),this.products=new Yt(t)}}return{buildApi:(...t)=>new Xt(...t),data:Wt}});
package/package.json CHANGED
@@ -1,24 +1,20 @@
1
1
  {
2
2
  "name": "@miso.ai/doggoganger",
3
- "version": "0.9.1-beta.17",
4
- "description": "A dummy miso endpoint for demo and testing",
3
+ "description": "A dummy Miso endpoint for demo and testing",
5
4
  "type": "module",
6
5
  "bin": {
7
6
  "doggoganger": "cli/index.js"
8
7
  },
9
8
  "main": "src/index.js",
10
- "module": "src/index.js",
11
9
  "publishConfig": {
12
10
  "access": "public"
13
11
  },
14
12
  "scripts": {
15
- "build:data": "node ./bin/data.js",
16
13
  "build:js": "rollup -c",
17
- "build": "npm run build:data && npm run build:js",
18
- "start:js": "rollup -w -c rollup.config.dev.mjs",
19
- "start": "nodemon cli/index.js",
20
- "dev": "npm run start -- -- -v",
21
- "version": "node ./bin/version.js"
14
+ "build": "npm run build:js",
15
+ "start:js": "rollup -w -c rollup.config.dev.js",
16
+ "start": "nodemon ./cli/index.js",
17
+ "dev": "npm run start -- -- -v"
22
18
  },
23
19
  "repository": {
24
20
  "type": "git",
@@ -33,9 +29,10 @@
33
29
  "url": "https://github.com/MisoAI/doggoganger/issues"
34
30
  },
35
31
  "dependencies": {
36
- "@koa/cors": "^4.0.0",
32
+ "@koa/cors": "^5.0.0",
37
33
  "@koa/router": "^12.0.0",
38
- "js-yaml": "^4.1.0",
34
+ "@miso.ai/doggoganger-api": "0.9.1-beta.19",
35
+ "@miso.ai/lorem": "0.9.1-beta.19",
39
36
  "koa": "^2.14.1",
40
37
  "koa-body": "^6.0.1",
41
38
  "koa-static": "^5.0.0",
@@ -43,9 +40,11 @@
43
40
  "yargs": "^17.5.1"
44
41
  },
45
42
  "devDependencies": {
43
+ "@rollup/plugin-node-resolve": "^16.0.1",
46
44
  "@rollup/plugin-terser": "^0.4.3",
47
45
  "rollup": "^3.23.0",
48
46
  "rollup-plugin-livereload": "^2.0.5",
49
47
  "rollup-plugin-serve": "^2.0.2"
50
- }
48
+ },
49
+ "version": "0.9.1-beta.19"
51
50
  }
@@ -0,0 +1,3 @@
1
+ import { config } from './rollup.util.js';
2
+
3
+ export default config('dev');
@@ -0,0 +1,3 @@
1
+ import { config } from './rollup.util.js';
2
+
3
+ export default config('prod');
@@ -1,3 +1,4 @@
1
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
1
2
  import terser from '@rollup/plugin-terser';
2
3
  import serve from 'rollup-plugin-serve';
3
4
  import livereload from 'rollup-plugin-livereload';
@@ -7,6 +8,7 @@ export function config(env) {
7
8
  let plugins;
8
9
  if (prod) {
9
10
  plugins = [
11
+ nodeResolve(),
10
12
  terser({
11
13
  compress: {
12
14
  pure_getters: true,
@@ -18,6 +20,7 @@ export function config(env) {
18
20
  ];
19
21
  } else {
20
22
  plugins = [
23
+ nodeResolve(),
21
24
  serve({
22
25
  port: 10098,
23
26
  }),
package/src/api.js CHANGED
@@ -1,4 +1,4 @@
1
- import Api from './api/index.js';
1
+ import { Api } from '@miso.ai/doggoganger-api';
2
2
 
3
3
  export default function buildApi(...args) {
4
4
  return new Api(...args);
package/src/browser.js CHANGED
@@ -1,5 +1,4 @@
1
- import Api from './api/index.js';
2
- import * as data from './data/index.js';
1
+ import { Api, data } from '@miso.ai/doggoganger-api';
3
2
 
4
3
  export default {
5
4
  buildApi: (...args) => new Api(...args),
@@ -1,10 +1,10 @@
1
+ import { Api } from '@miso.ai/doggoganger-api';
1
2
  import Koa from 'koa';
2
3
  import Router from '@koa/router';
3
4
  import cors from '@koa/cors';
4
5
  import serveStatic from 'koa-static';
5
6
  import { koaBody } from 'koa-body';
6
7
  import _route from './route/index.js';
7
- import Api from './api/index.js';
8
8
  import { exclusion } from './utils.js';
9
9
 
10
10
  export default function doggoganger({ port = 9901, serve = false, ...options } = {}) {
@@ -37,6 +37,8 @@ export default function doggoganger({ port = 9901, serve = false, ...options } =
37
37
  .use(router.allowedMethods())
38
38
  .use(handleUnrecognizedPath(options))
39
39
  .listen(port);
40
+
41
+ options.verbose && console.log(`API service running on port ${port}`);
40
42
  }
41
43
 
42
44
  function handleAllPath({ verbose } = {}) {
@@ -1,11 +1,11 @@
1
1
  import { delay, trimObj } from '../utils.js';
2
- import { gaussRandom } from '../data/utils.js';
2
+ import { utils } from '@miso.ai/lorem';
3
3
 
4
4
  const DEFAULT_OPTIONS = {
5
5
  enabled: true,
6
6
  verbose: false,
7
- min: 200,
8
- max: 2000,
7
+ min: 100,
8
+ max: 5000,
9
9
  };
10
10
 
11
11
  export default function latency(options) {
@@ -19,8 +19,8 @@ export default function latency(options) {
19
19
  ...getOptionsFromCtx(ctx),
20
20
  };
21
21
  if (enabled) {
22
- const time = (min + max) / 2 + gaussRandom() * (max - min) / 6;
23
- verbose && console.log(`Add latency: ${time}ms`);
22
+ const time = utils.rollLatency(min, max);
23
+ verbose && console.log(`Add request latency: ${time}ms`);
24
24
  await delay(time);
25
25
  }
26
26
  await next();
package/src/route/ask.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import Router from '@koa/router';
2
+ import { utils } from '@miso.ai/lorem';
2
3
  import { handler, parseBodyIfNecessary } from './utils.js';
4
+ import { delay } from '../utils.js';
5
+
6
+ const { rollLatency } = utils;
3
7
 
4
8
  function getOptionsFromCtx(ctx) {
5
9
  const speedRate = Number(ctx.get('x-speed-rate')) || undefined;
@@ -10,18 +14,43 @@ function getOptionsFromCtx(ctx) {
10
14
  return { answerFormat, answerSampling, answerLanguages, speedRate };
11
15
  }
12
16
 
17
+ const DEFAULT_LATENCY_OPTIONS = {
18
+ min: 100,
19
+ max: 5000,
20
+ };
21
+
13
22
  export default function(api) {
14
23
  const router = new Router();
15
24
 
16
- router.post('/questions', (ctx) => {
25
+ router.post('/questions', async (ctx) => {
17
26
  const payload = parseBodyIfNecessary(ctx.request.body);
18
27
  const data = api.ask.questions(payload, getOptionsFromCtx(ctx));
28
+ const time = rollLatency(DEFAULT_LATENCY_OPTIONS.min, DEFAULT_LATENCY_OPTIONS.max);
29
+ await delay(time);
30
+ ctx.body = JSON.stringify({ data });
31
+ });
32
+
33
+ router.get('/questions/:id/answer', async (ctx) => {
34
+ const { id } = ctx.params;
35
+ const data = api.ask.answer(id);
36
+ const time = rollLatency(DEFAULT_LATENCY_OPTIONS.min, DEFAULT_LATENCY_OPTIONS.max);
37
+ await delay(time);
38
+ ctx.body = JSON.stringify({ data });
39
+ });
40
+
41
+ router.post('/search', async (ctx) => {
42
+ const payload = parseBodyIfNecessary(ctx.request.body);
43
+ const data = api.ask.search(payload, getOptionsFromCtx(ctx));
44
+ const time = rollLatency(DEFAULT_LATENCY_OPTIONS.min, DEFAULT_LATENCY_OPTIONS.max);
45
+ await delay(time);
19
46
  ctx.body = JSON.stringify({ data });
20
47
  });
21
48
 
22
- router.get('/questions/:id/answer', (ctx) => {
49
+ router.get('/search/:id/answer', async (ctx) => {
23
50
  const { id } = ctx.params;
24
51
  const data = api.ask.answer(id);
52
+ const time = rollLatency(DEFAULT_LATENCY_OPTIONS.min, DEFAULT_LATENCY_OPTIONS.max);
53
+ await delay(time);
25
54
  ctx.body = JSON.stringify({ data });
26
55
  });
27
56
 
@@ -5,6 +5,7 @@ export default function(api) {
5
5
  const router = new Router();
6
6
 
7
7
  router.post('/', handler(api.products.upload, 'data'));
8
+ router.post('_delete', handler(api.products.batchDelete, 'data'));
8
9
 
9
10
  router.get('/_ids', (ctx) => {
10
11
  ctx.body = {
@@ -1,3 +1,4 @@
1
+
1
2
  export function parseBodyIfNecessary(body) {
2
3
  if (typeof body === 'string') {
3
4
  return JSON.parse(body);
@@ -42,7 +43,6 @@ export function responseFunction(response) {
42
43
  }
43
44
  switch (response) {
44
45
  case 'query':
45
- // TODO: miso_id
46
46
  return data => ({ data });
47
47
  case 'data':
48
48
  return data => ({ took: 5, errors: false, data });
@@ -1,34 +0,0 @@
1
- name: NPM publish
2
-
3
- on:
4
- release:
5
- types: [published]
6
-
7
- jobs:
8
- publish-npm:
9
- environment: production
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Get version
13
- id: version
14
- run: |
15
- VERSION=${{ github.event.release.tag_name }}
16
- echo "::set-output name=version::$(echo $VERSION | sed -e 's/v//gI')"
17
- - uses: actions/checkout@v2
18
- - uses: actions/setup-node@v2
19
- with:
20
- node-version: 16
21
- registry-url: https://registry.npmjs.org/
22
- - run: npm install
23
- - run: git config --global user.name "${{ github.actor }}"
24
- - run: git config --global user.email "github-action-${{ github.actor }}@users.noreply.github.com"
25
- - run: npm run version ${{ steps.version.outputs.version }}
26
- - run: npm run build
27
- - run: npm publish
28
- if: "!github.event.release.prerelease"
29
- env:
30
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31
- - run: npm publish --tag beta
32
- if: "github.event.release.prerelease"
33
- env:
34
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Miso Technologies
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,2 +0,0 @@
1
- # doggoganger
2
- Mock API endpoint service for demo and testing
package/bin/data.js DELETED
@@ -1,15 +0,0 @@
1
- import { fileURLToPath } from 'url';
2
- import { dirname, resolve } from 'path';
3
- import { writeFileSync, readFileSync } from 'fs';
4
- import yaml from 'js-yaml';
5
-
6
- const __dirname = dirname(fileURLToPath(import.meta.url));
7
-
8
- const WORDS_YAML = resolve(__dirname, '../data/words.yaml');
9
- const WORDS_JS = resolve(__dirname, '../src/data/words.js');
10
-
11
- const words = yaml.load(readFileSync(WORDS_YAML, 'utf8'));
12
- writeFileSync(WORDS_JS, `
13
- // genereated by bin/data.js
14
- export default ${JSON.stringify(words, null, 2)};
15
- `);
package/bin/version.js DELETED
@@ -1,46 +0,0 @@
1
- import { fileURLToPath } from 'url';
2
- import { dirname, join } from 'path';
3
- import { writeFileSync, readFileSync, existsSync } from 'fs';
4
-
5
- const __dirname = dirname(fileURLToPath(import.meta.url));
6
-
7
- const VERSION_REGEXP = /^\d+\.\d+\.\d+(?:-beta\.\d+)?$/;
8
- const version = process.argv[2];
9
-
10
- if (!version) {
11
- console.log(`Usage: npm run version [version]`);
12
- process.exit();
13
- }
14
- if (!VERSION_REGEXP.test(version)) {
15
- console.error(`Illegal version: ${version}`);
16
- process.exit(1);
17
- }
18
-
19
- const rootDir = join(__dirname, '..');
20
- //const VERSION_FILE_NAME = 'src/version.js';
21
- const PACKAGE_FILE_NAME = 'package.json';
22
-
23
- /*
24
- function writeVersionFile(path, version) {
25
- const filePath = join(rootDir, path, VERSION_FILE_NAME);
26
- if (existsSync(filePath)) {
27
- writeFileSync(filePath, `export default '${version}';`);
28
- }
29
- }
30
- */
31
-
32
- function readPackageFileSync(path) {
33
- const file = join(path, PACKAGE_FILE_NAME);
34
- return existsSync(file) ? JSON.parse(readFileSync(file)) : undefined;
35
- }
36
-
37
- function writePackageFileSync(path, data) {
38
- const file = join(path, PACKAGE_FILE_NAME);
39
- if (!existsSync(file)) {
40
- mkdirSync(dirname(file), { recursive: true });
41
- }
42
- writeFileSync(join(path, PACKAGE_FILE_NAME), JSON.stringify(data, null, 2));
43
- }
44
-
45
- const { name, version: _version, ...project } = readPackageFileSync(rootDir);
46
- writePackageFileSync(rootDir, { name, version, ...project });
package/data/words.yaml DELETED
@@ -1,178 +0,0 @@
1
- - lorem
2
- - ipsum
3
- - dolor
4
- - sit
5
- - amet
6
- - consectetur
7
- - adipiscing
8
- - elit
9
- - curabitur
10
- - vel
11
- - hendrerit
12
- - libero
13
- - eleifend
14
- - blandit
15
- - nunc
16
- - ornare
17
- - odio
18
- - ut
19
- - orci
20
- - gravida
21
- - imperdiet
22
- - nullam
23
- - purus
24
- - lacinia
25
- - a
26
- - pretium
27
- - quis
28
- - congue
29
- - praesent
30
- - sagittis
31
- - laoreet
32
- - auctor
33
- - mauris
34
- - non
35
- - velit
36
- - eros
37
- - dictum
38
- - proin
39
- - accumsan
40
- - sapien
41
- - nec
42
- - massa
43
- - volutpat
44
- - venenatis
45
- - sed
46
- - eu
47
- - molestie
48
- - lacus
49
- - quisque
50
- - porttitor
51
- - ligula
52
- - dui
53
- - mollis
54
- - tempus
55
- - at
56
- - magna
57
- - vestibulum
58
- - turpis
59
- - ac
60
- - diam
61
- - tincidunt
62
- - id
63
- - condimentum
64
- - enim
65
- - sodales
66
- - in
67
- - hac
68
- - habitasse
69
- - platea
70
- - dictumst
71
- - aenean
72
- - neque
73
- - fusce
74
- - augue
75
- - leo
76
- - eget
77
- - semper
78
- - mattis
79
- - tortor
80
- - scelerisque
81
- - nulla
82
- - interdum
83
- - tellus
84
- - malesuada
85
- - rhoncus
86
- - porta
87
- - sem
88
- - aliquet
89
- - et
90
- - nam
91
- - suspendisse
92
- - potenti
93
- - vivamus
94
- - luctus
95
- - fringilla
96
- - erat
97
- - donec
98
- - justo
99
- - vehicula
100
- - ultricies
101
- - varius
102
- - ante
103
- - primis
104
- - faucibus
105
- - ultrices
106
- - posuere
107
- - cubilia
108
- - curae
109
- - etiam
110
- - cursus
111
- - aliquam
112
- - quam
113
- - dapibus
114
- - nisl
115
- - feugiat
116
- - egestas
117
- - class
118
- - aptent
119
- - taciti
120
- - sociosqu
121
- - ad
122
- - litora
123
- - torquent
124
- - per
125
- - conubia
126
- - nostra
127
- - inceptos
128
- - himenaeos
129
- - phasellus
130
- - nibh
131
- - pulvinar
132
- - vitae
133
- - urna
134
- - iaculis
135
- - lobortis
136
- - nisi
137
- - viverra
138
- - arcu
139
- - morbi
140
- - pellentesque
141
- - metus
142
- - commodo
143
- - ut
144
- - facilisis
145
- - felis
146
- - tristique
147
- - ullamcorper
148
- - placerat
149
- - aenean
150
- - convallis
151
- - sollicitudin
152
- - integer
153
- - rutrum
154
- - duis
155
- - est
156
- - etiam
157
- - bibendum
158
- - donec
159
- - pharetra
160
- - vulputate
161
- - maecenas
162
- - mi
163
- - fermentum
164
- - consequat
165
- - suscipit
166
- - aliquam
167
- - habitant
168
- - senectus
169
- - netus
170
- - fames
171
- - quisque
172
- - euismod
173
- - curabitur
174
- - lectus
175
- - elementum
176
- - tempor
177
- - risus
178
- - cras
@@ -1,3 +0,0 @@
1
- import { config } from './rollup.util.mjs';
2
-
3
- export default config('dev');
package/rollup.config.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { config } from './rollup.util.mjs';
2
-
3
- export default config('prod');