1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[825],{12380:function(t,n,e){e.d(n,{$:function(){return u},a:function(){return s},getAuthProvider:function(){return a}});var r=e(7653);let i=(0,r.createContext)(null),o=null;function a(){if(!o)throw Error("AuthProvider not initialized â AuthFacadeProvider must mount before getAuthProvider() is called");return o}function u(t){let{provider:n,children:e}=t;o=n;let[a,u]=(0,r.useState)(()=>n.getCurrentUser()),[s,c]=(0,r.useState)(!1);(0,r.useEffect)(()=>n.onAuthChange(t=>{u(t),c(!0)}),[n]);let l=(0,r.useCallback)((t,e)=>n.signIn(t,e),[n]),d=(0,r.useCallback)(()=>n.signOut(),[n]),f=(0,r.useCallback)(()=>n.getIdToken(),[n]),h=(0,r.useMemo)(()=>({user:a,isReady:s,capabilities:n.capabilities,signIn:l,signOut:d,getIdToken:f}),[a,s,n,l,d,f]);return(0,r.createElement)(i.Provider,{value:h},e)}function s(){let t=(0,r.useContext)(i);if(!t)throw Error("useAuth must be used inside <AuthFacadeProvider>");return t}},42848:function(t,n,e){e.d(n,{O9:function(){return u},qB:function(){return a}});var r=e(7653);let i=(0,r.createContext)(null),o=null;function a(){if(!o)throw Error("SmartChatsBackend not initialized â BackendFacadeProvider must mount before getBackendInstance() is called");return o}function u(t){let{backend:n,children:e}=t;return o=n,(0,r.createElement)(i.Provider,{value:n},e)}},45207:function(t,n,e){e.d(n,{oi:function(){return nZ},kQ:function(){return nL},uz:function(){return n$},Jr:function(){return nK},j8:function(){return nR},DH:function(){return n3},fF:function(){return o},fp:function(){return i},Kn:function(){return u},bK:function(){return nJ},kg:function(){return r},jX:function(){return a}});var r={};e.r(r),e.d(r,{clear_all_logs:function(){return m},color_string:function(){return v},colors:function(){return y},export_logs:function(){return g},get_logger:function(){return _},simi_debug:function(){return p},suppress:function(){return f},unsuppress:function(){return h}});var i={};e.r(i),e.d(i,{add:function(){return tY},adder:function(){return t3},all_false:function(){return te},all_true:function(){return tt},any_false:function(){return tr},any_is_array:function(){return tA},any_true:function(){return tn},apply_function_dictionary_to_object:function(){return nt},async_apply_function_dictionary_to_object:function(){return nn},clone:function(){return tf},clone_array:function(){return Z},concat:function(){return tv},concat_accross_index:function(){return td},dict_to_list:function(){return $},diff:function(){return t6},divide:function(){return t2},divider:function(){return t5},enumerate:function(){return ts},enumermap:function(){return tm},equals:function(){return t8},filter:function(){return tO},filter_key:function(){return tC},filter_key_equals:function(){return tB},first:function(){return W},flat_once:function(){return tN},format:function(){return tG},fourth:function(){return V},get:function(){return F},getter:function(){return P},im_arr_rm:function(){return tp},im_push:function(){return th},indexer:function(){return Y},invert_dictionary:function(){return function t(n){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=E.Z(n),i=[];for(var o of r){let r=n[o];if(tK(r))t(r,S.Z(e,[o])).map(t=>i.push(t));else{let t=S.Z(e,[o]);i.push({value:r,path:t})}}return i}},is_array:function(){return tq},is_empty:function(){return tI},is_empty_array:function(){return tb},is_empty_map:function(){return J},is_empty_string:function(){return tZ},is_map:function(){return tK},is_null:function(){return tR},is_object:function(){return t$},is_something:function(){return tJ},is_string:function(){return tz},is_undefined:function(){return tL},is_zero:function(){return tE},join:function(){return tX},joiner:function(){return tV},keys:function(){return x},last:function(){return Q},len:function(){return tS},list_to_dict:function(){return tU},make_debouncer:function(){return t7},map:function(){return tu},map_get:function(){return ty},map_indexed:function(){return C},map_items:function(){return z},map_over_dic_values:function(){return K},map_prop:function(){return tc},map_prop_reduce:function(){return tl},map_set:function(){return tw},map_set_im:function(){return tk},merge_dictionaries:function(){return D},merge_dictionary:function(){return M},multiplier:function(){return t4},multiply:function(){return t1},nchars:function(){return tH},not_empty:function(){return tT},nth:function(){return G},partition:function(){return tg},rand_element:function(){return to},range:function(){return ta},recursive_flat:function(){return tM},recursive_flat_remove_empty:function(){return tD},remove_empty:function(){return tx},repeat:function(){return ti},second:function(){return H},set:function(){return j},set_im:function(){return U},setter:function(){return R},setter_im:function(){return L},shallow_copy:function(){return B},sort_by_prop:function(){return t_},split:function(){return tQ},substring:function(){return tW},subtract:function(){return t0},subtractor:function(){return t9},third:function(){return X},update_at:function(){return q},values:function(){return N},values_cloned:function(){return A},zip:function(){return tj},zip2:function(){return tF},zip_map:function(){return tP}});var o={};e.r(o),e.d(o,{add:function(){return ni},db:function(){return nr},get:function(){return no},log:function(){return ne}});var a={};e.r(a),e.d(a,{audio_context:function(){return nl},ensureResumed:function(){return nf},error:function(){return nE},input_ready:function(){return nS},m2f:function(){return na},note_obj_to_midi:function(){return np},note_to_freq:function(){return nm},note_to_midi:function(){return ng},note_to_note_obj:function(){return n_},play_note:function(){return nv},play_notes:function(){return ny},play_notes_delay:function(){return nw},proceed:function(){return nb},success:function(){return nk},tone:function(){return nh}});var u={};e.r(u),e.d(u,{CommonEventTypes:function(){return nT},InsightsClient:function(){return nM},InsightsScope:function(){return nD},createClient:function(){return nj},generateEventId:function(){return nx},generateSessionId:function(){return nB},generateTraceId:function(){return nA},getDefaultClient:function(){return nU},setDefaultClient:function(){return nP}});let s=[];function c(t){if(null==t||void 0==t)return String(t);if("object"==typeof t)try{return JSON.stringify(t)}catch(t){return"[unstringifiable object]"}return String(t)}function l(t){return"[".concat(t.time_str,"] ").concat(t.msg)}var d={};function f(t,n){d[t]=!0,_({id:"log"})("Suppressing ".concat(t,", reason=").concat(n||"none_given"))}function h(t){d[t]=!1,_({id:"log"})("Unsuppressing ".concat(t))}function p(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];window.__SIMI_DEBUG__&&console.log("[simi_debug]",...n)}function _(t){let{id:n}=t,e=function(){for(var t=arguments.length,e=Array(t),r=0;r<t;r++)e[r]=arguments[r];let i=e.map(c),o="[".concat(n,"]:: ").concat(i.join(" "));s.push({id:n,timestamp:Date.now(),time_str:function(){let t=new Date,n=String(t.getHours()).padStart(2,"0"),e=String(t.getMinutes()).padStart(2,"0"),r=String(t.getSeconds()).padStart(2,"0"),i=String(t.getMilliseconds()).padStart(3,"0");return"".concat(n,":").concat(e,":").concat(r,".").concat(i)}(),msg:o}),d[n]||console.log("[".concat(n,"]::"),...e)};return e.id=n,e.export_logs=function(){let t=s.filter(t=>t.id===n);return 0===t.length?"No logs for id: ".concat(n):t.map(l).join("\n")},e.clear_logs=function(){for(let t=s.length-1;t>=0;t--)s[t].id===n&&s.splice(t,1)},e}function g(t){let n=s;if(null==t?void 0:t.include){let e=new Set(t.include);n=n.filter(t=>e.has(t.id))}if(null==t?void 0:t.exclude){let e=new Set(t.exclude);n=n.filter(t=>!e.has(t.id))}return 0===n.length?"No logs found":n.map(l).join("\n")}function m(){s.length=0}function v(t,n){let e=y[t],r=y.reset;return"".concat(e).concat(n).concat(r)}var y={red:"\x1b[31m",green:"\x1b[32m",reset:"\x1b[0m"},w=e(66322),k=e(92599),E=e(33144),S=e(83178),b=e(77018),I=e(31446);let T=_({id:"fp"}),O=w.Z(k.Z);function C(t,n){return O((n,e)=>t(e,n),n)}function B(t){return tq(t)?Z(t):tK(t)?tf(t):t}function x(t){return Object.keys(t)}function A(t){let n=x(t),e=tf(t);return tI(n)?[]:tu(n,t=>e[t])}function N(t){let n=x(t);return tI(n)?[]:tu(n,n=>t[n])}function M(t,n){return Object.assign(tf(t),n)}function D(t){return t.reduce(M,{})}function F(t,n){return t[n]}function j(t,n,e){return t[n]=e,t}function U(t,n,e){let r=tf(t);return r[n]=e,r}function P(t){return function(n){return n[t]}}function R(t,n){return function(e){return e[t]=n,e}}function L(t,n){return function(e){return e[t]=n,e}}function J(t){return tK(t)&&0==tS(x(t))}function q(t,n,e){for(var r=t,i=0;i<n.length-1;i++)r=r[i];let o=Q(n);return r[o]=e(r[o]),tf(t)}function z(t){return tF(x(t),N(t))}var $=z;function K(t,n){let e=tu(N(t),n);return tP(x(t),e)}function Z(t){return JSON.parse(JSON.stringify(t))}function W(t){return t[0]}function H(t){return t[1]}function X(t){return t[2]}function V(t){return t[3]}function Q(t){let n=t.length;return t[n-1]}function G(t,n){return t[n]}function Y(t){return function(n){return n[t]}}function tt(t){return t.reduce((t,n)=>t&&n)}function tn(t){return!tI(t)&&t.reduce((t,n)=>t||n)}function te(t){return!tn(t)}function tr(t){return!tt(t)}function ti(t,n){let e=[];for(var r of ta(n))e.push(B(t));return e}function to(t){return t[Math.floor(Math.random()*t.length)]}function ta(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(n){for(var e=Array(n-t).fill(0),r=0;r<e.length;r++)e[r]=r+t;return e}for(var e=Array(t).fill(0),r=0;r<e.length;r++)e[r]=r;return e}function tu(t,n){return t.map(n)}function ts(t){return C((t,n)=>[t,n],t)}function tc(t,n){return k.Z(b.Z(t))(n)}function tl(t,n,e,r){return I.Z(n,e,tc(t,r))}function td(t){let n=[],e=t[0].length,r=t.length;for(var i=0;i<e;i++){for(var o=[],a=0;a<r;a++)o.push(t[a][i]);n.push(o)}return n}function tf(t){return JSON.parse(JSON.stringify(t))}function th(t,n){let e=tf(t);return e.push(n),e}function tp(t,n){return tf(t).filter(t=>t!=n)}function t_(t){var n=1;return"-"===t[0]&&(n=-1,t=t.substr(1)),function(e,r){return(e[t]<r[t]?-1:e[t]>r[t]?1:0)*n}}function tg(t,n){let e=Array(Math.ceil(t.length/n)).fill(null).map(t=>[]),r=0;for(var i=0;i<t.length;i++)i%n==0&&0!=i&&(r+=1),e[r].push(t[i]);return e}function tm(t,n){let e=[];
1for(var[r,i]of ts(t))e.push(n(r,i));return e}function tv(t,n){return t.concat(n)}function ty(t,n){return tu(t,P(n))}function tw(t,n,e){return tu(t,R(n,e))}function tk(t,n,e){return tu(t,L(n,e))}function tE(t){return 0==t}function tS(t){return t.length}function tb(t){return tq(t)&&0==tS(t)}function tI(t){return tR(t)||tL(t)||tb(t)||tZ(t)||J(t)}function tT(t){return!tI(t)}function tO(t,n){return t.filter(n)}function tC(t,n,e){return tO(t,t=>e(t[n]))}function tB(t,n,e){return tC(t,n,t=>t==e)}function tx(t){return tO(t,tT)}function tA(t){return tn(tu(t,tq))}function tN(t){return t.flat()}function tM(t){return tA(t)?tM(tN(t)):t}function tD(t){return tx(tM(t))}function tF(t,n){let e=[];for(var r=0;r<t.length;r++)e.push([t[r],n[r]]);return e}var tj=tF;function tU(t){let n={};for(var[e,r]of t)n[e]=r;return n}function tP(t,n){return tU(tj(t,n))}function tR(t){return null==t}function tL(t){return void 0==t}function tJ(t){return!(tR(t)||tL(t))}function tq(t){return tJ(t)&&t.constructor==Array}function tz(t){return tJ(t)&&t.constructor==String}function t$(t){return tJ(t)&&t.constructor==Object}function tK(t){return tJ(t)&&t$(t)&&!tq(t)}function tZ(t){return""==t}function tW(t,n,e){return t.substring(n,e)}function tH(t,n){return tW(t,0,n)}function tX(t,n){return t.join(n)}function tV(t){return function(n){return tX(n,t)}}function tQ(t,n){return t.split(n)}function tG(t,n){let e=Z(n),r=e.shift(),i=t;for(;r;)i=i.replace("{}",String(r)),r=e.shift();return i}function tY(t,n){return t+n}function t0(t,n){return t-n}function t1(t,n){return t*n}function t2(t,n){return t/n}function t3(t){return function(n){return n+t}}function t9(t){return function(n){return n-t}}function t5(t){return function(n){return n/t}}function t4(t){return function(n){return n*t}}function t6(t){let n=[];for(var e=1;e<t.length;e++)n.push(t[e]-t[e-1]);return n}function t8(t,n){return t==n}function t7(t,n){var e={attempt_ref:null};return r=>{e.attempt_ref&&clearTimeout(e.attempt_ref),e.attempt_ref=setTimeout(function(){n(r)},t)}}function nt(t,n){let e={},r=[];return E.Z(t).map(i=>{try{e[i]=t[i](n)}catch(t){r.push(t),e[i]=null}}),r.length&&(T("Error while applying function to dictionary"),T(r),T(e)),e}async function nn(t,n){let e={},r=[],i=E.Z(t).map(async i=>{try{e[i]=await t[i](n)}catch(t){r.push(t),e[i]=null}});return await Promise.all(i),r.length&&(T("Error while applying function to dictionary"),T(r),T(e)),e}var ne=_({id:"debug"}),nr={};function ni(t,n){nr[t]=n,ne("Added :".concat(t))}function no(t){return nr[t]}var na={12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:0,20:0,21:27.5,22:29.135,23:30.868,24:32.703,25:34.648,26:36.708,27:38.891,28:41.203,29:43.654,30:46.249,31:48.999,32:51.913,33:55,34:58.27,35:61.735,36:65.406,37:69.296,38:73.416,39:77.782,40:82.407,41:87.307,42:92.499,43:97.999,44:103.826,45:110,46:116.541,47:123.471,48:130.813,49:138.591,50:146.832,51:155.564,52:164.814,53:174.614,54:184.997,55:195.998,56:207.652,57:220,58:233.082,59:246.942,60:261.626,61:277.183,62:293.665,63:311.127,64:329.628,65:349.228,66:369.994,67:391.995,68:415.305,69:440,70:466.164,71:493.883,72:523.251,73:554.365,74:587.33,75:622.254,76:659.255,77:698.457,78:739.989,79:783.991,80:830.609,81:880,82:932.328,83:987.767,84:1046.502,85:1108.731,86:1174.659,87:1244.508,88:1318.51,89:1396.913,90:1479.978,91:1567.982,92:1661.219,93:1760,94:1864.655,95:1975.533,96:2093.005,97:2217.461,98:2349.318,99:2489.016,100:2637.021,101:2793.826,102:2959.956,103:3135.964,104:3322.438,105:3520,106:3729.31,107:3951.066,108:4186.009,109:4434.922,110:4698.637,111:4978.032,112:5274.042,113:5587.652,114:5919.912,115:6271.928,116:6644.876,117:7040,118:7458.62,119:7902.133,120:8372.019,121:8869.845,122:9397.273,123:9956.064,124:10548.083,125:11175.305,126:11839.823,127:12543.855};let nu={wait:t=>new Promise(n=>setTimeout(n,t))},ns=(t,n)=>t[n],nc=(t,n)=>{let e=0;return t.replace(/\{\}/g,()=>String(n[e++]))};var nl=null,nd=function(){return nl||(nl=new(window.AudioContext||window.webkitAudioContext))};function nf(){let t=nd();"suspended"===t.state&&t.resume()}async function nh(t){let{type:n="sine",duration:e=600,gain:r=.5,delay:i,freq:o}=t,a=nd();if("suspended"===a.state)try{await a.resume()}catch(t){}var u=a.createOscillator();u.frequency.value=o,u.type=n;var s=a.createGain();if(i){var c=a.createDelay();c.delayTime.value=i,s.connect(c),c.connect(a.destination)}s.gain.value=r,u.connect(s),s.connect(a.destination),u.start(0),await nu.wait(e),u.stop()}function np(t){let{num:n,mod:e,octave:r}=t,i=ns([0,0,2,4,5,7,9,11,12],n)+12*r;return e&&(i+="#"==e?1:-1),i}function n_(t){let n=t.split(".");var e=0,r=null,i=null;return n.length>1&&(e=Number(n[1])),n[0].length>1?(r=n[0][0],i=Number(n[0][1])):i=Number(n[0][0]),{num:i,mod:r,octave:e}}function ng(t){return np(n_(t))}function nm(t){return na[ng(t)]}async function nv(t,n,e){console.log(nc("note | n= {}, dur={}, k={}",[t,n,e]));let r=na[String((e?ng(e):60)+ng(t))],i=n||500;try{await nh({freq:r,duration:i})}catch(t){console.log("Error playing. You likely played a note outside of currently supported range"),console.log(t),console.log("freq + duration:"),console.log({freq:r,duration:i})}}async function ny(t,n,e){t.map(t=>nv(t,n,e))}async function nw(t,n,e,r){for(var i of t)nv(i,e,r),await nu.wait(n)}function nk(){ny(["1","3"],400,"3.5")}function nE(){ny(["1","b5"],200,"3.5")}function nS(){nw(["1","3"],100,100,"3.5")}function nb(){ny(["5.-1"],100,"3.5")}function nI(){return void 0!==window.document}let nT={USER_INPUT:"user_input",USER_INTERACTION:"user_interaction",USER_OUTPUT:"user_output",UI_CLICK:"ui_click",LLM_INVOCATION:"llm_invocation",EXECUTION:"execution",CODE_EXECUTION:"code_execution",EXECUTION_COMPLETE:"execution_complete",NOTE_GENERATION:"note_generation",TEST_RUN:"test_run",MODEL_TEST:"model_test",MODEL_TEST_COMPLETE:"model_test_complete"},nO=_({id:"insights"});function nC(t){let n=Date.now().toString(36),e=Math.random().toString(36).substring(2,9);return"".concat(t,"_").concat(n).concat(e)}function nB(){return nC("ses")}function nx(){return nC("evt")}function nA(){return nC("trc")}function nN(){if(!nI())return;let t={user_agent:navigator.userAgent,viewport_size:"".concat(window.innerWidth,"x").concat(window.innerHeight)};try{if("function"==typeof window.getAuth){let n=window.getAuth();(null==n?void 0:n.currentUser)&&(t.firebase_uid=n.currentUser.uid||null,t.firebase_email=n.currentUser.email||null,t.firebase_display_name=n.currentUser.displayName||null)}}catch(t){console.warn("[insights] Failed to capture Firebase auth data:",t)}return t}class nM{startBatchTimer(){this.batchTimer||(this.batchTimer=setInterval(()=>{this.eventBatch.length>0&&this.flushBatch()},this.config.batch_interval_ms))}stopBatchTimer(){this.batchTimer&&(clearInterval(this.batchTimer),this.batchTimer=null)}async addEvent(t,n){let e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!this.enabled)return nx();try{let r=nx(),i=Date.now(),o=e.parent_event_id,a=e.trace_id;if(this.chainStack.length>0){let t=this.chainStack[this.chainStack.length-1];o||(o=t.event_id),a||(a=t.trace_id)}let u={event_id:r,event_type:t,app_name:this.config.app_name,app_version:this.config.app_version,user_id:this.config.user_id,session_id:this.config.session_id,timestamp:i,payload:n,parent_event_id:o,trace_id:a,tags:e.tags,duration_ms:e.duration_ms,client_info:nN()};return this.eventBatch.push(u),this.sessionEvents.push(u),this.eventBatch.length>=this.config.batch_size&&await this.flushBatch(),r}catch(t){return nO("Error adding event: ".concat(t)),nx()}}async startChain(t,n){if(!this.enabled)return nx();try{var e;let r=this.chainStack[this.chainStack.length-1],i=null!==(e=null==r?void 0:r.trace_id)&&void 0!==e?e:nA(),o=await this.addEvent(t,n,{trace_id:i});return this.chainStack.push({event_id:o,trace_id:i}),o}catch(t){return nO("Error starting chain: ".concat(t)),nx()}}endChain(){this.chainStack.length>0&&this.chainStack.pop()}async addInChain(t,n){let e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.addEvent(t,n,e)}async addLLMInvocation(t){let n="error"===t.status?["error"]:[];return t.latency_ms>5e3&&n.push("slow"),this.addEvent(nT.LLM_INVOCATION,t,{tags:n,duration_ms:t.latency_ms})}async addExecution(t){let n="error"===t.status?["error"]:[];return t.duration_ms>1e4&&n.push("slow"),this.addEvent(nT.EXECUTION,t,{tags:n,duration_ms:t.duration_ms})}async addUserInput(t){return this.addEvent(nT.USER_INPUT,t)}async flushBatch(){if(0===this.eventBatch.length)return;let t=[...this.eventBatch];this.eventBatch=[];try{await this.flushViaAPI(t)}catch(n){nO("Error flushing batch: ".concat(n)),this.eventBatch.length<2*this.config.batch_size&&this.eventBatch.unshift(...t)}}
1flushTerminal(){if(0===this.eventBatch.length)return;if(!this.config.terminalEmit){this.flushBatch().catch(()=>{});return}let t=[...this.eventBatch];this.eventBatch=[];try{this.config.terminalEmit(t)}catch(n){this.eventBatch.unshift(...t)}}async flushViaAPI(t){let n;if(this.config.emit)nO("Flushing ".concat(t.length," events via injected emit")),n=await this.config.emit(t);else{nO("Flushing ".concat(t.length," events to ").concat(this.config.endpoint));let e=await fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t})});if(!e.ok)throw Error("HTTP ".concat(e.status,": ").concat(e.statusText));n=await e.json()}nO("Batch sent: ".concat(n.events_stored,"/").concat(n.events_received," stored")),n.errors&&n.errors.length>0&&nO("Batch had errors: ".concat(n.errors.join(", ")))}async shutdown(){this.stopBatchTimer(),await this.flushBatch(),nO("InsightsClient shutdown complete")}addSessionTags(t){for(let n of t)this.sessionTags.includes(n)||this.sessionTags.push(n);this.addEvent("session_tags",{tags:this.sessionTags},{tags:this.sessionTags})}getSessionTags(){return[...this.sessionTags]}getSessionId(){return this.config.session_id}getChainDepth(){return this.chainStack.length}exportSession(){return{session_id:this.config.session_id,app_name:this.config.app_name,tags:[...this.sessionTags],events:[...this.sessionEvents],exported_at:Date.now()}}setEnabled(t){this.enabled=t,t&&nI()&&!this.config.manual_flush?this.startBatchTimer():this.stopBatchTimer()}_getEmitContext(){return{eventBatch:this.eventBatch,sessionEvents:this.sessionEvents,app_name:this.config.app_name,app_version:this.config.app_version,user_id:this.config.user_id,session_id:this.config.session_id,enabled:this.enabled}}createScope(t){let n=this.chainStack.length>0?this.chainStack[this.chainStack.length-1].trace_id:void 0;return new nD(this._getEmitContext(),t,n)}constructor(t){var n;this.eventBatch=[],this.sessionEvents=[],this.batchTimer=null,this.chainStack=[],this.enabled=!0,this.sessionTags=[],this.config={app_name:t.app_name,app_version:t.app_version,user_id:t.user_id,session_id:t.session_id||nB(),endpoint:t.endpoint||"/api/insights/batch",emit:t.emit,terminalEmit:t.terminalEmit,batch_size:t.batch_size||50,batch_interval_ms:t.batch_interval_ms||5e3,enabled:void 0===t.enabled||t.enabled,manual_flush:null!==(n=t.manual_flush)&&void 0!==n&&n},this.enabled=this.config.enabled,nO("InsightsClient initialized for ".concat(this.config.app_name," v").concat(this.config.app_version)),nO("Session ID: ".concat(this.config.session_id)),nO("Batch size: ".concat(this.config.batch_size,", Interval: ").concat(this.config.batch_interval_ms,"ms")),this.enabled&&nI()&&!this.config.manual_flush&&this.startBatchTimer()}}class nD{async addEvent(t,n){let e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!this.ctx.enabled)return nx();try{let r=nx(),i=Date.now(),o=e.parent_event_id,a=e.trace_id||this.trace_id;if(this.chainStack.length>0){let t=this.chainStack[this.chainStack.length-1];o||(o=t.event_id),e.trace_id||(a=t.trace_id)}let u={...n,scope_name:this.scopeConfig.name,scope_metadata:this.scopeConfig.metadata},s=[...this.scopeConfig.tags||[],...e.tags||[]],c={event_id:r,event_type:t,app_name:this.ctx.app_name,app_version:this.ctx.app_version,user_id:this.ctx.user_id,session_id:this.ctx.session_id,timestamp:i,payload:u,parent_event_id:o,trace_id:a,tags:s.length>0?s:void 0,duration_ms:e.duration_ms,client_info:nN()};return this.ctx.eventBatch.push(c),this.ctx.sessionEvents.push(c),r}catch(t){return nO("Error adding scoped event: ".concat(t)),nx()}}async startChain(t,n){if(!this.ctx.enabled)return nx();try{var e;let r=this.chainStack[this.chainStack.length-1],i=null!==(e=null==r?void 0:r.trace_id)&&void 0!==e?e:this.trace_id,o=await this.addEvent(t,n,{trace_id:i});return this.chainStack.push({event_id:o,trace_id:i}),o}catch(t){return nO("Error starting scoped chain: ".concat(t)),nx()}}endChain(){this.chainStack.length>0&&this.chainStack.pop()}async addLLMInvocation(t){let n="error"===t.status?["error"]:[];return t.latency_ms>5e3&&n.push("slow"),this.addEvent(nT.LLM_INVOCATION,t,{tags:n,duration_ms:t.latency_ms})}async addExecution(t){let n="error"===t.status?["error"]:[];return t.duration_ms>1e4&&n.push("slow"),this.addEvent(nT.EXECUTION,t,{tags:n,duration_ms:t.duration_ms})}async addUserInput(t){return this.addEvent(nT.USER_INPUT,t)}createScope(t){return new nD(this.ctx,t,this.trace_id)}end(){this.addEvent("scope_end",{duration_ms:Date.now()-this.startedAt})}constructor(t,n,e){this.chainStack=[],this.ctx=t,this.scopeConfig=n,this.trace_id=nA(),this.parentTraceId=e,this.startedAt=Date.now(),this.addEvent("scope_start",{scope_name:n.name,metadata:n.metadata,parent_trace_id:e})}}let nF=null;function nj(t){return new nM(t)}function nU(){if(!nF)throw Error("Default InsightsClient not initialized. Call createClient() first or set defaultClient.");return nF}function nP(t){nF=t}function nR(t){var n,e,r;let i=String(null!==(n=t.kind)&&void 0!==n?n:"").trim(),o=String(null!==(e=t.summary)&&void 0!==e?e:"").trim(),a=String(null!==(r=t.source)&&void 0!==r?r:"unknown").trim()||"unknown";if(!i)throw Error("buildIssuePayload: kind is required");if(!o)throw Error("buildIssuePayload: summary is required");
1if(!nJ(t.severity))throw Error("buildIssuePayload: severity must be 'info' | 'warning' | 'error', got: ".concat(String(t.severity)));let u={kind:i,source:a,severity:t.severity,summary:o};return t.detail&&"object"==typeof t.detail&&(u.detail=t.detail),t.triggering_event_id&&(u.triggering_event_id=String(t.triggering_event_id)),u}let nL="issue";function nJ(t){return"info"===t||"warning"===t||"error"===t}function nq(t,n){return"appdata::".concat(t,"::").concat(n)}let nz="__keys__";class n${getKeySet(t){try{let n=localStorage.getItem(nq(t,nz));return n?new Set(JSON.parse(n)):new Set}catch(t){return new Set}}saveKeySet(t,n){localStorage.setItem(nq(t,nz),JSON.stringify([...n]))}async save(t,n,e,r){try{let i=nq(t,n),o=new Date().toISOString(),a=o;try{let t=localStorage.getItem(i);if(t){let n=JSON.parse(t);n.created_at&&(a=n.created_at)}}catch(t){}let u={app_id:t,data_key:n,content:e,metadata:r,created_at:a,updated_at:o};localStorage.setItem(i,JSON.stringify(u));let s=this.getKeySet(t);return s.add(n),this.saveKeySet(t,s),{ok:!0}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"localStorage save failed"}}}async load(t,n){try{let e=localStorage.getItem(nq(t,n));if(!e)return{ok:!0,data:void 0};let r=JSON.parse(e);return{ok:!0,data:r}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"localStorage load failed"}}}async remove(t,n){try{localStorage.removeItem(nq(t,n));let e=this.getKeySet(t);return e.delete(n),this.saveKeySet(t,e),{ok:!0}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"localStorage remove failed"}}}async list(t){try{let n=this.getKeySet(t);return{ok:!0,data:[...n]}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"localStorage list failed"}}}}class nK{extractResult(t){var n,e,r;let i=null==t?void 0:null===(e=t.data)||void 0===e?void 0:null===(n=e.result)||void 0===n?void 0:n.result;return Array.isArray(i)&&i.length>0&&(null===(r=i[0])||void 0===r?void 0:r.result)?i[0].result:i}async save(t,n,e,r){try{let i="".concat(t,"_").concat(n).replace(/[^a-zA-Z0-9_]/g,"_"),o=JSON.stringify(e),a=r?JSON.stringify(r):null;return await this.queryFn({query:"UPSERT type::record('app_data', $rid) SET app_id=$app_id, data_key=$data_key, content=$content, metadata=$metadata, updated_at=time::now()",variables:{rid:i,app_id:t,data_key:n,content:o,metadata:a}}),{ok:!0}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"SurrealDB save failed"}}}async load(t,n){try{let e=await this.queryFn({query:"SELECT * FROM app_data WHERE app_id=$app_id AND data_key=$data_key LIMIT 1",variables:{app_id:t,data_key:n}}),r=this.extractResult(e);if(!r||Array.isArray(r)&&0===r.length)return{ok:!0,data:void 0};let i=Array.isArray(r)?r[0]:r,o={app_id:i.app_id,data_key:i.data_key,content:JSON.parse(i.content),metadata:i.metadata?JSON.parse(i.metadata):void 0,created_at:i.created_at,updated_at:i.updated_at};return{ok:!0,data:o}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"SurrealDB load failed"}}}async remove(t,n){try{return await this.queryFn({query:"DELETE FROM app_data WHERE app_id=$app_id AND data_key=$data_key",variables:{app_id:t,data_key:n}}),{ok:!0}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"SurrealDB remove failed"}}}async list(t){try{let n=await this.queryFn({query:"SELECT data_key FROM app_data WHERE app_id=$app_id",variables:{app_id:t}}),e=this.extractResult(n);if(!e||Array.isArray(e)&&0===e.length)return{ok:!0,data:[]};let r=(Array.isArray(e)?e:[e]).map(t=>t.data_key);return{ok:!0,data:r}}catch(t){return{ok:!1,error:(null==t?void 0:t.message)||"SurrealDB list failed"}}}constructor(t){this.queryFn=t}}class nZ{static backendModeKey(t){return"appdata::".concat(t,"::__backend_mode__")}readModeFlag(){try{let t=localStorage.getItem(nZ.backendModeKey(this.app_id));return"cloud"===t?"cloud":"local"}catch(t){return"local"}}writeModeFlag(t){try{localStorage.setItem(nZ.backendModeKey(this.app_id),t)}catch(t){}}addInsightEvent(t,n){try{var e;null===(e=this.insights)||void 0===e||e.addEvent(t,{app_id:this.app_id,...n})}catch(t){}}getMode(){return this.mode}getLocalBackend(){return this.localBackend}switchToCloud(t){let n=this.mode;this.surrealBackend||(this.surrealBackend=new nK(t)),this.backend=this.surrealBackend,this.mode="cloud",this.writeModeFlag("cloud"),this.addInsightEvent("appdata_mode_switch",{from:n,to:"cloud"})}switchToLocal(){let t=this.mode;this.backend=this.localBackend,this.mode="local",this.writeModeFlag("local"),this.addInsightEvent("appdata_mode_switch",{from:t,to:"local"})}setBackend(t){this.backend=t}setInsights(t){this.insights=t}emitEvent(t,n){this.addInsightEvent(t,n)}async get(t){let n=Date.now(),e=await this.backend.load(this.app_id,t),r=Date.now()-n,i=e.ok&&e.data?e.data.content:null;return(this.addInsightEvent("appdata_load",{data_key:t,ok:e.ok,duration_ms:r,mode:this.mode,content:i}),e.ok&&e.data)?e.data.content:null}async set(t,n,e){let r=Date.now(),i=await this.backend.save(this.app_id,t,n,e),o=Date.now()-r;return this.addInsightEvent("appdata_save",{data_key:t,ok:i.ok,duration_ms:o,mode:this.mode,content:n}),i.ok}async remove(t){let n=Date.now(),e=await this.backend.remove(this.app_id,t),r=Date.now()-n;return this.addInsightEvent("appdata_remove",{data_key:t,ok:e.ok,duration_ms:r,mode:this.mode}),e.ok}async list(){let t=Date.now(),n=await this.backend.list(this.app_id),e=Date.now()-t;return this.addInsightEvent("appdata_list",{ok:n.ok,duration_ms:e,mode:this.mode,keys:n.data||[]}),n.data||[]}async loadFull(t){let n=Date.now(),e=await this.backend.load(this.app_id,t),r=Date.now()-n;return this.addInsightEvent("appdata_load",{data_key:t,ok:e.ok,duration_ms:r,mode:this.mode,full:!0,content:e.ok&&e.data?e.data.content:null}),e}async saveFull(t,n,e){let r=Date.now(),i=await this.backend.save(this.app_id,t,n,e),o=Date.now()-r;return this.addInsightEvent("appdata_save",{data_key:t,ok:i.ok,duration_ms:o,mode:this.mode,full:!0,content:n}),i}async migrate(t,n){let e=Date.now(),r=await t.list(this.app_id);if(!r.ok||!r.data)return{ok:!1,error:r.error||"Failed to list keys from source"};let i=0,o=0;for(let e of r.data){let r=await t.load(this.app_id,e);if(!r.ok||!r.data){o++;continue}(await n.save(this.app_id,e,r.data.content,r.data.metadata)).ok?
1i++:o++}let a=Date.now()-e;return this.addInsightEvent("appdata_migrate",{ok:0===o,migrated:i,failed:o,duration_ms:a,mode:this.mode}),{ok:0===o,data:{migrated:i,failed:o},error:o>0?"".concat(o," key(s) failed to migrate"):void 0}}constructor(t){if(this.app_id=t.app_id,this.insights=t.insights||null,this.localBackend=new n$,this.surrealBackend=t.cloudQueryFn?new nK(t.cloudQueryFn):null,t.backend)this.backend=t.backend,this.mode="local";else{let n=this.readModeFlag();this.mode=n,"cloud"===this.mode&&this.surrealBackend?this.backend=this.surrealBackend:(this.backend=this.localBackend,"cloud"!==this.mode||this.surrealBackend||(this.mode="local")),this.addInsightEvent("appdata_init",{flag_mode:n,resolved_mode:this.mode,has_cloud_query_fn:!!t.cloudQueryFn,backend_type:"cloud"===this.mode?"surreal":"local"})}}}var nW=e(68321);function nH(t,n){return n.split(".").reduce((t,n)=>{if(null!=t)return t[n]},t)}function nX(t){return new Promise(n=>setTimeout(n,t))}function nV(t,n,e){try{return Function("state","results","return "+t)(n,e)}catch(t){return!1}}async function nQ(t,n,e,r){let i=performance.now();for(;performance.now()-i<r;){if(nV(t,n(),e))return{ok:!0,waited_ms:Math.round(performance.now()-i)};await nX(100)}return{ok:!1,waited_ms:Math.round(performance.now()-i)}}function nG(t){return"action"in t}function nY(t){return"assert"in t}function n0(t){return"waitFor"in t}async function n1(t,n,e,r,i){var o,a,u,s,c,l,d;let f;let h=null!==(a=null==i?void 0:i.speed)&&void 0!==a?a:1,p=[],_=performance.now(),g=performance.now();for(;!r()&&performance.now()-g<1e4;)await nX(100);let m=["simi",t.app,t.id,...t.tags||[]],v=r();for(let a of((null==v?void 0:v.addSessionTags)&&v.addSessionTags(m),null==v||v.addEvent("simi_workflow_start",{workflow_id:t.id,app:t.app,step_count:t.steps.length,tags:m,...(null===(o=t.setupWorkflows)||void 0===o?void 0:o.length)?{setup_workflows:t.setupWorkflows}:{}}),null!==(u=t.setupWorkflows)&&void 0!==u?u:[])){let o=null==i?void 0:null===(s=i.workflowRegistry)||void 0===s?void 0:s[a];if(!o){let n="setupWorkflow not found in registry: ".concat(a);return null==v||v.addEvent("simi_workflow_complete",{workflow_id:t.id,total_ms:Math.round(performance.now()-_),steps_passed:0,steps_failed:0,completed:!1,error:n}),{completed:!1,workflow_id:t.id,total_ms:Math.round(performance.now()-_),steps:[],error:n}}let u=await n1(o,n,e,r,i);if(!u.completed){let n='setup "'.concat(a,'" failed: ').concat(null!==(c=u.error)&&void 0!==c?c:"unknown error");return null==v||v.addEvent("simi_workflow_complete",{workflow_id:t.id,total_ms:Math.round(performance.now()-_),steps_passed:0,steps_failed:0,completed:!1,error:n}),{completed:!1,workflow_id:t.id,total_ms:Math.round(performance.now()-_),steps:[],error:n}}}let y={};for(let r=0;r<t.steps.length;r++){let i=t.steps[r],o=(d=r,nG(i)?i.id||i.action:nY(i)?"assert_".concat(d):n0(i)?"waitFor_".concat(d):"step_".concat(d)),a=performance.now();try{if(nG(i)){let r,u=[];if(i.args&&i.args.length>0){let{resolved:n,resolverEvents:r}=function(t,n){let e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=[];return{resolved:t.map(t=>{if(!(null!==t&&"object"==typeof t&&"$resolve"in t))return t;try{let i=function(t,n,e){let r=n();switch(t.$resolve){case"state":{let n=nH(r,t.path);if(void 0===n)throw Error('state resolver: path "'.concat(t.path,'" not found in state'));return n}case"find":{let n=nH(r,t.path);if(!Array.isArray(n))throw Error('find resolver: path "'.concat(t.path,'" is not an array (got ').concat(typeof n,")"));if(0===n.length)throw Error('find resolver: array at "'.concat(t.path,'" is empty'));if(void 0!==t.index){let e=n[t.index];if(void 0===e)throw Error("find resolver: index ".concat(t.index,' out of bounds for "').concat(t.path,'" (length ').concat(n.length,")"));return e}if(t.match){let e=t.match,r=n.find(t=>Object.keys(e).every(n=>(function t(n,e,r){let i=n[e];return r instanceof RegExp?r.test(String(i)):null===r||"object"!=typeof r||Array.isArray(r)?i===r:null!==i&&"object"==typeof i&&Object.keys(r).every(n=>t(i,n,r[n]))})(t,n,e[n])));if(void 0===r)throw Error('find resolver: no match in "'.concat(t.path,'" for ').concat(JSON.stringify(e)));return r}throw Error('find resolver: must specify either "index" or "match"')}case"eval":return t.fn(r,e);case"result":{let n=e[t.step];if(void 0===n)throw Error('result resolver: no result for step "'.concat(t.step,'"'));if(t.path){let e=nH(n,t.path);if(void 0===e)throw Error('result resolver: path "'.concat(t.path,'" not found in result for step "').concat(t.step,'"'));return e}return n}default:throw Error("Unknown resolver type: ".concat(t.$resolve))}}(t,n,e);return r.push({resolver:t,status:"ok"}),i}catch(n){throw r.push({resolver:t,status:"error",error:n.message}),n}}),resolverEvents:r}}(i.args,e,y);for(let e of(u=n,r))null==v||v.addEvent("simi_resolve",{workflow_id:t.id,step:o,resolver_type:e.resolver.$resolve,status:e.status,...e.error?{error:e.error}:{}})}let s=n(i.action,...u);if(s&&"function"==typeof s.then){if(i.timeout){let t=new Promise((t,n)=>setTimeout(()=>n(Error('Action "'.concat(i.action,'" timed out after ').concat(i.timeout,"ms"))),i.timeout));r=await Promise.race([s,t])}else r=await s}else r=s;let c=Math.round(performance.now()-a);y[o]=r,p.push({step:o,result:r,duration_ms:c,status:"ok"}),null==v||v.addEvent("simi_step",{workflow_id:t.id,step:o,type:"action",action:i.action,duration_ms:c,status:"ok"}),i.wait&&await nX(i.wait/h)}else if(nY(i)){let n=nV(i.assert,e(),y),r=Math.round(performance.now()-a);if(!n){let n=i.message||"Assertion failed: ".concat(i.assert);p.push({step:o,duration_ms:r,status:"error",error:n}),null==v||v.addEvent("simi_step",{workflow_id:t.id,step:o,type:"assert",expression:i.assert,duration_ms:r,status:"error",error:n}),f=n;break}p.push({step:o,duration_ms:r,status:"ok"}),null==v||v.addEvent("simi_step",{workflow_id:t.id,step:o,type:"assert",expression:i.assert,duration_ms:r,status:"ok"})}else if(n0(i)){let n=null!==(l=i.timeout)&&void 0!==l?l:1e4,{ok:r,waited_ms:u}=await nQ(i.waitFor,e,y,n),s=Math.round(performance.now()-a);if(!r){let e="Timed out after ".concat(n,"ms waiting for: ").concat(i.waitFor);p.push({step:o,duration_ms:s,status:"error",error:e}),null==v||v.addEvent("simi_step",{workflow_id:t.id,step:o,type:"waitFor",expression:i.waitFor,waited_ms:u,duration_ms:s,status:"error",error:e}),f=e;break}p.push({step:o,duration_ms:s,status:"ok"}),null==v||v.addEvent("simi_step",{workflow_id:t.id,step:o,type:"waitFor",expression:i.waitFor,waited_ms:u,duration_ms:s,status:"ok"})}}catch(r){let n=Math.round(performance.now()-a),e=(null==r?void 0:r.message)||String(r);p.push({step:o,duration_ms:n,status:"error",error:e}),null==v||v.addEvent("simi_step",{workflow_id:t.id,step:o,type:nG(i)?"action":"unknown",duration_ms:n,status:"error",error:e}),f=e;break}}let w=Math.round(performance.now()-_),k=!f,E=p.filter(t=>"ok"===t.status).length,S=p.filter(t=>"error"===t.status).length;return null==v||v.addEvent("simi_workflow_complete",{workflow_id:t.id,total_ms:w,steps_passed:E,steps_failed:S,completed:k,...f?{error:f}:{}}
1),{completed:k,workflow_id:t.id,total_ms:w,steps:p,...f?{error:f}:{}}}function n2(t){try{let n=JSON.stringify(t);if(n&&n.length>2e3)return"[truncated: ".concat(n.length," chars]");return JSON.parse(n)}catch(t){return"[unserializable]"}}function n3(t){let{appName:n,silent:e}=t,r=null,i={emit:(t,e)=>{r&&r.addEvent(t,{app:n,...e})},getClient:()=>r},o=(0,nW.U)((o,a,u)=>{let s=t.creator(o,a,u,i),c={};for(let[t,i]of Object.entries(s)){if("function"!=typeof i||e&&("function"==typeof e?e(t):e.includes(t))){c[t]=i;continue}c[t]=function(){let e,o;for(var a=arguments.length,u=Array(a),s=0;s<a;s++)u[s]=arguments[s];let c=performance.now(),l="ok";try{e=i(...u)}catch(t){throw l="error",o=(null==t?void 0:t.message)||String(t),t}if(e&&"object"==typeof e&&"function"==typeof e.then)return e.then(e=>{let i=Math.round(performance.now()-c);return r&&r.addEvent("action",{app:n,action:t,kind:"async",args:n2(u),result:n2(e),duration_ms:i,status:"ok"},{duration_ms:i}),e},e=>{let i=Math.round(performance.now()-c);throw r&&r.addEvent("action",{app:n,action:t,kind:"async",args:n2(u),duration_ms:i,status:"error",error:(null==e?void 0:e.message)||String(e)},{duration_ms:i}),e});let d=Math.round(performance.now()-c);return r&&r.addEvent("action",{app:n,action:t,kind:"sync",args:n2(u),result:n2(e),duration_ms:d,status:l,...o?{error:o}:{}},{duration_ms:d}),e}}return c});function a(t){for(var e=arguments.length,r=Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];let a=o.getState()[t];if("function"!=typeof a)throw Error("[".concat(n,'] No action named "').concat(t,'"'));return a(...r)}{let e={dispatch:a,getState:o.getState};if(t.workflows){let n={},i={};for(let n of Object.values(t.workflows))i[n.id]=n;for(let e of Object.values(t.workflows))n[e.id]=async t=>{var n;let u={...t,workflowRegistry:{...i,...null!==(n=null==t?void 0:t.workflowRegistry)&&void 0!==n?n:{}}},s=await n1(e,a,o.getState,()=>r,u);return r&&"function"==typeof r.flushBatch&&await r.flushBatch(),s};e.simi={workflows:n,list:()=>Object.keys(n)}}window["__".concat(n,"__")]=e}return o.setInsights=t=>{r=t},o.dispatch=a,o}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.