diff --git a/assets/index-BQvSoGTm.js b/assets/index-BQvSoGTm.js index 3982861..639a561 100644 --- a/assets/index-BQvSoGTm.js +++ b/assets/index-BQvSoGTm.js @@ -1565,4 +1565,4 @@ https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety Toolcall output > `),r.code_interpreter.outputs.forEach(a=>{a.type==="logs"&&console.log(` ${a.logs} -`)})))})}async initThread(t=null){const n=[];t&&n.push({tool_resources:{code_interpreter:{file_ids:[t.id]}}}),this._thread=await this._client.beta.threads.create(...n)}async getFile(t){return(await this._client.files.list()).data.find(r=>r.filename===t)}async uploadFile(t){return await this._client.files.create({file:t,purpose:"assistants"})}}class xW{constructor({instructions:t,model:n="gpt-4o",filename:r="/llm-treemaps/assets/webgl-operate.csv",setAssistantBusy:i,onReadyCallback:a,onMessageCallback:o,onSystemCallback:_,onUpdateLatestAssistantMessage:u,onNotificationCallback:f}){this._assistant=null,this.instructions=t,this.model=n,this._filename=r,this._setAssistantBusy=i,this._readyCallback=a,this._messageCallback=o,this._onSystemCallback=_,this._onUpdateLatestAssistantMessage=u,this._notificationCallback=f,this._systemMessage=!1,this._systemMessageContent=""}async setToken(t){this._assistant=new IW({apiKey:t,instructions:this.instructions,model:this.model}),this._assistant.init().then(()=>this.fetchApiFile(this._filename)).then(n=>this._assistant.initThread(n)).then(()=>{this._readyCallback(!0),this._notificationCallback({source:"System",message:"API Token valid"})})}async fetchApiFile(t){let n=await this._assistant.getFile(t);if(!n){const r=await Xj(t);n=await this._assistant.uploadFile(r)}return n}sendMessage(t){this._readyCallback(!1),this._assistant.streamMessage(t,this)}_onTextCreated(t="text"){this._checkSystemMessage(),this._messageCallback("",t),this._setAssistantBusy(!1)}_onTextDelta(t){if(t==="```"&&(this._systemMessage=!0),!this._systemMessage)this._onUpdateLatestAssistantMessage(t);else{if(t==="json"||t==="```")return;this._systemMessageContent+=t}}_onRunCompleted(){this._checkSystemMessage(),this._readyCallback(!0)}_checkSystemMessage(){if(!this._systemMessage)return;console.log(this._systemMessageContent);const t=JSON.parse(this._systemMessageContent);this._onSystemCallback(t),this._systemMessage=!1,this._systemMessageContent=""}}function wW(e){const t={name:"/",children:[]};return e.forEach(n=>{const r=n.filename.replace("./","").split("/");r.reduce((i,a)=>{if(!i.children.find(o=>o.name===a)){const o={name:a,filename:n.filename,children:[]};a===r[r.length-1]&&(o.metrics=n),i.children.push(o)}return i.children.find(o=>o.name===a)},t)}),console.log(t),t.children.length===1?t.children[0]:t}function DW(e,t=["loc","noc","cloc","dc","nof"]){const n=new Dh.Configuration,r=[],i=new Map,a=new Map,o=Object.fromEntries(t.map(d=>[d,[0]]));function _(d,s=0){const c=r.length+1;i.set(c,d.name),a.set(d.filename,c),r.push([s,c]),d.metrics?t.forEach(l=>{o[l].push(d.metrics[l])}):t.forEach(l=>{o[l].push(0)}),d.children.forEach(l=>{_(l,c)})}_(e),console.log("names",i),console.log("edges",r),console.log("variables",o),n.topology={edges:r,format:"tupled"};const u=[{identifier:"source-null",type:"numbers",data:new Array(i.size+1).fill(0),linearization:"topology"}];t.forEach(d=>{u.push({identifier:`source-${d}`,type:"numbers",data:o[d],linearization:"topology"})}),n.buffers=u;const f=[{identifier:"weights",source:"buffer:source-loc",transformations:[{type:"fill-invalid",value:0,invalidValue:-1},{type:"propagate-up",operation:"sum"}]}];return t.forEach(d=>{f.push({identifier:d,source:`buffer:source-${d}`,transformations:[{type:"fill-invalid",value:0,invalidValue:-1},{type:"normalize",operation:"zero-to-max"}]})}),n.bufferViews=f,n.colors=[{identifier:"emphasis",space:"hex",value:"#00b0ff"},{identifier:"auxiliary",space:"hex",values:["#00aa5e","#71237c"]},{identifier:"inner",space:"hex",values:["#e8eaee","#eef0f4"]},{identifier:"leaf",space:"hex",values:["#d73027","#fc8d59","#fee090","#ffffbf","#e0f3f8","#91bfdb","#4575b4"]}],n.layout={algorithm:"snake",weight:"bufferView:weights",sort:{key:"bufferView:weights",algorithm:"keep"},parentPadding:{type:"relative",value:.05},siblingMargin:{type:"relative",value:.05},accessoryPadding:{type:"absolute",direction:"bottom",value:[0,.02,.01,0],relativeAreaThreshold:.4,targetAspectRatio:8}},n.geometry={parentLayer:{showRoot:!1},leafLayers:[{colorMap:"color:leaf",height:"buffer:source-null"},{colorMap:"color:leaf",height:"buffer:source-null"}],emphasis:{outline:new Array,highlight:new Array},heightScale:.5},n.labels={innerNodeLayerRange:[0,4],numTopInnerNodes:6,numTopWeightNodes:6,numTopHeightNodes:6,numTopColorNodes:6},n.altered.alter("labels"),n.filenameToIndex=a,n}let dm=null,jC=0;function LW(){const[e,t]=W.useState({source:"System",message:"supply api token in settings"}),[n,r]=W.useState([]),[i,a]=W.useState(null),[o,_]=W.useState({model:$s.model,instructions:$s.instructions}),[u,f]=W.useState(!0),[d,s]=W.useState(!1),[c,l]=W.useState(!0),h=W.useRef();W.useEffect(()=>{async function A(){const N=await Qj("/llm-treemaps/assets/webgl-operate.csv"),w=wW(N.rows);a(DW(w))}A()},[]);function g(A){f(!A)}function m(A,N="text"){r(w=>[...w,{id:jC++,from:"assistant",type:N,content:A}])}function E(A){r(N=>{const w=N.length-1,L=[...N];return L[w]={id:L[w].id,from:"assistant",type:L[w].type,content:L[w].content+A},L})}function S(A){r(N=>{const w=N.length-1,L=[...N];return L[w]={id:L[w].id,from:"assistant",type:L[w].type,content:L[w].content,system:A},L}),A.mapping&&v(A.mapping),A.highlight&&y(A.highlight)}function v(A){console.log("(System) change mapping",A),h.current.changeMapping(A)}function y(A){console.log("(System) highlight node",A),h.current.highlightNode(A)}function T(A){dm=new xW({instructions:$s.instructions,model:$s.model,setAssistantBusy:s,onReadyCallback:g,onMessageCallback:m,onSystemCallback:S,onUpdateLatestAssistantMessage:E,onNotificationCallback:t}),dm.setToken(A)}function O(A){_(A)}function C(A){s(!0),r(N=>[...N,{id:jC++,from:"user",content:A}]),dm.sendMessage(A)}return te.jsxs(te.Fragment,{children:[te.jsx(bq,{...e}),te.jsxs(Bg,{fluid:!0,children:[te.jsx(Sq,{config:o,hidden:c,setConfig:O,setHidden:l,setToken:T}),te.jsx(Eq,{hideSettings:l}),te.jsxs(ec,{className:"appContent vh-100",children:[te.jsx(Jl,{lg:5,className:"chatWindow position-absolute start-0 top-0 h-100 overflow-hidden",children:te.jsx(gq,{messages:n,onSendMessage:C,formLocked:u,assistantBusy:d,applyTreemapMapping:v,applyTreemapHighlighting:y})}),te.jsx(Jl,{lg:7,className:"canvasWindow position-absolute end-0 top-0 h-100",children:i&&te.jsx(Wj,{config:i,ref:h})})]})]})]})}pm.createRoot(document.getElementById("root")).render(te.jsx(lt.StrictMode,{children:te.jsx(LW,{})})); +`)})))})}async initThread(t=null){const n=[];t&&n.push({tool_resources:{code_interpreter:{file_ids:[t.id]}}}),this._thread=await this._client.beta.threads.create(...n)}async getFile(t){return(await this._client.files.list()).data.find(r=>r.filename===t)}async uploadFile(t){return await this._client.files.create({file:t,purpose:"assistants"})}}class xW{constructor({instructions:t,model:n="gpt-4o",filename:r="llm-treemaps/assets/webgl-operate.csv",setAssistantBusy:i,onReadyCallback:a,onMessageCallback:o,onSystemCallback:_,onUpdateLatestAssistantMessage:u,onNotificationCallback:f}){this._assistant=null,this.instructions=t,this.model=n,this._filename=r,this._setAssistantBusy=i,this._readyCallback=a,this._messageCallback=o,this._onSystemCallback=_,this._onUpdateLatestAssistantMessage=u,this._notificationCallback=f,this._systemMessage=!1,this._systemMessageContent=""}async setToken(t){this._assistant=new IW({apiKey:t,instructions:this.instructions,model:this.model}),this._assistant.init().then(()=>this.fetchApiFile(this._filename)).then(n=>this._assistant.initThread(n)).then(()=>{this._readyCallback(!0),this._notificationCallback({source:"System",message:"API Token valid"})})}async fetchApiFile(t){let n=await this._assistant.getFile(t);if(!n){const r=await Xj(t);n=await this._assistant.uploadFile(r)}return n}sendMessage(t){this._readyCallback(!1),this._assistant.streamMessage(t,this)}_onTextCreated(t="text"){this._checkSystemMessage(),this._messageCallback("",t),this._setAssistantBusy(!1)}_onTextDelta(t){if(t==="```"&&(this._systemMessage=!0),!this._systemMessage)this._onUpdateLatestAssistantMessage(t);else{if(t==="json"||t==="```")return;this._systemMessageContent+=t}}_onRunCompleted(){this._checkSystemMessage(),this._readyCallback(!0)}_checkSystemMessage(){if(!this._systemMessage)return;console.log(this._systemMessageContent);const t=JSON.parse(this._systemMessageContent);this._onSystemCallback(t),this._systemMessage=!1,this._systemMessageContent=""}}function wW(e){const t={name:"/",children:[]};return e.forEach(n=>{const r=n.filename.replace("./","").split("/");r.reduce((i,a)=>{if(!i.children.find(o=>o.name===a)){const o={name:a,filename:n.filename,children:[]};a===r[r.length-1]&&(o.metrics=n),i.children.push(o)}return i.children.find(o=>o.name===a)},t)}),console.log(t),t.children.length===1?t.children[0]:t}function DW(e,t=["loc","noc","cloc","dc","nof"]){const n=new Dh.Configuration,r=[],i=new Map,a=new Map,o=Object.fromEntries(t.map(d=>[d,[0]]));function _(d,s=0){const c=r.length+1;i.set(c,d.name),a.set(d.filename,c),r.push([s,c]),d.metrics?t.forEach(l=>{o[l].push(d.metrics[l])}):t.forEach(l=>{o[l].push(0)}),d.children.forEach(l=>{_(l,c)})}_(e),console.log("names",i),console.log("edges",r),console.log("variables",o),n.topology={edges:r,format:"tupled"};const u=[{identifier:"source-null",type:"numbers",data:new Array(i.size+1).fill(0),linearization:"topology"}];t.forEach(d=>{u.push({identifier:`source-${d}`,type:"numbers",data:o[d],linearization:"topology"})}),n.buffers=u;const f=[{identifier:"weights",source:"buffer:source-loc",transformations:[{type:"fill-invalid",value:0,invalidValue:-1},{type:"propagate-up",operation:"sum"}]}];return t.forEach(d=>{f.push({identifier:d,source:`buffer:source-${d}`,transformations:[{type:"fill-invalid",value:0,invalidValue:-1},{type:"normalize",operation:"zero-to-max"}]})}),n.bufferViews=f,n.colors=[{identifier:"emphasis",space:"hex",value:"#00b0ff"},{identifier:"auxiliary",space:"hex",values:["#00aa5e","#71237c"]},{identifier:"inner",space:"hex",values:["#e8eaee","#eef0f4"]},{identifier:"leaf",space:"hex",values:["#d73027","#fc8d59","#fee090","#ffffbf","#e0f3f8","#91bfdb","#4575b4"]}],n.layout={algorithm:"snake",weight:"bufferView:weights",sort:{key:"bufferView:weights",algorithm:"keep"},parentPadding:{type:"relative",value:.05},siblingMargin:{type:"relative",value:.05},accessoryPadding:{type:"absolute",direction:"bottom",value:[0,.02,.01,0],relativeAreaThreshold:.4,targetAspectRatio:8}},n.geometry={parentLayer:{showRoot:!1},leafLayers:[{colorMap:"color:leaf",height:"buffer:source-null"},{colorMap:"color:leaf",height:"buffer:source-null"}],emphasis:{outline:new Array,highlight:new Array},heightScale:.5},n.labels={innerNodeLayerRange:[0,4],numTopInnerNodes:6,numTopWeightNodes:6,numTopHeightNodes:6,numTopColorNodes:6},n.altered.alter("labels"),n.filenameToIndex=a,n}let dm=null,jC=0;function LW(){const[e,t]=W.useState({source:"System",message:"supply api token in settings"}),[n,r]=W.useState([]),[i,a]=W.useState(null),[o,_]=W.useState({model:$s.model,instructions:$s.instructions}),[u,f]=W.useState(!0),[d,s]=W.useState(!1),[c,l]=W.useState(!0),h=W.useRef();W.useEffect(()=>{async function A(){const N=await Qj("/llm-treemaps/assets/webgl-operate.csv"),w=wW(N.rows);a(DW(w))}A()},[]);function g(A){f(!A)}function m(A,N="text"){r(w=>[...w,{id:jC++,from:"assistant",type:N,content:A}])}function E(A){r(N=>{const w=N.length-1,L=[...N];return L[w]={id:L[w].id,from:"assistant",type:L[w].type,content:L[w].content+A},L})}function S(A){r(N=>{const w=N.length-1,L=[...N];return L[w]={id:L[w].id,from:"assistant",type:L[w].type,content:L[w].content,system:A},L}),A.mapping&&v(A.mapping),A.highlight&&y(A.highlight)}function v(A){console.log("(System) change mapping",A),h.current.changeMapping(A)}function y(A){console.log("(System) highlight node",A),h.current.highlightNode(A)}function T(A){dm=new xW({instructions:$s.instructions,model:$s.model,setAssistantBusy:s,onReadyCallback:g,onMessageCallback:m,onSystemCallback:S,onUpdateLatestAssistantMessage:E,onNotificationCallback:t}),dm.setToken(A)}function O(A){_(A)}function C(A){s(!0),r(N=>[...N,{id:jC++,from:"user",content:A}]),dm.sendMessage(A)}return te.jsxs(te.Fragment,{children:[te.jsx(bq,{...e}),te.jsxs(Bg,{fluid:!0,children:[te.jsx(Sq,{config:o,hidden:c,setConfig:O,setHidden:l,setToken:T}),te.jsx(Eq,{hideSettings:l}),te.jsxs(ec,{className:"appContent vh-100",children:[te.jsx(Jl,{lg:5,className:"chatWindow position-absolute start-0 top-0 h-100 overflow-hidden",children:te.jsx(gq,{messages:n,onSendMessage:C,formLocked:u,assistantBusy:d,applyTreemapMapping:v,applyTreemapHighlighting:y})}),te.jsx(Jl,{lg:7,className:"canvasWindow position-absolute end-0 top-0 h-100",children:i&&te.jsx(Wj,{config:i,ref:h})})]})]})]})}pm.createRoot(document.getElementById("root")).render(te.jsx(lt.StrictMode,{children:te.jsx(LW,{})}));