@miso.ai/doggoganger 0.9.1-beta.10 → 0.9.1-beta.11

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)):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}var l=Object.freeze({__proto__:null,formatDatetime:i,gaussRandom:u,id:r,imageUrl:s,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 d({decorates:t=[],output:e="string",size:n,min:r,max:o,...s}={}){let i=b(n||[r,o])(h(s));for(const e of t)i=p(e)(i);return p(e)(i)}const m={string:g,array:_,title:y,description:q,multiline:w};function p(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*h({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 _(){return t=>[...t]}function w({wordsPerLine:t={avg:10,std:3,min:1}}={}){return e=>{let n=v(t),r="";for(let o of e)r&&(0==n--?(r+="\n",n=v(t)):r+=" "),r+=o;return r}}function b(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 z(e)}}function q({wordsPerSentence:t={avg:24,std:5,min:1},punctuation:e="."}={}){return function*(n){let r,o=0;for(let s of n)r&&(yield r),r=s,0===o&&(r=z(r),o=v(t)),0==--o&&(r+=e);r&&(r.endsWith(e)||(r+=e),yield r)}}function z(t){return t[0].toUpperCase()+t.substring(1)}function v(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 $=Object.freeze({__proto__:null,array:_,base:h,description:q,limit:b,lorem:d,multiline:w,string:g,title:y});const M="// 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 x=Object.freeze({__proto__:null,javascript:function(){return M},js:function(){return M}});function j({features:t,blocks:e=[8,12],sampling:n=1}={}){let r=[];return[r,t]=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]}(t),function(t,e){const n=[];for(const r of t)1>e&&Math.random()>=e||n.push(r());return n}([()=>S({features:t}),()=>A({features:t}),...r.map((e=>()=>O({lang:e,features:t}))),...r.length?[]:[()=>O({features:t})],()=>A({features:t}),()=>C({features:t}),()=>D(),()=>A({features:t}),()=>k(),()=>S({features:t}),()=>A({features:t}),()=>F({features:t}),()=>A({features:t})],n).join("\n\n")}function k(){return"*-_".charAt(e(0,2)).repeat(e(3,6))}function S({level:t=[1,6],size:n=[1,8],content:r}){const o=r||d({size:n});return`${"#".repeat(e(...t))} ${o}`}function O({lang:t,content:n,size:r,fenceChar:o="`"}){return"random"===o&&(o="`~".charAt(e(0,1))),n=n||B({lang:t,size:r}),`${o.repeat(3)}${t||""}\n${n}\n${o.repeat(3)}`}function A({size:t=[20,50]}){return d({size:t,decorates:["description",U()]})}function C({columns:t=[2,4],rows:n=[2,8]}){t=e(...t),n=e(...n);const r=[...K({size:1},t-1),{size:[3,8]}],o=[d({size:t,output:"array"}),r.map((()=>"---"))];for(let t=0;n-1>t;t++)o.push(r.map((({size:t})=>d({size:t}))));return o.map(J).join("\n")}function D({url:t,imageSize:e=[400,250],...n}={}){return t=t||s(e),`![${E(n)}](${t})`}const T=["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?T[Math.floor(3*Math.random())]:n,i=[];for(;r>0;){const a=e(1,r);let u=A({features:t,size:o});a>1&&(u+="\n"+F({features:t,type:n,count:a-1,size:o})),i.push(W(s,u)),r-=a}return i.join("\n")}const H={"code-span":()=>["`","`"],"emphasis-1":()=>K(I(1),2),"emphasis-2":()=>K(I(2),2),"emphasis-3":()=>K(I(3),2),strikethrough:()=>["~","~"],link:({url:t="https://miso.ai"}={})=>["[",`](${t})`]};function I(t=[1,3]){return t="number"==typeof t?t:e(...t),"_*".charAt(e(0,1)).repeat(t)}const L=Object.keys(H),P=new Set(L);function U({features:t=L,size:n=[1,3],rest:r=[0,8]}={}){t=t.filter((t=>P.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,c=a();for(const l of r)if(u&&(yield u),0===c)if(o)u=`${l}${o}`,o=void 0,c=a();else{const[r,a]=H[0>i?t[e(0,t.length-1)]:s[i--]]();u=`${r}${l}`,o=a,c="number"==typeof n?n:e(...n)}else u=l,c--;u&&(yield void 0!==o?`${u}${o}`:u)}}function E({size:t=[1,3],content:e}={}){return e||d({size:t})}function R(t,e){return e.split("\n").map((e=>" ".repeat(t)+e)).join("\n")}function W(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"+R("ordered"===t?3:2,r):o}function B({lang:t,size:e=[10,30]}){return t&&x[t]?x[t]():d({output:"multiline",size:e})}function J(t){return`| ${t.join(" | ")} |`}function K(t,e){const n=[];for(let r=0;e>r;r++)n.push("function"==typeof t?t():t);return n}var G=Object.freeze({__proto__:null,atxHeading:S,blockquote:function({size:t=[3,5]}){return d({size:t}).split("\n").map((t=>"> "+t)).join("\n")},codeSpan:function(t){return`\`${E(t)}\``},decorate:U,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}${E(n)}${r}`},fencedCodeBlock:O,hr:k,image:D,indent:R,indentedCodeBlock:function({lang:t,content:e,size:n}){return R(4,e=e||B({lang:t,size:n}))},link:function({url:t="https://miso.ai",...e}={}){return`[${E(e)}](${t})`},linkReferenceDefinition:function({label:t,destination:e,title:n}){return`[${t}]: ${e}${void 0!==n?" "+n:""}`},list:F,listItem:W,markdown:j,paragraph:A,setextHeading:function({level:t=[1,2],size:n=[1,8],content:r}){return`${r||d({size:n})}\n${"=-".charAt(e(...t)-1).repeat(3)}`},table:C});function N({size:t=300}={}){return s(t)}function Q({size:t=[1,3]}={}){return d({size:t,decorates:["title"],output:"array"})}function V({size:t=[1,4]}={}){return d({size:t,output:"array"})}function Z({size:t=[2,6]}={}){return d({size:t,decorates:["title"]})}function X({size:t=[10,20],...e}={}){return d({size:t,decorates:[Object.keys(e).length?["description",e]:"description"]})}function Y(){return Math.floor(1e4*Math.random())/100}function*tt({rows:t,...e}={}){for(let n=0;t>n;n++)yield et({...e,index:n})}function et({}={}){const t=r(),e=n(Y,[1,2]);return e.sort(),{product_id:t,authors:Q(),categories:[],tags:V(),title:Z(),description:X(),cover_image:N(),url:"https://dummy.miso.ai/products/"+t,sale_price:e[0],original_price:e[e.length-1],rating:Math.floor(500*Math.random())/100+1,availability:Math.random()>.3?"IN_STOCK":"OUT_OF_STOCK"}}function*nt({rows:t,...e}={}){for(let n=0;t>n;n++)yield rt({...e,index:n})}function rt({}={}){const t=r();return{product_id:t,authors:Q(),categories:[],tags:V(),title:Z({size:[4,10]}),snippet:X({size:[20,40]}),cover_image:N(),url:"/products/"+t}}function*ot({rows:t=5,...e}={}){for(let n=0;t>n;n++)yield st({...e,index:n})}function st({}={}){return X({size:[4,8],punctuation:"?"})}function it({question:e,parent_question_id:n,timestamp:r=Date.now()},{answerFormat:o="markdown",answerSampling:s,answerLanguages:u=[]}={}){const c=t(),l=i(r),f=void 0!==s?Math.max(0,Math.min(1,s)):void 0,m=function({format:t,sampling:e,features:n}){return"markdown"===t?j({sampling:e,features:n}):d({min:a(50,e),max:a(50,e),decorates:["description"]})}({format:o,sampling:f,features:u.length?u.map((t=>"lang-"+t)):void 0}),p=[...nt({rows:at(6,8,f)})];return{question:e,question_id:c,...n&&{parent_question_id:n},datetime:l,answer:m,sources:[...nt({rows:at(4,6,f)})],related_resources:p,followup_questions:[...ot({rows:at(3,6)})]}}function at(t,n,r){return e(a(t,r),a(n,r))}var ut=Object.freeze({__proto__:null,answer:it,articles:nt,lorem:$,md:G,products:tt,questions:ot,utils:l});const ct=[{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 lt{constructor(t={}){this._options=t,this._answers=new Map}questions(t,e={}){const n=new ft(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:[...ot(t)]}}}class ft{constructor({question:t,parent_question_id:e},{answerFormat:n,answerSampling:r,answerLanguages:o,...s}={}){this._options=Object.freeze(s);const i=this.timestamp=Date.now();this._data=it({question:t,parent_question_id:e,timestamp:i},{answerFormat:n,answerSampling:r,answerLanguages:o})}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 ct)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 dt{constructor(t){this._options=t}search({rows:t=5}){return{products:[...tt({rows:t})]}}}class mt{constructor(t){this._options=t}user_to_products({rows:t=5}){return{products:[...tt({rows:t})]}}product_to_products({rows:t=5}){return{products:[...tt({rows:t})]}}}class pt{constructor(t){this._options=t}upload(t){return[]}}class ht{constructor(t){this._options=t}upload(t){return[]}ids(){const t=[];for(let e=0;5e3>e;e++)t.push(gt(e));return{ids:t}}}function gt(t){return`${10>t?"p_000":100>t?"p_00":1e3>t?"p_0":"p_"}${t}`}class _t{constructor(t){this.ask=new lt(t),this.search=new dt(t),this.recommendation=new mt(t),this.interactions=new pt(t),this.products=new ht(t)}}return{buildApi:(...t)=>new _t(...t),data:ut}}));
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)):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}var l=Object.freeze({__proto__:null,formatDatetime:i,gaussRandom:u,id:r,imageUrl:s,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 d({decorates:t=[],output:e="string",size:n,min:r,max:o,...s}={}){let i=b(n||[r,o])(h(s));for(const e of t)i=m(e)(i);return m(e)(i)}const p={string:g,array:_,title:y,description:v,multiline:w};function m(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*h({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 _(){return t=>[...t]}function w({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 b(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 z(e)}}function v({wordsPerSentence:t={avg:24,std:5,min:1},punctuation:e="."}={}){return function*(n){let r,o=0;for(let s of n)r&&(yield r),r=s,0===o&&(r=z(r),o=q(t)),0==--o&&(r+=e);r&&(r.endsWith(e)||(r+=e),yield r)}}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 $=Object.freeze({__proto__:null,array:_,base:h,description:v,limit:b,lorem:d,multiline:w,string:g,title:y});const M="// 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 x=Object.freeze({__proto__:null,javascript:function(){return M},js:function(){return M}});function j({features:t,blocks:e=[8,12],sampling:n=1}={}){let r=[];return[r,t]=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]}(t),function(t,e){const n=[];for(const r of t)1>e&&Math.random()>=e||n.push(r());return n}([()=>S({features:t}),()=>A({features:t}),...r.map((e=>()=>O({lang:e,features:t}))),...r.length?[]:[()=>O({features:t})],()=>A({features:t}),()=>C({features:t}),()=>D(),()=>A({features:t}),()=>k(),()=>S({features:t}),()=>A({features:t}),()=>F({features:t}),()=>A({features:t})],n).join("\n\n")}function k(){return"*-_".charAt(e(0,2)).repeat(e(3,6))}function S({level:t=[1,6],size:n=[1,8],content:r}){const o=r||d({size:n});return`${"#".repeat(e(...t))} ${o}`}function O({lang:t,content:n,size:r,fenceChar:o="`"}){return"random"===o&&(o="`~".charAt(e(0,1))),n=n||B({lang:t,size:r}),`${o.repeat(3)}${t||""}\n${n}\n${o.repeat(3)}`}function A({size:t=[20,50]}){return d({size:t,decorates:["description",U()]})}function C({columns:t=[2,4],rows:n=[2,8]}){t=e(...t),n=e(...n);const r=[...K({size:1},t-1),{size:[3,8]}],o=[d({size:t,output:"array"}),r.map((()=>"---"))];for(let t=0;n-1>t;t++)o.push(r.map((({size:t})=>d({size:t}))));return o.map(J).join("\n")}function D({url:t,imageSize:e=[400,250],...n}={}){return t=t||s(e),`![${E(n)}](${t})`}const T=["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?T[Math.floor(3*Math.random())]:n,i=[];for(;r>0;){const a=e(1,r);let u=A({features:t,size:o});a>1&&(u+="\n"+F({features:t,type:n,count:a-1,size:o})),i.push(W(s,u)),r-=a}return i.join("\n")}const H={"code-span":()=>["`","`"],"emphasis-1":()=>K(I(1),2),"emphasis-2":()=>K(I(2),2),"emphasis-3":()=>K(I(3),2),strikethrough:()=>["~","~"],link:({url:t="https://miso.ai"}={})=>["[",`](${t})`]};function I(t=[1,3]){return t="number"==typeof t?t:e(...t),"_*".charAt(e(0,1)).repeat(t)}const L=Object.keys(H),P=new Set(L);function U({features:t=L,size:n=[1,3],rest:r=[0,8]}={}){t=t.filter((t=>P.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,c=a();for(const l of r)if(u&&(yield u),0===c)if(o)u=`${l}${o}`,o=void 0,c=a();else{const[r,a]=H[0>i?t[e(0,t.length-1)]:s[i--]]();u=`${r}${l}`,o=a,c="number"==typeof n?n:e(...n)}else u=l,c--;u&&(yield void 0!==o?`${u}${o}`:u)}}function E({size:t=[1,3],content:e}={}){return e||d({size:t})}function R(t,e){return e.split("\n").map((e=>" ".repeat(t)+e)).join("\n")}function W(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"+R("ordered"===t?3:2,r):o}function B({lang:t,size:e=[10,30]}){return t&&x[t]?x[t]():d({output:"multiline",size:e})}function J(t){return`| ${t.join(" | ")} |`}function K(t,e){const n=[];for(let r=0;e>r;r++)n.push("function"==typeof t?t():t);return n}var G=Object.freeze({__proto__:null,atxHeading:S,blockquote:function({size:t=[3,5]}){return d({size:t}).split("\n").map((t=>"> "+t)).join("\n")},codeSpan:function(t){return`\`${E(t)}\``},decorate:U,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}${E(n)}${r}`},fencedCodeBlock:O,hr:k,image:D,indent:R,indentedCodeBlock:function({lang:t,content:e,size:n}){return R(4,e=e||B({lang:t,size:n}))},link:function({url:t="https://miso.ai",...e}={}){return`[${E(e)}](${t})`},linkReferenceDefinition:function({label:t,destination:e,title:n}){return`[${t}]: ${e}${void 0!==n?" "+n:""}`},list:F,listItem:W,markdown:j,paragraph:A,setextHeading:function({level:t=[1,2],size:n=[1,8],content:r}){return`${r||d({size:n})}\n${"=-".charAt(e(...t)-1).repeat(3)}`},table:C});function N({size:t=300}={}){return s(t)}function Q({size:t=[1,3]}={}){return d({size:t,decorates:["title"],output:"array"})}function V({size:t=[1,4]}={}){return d({size:t,output:"array"})}function Z({size:t=[2,6]}={}){return d({size:t,decorates:["title"]})}function X({size:t=[10,20],...e}={}){return d({size:t,decorates:[Object.keys(e).length?["description",e]:"description"]})}function Y({paragraphs:t=8,sections:e,paragraph:n,image:r}={}){n={size:[30,60],...n},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>${Z()}</h4>`);i++<(t+1)*s;)o.push(`<p>${X(n)}</p>`);o.push(`<div class="image-container"><img src="${N(r)}"></div>`)}return o.join("")}function tt(){return Math.random()>.3?"IN_STOCK":"OUT_OF_STOCK"}function et(){return Math.floor(1e4*Math.random())/100}function nt(){return Math.floor(500*Math.random())/100+1}function rt({format:t,sampling:e,features:n}){return"markdown"===t?j({sampling:e,features:n}):d({min:a(50,e),max:a(50,e),decorates:["description"]})}function*ot({rows:t,...e}={}){for(let n=0;t>n;n++)yield st({...e,index:n})}function st({}={}){const t=r(),e=n(et,[1,2]);return e.sort(),{product_id:t,authors:Q(),categories:[],tags:V(),title:Z(),description:X(),cover_image:N(),url:"https://dummy.miso.ai/products/"+t,sale_price:e[0],original_price:e[e.length-1],rating:nt(),availability:tt()}}function*it({rows:t,...e}={}){for(let n=0;t>n;n++)yield at({...e,index:n})}function at({}={}){const t=r();return{product_id:t,authors:Q(),categories:[],tags:V(),title:Z({size:[4,10]}),snippet:X({size:[20,40]}),html:Y(),cover_image:N(),url:"/products/"+t}}function*ut({rows:t=5,...e}={}){for(let n=0;t>n;n++)yield ct({...e,index:n})}function ct({}={}){return X({size:[4,8],punctuation:"?"})}function lt({question:e,parent_question_id:n,timestamp:r=Date.now()},{answerFormat:o="markdown",answerSampling:s,answerLanguages:a=[]}={}){const u=t(),c=i(r),l=void 0!==s?Math.max(0,Math.min(1,s)):void 0,f=rt({format:o,sampling:l,features:a.length?a.map((t=>"lang-"+t)):void 0}),d=[...it({rows:ft(6,8,l)})].map(dt);return{question:e,question_id:u,...n&&{parent_question_id:n},datetime:c,answer:f,sources:[...it({rows:ft(4,6,l)})].map(dt),related_resources:d,followup_questions:[...ut({rows:ft(3,6)})]}}function ft(t,n,r){return e(a(t,r),a(n,r))}function dt({html:t,...e}){return e}var pt=Object.freeze({__proto__:null,answer:lt,articles:it,fields:Object.freeze({__proto__:null,answer:rt,authors:Q,availability:tt,description:X,html:Y,image:N,price:et,rating:nt,tags:V,title:Z}),lorem:$,md:G,products:ot,questions:ut,utils:l});const mt=[{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 ht{constructor(t={}){this._options=t,this._answers=new Map}questions(t,e={}){const n=new gt(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:[...ut(t)]}}}class gt{constructor({question:t,parent_question_id:e},{answerFormat:n,answerSampling:r,answerLanguages:o,...s}={}){this._options=Object.freeze(s);const i=this.timestamp=Date.now();this._data=lt({question:t,parent_question_id:e,timestamp:i},{answerFormat:n,answerSampling:r,answerLanguages:o})}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 mt)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 _t{constructor(t){this._options=t}search({rows:t=5}){return{products:[...ot({rows:t})]}}}class wt{constructor(t){this._options=t}user_to_products({rows:t=5}){return{products:[...ot({rows:t})]}}product_to_products({rows:t=5}){return{products:[...ot({rows:t})]}}}class bt{constructor(t){this._options=t}upload(t){return[]}}class yt{constructor(t){this._options=t}upload(t){return[]}ids(){const t=[];for(let e=0;5e3>e;e++)t.push(vt(e));return{ids:t}}}function vt(t){return`${10>t?"p_000":100>t?"p_00":1e3>t?"p_0":"p_"}${t}`}class zt{constructor(t){this.ask=new ht(t),this.search=new _t(t),this.recommendation=new wt(t),this.interactions=new bt(t),this.products=new yt(t)}}return{buildApi:(...t)=>new zt(...t),data:pt}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miso.ai/doggoganger",
3
- "version": "0.9.1-beta.10",
3
+ "version": "0.9.1-beta.11",
4
4
  "description": "A dummy miso endpoint for demo and testing",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,8 +12,8 @@ export function answer({ question, parent_question_id, timestamp = Date.now() },
12
12
  const features = answerLanguages.length ? answerLanguages.map(language => `lang-${language}`) : undefined;
13
13
 
14
14
  const answer = fields.answer({ format: answerFormat, sampling, features });
15
- const related_resources = [...articles({ rows: sampleRandomInt(6, 8, sampling) })];
16
- const sources = [...articles({ rows: sampleRandomInt(4, 6, sampling) })];
15
+ const related_resources = [...articles({ rows: sampleRandomInt(6, 8, sampling) })].map(excludeHtml);
16
+ const sources = [...articles({ rows: sampleRandomInt(4, 6, sampling) })].map(excludeHtml);
17
17
  const followup_questions = [...questions({ rows: sampleRandomInt(3, 6) })];
18
18
 
19
19
  return {
@@ -31,3 +31,7 @@ export function answer({ question, parent_question_id, timestamp = Date.now() },
31
31
  function sampleRandomInt(min, max, sampling) {
32
32
  return randomInt(sample(min, sampling), sample(max, sampling));
33
33
  }
34
+
35
+ function excludeHtml({ html, ...rest }) {
36
+ return rest;
37
+ }
@@ -17,7 +17,7 @@ function article({} = {}) {
17
17
  tags: fields.tags(),
18
18
  title: fields.title({ size: [4, 10] }),
19
19
  snippet: fields.description({ size: [20, 40] }),
20
- //html,
20
+ html: fields.html(),
21
21
  cover_image: fields.image(),
22
22
  url: `/products/${id}`,
23
23
  };
@@ -38,6 +38,30 @@ export function description({ size = [10, 20], ...options } = {}) {
38
38
  });
39
39
  }
40
40
 
41
+ export function html({ paragraphs = 8, sections, paragraph, image: imageOptions } = {}) {
42
+ paragraph = {
43
+ size: [30, 60],
44
+ ...paragraph,
45
+ };
46
+ if (sections === undefined) {
47
+ sections = Math.floor(paragraphs * (1 + Math.random()) / 4);
48
+ }
49
+ sections = Math.max(1, Math.min(sections, paragraphs));
50
+ const content = [];
51
+ const pps = paragraphs / sections;
52
+ let j = 0;
53
+ for (let i = 0; i < sections; i++) {
54
+ if (i > 0) {
55
+ content.push(`<h4>${title()}</h4>`);
56
+ }
57
+ while (j++ < (i + 1) * pps) {
58
+ content.push(`<p>${description(paragraph)}</p>`);
59
+ }
60
+ content.push(`<div class="image-container"><img src="${image(imageOptions)}"></div>`);
61
+ }
62
+ return content.join('');
63
+ }
64
+
41
65
  export function availability() {
42
66
  return Math.random() > 0.3 ? 'IN_STOCK' : 'OUT_OF_STOCK';
43
67
  }
package/src/data/index.js CHANGED
@@ -5,3 +5,4 @@ export * from './articles.js';
5
5
  export * from './questions.js';
6
6
  export * from './answers.js';
7
7
  export * as utils from './utils.js';
8
+ export * as fields from './fields.js';