@kb-labs/agent-entry 2.118.2 → 2.119.0-canary.85d060ea6

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
- "use strict";(self.rspackChunk_kb_labs_agent_entry=self.rspackChunk_kb_labs_agent_entry||[]).push([[596],{6026(e,t){var n=Symbol.for("react.transitional.element");function r(e,t,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==t.key&&(o=""+t.key),"key"in t)for(var i in r={},t)"key"!==i&&(r[i]=t[i]);else r=t;return{$$typeof:n,type:e,key:o,ref:void 0!==(t=r.ref)?t:null,props:r}}t.Fragment=Symbol.for("react.fragment"),t.jsx=r,t.jsxs=r},4552(e,t,n){e.exports=n(6026)},5916(e,t,n){n.r(t),n.d(t,{default:()=>$});var r=n(4552),o=n(92),i=n(5963),l=n(5155),s=n(4519);function a(e){var t,n=e.currentSessionId,o=e.onSessionChange,i=e.onNewChat,a=(0,l.useUITheme)().token,c=(0,s.useData)("/v1/plugins/agents/sessions?limit=20"),u=c.data,d=c.isLoading,p=null!=(t=null==u?void 0:u.sessions)?t:[],f=function(e){var t=p.find(function(t){return t.id===e});t&&o(e,t)};return(0,r.jsxs)(l.UISpace,{size:"small",style:{width:"100%"},children:[(0,r.jsx)(l.UIIcon,{name:"HistoryOutlined",style:{color:a.colorTextTertiary}}),(0,r.jsx)(l.UISelect,{style:{flex:1,minWidth:200},placeholder:"New chat",value:null!=n?n:void 0,onChange:function(e){return f(e)},loading:d,allowClear:!0,onClear:i,notFoundContent:d?(0,r.jsx)(l.UISpin,{size:"small"}):(0,r.jsx)(l.UITypographyText,{type:"secondary",children:"No sessions yet"}),optionLabelProp:"label",options:p.map(function(e){return{value:e.id,label:e.name||e.task||"Untitled",lastActivityAt:e.lastActivityAt}}),optionRender:function(e){var t,n,o,i,s;return(0,r.jsxs)(l.UISpace,{style:{width:"100%",justifyContent:"space-between"},children:[(0,r.jsx)(l.UITypographyText,{ellipsis:!0,style:{maxWidth:180},children:e.label}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:11},children:(t=new Date(e.data.lastActivityAt),o=Math.floor((n=new Date().getTime()-t.getTime())/6e4),i=Math.floor(n/36e5),s=Math.floor(n/864e5),o<1?"just now":o<60?"".concat(o,"m ago"):i<24?"".concat(i,"h ago"):s<7?"".concat(s,"d ago"):t.toLocaleDateString())})]})}}),(0,r.jsx)(l.UITooltip,{title:"New Chat",children:(0,r.jsx)(l.UIButton,{variant:"primary",icon:(0,r.jsx)(l.UIIcon,{name:"PlusOutlined"}),onClick:i})})]})}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function u(e,t,n,r,o,i,l){try{var s=e[i](l),a=s.value}catch(e){n(e);return}s.done?t(a):Promise.resolve(a).then(r,o)}function d(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function l(e){u(i,r,o,l,s,"next",e)}function s(e){u(i,r,o,l,s,"throw",e)}l(void 0)})}}function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function f(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],l=!0,s=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);l=!0);}catch(e){s=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(s)throw r}}return i}}(e,t)||h(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return c(e,t)}}function g(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),s=Object.defineProperty;return s(l,"next",{value:a(0)}),s(l,"throw",{value:a(1)}),s(l,"return",{value:a(2)}),"function"==typeof Symbol&&s(l,Symbol.iterator,{value:function(){return this}}),l;function a(s){return function(a){var c=[s,a];if(n)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var x=n(9497).theme.useToken;function m(e){var t=e.turns,n=e.isLoading,o=e.isError,i=e.onRetry,s=e.sessionId,a=x().token;return n?(0,r.jsxs)(l.UIFlex,{justify:"center",align:"center",style:{minHeight:240,gap:8},children:[(0,r.jsx)(l.UISpin,{size:"small"}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:13},children:"Loading history..."})]}):o?(0,r.jsxs)("div",{style:{minHeight:240,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12},children:[(0,r.jsx)(l.UIIcon,{name:"DisconnectOutlined",style:{fontSize:24,color:a.colorTextTertiary}}),(0,r.jsx)(l.UITypographyText,{type:"secondary",children:"Failed to load history"}),i&&(0,r.jsx)(l.UIButton,{size:"small",onClick:i,children:"Retry"})]}):0===t.length?(0,r.jsx)(l.UIFlex,{justify:"center",align:"center",style:{minHeight:240},children:(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:14},children:"Ask anything to get started"})}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",padding:"16px 16px 40px",gap:24},children:t.map(function(e){return(0,r.jsx)(v,{turn:e,sessionId:s,token:a},e.id)})})}function v(e){var t,n,o,i,s,a,c,u,d=e.turn,p=e.sessionId,f=e.token;if("user"===d.type){var y=d.steps.find(function(e){return"text"===e.type});return(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"flex-end",gap:8},children:[(0,r.jsx)("span",{style:{maxWidth:"68%",background:f.colorFillTertiary,borderRadius:"".concat(f.borderRadiusLG,"px ").concat(f.borderRadiusLG,"px 3px ").concat(f.borderRadiusLG,"px"),padding:"10px 16px",fontSize:14,lineHeight:1.55,color:f.colorText,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:(null==y?void 0:y.type)==="text"?y.content:""}),(0,r.jsx)("div",{style:{width:28,height:28,borderRadius:"50%",background:f.colorFillSecondary,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,r.jsx)(l.UIIcon,{name:"UserOutlined",style:{fontSize:13,color:f.colorTextSecondary}})})]})}var h="streaming"===d.status,g=d.steps.filter(function(e){return"text"===e.type}),x=g.filter(function(e){var t,n;return!P(null!=(t=e.content)?t:"")&&(null==(n=e.content)?void 0:n.trim())}),m=d.steps.find(function(e){return"tool_use"===e.type&&"report"===e.toolName}),v=null==m||null==(a=m.input)?void 0:a.answer,j=d.steps.filter(function(e){return"text"!==e.type&&("tool_use"!==e.type||"report"!==e.toolName)}),I=j.length>0||h&&g.every(function(e){var t;return P(null!=(t=e.content)?t:"")}),k=null!=v?v:null,w=null==(c=d.metadata)?void 0:c.fileChanges,T=null==(u=d.metadata)?void 0:u.runId,U=!h&&w&&w.length>0&&!!p&&!!T,z={display:"flex",flexDirection:"column",borderLeft:"2px solid ".concat(f.colorBorderSecondary),paddingLeft:12,gap:6,marginLeft:6};return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("div",{style:{width:22,height:22,borderRadius:"50%",background:f.colorFillSecondary,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,r.jsx)(l.UIIcon,{name:"RobotOutlined",style:{fontSize:12,color:f.colorTextSecondary}})}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:12},children:"Agent"}),(0,r.jsxs)(l.UITypographyText,{type:"secondary",style:{fontSize:11},children:["\xb7 ",(t=new Date(d.startedAt),o=Math.floor((n=new Date().getTime()-t.getTime())/6e4),i=Math.floor(n/36e5),s=Math.floor(n/864e5),o<1?"just now":o<60?"".concat(o,"m ago"):i<24?"".concat(i,"h ago"):s<7?"".concat(s,"d ago"):t.toLocaleDateString())]}),h&&(0,r.jsx)(l.UITag,{color:"processing",style:{fontSize:11,lineHeight:"18px"},children:"Running"}),"failed"===d.status&&(0,r.jsx)(l.UITag,{color:"error",style:{fontSize:11,lineHeight:"18px"},children:"Failed"})]}),I&&(0,r.jsx)("div",{style:z,children:(0,r.jsx)(b,{steps:j,isStreaming:h,token:f})}),k&&(0,r.jsx)("div",{style:z,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(S,{color:f.colorPrimary}),(0,r.jsx)(l.UIMarkdownViewer,{content:k,style:{flex:1}})]})}),!k&&x.map(function(e){var t;return"text"===e.type&&(null==(t=e.content)?void 0:t.trim())?(0,r.jsx)("div",{style:z,children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(S,{color:f.colorPrimary}),(0,r.jsx)(l.UIMarkdownViewer,{content:e.content,style:{flex:1}})]})},e.id):null}),U&&(0,r.jsx)("div",{style:z,children:(0,r.jsx)(O,{sessionId:p,runId:T,fileChanges:w,token:f})})]})}function b(e){var t=e.steps,n=e.isStreaming,i=e.token,s=y((0,o.useState)(n),2),a=s[0],c=s[1];(0,o.useEffect)(function(){n&&c(!0)},[n]);var u=Object.entries(function(e){var t={},n=!0,r=!1,o=void 0;try{for(var i,l=e[Symbol.iterator]();!(n=(i=l.next()).done);n=!0){var s=i.value;if("tool_use"===s.type){var a,c=A(s.toolName);t[c]=(null!=(a=t[c])?a:0)+1}}}catch(e){r=!0,o=e}finally{try{n||null==l.return||l.return()}finally{if(r)throw o}}return t}(t)).map(function(e){var t=y(e,2),n=t[0],r=t[1];return r>1?"".concat(n," \xd7").concat(r):n}),d=t.reduce(function(e,t){var n;return e+("tool_use"===t.type&&null!=(n=t.durationMs)?n:0)},0),p={display:"inline-flex",alignItems:"center",gap:5,background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontSize:12,color:i.colorTextSecondary,fontFamily:"inherit"};return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{style:p,onClick:function(){return c(function(e){return!e})},children:[(0,r.jsx)(l.UIIcon,{name:a?"DownOutlined":"RightOutlined",style:{fontSize:9,color:i.colorTextTertiary}}),n?(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined",style:{fontSize:11,color:i.colorTextTertiary}}):null,(0,r.jsxs)("span",{style:{fontWeight:500,color:i.colorText},children:[t.length," ",1===t.length?"action":"actions"]}),!a&&u.length>0&&(0,r.jsxs)("span",{style:{color:i.colorTextTertiary},children:["— ",u.join(" ")]}),!a&&d>0&&(0,r.jsxs)("span",{style:{color:i.colorTextTertiary},children:["\xb7 ",(d/1e3).toFixed(1),"s"]})]}),a&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5,marginTop:4},children:[t.map(function(e,o){return(0,r.jsx)(I,{step:e,isLast:!1,isStreaming:n&&o===t.length-1,token:i},e.id)}),n&&0===t.length&&(0,r.jsx)(j,{token:i})]})]})}function S(e){var t=e.color,n=e.pulse;return(0,r.jsx)("span",{style:{flexShrink:0,width:8,height:8,marginTop:6,borderRadius:"50%",background:t,opacity:n?.6:1}})}function j(e){var t=e.token;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined",style:{fontSize:11,color:t.colorTextTertiary}}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:13},children:"Thinking..."})]})}function I(e){var t,n,o,i=e.step,s=e.isStreaming,a=e.token;switch(i.type){case"thinking":var c,u,d=null!=(c=null==(u=i.content)?void 0:u.trim())?c:"";if(P(d))return null;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(S,{color:a.colorWarning,pulse:s}),(0,r.jsx)("div",{style:{flex:1},children:(0,r.jsx)(l.UIMarkdownViewer,{content:d,style:{fontSize:13,opacity:.8}})})]});case"tool_use":return(0,r.jsx)(k,{step:i,isStreaming:s,token:a});case"tool_result":return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:i.success?"CheckCircleOutlined":"CloseCircleOutlined",style:{fontSize:13,marginTop:2,color:i.success?a.colorSuccess:a.colorError}}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsxs)("span",{style:{fontSize:13,color:a.colorTextSecondary},children:[(0,r.jsx)("span",{style:{fontWeight:500,color:a.colorText},children:A(i.toolName)}),void 0!==i.durationMs&&(0,r.jsxs)("span",{style:{marginLeft:6,fontSize:11,color:a.colorTextTertiary},children:[i.durationMs,"ms"]})]}),!i.success&&i.error&&(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:a.colorError},children:i.error})]})]});case"subagent":return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:"RobotOutlined",style:{fontSize:13,marginTop:2,color:a.colorPrimary}}),(0,r.jsxs)("span",{style:{fontSize:13,color:a.colorTextSecondary},children:[(0,r.jsxs)("span",{style:{fontWeight:500,color:a.colorText},children:["Agent: ",i.agentName]}),(0,r.jsxs)("span",{style:{marginLeft:6},children:["— ",null==(n=i.task)?void 0:n.slice(0,60),(null!=(t=null==(o=i.task)?void 0:o.length)?t:0)>60?"...":""]})]})]});case"error":return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:"ExclamationCircleOutlined",style:{fontSize:13,marginTop:2,color:a.colorError}}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:500,color:a.colorError},children:i.code}),(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:a.colorError},children:i.message})]})]});default:return null}}function k(e){var t,n,i,s=e.step,a=e.isStreaming,c=e.token,u=y((0,o.useState)(!1),2),d=u[0],p=u[1],f="pending"===s.status,h="done"===s.status,g="error"===s.status,x=h&&!1===s.success,m=function(e){var t=e.input;if(!t)return{};var n=e.toolName.toLowerCase(),r=n.includes("read"),o=n.includes("write")||n.includes("patch")||n.includes("edit"),i=null!=(s=null!=(a=null!=(c=t.path)?c:t.filePath)?a:t.file_path)?s:t.file;if(i){var l=null!=(h=String(i).split("/").pop())?h:String(i);if(r){var s,a,c,u,d,p,f,y,h,g,x,m,v,b,S=null!=(x=null!=(m=t.offset)?m:t.startLine)?x:t.start_line,j=null!=(v=null!=(b=t.limit)?b:t.endLine)?v:t.end_line;void 0!==S&&void 0!==j?g="".concat(S,"-").concat(Number(S)+Number(j)):void 0!==j&&(g="".concat(j," lines"))}return{summary:l,filePath:String(i),badge:g}}var I=null!=(u=null!=(d=null!=(p=t.query)?p:t.text)?d:t.pattern)?u:t.search;if(I)return{summary:String(I).slice(0,100)};var k=null!=(f=t.command)?f:t.cmd;if(k)return{summary:String(k).slice(0,100)};if(o)return{};var w=null!=(y=t.content)?y:t.message;return w?{summary:String(w).slice(0,100)}:{}}(s),v=h&&!!(null==(i=s.metadata)?void 0:i.diff),b=h&&null!=s.output,S=s.input,j=/write|patch|edit/i.test(s.toolName)&&h&&!!(null!=(n=null==S?void 0:S.content)?n:null==S?void 0:S.new_content),I=b||v||j||g,k=f?a?c.colorTextTertiary:c.colorPrimary:h&&!x?c.colorSuccess:c.colorError,T=s.metadata,O=h&&(null==T?void 0:T.uiHint)==="todo"&&null!=T.structured?T.structured.todoList:void 0;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:f&&a?"LoadingOutlined":(t=s.toolName.toLowerCase(),/read|open/.test(t)?"FileTextOutlined":/write|patch|edit/.test(t)?"EditOutlined":/bash|exec|shell|run/.test(t)?"CodeOutlined":/grep|search|glob|find/.test(t)?"SearchOutlined":/todo/.test(t)?"CheckSquareOutlined":/rag|mind|embed/.test(t)?"BulbOutlined":/agent|subagent/.test(t)?"RobotOutlined":/delete|remove/.test(t)?"DeleteOutlined":"ApiOutlined"),style:{fontSize:13,marginTop:2,color:k,flexShrink:0}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsxs)("button",{onClick:function(){return I&&p(function(e){return!e})},disabled:!I,style:{display:"inline-flex",alignItems:"center",gap:6,background:"none",border:"none",padding:0,cursor:I?"pointer":"default",fontSize:13,color:c.colorText,flexWrap:"wrap",fontFamily:"inherit"},children:[(0,r.jsx)("span",{style:{fontWeight:500},children:A(s.toolName)}),m.badge&&(0,r.jsx)("span",{style:{fontSize:11,color:c.colorTextSecondary,background:c.colorFillSecondary,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:m.badge}),h&&(null==T?void 0:T.resultCount)!==void 0&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorTextSecondary,background:c.colorFillSecondary,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:[T.resultCount," results"]}),h&&(null==T?void 0:T.exitCode)!==void 0&&0!==T.exitCode&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorError,background:c.colorErrorBg,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:["exit ",T.exitCode]}),h&&((null==T?void 0:T.linesAdded)!==void 0||(null==T?void 0:T.linesRemoved)!==void 0)&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorSuccess,background:c.colorSuccessBg,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:[(null==T?void 0:T.linesAdded)!=null&&T.linesAdded>0?"+".concat(T.linesAdded):"",(null==T?void 0:T.linesRemoved)!=null&&T.linesRemoved>0?" -".concat(T.linesRemoved):""]}),!f&&void 0!==s.durationMs&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorTextTertiary},children:[s.durationMs,"ms"]}),I&&(0,r.jsx)("span",{style:{fontSize:11,color:c.colorTextTertiary},children:d?"▲":"▼"})]}),m.summary&&(0,r.jsx)("p",{style:{margin:"2px 0 0",fontSize:12,color:c.colorTextSecondary},children:m.filePath?(0,r.jsx)(U,{path:m.filePath,label:m.summary,token:c}):m.summary}),null!=O&&(0,r.jsx)(R,{todoList:O,token:c}),g&&s.error&&(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:c.colorError},children:s.error}),x&&!d&&null!=s.output&&(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:c.colorError},children:String(s.output)}),d&&(0,r.jsx)("div",{style:{marginTop:6},children:(0,r.jsx)(w,{step:s,hasDiff:v,hasOutput:b,token:c})})]})]})}function w(e){var t=e.step,n=e.hasDiff,o=e.hasOutput,i=e.token,s=t.input,a=t.toolName.toLowerCase(),c=a.includes("write")||a.includes("patch")||a.includes("edit"),u=a.includes("read"),d=a.includes("bash")||a.includes("exec")||a.includes("shell")||a.includes("run"),y=a.includes("grep")||a.includes("search")||a.includes("glob")||a.includes("list")||a.includes("rag"),h={margin:0,padding:"8px 10px",fontSize:12,lineHeight:1.5,borderRadius:i.borderRadius,overflow:"auto",maxHeight:300,whiteSpace:"pre-wrap",wordBreak:"break-all"};if(c){if(n)return(0,r.jsx)(T,{diff:t.metadata.diff,token:i});var g=null!=(x=null!=(m=null==s?void 0:s.content)?m:null==s?void 0:s.new_content)?x:null==s?void 0:s.text;if(g){var x,m,v,b,S,j=null!=(v=null!=(b=null!=(S=null==s?void 0:s.path)?S:null==s?void 0:s.filePath)?b:null==s?void 0:s.file_path)?v:null==s?void 0:s.file,I=j?j.split(".").pop():void 0;return(0,r.jsxs)("div",{children:[j&&(0,r.jsx)("div",{style:{fontSize:11,color:i.colorTextTertiary,padding:"3px 8px",background:i.colorFillSecondary,borderRadius:"".concat(i.borderRadius,"px ").concat(i.borderRadius,"px 0 0")},children:j}),(0,r.jsx)("pre",{style:f(p({},h),{background:i.colorFillSecondary,borderRadius:j?"0 0 ".concat(i.borderRadius,"px ").concat(i.borderRadius,"px"):i.borderRadius}),className:I?"lang-".concat(I):void 0,children:String(g)})]})}return null}if(u&&o)return(0,r.jsx)("pre",{style:f(p({},h),{background:i.colorFillSecondary}),children:D(t.output)});if(d&&o)return(0,r.jsx)("pre",{style:f(p({},h),{background:i.colorBgSpotlight,color:i.colorTextLightSolid}),children:D(t.output)});if(y&&o)return(0,r.jsx)("pre",{style:f(p({},h),{background:i.colorFillSecondary}),children:D(t.output)});if(n)return(0,r.jsx)(T,{diff:t.metadata.diff,token:i});if(o){var k="done"===t.status&&!1===t.success,w=D(t.output);return k?(0,r.jsx)("pre",{style:f(p({},h),{background:i.colorErrorBg,color:i.colorError}),children:w}):(0,r.jsx)(l.UIMarkdownViewer,{content:w,style:{fontSize:12}})}return null}function T(e){var t=e.diff,n=e.token,o=t.split("\n");return(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",fontSize:12,lineHeight:1.5,borderRadius:n.borderRadius,overflow:"auto",maxHeight:300,background:n.colorFillSecondary,whiteSpace:"pre"},children:o.map(function(e,t){var o=e.startsWith("+")&&!e.startsWith("+++")?n.colorSuccess:e.startsWith("-")&&!e.startsWith("---")?n.colorError:e.startsWith("@@")?n.colorInfo:void 0;return(0,r.jsxs)("span",{style:o?{color:o}:void 0,children:[e,"\n"]},t)})})}function U(e){var t=e.path,n=e.label,i=e.token,l=y((0,o.useState)(!1),2),s=l[0],a=l[1];return(0,r.jsxs)("span",{onClick:function(e){e.stopPropagation(),navigator.clipboard.writeText(t).then(function(){a(!0),setTimeout(function(){return a(!1)},1500)})},title:t,style:{cursor:"pointer",color:s?i.colorSuccess:i.colorTextSecondary,fontFamily:"monospace",fontSize:12},children:[n,s?" ✓":""]})}function O(e){var t=e.sessionId,n=e.runId,i=e.fileChanges,a=e.token,u=y((0,o.useState)(new Set),2),p=u[0],f=u[1],x=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(t,"/rollback"),"POST"),m=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(t,"/approve"),"POST"),v=i.filter(function(e){return!p.has(e.changeId)&&!e.approved});return 0===v.length?null:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:"FileOutlined",style:{fontSize:13,marginTop:2,color:a.colorSuccess}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[(0,r.jsxs)(l.UITypographyText,{style:{fontSize:13,fontWeight:500},children:[v.length," ",L(v.length)," changed"]}),(0,r.jsxs)(l.UIFlex,{gap:4,children:[(0,r.jsx)("button",{onClick:function(){d(function(){return g(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,m.mutateAsync({runId:n})];case 1:return e.sent(),f(new Set(v.map(function(e){return e.changeId}))),[3,3];case 2:return e.sent(),console.error("Failed to approve changes"),[3,3];case 3:return[2]}})})()},disabled:m.isLoading||x.isLoading,title:"Approve all",style:{background:a.colorSuccessBg,border:"1px solid ".concat(a.colorSuccessBorder),color:a.colorSuccess,borderRadius:a.borderRadius,padding:"2px 8px",fontSize:12,cursor:"pointer"},children:"✓"}),(0,r.jsx)("button",{onClick:function(){(0,l.UIModalConfirm)({title:"Rollback changes?",content:"This will revert ".concat(v.length," ").concat(L(v.length)," to the state before the agent run."),okText:"Rollback",okButtonProps:{danger:!0},cancelText:"Cancel",onOk:function(){return d(function(){var e,t;return g(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,x.mutateAsync({runId:n})];case 1:return(null==(e=(t=r.sent()).conflicts)?void 0:e.length)&&console.warn("Rolled back: ".concat(t.rolledBack,", skipped: ").concat(t.skipped)),f(new Set(v.map(function(e){return e.changeId}))),[3,3];case 2:return r.sent(),console.error("Failed to rollback changes"),[3,3];case 3:return[2]}})})()}})},disabled:x.isLoading||m.isLoading,title:"Rollback all",style:{background:a.colorErrorBg,border:"1px solid ".concat(a.colorErrorBorder),color:a.colorError,borderRadius:a.borderRadius,padding:"2px 8px",fontSize:12,cursor:"pointer"},children:"✕"})]})]}),(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:2},children:v.map(function(e){return(0,r.jsx)(z,{change:e,sessionId:t,onDismiss:function(){return f(function(t){return new Set(((function(e){if(Array.isArray(e))return c(e)})(t)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||h(t)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).concat([e.changeId]))})},token:a},e.changeId)})})]})]})}function z(e){var t,n=e.change,i=e.sessionId,a=e.onDismiss,c=e.token,u=y((0,o.useState)(!1),2),p=u[0],f=u[1],h=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(i,"/rollback"),"POST"),x=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(i,"/approve"),"POST"),m=p?"/v1/plugins/agents/sessions/".concat(i,"/changes/").concat(encodeURIComponent(n.changeId),"/diff"):"",v=(0,s.useData)(m,{enabled:p}),b=v.data,S=v.isLoading,j=v.isError,I=n.isNew?(0,r.jsx)(l.UITag,{color:"success",children:"new"}):"delete"===n.operation?(0,r.jsx)(l.UITag,{color:"error",children:"del"}):(0,r.jsx)(l.UITag,{color:"blue",children:"mod"});return(0,r.jsxs)("li",{children:[(0,r.jsxs)("div",{onClick:function(){return f(function(e){return!e})},style:{display:"flex",alignItems:"center",gap:6,fontSize:12,cursor:"pointer",padding:"2px 4px",borderRadius:c.borderRadiusSM,background:p?c.colorFillSecondary:"transparent"},children:[I,(0,r.jsx)("span",{style:{flex:1,fontFamily:"monospace",color:c.colorTextSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:null!=(t=n.filePath.split("/").pop())?t:n.filePath}),(0,r.jsx)("span",{style:{color:c.colorTextTertiary,fontFamily:"monospace",fontSize:11},children:n.filePath.includes("/")?n.filePath.slice(0,n.filePath.lastIndexOf("/")):""}),!n.approved&&(0,r.jsxs)("div",{style:{display:"flex",gap:4},onClick:function(e){return e.stopPropagation()},children:[(0,r.jsx)("button",{onClick:function(e){e.stopPropagation(),x.mutateAsync({changeIds:[n.changeId]}).then(a).catch(function(){console.error("Failed to approve file")})},disabled:x.isLoading,title:"Approve",style:{background:"none",border:"none",cursor:"pointer",color:c.colorSuccess,fontSize:13,padding:"0 2px"},children:"✓"}),(0,r.jsx)("button",{onClick:function(e){e.stopPropagation(),(0,l.UIModalConfirm)({title:"Rollback file?",content:n.filePath,okText:"Rollback",okButtonProps:{danger:!0},cancelText:"Cancel",onOk:function(){return d(function(){return g(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,h.mutateAsync({changeIds:[n.changeId]})];case 1:return e.sent(),a(),[3,3];case 2:return e.sent(),console.error("Failed to rollback file"),[3,3];case 3:return[2]}})})()}})},disabled:h.isLoading,title:"Rollback",style:{background:"none",border:"none",cursor:"pointer",color:c.colorError,fontSize:13,padding:"0 2px"},children:"✕"})]})]}),p&&(0,r.jsxs)("div",{style:{marginTop:4,marginLeft:4},children:[S&&(0,r.jsx)(l.UISpin,{size:"small"}),(null==b?void 0:b.diff)&&(0,r.jsx)(T,{diff:b.diff,token:c}),j&&(0,r.jsx)("span",{style:{color:c.colorError,fontSize:12},children:"Failed to load diff"})]})]})}var C={completed:"✓","in-progress":"●",blocked:"✕",pending:"○"};function R(e){var t,n=e.todoList,o=e.token;if(!(null==n||null==(t=n.items)?void 0:t.length))return null;var i=n.items.filter(function(e){return"completed"===e.status}).length;return(0,r.jsxs)("div",{style:{marginTop:6,background:o.colorFillTertiary,borderRadius:o.borderRadius,padding:"8px 10px"},children:[(0,r.jsxs)("div",{style:{fontSize:11,color:o.colorTextTertiary,marginBottom:6,fontWeight:500},children:[i,"/",n.items.length]}),(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:2},children:n.items.map(function(e){var t;return(0,r.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,lineHeight:1.5,padding:"2px 0"},children:[(0,r.jsx)("span",{style:{fontSize:12,flexShrink:0,width:14,textAlign:"center",lineHeight:1},children:null!=(t=C[e.status])?t:"○"}),"completed"===e.status?(0,r.jsx)(l.UITypographyText,{type:"success",style:{flex:1,minWidth:0,textDecoration:"line-through"},children:e.description}):"pending"===e.status||"blocked"===e.status?(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{flex:1,minWidth:0},children:e.description}):(0,r.jsx)(l.UITypographyText,{style:{flex:1,minWidth:0},children:e.description}),"medium"!==e.priority&&(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:11,flexShrink:0},children:e.priority})]},e.id)})})]})}function A(e){var t=e.trim().toLowerCase().replace(/[_-]/g," ");if(t.includes("fs read")||t.includes("read file"))return"Read";if(t.includes("fs write")||t.includes("write file"))return"Write";if(t.includes("fs patch")||t.includes("patch file")||t.includes("fs edit")||t.includes("edit file"))return"Edit";if(t.includes("fs delete")||t.includes("delete file")||t.includes("remove file"))return"Delete";if(t.includes("fs list")||t.includes("list files")||t.includes("glob"))return"Glob";if(t.includes("grep")||t.includes("search content"))return"Grep";if(t.includes("bash")||t.includes("exec")||t.includes("shell")||t.includes("run command"))return"Bash";if(t.includes("rag")||t.includes("mind"))return"Mind";if(t.includes("todo"))return"TodoWrite";var n=e.indexOf(":");return(n>=0?e.slice(n+1):e).replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,function(e){return e.toUpperCase()})}function P(e){var t=e.trim().toLowerCase();return!!("[executing tools...]"===t||"[thinking...]"===t||"[planning...]"===t||"[analyzing...]"===t||"analyzing context and choosing the next step."===t||t.startsWith("checking facts with tool:")||t.startsWith("running step with tool:")||t.startsWith("running the next step"))||"done."===t||"ok."===t||"done"===t||"ok"===t}function L(e){return 1===e?"file":"files"}function D(e){if("string"==typeof e)return e.slice(0,2e3);try{return JSON.stringify(e,null,2).slice(0,2e3)}catch(t){return String(e).slice(0,2e3)}}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function M(e,t,n,r,o,i,l){try{var s=e[i](l),a=s.value}catch(e){n(e);return}s.done?t(a):Promise.resolve(a).then(r,o)}function F(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function l(e){M(i,r,o,l,s,"next",e)}function s(e){M(i,r,o,l,s,"throw",e)}l(void 0)})}}function B(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function W(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],l=!0,s=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);l=!0);}catch(e){s=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(s)throw r}}return i}}(e,t)||N(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _(e){return function(e){if(Array.isArray(e))return E(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||N(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function N(e,t){if(e){if("string"==typeof e)return E(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return E(e,t)}}function q(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),s=Object.defineProperty;return s(l,"next",{value:a(0)}),s(l,"throw",{value:a(1)}),s(l,"return",{value:a(2)}),"function"==typeof Symbol&&s(l,Symbol.iterator,{value:function(){return this}}),l;function a(s){return function(a){var c=[s,a];if(n)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function H(e,t){if(e.sequence!==t.sequence)return e.sequence-t.sequence;if(e.type!==t.type){if("user"===e.type)return -1;if("user"===t.type)return 1}return e.startedAt.localeCompare(t.startedAt)}function G(e){var t=e.status,n=e.sessionId,o=e.onReconnect,i=(0,l.useUITheme)().token;return n&&"connected"!==t?"connecting"===t?(0,r.jsxs)(l.UISpace,{size:4,children:[(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined",style:{fontSize:12,color:i.colorTextTertiary}}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:12},children:"Connecting..."})]}):(0,r.jsxs)(l.UISpace,{size:4,children:[(0,r.jsx)(l.UIIcon,{name:"DisconnectOutlined",style:{fontSize:12,color:i.colorError}}),(0,r.jsx)(l.UIButton,{variant:"link",size:"small",style:{padding:0,fontSize:12,height:"auto"},onClick:o,children:"Reconnect"})]}):null}let $=function(){var e,t,n=(0,l.useUITheme)().token,c=(0,o.useRef)(null),u=W((0,i.useSearchParams)(),2),d=u[0],p=u[1],f=W((0,o.useState)(function(){return d.get("session")}),2),y=f[0],h=f[1],g=W((0,o.useState)(function(){return d.get("session")}),2),x=g[0],v=g[1],b=W((0,o.useState)(""),2),S=b[0],j=b[1],I=W((0,o.useState)(null),2),k=I[0],w=I[1],T=W((0,o.useState)("idle"),2),U=T[0],O=T[1],z=W((0,o.useState)([]),2),C=z[0],R=z[1],A=W((0,o.useState)([]),2),P=A[0],L=A[1],D=W((0,o.useState)("auto"),2),E=D[0],M=D[1],N=W((0,o.useState)("medium"),2),$=N[0],V=N[1],K=W((0,o.useState)(!0),2),J=K[0],Z=K[1],Q=W((0,o.useState)("execute"),2),X=Q[0],Y=Q[1],ee=W((0,o.useState)(!1),2),et=ee[0],en=ee[1],er="mind-assistant",eo=y?(e="https:"===window.location.protocol?"wss:":"ws:",t=window.location.host,"".concat(e,"//").concat(t,"/api/v1/ws/plugins/agents/session/").concat(y)):null,ei=(0,s.useMutateData)("/v1/plugins/agents/run","POST"),el=(0,s.useMutateData)(k?"/v1/plugins/agents/run/".concat(k,"/stop"):"/v1/plugins/agents/run/noop/stop","POST"),es=y?"/v1/plugins/agents/sessions/".concat(y,"/turns"):"",ea=(0,s.useData)(es,{enabled:!!y}),ec=ea.data,eu=ea.isFetching,ed=ea.isError,ep=ea.refetch;(0,o.useEffect)(function(){y&&(ec||ed)&&!eu&&v(y)},[y,ec,ed,eu]);var ef=(0,s.useWebSocket)(eo,{reconnect:!0,maxReconnects:10,reconnectIntervalMs:2e3,onMessage:function(e){switch(e.type){case"conversation:snapshot":L(_(e.payload.completedTurns).concat(_(e.payload.activeTurns)).sort(function(e,t){return e.sequence-t.sequence})),R([]);break;case"turn:snapshot":var t=e.payload.turn;L(function(e){var n=e.findIndex(function(e){return e.id===t.id});if(n>=0){var r=_(e);return r[n]=t,r}return _(e).concat([t]).sort(function(e,t){return e.sequence-t.sequence})});break;case"run:completed":var n=e.payload,r=n.success,o=n.summary;O(r?"completed":"failed"),R([]),ep(),console.log("[AgentsPage] Run completed:",o);break;case"error":var i=e.payload,s=i.code,a=i.message;l.UIMessage.error("Agent error [".concat(s,"]: ").concat(a))}}});(0,o.useEffect)(function(){var e=c.current;e&&(e.scrollTop=e.scrollHeight)},[P.length,C.length]);var ey=(0,o.useCallback)(function(e,t){h(e),v(null),p({session:e},{replace:!0}),w(null),O("idle"),R([]),L([]),ef.clear()},[ef,p]),eh=(0,o.useCallback)(function(){h(null),v(null),p({},{replace:!0}),w(null),O("idle"),R([]),L([]),ef.clear()},[ef,p]),eg=(0,o.useCallback)(function(){return F(function(){var e,t,n,r;return q(this,function(o){switch(o.label){case 0:if(!S.trim())return[2];e=S.trim(),j(""),O("running"),t={id:"optimistic-user-".concat(Date.now()),type:"user",sequence:9999,startedAt:new Date().toISOString(),completedAt:new Date().toISOString(),status:"completed",steps:[{type:"text",id:"opt-1",timestamp:new Date().toISOString(),content:e,role:"user"}],metadata:{agentId:"user"}},R(function(e){return _(e).concat([t])}),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,ei.mutateAsync({task:e,agentId:er,sessionId:null!=y?y:void 0,tier:$,enableEscalation:J,responseMode:E,mode:X})];case 2:return n=o.sent(),y||(h(n.sessionId),v(n.sessionId),p({session:n.sessionId},{replace:!0})),w(n.runId),ef.isConnected&&setTimeout(function(){return R([])},500),[3,4];case 3:return r=o.sent(),R(function(e){return e.filter(function(e){return e.id!==t.id})}),O("failed"),l.UIMessage.error("Failed to start: ".concat(B(r,Error)?r.message:String(r))),[3,4];case 4:return[2]}})})()},[S,er,y,$,J,E,X,p,ei,ef]),ex=(0,o.useCallback)(function(){return F(function(){var e;return q(this,function(t){switch(t.label){case 0:if(!k)return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,el.mutateAsync({reason:"Stopped by user"})];case 2:return t.sent(),O("stopped"),l.UIMessage.info("Stopped"),[3,4];case 3:return e=t.sent(),l.UIMessage.error("Failed to stop: ".concat(B(e,Error)?e.message:String(e))),[3,4];case 4:return[2]}})})()},[k,el]),em="running"===U||ei.isLoading,ev=null!==y&&y!==x,eb=function(){if(ev)return[];var e=null!=(i=null==ec?void 0:ec.turns)?i:[],t=new Map;if(0===P.length){var n=!0,r=!1,o=void 0;try{for(var i,l,s=e[Symbol.iterator]();!(n=(l=s.next()).done);n=!0){var a=l.value;t.set(a.id,a)}}catch(e){r=!0,o=e}finally{try{n||null==s.return||s.return()}finally{if(r)throw o}}}else{var c=!0,u=!1,d=void 0;try{for(var p,f=e[Symbol.iterator]();!(c=(p=f.next()).done);c=!0){var y=p.value;t.set(y.id,y)}}catch(e){u=!0,d=e}finally{try{c||null==f.return||f.return()}finally{if(u)throw d}}var h=!0,g=!1,x=void 0;try{for(var m,v=P[Symbol.iterator]();!(h=(m=v.next()).done);h=!0){var b=m.value;t.set(b.id,b)}}catch(e){g=!0,x=e}finally{try{h||null==v.return||v.return()}finally{if(g)throw x}}}var S=new Set(_(t.values()).filter(function(e){return"user"===e.type}).flatMap(function(e){return e.steps.filter(function(e){return"text"===e.type}).map(function(e){var t;return null==(t=e.content)?void 0:t.trim()})}).filter(Boolean)),j=!0,I=!1,k=void 0;try{for(var w,T=C[Symbol.iterator]();!(j=(w=T.next()).done);j=!0){var U,O,z=w.value,R=null==(O=z.steps.find(function(e){return"text"===e.type}))||null==(U=O.content)?void 0:U.trim();R&&!S.has(R)&&t.set(z.id,z)}}catch(e){I=!0,k=e}finally{try{j||null==T.return||T.return()}finally{if(I)throw k}}return _(t.values()).sort(H)}(),eS=function(){if(!em||eb.some(function(e){return"assistant"===e.type&&"streaming"===e.status}))return eb;var e=_(eb).reverse().find(function(e){return"user"===e.type});if(!e||eb.some(function(t){return"assistant"===t.type&&"completed"===t.status&&t.sequence>e.sequence}))return eb;var t={id:"thinking-loader-".concat(e.id),type:"assistant",sequence:e.sequence+.1,startedAt:new Date().toISOString(),completedAt:null,status:"streaming",steps:[],metadata:{agentId:"assistant-loader"}};return _(eb).concat([t]).sort(H)}(),ej=ev||eu&&0===eb.length&&!!y;return(0,r.jsx)("div",{style:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:(0,r.jsxs)(l.UICard,{title:(0,r.jsxs)(l.UISpace,{children:[(0,r.jsx)(l.UIIcon,{name:"RobotOutlined"}),(0,r.jsx)("span",{children:"Agent"})]}),extra:(0,r.jsx)(a,{currentSessionId:y,onSessionChange:ey,onNewChat:eh}),style:{height:"100%",display:"flex",flexDirection:"column"},styles:{body:{flex:1,display:"flex",flexDirection:"column",padding:0,overflow:"hidden"}},children:[(0,r.jsx)("div",{ref:c,style:{flex:1,overflow:"auto"},children:(0,r.jsx)(m,{turns:eS,isLoading:ej,isError:ed,onRetry:function(){ep()},sessionId:y})}),(0,r.jsx)("div",{style:{borderTop:"1px solid ".concat(n.colorBorderSecondary),padding:"12px 16px",background:n.colorBgContainer},children:(0,r.jsxs)("div",{onFocus:function(){return en(!0)},onBlur:function(){return en(!1)},style:{border:"1px solid ".concat(et?"execute"===X?n.colorError:n.colorPrimary:"plan"===X?n.colorPrimary:n.colorBorder),borderRadius:n.borderRadiusLG,background:n.colorBgContainer,boxShadow:et?"0 0 0 2px ".concat("execute"===X?n.colorErrorBg:n.colorPrimaryBg):"none",transition:"border-color 0.2s, box-shadow 0.2s",overflow:"hidden"},children:[(0,r.jsx)(l.UIInputTextArea,{value:S,onChange:function(e){return j(e.target.value)},onKeyDown:function(e){"Enter"!==e.key||e.shiftKey||"running"===U||ei.isLoading||(e.preventDefault(),eg())},placeholder:"Message...",autoSize:{minRows:2,maxRows:8},disabled:em,variant:"borderless",style:{resize:"none",padding:"10px 12px 4px",border:"none",boxShadow:"none",outline:"none"}}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 8px 8px"},children:[(0,r.jsxs)(l.UISpace,{size:6,children:[(0,r.jsx)(G,{status:ef.status,sessionId:y,onReconnect:function(){return ef.connect()}}),(0,r.jsx)(l.UISelect,{value:X,onChange:function(e){return Y(e)},disabled:em,size:"small",variant:"borderless",style:{width:110},options:[{value:"execute",label:"Execute"},{value:"plan",label:"Plan"}]}),(0,r.jsx)(l.UISelect,{value:E,onChange:function(e){return M(e)},disabled:em,size:"small",variant:"borderless",style:{width:80},options:[{value:"auto",label:"Auto"},{value:"brief",label:"Brief"},{value:"deep",label:"Deep"}]}),(0,r.jsx)(l.UISelect,{value:$,onChange:function(e){return V(e)},disabled:em,size:"small",variant:"borderless",style:{width:100},options:[{value:"small",label:"Small"},{value:"medium",label:"Medium"},{value:"large",label:"Large"}]}),(0,r.jsxs)(l.UISpace,{size:4,align:"center",children:[(0,r.jsx)(l.UISwitch,{checked:J,onChange:Z,disabled:em||"large"===$,size:"small"}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:12},children:"Auto escalate"})]})]}),(0,r.jsx)("div",{children:em?(0,r.jsx)(l.UIButton,{danger:!0,size:"small",icon:el.isLoading?(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined"}):(0,r.jsx)(l.UIIcon,{name:"StopOutlined"}),onClick:ex,disabled:el.isLoading,children:"Stop"}):(0,r.jsx)(l.UIButton,{variant:"primary",size:"small",icon:ei.isLoading?(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined"}):(0,r.jsx)(l.UIIcon,{name:"SendOutlined"}),onClick:eg,disabled:!S.trim()||ei.isLoading,children:"Send"})})]})]})})]})})}}}]);
1
+ "use strict";(self.rspackChunk_kb_labs_agent_entry=self.rspackChunk_kb_labs_agent_entry||[]).push([[596],{6026(e,t){var n=Symbol.for("react.transitional.element");function r(e,t,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==t.key&&(o=""+t.key),"key"in t)for(var i in r={},t)"key"!==i&&(r[i]=t[i]);else r=t;return{$$typeof:n,type:e,key:o,ref:void 0!==(t=r.ref)?t:null,props:r}}t.Fragment=Symbol.for("react.fragment"),t.jsx=r,t.jsxs=r},4552(e,t,n){e.exports=n(6026)},9243(e,t,n){n.r(t),n.d(t,{default:()=>Y});var r=n(4552),o=n(1692),i=n(719),l=n(4035),s=n(3377);function a(e){var t,n=e.currentSessionId,o=e.onSessionChange,i=e.onNewChat,a=(0,l.useUITheme)().token,c=(0,s.useData)("/v1/plugins/agents/sessions?limit=20"),u=c.data,d=c.isLoading,p=null!=(t=null==u?void 0:u.sessions)?t:[],f=p.find(function(e){return e.id===n}),y=f?f.name||f.task||"Untitled":"New chat",g=d?[{key:"loading",label:(0,r.jsx)(l.UISpin,{size:"small"}),disabled:!0}]:0===p.length?[{key:"empty",label:(0,r.jsx)(l.UITypographyText,{type:"secondary",children:"No sessions yet"}),disabled:!0}]:p.map(function(e){var t,n,i,s,a;return{key:e.id,label:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,minWidth:220},children:[(0,r.jsx)(l.UITypographyText,{ellipsis:!0,style:{maxWidth:190},children:e.name||e.task||"Untitled"}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:11,flexShrink:0},children:(t=new Date(e.lastActivityAt),i=Math.floor((n=new Date().getTime()-t.getTime())/6e4),s=Math.floor(n/36e5),a=Math.floor(n/864e5),i<1?"just now":i<60?"".concat(i,"m ago"):s<24?"".concat(s,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString())})]}),onClick:function(){return o(e.id,e)}}});return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)(l.UIDropdown,{menu:{items:g},trigger:["click"],placement:"bottomRight",children:(0,r.jsxs)("button",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 10px",border:"1px solid ".concat(a.colorBorderSecondary),borderRadius:999,background:a.colorBgContainer,cursor:"pointer",fontFamily:"inherit",fontSize:13,color:a.colorText,maxWidth:220},children:[(0,r.jsx)(l.UIIcon,{name:"HistoryOutlined",style:{fontSize:12,color:a.colorTextTertiary,flexShrink:0}}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),(0,r.jsx)(l.UIIcon,{name:"DownOutlined",style:{fontSize:9,color:a.colorTextTertiary,flexShrink:0}})]})}),(0,r.jsx)(l.UITooltip,{title:"New chat",children:(0,r.jsx)(l.UIButton,{shape:"circle",size:"small",variant:"primary",icon:(0,r.jsx)(l.UIIcon,{name:"PlusOutlined",style:{fontSize:12}}),onClick:i})})]})}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function u(e,t,n,r,o,i,l){try{var s=e[i](l),a=s.value}catch(e){n(e);return}s.done?t(a):Promise.resolve(a).then(r,o)}function d(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function l(e){u(i,r,o,l,s,"next",e)}function s(e){u(i,r,o,l,s,"throw",e)}l(void 0)})}}function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function f(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],l=!0,s=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);l=!0);}catch(e){s=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(s)throw r}}return i}}(e,t)||h(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),s=Object.defineProperty;return s(l,"next",{value:a(0)}),s(l,"throw",{value:a(1)}),s(l,"return",{value:a(2)}),"function"==typeof Symbol&&s(l,Symbol.iterator,{value:function(){return this}}),l;function a(s){return function(a){var c=[s,a];if(n)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function h(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return c(e,t)}}var x=n(3261).theme.useToken;function m(e){var t=e.turns,n=e.isLoading,o=e.isError,i=e.onRetry,s=e.sessionId,a=x().token;return n?(0,r.jsxs)(l.UIFlex,{justify:"center",align:"center",style:{minHeight:240,gap:8},children:[(0,r.jsx)(l.UISpin,{size:"small"}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:13},children:"Loading history..."})]}):o?(0,r.jsxs)("div",{style:{minHeight:240,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12},children:[(0,r.jsx)(l.UIIcon,{name:"DisconnectOutlined",style:{fontSize:24,color:a.colorTextTertiary}}),(0,r.jsx)(l.UITypographyText,{type:"secondary",children:"Failed to load history"}),i&&(0,r.jsx)(l.UIButton,{size:"small",onClick:i,children:"Retry"})]}):0===t.length?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:320,gap:10},children:[(0,r.jsx)("div",{style:{width:40,height:40,borderRadius:"50%",background:a.colorFillTertiary,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)(l.UIIcon,{name:"RobotOutlined",style:{fontSize:18,color:a.colorTextSecondary}})}),(0,r.jsx)(l.UITypographyText,{style:{fontSize:15,fontWeight:500},children:"What are we working on?"}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:13},children:"Ask anything to get started"})]}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",padding:"16px 16px 40px",gap:24},children:t.map(function(e){return(0,r.jsx)(b,{turn:e,sessionId:s,token:a},e.id)})})}function b(e){var t,n,o,i,s,a,c,u,d=e.turn,p=e.sessionId,f=e.token;if("user"===d.type){var y=d.steps.find(function(e){return"text"===e.type});return(0,r.jsx)("div",{style:{display:"flex",justifyContent:"flex-end"},children:(0,r.jsx)("span",{style:{maxWidth:"70%",background:f.colorFillTertiary,borderRadius:f.borderRadiusLG,padding:"9px 14px",fontSize:14,lineHeight:1.55,color:f.colorText,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:(null==y?void 0:y.type)==="text"?y.content:""})})}var g="streaming"===d.status,h=d.steps.filter(function(e){return"text"===e.type}),x=h.filter(function(e){var t,n;return!A(null!=(t=e.content)?t:"")&&(null==(n=e.content)?void 0:n.trim())}),m=d.steps.find(function(e){return"tool_use"===e.type&&"report"===e.toolName}),b=null==m||null==(a=m.input)?void 0:a.answer,S=d.steps.filter(function(e){return"text"!==e.type&&("tool_use"!==e.type||"report"!==e.toolName)}),I=S.length>0,k=g&&0===S.length&&h.every(function(e){var t;return A(null!=(t=e.content)?t:"")}),w=null!=b?b:null,T=null==(c=d.metadata)?void 0:c.fileChanges,O=null==(u=d.metadata)?void 0:u.runId,U=!g&&T&&T.length>0&&!!p&&!!O,C={display:"flex",flexDirection:"column"},R=g?"Running":"failed"===d.status?"Failed":null,P=g?f.colorPrimary:f.colorError;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:6},children:[(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:12,fontWeight:500},children:"Agent"}),(0,r.jsxs)(l.UITypographyText,{type:"secondary",style:{fontSize:11},children:["\xb7 ",(t=new Date(d.startedAt),o=Math.floor((n=new Date().getTime()-t.getTime())/6e4),i=Math.floor(n/36e5),s=Math.floor(n/864e5),o<1?"just now":o<60?"".concat(o,"m ago"):i<24?"".concat(i,"h ago"):s<7?"".concat(s,"d ago"):t.toLocaleDateString())]}),R&&(0,r.jsxs)(l.UITypographyText,{style:{fontSize:11,color:P},children:["\xb7 ",R]})]}),I&&(0,r.jsx)("div",{style:C,children:(0,r.jsx)(v,{steps:S,isStreaming:g,token:f})}),!I&&k&&(0,r.jsx)(j,{token:f}),w&&(0,r.jsx)("div",{style:C,children:(0,r.jsx)(l.UIMarkdownViewer,{content:w,style:{padding:0}})}),!w&&x.map(function(e){var t;return"text"===e.type&&(null==(t=e.content)?void 0:t.trim())?(0,r.jsx)("div",{style:C,children:(0,r.jsx)(l.UIMarkdownViewer,{content:e.content,style:{padding:0}})},e.id):null}),U&&(0,r.jsx)("div",{style:C,children:(0,r.jsx)(z,{sessionId:p,runId:O,fileChanges:T,token:f})})]})}function v(e){var t=e.steps,n=e.isStreaming,i=e.token,s=y((0,o.useState)(n),2),a=s[0],c=s[1];(0,o.useEffect)(function(){n&&c(!0)},[n]);var u=Object.entries(function(e){var t={},n=!0,r=!1,o=void 0;try{for(var i,l=e[Symbol.iterator]();!(n=(i=l.next()).done);n=!0){var s=i.value;if("tool_use"===s.type){var a,c=P(s.toolName);t[c]=(null!=(a=t[c])?a:0)+1}}}catch(e){r=!0,o=e}finally{try{n||null==l.return||l.return()}finally{if(r)throw o}}return t}(t)).map(function(e){var t=y(e,2),n=t[0],r=t[1];return r>1?"".concat(n," \xd7").concat(r):n}),d=t.reduce(function(e,t){var n;return e+("tool_use"===t.type&&null!=(n=t.durationMs)?n:0)},0),p={display:"inline-flex",alignItems:"center",gap:5,background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontSize:12,color:i.colorTextSecondary,fontFamily:"inherit"};return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{style:p,onClick:function(){return c(function(e){return!e})},children:[(0,r.jsx)(l.UIIcon,{name:a?"DownOutlined":"RightOutlined",style:{fontSize:9,color:i.colorTextTertiary}}),n?(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined",style:{fontSize:11,color:i.colorTextTertiary}}):null,(0,r.jsxs)("span",{style:{fontWeight:500,color:i.colorText},children:[t.length," ",1===t.length?"action":"actions"]}),!a&&u.length>0&&(0,r.jsxs)("span",{style:{color:i.colorTextTertiary},children:["— ",u.join(" ")]}),!a&&d>0&&(0,r.jsxs)("span",{style:{color:i.colorTextTertiary},children:["\xb7 ",(d/1e3).toFixed(1),"s"]})]}),a&&(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:5,marginTop:4},children:t.map(function(e,o){return(0,r.jsx)(I,{step:e,isLast:!1,isStreaming:n&&o===t.length-1,token:i},e.id)})})]})}var S=["Thinking","Pondering","Reasoning","Mulling","Puzzling","Cogitating","Percolating","Ruminating","Noodling","Working"];function j(e){var t=e.token,n=y((0,o.useState)(function(){return S[Math.floor(Math.random()*S.length)]}),2),i=n[0],s=n[1];return(0,o.useEffect)(function(){var e=setInterval(function(){s(function(e){var t=S.filter(function(t){return t!==e});return t[Math.floor(Math.random()*t.length)]})},2200);return function(){return clearInterval(e)}},[]),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined",style:{fontSize:11,color:t.colorTextTertiary}}),(0,r.jsxs)(l.UITypographyText,{type:"secondary",style:{fontSize:13},children:[i,"..."]})]})}function I(e){var t,n,o,i=e.step,s=e.isStreaming,a=e.token;switch(i.type){case"thinking":var c,u,d=null!=(c=null==(u=i.content)?void 0:u.trim())?c:"";if(A(d))return null;return(0,r.jsx)(l.UIMarkdownViewer,{content:d,style:{fontSize:13,color:a.colorTextSecondary,padding:0}});case"tool_use":return(0,r.jsx)(k,{step:i,isStreaming:s,token:a});case"tool_result":return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:i.success?"CheckCircleOutlined":"CloseCircleOutlined",style:{fontSize:13,marginTop:2,color:i.success?a.colorSuccess:a.colorError}}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsxs)("span",{style:{fontSize:13,color:a.colorTextSecondary},children:[(0,r.jsx)("span",{style:{fontWeight:500,color:a.colorText},children:P(i.toolName)}),void 0!==i.durationMs&&(0,r.jsxs)("span",{style:{marginLeft:6,fontSize:11,color:a.colorTextTertiary},children:[i.durationMs,"ms"]})]}),!i.success&&i.error&&(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:a.colorError},children:i.error})]})]});case"subagent":return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:"RobotOutlined",style:{fontSize:13,marginTop:2,color:a.colorPrimary}}),(0,r.jsxs)("span",{style:{fontSize:13,color:a.colorTextSecondary},children:[(0,r.jsxs)("span",{style:{fontWeight:500,color:a.colorText},children:["Agent: ",i.agentName]}),(0,r.jsxs)("span",{style:{marginLeft:6},children:["— ",null==(n=i.task)?void 0:n.slice(0,60),(null!=(t=null==(o=i.task)?void 0:o.length)?t:0)>60?"...":""]})]})]});case"error":return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:"ExclamationCircleOutlined",style:{fontSize:13,marginTop:2,color:a.colorError}}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:500,color:a.colorError},children:i.code}),(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:a.colorError},children:i.message})]})]});default:return null}}function k(e){var t,n,i,s=e.step,a=e.isStreaming,c=e.token,u=y((0,o.useState)(!1),2),d=u[0],p=u[1],f="pending"===s.status,g="done"===s.status,h="error"===s.status,x=g&&!1===s.success,m=function(e){var t=e.input;if(!t)return{};var n=e.toolName.toLowerCase(),r=n.includes("read"),o=n.includes("write")||n.includes("patch")||n.includes("edit"),i=null!=(s=null!=(a=null!=(c=t.path)?c:t.filePath)?a:t.file_path)?s:t.file;if(i){var l=null!=(g=String(i).split("/").pop())?g:String(i);if(r){var s,a,c,u,d,p,f,y,g,h,x,m,b,v,S=null!=(x=null!=(m=t.offset)?m:t.startLine)?x:t.start_line,j=null!=(b=null!=(v=t.limit)?v:t.endLine)?b:t.end_line;void 0!==S&&void 0!==j?h="".concat(S,"-").concat(Number(S)+Number(j)):void 0!==j&&(h="".concat(j," lines"))}return{summary:l,filePath:String(i),badge:h}}var I=null!=(u=null!=(d=null!=(p=t.query)?p:t.text)?d:t.pattern)?u:t.search;if(I)return{summary:String(I).slice(0,100)};var k=null!=(f=t.command)?f:t.cmd;if(k)return{summary:String(k).slice(0,100)};if(o)return{};var w=null!=(y=t.content)?y:t.message;return w?{summary:String(w).slice(0,100)}:{}}(s),b=g&&!!(null==(i=s.metadata)?void 0:i.diff),v=g&&null!=s.output,S=s.input,j=/write|patch|edit/i.test(s.toolName)&&g&&!!(null!=(n=null==S?void 0:S.content)?n:null==S?void 0:S.new_content),I=v||b||j||h,k=f?a?c.colorTextTertiary:c.colorPrimary:g&&!x?c.colorSuccess:c.colorError,T=s.metadata,z=g&&(null==T?void 0:T.uiHint)==="todo"&&null!=T.structured?T.structured.todoList:void 0;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:f&&a?"LoadingOutlined":(t=s.toolName.toLowerCase(),/read|open/.test(t)?"FileTextOutlined":/write|patch|edit/.test(t)?"EditOutlined":/bash|exec|shell|run/.test(t)?"CodeOutlined":/grep|search|glob|find/.test(t)?"SearchOutlined":/todo/.test(t)?"CheckSquareOutlined":/rag|mind|embed/.test(t)?"BulbOutlined":/agent|subagent/.test(t)?"RobotOutlined":/delete|remove/.test(t)?"DeleteOutlined":"ApiOutlined"),style:{fontSize:13,marginTop:2,color:k,flexShrink:0}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsxs)("button",{onClick:function(){return I&&p(function(e){return!e})},disabled:!I,style:{display:"inline-flex",alignItems:"center",gap:6,background:"none",border:"none",padding:0,cursor:I?"pointer":"default",fontSize:13,color:c.colorText,flexWrap:"wrap",fontFamily:"inherit"},children:[(0,r.jsx)("span",{style:{fontWeight:500},children:P(s.toolName)}),m.badge&&(0,r.jsx)("span",{style:{fontSize:11,color:c.colorTextSecondary,background:c.colorFillSecondary,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:m.badge}),g&&(null==T?void 0:T.resultCount)!==void 0&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorTextSecondary,background:c.colorFillSecondary,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:[T.resultCount," results"]}),g&&(null==T?void 0:T.exitCode)!==void 0&&0!==T.exitCode&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorError,background:c.colorErrorBg,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:["exit ",T.exitCode]}),g&&((null==T?void 0:T.linesAdded)!==void 0||(null==T?void 0:T.linesRemoved)!==void 0)&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorSuccess,background:c.colorSuccessBg,borderRadius:c.borderRadiusSM,padding:"0 5px"},children:[(null==T?void 0:T.linesAdded)!=null&&T.linesAdded>0?"+".concat(T.linesAdded):"",(null==T?void 0:T.linesRemoved)!=null&&T.linesRemoved>0?" -".concat(T.linesRemoved):""]}),!f&&void 0!==s.durationMs&&(0,r.jsxs)("span",{style:{fontSize:11,color:c.colorTextTertiary},children:[s.durationMs,"ms"]}),I&&(0,r.jsx)(l.UIIcon,{name:d?"UpOutlined":"DownOutlined",style:{fontSize:9,color:c.colorTextTertiary}})]}),m.summary&&(0,r.jsx)("p",{style:{margin:"2px 0 0",fontSize:12,color:c.colorTextSecondary},children:m.filePath?(0,r.jsx)(O,{path:m.filePath,label:m.summary,token:c}):m.summary}),null!=z&&(0,r.jsx)(R,{todoList:z,token:c}),h&&s.error&&(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:c.colorError},children:s.error}),x&&!d&&null!=s.output&&(0,r.jsx)("p",{style:{margin:"4px 0 0",fontSize:12,color:c.colorError},children:String(s.output)}),d&&(0,r.jsx)("div",{style:{marginTop:6},children:(0,r.jsx)(w,{step:s,hasDiff:b,hasOutput:v,token:c})})]})]})}function w(e){var t=e.step,n=e.hasDiff,o=e.hasOutput,i=e.token,s=t.input,a=t.toolName.toLowerCase(),c=a.includes("write")||a.includes("patch")||a.includes("edit"),u=a.includes("read"),d=a.includes("bash")||a.includes("exec")||a.includes("shell")||a.includes("run"),y=a.includes("grep")||a.includes("search")||a.includes("glob")||a.includes("list")||a.includes("rag"),g={margin:0,padding:"8px 10px",fontSize:12,lineHeight:1.5,borderRadius:i.borderRadius,overflow:"auto",maxHeight:300,whiteSpace:"pre-wrap",wordBreak:"break-all"};if(c){if(n)return(0,r.jsx)(T,{diff:t.metadata.diff,token:i});var h=null!=(x=null!=(m=null==s?void 0:s.content)?m:null==s?void 0:s.new_content)?x:null==s?void 0:s.text;if(h){var x,m,b,v,S,j=null!=(b=null!=(v=null!=(S=null==s?void 0:s.path)?S:null==s?void 0:s.filePath)?v:null==s?void 0:s.file_path)?b:null==s?void 0:s.file,I=j?j.split(".").pop():void 0;return(0,r.jsxs)("div",{children:[j&&(0,r.jsx)("div",{style:{fontSize:11,color:i.colorTextTertiary,padding:"3px 8px",background:i.colorFillSecondary,borderRadius:"".concat(i.borderRadius,"px ").concat(i.borderRadius,"px 0 0")},children:j}),(0,r.jsx)("pre",{style:f(p({},g),{background:i.colorFillSecondary,borderRadius:j?"0 0 ".concat(i.borderRadius,"px ").concat(i.borderRadius,"px"):i.borderRadius}),className:I?"lang-".concat(I):void 0,children:String(h)})]})}return null}if(u&&o)return(0,r.jsx)("pre",{style:f(p({},g),{background:i.colorFillSecondary}),children:E(t.output)});if(d&&o)return(0,r.jsx)("pre",{style:f(p({},g),{background:i.colorBgSpotlight,color:i.colorTextLightSolid}),children:E(t.output)});if(y&&o)return(0,r.jsx)("pre",{style:f(p({},g),{background:i.colorFillSecondary}),children:E(t.output)});if(n)return(0,r.jsx)(T,{diff:t.metadata.diff,token:i});if(o){var k="done"===t.status&&!1===t.success,w=E(t.output);return k?(0,r.jsx)("pre",{style:f(p({},g),{background:i.colorErrorBg,color:i.colorError}),children:w}):(0,r.jsx)(l.UIMarkdownViewer,{content:w,style:{fontSize:12,padding:0}})}return null}function T(e){var t=e.diff,n=e.token,o=t.split("\n");return(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",fontSize:12,lineHeight:1.5,borderRadius:n.borderRadius,overflow:"auto",maxHeight:300,background:n.colorFillSecondary,whiteSpace:"pre"},children:o.map(function(e,t){var o=e.startsWith("+")&&!e.startsWith("+++")?n.colorSuccess:e.startsWith("-")&&!e.startsWith("---")?n.colorError:e.startsWith("@@")?n.colorInfo:void 0;return(0,r.jsxs)("span",{style:o?{color:o}:void 0,children:[e,"\n"]},t)})})}function O(e){var t=e.path,n=e.label,i=e.token,l=y((0,o.useState)(!1),2),s=l[0],a=l[1];return(0,r.jsxs)("span",{onClick:function(e){e.stopPropagation(),navigator.clipboard.writeText(t).then(function(){a(!0),setTimeout(function(){return a(!1)},1500)})},title:t,style:{cursor:"pointer",color:s?i.colorSuccess:i.colorTextSecondary,fontFamily:"monospace",fontSize:12},children:[n,s?" ✓":""]})}function z(e){var t=e.sessionId,n=e.runId,i=e.fileChanges,a=e.token,u=y((0,o.useState)(new Set),2),p=u[0],f=u[1],x=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(t,"/rollback"),"POST"),m=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(t,"/approve"),"POST"),b=i.filter(function(e){return!p.has(e.changeId)&&!e.approved});return 0===b.length?null:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:"FileOutlined",style:{fontSize:13,marginTop:2,color:a.colorSuccess}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[(0,r.jsxs)(l.UITypographyText,{style:{fontSize:13,fontWeight:500},children:[b.length," ",M(b.length)," changed"]}),(0,r.jsxs)(l.UIFlex,{gap:4,children:[(0,r.jsx)("button",{onClick:function(){d(function(){return g(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,m.mutateAsync({runId:n})];case 1:return e.sent(),f(new Set(b.map(function(e){return e.changeId}))),[3,3];case 2:return e.sent(),console.error("Failed to approve changes"),[3,3];case 3:return[2]}})})()},disabled:m.isLoading||x.isLoading,title:"Approve all",style:{background:a.colorSuccessBg,border:"1px solid ".concat(a.colorSuccessBorder),color:a.colorSuccess,borderRadius:a.borderRadius,padding:"2px 8px",fontSize:12,cursor:"pointer"},children:"✓"}),(0,r.jsx)("button",{onClick:function(){(0,l.UIModalConfirm)({title:"Rollback changes?",content:"This will revert ".concat(b.length," ").concat(M(b.length)," to the state before the agent run."),okText:"Rollback",okButtonProps:{danger:!0},cancelText:"Cancel",onOk:function(){return d(function(){var e,t;return g(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,x.mutateAsync({runId:n})];case 1:return(null==(e=(t=r.sent()).conflicts)?void 0:e.length)&&console.warn("Rolled back: ".concat(t.rolledBack,", skipped: ").concat(t.skipped)),f(new Set(b.map(function(e){return e.changeId}))),[3,3];case 2:return r.sent(),console.error("Failed to rollback changes"),[3,3];case 3:return[2]}})})()}})},disabled:x.isLoading||m.isLoading,title:"Rollback all",style:{background:a.colorErrorBg,border:"1px solid ".concat(a.colorErrorBorder),color:a.colorError,borderRadius:a.borderRadius,padding:"2px 8px",fontSize:12,cursor:"pointer"},children:"✕"})]})]}),(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:2},children:b.map(function(e){return(0,r.jsx)(U,{change:e,sessionId:t,onDismiss:function(){return f(function(t){return new Set(((function(e){if(Array.isArray(e))return c(e)})(t)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||h(t)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).concat([e.changeId]))})},token:a},e.changeId)})})]})]})}function U(e){var t,n=e.change,i=e.sessionId,a=e.onDismiss,c=e.token,u=y((0,o.useState)(!1),2),p=u[0],f=u[1],h=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(i,"/rollback"),"POST"),x=(0,s.useMutateData)("/v1/plugins/agents/sessions/".concat(i,"/approve"),"POST"),m=p?"/v1/plugins/agents/sessions/".concat(i,"/changes/").concat(encodeURIComponent(n.changeId),"/diff"):"",b=(0,s.useData)(m,{enabled:p}),v=b.data,S=b.isLoading,j=b.isError,I=n.isNew?(0,r.jsx)(l.UITag,{color:"success",children:"new"}):"delete"===n.operation?(0,r.jsx)(l.UITag,{color:"error",children:"del"}):(0,r.jsx)(l.UITag,{color:"blue",children:"mod"});return(0,r.jsxs)("li",{children:[(0,r.jsxs)("div",{onClick:function(){return f(function(e){return!e})},style:{display:"flex",alignItems:"center",gap:6,fontSize:12,cursor:"pointer",padding:"2px 4px",borderRadius:c.borderRadiusSM,background:p?c.colorFillSecondary:"transparent"},children:[I,(0,r.jsx)("span",{style:{flex:1,fontFamily:"monospace",color:c.colorTextSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:null!=(t=n.filePath.split("/").pop())?t:n.filePath}),(0,r.jsx)("span",{style:{color:c.colorTextTertiary,fontFamily:"monospace",fontSize:11},children:n.filePath.includes("/")?n.filePath.slice(0,n.filePath.lastIndexOf("/")):""}),!n.approved&&(0,r.jsxs)("div",{style:{display:"flex",gap:4},onClick:function(e){return e.stopPropagation()},children:[(0,r.jsx)("button",{onClick:function(e){e.stopPropagation(),x.mutateAsync({changeIds:[n.changeId]}).then(a).catch(function(){console.error("Failed to approve file")})},disabled:x.isLoading,title:"Approve",style:{background:"none",border:"none",cursor:"pointer",color:c.colorSuccess,fontSize:13,padding:"0 2px"},children:"✓"}),(0,r.jsx)("button",{onClick:function(e){e.stopPropagation(),(0,l.UIModalConfirm)({title:"Rollback file?",content:n.filePath,okText:"Rollback",okButtonProps:{danger:!0},cancelText:"Cancel",onOk:function(){return d(function(){return g(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,h.mutateAsync({changeIds:[n.changeId]})];case 1:return e.sent(),a(),[3,3];case 2:return e.sent(),console.error("Failed to rollback file"),[3,3];case 3:return[2]}})})()}})},disabled:h.isLoading,title:"Rollback",style:{background:"none",border:"none",cursor:"pointer",color:c.colorError,fontSize:13,padding:"0 2px"},children:"✕"})]})]}),p&&(0,r.jsxs)("div",{style:{marginTop:4,marginLeft:4},children:[S&&(0,r.jsx)(l.UISpin,{size:"small"}),(null==v?void 0:v.diff)&&(0,r.jsx)(T,{diff:v.diff,token:c}),j&&(0,r.jsx)("span",{style:{color:c.colorError,fontSize:12},children:"Failed to load diff"})]})]})}var C={completed:"✓","in-progress":"●",blocked:"✕",pending:"○"};function R(e){var t,n=e.todoList,o=e.token;if(!(null==n||null==(t=n.items)?void 0:t.length))return null;var i=n.items.filter(function(e){return"completed"===e.status}).length;return(0,r.jsxs)("div",{style:{marginTop:6,background:o.colorFillTertiary,borderRadius:o.borderRadius,padding:"8px 10px"},children:[(0,r.jsxs)("div",{style:{fontSize:11,color:o.colorTextTertiary,marginBottom:6,fontWeight:500},children:[i,"/",n.items.length]}),(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:2},children:n.items.map(function(e){var t;return(0,r.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,lineHeight:1.5,padding:"2px 0"},children:[(0,r.jsx)("span",{style:{fontSize:12,flexShrink:0,width:14,textAlign:"center",lineHeight:1},children:null!=(t=C[e.status])?t:"○"}),"completed"===e.status?(0,r.jsx)(l.UITypographyText,{type:"success",style:{flex:1,minWidth:0,textDecoration:"line-through"},children:e.description}):"pending"===e.status||"blocked"===e.status?(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{flex:1,minWidth:0},children:e.description}):(0,r.jsx)(l.UITypographyText,{style:{flex:1,minWidth:0},children:e.description}),"medium"!==e.priority&&(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:11,flexShrink:0},children:e.priority})]},e.id)})})]})}function P(e){var t=e.trim().toLowerCase().replace(/[_-]/g," ");if(t.includes("fs read")||t.includes("read file"))return"Read";if(t.includes("fs write")||t.includes("write file"))return"Write";if(t.includes("fs patch")||t.includes("patch file")||t.includes("fs edit")||t.includes("edit file"))return"Edit";if(t.includes("fs delete")||t.includes("delete file")||t.includes("remove file"))return"Delete";if(t.includes("fs list")||t.includes("list files")||t.includes("glob"))return"Glob";if(t.includes("grep")||t.includes("search content"))return"Grep";if(t.includes("bash")||t.includes("exec")||t.includes("shell")||t.includes("run command"))return"Bash";if(t.includes("rag")||t.includes("mind"))return"Mind";if(t.includes("todo"))return"TodoWrite";var n=e.indexOf(":");return(n>=0?e.slice(n+1):e).replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,function(e){return e.toUpperCase()})}function A(e){var t=e.trim().toLowerCase();return!!("[executing tools...]"===t||"[thinking...]"===t||"[planning...]"===t||"[analyzing...]"===t||"analyzing context and choosing the next step."===t||t.startsWith("checking facts with tool:")||t.startsWith("running step with tool:")||t.startsWith("running the next step"))||"done."===t||"ok."===t||"done"===t||"ok"===t}function M(e){return 1===e?"file":"files"}function E(e){if("string"==typeof e)return e.slice(0,2e3);try{return JSON.stringify(e,null,2).slice(0,2e3)}catch(t){return String(e).slice(0,2e3)}}function D(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function L(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function B(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function F(e){return function(e){if(Array.isArray(e))return D(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e){if(e){if("string"==typeof e)return D(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return D(e,void 0)}}(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function W(){return{turnsById:new Map,lastSeq:0}}function q(e,t){var n=new Map(e.turnsById);return n.set(t.id,t),B(L({},e),{turnsById:n})}function N(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function _(e,t,n,r,o,i,l){try{var s=e[i](l),a=s.value}catch(e){n(e);return}s.done?t(a):Promise.resolve(a).then(r,o)}function H(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function l(e){_(i,r,o,l,s,"next",e)}function s(e){_(i,r,o,l,s,"throw",e)}l(void 0)})}}function $(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function G(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],l=!0,s=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);l=!0);}catch(e){s=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(s)throw r}}return i}}(e,t)||J(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function V(e){return function(e){if(Array.isArray(e))return N(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||J(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function K(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),s=Object.defineProperty;return s(l,"next",{value:a(0)}),s(l,"throw",{value:a(1)}),s(l,"return",{value:a(2)}),"function"==typeof Symbol&&s(l,Symbol.iterator,{value:function(){return this}}),l;function a(s){return function(a){var c=[s,a];if(n)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function J(e,t){if(e){if("string"==typeof e)return N(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return N(e,t)}}function Q(e,t){if(e.sequence!==t.sequence)return e.sequence-t.sequence;if(e.type!==t.type){if("user"===e.type)return -1;if("user"===t.type)return 1}return e.startedAt.localeCompare(t.startedAt)}function X(e){var t=e.status,n=e.sessionId,o=e.onReconnect,i=(0,l.useUITheme)().token;return n&&"connected"!==t?"connecting"===t?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[(0,r.jsx)(l.UIIcon,{name:"LoadingOutlined",style:{fontSize:12,color:i.colorTextTertiary}}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:12},children:"Connecting..."})]}):(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[(0,r.jsx)(l.UIIcon,{name:"DisconnectOutlined",style:{fontSize:12,color:i.colorError}}),(0,r.jsx)(l.UIButton,{variant:"link",size:"small",style:{padding:0,fontSize:12,height:"auto"},onClick:o,children:"Reconnect"})]}):null}function Z(e){var t=e.responseMode,n=e.setResponseMode,o=e.tier,i=e.setTier,s=e.enableEscalation,a=e.setEnableEscalation,c=e.disabled,u=e.token;return(0,r.jsxs)("div",{style:{width:220,display:"flex",flexDirection:"column",gap:14,padding:4},children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:11,fontWeight:500},children:"RESPONSE"}),(0,r.jsx)(l.UISegmented,{block:!0,size:"small",value:t,onChange:function(e){return n(e)},disabled:c,style:{marginTop:6},options:[{value:"auto",label:"Auto"},{value:"brief",label:"Brief"},{value:"deep",label:"Deep"}]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:11,fontWeight:500},children:"MODEL TIER"}),(0,r.jsx)(l.UISegmented,{block:!0,size:"small",value:o,onChange:function(e){return i(e)},disabled:c,style:{marginTop:6},options:[{value:"small",label:"Small"},{value:"medium",label:"Medium"},{value:"large",label:"Large"}]})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(l.UITypographyText,{style:{fontSize:13},children:"Auto escalate"}),(0,r.jsx)(l.UISwitch,{checked:s,onChange:a,disabled:c||"large"===o,size:"small"})]}),(0,r.jsx)(l.UITypographyText,{type:"secondary",style:{fontSize:11,borderTop:"1px solid ".concat(u.colorBorderSecondary),paddingTop:8},children:"Escalates to a larger model when the task needs it."})]})}let Y=function(){var e,t,n,c=(0,l.useUITheme)().token,u=(0,o.useRef)(null),d=G((0,i.useSearchParams)(),2),p=d[0],f=d[1],y=G((0,o.useState)(function(){return p.get("session")}),2),g=y[0],h=y[1],x=G((0,o.useState)(function(){return p.get("session")}),2),b=x[0],v=x[1],S=G((0,o.useState)(""),2),j=S[0],I=S[1],k=G((0,o.useState)(null),2),w=k[0],T=k[1],O=G((0,o.useState)("idle"),2),z=O[0],U=O[1],C=G((0,o.useState)(new Map),2),R=C[0],P=C[1],A=G((0,o.useState)(W()),2),M=A[0],E=A[1],D=G((0,o.useState)(!1),2),N=D[0],_=D[1],J=G((0,o.useState)(null),2),Y=J[0],ee=J[1],et=G((0,o.useState)("auto"),2),en=et[0],er=et[1],eo=G((0,o.useState)("medium"),2),ei=eo[0],el=eo[1],es=G((0,o.useState)(!0),2),ea=es[0],ec=es[1],eu=G((0,o.useState)("execute"),2),ed=eu[0],ep=eu[1],ef=G((0,o.useState)(!1),2),ey=ef[0],eg=ef[1],eh="mind-assistant",ex=g?(e="https:"===window.location.protocol?"wss:":"ws:",t=window.location.host,n="".concat(e,"//").concat(t,"/api/v1/ws/plugins/agents/session/").concat(g),null!=Y?"".concat(n,"?afterSeq=").concat(Y):n):null,em=(0,s.useMutateData)("/v1/plugins/agents/run","POST"),eb=(0,s.useMutateData)(w?"/v1/plugins/agents/run/".concat(w,"/stop"):"/v1/plugins/agents/run/noop/stop","POST"),ev=g?"/v1/plugins/agents/sessions/".concat(g,"/turns"):"",eS=(0,s.useData)(ev,{enabled:!!g}),ej=eS.data,eI=eS.isFetching,ek=eS.isError,ew=eS.refetch;(0,o.useEffect)(function(){g&&(ej||ek)&&!eI&&v(g)},[g,ej,ek,eI]);var eT=(0,s.useWebSocket)(ex,{reconnect:!0,maxReconnects:10,reconnectIntervalMs:2e3,onMessage:function(e){switch(e.type){case"conversation:snapshot":var t=e.payload,n=t.completedTurns,r=t.activeTurns,o=t.seq,i=V(n).concat(V(r));E(function(e,t){var n=new Map,r=!0,o=!1,i=void 0;try{for(var l,s=e[Symbol.iterator]();!(r=(l=s.next()).done);r=!0){var a=l.value;n.set(a.id,a)}}catch(e){o=!0,i=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw i}}return{turnsById:n,lastSeq:t}}(i,o)),_(!0),ee(null),P(function(e){return function(e,t){if(0===e.size)return e;var n=new Set(t.filter(function(e){return"user"===e.type&&e.metadata.clientId}).map(function(e){return e.metadata.clientId}));if(!F(e.keys()).some(function(e){return n.has(e)}))return e;var r=new Map(e),o=!0,i=!1,l=void 0;try{for(var s,a=n[Symbol.iterator]();!(o=(s=a.next()).done);o=!0){var c=s.value;r.delete(c)}}catch(e){i=!0,l=e}finally{try{o||null==a.return||a.return()}finally{if(i)throw l}}return r}(e,i)});break;case"turn:delta":var s=e.payload.delta;E(function(e){var t=function(e,t){if(t.seq<=e.lastSeq)return{status:"duplicate",state:e};var n=t.seq>e.lastSeq+1,r=new Map(e.turnsById);switch(t.kind){case"turn:created":r.set(t.turn.id,t.turn);break;case"turn:step:appended":var o=r.get(t.turnId);o&&r.set(t.turnId,B(L({},o),{steps:F(o.steps).concat([t.step])}));break;case"turn:step:updated":var i=r.get(t.turnId);if(i){var l=i.steps.map(function(e){return e.id===t.step.id?t.step:e});r.set(t.turnId,B(L({},i),{steps:l}))}break;case"turn:status":var s=r.get(t.turnId);s&&r.set(t.turnId,B(L({},s),{status:t.status,completedAt:t.completedAt,error:t.error}));break;case"turn:metadata":var a=r.get(t.turnId);a&&r.set(t.turnId,B(L({},a),{metadata:L({},a.metadata,t.patch)}))}return{status:n?"gap":"applied",state:{turnsById:r,lastSeq:t.seq}}}(e,s);return"gap"===t.status&&ee(e.lastSeq),t.state});break;case"run:completed":var a=e.payload,c=a.success,u=a.summary,d=a.seq,p=a.turn;U(c?"completed":"failed"),E(function(e){var t;return d>(t=p?q(e,p):e).lastSeq?B(L({},t),{lastSeq:d}):t}),console.log("[AgentsPage] Run completed:",u);break;case"error":var f=e.payload,y=f.code,g=f.message;l.UIMessage.error("Agent error [".concat(y,"]: ").concat(g))}}});(0,o.useEffect)(function(){var e=u.current;e&&(e.scrollTop=e.scrollHeight)},[M.turnsById.size,R.size]);var eO=(0,o.useCallback)(function(e,t){h(e),v(null),f({session:e},{replace:!0}),T(null),U("idle"),P(new Map),E(W()),_(!1),ee(null),eT.clear()},[eT,f]),ez=(0,o.useCallback)(function(){h(null),v(null),f({},{replace:!0}),T(null),U("idle"),P(new Map),E(W()),_(!1),ee(null),eT.clear()},[eT,f]),eU=(0,o.useCallback)(function(){return H(function(){var e,t,n,r,o;return K(this,function(i){switch(i.label){case 0:if(!j.trim())return[2];e=j.trim(),I(""),U("running"),t=crypto.randomUUID(),n={id:"optimistic-".concat(t),type:"user",sequence:Number.MAX_SAFE_INTEGER,startedAt:new Date().toISOString(),completedAt:new Date().toISOString(),status:"completed",steps:[{type:"text",id:"opt-1",timestamp:new Date().toISOString(),content:e,role:"user"}],metadata:{agentId:"user",clientId:t}},P(function(e){return new Map(e).set(t,n)}),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,em.mutateAsync({task:e,agentId:eh,sessionId:null!=g?g:void 0,tier:ei,enableEscalation:ea,responseMode:en,mode:ed,clientId:t})];case 2:return r=i.sent(),g||(h(r.sessionId),v(r.sessionId),f({session:r.sessionId},{replace:!0})),T(r.runId),E(function(e){return q(e,r.userTurn)}),P(function(e){var n=new Map(e);return n.delete(t),n}),[3,4];case 3:return o=i.sent(),P(function(e){var n=new Map(e);return n.delete(t),n}),U("failed"),l.UIMessage.error("Failed to start: ".concat($(o,Error)?o.message:String(o))),[3,4];case 4:return[2]}})})()},[j,eh,g,ei,ea,en,ed,f,em]),eC=(0,o.useCallback)(function(){return H(function(){var e;return K(this,function(t){switch(t.label){case 0:if(!w)return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,eb.mutateAsync({reason:"Stopped by user"})];case 2:return t.sent(),U("stopped"),l.UIMessage.info("Stopped"),[3,4];case 3:return e=t.sent(),l.UIMessage.error("Failed to stop: ".concat($(e,Error)?e.message:String(e))),[3,4];case 4:return[2]}})})()},[w,eb]),eR="running"===z||em.isLoading,eP=null!==g&&g!==b,eA=function(){if(eP)return[];var e,t=N?V(M.turnsById.values()):null!=(e=null==ej?void 0:ej.turns)?e:[];return V(t).concat(V(R.values())).sort(Q)}(),eM=function(){if(!eR||eA.some(function(e){return"assistant"===e.type&&"streaming"===e.status}))return eA;var e=V(eA).reverse().find(function(e){return"user"===e.type});if(!e||eA.some(function(t){return"assistant"===t.type&&"completed"===t.status&&t.sequence>e.sequence}))return eA;var t={id:"thinking-loader-".concat(e.id),type:"assistant",sequence:e.sequence+.1,startedAt:new Date().toISOString(),completedAt:null,status:"streaming",steps:[],metadata:{agentId:"assistant-loader"}};return V(eA).concat([t]).sort(Q)}(),eE=eP||eI&&0===eA.length&&!!g,eD=!!j.trim()&&!em.isLoading;return(0,r.jsxs)("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:28,overflow:"hidden",display:"flex",flexDirection:"column",background:c.colorBgContainer},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",borderBottom:"1px solid ".concat(c.colorBorderSecondary),flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)(l.UIIcon,{name:"RobotOutlined",style:{fontSize:15,color:c.colorTextSecondary}}),(0,r.jsx)(l.UITypographyText,{strong:!0,style:{fontSize:14},children:"Agent"})]}),(0,r.jsx)(a,{currentSessionId:g,onSessionChange:eO,onNewChat:ez})]}),(0,r.jsx)("div",{ref:u,style:{flex:1,overflow:"auto"},children:(0,r.jsx)("div",{style:{maxWidth:860,margin:"0 auto",width:"100%"},children:(0,r.jsx)(m,{turns:eM,isLoading:eE,isError:ek,onRetry:function(){ew()},sessionId:g})})}),(0,r.jsx)("div",{style:{padding:"0 20px 18px",flexShrink:0},children:(0,r.jsx)("div",{style:{maxWidth:860,margin:"0 auto",width:"100%"},children:(0,r.jsxs)("div",{onFocus:function(){return eg(!0)},onBlur:function(){return eg(!1)},style:{border:"1px solid ".concat(ey?c.colorPrimary:c.colorBorderSecondary),borderRadius:20,background:c.colorBgContainer,boxShadow:ey?"0 0 0 3px ".concat(c.colorPrimaryBg):"0 1px 2px rgba(0,0,0,0.04)",transition:"border-color 0.15s, box-shadow 0.15s",overflow:"hidden"},children:[(0,r.jsx)(l.UIInputTextArea,{value:j,onChange:function(e){return I(e.target.value)},onKeyDown:function(e){"Enter"!==e.key||e.shiftKey||"running"===z||em.isLoading||(e.preventDefault(),eU())},placeholder:"Message the agent...",autoSize:{minRows:1,maxRows:8},disabled:eR,variant:"borderless",style:{resize:"none",padding:"14px 16px 6px",border:"none",boxShadow:"none",outline:"none",fontSize:14}}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 10px 10px"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)(l.UISegmented,{size:"small",value:ed,onChange:function(e){return ep(e)},disabled:eR,options:[{value:"execute",label:"Execute"},{value:"plan",label:"Plan"}]}),(0,r.jsx)(l.UIPopover,{trigger:"click",placement:"topLeft",content:(0,r.jsx)(Z,{responseMode:en,setResponseMode:er,tier:ei,setTier:el,enableEscalation:ea,setEnableEscalation:ec,disabled:eR,token:c}),children:(0,r.jsxs)("button",{disabled:eR,style:{display:"inline-flex",alignItems:"center",gap:5,padding:"3px 10px",border:"1px solid ".concat(c.colorBorderSecondary),borderRadius:999,background:"transparent",cursor:eR?"default":"pointer",opacity:eR?.6:1,fontFamily:"inherit",fontSize:12,color:c.colorTextSecondary},children:[(0,r.jsx)(l.UIIcon,{name:"ControlOutlined",style:{fontSize:11}}),(0,r.jsx)("span",{children:"small"===ei?"Small":"large"===ei?"Large":"Medium"}),ea&&(0,r.jsx)("span",{style:{color:c.colorTextTertiary},children:"\xb7 Auto"})]})}),(0,r.jsx)(X,{status:eT.status,sessionId:g,onReconnect:function(){return eT.connect()}})]}),(0,r.jsx)("div",{children:eR?(0,r.jsx)("button",{onClick:eC,disabled:eb.isLoading,title:"Stop",style:{width:30,height:30,borderRadius:"50%",border:"none",background:c.colorError,color:c.colorTextLightSolid,display:"flex",alignItems:"center",justifyContent:"center",cursor:eb.isLoading?"default":"pointer"},children:(0,r.jsx)(l.UIIcon,{name:eb.isLoading?"LoadingOutlined":"StopOutlined",style:{fontSize:13,color:"inherit"}})}):(0,r.jsx)("button",{onClick:eU,disabled:!eD,title:"Send",style:{width:30,height:30,borderRadius:"50%",border:"none",background:eD?c.colorText:c.colorFillTertiary,color:eD?c.colorBgContainer:c.colorTextQuaternary,display:"flex",alignItems:"center",justifyContent:"center",cursor:eD?"pointer":"default",transition:"background 0.15s"},children:(0,r.jsx)(l.UIIcon,{name:em.isLoading?"LoadingOutlined":"ArrowUpOutlined",style:{fontSize:13,color:"inherit"}})})})]})]})})})]})}}}]);
@@ -114,8 +114,8 @@
114
114
  "sync": [
115
115
  "117.js",
116
116
  "326.js",
117
- "62.js",
118
- "648.js"
117
+ "648.js",
118
+ "832.js"
119
119
  ],
120
120
  "async": []
121
121
  },
@@ -122,8 +122,8 @@
122
122
  "sync": [
123
123
  "117.js",
124
124
  "326.js",
125
- "62.js",
126
- "648.js"
125
+ "648.js",
126
+ "832.js"
127
127
  ],
128
128
  "async": []
129
129
  },