@pasko70/pibo 1.4.3 → 1.4.5

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.
Files changed (23) hide show
  1. package/dist/apps/chat-ui/assets/{dist-BAXNalar.js → dist-85Cc5Hut.js} +1 -1
  2. package/dist/apps/chat-ui/assets/{dist-DnACFKyO.js → dist-B8jspmzT.js} +1 -1
  3. package/dist/apps/chat-ui/assets/{dist-CiDSXgtg.js → dist-BGqK-7Ep.js} +1 -1
  4. package/dist/apps/chat-ui/assets/{dist-C3PnEkhb.js → dist-BtF63vik.js} +1 -1
  5. package/dist/apps/chat-ui/assets/{dist-vKlxFkTa.js → dist-CQXtvBTs.js} +1 -1
  6. package/dist/apps/chat-ui/assets/{dist-ZB1-ui2y.js → dist-D1Laodgo.js} +1 -1
  7. package/dist/apps/chat-ui/assets/{dist-CYPL-B2Z.js → dist-DE8W5WKg.js} +1 -1
  8. package/dist/apps/chat-ui/assets/{dist-BwUvs6Ph.js → dist-DcME5mJj.js} +1 -1
  9. package/dist/apps/chat-ui/assets/{dist-BAGS_xkV.js → dist-eG89IJAV.js} +1 -1
  10. package/dist/apps/chat-ui/assets/{dist-C0zsJ8II.js → dist-ecTM1pdv.js} +1 -1
  11. package/dist/apps/chat-ui/assets/{dist-B2BEpL7n.js → dist-oLAGkW6G.js} +1 -1
  12. package/dist/apps/chat-ui/assets/{index-0x7tuTNX.js → index-D4uifikB.js} +17 -17
  13. package/dist/apps/chat-ui/index.html +1 -1
  14. package/dist/apps/chat-vscode-web/assets/{index-C3GTPyDo.js → index-CRUSv6iR.js} +3 -3
  15. package/dist/apps/chat-vscode-web/index.html +1 -1
  16. package/dist/apps/vscode-artifacts/latest.vsix +0 -0
  17. package/dist/apps/vscode-artifacts/{pibo-vscode-ext-1.4.2.vsix → pibo-vscode-ext-1.4.5.vsix} +0 -0
  18. package/dist/plugins/codex-compat.js +2 -0
  19. package/dist/providers/glm.js +1 -1
  20. package/dist/session-ui/terminalRows.js +55 -8
  21. package/dist/tools/codex-image-generation.js +272 -0
  22. package/package.json +1 -1
  23. package/dist/apps/vscode-artifacts/pibo-vscode-ext-1.4.3.vsix +0 -0
@@ -36,6 +36,6 @@ Error generating stack: `+e.message+`
36
36
  `,inConstruct:`tableCell`},{atBreak:!0,character:`|`,after:`[ :-]`},{character:`|`,inConstruct:`tableCell`},{atBreak:!0,character:`:`,after:`-`},{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{inlineCode:f,table:o,tableCell:c,tableRow:s}};function o(e,t,n,r){return l(u(e,n,r),e.align)}function s(e,t,n,r){let i=l([d(e,n,r)]);return i.slice(0,i.indexOf(`
37
37
  `))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return Qh(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i<r.length;)a[i]=d(r[i],t,n);return o(),a}function d(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`tableRow`);for(;++i<r.length;)a[i]=c(r[i],e,t,n);return o(),a}function f(e,t,n){let r=Yg.inlineCode(e,t,n);return n.stack.includes(`tableCell`)&&(r=r.replace(/\|/g,`\\$&`)),r}}function a_(){return{exit:{taskListCheckValueChecked:s_,taskListCheckValueUnchecked:s_,paragraph:c_}}}function o_(){return{unsafe:[{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{listItem:l_}}}function s_(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function c_(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i<r.length;){let e=r[i];if(e.type===`paragraph`){a=e;break}}a===e&&(n.value=n.value.slice(1),n.value.length===0?e.children.shift():e.position&&n.position&&typeof n.position.start.offset==`number`&&(n.position.start.column++,n.position.start.offset++,e.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function l_(e,t,n,r){let i=e.children[0],a=typeof e.checked==`boolean`&&i&&i.type===`paragraph`,o=`[`+(e.checked?`x`:` `)+`] `,s=n.createTracker(r);a&&s.move(o);let c=Yg.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(e){return e+o}}function u_(){return[gh(),Bh(),Gh(),Xg(),a_()]}function d_(e){return{extensions:[_h(),Vh(e),Kh(),i_(e),o_()]}}var f_={tokenize:E_,partial:!0},p_={tokenize:D_,partial:!0},m_={tokenize:O_,partial:!0},h_={tokenize:k_,partial:!0},g_={tokenize:A_,partial:!0},__={name:`wwwAutolink`,tokenize:w_,previous:j_},v_={name:`protocolAutolink`,tokenize:T_,previous:M_},y_={name:`emailAutolink`,tokenize:C_,previous:N_},b_={};function x_(){return{text:b_}}for(var S_=48;S_<123;)b_[S_]=y_,S_++,S_===58?S_=65:S_===91&&(S_=97);b_[43]=y_,b_[45]=y_,b_[46]=y_,b_[95]=y_,b_[72]=[y_,v_],b_[104]=[y_,v_],b_[87]=[y_,__],b_[119]=[y_,__];function C_(e,t,n){let r=this,i,a;return o;function o(t){return!P_(t)||!N_.call(r,r.previous)||F_(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkEmail`),s(t))}function s(t){return P_(t)?(e.consume(t),s):t===64?(e.consume(t),c):n(t)}function c(t){return t===46?e.check(g_,u,l)(t):t===45||t===95||_u(t)?(a=!0,e.consume(t),c):u(t)}function l(t){return e.consume(t),i=!0,c}function u(o){return a&&i&&gu(r.previous)?(e.exit(`literalAutolinkEmail`),e.exit(`literalAutolink`),t(o)):n(o)}}function w_(e,t,n){let r=this;return i;function i(t){return t!==87&&t!==119||!j_.call(r,r.previous)||F_(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkWww`),e.check(f_,e.attempt(p_,e.attempt(m_,a),n),n)(t))}function a(n){return e.exit(`literalAutolinkWww`),e.exit(`literalAutolink`),t(n)}}function T_(e,t,n){let r=this,i=``,a=!1;return o;function o(t){return(t===72||t===104)&&M_.call(r,r.previous)&&!F_(r.events)?(e.enter(`literalAutolink`),e.enter(`literalAutolinkHttp`),i+=String.fromCodePoint(t),e.consume(t),s):n(t)}function s(t){if(gu(t)&&i.length<5)return i+=String.fromCodePoint(t),e.consume(t),s;if(t===58){let n=i.toLowerCase();if(n===`http`||n===`https`)return e.consume(t),c}return n(t)}function c(t){return t===47?(e.consume(t),a?l:(a=!0,c)):n(t)}function l(t){return t===null||yu(t)||Cu(t)||Tu(t)||wu(t)?n(t):e.attempt(p_,e.attempt(m_,u),n)(t)}function u(n){return e.exit(`literalAutolinkHttp`),e.exit(`literalAutolink`),t(n)}}function E_(e,t,n){let r=0;return i;function i(t){return(t===87||t===119)&&r<3?(r++,e.consume(t),i):t===46&&r===3?(e.consume(t),a):n(t)}function a(e){return e===null?n(e):t(e)}}function D_(e,t,n){let r,i,a;return o;function o(t){return t===46||t===95?e.check(h_,c,s)(t):t===null||Cu(t)||Tu(t)||t!==45&&wu(t)?c(t):(a=!0,e.consume(t),o)}function s(t){return t===95?r=!0:(i=r,r=void 0),e.consume(t),o}function c(e){return i||r||!a?n(e):t(e)}}function O_(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(h_,t,a)(o):o===null||Cu(o)||Tu(o)?t(o):(e.consume(o),i)}function a(t){return t===41&&r++,e.consume(t),i}}function k_(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),a):o===93?(e.consume(o),i):o===60||o===null||Cu(o)||Tu(o)?t(o):n(o)}function i(e){return e===null||e===40||e===91||Cu(e)||Tu(e)?t(e):r(e)}function a(e){return gu(e)?o(e):n(e)}function o(t){return t===59?(e.consume(t),r):gu(t)?(e.consume(t),o):n(t)}}function A_(e,t,n){return r;function r(t){return e.consume(t),i}function i(e){return _u(e)?n(e):t(e)}}function j_(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Cu(e)}function M_(e){return!gu(e)}function N_(e){return!(e===47||P_(e))}function P_(e){return e===43||e===45||e===46||e===95||_u(e)}function F_(e){let t=e.length,n=!1;for(;t--;){let r=e[t][1];if((r.type===`labelLink`||r.type===`labelImage`)&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var I_={tokenize:W_,partial:!0};function L_(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:V_,continuation:{tokenize:H_},exit:U_}},text:{91:{name:`gfmFootnoteCall`,tokenize:B_},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:R_,resolveTo:z_}}}}function R_(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=hu(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function z_(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function B_(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||Cu(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(hu(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return Cu(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function V_(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||Cu(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=hu(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return Cu(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),Ou(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function H_(e,t,n){return e.check(Uu,t,e.attempt(I_,t,n))}function U_(e){e.exit(`gfmFootnoteDefinition`)}function W_(e,t,n){let r=this;return Ou(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function G_(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`strikethroughSequenceTemporary`&&e[n][1]._close){let r=n;for(;r--;)if(e[r][0]===`exit`&&e[r][1].type===`strikethroughSequenceTemporary`&&e[r][1]._open&&e[n][1].end.offset-e[n][1].start.offset===e[r][1].end.offset-e[r][1].start.offset){e[n][1].type=`strikethroughSequence`,e[r][1].type=`strikethroughSequence`;let i={type:`strikethrough`,start:Object.assign({},e[r][1].start),end:Object.assign({},e[n][1].end)},a={type:`strikethroughText`,start:Object.assign({},e[r][1].end),end:Object.assign({},e[n][1].start)},o=[[`enter`,i,t],[`enter`,e[r][1],t],[`exit`,e[r][1],t],[`enter`,a,t]],s=t.parser.constructs.insideSpan.null;s&&cu(o,o.length,0,Iu(s,e.slice(r+1,n),t)),cu(o,o.length,0,[[`exit`,a,t],[`enter`,e[n][1],t],[`exit`,e[n][1],t],[`exit`,i,t]]),cu(e,r-1,n-r+3,o),n=r+o.length-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`strikethroughSequenceTemporary`&&(e[n][1].type=`data`);return e}function i(e,n,r){let i=this.previous,a=this.events,o=0;return s;function s(t){return i===126&&a[a.length-1][1].type!==`characterEscape`?r(t):(e.enter(`strikethroughSequenceTemporary`),c(t))}function c(a){let s=Fu(i);if(a===126)return o>1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=Fu(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var K_=class{constructor(){this.map=[]}add(e,t,n){q_(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function q_(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function J_(e,t){let n=!1,r=[];for(;t<e.length;){let i=e[t];if(n){if(i[0]===`enter`)i[1].type===`tableContent`&&r.push(e[t+1][1].type===`tableDelimiterMarker`?`left`:`none`);else if(i[1].type===`tableContent`){if(e[t-1][1].type===`tableDelimiterMarker`){let e=r.length-1;r[e]=r[e]===`left`?`center`:`right`}}else if(i[1].type===`tableDelimiterRow`)break}else i[0]===`enter`&&i[1].type===`tableDelimiterRow`&&(n=!0);t+=1}return r}function Y_(){return{flow:{null:{name:`table`,tokenize:X_,resolveAll:Z_}}}}function X_(e,t,n){let r=this,i=0,a=0,o;return s;function s(e){let t=r.events.length-1;for(;t>-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):Z(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):Q(t)?Ou(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||Cu(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,Q(t)?Ou(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return Q(t)?Ou(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||Z(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return Q(t)?Ou(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||Z(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||Z(n)?(e.exit(`tableRow`),t(n)):Q(n)?Ou(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||Cu(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function Z_(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new K_;for(;++n<e.length;){let p=e[n],m=p[1];p[0]===`enter`?m.type===`tableHead`?(s=!1,c!==0&&($_(f,t,c,l,u),u=void 0,c=0),l={type:`table`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,l,t]])):m.type===`tableRow`||m.type===`tableDelimiterRow`?(r=!0,d=void 0,a=[0,0,0,0],o=[0,n+1,0,0],s&&(s=!1,u={type:`tableBody`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,u,t]])),i=m.type===`tableDelimiterRow`?2:u?3:1):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)?(r=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],d=Q_(f,t,a,i,void 0,d),a=[0,0,0,0]),o[2]=n)):m.type===`tableCellDivider`&&(r?r=!1:(a[1]!==0&&(o[0]=o[1],d=Q_(f,t,a,i,void 0,d)),a=o,o=[a[1],n,0,0])):m.type===`tableHead`?(s=!0,c=n):m.type===`tableRow`||m.type===`tableDelimiterRow`?(c=n,a[1]===0?o[1]!==0&&(d=Q_(f,t,o,i,n,d)):(o[0]=o[1],d=Q_(f,t,a,i,n,d)),i=0):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)&&(o[3]=n)}for(c!==0&&$_(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){let e=t.events[n];e[0]===`enter`&&e[1].type===`table`&&(e[1]._align=J_(t.events,n))}return e}function Q_(e,t,n,r,i,a){let o=r===1?`tableHeader`:r===2?`tableDelimiter`:`tableData`;n[0]!==0&&(a.end=Object.assign({},ev(t.events,n[0])),e.add(n[0],0,[[`exit`,a,t]]));let s=ev(t.events,n[1]);if(a={type:o,start:Object.assign({},s),end:Object.assign({},s)},e.add(n[1],0,[[`enter`,a,t]]),n[2]!==0){let i=ev(t.events,n[2]),a=ev(t.events,n[3]),o={type:`tableContent`,start:Object.assign({},i),end:Object.assign({},a)};if(e.add(n[2],0,[[`enter`,o,t]]),r!==2){let r=t.events[n[2]],i=t.events[n[3]];if(r[1].end=Object.assign({},i[1].end),r[1].type=`chunkText`,r[1].contentType=`text`,n[3]>n[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},ev(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function $_(e,t,n,r,i){let a=[],o=ev(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function ev(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var tv={name:`tasklistCheck`,tokenize:rv};function nv(){return{text:{91:tv}}}function rv(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return Cu(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return Z(r)?t(r):Q(r)?e.check({tokenize:iv},t,n)(r):n(r)}}function iv(e,t,n){return Ou(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function av(e){return du([x_(),L_(),G_(e),Y_(),nv()])}var ov={};function sv(e){let t=this,n=e||ov,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(av(n)),a.push(u_()),o.push(d_(n))}var cv=l(o(((e,t)=>{var n=function(e){var t=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,n=0,r={},i={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function e(t){return t instanceof a?new a(t.type,e(t.content),t.alias):Array.isArray(t)?t.map(e):t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/\u00a0/g,` `)},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,`__id`,{value:++n}),e.__id},clone:function e(t,n){n||={};var r,a;switch(i.util.type(t)){case`Object`:if(a=i.util.objId(t),n[a])return n[a];for(var o in r={},n[a]=r,t)t.hasOwnProperty(o)&&(r[o]=e(t[o],n));return r;case`Array`:return a=i.util.objId(t),n[a]?n[a]:(r=[],n[a]=r,t.forEach(function(t,i){r[i]=e(t,n)}),r);default:return t}},getLanguage:function(e){for(;e;){var n=t.exec(e.className);if(n)return n[1].toLowerCase();e=e.parentElement}return`none`},setLanguage:function(e,n){e.className=e.className.replace(RegExp(t,`gi`),``),e.classList.add(`language-`+n)},currentScript:function(){if(typeof document>`u`)return null;if(document.currentScript&&document.currentScript.tagName===`SCRIPT`)return document.currentScript;try{throw Error()}catch(r){var e=(/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(r.stack)||[])[1];if(e){var t=document.getElementsByTagName(`script`);for(var n in t)if(t[n].src==e)return t[n]}return null}},isActive:function(e,t,n){for(var r=`no-`+t;e;){var i=e.classList;if(i.contains(t))return!0;if(i.contains(r))return!1;e=e.parentElement}return!!n}},languages:{plain:r,plaintext:r,text:r,txt:r,extend:function(e,t){var n=i.util.clone(i.languages[e]);for(var r in t)n[r]=t[r];return n},insertBefore:function(e,t,n,r){r||=i.languages;var a=r[e],o={};for(var s in a)if(a.hasOwnProperty(s)){if(s==t)for(var c in n)n.hasOwnProperty(c)&&(o[c]=n[c]);n.hasOwnProperty(s)||(o[s]=a[s])}var l=r[e];return r[e]=o,i.languages.DFS(i.languages,function(t,n){n===l&&t!=e&&(this[t]=o)}),o},DFS:function e(t,n,r,a){a||={};var o=i.util.objId;for(var s in t)if(t.hasOwnProperty(s)){n.call(t,s,t[s],r||s);var c=t[s],l=i.util.type(c);l===`Object`&&!a[o(c)]?(a[o(c)]=!0,e(c,n,null,a)):l===`Array`&&!a[o(c)]&&(a[o(c)]=!0,e(c,n,s,a))}}},plugins:{},highlightAll:function(e,t){i.highlightAllUnder(document,e,t)},highlightAllUnder:function(e,t,n){var r={callback:n,container:e,selector:`code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code`};i.hooks.run(`before-highlightall`,r),r.elements=Array.prototype.slice.apply(r.container.querySelectorAll(r.selector)),i.hooks.run(`before-all-elements-highlight`,r);for(var a=0,o;o=r.elements[a++];)i.highlightElement(o,t===!0,r.callback)},highlightElement:function(t,n,r){var a=i.util.getLanguage(t),o=i.languages[a];i.util.setLanguage(t,a);var s=t.parentElement;s&&s.nodeName.toLowerCase()===`pre`&&i.util.setLanguage(s,a);var c={element:t,language:a,grammar:o,code:t.textContent};function l(e){c.highlightedCode=e,i.hooks.run(`before-insert`,c),c.element.innerHTML=c.highlightedCode,i.hooks.run(`after-highlight`,c),i.hooks.run(`complete`,c),r&&r.call(c.element)}if(i.hooks.run(`before-sanity-check`,c),s=c.element.parentElement,s&&s.nodeName.toLowerCase()===`pre`&&!s.hasAttribute(`tabindex`)&&s.setAttribute(`tabindex`,`0`),!c.code){i.hooks.run(`complete`,c),r&&r.call(c.element);return}if(i.hooks.run(`before-highlight`,c),!c.grammar){l(i.util.encode(c.code));return}if(n&&e.Worker){var u=new Worker(i.filename);u.onmessage=function(e){l(e.data)},u.postMessage(JSON.stringify({language:c.language,code:c.code,immediateClose:!0}))}else l(i.highlight(c.code,c.grammar,c.language))},highlight:function(e,t,n){var r={code:e,grammar:t,language:n};if(i.hooks.run(`before-tokenize`,r),!r.grammar)throw Error(`The language "`+r.language+`" has no grammar.`);return r.tokens=i.tokenize(r.code,r.grammar),i.hooks.run(`after-tokenize`,r),a.stringify(i.util.encode(r.tokens),r.language)},tokenize:function(e,t){var n=t.rest;if(n){for(var r in n)t[r]=n[r];delete t.rest}var i=new c;return l(i,i.head,e),s(e,i,t,i.head,0),d(i)},hooks:{all:{},add:function(e,t){var n=i.hooks.all;n[e]=n[e]||[],n[e].push(t)},run:function(e,t){var n=i.hooks.all[e];if(!(!n||!n.length))for(var r=0,a;a=n[r++];)a(t)}},Token:a};e.Prism=i;function a(e,t,n,r){this.type=e,this.content=t,this.alias=n,this.length=(r||``).length|0}a.stringify=function e(t,n){if(typeof t==`string`)return t;if(Array.isArray(t)){var r=``;return t.forEach(function(t){r+=e(t,n)}),r}var a={type:t.type,content:e(t.content,n),tag:`span`,classes:[`token`,t.type],attributes:{},language:n},o=t.alias;o&&(Array.isArray(o)?Array.prototype.push.apply(a.classes,o):a.classes.push(o)),i.hooks.run(`wrap`,a);var s=``;for(var c in a.attributes)s+=` `+c+`="`+(a.attributes[c]||``).replace(/"/g,`&quot;`)+`"`;return`<`+a.tag+` class="`+a.classes.join(` `)+`"`+s+`>`+a.content+`</`+a.tag+`>`};function o(e,t,n,r){e.lastIndex=t;var i=e.exec(n);if(i&&r&&i[1]){var a=i[1].length;i.index+=a,i[0]=i[0].slice(a)}return i}function s(e,t,n,r,c,d){for(var f in n)if(!(!n.hasOwnProperty(f)||!n[f])){var p=n[f];p=Array.isArray(p)?p:[p];for(var m=0;m<p.length;++m){if(d&&d.cause==f+`,`+m)return;var h=p[m],g=h.inside,_=!!h.lookbehind,v=!!h.greedy,y=h.alias;if(v&&!h.pattern.global){var b=h.pattern.toString().match(/[imsuy]*$/)[0];h.pattern=RegExp(h.pattern.source,b+`g`)}for(var x=h.pattern||h,S=r.next,C=c;S!==t.tail&&!(d&&C>=d.reach);C+=S.value.length,S=S.next){var w=S.value;if(t.length>e.length)return;if(!(w instanceof a)){var T=1,E;if(v){if(E=o(x,C,e,_),!E||E.index>=e.length)break;var ee=E.index,D=E.index+E[0].length,O=C;for(O+=S.value.length;ee>=O;)S=S.next,O+=S.value.length;if(O-=S.value.length,C=O,S.value instanceof a)continue;for(var te=S;te!==t.tail&&(O<D||typeof te.value==`string`);te=te.next)T++,O+=te.value.length;T--,w=e.slice(C,O),E.index-=C}else if(E=o(x,0,w,_),!E)continue;var ee=E.index,ne=E[0],re=w.slice(0,ee),ie=w.slice(ee+ne.length),ae=C+w.length;d&&ae>d.reach&&(d.reach=ae);var oe=S.prev;re&&(oe=l(t,oe,re),C+=re.length),u(t,oe,T);var k=new a(f,g?i.tokenize(ne,g):ne,y,ne);if(S=l(t,oe,k),ie&&l(t,S,ie),T>1){var A={cause:f+`,`+m,reach:ae};s(e,t,n,S.prev,C,A),d&&A.reach>d.reach&&(d.reach=A.reach)}}}}}}function c(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0}function l(e,t,n){var r=t.next,i={value:n,prev:t,next:r};return t.next=i,r.prev=i,e.length++,i}function u(e,t,n){for(var r=t.next,i=0;i<n&&r!==e.tail;i++)r=r.next;t.next=r,r.prev=t,e.length-=i}function d(e){for(var t=[],n=e.head.next;n!==e.tail;)t.push(n.value),n=n.next;return t}if(!e.document)return e.addEventListener&&(i.disableWorkerMessageHandler||e.addEventListener(`message`,function(t){var n=JSON.parse(t.data),r=n.language,a=n.code,o=n.immediateClose;e.postMessage(i.highlight(a,i.languages[r],r)),o&&e.close()},!1)),i;var f=i.util.currentScript();f&&(i.filename=f.src,f.hasAttribute(`data-manual`)&&(i.manual=!0));function p(){i.manual||i.highlightAll()}if(!i.manual){var m=document.readyState;m===`loading`||m===`interactive`&&f&&f.defer?document.addEventListener(`DOMContentLoaded`,p):window.requestAnimationFrame?window.requestAnimationFrame(p):window.setTimeout(p,16)}return i}(typeof window<`u`?window:typeof WorkerGlobalScope<`u`&&self instanceof WorkerGlobalScope?self:{});t!==void 0&&t.exports&&(t.exports=n),typeof global<`u`&&(global.Prism=n),n.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:`attr-equals`},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:`named-entity`},/&#x?[\da-f]{1,8};/i]},n.languages.markup.tag.inside[`attr-value`].inside.entity=n.languages.markup.entity,n.languages.markup.doctype.inside[`internal-subset`].inside=n.languages.markup,n.hooks.add(`wrap`,function(e){e.type===`entity`&&(e.attributes.title=e.content.replace(/&amp;/,`&`))}),Object.defineProperty(n.languages.markup.tag,`addInlined`,{value:function(e,t){var r={};r[`language-`+t]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:n.languages[t]},r.cdata=/^<!\[CDATA\[|\]\]>$/i;var i={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:r}};i[`language-`+t]={pattern:/[\s\S]+/,inside:n.languages[t]};var a={};a[e]={pattern:RegExp(`(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[\\s\\S])*?(?=<\\/__>)`.replace(/__/g,function(){return e}),`i`),lookbehind:!0,greedy:!0,inside:i},n.languages.insertBefore(`markup`,`cdata`,a)}}),Object.defineProperty(n.languages.markup.tag,`addAttribute`,{value:function(e,t){n.languages.markup.tag.inside[`special-attr`].push({pattern:RegExp(`(^|["'\\s])(?:`+e+`)\\s*=\\s*(?:"[^"]*"|'[^']*'|[^\\s'">=]+(?=[\\s>]))`,`i`),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,`language-`+t],inside:n.languages[t]},punctuation:[{pattern:/^=/,alias:`attr-equals`},/"|'/]}}}})}}),n.languages.html=n.languages.markup,n.languages.mathml=n.languages.markup,n.languages.svg=n.languages.markup,n.languages.xml=n.languages.extend(`markup`,{}),n.languages.ssml=n.languages.xml,n.languages.atom=n.languages.xml,n.languages.rss=n.languages.xml,(function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp(`@[\\w-](?:[^;{\\s"']|\\s+(?!\\s)|`+t.source+`)*?(?:;|(?=\\s*\\{))`),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:`selector`},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp(`\\burl\\((?:`+t.source+`|(?:[^\\\\\\r\\n()"']|\\\\[\\s\\S])*)\\)`,`i`),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp(`^`+t.source+`$`),alias:`url`}}},selector:{pattern:RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|`+t.source+`)*(?=\\s*\\{)`),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined(`style`,`css`),n.tag.addAttribute(`style`,`css`))})(n),n.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/},n.languages.javascript=n.languages.extend(`clike`,{"class-name":[n.languages.clike[`class-name`],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(`(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])`),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),n.languages.javascript[`class-name`][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,n.languages.insertBefore(`javascript`,`keyword`,{regex:{pattern:RegExp(`((?:^|[^$\\w\\xA0-\\uFFFF."'\\])\\s]|\\b(?:return|yield))\\s*)\\/(?:(?:\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/)*(?:$|[\\r\\n,.;:})\\]]|\\/\\/))`),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:`language-regex`,inside:n.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:`function`},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:n.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:n.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:n.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:n.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),n.languages.insertBefore(`javascript`,`string`,{hashbang:{pattern:/^#!.*/,greedy:!0,alias:`comment`},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:`string`},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:`punctuation`},rest:n.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:`property`}}),n.languages.insertBefore(`javascript`,`operator`,{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:`property`}}),n.languages.markup&&(n.languages.markup.tag.addInlined(`script`,`javascript`),n.languages.markup.tag.addAttribute(`on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)`,`javascript`)),n.languages.js=n.languages.javascript,(function(){if(n===void 0||typeof document>`u`)return;Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector);var e=`Loading…`,t=function(e,t){return`✖ Error `+e+` while fetching file: `+t},r=`✖ Error: File does not exist or is empty`,i={js:`javascript`,py:`python`,rb:`ruby`,ps1:`powershell`,psm1:`powershell`,sh:`bash`,bat:`batch`,h:`c`,tex:`latex`},a=`data-src-status`,o=`loading`,s=`loaded`,c=`failed`,l=`pre[data-src]:not([`+a+`="`+s+`"]):not([`+a+`="`+o+`"])`;function u(e,n,i){var a=new XMLHttpRequest;a.open(`GET`,e,!0),a.onreadystatechange=function(){a.readyState==4&&(a.status<400&&a.responseText?n(a.responseText):a.status>=400?i(t(a.status,a.statusText)):i(r))},a.send(null)}function d(e){var t=/^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(e||``);if(t){var n=Number(t[1]),r=t[2],i=t[3];return r?i?[n,Number(i)]:[n,void 0]:[n,n]}}n.hooks.add(`before-highlightall`,function(e){e.selector+=`, `+l}),n.hooks.add(`before-sanity-check`,function(t){var r=t.element;if(r.matches(l)){t.code=``,r.setAttribute(a,o);var f=r.appendChild(document.createElement(`CODE`));f.textContent=e;var p=r.getAttribute(`data-src`),m=t.language;if(m===`none`){var h=(/\.(\w+)$/.exec(p)||[,`none`])[1];m=i[h]||h}n.util.setLanguage(f,m),n.util.setLanguage(r,m);var g=n.plugins.autoloader;g&&g.loadLanguages(m),u(p,function(e){r.setAttribute(a,s);var t=d(r.getAttribute(`data-range`));if(t){var i=e.split(/\r\n?|\n/g),o=t[0],c=t[1]==null?i.length:t[1];o<0&&(o+=i.length),o=Math.max(0,Math.min(o-1,i.length)),c<0&&(c+=i.length),c=Math.max(0,Math.min(c,i.length)),e=i.slice(o,c).join(`
38
38
  `),r.hasAttribute(`data-start`)||r.setAttribute(`data-start`,String(o+1))}f.textContent=e,n.highlightElement(f)},function(e){r.setAttribute(a,c),f.textContent=e})}}),n.plugins.fileHighlight={highlight:function(e){for(var t=(e||document).querySelectorAll(l),r=0,i;i=t[r++];)n.highlightElement(i)}};var f=!1;n.fileHighlight=function(){f||=(console.warn("Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead."),!0),n.plugins.fileHighlight.highlight.apply(this,arguments)}})()}))(),1);function lv(e){return typeof e==`object`&&!!e&&`languages`in e}var uv=globalThis,dv=lv(uv.Prism)?uv.Prism:cv.default;uv.Prism=dv,typeof window<`u`&&(window.Prism=dv);var fv;function pv(){if(fv!==void 0)return fv;let e=kv();if(!e)return fv=!1,fv;try{let t=new URL(e.location.href).searchParams.get(`debugStreaming`);fv=t===null?e.localStorage.getItem(`pibo.chat.debugStreaming`)===`1`:t!==`0`&&t!==`false`}catch{fv=!1}return fv}function mv(e,t){Tv(e,e=>{e.liveOpenCount+=1,e.lastReadyState=t})}function hv(e,t){Tv(e,e=>{e.liveErrorCount+=1,e.lastReadyState=t})}function gv(e,t,n,r){Tv(e,e=>{let i=jv();e.eventCount+=1,e.eventTypeCounts[t.type]=(e.eventTypeCounts[t.type]??0)+1,e.lastEventAt=i,e.firstEventAt??=i,e.lastReadyState=r;let a=n||t.streamFrameId;if(a){e.lastEventId=a;let t=wv(a);t===`durable`?e.lastDurableCursor=a:t===`transient`&&(e.lastTransientLiveId=a)}t.type===`TEXT_MESSAGE_CONTENT`&&typeof t.delta==`string`?(e.firstTextDeltaAt??=i,e.textDeltaCount+=1,e.textDeltaBytes+=Av(t.delta)):t.type===`REASONING_MESSAGE_CONTENT`&&typeof t.delta==`string`&&(e.firstReasoningDeltaAt??=i,e.reasoningDeltaCount+=1,e.reasoningDeltaBytes+=Av(t.delta))})}function _v(e,t,n,r){Tv(e,e=>{if(e.firstEnqueueAt??=jv(),e.enqueueCount+=1,r&&(e.enqueueFlushImmediateCount+=1),e.pendingEventCount=n,t.streamFrameId){let n=wv(t.streamFrameId);n===`durable`?e.lastDurableCursor=t.streamFrameId:n===`transient`&&(e.lastTransientLiveId=t.streamFrameId)}})}function vv(e,t,n){Tv(e,e=>{let r=jv();e.firstFlushAt??=r,e.firstOverlayUpdateAt??=r,e.flushCount+=1,e.flushedEventCount+=t,e.pendingEventCount=0,e.overlayUpdateCount+=1,e.overlayEventCount=n,e.lastFlushAt=r})}function yv(e,t){Tv(e,e=>{let n=Mv(t);e.liveTraceComputeCount+=1,e.liveTraceComputeDurationMsLast=n,e.liveTraceComputeDurationMsTotal+=n,e.liveTraceComputeDurationMsMax=Math.max(e.liveTraceComputeDurationMsMax??0,n)})}function bv(e,t){Ev(n=>{let r=Mv(t);n.markdownRenderCount+=1,n.markdownRenderDurationMsLast=r,n.markdownRenderDurationMsTotal+=r,n.markdownRenderDurationMsMax=Math.max(n.markdownRenderDurationMsMax??0,r),e===`plain`?(n.markdownRenderPlainCount+=1,n.markdownRenderPlainDurationMsTotal+=r,n.markdownRenderPlainDurationMsMax=Math.max(n.markdownRenderPlainDurationMsMax??0,r)):e===`gfm-fast`?(n.markdownRenderGfmFastCount+=1,n.markdownRenderGfmFastDurationMsTotal+=r,n.markdownRenderGfmFastDurationMsMax=Math.max(n.markdownRenderGfmFastDurationMsMax??0,r)):(n.markdownRenderFullCount+=1,n.markdownRenderFullDurationMsTotal+=r,n.markdownRenderFullDurationMsMax=Math.max(n.markdownRenderFullDurationMsMax??0,r),e===`gfm`?(n.markdownRenderGfmCount+=1,n.markdownRenderGfmDurationMsTotal+=r,n.markdownRenderGfmDurationMsMax=Math.max(n.markdownRenderGfmDurationMsMax??0,r)):(n.markdownRenderCommonMarkCount+=1,n.markdownRenderCommonMarkDurationMsTotal+=r,n.markdownRenderCommonMarkDurationMsMax=Math.max(n.markdownRenderCommonMarkDurationMsMax??0,r)))})}function xv(e,t){Tv(e,e=>{e.traceRefreshScheduledCount+=1,e.lastTraceRefreshScheduledAt=jv(),e.lastTraceRefreshDelayMs=t})}function Sv(e,t){Tv(e,e=>{t.traceBaseUpdated&&(e.traceBaseUpdateCount+=1),e.overlayEventCount=t.overlayEventCount,t.traceBaseOutputLength!==void 0&&(e.traceBaseOutputLength=t.traceBaseOutputLength),t.currentOutputLength!==void 0&&(e.currentOutputLength=t.currentOutputLength)})}function Cv(e){let t=kv();if(!t?.__piboStreamingBenchmarkShouldDropOverlayEvent)return!1;try{return!!t.__piboStreamingBenchmarkShouldDropOverlayEvent(e)}catch{return!1}}function wv(e){return e?/^live:\d+$/.test(e)?`transient`:/^\d+:\d+$/.test(e)?`durable`:`other`:`missing`}function Tv(e,t){Ev(n=>{n.sessionIds.includes(e)||n.sessionIds.push(e),n.selectedPiboSessionId=e,t(n)})}function Ev(e){let t=Dv();t&&(e(t),t.updatedAt=jv())}function Dv(){if(!pv())return;let e=kv();if(e)return e.__piboStreamingDebugReset||=()=>(e.__piboStreamingDebug=Ov(),e.__piboStreamingDebug),e.__piboStreamingDebug??=Ov(),e.__piboStreamingDebug}function Ov(){let e=jv();return{enabled:!0,startedAt:e,updatedAt:e,sessionIds:[],liveOpenCount:0,liveErrorCount:0,eventCount:0,eventTypeCounts:{},textDeltaCount:0,textDeltaBytes:0,reasoningDeltaCount:0,reasoningDeltaBytes:0,enqueueCount:0,enqueueFlushImmediateCount:0,pendingEventCount:0,flushCount:0,flushedEventCount:0,overlayUpdateCount:0,overlayEventCount:0,liveTraceComputeCount:0,liveTraceComputeDurationMsTotal:0,markdownRenderCount:0,markdownRenderPlainCount:0,markdownRenderFullCount:0,markdownRenderCommonMarkCount:0,markdownRenderGfmCount:0,markdownRenderGfmFastCount:0,markdownRenderDurationMsTotal:0,markdownRenderPlainDurationMsTotal:0,markdownRenderFullDurationMsTotal:0,markdownRenderCommonMarkDurationMsTotal:0,markdownRenderGfmDurationMsTotal:0,markdownRenderGfmFastDurationMsTotal:0,traceRefreshScheduledCount:0,traceRefreshStartedCount:0,traceRefreshCompletedCount:0,traceRefreshFailedCount:0,traceRefreshDurationMsTotal:0,traceBaseUpdateCount:0}}function kv(){return typeof window>`u`?void 0:window}function Av(e){return typeof TextEncoder<`u`?new TextEncoder().encode(e).byteLength:e.length}function jv(){return new Date().toISOString()}function Mv(e){return Math.max(0,Math.round(e*1e3)/1e3)}(function(e){var t=`\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b`,n={pattern:/(^(["']?)\w+\2)[ \t]+\S.*/,lookbehind:!0,alias:`punctuation`,inside:null},r={bash:n,environment:{pattern:RegExp(`\\$`+t),alias:`constant`},variable:[{pattern:/\$?\(\([\s\S]+?\)\)/,greedy:!0,inside:{variable:[{pattern:/(^\$\(\([\s\S]+)\)\)/,lookbehind:!0},/^\$\(\(/],number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,operator:/--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp(`(\\{)`+t),lookbehind:!0,alias:`constant`}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:`important`},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:`function`},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:`function`}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:`variable`,lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/,inside:{environment:{pattern:RegExp(`(^|[\\s;|&]|[<>]\\()`+t),lookbehind:!0,alias:`constant`}},alias:`variable`,lookbehind:!0},parameter:{pattern:/(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,alias:`variable`,lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:r},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:r},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:r.entity}}],environment:{pattern:RegExp(`\\$?`+t),alias:`constant`},variable:r.variable,function:{pattern:/(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|java|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|sysctl|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,lookbehind:!0,alias:`class-name`},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:`important`},operator:{pattern:/\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,inside:{"file-descriptor":{pattern:/^\d/,alias:`important`}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var i=[`comment`,`function-name`,`for-or-select`,`assign-left`,`parameter`,`string`,`environment`,`function`,`keyword`,`builtin`,`boolean`,`file-descriptor`,`operator`,`punctuation`,`number`],a=r.variable[1].inside,o=0;o<i.length;o++)a[i[o]]=e.languages.bash[i[o]];e.languages.sh=e.languages.bash,e.languages.shell=e.languages.bash})(Prism),(function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp(`@[\\w-](?:[^;{\\s"']|\\s+(?!\\s)|`+t.source+`)*?(?:;|(?=\\s*\\{))`),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:`selector`},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp(`\\burl\\((?:`+t.source+`|(?:[^\\\\\\r\\n()"']|\\\\[\\s\\S])*)\\)`,`i`),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp(`^`+t.source+`$`),alias:`url`}}},selector:{pattern:RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|`+t.source+`)*(?=\\s*\\{)`),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined(`style`,`css`),n.tag.addAttribute(`style`,`css`))})(Prism),Prism.languages.javascript=Prism.languages.extend(`clike`,{"class-name":[Prism.languages.clike[`class-name`],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(`(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])`),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),Prism.languages.javascript[`class-name`][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,Prism.languages.insertBefore(`javascript`,`keyword`,{regex:{pattern:RegExp(`((?:^|[^$\\w\\xA0-\\uFFFF."'\\])\\s]|\\b(?:return|yield))\\s*)\\/(?:(?:\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/)*(?:$|[\\r\\n,.;:})\\]]|\\/\\/))`),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:`language-regex`,inside:Prism.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:`function`},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:Prism.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),Prism.languages.insertBefore(`javascript`,`string`,{hashbang:{pattern:/^#!.*/,greedy:!0,alias:`comment`},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:`string`},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:`punctuation`},rest:Prism.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:`property`}}),Prism.languages.insertBefore(`javascript`,`operator`,{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:`property`}}),Prism.languages.markup&&(Prism.languages.markup.tag.addInlined(`script`,`javascript`),Prism.languages.markup.tag.addAttribute(`on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)`,`javascript`)),Prism.languages.js=Prism.languages.javascript,Prism.languages.json={property:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,lookbehind:!0,greedy:!0},comment:{pattern:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},number:/-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:false|true)\b/,null:{pattern:/\bnull\b/,alias:`keyword`}},Prism.languages.webmanifest=Prism.languages.json,(function(e){var t=`(?:\\\\.|[^\\\\\\n\\r]|(?:\\n|\\r\\n?)(?![\\r\\n]))`;function n(e){return e=e.replace(/<inner>/g,function(){return t}),RegExp(`((?:^|[^\\\\])(?:\\\\{2})*)(?:`+e+`)`)}var r="(?:\\\\.|``(?:[^`\\r\\n]|`(?!`))+``|`[^`\\r\\n]+`|[^\\\\|\\r\\n`])+",i=`\\|?__(?:\\|__)+\\|?(?:(?:\\n|\\r\\n?)|(?![\\s\\S]))`.replace(/__/g,function(){return r}),a=`\\|?[ \\t]*:?-{3,}:?[ \\t]*(?:\\|[ \\t]*:?-{3,}:?[ \\t]*)+\\|?(?:\\n|\\r\\n?)`;e.languages.markdown=e.languages.extend(`markup`,{}),e.languages.insertBefore(`markdown`,`prolog`,{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S+(?:\s+\S+)*/,alias:[`yaml`,`language-yaml`],inside:e.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:`punctuation`},table:{pattern:RegExp(`^`+i+a+`(?:`+i+`)*`,`m`),inside:{"table-data-rows":{pattern:RegExp(`^(`+i+a+`)(?:`+i+`)*$`),lookbehind:!0,inside:{"table-data":{pattern:RegExp(r),inside:e.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp(`^(`+i+`)`+a+`$`),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp(`^`+i+`$`),inside:{"table-header":{pattern:RegExp(r),alias:`important`,inside:e.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:`keyword`},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:`important`,inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:`important`,inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:`punctuation`},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:`punctuation`},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:`url`},bold:{pattern:n(`\\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\\b|\\*\\*(?:(?!\\*)<inner>|\\*(?:(?!\\*)<inner>)+\\*)+\\*\\*`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:n(`\\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\\b|\\*(?:(?!\\*)<inner>|\\*\\*(?:(?!\\*)<inner>)+\\*\\*)+\\*`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:n(`(~~?)(?:(?!~)<inner>)+\\2`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},"code-snippet":{pattern:/(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,lookbehind:!0,greedy:!0,alias:[`code`,`keyword`]},url:{pattern:n(`!?\\[(?:(?!\\])<inner>)+\\](?:\\([^\\s)]+(?:[\\t ]+"(?:\\\\.|[^"\\\\])*")?\\)|[ \\t]?\\[(?:(?!\\])<inner>)+\\])`),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),[`url`,`bold`,`italic`,`strike`].forEach(function(t){[`url`,`bold`,`italic`,`strike`,`code-snippet`].forEach(function(n){t!==n&&(e.languages.markdown[t].inside.content.inside[n]=e.languages.markdown[n])})}),e.hooks.add(`after-tokenize`,function(e){if(e.language!==`markdown`&&e.language!==`md`)return;function t(e){if(!(!e||typeof e==`string`))for(var n=0,r=e.length;n<r;n++){var i=e[n];if(i.type!==`code`){t(i.content);continue}var a=i.content[1],o=i.content[3];if(a&&o&&a.type===`code-language`&&o.type===`code-block`&&typeof a.content==`string`){var s=a.content.replace(/\b#/g,`sharp`).replace(/\b\+\+/g,`pp`);s=(/[a-z][\w-]*/i.exec(s)||[``])[0].toLowerCase();var c=`language-`+s;o.alias?typeof o.alias==`string`?o.alias=[o.alias,c]:o.alias.push(c):o.alias=[c]}}}t(e.tokens)}),e.hooks.add(`wrap`,function(t){if(t.type===`code-block`){for(var n=``,r=0,i=t.classes.length;r<i;r++){var a=t.classes[r],o=/language-(.+)/.exec(a);if(o){n=o[1];break}}var s=e.languages[n];if(s)t.content=e.highlight(l(t.content),s,n);else if(n&&n!==`none`&&e.plugins.autoloader){var c=`md-`+new Date().valueOf()+`-`+Math.floor(Math.random()*0x2386f26fc10000);t.attributes.id=c,e.plugins.autoloader.loadLanguages(n,function(){var t=document.getElementById(c);t&&(t.innerHTML=e.highlight(t.textContent,e.languages[n],n))})}}});var o=RegExp(e.languages.markup.tag.pattern.source,`gi`),s={amp:`&`,lt:`<`,gt:`>`,quot:`"`},c=String.fromCodePoint||String.fromCharCode;function l(e){var t=e.replace(o,``);return t=t.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi,function(e,t){return t=t.toLowerCase(),t[0]===`#`?c(t[1]===`x`?parseInt(t.slice(2),16):Number(t.slice(1))):s[t]||e}),t}e.languages.md=e.languages.markdown})(Prism),(function(e){e.languages.typescript=e.languages.extend(`javascript`,{"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter,delete e.languages.typescript[`literal-property`];var t=e.languages.extend(`typescript`,{});delete t[`class-name`],e.languages.typescript[`class-name`].inside=t,e.languages.insertBefore(`typescript`,`function`,{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:`operator`},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:`class-name`,inside:t}}}}),e.languages.ts=e.languages.typescript})(Prism),(function(e){var t=/[*&][^\s[\]{},]+/,n=/!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/,r=`(?:`+n.source+`(?:[ ]+`+t.source+`)?|`+t.source+`(?:[ ]+`+n.source+`)?)`,i=`(?:[^\\s\\x00-\\x08\\x0e-\\x1f!"#%&'*,\\-:>?@[\\]\`{|}\\x7f-\\x84\\x86-\\x9f\\ud800-\\udfff\\ufffe\\uffff]|[?:-]<PLAIN>)(?:[ \\t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*`.replace(/<PLAIN>/g,function(){return`[^\\s\\x00-\\x08\\x0e-\\x1f,[\\]{}\\x7f-\\x84\\x86-\\x9f\\ud800-\\udfff\\ufffe\\uffff]`}),a=`"(?:[^"\\\\\\r\\n]|\\\\.)*"|'(?:[^'\\\\\\r\\n]|\\\\.)*'`;function o(e,t){t=(t||``).replace(/m/g,``)+`m`;var n=`([:\\-,[{]\\s*(?:\\s<<prop>>[ \\t]+)?)(?:<<value>>)(?=[ \\t]*(?:$|,|\\]|\\}|(?:[\\r\\n]\\s*)?#))`.replace(/<<prop>>/g,function(){return r}).replace(/<<value>>/g,function(){return e});return RegExp(n,t)}e.languages.yaml={scalar:{pattern:RegExp(`([\\-:]\\s*(?:\\s<<prop>>[ \\t]+)?[|>])[ \\t]*(?:((?:\\r?\\n|\\r)[ \\t]+)\\S[^\\r\\n]*(?:\\2[^\\r\\n]+)*)`.replace(/<<prop>>/g,function(){return r})),lookbehind:!0,alias:`string`},comment:/#.*/,key:{pattern:RegExp(`((?:^|[:\\-,[{\\r\\n?])[ \\t]*(?:<<prop>>[ \\t]+)?)<<key>>(?=\\s*:\\s)`.replace(/<<prop>>/g,function(){return r}).replace(/<<key>>/g,function(){return`(?:`+i+`|`+a+`)`})),lookbehind:!0,greedy:!0,alias:`atrule`},directive:{pattern:/(^[ \t]*)%.+/m,lookbehind:!0,alias:`important`},datetime:{pattern:o(`\\d{4}-\\d\\d?-\\d\\d?(?:[tT]|[ \\t]+)\\d\\d?:\\d{2}:\\d{2}(?:\\.\\d*)?(?:[ \\t]*(?:Z|[-+]\\d\\d?(?::\\d{2})?))?|\\d{4}-\\d{2}-\\d{2}|\\d\\d?:\\d{2}(?::\\d{2}(?:\\.\\d*)?)?`),lookbehind:!0,alias:`number`},boolean:{pattern:o(`false|true`,`i`),lookbehind:!0,alias:`important`},null:{pattern:o(`null|~`,`i`),lookbehind:!0,alias:`important`},string:{pattern:o(a),lookbehind:!0,greedy:!0},number:{pattern:o(`[+-]?(?:0x[\\da-f]+|0o[0-7]+|(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?|\\.inf|\\.nan)`,`i`),lookbehind:!0},tag:n,important:t,punctuation:/---|[:[\]{}\-,|>?]|\.\.\./},e.languages.yml=e.languages.yaml})(Prism);var Nv=[`p`,`br`,`strong`,`em`,`a`,`ul`,`ol`,`li`,`blockquote`,`code`,`pre`,`h1`,`h2`,`h3`,`h4`,`hr`,`table`,`thead`,`tbody`,`tr`,`th`,`td`,`input`,`del`],Pv=[sv],Fv=[],Iv=/[\n\r\\`*_\[\]<>]|~~/,Lv=/^\s*(?:#{1,6}\s|[-+>]|(?:\d+[.)]))\s/,Rv=/^\s*-{3,}\s*$/,zv=/\b(?:https?:\/\/|www\.)|\S+@\S+\.\S+/i,Bv=/^\s*[-+*]\s+\[[ xX]\]\s/m,Vv=/(^|\n)\s*\|?.+\|.+\n\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*(?:\n|$)/;function Hv(e){return e.length>0&&!Iv.test(e)&&!Lv.test(e)&&!Rv.test(e)&&!(Uv(e)&&zv.test(e))}function Uv(e){return e.includes(`://`)||e.includes(`www.`)||e.includes(`@`)}function Wv(e){let t=Gv(e);return t?t.openerEnd>=e.length?e.slice(0,t.openerStart):`${e}\``:e}function Gv(e){let t=0;for(;t<e.length;){let n=e.indexOf("`",t);if(n===-1)return;if(Jv(e,n)){t=n+1;continue}if(qv(e,n)!==1)return;let r=Kv(e,n+1);if(r===-1)return{openerStart:n,openerEnd:n+1};t=r+1}}function Kv(e,t){for(;t<e.length;){let n=e.indexOf("`",t);if(n===-1)return-1;let r=qv(e,n);if(r===1)return n;t=n+r}return-1}function qv(e,t){let n=t;for(;n<e.length&&e[n]==="`";)n+=1;return n-t}function Jv(e,t){let n=0,r=t-1;for(;r>=0&&e[r]===`\\`;)n+=1,--r;return n%2==1}function Yv(e){return e.includes(`~~`)||e.includes(`[`)&&Bv.test(e)||e.includes(`|`)&&Vv.test(e)||Uv(e)&&zv.test(e)}var Xv=/[\n\r\\`*_\[\]<>]/,Zv=/^\s*[-+*]\s+\[([ xX])\]\s+(.+?)\s*$/,Qv=/[\n\r\\<>|~]/,$v=/[\n\r\\\[\]<>|~]/,ey=/[\s\[\]()`<>]/;function ty(e){if(!e.includes(`~~`)||Xv.test(e)||Lv.test(e)||Rv.test(e)||Uv(e)&&zv.test(e)||e.includes(`[`)&&Bv.test(e)||e.includes(`|`)&&Vv.test(e))return;let t=[],n=0,r=0;for(;n<e.length;){let i=e.indexOf(`~~`,n);if(i===-1){t.push(e.slice(n));break}let a=e.indexOf(`~~`,i+2);if(a===-1||a===i+2)return;let o=e.slice(n,i);o&&t.push(o);let s=e.slice(i+2,a);if(s.includes(`~`))return;t.push((0,M.jsx)(`del`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`del`,children:s},`del-${r}`)),r+=1,n=a+2}return r>0?(0,M.jsx)(`p`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`p`,children:t}):void 0}function ny(e){if(!e||ey.test(e))return;let t=sh(e);if(t){if(t.startsWith(`/`)||t.startsWith(`#`))return t;try{let e=new URL(t);return e.protocol===`http:`||e.protocol===`https:`||e.protocol===`mailto:`?t:void 0}catch{return}}}function ry(e,t){if(!e||$v.test(e))return;let n=[],r=0,i=0,a=0,o=0;for(;r<e.length;){let s=e.indexOf(`**`,r),c=e.indexOf(`_`,r),l=e.indexOf("`",r),u=s===-1?1/0:s,d=c===-1?1/0:c,f=Math.min(u,d,l===-1?1/0:l);if(f===1/0){let t=e.slice(r);if(t.includes(`*`)||t.includes(`_`)||t.includes("`")||Uv(t)&&zv.test(t))return;t&&n.push(t);break}let p=e.slice(r,f);if(p.includes(`*`)||p.includes(`_`)||p.includes("`")||Uv(p)&&zv.test(p))return;if(p&&n.push(p),f===u){let a=e.indexOf(`**`,f+2);if(a===-1||a===f+2)return;let o=e.slice(f+2,a);if(o.includes(`*`)||o.includes("`")||o.includes(`[`)||o.includes(`]`))return;if(o.includes(`_`)){if(!o.startsWith(`_`)||!o.endsWith(`_`)||o.length<=2)return;let e=o.slice(1,-1);if(e.includes(`*`)||e.includes(`_`)||e.includes("`")||e.includes(`[`)||e.includes(`]`))return;n.push((0,M.jsx)(`strong`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`strong`,children:(0,M.jsx)(`em`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`em`,children:e})},`link-${t}-strong-${i}`))}else n.push((0,M.jsx)(`strong`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`strong`,children:o},`link-${t}-strong-${i}`));i+=1,r=a+2}else if(f===d){if(e[f+1]===`_`)return;let i=e.indexOf(`_`,f+1);if(i===-1||i===f+1)return;let o=e.slice(f+1,i);if(o.includes(`**`)){if(!o.startsWith(`**`)||!o.endsWith(`**`)||o.length<=4)return;let e=o.slice(2,-2);if(e.includes(`*`)||e.includes(`_`)||e.includes("`")||e.includes(`[`)||e.includes(`]`))return;n.push((0,M.jsx)(`em`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`em`,children:(0,M.jsx)(`strong`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`strong`,children:e})},`link-${t}-em-${a}`))}else{if(o.includes(`*`)||o.includes(`_`)||o.includes("`")||o.includes(`[`)||o.includes(`]`))return;n.push((0,M.jsx)(`em`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`em`,children:o},`link-${t}-em-${a}`))}a+=1,r=i+1}else{if(e[f+1]==="`")return;let i=e.indexOf("`",f+1);if(i===-1||i===f+1)return;let a=e.slice(f+1,i);if(a.includes("`")||a.includes(`[`)||a.includes(`]`)||a.startsWith(` `)||a.endsWith(` `))return;n.push((0,M.jsx)(`code`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`code`,children:a},`link-${t}-code-${o}`)),o+=1,r=i+1}}return n.length>0?n:void 0}function iy(e){let t=[],n=0,r=0,i=0,a=0;for(;n<e.length;){let o=e.indexOf(`**`,n),s=e.indexOf("`",n),c=e.indexOf(`[`,n),l=o===-1?1/0:o,u=s===-1?1/0:s,d=Math.min(l,u,c===-1?1/0:c);if(d===1/0){let r=e.slice(n);if(r.includes(`*`)||r.includes(`_`)||r.includes("`")||r.includes(`[`)||r.includes(`]`)||Uv(r)&&zv.test(r))return;r&&t.push(r);break}let f=e.slice(n,d);if(f.includes(`*`)||f.includes(`_`)||f.includes("`")||f.includes(`[`)||f.includes(`]`)||Uv(f)&&zv.test(f))return;if(f&&t.push(f),d===l){let i=e.indexOf(`**`,d+2);if(i===-1||i===d+2)return;let a=e.slice(d+2,i);if(a.includes(`*`)||a.includes(`_`)||a.includes("`")||a.includes(`[`)||a.includes(`]`))return;t.push((0,M.jsx)(`strong`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`strong`,children:a},`strong-${r}`)),r+=1,n=i+2}else if(d===u){if(e[d+1]==="`")return;let r=e.indexOf("`",d+1);if(r===-1||r===d+1)return;let a=e.slice(d+1,r);if(a.includes(`_`)||a.includes("`")||a.includes(`[`)||a.includes(`]`)||a.startsWith(` `)||a.endsWith(` `))return;t.push((0,M.jsx)(`code`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`code`,children:a},`code-${i}`)),i+=1,n=r+1}else{let r=e.indexOf(`](`,d+1);if(r===-1||r===d+1)return;let i=e.indexOf(`)`,r+2);if(i===-1||i===r+2)return;let o=ry(e.slice(d+1,r),a),s=ny(e.slice(r+2,i));if(!s||!o)return;t.push((0,M.jsx)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`a`,children:o},`link-${a}`)),a+=1,n=i+1}}return t.length>0?t:void 0}function ay(e){let t=Zv.exec(e);if(!t)return;let n=t[2];if(!n||Qv.test(n))return;let r=iy(n);if(r)return(0,M.jsx)(`ul`,{className:`contains-task-list`,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`ul`,children:(0,M.jsxs)(`li`,{className:`task-list-item`,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`li`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:t[1].toLowerCase()===`x`,readOnly:!0,disabled:!0,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`input`}),r]})})}var oy={p({children:e,node:t,...n}){return(0,M.jsx)(`p`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`p`,...n,children:e})},ul({children:e,node:t,...n}){return(0,M.jsx)(`ul`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`ul`,...n,children:e})},ol({children:e,node:t,...n}){return(0,M.jsx)(`ol`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`ol`,...n,children:e})},li({children:e,node:t,...n}){return(0,M.jsx)(`li`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`li`,...n,children:e})},blockquote({children:e,node:t,...n}){return(0,M.jsx)(`blockquote`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`blockquote`,...n,children:e})},pre({children:e,node:t,...n}){return(0,M.jsx)(`pre`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`pre`,...n,children:e})},a({href:e,children:t}){return(0,M.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`a`,children:t})},code({className:e,children:t,node:n,...r}){let i=sy(e),a=String(t).replace(/\n$/,``);if(!i)return(0,M.jsx)(`code`,{className:e,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`code`,...r,children:t});let o=dv.languages[i];return o?(0,M.jsx)(`code`,{className:`language-${i}`,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`code`,dangerouslySetInnerHTML:{__html:dv.highlight(a,o,i)},...r}):(0,M.jsx)(`code`,{className:e,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`code`,...r,children:t})},th({children:e,node:t,...n}){return(0,M.jsx)(`th`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`th`,...n,children:e})},td({children:e,node:t,...n}){return(0,M.jsx)(`td`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`td`,...n,children:e})},input({checked:e,node:t,...n}){return(0,M.jsx)(`input`,{type:`checkbox`,checked:!!e,readOnly:!0,disabled:!0,"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`input`,...n})}};function sy(e){let t=/language-(\S+)/.exec(e??``);if(!t)return;let n=t[1].toLowerCase();return n===`sh`||n===`shell`?`bash`:n===`js`?`javascript`:n===`ts`?`typescript`:n===`md`?`markdown`:n===`yml`?`yaml`:n}function cy(e,t){t!==void 0&&bv(e,(typeof performance>`u`?Date.now():performance.now())-t)}var ly=(e,t,n)=>{if(n.tagName!==`a`||t!==`href`)return``;let r=sh(e);if(!r)return``;if(r.startsWith(`/`)||r.startsWith(`#`))return r;try{let e=new URL(r);return e.protocol===`http:`||e.protocol===`https:`||e.protocol===`mailto:`?r:``}catch{return``}},uy=(0,v.memo)(function({children:e,streaming:t=!1}){let n=pv()?typeof performance>`u`?Date.now():performance.now():void 0,r=t?Wv(e):e,i=`commonmark`,a;if(Hv(r))i=`plain`,a=(0,M.jsx)(`p`,{"data-pibo-component":`MarkdownRenderer`,"data-pibo-markdown-node":`p`,children:r});else{let e=Yv(r),t=e?ty(r)??ay(r):void 0;t?(i=`gfm-fast`,a=t):(i=e?`gfm`:`commonmark`,a=rh({allowedElements:Nv,children:r,components:oy,remarkPlugins:e?Pv:Fv,skipHtml:!0,urlTransform:ly}))}return cy(i,n),a}),dy={"agent.run":{color:`text-[#11a4d4]`,bgColor:`bg-[#11a4d4]/20`,borderColor:`border-[#11a4d4]`,label:`Agent Run`},"tool.call":{color:`text-purple-500`,bgColor:`bg-purple-500/20`,borderColor:`border-purple-500`,label:`Tool Call`},"tool.result":{color:`text-green-500`,bgColor:`bg-green-500/20`,borderColor:`border-green-500`,label:`Tool Result`},"model.request":{color:`text-blue-500`,bgColor:`bg-blue-500/20`,borderColor:`border-blue-500`,label:`Model Request`},"model.response":{color:`text-[#0bda57]`,bgColor:`bg-[#0bda57]/20`,borderColor:`border-[#0bda57]`,label:`Model Response`},"model.reasoning":{color:`text-amber-500`,bgColor:`bg-amber-500/20`,borderColor:`border-amber-500`,label:`Reasoning`},"agent.delegation":{color:`text-orange-500`,bgColor:`bg-orange-500/20`,borderColor:`border-orange-500`,label:`Agent Delegation`},"agent.async":{color:`text-orange-500`,bgColor:`bg-orange-500/20`,borderColor:`border-orange-500`,label:`Async Agent`},"yielded.run":{color:`text-[#11a4d4]`,bgColor:`bg-[#11a4d4]/20`,borderColor:`border-[#11a4d4]`,label:`Yielded Run`},"user.prompt":{color:`text-cyan-500`,bgColor:`bg-cyan-500/20`,borderColor:`border-cyan-500`,label:`User Prompt`},user_input:{color:`text-slate-500`,bgColor:`bg-slate-800`,borderColor:`border-slate-600`,label:`User Input`},"execution.command":{color:`text-yellow-500`,bgColor:`bg-yellow-500/20`,borderColor:`border-yellow-500`,label:`Command`}},fy=12;function py(e,t){return t===`all`||e<t}(0,v.memo)(function e({span:t,startTime:n,depth:r=0,expansionDepth:i,expansionSignal:a,expandThinking:o,onFork:s,onOpenSession:c}){let[l,u]=(0,v.useState)(()=>py(r,i)),[d,f]=(0,v.useState)(()=>t.spanType===`model.reasoning`?o:py(r,i));(0,v.useEffect)(()=>{let e=py(r,i);u(e),f(t.spanType===`model.reasoning`?o:e)},[r,i,a,o,t.spanType]),dy[t.spanType]||dy[`agent.run`],t.status,t.status,t.spanType===`user.prompt`||t.spanType;let p=!!t.children?.length;return Ey(t.startTime,n),t.durationUs?`${(t.durationUs/1e3).toFixed(1)}`:t.endTime&&`${((t.endTime-t.startTime)/1e3).toFixed(1)}`,(0,M.jsx)(my,{span:t,startTime:n,depth:r,contentExpanded:d,childrenExpanded:l,onToggle:(0,v.useCallback)(()=>{f(e=>!e),p&&u(e=>!e)},[p]),onFork:s,onOpenSession:c,childrenContent:p?t.children?.map(t=>(0,M.jsx)(e,{span:t,startTime:n,depth:r+1,expansionDepth:i,expansionSignal:a,expandThinking:o,onFork:s,onOpenSession:c},t.id)):void 0})});var my=(0,v.memo)(function({span:e,startTime:t,depth:n=0,contentExpanded:r,childrenExpanded:i,onToggle:a,onFork:o,onOpenSession:s,childrenContent:c}){let l=dy[e.spanType]||dy[`agent.run`],u=e.status===`UNSET`,d=Cy(e.status,u),f=e.spanType===`user.prompt`||e.spanType===`user_input`,p=!!e.children?.length,m=Ey(e.startTime,t),h=e.durationUs?`${(e.durationUs/1e3).toFixed(1)}ms`:e.endTime?`${((e.endTime-e.startTime)/1e3).toFixed(1)}ms`:null;return(0,M.jsx)(`div`,{className:`relative mb-4 group`,style:{marginLeft:n>0?fy:0,width:n>0?`calc(100% - ${fy}px)`:`var(--trace-readable-width)`,maxWidth:`100%`},children:(0,M.jsxs)(`div`,{className:`min-w-0 ${f?`bg-[#11a4d4]/10`:`bg-white dark:bg-[#1a262b]`} border ${d.cardClass} rounded-sm shadow-sm transition-all hover:border-opacity-70 focus:outline-none focus:ring-1 focus:ring-[#11a4d4]/50 ${u?d.glowClass:``}`,onDoubleClick:e=>{hy(e)||a()},onKeyDown:e=>{hy(e)||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},role:`button`,tabIndex:0,"aria-expanded":r,children:[(0,M.jsx)(gy,{span:e,config:l,statusStyles:d,isActive:u,contentExpanded:r,duration:h,relativeTime:m,onToggle:a,onFork:o,onOpenSession:s}),r?(0,M.jsx)(yy,{span:e}):null,p&&i&&r?(0,M.jsx)(`div`,{className:`min-w-0 border-t border-slate-700 bg-slate-900/50 py-4`,children:c}):null]})})});function hy(e){let t=e.target;if(!(t instanceof Element)||t===e.currentTarget)return!1;let n=t.closest(`button, a, input, textarea, select, summary, [role='button'], [tabindex]:not([tabindex='-1'])`);return!!(n&&n!==e.currentTarget)}function gy({span:e,config:t,statusStyles:n,isActive:r,contentExpanded:i,duration:a,relativeTime:o,onToggle:s,onFork:c,onOpenSession:l}){let u=e.spanType===`user.prompt`||e.spanType===`user_input`?`bg-[#11a4d4]/10`:n.headerClass;return(0,M.jsx)(`div`,{className:`${i?`border-b ${t.borderColor}/20`:``} ${u}`,children:(0,M.jsxs)(`div`,{className:`box-border flex w-full min-w-0 items-center`,style:{maxWidth:`100%`},children:[(0,M.jsx)(`div`,{className:`min-w-0 flex-1 px-4 py-2 text-left`,children:(0,M.jsxs)(`span`,{className:`min-w-0 text-xs font-bold ${t.color} uppercase tracking-wider flex items-center gap-2`,children:[i?(0,M.jsx)(Me,{size:12}):(0,M.jsx)(Ne,{size:12}),(0,M.jsx)(_y,{spanType:e.spanType,config:t,isActive:r}),(0,M.jsx)(`span`,{className:`shrink-0`,children:t.label}),e.name?(0,M.jsxs)(`span`,{className:`min-w-0 truncate font-normal text-slate-500 dark:text-slate-400 normal-case`,children:[`: `,e.name]}):null,r?(0,M.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}),(0,M.jsx)(by,{forkEntryId:e.pibo?.traceNodeType===`user.message`?e.pibo.entryId:void 0,linkedPiboSessionId:e.pibo?.linkedPiboSessionId,onFork:c,onOpenSession:l}),(0,M.jsx)(vy,{duration:a,relativeTime:o})]})})}function _y({spanType:e,config:t,isActive:n}){return(0,M.jsxs)(`span`,{className:`relative inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full ${t.bgColor} border-2 ${t.borderColor} ${n?`shadow-[0_0_10px_rgba(17,164,212,0.4)]`:``}`,children:[(0,M.jsx)(Sy,{type:e,className:t.color}),n?(0,M.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-1.5 w-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}function vy({duration:e,relativeTime:t}){return(0,M.jsxs)(`div`,{className:`ml-2 mr-4 flex w-36 shrink-0 items-center justify-end gap-2 font-mono tabular-nums`,children:[e?(0,M.jsx)(`span`,{className:`text-[10px] text-slate-500 dark:text-slate-400`,children:e}):null,(0,M.jsx)(`span`,{className:`text-xs text-slate-400 dark:text-slate-500`,children:t})]})}var yy=(0,v.memo)(function({span:e}){let[t,n]=(0,v.useState)(!1),{spanType:r,attributes:i,name:a}=e,o=i.content||i.input||i.output||i.message,s=i.tool_name||i.tool?.name||i[`tool.name`],c=typeof s==`string`?s:null,l=i.output||i.result||i[`tool.result`],u=i.arguments||i.args||i[`tool.arguments`],d=e.status===`ERROR`?(0,M.jsxs)(`div`,{className:`mx-4 mt-4 p-3 bg-red-500/10 border border-red-500/20 rounded-sm text-xs`,children:[(0,M.jsx)(`div`,{className:`flex items-center gap-2 font-semibold text-red-500 mb-1`,children:`Error`}),e.statusMessage?(0,M.jsx)(`div`,{className:`font-mono text-red-400 mb-2`,children:e.statusMessage}):null]}):null;if(r===`user.prompt`||r===`user_input`)return(0,M.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,M.jsx)(`div`,{className:`min-w-0 break-words p-4 font-mono text-sm text-slate-300 whitespace-pre-wrap`,children:typeof o==`string`?o:JSON.stringify(o)})]});if(r===`model.response`)return(0,M.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,M.jsx)(`div`,{className:`model-response-markdown min-w-0 p-4 text-sm text-slate-200 leading-relaxed`,children:typeof o==`string`?(0,M.jsx)(uy,{children:o}):(0,M.jsx)(Sc,{value:o})})]});if(r===`tool.result`)return(0,M.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,M.jsxs)(`div`,{className:`p-4 bg-green-500/5 border-t border-green-500/20`,children:[(0,M.jsxs)(`div`,{className:`text-xs font-medium text-green-400 mb-2`,children:[`Returned from `,c||a,`:`]}),(0,M.jsx)(Sc,{value:l??o})]})]});if(r===`tool.call`){let e=Dy(u)?u:{},r=Object.keys(e).length>0;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`p-4 bg-[#0e1116] border-b border-slate-800`,children:(0,M.jsx)(xy,{name:c??a,args:e})}),l==null?null:(0,M.jsxs)(`div`,{className:`px-4 py-2 bg-[#1a262b] flex items-center gap-2`,children:[(0,M.jsx)(Ce,{size:14,className:`text-slate-400`}),(0,M.jsx)(`span`,{className:`text-xs font-mono text-slate-500`,children:`Output:`}),(0,M.jsx)(`code`,{className:`min-w-0 max-w-md truncate text-xs font-mono text-slate-300`,children:typeof l==`string`?l.slice(0,100):JSON.stringify(l).slice(0,100)})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`w-full px-4 py-1.5 flex items-center gap-1.5 text-[11px] font-medium text-slate-400 hover:text-slate-200 bg-slate-900/40 hover:bg-slate-800/60 border-t border-slate-700/40 transition-colors`,children:[t?(0,M.jsx)(Je,{size:12}):(0,M.jsx)(Ye,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,M.jsxs)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116]`,children:[r?(0,M.jsxs)(`div`,{className:`px-4 pt-3 pb-2`,children:[(0,M.jsx)(`div`,{className:`text-[10px] font-semibold text-blue-400 uppercase tracking-wider mb-1.5`,children:`Input`}),(0,M.jsx)(Sc,{value:e})]}):null,l==null?null:(0,M.jsxs)(`div`,{className:`px-4 pt-2 pb-3 border-t border-slate-700/30`,children:[(0,M.jsx)(`div`,{className:`text-[10px] font-semibold text-green-400 uppercase tracking-wider mb-1.5`,children:`Output`}),(0,M.jsx)(Sc,{value:l})]})]}):null,d]})}if(r===`yielded.run`){let e=Dy(l)?l:Dy(o)?o:{};return(0,M.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,M.jsxs)(`div`,{className:`p-4 border-b border-[#11a4d4]/20 bg-[#11a4d4]/5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,M.jsx)(Te,{size:14,className:`text-[#11a4d4]`}),(0,M.jsx)(`span`,{className:`text-sm font-medium text-[#11a4d4]`,children:`Run notification`}),(0,M.jsx)(`span`,{className:`text-xs font-mono text-slate-400`,children:typeof i.content==`string`?i.content:a})]}),(0,M.jsx)(wy,{notification:e})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`w-full px-4 py-1.5 flex items-center gap-1.5 text-[11px] font-medium text-slate-400 hover:text-slate-200 bg-slate-900/40 hover:bg-slate-800/60 border-t border-slate-700/40 transition-colors`,children:[t?(0,M.jsx)(Je,{size:12}):(0,M.jsx)(Ye,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,M.jsx)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116] px-4 py-3`,children:(0,M.jsx)(Sc,{value:e})}):null]})}if(r===`model.reasoning`){let e=i.reasoning||i[`model.reasoning`]||o;return(0,M.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,M.jsxs)(`div`,{className:`min-w-0 break-words p-4 font-mono text-sm text-slate-300 bg-amber-500/5 leading-relaxed whitespace-pre-wrap`,children:[(0,M.jsx)(`span`,{className:`text-amber-500 opacity-60`,children:`// Model reasoning`}),(0,M.jsx)(`br`,{}),typeof e==`string`?e:JSON.stringify(e,null,2)]})]})}if(r===`agent.delegation`){let e=i[`delegation.target_agent`],t=i[`delegation.query`],n=i[`result.status`];return(0,M.jsxs)(M.Fragment,{children:[d,(0,M.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,M.jsx)(Qe,{size:14,className:`text-orange-500`}),(0,M.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Delegated to:`}),(0,M.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),n?(0,M.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-[10px] font-bold rounded-sm bg-green-500/20 text-green-500`,children:n.toUpperCase()}):null]}),t?(0,M.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,Oy(t),`"`]}):null]})]})}if(r===`agent.async`){let e=i[`async_agent.target_agent`],t=i[`async_agent.query`],n=i[`async_agent.started_by`],r=i.run_id,a=i[`result.status`];return(0,M.jsxs)(M.Fragment,{children:[d,(0,M.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-2`,children:[(0,M.jsx)(Qe,{size:14,className:`text-orange-500`}),(0,M.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Async agent started:`}),(0,M.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),a?(0,M.jsx)(`span`,{className:`px-2 py-0.5 text-[10px] font-bold rounded-sm bg-orange-500/15 text-orange-400`,children:a.toUpperCase()}):null]}),(0,M.jsxs)(`div`,{className:`mb-2 flex flex-wrap gap-x-3 gap-y-1 font-mono text-[11px] text-slate-500`,children:[(0,M.jsxs)(`span`,{children:[`Started by `,n||`pibo_run_start`]}),r?(0,M.jsx)(`span`,{children:r}):null]}),t?(0,M.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,Oy(t),`"`]}):null]})]})}return r===`agent.run`?(0,M.jsx)(`div`,{className:`flex flex-col`,children:d}):(0,M.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,M.jsx)(`div`,{className:`p-4 font-mono text-sm text-slate-300`,children:(0,M.jsx)(Sc,{value:i})})]})});function by({forkEntryId:e,linkedPiboSessionId:t,onFork:n,onOpenSession:r}){let i=e&&n?e:void 0,a=t&&r?t:void 0;return!i&&!a?null:(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[i?(0,M.jsx)(`button`,{type:`button`,onClick:()=>n?.(i),className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 bg-[#151f24]/80 text-slate-400 transition-colors hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Fork user message`,"aria-label":`Fork user message`,children:(0,M.jsx)(Qe,{size:14})}):null,a?(0,M.jsx)(`button`,{type:`button`,onClick:()=>r?.(a),className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 bg-[#151f24]/80 text-slate-400 transition-colors hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Open child session`,"aria-label":`Open child session`,children:(0,M.jsx)(qe,{size:14})}):null]})}function xy({name:e,args:t}){return(0,M.jsxs)(`code`,{className:`font-mono text-xs text-green-400`,children:[(0,M.jsx)(`span`,{className:`text-purple-400`,children:`def`}),` `,(0,M.jsx)(`span`,{className:`text-yellow-300`,children:e}),(0,M.jsxs)(`span`,{children:[`(`,Object.entries(t).map(([e,t],n)=>(0,M.jsxs)(`span`,{children:[n>0?`, `:null,(0,M.jsx)(`span`,{className:`text-blue-400`,children:e}),`=`,(0,M.jsx)(`span`,{className:`text-green-300`,children:typeof t==`string`?`'${t.slice(0,50)}${t.length>50?`...`:``}'`:Oy(t).slice(0,50)})]},e)),`)`]})]})}function Sy({type:e,className:t}){let n={size:14,className:t};switch(e){case`agent.run`:return(0,M.jsx)(ke,{...n});case`tool.call`:return(0,M.jsx)(Ee,{...n});case`tool.result`:return(0,M.jsx)(Ce,{...n});case`model.request`:return(0,M.jsx)(Oe,{...n});case`model.response`:return(0,M.jsx)(Ce,{...n});case`model.reasoning`:return(0,M.jsx)(it,{...n});case`agent.delegation`:return(0,M.jsx)(Qe,{...n});case`agent.async`:return(0,M.jsx)(Qe,{...n});case`yielded.run`:return(0,M.jsx)(Te,{...n});case`user.prompt`:return(0,M.jsx)(ct,{...n});case`user_input`:return(0,M.jsx)(_t,{...n});case`execution.command`:return(0,M.jsx)(Ee,{...n});default:return(0,M.jsx)(je,{...n})}}function Cy(e,t){return e===`ERROR`?{cardClass:`border-[#ff6b00]/50`,headerClass:`bg-[#ff6b00]/5`,glowClass:``}:e===`OK`?{cardClass:`border-[#0bda57]/30`,headerClass:`bg-[#0bda57]/5`,glowClass:``}:t?{cardClass:`border-[#11a4d4]/50`,headerClass:`bg-[#11a4d4]/5`,glowClass:`shadow-[0_0_10px_rgba(17,164,212,0.1)]`}:{cardClass:`border-slate-700`,headerClass:`bg-[#151f24]`,glowClass:``}}function wy({notification:e}){let t=[[`completed`,`text-green-500`,e.completed],[`failed`,`text-red-400`,e.failed],[`cancelled`,`text-slate-400`,e.cancelled],[`running`,`text-[#11a4d4]`,e.running]].map(([e,t,n])=>({name:e,color:t,runs:Array.isArray(n)?n.filter(Dy):[]})).filter(e=>e.runs.length>0);return t.length===0?(0,M.jsx)(`div`,{className:`text-xs text-slate-400`,children:`No yielded run updates.`}):(0,M.jsx)(`div`,{className:`grid gap-2`,children:t.map(e=>(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider ${e.color}`,children:e.name}),(0,M.jsx)(`div`,{className:`grid gap-1`,children:e.runs.map((t,n)=>(0,M.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2 rounded-sm border border-slate-700/60 bg-[#0e1116]/60 px-2 py-1.5`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate font-mono text-xs text-slate-200`,children:Ty(t.toolName)||`yielded tool`}),(0,M.jsx)(`div`,{className:`truncate font-mono text-[10px] text-slate-500`,children:Ty(t.runId)})]}),(0,M.jsx)(`div`,{className:`font-mono text-[10px] uppercase text-slate-400`,children:Ty(t.status)||e.name})]},`${e.name}-${n}`))})]},e.name))})}function Ty(e){return typeof e==`string`?e:``}function Ey(e,t){let n=(e-t)/1e3,r=Math.floor(n/6e4),i=Math.floor(n%6e4/1e3),a=Math.floor(n%1e3);return`${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}.${String(a).padStart(3,`0`)}`}function Dy(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Oy(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}var ky=5e3,Ay=50,jy=new Map;function My(e){let t=jy.get(e);return t||(t={snapshots:[],pending:null,pendingTimer:null},jy.set(e,t)),t}function Ny(){try{return localStorage.getItem(`pibo.chat.traceDebug`)===`true`}catch{return!1}}function Py(e){let t=0;for(let n of e)for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);t=(t<<5)-t+r,t|=0}return t.toString(36)}function Fy(e){if(!e.pending)return;let t=e.pending;if(t.layers.length===0){e.pending=null;return}let n=e.snapshots.at(-1);n&&n.trigger===t.trigger&&n.traceVersion===t.traceVersion&&JSON.stringify(n.layers.map(e=>e.ids))===JSON.stringify(t.layers.map(e=>e.ids))||(e.snapshots.push(t),e.snapshots.length>ky&&e.snapshots.shift()),e.pending=null}function Iy(e){if(!Ny())return;let t=My(e.piboSessionId);if(t.pendingTimer&&=(clearTimeout(t.pendingTimer),null),(!t.pending||t.pending.trigger!==e.trigger||t.pending.piboSessionId!==e.piboSessionId)&&(Fy(t),t.pending={timestamp:Date.now(),piboSessionId:e.piboSessionId,trigger:e.trigger,layers:[],expansionOverrides:e.expansionOverrides,traceVersion:e.traceVersion,latestStreamId:e.latestStreamId,lastRawEventId:e.lastRawEventId}),e.layer){let n=t.pending.layers.findIndex(t=>t.kind===e.layer.kind);n>=0?t.pending.layers[n]=e.layer:t.pending.layers.push(e.layer)}e.expansionOverrides!==void 0&&(t.pending.expansionOverrides=e.expansionOverrides),t.pendingTimer=setTimeout(()=>{Fy(t),t.pendingTimer=null},Ay)}function Ly(e,t,n,r){let i=Vy(n);Iy({piboSessionId:e,trigger:t,layer:{kind:`backendNodes`,ids:i.map(e=>e.id),digest:Py(i.map(e=>e.id)),meta:i.map(e=>({id:e.id,type:e.type,orderKey:JSON.stringify(e.orderKey),parentId:e.parentId}))},...r})}function Ry(e){let t=jy.get(e);return t?(Fy(t),t.snapshots):[]}function zy(e){if(e){let t=Ry(e);return JSON.stringify({piboSessionId:e,snapshots:t},null,2)}let t={};for(let[e,n]of jy)Fy(n),t[e]=n.snapshots;return JSON.stringify(t,null,2)}function By(e){e?jy.delete(e):jy.clear()}function Vy(e){return e.flatMap(e=>[e,...Vy(e.children??[])])}typeof window<`u`&&(window.__piboTraceSnapshots={exportAsJson:e=>{let t=zy(e),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`trace-snapshots-${e??`all`}-${Date.now()}.json`,i.click(),URL.revokeObjectURL(r)},getSnapshots:Ry,clearSnapshots:By,exportSnapshots:zy});function Hy(e){if(e==null)return{kind:`empty`};let t=Uy(e);return t===void 0?{kind:`json`,value:e}:{kind:`text`,text:t}}function Uy(e){if(typeof e==`string`)return e;if(Array.isArray(e)){let t=e.map(Uy).filter(e=>e!==void 0);return t.length===e.length&&t.length>0?t.join(``):void 0}if(!Gy(e))return;let t=typeof e.type==`string`?e.type:void 0;if(t===`text`&&typeof e.text==`string`)return e.text;if(t===`text`&&typeof e.content==`string`)return e.content;if(t===`output_text`&&typeof e.text==`string`)return e.text;let n=Uy(e.content);if(n!==void 0&&Wy(e))return n;let r=Gy(e.message)?Uy(e.message.content):void 0;if(r!==void 0)return r}function Wy(e){let t=Object.keys(e).filter(t=>e[t]!==void 0);return t.length===1&&t[0]===`content`||t.every(e=>e===`content`||e===`type`)||t.every(e=>e===`content`||e===`details`||e===`type`)?!0:typeof e.type==`string`&&e.type.includes(`text`)}function Gy(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Ky({row:e,onOpenSession:t}){return(0,M.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-details":e.kind,children:e.detailItems?.length?(0,M.jsx)(`div`,{className:`space-y-3`,children:e.detailItems.map(e=>(0,M.jsxs)(`div`,{className:`space-y-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e.label}),e.linkedPiboSessionId?(0,M.jsx)(`button`,{type:`button`,onClick:()=>t(e.linkedPiboSessionId),className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:`Open Session`}):null]}),(0,M.jsx)(qy,{label:`Input`,value:e.input}),(0,M.jsx)(qy,{label:`Output`,value:e.output}),(0,M.jsx)(Jy,{value:e.output}),e.error?(0,M.jsx)(Zy,{label:`Error`,value:e.error,tone:`red`}):null]},e.id))}):(0,M.jsxs)(`div`,{className:`space-y-3`,children:[(0,M.jsx)(qy,{label:`Input`,value:e.input}),(0,M.jsx)(qy,{label:`Output`,value:e.output}),(0,M.jsx)(Jy,{value:e.output}),e.error?(0,M.jsx)(Zy,{label:`Error`,value:e.error,tone:`red`}):null,e.linkedPiboSessionId?(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Child session`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>t(e.linkedPiboSessionId),className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e.linkedPiboSessionId})]}):null]})})}function qy({label:e,value:t}){let n=Hy(t);if(n.kind===`empty`)return null;if(n.kind===`text`){let t=Qy(n.text);return t?.kind===`json`?(0,M.jsx)(Xy,{label:e,value:t.value,meta:t.meta}):t?.kind===`text`?(0,M.jsx)(Zy,{label:e,value:t.text}):(0,M.jsx)(Zy,{label:e,value:n.text})}return(0,M.jsx)(Xy,{label:e,value:n.value})}function Jy({value:e}){let t=Yy(e);return t?(0,M.jsxs)(`details`,{className:`space-y-1 border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:[(0,M.jsxs)(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-[#38bdf8]`,children:[`Show full output (`,t.originalLines,` lines)`]}),t.fullOutput?(0,M.jsx)(`pre`,{className:`mt-2 max-h-[520px] overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-[1.45] text-[#d4d4d4]`,children:t.fullOutput}):t.fullOutputPath?(0,M.jsxs)(`div`,{className:`mt-2 min-w-0 break-words font-mono text-[12px] text-[#d4d4d4]`,children:[`Full output file: `,t.fullOutputPath]}):null]}):null}function Yy(e){if(!tb(e))return;let t=tb(e.details)?e.details.piboBashOutputCompaction:void 0;if(!tb(t)||t.kind!==`validation-output`)return;let n=typeof t.originalLines==`number`?t.originalLines:void 0;if(n!==void 0)return{originalLines:n,fullOutput:typeof t.fullOutput==`string`?t.fullOutput:void 0,fullOutputPath:typeof t.fullOutputPath==`string`?t.fullOutputPath:void 0}}function Xy({label:e,value:t,meta:n}){return(0,M.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-json":e,children:[(0,M.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),n?(0,M.jsxs)(`div`,{className:`min-w-0 break-words text-[11px] text-[#737373]`,children:[`Status: `,n]}):null]}),(0,M.jsx)(`div`,{className:`compact-terminal-json border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:(0,M.jsx)(Sc,{value:t,showControls:!1})})]})}function Zy({label:e,value:t,tone:n=`default`}){return(0,M.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-text":e,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),(0,M.jsx)(`pre`,{className:`m-0 whitespace-pre-wrap break-words border border-[#2a2a2a] bg-[#0b0b0b] p-2 font-mono text-[12px] leading-[1.45] ${n===`red`?`text-[#ef4444]`:`text-[#d4d4d4]`}`,children:t})]})}function Qy(e){let t=e.trim();if(!t)return;let n=eb(t);if(n!==void 0)return $y(n);let r=t.split(/\r?\n/);for(let e=1;e<r.length;e+=1){let t=r.slice(e).join(`
39
- `).trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))continue;let n=eb(t);if(n!==void 0)return $y(n,r.slice(0,e).join(` `).trim()||void 0)}}function $y(e,t){let n=Hy(e);if(n.kind===`text`){let e=Qy(n.text);return e?.kind===`json`?{...e,meta:e.meta??t}:{kind:`text`,text:n.text}}return{kind:`json`,value:e,meta:t}}function eb(e){if(!(!e.startsWith(`{`)&&!e.startsWith(`[`)))try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}function tb(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function nb({name:e,input:t}){return(0,M.jsxs)(`span`,{className:`compact-terminal-function-call`,children:[(0,M.jsx)(`span`,{className:`text-[#facc15] font-semibold`,children:e}),(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`(`}),t===void 0?null:(0,M.jsx)(rb,{value:t}),(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`)`})]})}function rb({value:e}){let[t,n]=(0,v.useState)(()=>new Set([`$`])),[r,i]=(0,v.useState)(()=>new Set);return(0,M.jsx)(ib,{value:e,path:`$`,expandedPaths:t,expandedStrings:r,onTogglePath:e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onToggleString:e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}})}function ib({value:e,path:t,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a}){if(Array.isArray(e))return(0,M.jsx)(ab,{value:e,path:t,open:`[`,close:`]`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(sb(e))return(0,M.jsx)(ab,{value:e,path:t,open:`{`,close:`}`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(typeof e==`string`){let n=r.has(t),i=e.length>140&&!n,o=i?`${e.slice(0,140)}...`:e,s=(0,M.jsx)(`span`,{className:`text-[#fb923c]`,children:JSON.stringify(o)});return!i&&e.length<=140?s:(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a(t)},className:`compact-terminal-json-toggle text-left align-baseline`,title:n?`Collapse string`:`Expand string`,children:s})}return typeof e==`number`||typeof e==`boolean`||e===null?(0,M.jsx)(`span`,{className:`text-[#60a5fa]`,children:String(e)}):(0,M.jsx)(`span`,{className:`text-[#737373]`,children:JSON.stringify(String(e))})}function ab({value:e,path:t,open:n,close:r,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s}){let c=Array.isArray(e)?e.map((e,t)=>[String(t),e]):Object.entries(e);return i.has(t)?(0,M.jsxs)(`span`,{children:[(0,M.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Collapse JSON`,"aria-label":`Collapse JSON at ${t}`,"data-inline-json-path":t,children:[(0,M.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▾`}),n]}),c.map(([n,r],c)=>{let l=`${t}.${ob(n)}`;return(0,M.jsxs)(`span`,{children:[c>0?(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`, `}):null,Array.isArray(e)?null:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:JSON.stringify(n)}),(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`:`})]}),(0,M.jsx)(ib,{value:r,path:l,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s})]},l)}),(0,M.jsx)(`span`,{className:`text-[#737373]`,children:r})]}):(0,M.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Expand JSON`,"aria-label":`Expand JSON at ${t}`,"data-inline-json-path":t,children:[(0,M.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▸`}),n,`...`,r]})}function ob(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`.`,`\\.`)}function sb(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function cb({line:e,status:t,clampLines:n}){let r=`min-w-0 whitespace-pre-wrap break-words ${n?`block overflow-hidden`:``}`;return(0,M.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,M.jsx)(`span`,{className:`whitespace-pre ${ub(e.prefix,t)}`,children:lb(e.prefix)}),(0,M.jsxs)(`span`,{className:r,style:n?{maxHeight:`${n*1.45}em`}:void 0,children:[e.tokens.map((e,t)=>(0,M.jsx)(`span`,{className:db(e),children:e.text},`${t}:${e.text}`)),e.functionCall?(0,M.jsx)(nb,{name:e.functionCall.name,input:e.functionCall.input}):null]})]})}function lb(e=`none`){switch(e){case`bullet`:return`•`;case`detail`:return`└`;case`continuation`:return` `;case`prompt`:return`›`;default:return` `}}function ub(e=`none`,t){if(e===`bullet`){if(t===`running`)return`text-[#38bdf8]`;if(t===`error`)return`text-[#ef4444]`;if(t===`done`)return`text-[#22c55e]`}return`text-[#737373]`}function db(e){return`${e.tone===`dim`?`text-[#737373]`:e.tone===`cyan`?`text-[#38bdf8]`:e.tone===`green`?`text-[#22c55e]`:e.tone===`red`?`text-[#ef4444]`:e.tone===`magenta`?`text-[#d946ef]`:e.tone===`yellow`?`text-[#facc15]`:e.tone===`blue`?`text-[#60a5fa]`:e.tone===`amber`?`text-[#f59e0b]`:`text-[#d4d4d4]`} ${e.weight===`bold`?`font-bold`:e.weight===`semibold`?`font-semibold`:`font-normal`} ${e.italic?`italic`:``}`.trim()}async function fb(e,t){let n=new URLSearchParams({piboSessionId:e}),r=await fetch(`/api/chat/trace/summary?${n.toString()}`,{headers:t?{"if-none-match":mb(t)}:void 0});if(r.status===304)return{notModified:!0,version:hb(r.headers.get(`etag`))??t};let i=await r.json().catch(()=>void 0);if(!r.ok){let e=i&&typeof i==`object`&&`error`in i?String(i.error):`Request failed`,t=Error(e);throw t.status=r.status,t.data=i,t}return{summary:i,notModified:!1,version:hb(r.headers.get(`etag`))??i.version}}async function pb(e,t={}){let n=new URLSearchParams({piboSessionId:e});t.includeRawEvents&&n.set(`includeRawEvents`,`true`),t.rawEventsLimit&&n.set(`rawEventsLimit`,String(t.rawEventsLimit)),t.pageSize&&n.set(`pageSize`,String(t.pageSize)),t.beforeSequence===void 0?t.eventLimit&&n.set(`eventLimit`,String(t.eventLimit)):n.set(`beforeSequence`,String(t.beforeSequence));let r=await fetch(`/api/chat/trace?${n.toString()}`,{headers:t.knownVersion?{"if-none-match":mb(t.knownVersion)}:void 0});if(r.status===304)return{notModified:!0,version:hb(r.headers.get(`etag`))??t.knownVersion};let i=await r.json().catch(()=>void 0);if(!r.ok){let e=i&&typeof i==`object`&&`error`in i?String(i.error):`Request failed`,t=Error(e);throw t.status=r.status,t.data=i,t}return{trace:i,notModified:!1,version:hb(r.headers.get(`etag`))??i.version}}function mb(e){return`"${e}"`}function hb(e){if(!e)return;let t=e.trim();return t.startsWith(`W/`)?hb(t.slice(2)):t.startsWith(`"`)&&t.endsWith(`"`)?t.slice(1,-1):t}async function gb(e,t={}){let n=new URLSearchParams({piboSessionId:e});return t.status&&n.set(`status`,t.status),t.limit&&n.set(`limit`,String(t.limit)),t.scope&&n.set(`scope`,t.scope),O(`/api/web-annotations?${n.toString()}`)}async function _b(e,t){return O(`/api/web-annotations/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(xb(t))})}async function vb(e){let t=new URLSearchParams;return e?.trim()&&t.set(`cdpUrl`,e.trim()),O(`/api/web-annotations/targets${t.size?`?${t.toString()}`:``}`)}async function yb(e){return O(`/api/web-annotations/bindings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(xb(e))})}async function bb(e,t){return O(`/api/web-annotations/bindings/${encodeURIComponent(e)}/inject`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(xb(t))})}function xb(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``))}async function Sb(e,t,n){return O(`/api/chat/projects/${encodeURIComponent(e)}/workflow-sessions/${encodeURIComponent(t)}/human-actions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)})}function Cb(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function wb(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function Tb(e){return Eb(e)?e.result:e}function Eb(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}var Db={device_code:`Device code`,api_key:`API key`,oauth:`Browser OAuth`};function Ob({row:e,piboSessionId:t}){let n=Cb(e.output)?e.output:void 0,r=(0,v.useMemo)(()=>n?.providers??[],[n?.providers]),[i,a]=(0,v.useState)({type:`select_provider`}),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(null),m=(0,v.useCallback)(()=>{a({type:`select_provider`}),l(``),d(``)},[]),h=(0,v.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),p(e),window.setTimeout(()=>p(t=>t===e?null:t),1600)}catch{}},[]),g=(0,v.useCallback)(async e=>{if(!t){a({type:`error`,provider:e,message:`Select a chat session before starting login.`});return}s(!0),a({type:`device_starting`,provider:e});try{let n=Tb(await oe(t,`login.start`,{provider:e.id}));if(!n?.url){a({type:`error`,provider:e,message:`No login URL returned.`});return}a({type:`device_flow`,provider:e,url:n.url,state:n.state,userCode:n.userCode,instructions:n.instructions})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t]),_=(0,v.useCallback)(async(e,n,r)=>{if(t){s(!0);try{await oe(t,`login.complete`,{provider:e.id,state:n??``,...r?{code:r}:{}}),a({type:`success`,provider:e,message:`${e.name} login completed.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[t]),y=(0,v.useCallback)(async e=>{if(!t)return;let n=c.trim();if(n){s(!0);try{await oe(t,`login.apikey`,{provider:e.id,apiKey:n}),l(``),a({type:`success`,provider:e,message:`${e.name} API key saved.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[c,t]);return n?(0,M.jsx)(kb,{title:i.type===`select_provider`?`Login`:Mb(i),tone:i.type===`error`?`red`:i.type===`success`?`green`:`cyan`,action:i.type===`select_provider`?void 0:(0,M.jsx)(Ab,{onClick:m,disabled:o}),children:i.type===`select_provider`?(0,M.jsxs)(`div`,{className:`grid gap-2`,children:[(0,M.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a provider. Use `,(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` anytime.`]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>a({type:`select_method`,provider:e}),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[(0,M.jsx)(`span`,{children:e.name}),e.configured?(0,M.jsx)(`span`,{className:`text-[#22c55e]`,children:`●`}):null]},e.id))})]}):i.type===`select_method`?(0,M.jsxs)(`div`,{className:`grid gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Provider:`}),(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.provider.name}),i.provider.configured?(0,M.jsx)(jb,{tone:`green`,children:`Configured`}):(0,M.jsx)(jb,{tone:`neutral`,children:`Not configured`})]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.provider.authMethods.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>e===`api_key`?a({type:`api_key`,provider:i.provider}):void g(i.provider),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[e===`api_key`?(0,M.jsx)(nt,{size:11}):(0,M.jsx)(st,{size:11}),Db[e]]},e))})]}):i.type===`device_starting`?(0,M.jsxs)(`div`,{className:`inline-flex items-center gap-2 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(ot,{size:13,className:`animate-spin`}),` Starting device login...`]}):i.type===`device_flow`?(0,M.jsxs)(`div`,{className:`grid gap-2 text-[11px]`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Open:`}),(0,M.jsxs)(`a`,{href:i.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[#38bdf8] hover:underline`,children:[Nb(i.url),` `,(0,M.jsx)(qe,{size:11})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>void h(i.url),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[f===i.url?(0,M.jsx)(Be,{size:10}):(0,M.jsx)(We,{size:10}),` `,f===i.url?`Copied`:`Copy`]})]}),i.userCode?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Code:`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void h(i.userCode),className:`border border-[#1f4960] px-2 py-0.5 font-semibold tracking-widest text-[#38bdf8] hover:border-[#38bdf8]`,children:i.userCode}),(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`then`}),(0,M.jsxs)(`button`,{type:`button`,disabled:o,onClick:()=>void _(i.provider,i.state),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-0.5 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,M.jsx)(ot,{size:11,className:`animate-spin`}):(0,M.jsx)(Be,{size:11}),` Complete`]})]}):(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,M.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),placeholder:`authorization code`,className:`min-w-0 flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,M.jsxs)(`button`,{type:`button`,disabled:o||!u.trim(),onClick:()=>void _(i.provider,i.state,u.trim()),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,M.jsx)(ot,{size:11,className:`animate-spin`}):(0,M.jsx)(Be,{size:11}),` Complete`]})]}),i.instructions?(0,M.jsx)(`div`,{className:`text-[#737373]`,children:i.instructions}):null]}):i.type===`api_key`?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`API key:`}),(0,M.jsx)(`input`,{type:`password`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y(i.provider)},placeholder:`sk-...`,className:`min-w-[12rem] flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,M.jsxs)(`button`,{type:`button`,disabled:o||!c.trim(),onClick:()=>void y(i.provider),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,M.jsx)(ot,{size:11,className:`animate-spin`}):(0,M.jsx)(Be,{size:11}),` Save`]})]}):i.type===`success`?(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-[#22c55e]`,children:[(0,M.jsx)(Be,{size:13}),` `,i.message]}):(0,M.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-[#ef4444]`,children:[(0,M.jsx)(Re,{size:13,className:`mt-0.5 shrink-0`}),` `,(0,M.jsx)(`span`,{children:i.message})]})}):(0,M.jsx)(kb,{title:`Login`,tone:`red`,children:`Unparseable login payload.`})}function kb({title:e,tone:t,action:n,children:r}){return(0,M.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`login`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,M.jsx)(st,{size:14,className:t===`red`?`text-[#ef4444]`:t===`green`?`text-[#22c55e]`:`text-[#38bdf8]`}),(0,M.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e}),n?(0,M.jsx)(`div`,{className:`ml-auto`,children:n}):null]}),r]})}function Ab({onClick:e,disabled:t}){return(0,M.jsxs)(`button`,{type:`button`,disabled:t,onClick:e,className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-1.5 py-0.5 text-[11px] text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[(0,M.jsx)(we,{size:10}),` Back`]})}function jb({tone:e,children:t}){return(0,M.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[10px] ${e===`green`?`border-[#14532d] text-[#22c55e]`:`border-[#3a3a3a] text-[#737373]`}`,children:t})}function Mb(e){return`provider`in e&&e.provider?e.provider.name:`Login`}function Nb(e){try{let t=new URL(e);return`${t.host}${t.pathname}`}catch{return e.length>42?`${e.slice(0,39)}...`:e}}function Pb({row:e,piboSessionId:t,onModelChanged:n}){let r=Tb(e.output),i=(wb(r)?r:void 0)?.providers??[],a=(0,v.useMemo)(()=>i.flatMap(e=>e.models.map(t=>({...t,providerLabel:e.label}))),[i]),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=(0,v.useMemo)(()=>{let e=o.trim().toLowerCase();return e?a.filter(t=>`${t.providerLabel} ${t.provider} ${t.label} ${t.id}`.toLowerCase().includes(e)):a},[a,o]),h=async e=>{if(!(!t||u)){d(!0),l(e),p(null);try{await re(t,{activeModel:{provider:e.provider,id:e.id}}),p(`Selected ${e.provider}/${e.id}.`),await n?.()}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}};return(0,M.jsxs)(`div`,{className:`ml-[1.9rem] max-w-3xl border border-[#3a3a3a] bg-[#111111] text-[12px] shadow-lg`,"data-shared-terminal-card":`model`,children:[(0,M.jsx)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[#2a2a2a] px-3 py-2`,children:(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`text-[#d4d4d4]`,children:`Model`}),(0,M.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a model from authenticated providers. Use `,(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` to add providers.`]})]})}),(0,M.jsxs)(`div`,{className:`space-y-2 p-3`,children:[i.length?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`label`,{className:`flex items-center gap-2 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[#737373]`,children:[(0,M.jsx)(pt,{size:13}),(0,M.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),placeholder:`Search models`,className:`min-w-0 flex-1 bg-transparent text-[#d4d4d4] outline-none placeholder:text-[#525252]`})]}),(0,M.jsx)(`div`,{className:`max-h-72 overflow-auto border border-[#2a2a2a]`,children:m.length?m.map(e=>(0,M.jsxs)(`button`,{type:`button`,disabled:u,onClick:()=>void h(e),className:`grid w-full grid-cols-[150px_1fr_auto] gap-2 border-b border-[#1f1f1f] px-3 py-2 text-left hover:bg-[#38bdf8]/10 disabled:opacity-50`,children:[(0,M.jsx)(`span`,{className:`truncate text-[#737373]`,children:e.providerLabel}),(0,M.jsxs)(`span`,{className:`min-w-0`,children:[(0,M.jsx)(`span`,{className:`block truncate text-[#d4d4d4]`,children:e.label}),(0,M.jsxs)(`span`,{className:`block truncate text-[11px] text-[#737373]`,children:[e.provider,`/`,e.id]})]}),c?.provider===e.provider&&c?.id===e.id?(0,M.jsx)(je,{size:14,className:`text-[#22c55e]`}):null]},`${e.provider}:${e.id}`)):(0,M.jsx)(`div`,{className:`px-3 py-2 text-[#737373]`,children:`No matching models.`})})]}):(0,M.jsxs)(`div`,{className:`text-[#737373]`,children:[`No authenticated model providers found. Run `,(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` first.`]}),f?(0,M.jsx)(`div`,{className:`text-[11px] text-[#a3a3a3]`,children:f}):null]})]})}function Fb(e={}){let t=[],n=[],r=Hb(e.warnings),i=Hb(e.errors);(e.session?.id||e.session?.title)&&t.push({id:`session`,label:`Session`,value:Ib([e.session?.title,e.session?.id].filter(Boolean).join(` | `))}),e.session?.profile&&t.push({id:`profile`,label:`Profile`,value:Ib(e.session.profile)}),e.session?.status&&t.push({id:`session-status`,label:`Session status`,value:Ib(e.session.status),tone:e.session.status===`error`||e.session.status===`disposed`?`red`:`neutral`}),(e.model?.provider||e.model?.id||e.model?.label)&&t.push({id:`model`,label:`Model`,value:Ib(e.model.label??[e.model.provider,e.model.id].filter(Boolean).join(`/`))}),e.runtime?.state&&t.push({id:`runtime`,label:`Runtime`,value:Ib(e.runtime.state),tone:e.runtime.connected===!1||e.runtime.disposed?`red`:`green`}),e.runtime?.disposed!==void 0&&t.push({id:`disposed`,label:`Disposed`,value:e.runtime.disposed?`yes`:`no`,tone:e.runtime.disposed?`red`:`neutral`}),typeof e.runtime?.queuedMessages==`number`&&t.push({id:`queue`,label:`Queue`,value:String(e.runtime.queuedMessages)}),e.runtime?.processing!==void 0&&t.push({id:`processing`,label:`Processing`,value:e.runtime.processing?`yes`:`no`,tone:e.runtime.processing?`cyan`:`neutral`}),e.runtime?.streaming!==void 0&&t.push({id:`streaming`,label:`Streaming`,value:e.runtime.streaming?`yes`:`no`,tone:e.runtime.streaming?`cyan`:`neutral`}),e.cwd&&t.push({id:`cwd`,label:`CWD`,value:Ib(e.cwd)});let a=typeof e.thinking==`string`?{level:e.thinking}:e.thinking;(a?.level||a?.supported!==void 0)&&t.push({id:`thinking`,label:`Thinking`,value:Ib(a.level??(a.supported===!1?`unsupported`:`available`)),tone:a.supported===!1?`red`:`yellow`}),e.fastMode!==void 0&&t.push({id:`fast-mode`,label:`Fast mode`,value:typeof e.fastMode==`string`?Ib(e.fastMode):e.fastMode?`on`:`off`,tone:e.fastMode?`green`:`neutral`});let o=Hb(e.tools?.enabled),s=Hb(e.tools?.active);o.length&&t.push({id:`enabled-tools`,label:`Enabled tools`,value:`${o.length}${o.length<=4?` (${o.join(`, `)})`:``}`}),s.length&&t.push({id:`active-tools`,label:`Active tools`,value:`${s.length}${s.length<=4?` (${s.join(`, `)})`:``}`,tone:`cyan`}),e.providerUsage?.planType&&t.push({id:`provider-plan`,label:`Provider plan`,value:Ib(e.providerUsage.planType)}),e.providerUsage?.credits&&t.push({id:`provider-credits`,label:`Credits`,value:e.providerUsage.credits.unlimited?`unlimited`:Ib(e.providerUsage.credits.balance??`available`)}),e.message&&t.push({id:`message`,label:`Message`,value:Ib(e.message)}),n.push(Lb(e.contextUsage));for(let t of Rb(e.providerUsage))n.push(t);return{kind:`status`,title:`Status`,fields:t,progress:n,warnings:r,errors:i}}function Ib(e){return e.replace(/\b([A-Z0-9_]*(?:API[_-]?KEY|TOKEN|SECRET|PASSWORD)[A-Z0-9_]*)\s*=\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(api[_-]?key|token|secret|password)\s*[:=]\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(?:sk|pk|pibo|ghp|github_pat)_[A-Za-z0-9_\-]{8,}\b/g,`[redacted]`)}function Lb(e){if(!e||e.tokens===void 0&&e.contextWindow===void 0&&e.percent===void 0)return{id:`context`,label:`Context`,state:`unavailable`,text:`Context usage unavailable`,tone:`neutral`};let t=zb(e.percent??(e.tokens!==void 0&&e.contextWindow?e.tokens/e.contextWindow*100:void 0));return{id:`context`,label:`Context`,state:t===void 0?`unavailable`:`available`,value:e.tokens,max:e.contextWindow,percent:t,text:t===void 0?`Context usage unavailable`:`${e.tokens??`?`}/${e.contextWindow??`?`} tokens (${t.toFixed(1)}%)`,tone:Bb(t)}}function Rb(e){return e?.limits?.length?e.limits.map((t,n)=>{let r=zb(t.usedPercent),i=zb(t.remainingPercent??(r===void 0?void 0:100-r)),a=e.provider?`${e.provider} `:``,o=[i===void 0?void 0:`${i.toFixed(1)}% remaining`,t.resetsAt?`resets ${Ib(t.resetsAt)}`:void 0].filter(Boolean).join(`, `);return{id:`provider-${n}`,label:`${a}${t.label??`quota`}`.trim(),state:i===void 0?`unavailable`:`available`,percent:i,text:i===void 0?`Provider usage unavailable`:o,tone:Vb(i)}}):[{id:`provider`,label:`Provider quota`,state:`unavailable`,text:`Provider usage unavailable`,tone:`neutral`}]}function zb(e){if(!(typeof e!=`number`||!Number.isFinite(e)))return Math.max(0,Math.min(100,e))}function Bb(e){return e===void 0?`neutral`:e>=80?`red`:e>=50?`yellow`:`green`}function Vb(e){return e===void 0?`neutral`:e<=20?`red`:e<=50?`yellow`:`green`}function Hb(e){return(e??[]).map(e=>Ib(e)).filter(e=>e.length>0)}function Ub(e){switch(e.kind){case`tool.status`:return Wb(e);case`tool.thinking`:return Gb(e);case`tool.model`:return Kb(e);case`tool.login`:return qb(e);case`tool.call`:case`tool.image`:case`tool.group.exploring`:case`tool.group.images`:return Jb(e);case`yielded.run`:return Yb(e,`yielded-run`,`Yielded run`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`);case`execution.compaction`:return Yb(e,`compaction`,e.status===`error`?`Compaction failed`:e.status===`running`?`Compacting`:`Compaction`,e.status===`error`?`red`:`magenta`);case`execution.command`:return Yb(e,`command`,`Command`,e.status===`error`?`red`:`yellow`);case`error`:return Yb(e,`error`,`Error`,`red`);default:return}}function Wb(e){let t=Zb(e.output),n=Qb(t,`activeModel`)??Qb(t,`model`),r=Fb({session:{id:tx(t,`piboSessionId`)??tx(t,`sessionId`),title:tx(t,`sessionTitle`)??tx(t,`title`),profile:tx(t,`profile`)??tx(t,`activeAgentId`)??tx(t,`agentId`),status:rx(t,`disposed`)?`disposed`:tx(t,`sessionStatus`)},model:n?{provider:tx(n,`provider`),id:tx(n,`id`),label:tx(n,`label`)}:void 0,runtime:{state:rx(t,`disposed`)?`disposed`:rx(t,`processing`)?`processing`:rx(t,`streaming`)?`streaming`:tx(t,`mode`)??`idle`,connected:rx(t,`connected`),queuedMessages:nx(t,`queuedMessages`),processing:rx(t,`processing`),streaming:rx(t,`streaming`),disposed:rx(t,`disposed`)},cwd:tx(t,`cwd`),contextUsage:Qb(t,`contextUsage`),providerUsage:Qb(t,`providerUsage`),tools:{enabled:ex(t,`enabledTools`),active:ex(t,`activeTools`)},thinking:tx(t,`thinkingLevel`)?{level:tx(t,`thinkingLevel`)}:void 0,fastMode:rx(t,`fastMode`),warnings:ex(t,`warnings`),errors:ex(t,`errors`),message:tx(t,`message`)});return{id:e.id,kind:`status`,title:`Status`,status:e.status,tone:e.status===`error`?`red`:`green`,rows:r.fields.map(e=>({label:e.label,value:e.value,tone:e.tone})),statusView:r,sourceRowKind:e.kind}}function Gb(e){let t=Zb(e.output),n=tx(t,`level`)??`unknown`,r=t?.supported!==!1,i=ex(t,`availableLevels`);return{id:e.id,kind:`thinking`,title:`Thinking`,status:e.status,tone:r?`yellow`:`red`,rows:[{label:`Current`,value:Ib(n)},{label:`Supported`,value:r?`yes`:`no`,tone:r?`green`:`red`}],actions:i.map(e=>({id:`thinking:${e}`,label:e,action:`thinking.set`,value:e,disabled:!r})),sourceRowKind:e.kind}}function Kb(e){let t=$b(Zb(e.output),`providers`),n=t.flatMap(e=>{let t=tx(e,`id`)??tx(e,`provider`)??`provider`,n=tx(e,`label`)??tx(e,`name`)??t;return $b(e,`models`).map(e=>{let r=tx(e,`id`)??`model`,i=tx(e,`label`)??r;return{id:`model:${t}:${r}`,label:`${n} / ${i}`,action:`model.select`,value:`${t}/${r}`}})});return{id:e.id,kind:`model`,title:`Model`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)},{label:`Models`,value:String(n.length)}],actions:n,sourceRowKind:e.kind}}function qb(e){let t=$b(Zb(e.output),`providers`),n=t.map(e=>{let t=tx(e,`id`)??`provider`;return{id:`login:${t}`,label:tx(e,`name`)??tx(e,`label`)??t,action:`login.selectProvider`,value:t,description:ex(e,`authMethods`).join(`, `)}});return{id:e.id,kind:`login`,title:`Login`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)}],actions:n,sourceRowKind:e.kind}}function Jb(e){return Yb(e,`tool`,e.kind===`tool.group.exploring`?`Exploring`:e.kind===`tool.image`||e.kind===`tool.group.images`?`Image`:`Tool`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`)}function Yb(e,t,n,r){let i=e.lines.flatMap(e=>{let t=`${e.tokens.map(e=>e.text).join(``)}${e.functionCall?`${e.functionCall.name}${e.functionCall.input===void 0?``:` ${Xb(e.functionCall.input)}`}`:``}`.trim();return t?[{value:Ib(t)}]:[]}),a=e.lines.length===0&&typeof e.output==`string`&&e.output.trim()?[{value:Ib(e.output.trim())}]:[],o=[e.error?{label:`Error`,value:Ib(e.error),tone:`red`}:void 0].filter(e=>!!e);return{id:e.id,kind:t,title:n,status:e.status,tone:r,rows:[...i,...a,...o],sourceRowKind:e.kind}}function Xb(e){try{return JSON.stringify(e)}catch{return String(e)}}function Zb(e){if(e){if(typeof e==`string`)try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}catch{return}return typeof e==`object`&&!Array.isArray(e)?e:void 0}}function Qb(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function $b(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)):[]}function ex(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function tx(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function nx(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function rx(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}var ix={transcript:0,"event-log":1,live:2},ax={"user.message":0,"execution.command":1,"execution.compaction":1,"agent.turn":2,"model.reasoning":3,"tool.call":4,"agent.delegation":4,"agent.async":5,"tool.result":6,"yielded.run":7,"assistant.message":8,error:9};function ox(e,t){return{sourceRank:ix[`event-log`],turnSeq:e??2**53-1,eventSequence:e,phaseRank:ax[t]}}function sx(e,t,n){let r=e??2**53-1,i=t??2**53-1;return{sourceRank:ix.live,turnSeq:r,streamId:r,streamFrameIndex:i,phaseRank:ax[n]}}function cx(e){let[t,n]=e.split(`:`);if(t===void 0||n===void 0)return;let r=Number(t),i=Number(n);if(!(!Number.isInteger(r)||r<0)&&!(!Number.isInteger(i)||i<0))return{streamId:r,frameIndex:i}}function lx(e,t){if(e)return{...e,contentPartIndex:(e.contentPartIndex??0)+.1,phaseRank:ax[t]}}function ux(e,t){return!e&&!t?0:e?t?e.sourceRank-t.sourceRank||e.turnSeq-t.turnSeq||(e.transcriptIndex??2**53-1)-(t.transcriptIndex??2**53-1)||(e.eventSequence??2**53-1)-(t.eventSequence??2**53-1)||(e.streamId??2**53-1)-(t.streamId??2**53-1)||(e.streamFrameIndex??2**53-1)-(t.streamFrameIndex??2**53-1)||(e.contentPartIndex??0)-(t.contentPartIndex??0)||e.phaseRank-t.phaseRank:-1:1}function dx(e){let t=!1,n=e.map(e=>e.children.length?(t=!0,{...e,children:dx(e.children)}):e);return fx(n)?t?n:[...e]:[...n].sort(px)}function fx(e){for(let t=1;t<e.length;t+=1)if(px(e[t-1],e[t])>0)return!1;return!0}function px(e,t){let n=mx(e.startedAt,t.startedAt);if(n!==0)return n;let r=ux(e.orderKey,t.orderKey);return r===0?e.id.localeCompare(t.id):r}function mx(e,t){return!e&&!t?0:e?t?e.localeCompare(t):-1:1}function hx(e){let t=[],n=[...e].reverse();for(;n.length;){let e=n.pop();if(e){t.push(e);for(let t=e.children.length-1;t>=0;--t)n.push(e.children[t])}}return t}function gx(e,t,n,r){if(!_x(t))return;let i=r.get(e)?.filter(e=>e.metadata?.subagentToolName===t)??[],a=yx(n);return a?i.find(e=>e.metadata?.threadKey===a)?.id:i.length===1?i[0].id:void 0}function _x(e){return e.startsWith(`pibo_subagent_`)}function vx(e){return e.slice(14)}function yx(e){let t=`args`in e&&e.args&&typeof e.args==`object`&&!Array.isArray(e.args)?e.args:void 0,n=t&&`threadKey`in t?t.threadKey:void 0;return typeof n==`string`&&n.trim()?n.trim():void 0}function bx(e,t,n,r){let i=Sx(e,t,n,r);if(!i)return;let a=e.children.find(e=>e.id===i.id);if(a){wx(a,i),a.runId=i.runId??a.runId;return}e.children.push(i)}function xx(e){let t=new Map;for(let n of hx(e)){let e=Tx(n.output);if(!e)continue;let r=Dx(e.runId);r&&t.set(r,{snapshot:e,completedAt:Dx(e.completedAt)??Dx(e.updatedAt)??n.completedAt})}for(let n of hx(e)){if(n.type!==`agent.async`||!n.runId)continue;let e=t.get(n.runId);if(!e)continue;let r=Dx(e.snapshot.status);r!==`completed`&&r!==`cancelled`&&r!==`failed`||(n.status=r===`failed`?`error`:`done`,n.completedAt=e.completedAt??n.completedAt,n.output=e.snapshot,r===`failed`&&(n.error=Dx(e.snapshot.summary)??n.error))}}function Sx(e,t,n,r){if(!Cx(e))return;let i=Tx(e.output),a=kx(e.input)?e.input:{},o=Dx(i?.toolName)??Dx(a.toolName)??r?.title;if(!o||!_x(o))return;let s=Dx(r?.summary)??vx(o),c=Dx(i?.runId),l=Dx(i?.status),u=a.arguments,d=Dx(i?.completionPolicy)??Dx(a.completionPolicy);return{id:`${e.id}:async-agent`,parentId:e.id,piboSessionId:t,eventId:e.eventId,toolCallId:e.toolCallId,runId:c,type:`agent.async`,title:s,status:Ox(e,l),startedAt:r?.startedAt??n??e.startedAt,completedAt:l===`completed`||l===`cancelled`?e.completedAt:void 0,summary:`Started by ${e.title}`,input:{startedBy:e.title,startToolCallId:e.toolCallId,toolName:o,subagentName:s,runId:c,completionPolicy:d,arguments:u,threadKey:kx(r?.input)?r.input.threadKey:void 0},output:i,error:e.error,linkedPiboSessionId:r?.linkedPiboSessionId??e.linkedPiboSessionId,source:e.source,stableKey:c?`async-agent:${c}`:`${e.stableKey??e.id}:async-agent`,orderKey:lx(e.orderKey,`agent.async`),children:[]}}function Cx(e){return e.type===`tool.call`&&e.title===`pibo_run_start`}function wx(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt,e.linkedPiboSessionId=t.linkedPiboSessionId??e.linkedPiboSessionId}function Tx(e){if(kx(e)){if(Ex(e))return e;if(kx(e.details)&&Ex(e.details))return e.details}}function Ex(e){return typeof e.runId==`string`&&typeof e.toolName==`string`}function Dx(e){return typeof e==`string`?e:void 0}function Ox(e,t){return e.status===`error`||t===`failed`?`error`:t===`completed`||t===`cancelled`?`done`:`running`}function kx(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Ax(e){let t=(e??``).trim();if(!t.startsWith(`<pibo_run_notification>`)||!t.endsWith(`</pibo_run_notification>`))return;let n=t.slice(23,t.length-24).trim();try{let e=JSON.parse(n);return!e||typeof e!=`object`||Array.isArray(e)?void 0:e}catch{return}}function jx(e){let t=Mx(e.notification),n=t.length===1?t[0]:void 0,r=Px(e.notification.failed),i=Px(e.notification.running);return{id:e.id,entryId:e.entryId,piboSessionId:e.piboSessionId,eventId:e.eventId,runId:typeof n?.runId==`string`?n.runId:void 0,type:`yielded.run`,title:`Run Notification`,status:r>0?`error`:i>0?`running`:`done`,startedAt:e.startedAt,summary:Fx(e.notification),output:e.notification,source:e.source,stableKey:e.stableKey??e.id,orderKey:e.orderKey,children:[]}}function Mx(e){return[...Nx(e.completed),...Nx(e.failed),...Nx(e.cancelled),...Nx(e.running)]}function Nx(e){return Array.isArray(e)?e.filter(Ix):[]}function Px(e){return Array.isArray(e)?e.length:0}function Fx(e){let t=[[Px(e.completed),`completed`],[Px(e.failed),`failed`],[Px(e.cancelled),`cancelled`],[Px(e.running),`running`]].filter(([e])=>Number(e)>0).map(([e,t])=>`${e} ${t}`);return t.length?t.join(`, `):`No yielded run updates`}function Ix(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Lx(e,t,n,r,i,a,o,s,c){let l=r.payload;if(o&&eS(l)&&!tS(l,s)||o&&nS(l,c))return;if(l.type===`assistant_delta`){Jx(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`thinking_delta`){Xx(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`assistant_message`){let i=Rx(n,l,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex),a=t.get(i.id);if(a){Yx(a,i),Qx(t,a);return}Qx(t,i),e.push(i),t.set(i.id,i);return}let u=qx(n,l,i,a,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);if(u){if(u.type===`agent.turn`&&u.eventId){let e=[...t.values()].find(e=>e.type===`agent.turn`&&e.eventId===u.eventId);if(e){e.status=u.status,e.completedAt=u.completedAt??e.completedAt;return}}if(u.type===`assistant.message`){let e=t.get(u.id);if(e){Yx(e,u),Qx(t,e);return}Qx(t,u)}if(u.type===`execution.compaction`){let t=fS(e);if(t){pS(t,u);return}}if(u.type===`model.reasoning`){let e=t.get(u.id);if(e){Zx(e,u);return}}if(u.toolCallId){let e=[...t.values()].find(e=>e.toolCallId===u.toolCallId&&(e.type===`tool.call`||e.type===`agent.delegation`));if(e){if(Cx(e)&&u.type===`agent.delegation`){bx(e,n,r.createdAt,u);return}dS(e,u),bx(e,n,r.createdAt);return}}if(!(u.eventId&&t.has(u.id))){zx(u,t),bx(u,n,r.createdAt),e.push(u);for(let e of hx([u]))t.set(e.id,e)}}}function Rx(e,t,n,r,i,a){let o=typeof t.eventId==`string`?t.eventId:void 0,s=cS(t);return{id:s?sS(s):`event:${t.type}:${gS(t)}`,piboSessionId:e,eventId:o,parentId:o?oS(o):void 0,type:`assistant.message`,title:`Agent Message`,status:`done`,startedAt:n,summary:t.text,output:t.text,source:`event-log`,stableKey:s?`assistant:${s}`:aS(t),orderKey:rS(r,t.type,i,a),children:[]}}function zx(e,t){if(e.type!==`execution.command`||e.parentId&&t.has(e.parentId))return;let n=[...t.values()].filter(n=>{if(n.type!==`agent.turn`||!n.startedAt||!e.startedAt||n.startedAt>e.startedAt)return!1;let r=Bx(n,t);return r===void 0||e.startedAt<=r}).sort(px).at(-1);n&&(e.parentId=n.id)}function Bx(e,t){return e.completedAt?e.completedAt:[...t.values()].filter(t=>t.type===`error`&&t.eventId!==void 0&&t.eventId===e.eventId&&t.startedAt!==void 0).sort(px).at(0)?.startedAt}function Vx(e){return e.some(e=>{let t=e.payload.type;return t!==`assistant_delta`&&t!==`thinking_delta`})}function Hx(e){if(e.type===`assistant_delta`){if(e.text.length===0)return;let t=cS(e);return t?sS(t):void 0}if(e.type===`thinking_delta`){if(e.text.length===0)return;let t=uS(e);return t?lS(t):void 0}}function Ux(e,t){let n=t.payload;if(n.type!==`message_queued`||n.source!==`user`)return!1;let r=typeof n.eventId==`string`?n.eventId:t.eventId,i=typeof n.text==`string`?n.text:void 0;return e.some(e=>e.type!==`user.message`||e.source!==`transcript`?!1:r&&(e.entryId===r||e.stableKey===`entry:${r}`)?!0:!!(i&&Wx(e)===i))}function Wx(e){if(typeof e.output==`string`)return e.output;if(typeof e.summary==`string`)return e.summary}function Gx(e){if(e.streamId!==void 0){let t=e.payload;return e.streamFrameIndex===void 0?`stream:${e.streamId}:${t.type}`:`stream:${e.streamId}:${e.streamFrameIndex}:${t.type}`}return e.eventSequence===void 0?`id:${e.id}`:`sequence:${e.piboSessionId??``}:${e.eventSequence}`}function Kx(e,t){let n=t;for(let t of e)t.streamId!==void 0&&(n=n===void 0?t.streamId:Math.max(n,t.streamId));return n}function qx(e,t,n,r,i,a,o,s,c){let l=`eventId`in t&&typeof t.eventId==`string`?t.eventId:void 0,u=`event:${t.type}:${l??gS(t)}`,d=l?oS(l):void 0,f={id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:aS(t),orderKey:rS(o,t.type,s,c),children:[]};switch(t.type){case`message_queued`:{let n=Ax(t.text);return t.source===`service`&&n?jx({id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:l?`run-notification:${l}`:u,orderKey:rS(o,t.type,s,c),notification:n}):{...f,type:`user.message`,title:`User Message`,status:`done`,summary:t.text,output:t.text}}case`message_started`:case`message_finished`:return t.source===`service`?void 0:{...f,id:l?oS(l):u,type:`agent.turn`,title:`Agent Turn`,status:t.type===`message_finished`||i!==`running`?`done`:`running`,completedAt:t.type===`message_finished`?a:void 0,stableKey:l?`turn:${l}`:f.stableKey};case`thinking_finished`:{if(!mS(t.text))return;let e=uS(t);return{...f,id:e?lS(e):u,parentId:d,type:`model.reasoning`,title:`Thinking`,status:`done`,summary:t.text,output:t.text,stableKey:e?`reasoning:${e}`:f.stableKey}}case`assistant_message`:{let e=cS(t);return{...f,id:e?sS(e):u,parentId:d,type:`assistant.message`,title:`Agent Message`,status:`done`,summary:t.text,output:t.text,stableKey:e?`assistant:${e}`:f.stableKey}}case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:{let o=_x(t.toolName),s=r.get(t.toolCallId)??(o?gx(e,t.toolName,t,n):void 0);return{...f,id:`tool:${t.toolCallId}`,parentId:d,toolCallId:t.toolCallId,type:o?`agent.delegation`:`tool.call`,title:t.toolName,status:t.type===`tool_execution_finished`?t.isError?`error`:`done`:i===`running`&&(t.type===`tool_execution_started`||t.type===`tool_execution_updated`)?`running`:`done`,completedAt:t.type===`tool_execution_finished`?a:void 0,input:`args`in t?t.args:void 0,output:t.type===`tool_execution_finished`?t.result:t.type===`tool_execution_updated`?t.partialResult:void 0,error:t.type===`tool_execution_finished`&&t.isError?hS(t.result):void 0,linkedPiboSessionId:s,stableKey:`tool:${t.toolCallId}`,children:[]}}case`subagent_session`:return{...f,id:t.toolCallId?`tool:${t.toolCallId}`:u,eventId:l,toolCallId:t.toolCallId,type:`agent.delegation`,title:t.toolName,status:i===`running`?`running`:`done`,summary:t.subagentName,input:{subagentName:t.subagentName,threadKey:t.threadKey},linkedPiboSessionId:t.childPiboSessionId,stableKey:t.toolCallId?`tool:${t.toolCallId}`:`subagent:${t.childPiboSessionId}`,children:[]};case`execution_result`:return $x(t.action)?void 0:{...f,type:`execution.command`,title:t.action,status:`done`,input:{action:t.action},output:t.result};case`compaction_start`:return{...f,id:`event:compaction:${o??s??gS(t)}`,type:`execution.compaction`,title:`compact`,status:`running`,summary:`Compacting`,input:{reason:t.reason},stableKey:`compaction:active`};case`compaction_end`:return{...f,id:`event:compaction:end:${o??s??gS(t)}`,type:`execution.compaction`,title:`compact`,status:t.errorMessage?`error`:`done`,completedAt:a,summary:t.aborted?`Compaction skipped`:t.errorMessage?`Compaction failed`:`Compacted`,input:{reason:t.reason},output:t.result,error:t.errorMessage,stableKey:`compaction:active`};case`session_error`:return{...f,type:`error`,title:`Session Error`,status:`error`,summary:t.errorDetails?.userMessage,input:t.errorDetails,error:t.error,output:t.error};default:return}}function Jx(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=cS(n),l=c?sS(c):`event:assistant_delta:${gS(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?oS(n.eventId):void 0,piboSessionId:n.piboSessionId,eventId:n.eventId,type:`assistant.message`,title:`Agent Message`,status:r===`running`?`running`:`done`,startedAt:i,summary:n.text,output:n.text,source:`event-log`,stableKey:c?`assistant:${c}`:l,orderKey:rS(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function Yx(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt}function Xx(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=uS(n),l=c?lS(c):`event:thinking_delta:${gS(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?oS(n.eventId):void 0,piboSessionId:n.piboSessionId,eventId:n.eventId,type:`model.reasoning`,title:`Thinking`,status:r===`running`?`running`:`done`,startedAt:i,summary:n.text,output:n.text,source:`event-log`,stableKey:c?`reasoning:${c}`:l,orderKey:rS(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function Zx(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.output=t.output??e.output,e.completedAt=t.completedAt??e.completedAt}function Qx(e,t){if(!t.parentId||t.status!==`done`)return;let n=e.get(t.parentId);!n||n.type!==`agent.turn`||(n.status=`done`,n.completedAt=t.completedAt??t.startedAt??n.completedAt)}function $x(e){return e===`session.fork`||e===`session.clone`||e===`session.switch`}function eS(e){return e.type===`message_queued`||e.type===`message_started`||e.type===`message_finished`||e.type===`assistant_delta`||e.type===`assistant_message`||e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`}function tS(e,t){let n=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;return!!(n&&t.has(n))}function nS(e,t){return t!==`running`&&e.type===`tool_call`}function rS(e,t,n,r){return e===void 0&&(n!==void 0||r!==void 0)?sx(n,r,iS(t)):ox(e,iS(t))}function iS(e){switch(e){case`message_queued`:return`user.message`;case`message_started`:case`message_finished`:return`agent.turn`;case`thinking_started`:case`thinking_delta`:case`thinking_finished`:return`model.reasoning`;case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:case`subagent_session`:return`tool.call`;case`assistant_delta`:case`assistant_message`:return`assistant.message`;case`execution_result`:return`execution.command`;case`compaction_start`:case`compaction_end`:return`execution.compaction`;case`session_error`:return`error`;default:return`execution.command`}}function aS(e){let t=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;if(e.type===`tool_call`||e.type===`tool_execution_started`||e.type===`tool_execution_updated`||e.type===`tool_execution_finished`||e.type===`subagent_session`&&e.toolCallId)return`tool:${e.toolCallId}`;if(t&&(e.type===`message_started`||e.type===`message_finished`))return`turn:${t}`;if(e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`){let t=uS(e);if(t)return`reasoning:${t}`}if(e.type===`assistant_delta`||e.type===`assistant_message`){let t=cS(e);if(t)return`assistant:${t}`}return`event:${e.type}:${t??gS(e)}`}function oS(e){return`event:message:${e}`}function sS(e){return`event:assistant:${e}`}function cS(e){if(!e.eventId)return;let t=typeof e.assistantIndex==`number`?e.assistantIndex:e.contentIndex;return typeof t==`number`?`${e.eventId}:assistant:${t}`:e.eventId}function lS(e){return`event:thinking:${e}`}function uS(e){if(!e.eventId)return;let t=typeof e.thinkingIndex==`number`?e.thinkingIndex:e.contentIndex;return typeof t==`number`?`${e.eventId}:thinking:${t}`:e.eventId}function dS(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt,e.linkedPiboSessionId=t.linkedPiboSessionId??e.linkedPiboSessionId}function fS(e){return hx([...e]).reverse().find(e=>e.type===`execution.compaction`&&e.status===`running`)}function pS(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt}function mS(e){return typeof e==`string`&&e.trim().length>0}function hS(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function gS(e){return _S(new TextEncoder().encode(JSON.stringify(e))).slice(0,48)}function _S(e){let t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,n=``,r=0;for(;r+2<e.length;r+=3){let i=e[r]<<16|e[r+1]<<8|e[r+2];n+=t[i>>18&63]+t[i>>12&63]+t[i>>6&63]+t[i&63]}if(r<e.length){let i=e[r],a=r+1<e.length?e[r+1]:0,o=i<<16|a<<8;n+=t[o>>18&63]+t[o>>12&63],r+1<e.length&&(n+=t[o>>6&63])}return n}function vS(e){let t=new Map;for(let n of e)t.set(n.id,n);let n=[];for(let r of e){if(!r.parentId){n.push(r);continue}let e=t.get(r.parentId);e?e.children.push(r):n.push(r)}return dx(n)}function yS(e,t,n){return t.map(t=>bS(e,t,n))}function bS(e,t,n){let r=e.get(t.id);if(t.children.length===0){let e=r!==void 0&&r.children.length===0;return r&&e&&(n&&!n.has(t.id)||xS(r,t))?r:e?{...t,children:r.children}:{...t,children:[]}}let i=t.children.map(t=>bS(e,t,n)),a=r!==void 0&&r.children.length===i.length&&r.children.every((e,t)=>e===i[t]);return r&&a&&(n&&!n.has(t.id)||xS(r,t))?r:a?{...t,children:r?.children??i}:{...t,children:i}}function xS(e,t){return e.id===t.id&&e.parentId===t.parentId&&e.entryId===t.entryId&&e.piboSessionId===t.piboSessionId&&e.eventId===t.eventId&&e.toolCallId===t.toolCallId&&e.runId===t.runId&&e.type===t.type&&e.title===t.title&&e.status===t.status&&e.startedAt===t.startedAt&&e.completedAt===t.completedAt&&e.durationMs===t.durationMs&&e.summary===t.summary&&e.input===t.input&&e.output===t.output&&e.error===t.error&&e.linkedPiboSessionId===t.linkedPiboSessionId&&e.source===t.source&&e.stableKey===t.stableKey&&SS(e.orderKey,t.orderKey)}function SS(e,t){return e===t?!0:!e||!t?!1:e.sourceRank===t.sourceRank&&e.turnSeq===t.turnSeq&&e.transcriptIndex===t.transcriptIndex&&e.contentPartIndex===t.contentPartIndex&&e.eventSequence===t.eventSequence&&e.streamId===t.streamId&&e.streamFrameIndex===t.streamFrameIndex&&e.phaseRank===t.phaseRank}function CS(e,t,n){if(!t.length)return e;let r=new Set(e.rawEvents.map(e=>Gx(e))),i=[];for(let e of t){let t=Gx(e);r.has(t)||(r.add(t),i.push(e))}if(!i.length)return e;let a=hx(e.nodes),o=[],s=new Map,c=new Map;for(let e of a){c.set(e.id,e);let t={...e,children:[]};o.push(t),s.set(t.id,t)}let l=new Map,u=new Map,d=new Set,f=[],p=new Set;for(let t of i){if(Ux(o,t))continue;f.push(t);let r=Hx(t.payload);p&&r?p.add(r):p=void 0,Lx(o,s,e.piboSessionId,t,l,u,!1,d,n)}if(!f.length)return e;let m=vS(o);Vx(f)&&xx(m);let h=yS(c,m,p);return{...e,rawEvents:e.rawEvents.length?[...e.rawEvents,...f]:f,nodes:h,latestStreamId:Kx(f,e.latestStreamId)}}function wS(e,t){return e?XS(TS(e.nodes).sort((e,t)=>px(e.node,t.node)).filter(e=>e.node.type!==`agent.turn`&&(t.showThinking||e.node.type!==`model.reasoning`)).map(e=>ES(e.node,e.turnId))).map(e=>e.row):[]}function TS(e,t){let n=[];for(let r of e)r.type!==`agent.turn`&&n.push({node:r,turnId:t}),n.push(...TS(r.children,r.type===`agent.turn`?r.id:t));return n}function ES(e,t){let n;switch(e.type){case`user.message`:n={row:OS(e),turnId:t};break;case`assistant.message`:n={row:kS(e),turnId:t};break;case`model.reasoning`:n={row:AS(e),turnId:t};break;case`tool.call`:n=jS(e,t);break;case`tool.result`:n=NS(e,t);break;case`agent.delegation`:n={row:FS(e),turnId:t};break;case`agent.async`:n={row:IS(e),turnId:t};break;case`yielded.run`:n={row:LS(e),turnId:t};break;case`execution.command`:n={row:zS(e),turnId:t};break;case`execution.compaction`:n={row:RS(e),turnId:t};break;case`error`:n={row:JS(e),turnId:t};break;case`agent.turn`:n={row:{id:e.id,kind:`error`,status:`neutral`,lines:[],sourceNodeIds:[e.id]},turnId:t};break}return{...n,row:{...n.row,...DS(e)}}}function DS(e){return{eventId:e.eventId,runId:e.runId,orderSource:e.source,orderStreamId:e.orderKey?.streamId,orderStreamFrameIndex:e.orderKey?.streamFrameIndex}}function OS(e){let t=SC(e.output)||SC(e.summary)||e.title;return{id:e.id,kind:`message.user`,status:bC(e.status),lines:[{prefix:`prompt`,tokens:[$(t)]}],sourceNodeIds:[e.id],forkEntryId:e.entryId,output:t}}function kS(e){return{id:e.id,kind:`message.assistant`,status:bC(e.status),lines:[],sourceNodeIds:[e.id],output:SC(e.output)||SC(e.summary)||``,error:e.error}}function AS(e){let t=fC(e.output??e.summary);return{id:e.id,kind:`reasoning`,status:bC(e.status),lines:[{prefix:`bullet`,tokens:[$(e.status===`running`?`Thinking`:`Thought`,`amber`,`semibold`)]}],sourceNodeIds:[e.id],markdown:t}}function jS(e,t){let n=hC(e.input);if(n&&mC(e.title))return{row:qS(e,n),turnId:t,exploring:void 0};let r=tC(e);if(r)return{row:MS(e,r),turnId:t,image:r.detail};let i=uC(e.error??e.output,5,e.error?`red`:`dim`);return{row:{id:e.id,kind:`tool.call`,status:bC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(_C(e.status),xC(e.status),`semibold`),$(` `)],functionCall:{name:e.title,input:e.input}},...i.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:dC(i,e.error?`error`:`output`)},turnId:t,exploring:oC(e)}}function MS(e,t){let n=bC(e.status),r=t.path?`Path: ${t.path}`:t.query?`Query: ${t.query}`:t.mimeType?`Type: ${t.mimeType}`:`Image content returned`;return{id:e.id,kind:`tool.image`,status:n,errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(iC(e.status,t.count),xC(e.status),`semibold`)]},{prefix:`detail`,tokens:[$(r,e.status===`error`?`red`:`cyan`)]}],sourceNodeIds:[e.id],input:rC(e.input),output:t.summary,error:e.error,expandable:e.input!==void 0||t.summary!==void 0||!!e.error}}function NS(e,t){let n=tC(e);return n?{row:MS(e,n),turnId:t,image:n.detail}:{row:PS(e),turnId:t}}function PS(e){let t=uC(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`tool.call`,status:bC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(e.status===`error`?`Tool failed`:`Returned`,xC(e.status),`semibold`),$(` ${e.title}`)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:dC(t,e.error?`error`:`output`)}}function FS(e){let t=SC(CC(e.input)?e.input.subagentName:void 0)||e.summary||e.title,n=pC((CC(e.input)?e.input.arguments:void 0)??e.input),r=n?[{prefix:`detail`,tokens:[$(n,`dim`)]}]:[];return{id:e.id,kind:`agent.delegation`,status:bC(e.status),lines:[{prefix:`bullet`,tokens:[$(vC(e.status),xC(e.status),`semibold`),$(` ${t}`,`cyan`)]},...r],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function IS(e){let t=uC(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`agent.async`,status:bC(e.status),lines:[{prefix:`bullet`,tokens:[$(yC(e.status),xC(e.status),`semibold`),$(` ${e.title}`,`cyan`)]},...t.lines],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:dC(t,e.error?`error`:`output`)}}function LS(e){let t=uC(e.output,5);return{id:e.id,kind:`yielded.run`,status:bC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(e.status===`running`?`Waiting on runs`:`Run update`,xC(e.status),`semibold`),$(e.summary?` ${e.summary}`:``)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:dC(t,`output`)}}function RS(e){let t=e.status===`running`?`Compacting`:e.status===`error`?`Compaction failed`:SC(e.summary)||`Compacted`;return{id:e.id,kind:`execution.compaction`,status:bC(e.status),lines:[{prefix:`bullet`,tokens:[$(t,xC(e.status),e.status===`error`?`bold`:`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function zS(e){if(e.title===`status`)return BS(e);if(e.title===`thinking`)return VS(e);if(e.title===`fast_mode`)return HS(e);if(e.title===`login`&&GS(e.output))return US(e);if(e.title===`model`&&KS(e.output))return WS(e);hC(e.output)??hC(e.input)??e.title;let t=uC(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:bC(e.status),lines:[{prefix:`bullet`,tokens:[$(`Command`,`yellow`,`semibold`),$(` /${e.title}`,`yellow`)]},...t.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:dC(t,e.error?`error`:`output`)}}function BS(e){return{id:e.id,kind:`tool.status`,status:bC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function VS(e){return{id:e.id,kind:`tool.thinking`,status:bC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function HS(e){let t=CC(e.output)?e.output:void 0,n=t?.mode===`fast`?`fast`:t?.mode===`normal`?`normal`:void 0,r=t?.changed!==!1,i=t?.supported!==!1,a=i?n===`fast`?r?`Switched to Fast mode.`:`Fast mode is already on.`:n===`normal`?r?`Switched to Normal mode.`:`Normal mode is already on.`:`Fast mode updated.`:`Fast mode is not supported by this model.`;return{id:e.id,kind:`execution.command`,status:bC(e.status),lines:[{prefix:`bullet`,tokens:[$(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function US(e){return{id:e.id,kind:`tool.login`,status:bC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function WS(e){return{id:e.id,kind:`tool.model`,status:bC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function GS(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function KS(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function qS(e,t){let n=uC(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:bC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(e.status===`running`?`Running`:`Ran`,xC(e.status),`semibold`),$(` `),...gC(t)]},...n.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:dC(n,e.error?`error`:`output`)}}function JS(e){return{id:e.id,kind:`error`,status:`error`,errorKind:`system`,lines:[{prefix:`bullet`,tokens:[$(e.title||`Error`,`red`,`bold`),$(e.error?` ${e.error}`:``,`red`)]},...YS(e.input)],sourceNodeIds:[e.id],input:e.input,error:e.error,output:e.output,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function YS(e){return CC(e)?[[`Class`,SC(e.errorClass)??SC(e.category)],[`Code`,SC(e.code)??SC(e.providerCode)],[`Origin`,SC(e.origin)],[`Provider`,[SC(e.api),SC(e.provider),SC(e.model)].filter(Boolean).join(` / `)||void 0],[`Retryable`,typeof e.retryable==`boolean`?e.retryable?`yes`:`no`:void 0]].filter(e=>typeof e[1]==`string`&&e[1].length>0).map(([e,t],n)=>({prefix:n===0?`detail`:`continuation`,tokens:[$(`${e}: `,`dim`),$(t,`red`)]})):[]}function XS(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],i=ZS(r);if(!i){t.push(r);continue}let a=[r],o=n+1;for(;o<e.length&&ZS(e[o])===i&&e[o].turnId===r.turnId;)a.push(e[o]),o+=1;if(a.length===1){t.push(r);continue}t.push({row:i===`images`?$S(a):QS(a),turnId:r.turnId}),n=o-1}return t}function ZS(e){if(e.image)return`images`;if(e.exploring)return`exploring`}function QS(e){let t=eC(e,`exploring`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`exploring`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:exploring:${a}:${o}`,kind:`tool.group.exploring`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(s===`running`?`Exploring`:s===`error`?`Exploring failed`:`Explored`,xC(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[$(e.label,e.status===`error`?`red`:`dim`)]})),...r>0?[{prefix:`continuation`,tokens:[$(`+${r} more explorations`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function $S(e){let t=eC(e,`images`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`images`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:images:${a}:${o}`,kind:`tool.group.images`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(s===`running`?`Viewing images`:s===`error`?`Image reads failed`:`Viewed images`,xC(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[$(e.label,e.status===`error`?`red`:`cyan`)]})),...r>0?[{prefix:`continuation`,tokens:[$(`+${r} more image reads`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function eC(e,t){return e.map(e=>{let n=t===`images`?e.image:e.exploring;return{id:e.row.id,label:n?.label??e.row.lines[0]?.tokens.map(e=>e.text).join(``)??e.row.id,status:e.row.status,input:e.row.input,output:e.row.output,error:e.row.error,linkedPiboSessionId:e.row.linkedPiboSessionId,previewOmission:e.row.previewOmission}})}function tC(e){let t=(e.title??``).trim().toLowerCase(),n=CC(e.input)?e.input:void 0,r=cC(n)??cC(CC(e.output)?aC(e.output,`details`):void 0)??cC(CC(e.output)?e.output:void 0),i=lC(n),a=nC(e.output),o=sC(t,[`view_image`,`image`,`screenshot`]);if(!a.length&&!o)return;let s=a.map(e=>e.mimeType).find(e=>!!e),c=Math.max(1,a.length),l={type:a.length>1?`images`:a.length===1?`image`:`image_reference`,path:r,query:i,mimeType:s,count:c>1?c:void 0,detail:a.length?`Image data hidden in terminal view.`:`Image path only; binary data is hidden in terminal view.`},u=r??i??s??`image`;return{count:c,path:r,query:i,mimeType:s,summary:l,detail:{id:e.id,label:`${e.status===`error`?`Image failed`:`Viewed image`} ${u}`,status:bC(e.status),input:rC(e.input),output:l,error:e.error}}}function nC(e,t=0,n=new Set){if(t>5||typeof e!=`object`||!e||n.has(e))return[];if(n.add(e),Array.isArray(e))return e.flatMap(e=>nC(e,t+1,n));let r=e,i=typeof r.type==`string`?r.type.toLowerCase():void 0,a=typeof r.mimeType==`string`?r.mimeType:typeof r.mime_type==`string`?r.mime_type:void 0,o=typeof r.data==`string`||typeof r.image_url==`string`||CC(r.image_url);if((i===`image`||i===`input_image`||i===`output_image`||i===`image_url`)&&(o||a?.startsWith(`image/`))||a?.startsWith(`image/`)&&o)return[{mimeType:a}];let s=[];return`content`in r&&s.push(r.content),`message`in r&&s.push(r.message),`result`in r&&s.push(r.result),`output`in r&&s.push(r.output),s.flatMap(e=>nC(e,t+1,n))}function rC(e){if(Array.isArray(e))return e.map(rC);if(!CC(e))return e;let t={};for(let[n,r]of Object.entries(e)){if((n===`data`||n===`image_url`)&&typeof r==`string`&&r.length>120){t[n]=`[hidden ${n}]`;continue}t[n]=rC(r)}return t}function iC(e,t){return e===`running`?t>1?`Viewing images`:`Viewing image`:e===`error`?t>1?`Image reads failed`:`Image read failed`:t>1?`Viewed images`:`Viewed image`}function aC(e,t){let n=e?.[t];return CC(n)?n:void 0}function oC(e){let t=(e.title??``).trim().toLowerCase(),n=CC(e.input)?e.input:void 0;if(sC(t,[`read`,`open`]))return{id:e.id,label:`Read ${cC(n)??pC(e.input)}`,status:bC(e.status),input:e.input,output:e.output,error:e.error};if(sC(t,[`list`,`ls`,`glob`]))return{id:e.id,label:`List ${cC(n)??pC(e.input)}`,status:bC(e.status),input:e.input,output:e.output,error:e.error};if(sC(t,[`search`,`find`,`grep`,`rg`])){let t=lC(n),r=cC(n);return{id:e.id,label:`Search ${t??pC(e.input)}${r?` in ${r}`:``}`,status:bC(e.status),input:e.input,output:e.output,error:e.error}}}function sC(e,t){return t.some(t=>e===t||e.startsWith(`${t}_`)||e.endsWith(`_${t}`)||e.includes(t))}function cC(e){if(e)for(let t of[`path`,`file`,`filePath`,`filepath`,`url`,`uri`,`cwd`,`pattern`,`glob`]){let n=SC(e[t]);if(n)return n}}function lC(e){if(e)for(let t of[`query`,`pattern`,`text`,`name`,`q`,`regex`]){let n=SC(e[t]);if(n)return n}}function uC(e,t,n=`dim`,r=160){let i={lines:[],visibleLineCount:0,omittedLineCount:0,totalLineCount:0,maxVisibleLineCount:t},a=fC(e);if(!a)return i;let o=a.split(/\r?\n/).map(e=>e.trimEnd()).filter((e,t,n)=>e.length>0||n.length===1);if(!o.length)return i;let s=o.slice(0,t),c=Math.max(0,o.length-s.length),l=s.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[$(e,n)]}));return c>0&&l.push({prefix:`continuation`,tokens:[$(`+${c} more lines`,`dim`,`normal`,!0)]}),{lines:l,visibleLineCount:s.length,omittedLineCount:c,totalLineCount:o.length,maxVisibleLineCount:t}}function dC(e,t){if(!(e.omittedLineCount<=0))return{source:t,visibleLineCount:e.visibleLineCount,omittedLineCount:e.omittedLineCount,totalLineCount:e.totalLineCount,maxVisibleLineCount:e.maxVisibleLineCount}}function fC(e){let t=Uy(e);if(t!==void 0)return t.trim();if(typeof e==`string`)return e.trim();if(e==null)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function pC(e){return(typeof e==`string`?e:fC(e)).replace(/\s+/g,` `).trim()}function mC(e){let t=(e??``).trim().toLowerCase();return t===`shell`||t===`bash`||t===`terminal`}function hC(e){if(CC(e))for(let t of[`cmd`,`command`,`script`]){let n=SC(e[t]);if(n)return n}}function gC(e){let t=e.match(/\s+|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s]+/g)??[e],n=!1;return t.map(e=>/^\s+$/.test(e)?$(e):/^(?:&&|\|\||[|;<>]|2>&1)$/.test(e)?$(e,`red`,`semibold`):e.startsWith(`-`)?$(e,`magenta`):e.startsWith(`$`)||e.includes(`=`)?$(e,`yellow`):/^['"]/.test(e)?$(e,`green`):n?e.includes(`/`)||e.startsWith(`.`)?$(e,`cyan`):$(e,`default`):(n=!0,$(e,`green`,`semibold`)))}function _C(e){return e===`running`?`Calling`:e===`error`?`Call failed`:`Called`}function vC(e){return e===`running`?`Spawning`:e===`error`?`Spawn failed`:`Spawned`}function yC(e){return e===`running`?`Waiting for`:`Finished waiting for`}function bC(e){return e===`running`?`running`:e===`error`?`error`:`done`}function xC(e){return e===`running`?`cyan`:e===`error`?`red`:e===`done`?`green`:`default`}function $(e,t=`default`,n=`normal`,r=!1){return{text:e,tone:t,weight:n,italic:r}}function SC(e){return typeof e==`string`&&e.trim().length?e:void 0}function CC(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function wC(e){if(!e)return;let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else typeof e==`object`&&!Array.isArray(e)&&(t=e);if(!t)return;let n=typeof t.contextUsage==`object`&&t.contextUsage!==null?t.contextUsage:void 0,r=typeof t.providerUsage==`object`&&t.providerUsage!==null?t.providerUsage:void 0,i=Array.isArray(r?.limits)?r.limits.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)).map(e=>{let t=typeof e.usedPercent==`number`?e.usedPercent:void 0,n=typeof e.remainingPercent==`number`?e.remainingPercent:t===void 0?0:Math.max(0,Math.min(100,100-t));return{label:typeof e.label==`string`?e.label:`limit`,usedPercent:t??0,remainingPercent:n,resetsAt:typeof e.resetsAt==`string`?e.resetsAt:void 0}}):[],a=typeof r?.credits==`object`&&r.credits!==null?r.credits:void 0;return{piboSessionId:typeof t.piboSessionId==`string`?t.piboSessionId:void 0,queuedMessages:typeof t.queuedMessages==`number`?t.queuedMessages:void 0,processing:typeof t.processing==`boolean`?t.processing:void 0,streaming:typeof t.streaming==`boolean`?t.streaming:void 0,enabledTools:Array.isArray(t.enabledTools)?t.enabledTools.filter(e=>typeof e==`string`):Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,activeTools:Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,cwd:typeof t.cwd==`string`?t.cwd:void 0,disposed:typeof t.disposed==`boolean`?t.disposed:void 0,contextUsage:n?{tokens:typeof n.tokens==`number`?n.tokens:void 0,contextWindow:typeof n.contextWindow==`number`?n.contextWindow:void 0,percent:typeof n.percent==`number`?n.percent:void 0}:void 0,providerUsage:r&&(i.length>0||a)?{provider:typeof r.provider==`string`?r.provider:void 0,planType:typeof r.planType==`string`?r.planType:void 0,fetchedAt:typeof r.fetchedAt==`string`?r.fetchedAt:void 0,limits:i,credits:a?{unlimited:a.unlimited===!0,balance:typeof a.balance==`string`?a.balance:void 0}:void 0}:void 0}}function TC(e,t,n){return n?{id:e,label:t,value:n}:void 0}function EC({field:e,icon:t}){let n=t===`session`?et:Xe;return(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,M.jsx)(n,{size:11,className:`shrink-0 text-[#737373]`}),(0,M.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,M.jsx)(`span`,{className:`truncate font-mono ${e.id===`session`?`text-[#38bdf8]`:`text-[#d4d4d4]`}`,children:e.value})]})}function DC({progress:e,label:t}){let n=e.percent??0,r=e.tone===`red`?`bg-[#ef4444]`:e.tone===`yellow`?`bg-[#facc15]`:e.tone===`cyan`?`bg-[#38bdf8]`:`bg-[#22c55e]`;return(0,M.jsxs)(`div`,{className:`mt-3 space-y-1`,"data-shared-progress":e.id,"data-shared-progress-state":e.state,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:t??e.label}),(0,M.jsx)(`span`,{className:`font-mono text-[#d4d4d4]`,children:e.state===`available`?e.text:`unavailable`})]}),e.state===`available`?(0,M.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,M.jsx)(`div`,{className:`h-full rounded-full ${r} transition-all`,style:{width:`${Math.min(Math.max(n,0),100)}%`}})}):null]})}function OC(e){if(!e)return;let t=new Date(e);if(!Number.isNaN(t.getTime()))return t.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function kC({row:e}){let t=wC(e.output),n=Ub(e),r=n?.kind===`status`?n.statusView:void 0,[i,a]=(0,v.useState)(!1);if(!t||!r)return(0,M.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:(0,M.jsx)(`div`,{className:`text-[#737373]`,children:`Status (unparseable)`})});let o=new Map(r.fields.map(e=>[e.id,e])),s=o.get(`session`)??TC(`session`,`Session`,t.piboSessionId),c=o.get(`cwd`)??TC(`cwd`,`CWD`,t.cwd),l=r.progress.find(e=>e.id===`context`),u=r.progress.filter(e=>e.id.startsWith(`provider`)),d=t.providerUsage?.limits.length?t.providerUsage.limits:void 0,f=t.enabledTools??t.activeTools??[],p=r.fields.filter(e=>!new Set([`session`,`cwd`]).has(e.id)),m=t.providerUsage?.provider?`${t.providerUsage.provider} quota`:`Provider quota`;return(0,M.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,M.jsx)(Se,{size:14,className:`text-[#22c55e]`}),(0,M.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:r.title})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-1.5 sm:grid-cols-2`,children:[s?(0,M.jsx)(EC,{field:s,icon:`session`}):null,c?(0,M.jsx)(EC,{field:c,icon:`cwd`}):null,p.slice(0,8).map(e=>(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,M.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,M.jsx)(`span`,{className:`truncate font-mono text-[#d4d4d4]`,children:e.value})]},e.id))]}),(0,M.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[t.processing?(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(Ge,{size:10}),` Processing`]}):null,t.streaming?(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(Se,{size:10}),` Streaming`]}):null,typeof t.queuedMessages==`number`&&t.queuedMessages>0?(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[11px] text-[#d4d4d4]`,children:[(0,M.jsx)(rt,{size:10}),` Queued: `,t.queuedMessages]}):null,t.disposed?(0,M.jsx)(`span`,{className:`inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:`Disposed`}):null]}),l?(0,M.jsx)(DC,{progress:l,label:`Context Usage`}):null,u.length?(0,M.jsxs)(`div`,{className:`mt-3 space-y-1.5 border-t border-[#2a2a2a] pt-2`,"data-shared-provider-progress":u.length,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-[#737373]`,"data-shared-status-field":`provider-quota`,children:[(0,M.jsx)(Ze,{size:11}),(0,M.jsxs)(`span`,{children:[m,t.providerUsage?.planType?` (${t.providerUsage.planType})`:``]})]}),d?d.map(e=>{let t=OC(e.resetsAt);return(0,M.jsxs)(`div`,{className:`space-y-1`,"data-shared-progress":`provider-limit:${e.label}`,"data-shared-progress-state":`available`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#a3a3a3]`,children:e.label}),(0,M.jsxs)(`span`,{className:`shrink-0 font-mono text-[#d4d4d4]`,children:[e.remainingPercent.toFixed(0),`% left`,t?` · resets ${t}`:``]})]}),(0,M.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,M.jsx)(`div`,{className:`h-full rounded-full bg-[#38bdf8] transition-all`,style:{width:`${Math.min(Math.max(e.remainingPercent,0),100)}%`}})})]},`${e.label}-${e.resetsAt??``}`)}):u.map(e=>(0,M.jsx)(DC,{progress:e},e.id)),t.providerUsage?.credits?(0,M.jsxs)(`div`,{className:`text-[11px] text-[#a3a3a3]`,"data-shared-status-field":`provider-credits`,children:[`Credits: `,t.providerUsage.credits.unlimited?`unlimited`:t.providerUsage.credits.balance??`available`]}):null]}):null,r.warnings.length||r.errors.length?(0,M.jsxs)(`div`,{className:`mt-3 space-y-1 border-t border-[#2a2a2a] pt-2`,children:[r.warnings.map((e,t)=>(0,M.jsxs)(`div`,{"data-shared-status-warning":!0,className:`text-[11px] text-[#facc15]`,children:[`⚠ `,e]},`warning-${t}`)),r.errors.map((e,t)=>(0,M.jsxs)(`div`,{"data-shared-status-error":!0,className:`text-[11px] text-[#ef4444]`,children:[`✕ `,e]},`error-${t}`))]}):null,f.length>0?(0,M.jsxs)(`div`,{className:`mt-3`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1.5 text-[11px] text-[#737373] hover:text-[#d4d4d4]`,children:[(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i?`▾`:`▸`}),(0,M.jsxs)(`span`,{children:[`Enabled tools (`,f.length,`)`]})]}),i?(0,M.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:f.map(e=>(0,M.jsx)(`span`,{className:`inline-block rounded-sm border border-[#2a2a2a] bg-[#0b0b0b] px-1.5 py-0.5 font-mono text-[11px] text-[#a3a3a3]`,children:e},e))}):null]}):null]})}var AC=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`];function jC(e){let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else e&&typeof e==`object`&&!Array.isArray(e)&&(t=e);if(t)return{level:typeof t.level==`string`?t.level:void 0,availableLevels:Array.isArray(t.availableLevels)?t.availableLevels.filter(e=>typeof e==`string`):[],supported:typeof t.supported==`boolean`?t.supported:void 0}}function MC(e){return AC.includes(e)?e:void 0}function NC({row:e,onLevelSelect:t}){let n=jC(e.output);return n?(0,M.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,M.jsx)(ke,{size:14,className:`text-[#f59e0b]`}),(0,M.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:`Thinking`}),n.supported===!1?(0,M.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:[(0,M.jsx)(vt,{size:10}),` Unsupported`]}):(0,M.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(je,{size:10}),` Supported`]})]}),(0,M.jsxs)(`div`,{className:`grid gap-1.5 text-[11px]`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Current:`}),(0,M.jsx)(`span`,{className:`font-mono font-semibold text-[#f59e0b]`,children:n.level??`unknown`})]}),n.availableLevels.length?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,M.jsx)(`span`,{className:`mr-1 text-[#737373]`,children:`Available:`}),n.availableLevels.map(e=>{let r=MC(e),i=n.supported===!1||!r||!t;return(0,M.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>{r&&t?.(r)},className:`border bg-transparent px-1.5 py-0.5 ${e===n.level?`border-[#f59e0b] text-[#f59e0b]`:`border-[#3a3a3a] text-[#d4d4d4]`} ${i?`cursor-default`:`cursor-pointer`}`,children:e},e)})]}):null,(0,M.jsxs)(`div`,{className:`text-[#737373]`,children:[`Click a level or use `,(0,M.jsx)(`span`,{className:`text-[#f59e0b]`,children:`/thinking <level>`}),`.`]})]})]}):(0,M.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:(0,M.jsx)(`div`,{className:`text-[#737373]`,children:`Thinking (unparseable)`})})}var PC=180,FC={index:`LAST`,align:`end`},IC={top:2400,bottom:2400},LC=84,RC=6;function zC({traceView:e,selectedTrace:t,isLoading:n,showThinking:r,expandThinking:i,sessionAgentProfile:a,sessionActiveModel:o,selectedSessionStatus:s,selectedSessionSignal:c,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,agentProfiles:f,sessionProfileChangeDisabled:p,onSessionAgentProfileChange:m,onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:y}){let b=(0,v.useMemo)(()=>wS(e,{showThinking:r}),[r,e]),[x,S]=(0,v.useState)(new Set),[C,w]=(0,v.useState)(null),T=(0,v.useRef)({}),E=b.filter(e=>e.status===`running`).length,ee=b.filter(e=>JC(e,`user`)).length,D=b.filter(e=>JC(e,`tool`)).length,O=b.filter(e=>JC(e,`system`)).length,te=c?c.isTreeActive:s===`running`||E>0||t?.status===`UNSET`,ne=ka({itemCount:b.length,resetKey:e?.piboSessionId,contentKey:b,atBottomThreshold:PC});(0,v.useEffect)(()=>{S(e=>qC(e,b,i))},[i,b]),(0,v.useEffect)(()=>{let e=new Set(b.map(e=>e.id));w(t=>t&&e.has(t)?t:null);for(let t of[`system`,`tool`,`user`]){let n=T.current[t];n&&!e.has(n)&&delete T.current[t]}},[b]);let re=(0,v.useCallback)(e=>{let t=YC(b,e,T.current[e]);t&&(T.current[e]=t.row.id,w(t.row.id),ne.scrollToIndex(t.index,`start`,`fast-smooth`,{fromIndex:t.fromIndex,stagingAlign:e===`tool`?`end`:void 0}),XC(t.row.id))},[b,ne]),ie=e=>{e.expandable&&S(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},ae=(0,v.useCallback)((t,n)=>(0,M.jsx)(`div`,{className:`px-4`,children:(0,M.jsx)(HC,{row:n,expanded:x.has(n.id),focused:C===n.id,piboSessionId:e?.piboSessionId??``,onToggle:()=>ie(n),onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:y})}),[x,C,h,y,g,_,e?.piboSessionId]),oe=(0,v.useMemo)(()=>({Footer:te?rw:void 0}),[te]);return(0,M.jsxs)(`section`,{className:`relative min-w-0 flex-1 flex flex-col overflow-hidden bg-[#0b0b0b] text-[#d4d4d4]`,"data-pibo-component":`CompactTerminalSessionView`,"data-pibo-debug":`compact-terminal-session-view`,"data-pibo-session-id":e?.piboSessionId??void 0,children:[(0,M.jsx)(BC,{errorCount:O,toolErrorCount:D,userMessageCount:ee,onNavigate:re,sessionAgentProfile:a,sessionActiveModel:o,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,onOpenSession:g}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e?b.length?(0,M.jsx)(Li,{ref:ne.virtuosoRef,data:b,initialTopMostItemIndex:FC,increaseViewportBy:IC,defaultItemHeight:LC,className:`min-h-0 h-full overflow-x-hidden font-mono text-[12px] leading-[1.45]`,computeItemKey:(e,t)=>t.id,scrollerRef:ne.scrollerRef,atBottomStateChange:ne.atBottomStateChange,atBottomThreshold:ne.atBottomThreshold,followOutput:ne.followOutput,totalListHeightChanged:ne.totalListHeightChanged,alignToBottom:!0,components:oe,itemContent:ae},e.piboSessionId):(0,M.jsx)(pw,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m,message:`No visible trace rows yet.`}):(0,M.jsx)(pw,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m})}),ne.isSticky?null:(0,M.jsx)(`button`,{type:`button`,onClick:()=>ne.stickToBottom(`auto`),title:`Scroll to latest`,"aria-label":`Scroll to latest`,className:`absolute right-4 bottom-4 z-30 inline-flex h-9 w-9 items-center justify-center rounded-sm border border-[#38bdf8] bg-[#111111]/95 text-[#38bdf8] shadow-lg shadow-black/30 hover:bg-[#161616]`,children:(0,M.jsx)(Me,{size:18})})]})}function BC({errorCount:e,toolErrorCount:t,userMessageCount:n,onNavigate:r,sessionAgentProfile:i,sessionActiveModel:a,sessionBreadcrumbs:o,originSession:s,derivedSessions:c,onOpenSession:l}){return(0,M.jsxs)(`div`,{className:`border-b border-[#2a2a2a] bg-[#111111] px-4 py-2 text-[11px]`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i?(0,M.jsx)(dw,{tone:`neutral`,children:i}):null,a?(0,M.jsx)(dw,{tone:`purple`,children:a}):null,n>0?(0,M.jsxs)(dw,{tone:`cyan`,label:`${n} user messages · jump to previous user message`,onClick:()=>r(`user`),children:[n,(0,M.jsx)(ct,{size:12})]}):null,e>0?(0,M.jsxs)(dw,{tone:`red`,label:`${e} errors · jump to previous error`,onClick:()=>r(`system`),children:[e,(0,M.jsx)(Ve,{size:12})]}):null,t>0?(0,M.jsxs)(dw,{tone:`amber`,label:`${t} tool call errors · jump to previous tool error`,onClick:()=>r(`tool`),children:[t,(0,M.jsx)($e,{size:12})]}):null,s?(0,M.jsxs)(VC,{onClick:()=>l(s.piboSessionId),children:[`Origin `,s.label]}):null,c.map(e=>(0,M.jsxs)(VC,{onClick:()=>l(e.piboSessionId),children:[`Derived `,e.label]},e.piboSessionId))]}),o.length?(0,M.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1 text-[#737373]`,children:o.map((e,t)=>(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,M.jsx)(Ne,{size:12,className:`text-[#525252]`}):null,(0,M.jsx)(`button`,{type:`button`,onClick:()=>l(e.piboSessionId),className:`hover:text-[#38bdf8]`,children:e.label})]},e.piboSessionId))}):null]})}function VC({children:e,onClick:t}){return(0,M.jsx)(`button`,{type:`button`,onClick:t,className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e})}function HC({row:e,expanded:t,focused:n,piboSessionId:r,onToggle:i,onFork:a,onOpenSession:o,onThinkingLevelChange:s,onModelChanged:c}){let l=!t&&QC(e),u=l?ZC(e):e.lines;return(0,M.jsxs)(`div`,{className:KC(e,n),"data-pibo-component":`TerminalRow`,"data-pibo-debug":`terminal-row`,"data-pibo-terminal-row":`true`,"data-row-id":e.id,"data-row-kind":e.kind,"data-row-status":e.status,"data-trace-node-id":e.sourceNodeIds.join(` `),"data-event-id":e.eventId,"data-run-id":e.runId,"data-order-source":e.orderSource,"data-order-stream-id":e.orderStreamId,"data-order-frame-index":e.orderStreamFrameIndex,onDoubleClick:e.expandable?t=>{!e.expandable||$C(t)||i()}:void 0,onKeyDown:e.expandable?t=>{!e.expandable||$C(t)||(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),i())}:void 0,role:e.expandable?`button`:void 0,tabIndex:e.expandable||n?0:void 0,"aria-expanded":e.expandable?t:void 0,"aria-current":n?`true`:void 0,children:[(0,M.jsxs)(`div`,{className:`flex gap-3`,children:[(0,M.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,M.jsx)(UC,{row:e,visibleLines:u,collapseToolCallPreview:l,piboSessionId:r,onThinkingLevelChange:s,onModelChanged:c})}),(0,M.jsx)(GC,{row:e,onFork:a,onOpenSession:o})]}),t?(0,M.jsx)(Ky,{row:e,onOpenSession:o}):null]})}function UC({row:e,visibleLines:t,collapseToolCallPreview:n,piboSessionId:r,onThinkingLevelChange:i,onModelChanged:a}){return e.kind===`message.assistant`?(0,M.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalAssistantMessage`,children:(0,M.jsx)(`div`,{className:`compact-terminal-markdown`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`assistant-message`,children:(0,M.jsx)(uy,{streaming:e.status===`running`,children:typeof e.output==`string`?e.output:``})})}):e.kind===`tool.status`?(0,M.jsx)(kC,{row:e}):e.kind===`tool.thinking`?(0,M.jsx)(NC,{row:e,onLevelSelect:i}):e.kind===`tool.login`?(0,M.jsx)(Ob,{row:e,piboSessionId:r}):e.kind===`tool.model`?(0,M.jsx)(Pb,{row:e,piboSessionId:r,onModelChanged:a}):e.kind===`execution.compaction`&&e.status===`running`?(0,M.jsx)(lw,{}):e.kind===`reasoning`&&e.markdown?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(WC,{lines:t,status:e.status,clampPreview:n}),(0,M.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalReasoningMarkdown`,children:(0,M.jsx)(`div`,{className:`compact-terminal-markdown compact-terminal-reasoning`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`reasoning`,children:(0,M.jsx)(uy,{streaming:e.status===`running`,children:e.markdown})})})]}):(0,M.jsx)(WC,{lines:t,status:e.status,clampPreview:n})}function WC({lines:e,status:t,clampPreview:n}){return e.map((e,r)=>(0,M.jsx)(cb,{line:e,status:t,clampLines:n&&r===0?5:void 0},r))}function GC({row:e,onFork:t,onOpenSession:n}){return(0,M.jsxs)(`div`,{className:`flex shrink-0 items-start gap-1 transition-opacity ${e.forkEntryId?`opacity-100`:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:[e.linkedPiboSessionId?(0,M.jsx)(fw,{label:`Open linked session`,onClick:()=>n(e.linkedPiboSessionId),children:`Open`}):null,e.forkEntryId?(0,M.jsxs)(fw,{label:`Fork from this user message`,onClick:()=>t(e.forkEntryId),children:[(0,M.jsx)(Qe,{size:13}),`Fork`]}):null]})}function KC(e,t=!1){let n=e.kind===`message.user`?`group border-b border-[#141414] bg-[#11a4d4]/10 py-2 last:border-b-0 hover:bg-[#11a4d4]/15`:e.kind===`execution.command`?`group border-b border-[#141414] bg-[#f59e0b]/5 py-2 last:border-b-0 hover:bg-[#f59e0b]/10`:`group border-b border-[#141414] py-2 last:border-b-0 hover:bg-[#161616]`,r=e.expandable||t?` focus:outline-none focus:ring-1 focus:ring-[#38bdf8]/50`:``;return t?`${n}${r} ring-1 ring-[#38bdf8] bg-[#123040]`:`${n}${r}`}function qC(e,t,n){let r=new Set;for(let i of t)e.has(i.id)&&r.add(i.id),n&&i.kind===`reasoning`&&i.expandable&&r.add(i.id);return mw(e,r)?e:r}function JC(e,t){return t===`user`?e.kind===`message.user`:e.status===`error`?t===`tool`?e.errorKind===`tool`:e.errorKind!==`tool`:!1}function YC(e,t,n){let r=e.map((e,t)=>({row:e,index:t})).filter(({row:e})=>JC(e,t));if(!r.length)return;let i=n?e.findIndex(e=>e.id===n):-1,a=i>=0?i:e.length;return{...r.filter(e=>e.index<a).at(-1)??r[r.length-1],fromIndex:a}}function XC(e){let t=0,n=()=>{let r=Array.from(document.querySelectorAll(`[data-pibo-component="TerminalRow"]`)).find(t=>t.dataset.rowId===e);if(r){r.scrollIntoView({block:`start`,inline:`nearest`,behavior:`smooth`}),r.focus({preventScroll:!0});return}t+=1,t<8&&requestAnimationFrame(n)};requestAnimationFrame(()=>requestAnimationFrame(n))}function ZC(e){return e.kind===`tool.group.exploring`||e.kind===`tool.group.images`?e.lines.slice(0,RC):e.lines}function QC(e){return!!e.expandable&&(e.kind===`tool.call`||e.kind===`tool.image`||e.kind===`tool.group.exploring`||e.kind===`tool.group.images`||e.kind===`agent.delegation`||e.kind===`agent.async`||e.kind===`yielded.run`||e.kind===`execution.command`||e.kind===`execution.compaction`)}function $C(e){let t=e.target;if(!(t instanceof Element)||t===e.currentTarget)return!1;let n=t.closest(`button, a, input, textarea, select, summary, [role='button'], [tabindex]:not([tabindex='-1'])`);return!!(n&&n!==e.currentTarget)}var ew=`Working...`,tw=33,nw=126;function rw(){let{chars:e,activeIndex:t}=iw(ew);return(0,M.jsx)(`div`,{className:`border-t border-[#141414] px-4 py-2`,role:`status`,"aria-live":`polite`,"aria-label":`Working`,children:(0,M.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,M.jsx)(`span`,{className:`whitespace-pre text-[#737373]`,children:`•`}),(0,M.jsx)(`span`,{className:`compact-terminal-working-scramble`,"aria-hidden":`true`,children:e.map((e,n)=>(0,M.jsx)(`span`,{className:n===t?`compact-terminal-working-scramble-active`:void 0,children:e},n))})]})})}function iw(e){let t=(0,v.useMemo)(()=>Array.from(e),[e]),[n,r]=(0,v.useState)(()=>ow(t)),[i,a]=(0,v.useState)(0);return(0,v.useEffect)(()=>{let e=0,n=0,i=cw(),o=0;r(ow(t));let s=window.setInterval(()=>{if(o>0){o--;return}if(e>=t.length){e=0,n=0,i=cw(),r(ow(t)),a(0);return}let s=e,c=t[s]??` `;if(a(s),n++,n<i){r(e=>aw(e,s,sw(c)));return}r(e=>aw(e,s,c)),e++,n=0,i=cw(),e>=t.length&&(r(t),a(-1),o=18)},55);return()=>window.clearInterval(s)},[t]),{chars:n,activeIndex:i}}function aw(e,t,n){let r=[...e];return r[t]=n,r}function ow(e){return e.map(e=>sw(e))}function sw(e){let t=``;do{let e=tw+Math.floor(Math.random()*(nw-tw+1));t=String.fromCharCode(e)}while(t===e);return t}function cw(){return 2+Math.floor(Math.random()*11)}function lw(){let e=uw();return(0,M.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,M.jsx)(`span`,{className:`whitespace-pre text-[#38bdf8]`,children:`•`}),(0,M.jsxs)(`span`,{className:`min-w-0`,children:[(0,M.jsx)(`span`,{className:`font-semibold text-[#38bdf8]`,children:`Compacting`}),(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:e})]})]})}function uw(){let[e,t]=(0,v.useState)(0);return(0,v.useEffect)(()=>{let e=window.setInterval(()=>t(e=>(e+1)%4),400);return()=>window.clearInterval(e)},[]),`.`.repeat(e)}function dw({tone:e,label:t,onClick:n,children:r}){let i=`inline-flex items-center gap-1 border px-2 py-0.5 ${e===`cyan`?`border-[#1f4960] text-[#38bdf8]`:e===`red`?`border-[#5f2222] text-[#ef4444]`:e===`amber`?`border-[#6b4e16] text-[#f59e0b]`:e===`purple`?`border-purple-500/40 text-purple-300`:`border-[#3a3a3a] text-[#d4d4d4]`}`;return n?(0,M.jsx)(`button`,{type:`button`,onClick:n,className:`${i} hover:bg-white/5 focus:outline-none focus:ring-1 focus:ring-[#38bdf8]`,title:t,"aria-label":t,children:r}):(0,M.jsx)(`span`,{className:i,title:t,"aria-label":t,children:r})}function fw({label:e,onClick:t,children:n}){return(0,M.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e,title:e,className:`inline-flex min-h-7 min-w-7 items-center gap-1 border border-[#3a3a3a] px-2 text-[11px] text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:n})}function pw({isLoading:e,agentProfiles:t,disabled:n,onSelectAgentProfile:r,message:i}){return(0,M.jsxs)(`div`,{className:`flex min-h-full flex-col items-center justify-center gap-4 px-6 py-10 text-center text-[12px] text-[#737373]`,children:[(0,M.jsx)(`div`,{children:e?`Loading trace…`:i??`No trace selected.`}),t.length?(0,M.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:t.map(e=>(0,M.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>r(e.name),className:`border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:e.name},e.name))}):null]})}function mw(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function hw({traceView:e,isLoading:t,selectedSessionStatus:n,selectedSessionSignal:r,workflowProjectSession:i,workflowLifecycleEvents:a,sessionNodes:o,onOpenSession:s,onRefreshBootstrap:c,onError:l}){let u=i?Fw(i,e,n,r,a??[],o):null;return u?(0,M.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,M.jsxs)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-4`,children:[(0,M.jsx)(gw,{model:u}),(0,M.jsx)(_w,{}),(0,M.jsx)(vw,{model:u,onRefreshBootstrap:c,onError:l}),(0,M.jsx)(bw,{model:u}),(0,M.jsx)(xw,{model:u,onOpenSession:s}),(0,M.jsx)(Ow,{nodes:u.nodes,edges:u.edges}),(0,M.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,M.jsx)(Aw,{model:u}),(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,M.jsx)(jw,{model:u}),(0,M.jsx)(Mw,{model:u}),(0,M.jsx)(Nw,{model:u})]})]})]})}):(0,M.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,M.jsxs)(`div`,{className:`mx-auto flex max-w-4xl flex-col gap-4`,children:[(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,M.jsx)(rt,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState`]}),(0,M.jsx)(`p`,{className:`mt-2 text-sm text-slate-400`,children:t?`Loading session trace…`:`This session is not linked to a workflow run, so no Workflow/XState projection is available.`})]}),(0,M.jsx)(_w,{})]})})}function gw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,M.jsx)(rt,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState Projection`]}),(0,M.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2 text-xs`,children:[(0,M.jsx)(_T,{tone:`blue`,children:e.workflowId}),e.workflowRunId?(0,M.jsxs)(_T,{tone:`slate`,children:[`run `,ST(e.workflowRunId)]}):null,(0,M.jsx)(_T,{tone:vT(e.status),children:e.state})]})]}),(0,M.jsxs)(`div`,{className:`min-w-0 text-right font-mono text-[11px] text-slate-500`,children:[(0,M.jsxs)(`div`,{className:`truncate`,children:[`session `,ST(e.piboSessionId)]}),e.latestStreamId===void 0?null:(0,M.jsxs)(`div`,{children:[`stream `,e.latestStreamId]})]})]}),(0,M.jsx)(`p`,{className:`mt-3 text-sm text-slate-400`,children:`Dedicated Project workflow execution surface. This view derives the current XState-style UI snapshot from project-session workflow linkage and live session state while keeping kernel records as durable truth.`})]})}function _w(){return(0,M.jsx)(`div`,{className:`rounded-sm border border-amber-500/30 bg-amber-500/10 p-4 text-sm`,children:(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-amber-200`,children:[(0,M.jsx)(gt,{size:14}),`Workflow IR source-of-truth boundary`]}),(0,M.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-amber-100/80`,children:`Projects inspect configured sessions, workflow runs, and the XState-style projection derived from Pibo Workflow IR. Authoring stays in the Workflows tab; raw XState editing and inline executable code are not exposed here.`})]}),(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[(0,M.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`IR: source of truth`}),(0,M.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`XState: projection only`})]})]})})}function vw({model:e,onRefreshBootstrap:t,onError:n}){let r=e.workflowRunId?Dw(e):void 0,i=`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`;return(0,M.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,"aria-label":`Projects workflow execution shell`,children:[(0,M.jsx)(Tw,{title:`Workflow configured-session view`,icon:(0,M.jsx)(at,{size:14}),children:(0,M.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,M.jsx)(Ew,{label:`selected workflow`,value:i}),(0,M.jsx)(Ew,{label:`session state`,value:e.workflowRunId?`started`:`configured/not-started`}),(0,M.jsx)(Ew,{label:`input keys`,value:String(e.configuration.inputKeys.length)}),(0,M.jsx)(Ew,{label:`prompt overrides`,value:String(e.configuration.promptOverrideNodeIds.length)}),(0,M.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`Saved configuration is reviewed here before Start. Workflow selection and session overrides remain immutable for this configured Project session.`})]})}),(0,M.jsx)(Tw,{title:`Workflow run view`,icon:(0,M.jsx)(Se,{size:14}),children:(0,M.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,M.jsx)(Ew,{label:`run id`,value:e.workflowRunId?ST(e.workflowRunId):`not started`}),(0,M.jsx)(Ew,{label:`status`,value:e.state}),(0,M.jsx)(Ew,{label:`current node`,value:r?.label??`none`}),(0,M.jsx)(Ew,{label:`output`,value:e.finalOutput?`available`:`empty`}),(0,M.jsx)(Ew,{label:`error`,value:e.runtimeErrors.length?`${e.runtimeErrors.length} runtime errors`:e.validationErrors.length?`${e.validationErrors.length} validation diagnostics`:`none`}),(0,M.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This workflow run view container is the stable Project home for status, current node, output, and error sections.`})]})}),(0,M.jsx)(Tw,{title:`Human action area`,icon:(0,M.jsx)(Ue,{size:14}),children:(0,M.jsx)(yw,{model:e,onRefreshBootstrap:t,onError:n})})]})}function yw({model:e,onRefreshBootstrap:t,onError:n}){let[r,i]=(0,v.useState)({}),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)({}),[l,u]=(0,v.useState)({}),d=(e,t)=>{i(n=>({...n,[e]:t}))},f=async(i,a)=>{if(!i.waitTokenId||!a.registered)return;let s=`${i.waitTokenId}:${a.id}`,l=a.kind??`resume`,d;if(l===`resume`){let e=r[i.waitTokenId]??(i.payloadRequirements?.required?`{}`:``);if(e.trim())try{d=JSON.parse(e)}catch{let e=[{code:`WorkflowRuntimeError.invalidHumanActionPayload`,message:`Resume payload must be valid JSON before it can be submitted.`,severity:`error`,path:`$.payload`,hint:`Enter JSON such as {"comment":"Approved"}.`}];c(t=>({...t,[i.waitTokenId]:e})),n?.(`Resume payload must be valid JSON.`);return}}o(s),c(e=>({...e,[i.waitTokenId]:[]}));try{await Sb(e.projectId,e.piboSessionId,{waitTokenId:i.waitTokenId,actionId:a.id,...a.kind?{kind:a.kind}:{},...d===void 0?{}:{payload:d}}),u(e=>({...e,[i.waitTokenId]:`${a.displayName} submitted.`})),n?.(null),await t?.()}catch(e){let t=aT(e);c(e=>({...e,[i.waitTokenId]:t})),n?.(t[0]?.message??oT(e))}finally{o(null)}};return(0,M.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[e.pendingHumanActions.length?(0,M.jsx)(`div`,{className:`space-y-3`,children:e.pendingHumanActions.map(e=>{let t=[...e.diagnostics,...e.waitTokenId?s[e.waitTokenId]??[]:[]];return(0,M.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-amber-100`,"aria-label":`Pending workflow human action wait token`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`font-semibold`,children:e.label}),(0,M.jsx)(`div`,{className:`mt-1 break-words text-[11px] leading-5 text-amber-100/80`,children:e.prompt})]}),(0,M.jsx)(`span`,{className:`shrink-0 rounded border border-amber-400/40 bg-[#0b0f14]/40 px-1.5 py-0.5 font-mono text-[10px] text-amber-100/70`,children:e.waitTokenId?ST(e.waitTokenId):e.source})]}),(0,M.jsxs)(`div`,{className:`mt-2 grid gap-2 text-[11px] text-amber-100/75`,children:[(0,M.jsx)(Ew,{label:`human node`,value:e.humanNodeId??`unspecified`}),(0,M.jsx)(Ew,{label:`payload`,value:e.payloadRequirements?.description??`No persisted payload schema.`}),e.expiresAt?(0,M.jsx)(Ew,{label:`expires`,value:e.expiresAt}):null]}),e.payloadRequirements?.schema?(0,M.jsxs)(`div`,{className:`mt-2 rounded-sm border border-amber-400/25 bg-[#0b0f14]/50 p-2`,children:[(0,M.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider text-amber-100/70`,children:`Resume payload schema`}),(0,M.jsx)(Sc,{value:e.payloadRequirements.schema,defaultExpandLevel:1,maxHeight:`10rem`,showControls:!1})]}):null,e.availableActions.some(e=>e.kind===`resume`)?(0,M.jsxs)(`label`,{className:`mt-3 block text-[11px] text-amber-100/80`,children:[(0,M.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Resume payload JSON`}),(0,M.jsx)(`textarea`,{className:`min-h-20 w-full rounded-sm border border-amber-500/30 bg-[#0b0f14] px-2 py-1.5 font-mono text-[11px] text-amber-50 outline-none focus:border-[#11a4d4]`,value:r[e.waitTokenId??e.id]??(e.payloadRequirements?.required?`{}`:``),onChange:t=>d(e.waitTokenId??e.id,t.target.value),placeholder:`{"comment":"Approved"}`})]}):null,(0,M.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,"aria-label":`Workflow wait token actions`,children:e.availableActions.length?e.availableActions.map(t=>{let n=`${e.waitTokenId}:${t.id}`;return(0,M.jsx)(`button`,{type:`button`,disabled:!e.waitTokenId||!t.registered||a!==null,onClick:()=>void f(e,t),className:`rounded-sm border border-amber-400/40 bg-[#0b0f14]/70 px-2.5 py-1 text-[11px] font-semibold text-amber-100 transition hover:border-[#11a4d4] hover:text-[#8bdcf4] disabled:cursor-not-allowed disabled:opacity-50`,title:t.description??t.id,children:a===n?`Submitting…`:t.displayName},t.id)}):(0,M.jsx)(`span`,{className:`text-amber-100/60`,children:`No registered human actions are available for this wait token.`})}),e.waitTokenId&&l[e.waitTokenId]?(0,M.jsx)(`div`,{className:`mt-2 text-[11px] text-emerald-200`,children:l[e.waitTokenId]}):null,t.length?(0,M.jsx)(`div`,{className:`mt-2 space-y-1`,"aria-label":`Human action diagnostics`,children:t.map((e,t)=>(0,M.jsxs)(`div`,{className:`rounded border border-red-400/35 bg-red-500/15 p-2 text-[11px] leading-5 text-red-100`,children:[(0,M.jsx)(`div`,{children:e.message}),(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-red-100/70`,children:[e.code,e.path?` · ${e.path}`:``]})]},`${e.code}:${t}`))}):null]},e.id)})}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-slate-500`,children:`No pending human action. Approval, rejection, resume, and cancel controls render here when a persisted workflow wait token exists.`}),(0,M.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This human action area lives inside the workflow run context, validates wait-token state and resume payloads, and stays separate from normal Terminal chat controls.`})]})}function bw({model:e}){let t=e.workflowRunId?Dw(e):void 0,n=[...e.runtimeErrors.map(e=>({...e,source:e.source??`runtime`})),...e.validationErrors.map(e=>({...e,source:e.source??`validation`}))].slice(0,8);return(0,M.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow run inspection panel`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(Ke,{size:14}),`Workflow run inspection`]}),(0,M.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Status, current node, history, attempts, transfers, output, and errors are rendered from Project session and workflow run facts when a run is linked. The XState graph remains a visualization projection only.`})]}),(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2 text-[10px] uppercase tracking-wide`,children:[(0,M.jsx)(`span`,{className:`rounded border border-emerald-500/40 bg-emerald-500/10 px-2 py-1 text-emerald-200`,children:`kernel/run records: truth`}),(0,M.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-amber-500/10 px-2 py-1 text-amber-100`,children:`XState projection only`})]})]}),(0,M.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-3`,children:[(0,M.jsxs)(Sw,{title:`Status`,badge:e.state,icon:(0,M.jsx)(Se,{size:14}),children:[(0,M.jsx)(Cw,{label:`run id`,value:e.workflowRunId?ST(e.workflowRunId):`not started`}),(0,M.jsx)(Cw,{label:`status`,value:e.state}),(0,M.jsx)(Cw,{label:`record source`,value:e.workflowRunId?`Project workflow run id`:`no run record yet`})]}),(0,M.jsxs)(Sw,{title:`Current node`,badge:t?.status??`none`,icon:(0,M.jsx)(dt,{size:14}),children:[(0,M.jsx)(Cw,{label:`node`,value:t?.label??`none`}),(0,M.jsx)(Cw,{label:`node id`,value:t?.id??`none`}),(0,M.jsx)(Cw,{label:`source`,value:`project/session run cursor`})]}),(0,M.jsx)(Sw,{title:`Run history`,badge:`${e.runHistory.length}`,icon:(0,M.jsx)(tt,{size:14}),children:e.runHistory.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.runHistory.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:ST(e.id)}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${xT(e.status)}`,children:e.status})]}),(0,M.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.currentNodeId?`current ${e.currentNodeId}`:`no current node`,` · `,e.source]}),(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-600`,children:[`updated `,e.updatedAt]})]},e.id))}):(0,M.jsx)(ww,{children:e.workflowRunId?`No workflow run history for this selected Project session yet.`:`No current run attempts; this configured Project session has not been started.`})})]}),(0,M.jsxs)(`div`,{className:`mt-3 grid gap-3 lg:grid-cols-2`,children:[(0,M.jsx)(Sw,{title:`Node attempts`,badge:`${e.nodeAttempts.length}`,icon:(0,M.jsx)(at,{size:14}),children:e.nodeAttempts.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.nodeAttempts.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.label}),(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:[e.nodeId,` · attempt `,e.attempt]})]}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${xT(e.status)}`,children:e.status})]}),(0,M.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.kind,` · `,e.source]})]},e.id))}):(0,M.jsx)(ww,{children:e.workflowRunId?`No node attempts recorded for this workflow run yet.`:`No current node attempts; Start has not created a workflow run.`})}),(0,M.jsx)(Sw,{title:`Edge transfers`,badge:`${e.edgeTransfers.length}`,icon:(0,M.jsx)(Qe,{size:14}),children:e.edgeTransfers.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.edgeTransfers.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:e.edgeId}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${xT(e.status)}`,children:e.status})]}),(0,M.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.source,e.createdAt?` · ${e.createdAt}`:``]})]},e.id))}):(0,M.jsx)(ww,{children:`No edge transfers recorded for this workflow run yet.`})}),(0,M.jsx)(Sw,{title:`Output`,badge:e.finalOutput?`available`:`empty`,icon:(0,M.jsx)(ze,{size:14}),children:e.finalOutput?(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsx)(`div`,{className:`mb-2 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}),(0,M.jsx)(Sc,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`12rem`,showControls:!1})]}):(0,M.jsx)(ww,{children:`No workflow output has been recorded for this run yet.`})}),(0,M.jsx)(Sw,{title:`Error`,badge:n.length?`${n.length}`:`none`,icon:(0,M.jsx)(gt,{size:14}),children:n.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2 text-xs text-red-100`,children:[(0,M.jsx)(`div`,{className:`break-words`,children:e.message}),(0,M.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,M.jsx)(`span`,{children:e.code}):null,e.source?(0,M.jsx)(`span`,{children:e.source}):null]})]},e.id))}):(0,M.jsx)(ww,{children:`No workflow run errors are recorded.`})})]})]})}function xw({model:e,onOpenSession:t}){let n=zw(e.definitionLink);return(0,M.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow navigation links`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(qe,{size:14}),`Workflow navigation links`]}),(0,M.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Use these run-view links to move between real nested workflow sessions and the Workflows tab definition. Snapshot-only history is shown when the live definition is deleted or unavailable.`})]}),e.definitionLink.status===`live`&&n?(0,M.jsxs)(`a`,{className:`inline-flex shrink-0 items-center justify-center gap-1 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100`,href:n,children:[(0,M.jsx)(qe,{size:13}),`Open live workflow definition`]}):null]}),(0,M.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-2`,children:[(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Nested workflow child session links`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Nested workflow child sessions`}),(0,M.jsx)(`span`,{className:`rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:e.nestedSessionLinks.length})]}),e.nestedSessionLinks.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.nestedSessionLinks.map(e=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>t(e.piboSessionId),className:`w-full rounded-sm border border-slate-800 bg-[#0b0f14] p-2 text-left transition hover:border-[#11a4d4]/60 hover:bg-[#102331]`,children:(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.title}),(0,M.jsx)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:ST(e.piboSessionId)})]}),(0,M.jsx)(`span`,{className:`rounded border border-[#11a4d4]/40 bg-[#11a4d4]/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-[#8bdcf4]`,children:`open session`})]})},e.piboSessionId))}):(0,M.jsx)(ww,{children:`No nested workflow child sessions are linked under this selected Project session yet.`})]}),(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Workflow definition link state`,children:[(0,M.jsx)(`div`,{className:`mb-3 text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Workflow definition link`}),e.definitionLink.status===`live`&&n?(0,M.jsxs)(`div`,{className:`rounded-sm border border-emerald-500/35 bg-emerald-500/10 p-3 text-xs leading-5 text-emerald-100`,children:[(0,M.jsx)(`div`,{className:`font-semibold`,children:`Live workflow definition exists`}),(0,M.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-emerald-100/80`,children:Vw(e.definitionLink)}),e.definitionLink.definitionHash?(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-emerald-100/60`,children:[`snapshot `,ST(e.definitionLink.definitionHash)]}):null]}):(0,M.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-5 text-amber-100`,children:[(0,M.jsx)(`div`,{className:`font-semibold`,children:`Definition deleted — snapshot-only definition-deleted state`}),(0,M.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-amber-100/80`,children:Vw(e.definitionLink)}),(0,M.jsx)(`div`,{className:`mt-1 text-amber-100/80`,children:e.definitionLink.tombstoneLabel??`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}),e.definitionLink.definitionHash?(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-amber-100/60`,children:[`snapshot `,ST(e.definitionLink.definitionHash)]}):null]})]})]})]})}function Sw({title:e,badge:t,icon:n,children:r}){return(0,M.jsxs)(`section`,{className:`min-w-0 rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":e,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(`span`,{className:`text-[#11a4d4]`,children:n}),e]}),(0,M.jsx)(`span`,{className:`shrink-0 rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:t})]}),r]})}function Cw({label:e,value:t}){return(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 py-2 first:pt-0 last:border-b-0 last:pb-0`,children:[(0,M.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-slate-500`,children:e}),(0,M.jsx)(`span`,{className:`min-w-0 max-w-[14rem] truncate text-right font-mono text-xs text-slate-300`,title:t,children:t})]})}function ww({children:e}){return(0,M.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-800 bg-[#0b0f14] p-3 text-xs leading-5 text-slate-500`,children:e})}function Tw({title:e,icon:t,children:n}){return(0,M.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,"aria-label":e,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(`span`,{className:`text-[#11a4d4]`,children:t}),e]}),n]})}function Ew({label:e,value:t}){return(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,M.jsx)(`span`,{className:`uppercase tracking-wide text-slate-500`,children:e}),(0,M.jsx)(`span`,{className:`min-w-0 max-w-[12rem] truncate text-right font-mono text-slate-300`,title:t,children:t})]})}function Dw(e){return e.nodes.find(e=>e.status===`active`||e.status===`waiting`)??e.nodes[0]}function Ow({nodes:e,edges:t}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-4`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(dt,{size:14}),`Visual State Flow`]}),(0,M.jsx)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_auto_1fr_auto_1fr]`,children:e.map((e,n)=>(0,M.jsx)(kw,{node:e,edge:t[n]},e.id))})]})}function kw({node:e,edge:t}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`rounded-sm border p-3 ${yT(e.status)}`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,M.jsx)(gT,{status:e.status}),(0,M.jsx)(`div`,{className:`min-w-0 truncate text-sm font-semibold text-slate-100`,children:e.label})]}),(0,M.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]}),(0,M.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]}),t?(0,M.jsx)(`div`,{className:`hidden items-center justify-center text-center text-[10px] uppercase tracking-wide text-slate-500 md:flex`,children:(0,M.jsxs)(`div`,{children:[(0,M.jsx)(Qe,{size:14,className:`mx-auto mb-1 text-[#11a4d4]`}),t.label]})}):null]})}function Aw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(Se,{size:14}),`Current UI Snapshot`]}),(0,M.jsx)(Sc,{value:e.snapshot,showControls:!1})]})}function jw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(at,{size:14}),`Node Statuses`]}),(0,M.jsxs)(`span`,{className:`font-mono text-[11px] text-slate-500`,children:[e.nodes.length,` nodes`]})]}),(0,M.jsx)(`div`,{className:`space-y-2`,children:e.nodes.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border px-3 py-2 ${yT(e.status)}`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,M.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:(0,M.jsx)(gT,{status:e.status})}),(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-sm font-semibold text-slate-100`,children:e.label}),(0,M.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-slate-500`,children:e.id})]})]}),(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${bT(e.status)}`,children:e.status}),(0,M.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]})]}),(0,M.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]},e.id))}),(0,M.jsx)(`p`,{className:`mt-3 text-xs text-slate-500`,children:`Node status is reconstructed from the workflow run linkage and live session state; persisted kernel records remain the durable source of truth.`})]})}function Mw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(ze,{size:14}),`Final Output & Validation`]}),(0,M.jsxs)(`div`,{className:`space-y-4`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Final output`}),e.finalOutput?(0,M.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}):null]}),e.finalOutput?(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:(0,M.jsx)(Sc,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`14rem`,showControls:!1})}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No final workflow output is available yet. Completed workflow-backed sessions show the final assistant output here.`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Validation errors`}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 font-mono text-[10px] ${e.validationErrors.length?`border-red-500/40 bg-red-500/10 text-red-300`:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`}`,children:e.validationErrors.length?`${e.validationErrors.length} found`:`none`})]}),e.validationErrors.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.validationErrors.map(e=>(0,M.jsx)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2`,children:(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2 text-xs text-red-200`,children:[(0,M.jsx)(gt,{size:14,className:`mt-0.5 shrink-0 text-red-300`}),(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`break-words`,children:e.message}),(0,M.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,M.jsx)(`span`,{children:e.code}):null,e.path?(0,M.jsx)(`span`,{children:e.path}):null,e.source?(0,M.jsx)(`span`,{children:e.source}):null]})]})]})},e.id))}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No workflow validation diagnostics were found in the current session trace.`})]})]})]})}function Nw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(He,{size:14}),`Projection Facts`]}),(0,M.jsxs)(`dl`,{className:`space-y-3`,children:[(0,M.jsx)(Pw,{label:`projection kind`,value:`pibo.workflow.xstateUiModel`}),(0,M.jsx)(Pw,{label:`schema`,value:`v1`}),(0,M.jsx)(Pw,{label:`durable truth`,value:`kernel`}),(0,M.jsx)(Pw,{label:`private payloads`,value:`not exposed`}),(0,M.jsx)(Pw,{label:`states`,value:String(e.nodes.length)}),(0,M.jsx)(Pw,{label:`transitions`,value:String(e.edges.length)}),(0,M.jsx)(Pw,{label:`trace`,value:e.traceVersion??`pending`})]})]})}function Pw({label:e,value:t}){return(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,M.jsx)(`dt`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:e}),(0,M.jsx)(`dd`,{className:`min-w-0 truncate text-right font-mono text-xs text-slate-300`,children:t})]})}function Fw(e,t,n,r,i,a){if(!lT(e))return null;let o=uT(e,n),s=dT(e,n),c=fT(s),l=Zw(t,s),u=[...$w(t),...Qw(e,i)],d=Ww(e,o,c),f=Gw(t,e.workflowRunId),p=Jw(t,e.workflowRunId),m=Yw(t,r),h=Iw(e),g=Lw(a,e.piboSessionId),_=[{id:`workflow.entry`,label:`workflow entry`,kind:`initial`,status:s===`idle`?`active`:`completed`,description:`Project session is linked to a workflow-capable route.`},{id:`node.session`,label:t?.title??`pibo session actor`,kind:`agent`,status:c===`node.session`?s:s===`completed`?`completed`:`idle`,description:`Normal Pibo routed session used as the visible workflow actor.`},{id:pT(s),label:mT(s),kind:`terminal`,status:c.startsWith(`workflow.`)?s:`idle`,description:`Terminal state projected from the current workflow/session state.`}];return{projectId:e.projectId,workflowId:e.workflowId,...e.workflowVersion?{workflowVersion:e.workflowVersion}:{},...e.workflowRunId?{workflowRunId:e.workflowRunId}:{},piboSessionId:e.piboSessionId,state:o,status:s,traceTitle:t?.title,traceVersion:t?.version,latestStreamId:t?.latestStreamId,nodes:_,edges:[{id:`workflow.transition.entry.session`,source:`workflow.entry`,target:`node.session`,label:`WORKFLOW.START`},{id:`workflow.transition.session.terminal`,source:`node.session`,target:pT(s),label:hT(s)}],configuration:Hw(e),definitionLink:h,nestedSessionLinks:g,pendingHumanActions:Uw(e,r),runHistory:d,nodeAttempts:f,edgeTransfers:p,runtimeErrors:m,...l?{finalOutput:l}:{},validationErrors:u,snapshot:{kind:`pibo.workflow.xstateUiModel`,schemaVersion:1,projection:{workflowId:e.workflowId,initialStateId:`workflow.entry`,durableTruth:`kernel`,exposesPrivatePayloads:!1},authoring:{location:`workflows_tab`,rawXStateEditingUi:`not_exposed`,inlineExecutableCodeUi:`not_exposed`},current:{snapshotKind:`ui`,...e.workflowRunId?{runId:e.workflowRunId}:{},status:o,stateIds:[c],nodeId:c===`node.session`?`session`:void 0},nodeStatuses:_.map(e=>({id:e.id,kind:e.kind,status:e.status})),runInspection:{durableTruth:`kernel_run_records`,xstateProjectionOnly:!0,runHistoryCount:d.length,nodeAttemptCount:f.length,edgeTransferCount:p.length,runtimeErrorCount:m.length},result:{hasFinalOutput:!!l,validationErrorCount:u.length},actors:[{id:`workflow.actor.session`,kind:`agent`,piboSessionId:e.piboSessionId}],definitionLink:{status:h.status,workflowId:h.workflowId,workflowVersion:h.workflowVersion,hasLiveLink:h.status===`live`&&!!zw(h)},nestedWorkflowSessionCount:g.length}}}function Iw(e){return e.workflowDefinitionLink?e.workflowDefinitionLink:e.workflowVersion?{status:`live`,workflowId:e.workflowId,workflowVersion:e.workflowVersion,title:e.title??e.workflowId,href:Bw(e.workflowId,e.workflowVersion)}:{status:`snapshot_only_definition_deleted`,workflowId:e.workflowId,title:e.title??e.workflowId,tombstoneLabel:`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}}function Lw(e,t){let n=Rw(e,t);if(!n)return[];let r=[],i=e=>{for(let t of e)t.workflowSessionKind===`nested_workflow`&&r.push({piboSessionId:t.piboSessionId,title:t.title,kind:t.workflowSessionKind??t.profile??`workflow`,...t.workflowSessionKind?{workflowSessionKind:t.workflowSessionKind}:{}}),i(t.children)};return i(n.children),r}function Rw(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=Rw(n.children,t);if(e)return e}}function zw(e){if(e.status===`live`){if(e.href)return e.href;if(e.workflowVersion)return Bw(e.workflowId,e.workflowVersion)}}function Bw(e,t){return`/apps/chat/workflows/view/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function Vw(e){return`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`}function Hw(e){let t=e.configuration;return{inputKeys:Object.keys(t?.inputValues??{}).sort(),promptOverrideNodeIds:Object.keys(t?.promptOverrides??{}).sort()}}function Uw(e,t){if(e.pendingHumanActions?.length)return e.pendingHumanActions.map(e=>({id:`wait-token:${e.waitTokenId}`,waitTokenId:e.waitTokenId,workflowRunId:e.workflowRunId,...e.nodeAttemptId?{nodeAttemptId:e.nodeAttemptId}:{},...e.humanNodeId?{humanNodeId:e.humanNodeId}:{},prompt:e.prompt,label:`Pending registered human action`,source:`persisted wait token`,...e.schema?{schema:e.schema}:{},payloadRequirements:e.payloadRequirements,availableActions:e.availableActions,diagnostics:e.diagnostics,createdAt:e.createdAt,...e.expiresAt?{expiresAt:e.expiresAt}:{}}));let n=uT(e,void 0).toLowerCase(),r=[t?.aggregateStatus,t?.localStatus].filter(e=>typeof e==`string`).join(` `).toLowerCase();return n.includes(`waiting`)||n.includes(`blocked`)||r.includes(`waiting`)||r.includes(`blocked`)||t?.hasBlockedDescendant?[{id:`human-action:${e.piboSessionId}`,prompt:`Session signal indicates a wait, but no persisted workflow wait token is available in the Project run store.`,label:`Awaiting human action`,source:t?`session signal`:`project session state`,availableActions:[],diagnostics:[]}]:[]}function Ww(e,t,n){return e.workflowRunId?[{id:e.workflowRunId,status:t,currentNodeId:n,updatedAt:e.updatedAt,source:`project session run record`}]:[]}function Gw(e,t){return!t||!e?[]:eT(e.nodes).filter(Kw).slice(0,8).map((e,t)=>({id:e.id,nodeId:e.stableKey??e.entryId??e.type,label:e.title||e.type,kind:e.type,status:qw(e.status),attempt:t+1,source:`session trace fact`,...e.startedAt?{startedAt:e.startedAt}:{},...e.completedAt?{completedAt:e.completedAt}:{}}))}function Kw(e){return e.type===`agent.turn`||e.type===`tool.call`||e.type===`execution.command`||e.type===`agent.delegation`||e.type===`agent.async`||e.type===`yielded.run`||e.type===`error`}function qw(e){return e===`done`?`completed`:e===`error`?`failed`:`running`}function Jw(e,t){if(!t||!e)return[];let n=[];for(let r of e.rawEvents){if(!cT(r.payload))continue;let e=sT(r.payload.type),i=sT(r.payload.runId);if(e!==`edge.transferred`||i&&i!==t)continue;let a=sT(r.payload.edgeId);a&&n.push({id:sT(r.payload.edgeTransferId)??r.id,edgeId:a,status:`transferred`,source:r.type,createdAt:r.createdAt})}return n.slice(0,8)}function Yw(e,t){let n=[];for(let e of t?.errors??[])n.push({id:`signal:${n.length}`,message:e.message,...e.code?{code:e.code}:{},source:e.source??`session signal`});if(e){for(let t of eT(e.nodes)){let e=t.error??(t.status===`error`?nT(t.output)??nT(t.summary):void 0);e&&n.push({id:`node:${t.id}`,message:e,source:t.type})}for(let t of e.rawEvents){if(!cT(t.payload))continue;let e=t.payload.error,r=cT(e)?sT(e.message):sT(e),i=cT(e)?sT(e.code):void 0;r&&n.push({id:`event:${t.id}`,message:r,...i?{code:i}:{},source:t.type})}}return Xw(n).slice(0,8)}function Xw(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.message}:${e.source??``}`;return t.has(n)?!1:(t.add(n),!0)})}function Zw(e,t){if(t!==`completed`||!e)return;let n=eT(e.nodes),r=[...n].reverse().find(e=>e.type===`assistant.message`&&e.status===`done`&&(e.output!==void 0||e.summary));if(r)return{value:r.output??r.summary??``,source:`assistant.message`};let i=[...n].reverse().find(e=>e.status===`done`&&e.type!==`user.message`&&e.type!==`model.reasoning`&&e.output!==void 0);return i?{value:i.output,source:i.type}:void 0}function Qw(e,t){let n=[];for(let r of t)if(r.piboSessionId===e.piboSessionId&&!(r.type!==`project.workflow_start.blocked`&&r.validation?.trigger!==`before_workflow_start`))for(let e of r.diagnostics)e.severity===`error`&&n.push({id:`lifecycle:${r.id}:${n.length}`,message:e.message,code:e.code,path:e.path,source:`start lifecycle event`});return iT(n).slice(0,8)}function $w(e){if(!e)return[];let t=[];for(let n of eT(e.nodes)){let e=n.error??nT(n.output)??nT(n.summary);e&&(!rT([n.title,n.summary,n.error,n.type].filter(e=>typeof e==`string`).join(` `))&&!rT(e)||t.push({id:`node:${n.id}`,message:e,...n.type?{source:n.type}:{}}))}for(let n of e.rawEvents)tT(n.payload,`event:${n.id}`,t);return iT(t).slice(0,8)}function eT(e){let t=[],n=e=>{for(let r of e)t.push(r),n(r.children)};return n(e),t}function tT(e,t,n,r=0){if(r>4||!cT(e))return;let i=Array.isArray(e.diagnostics)?e.diagnostics:void 0;if(i)for(let e of i){if(!cT(e))continue;let r=sT(e.message)??nT(e);r&&n.push({id:`${t}:diagnostic:${n.length}`,message:r,...sT(e.code)?{code:sT(e.code)}:{},...sT(e.path)?{path:sT(e.path)}:{},source:`workflow.diagnostic`})}let a=e.error;if(cT(a)){let e=sT(a.code),r=sT(a.message)??nT(a);r&&rT([e,r].filter(Boolean).join(` `))&&n.push({id:`${t}:error:${n.length}`,message:r,...e?{code:e}:{},source:`workflow.error`})}else typeof a==`string`&&rT(a)&&n.push({id:`${t}:error:${n.length}`,message:a,source:`workflow.error`});for(let[i,a]of Object.entries(e))i===`diagnostics`||i===`error`||i!==`payload`&&i!==`output`&&i!==`result`&&i!==`data`||tT(a,`${t}:${i}`,n,r+1)}function nT(e){if(typeof e==`string`)return e;if(cT(e))return sT(e.message)??sT(e.error)??sT(e.summary)}function rT(e){let t=e.toLowerCase();return t.includes(`validation`)||t.includes(`validate`)||t.includes(`diagnostic`)||t.includes(`workflowinterfaceerror`)||t.includes(`workflowruntimeerror.validation`)}function iT(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.path??``}:${e.message}`;return t.has(n)?!1:(t.add(n),!0)})}function aT(e){return cT(e)&&cT(e.data)&&Array.isArray(e.data.diagnostics)?e.data.diagnostics.filter(cT).map(t=>({code:sT(t.code)??`WorkflowRuntimeError.humanActionRejected`,message:sT(t.message)??oT(e),severity:t.severity===`info`||t.severity===`warning`||t.severity===`error`?t.severity:`error`,...sT(t.path)?{path:sT(t.path)}:{},...sT(t.registryRef)?{registryRef:sT(t.registryRef)}:{},...sT(t.hint)?{hint:sT(t.hint)}:{}})):[{code:`WorkflowRuntimeError.humanActionRejected`,message:oT(e),severity:`error`}]}function oT(e){return e instanceof Error?e.message:String(e)}function sT(e){return typeof e==`string`&&e.trim()?e:void 0}function cT(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function lT(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function uT(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.workflowRunId?`workflow`:e.kind}function dT(e,t){let n=uT(e,t).toLowerCase();return e.archived?`cancelled`:n.includes(`complete`)||n.includes(`done`)?`completed`:n.includes(`fail`)||n.includes(`error`)?`failed`:n.includes(`cancel`)?`cancelled`:n.includes(`wait`)||n.includes(`blocked`)?`waiting`:!e.workflowRunId&&n.includes(`configured`)?`idle`:`active`}function fT(e){return e===`completed`?`workflow.completed`:e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`node.session`}function pT(e){return e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`workflow.completed`}function mT(e){return e===`failed`?`failed`:e===`cancelled`?`cancelled`:`completed`}function hT(e){return e===`failed`?`WORKFLOW.FAIL`:e===`cancelled`?`WORKFLOW.CANCEL`:`WORKFLOW.NODE.DONE`}function gT({status:e}){return e===`completed`?(0,M.jsx)(ze,{size:16,className:`text-emerald-300`}):e===`failed`?(0,M.jsx)(Ve,{size:16,className:`text-red-300`}):e===`cancelled`?(0,M.jsx)(gt,{size:16,className:`text-slate-400`}):e===`waiting`?(0,M.jsx)(Ue,{size:16,className:`text-amber-300`}):e===`active`?(0,M.jsx)(Se,{size:16,className:`text-[#11a4d4]`}):(0,M.jsx)(He,{size:16,className:`text-slate-500`})}function _T({tone:e,children:t}){return(0,M.jsx)(`span`,{className:`rounded border px-2 py-1 font-mono ${{blue:`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`,slate:`border-slate-700 bg-slate-900/50 text-slate-300`,green:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`,amber:`border-amber-500/40 bg-amber-500/10 text-amber-300`,red:`border-red-500/40 bg-red-500/10 text-red-300`}[e]}`,children:t})}function vT(e){return e===`completed`?`green`:e===`failed`||e===`cancelled`?`red`:e===`waiting`?`amber`:`blue`}function yT(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10`:e===`failed`?`border-red-500/40 bg-red-500/10`:e===`cancelled`?`border-slate-600 bg-slate-800/40`:e===`waiting`?`border-amber-500/40 bg-amber-500/10`:e===`active`?`border-[#11a4d4]/50 bg-[#11a4d4]/10 shadow-[0_0_0_1px_rgba(17,164,212,0.18)]`:`border-slate-800 bg-[#111820]`}function bT(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:e===`failed`||e===`cancelled`?`border-red-500/40 bg-red-500/10 text-red-300`:e===`waiting`?`border-amber-500/40 bg-amber-500/10 text-amber-300`:e===`active`?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function xT(e){let t=e.toLowerCase();return t.includes(`complete`)||t.includes(`done`)||t.includes(`transferred`)?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:t.includes(`fail`)||t.includes(`error`)||t.includes(`cancel`)?`border-red-500/40 bg-red-500/10 text-red-300`:t.includes(`wait`)||t.includes(`blocked`)?`border-amber-500/40 bg-amber-500/10 text-amber-300`:t.includes(`run`)||t.includes(`active`)||t.includes(`workflow`)?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function ST(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}var CT=[{id:`terminal`,label:`Terminal`,description:`Compact Codex-style terminal transcript.`,render:e=>(0,M.jsx)(zC,{...e})},{id:`workflow`,label:`Workflow`,description:`Workflow/XState visualization for workflow-backed project sessions.`,render:e=>(0,M.jsx)(hw,{...e})}],wT=new Map(CT.map(e=>[e.id,e]));function TT(){return CT}function ET(e){return wT.get(e)??wT.get(`terminal`)}var DT=`pibo.chat.composerHistory`,OT=100;function kT(){try{let e=localStorage.getItem(DT);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.trim().length>0).slice(-OT):[]}catch{return[]}}function AT(e){let t=e.trim();if(!t)return;let n=kT();if(n.at(-1)!==t)try{localStorage.setItem(DT,JSON.stringify([...n,t].slice(-OT)))}catch{}}function jT(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{return document.execCommand(`copy`),Promise.resolve()}finally{document.body.removeChild(t)}}function MT(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function NT({sessionId:e,disabled:t=!1,commands:n,skills:r,value:i,focusSignal:a,selectedWebAnnotations:o,selectedUploadAttachments:s,onValueChange:c,onCommand:l,onDetachWebAnnotation:u,onClearWebAnnotations:d,onAttachUploadedFiles:f,onDetachUploadAttachment:p,onClearUploadAttachments:m,onSend:h}){let g=(0,v.useRef)(null),_=(0,v.useRef)(null),y=(0,v.useRef)(null),b=(0,v.useRef)(null),x=(0,v.useRef)(null),S=(0,v.useRef)(null),C=(0,v.useRef)(null),[w,T]=(0,v.useState)(0),[E,ee]=(0,v.useState)(0),[D,O]=(0,v.useState)(0),[te,ne]=(0,v.useState)([]),[re,ie]=(0,v.useState)(!1),[ae,oe]=(0,v.useState)(null),[k,A]=(0,v.useState)(null),se=(0,v.useMemo)(()=>{for(let e=D-1;e>=0;e--){let t=i[e];if(t===` `||t===`
40
- `||t===` `)break;if(t===`$`){if(e>0&&i[e-1]===`\\`)continue;return{query:i.slice(e+1,D).toLowerCase(),startPos:e,endPos:D}}}return null},[i,D]),ce=i.trim().startsWith(`/`)?i.trim().split(/\s+/)[0]:null,le=se?PT(se.startPos,i.slice(se.startPos,D)):null,ue=ce?FT(ce):null,fe=(0,v.useMemo)(()=>se?r.filter(e=>e.name.toLowerCase().startsWith(se.query)):[],[se,r]),pe=(0,v.useMemo)(()=>ce?n.filter(e=>e.slash.startsWith(ce)):[],[ce,n]),me=le&&te.includes(le)?[]:fe,he=ue&&te.includes(ue)?[]:pe,ge=(0,v.useCallback)(e=>{e&&ne(t=>t.includes(e)?t:[...t,e])},[]),_e=(0,v.useCallback)(()=>{let e=[fe.length?le:null,pe.length?ue:null].filter(e=>!!e);e.length&&ne(t=>{let n=new Set(t);for(let t of e)n.add(t);return n.size===t.length?t:[...n]})},[ue,pe.length,fe.length,le]);(0,v.useEffect)(()=>{let e=[le,ue].filter(e=>!!e);ne(t=>t.filter(t=>e.includes(t)))},[ue,le]),(0,v.useEffect)(()=>{!he.length||w<he.length||T(0)},[w,he.length]),(0,v.useEffect)(()=>{!me.length||E<me.length||ee(0)},[E,me.length]),(0,v.useEffect)(()=>{let e=requestAnimationFrame(()=>x.current?.scrollIntoView({block:`nearest`}));return()=>cancelAnimationFrame(e)},[w,he.length]),(0,v.useEffect)(()=>{let e=requestAnimationFrame(()=>S.current?.scrollIntoView({block:`nearest`}));return()=>cancelAnimationFrame(e)},[E,me.length]),(0,v.useEffect)(()=>{C.current=null},[e]),(0,v.useEffect)(()=>{if(!k)return;let e=requestAnimationFrame(()=>b.current?.focus());return()=>{cancelAnimationFrame(e),URL.revokeObjectURL(k.previewUrl)}},[k]),(0,v.useEffect)(()=>{if(a<=0)return;let e=_.current;if(!e)return;let t=e.value.length;e.focus(),e.setSelectionRange(t,t),O(t)},[a]),(0,v.useEffect)(()=>{if(!he.length&&!me.length)return;let e=e=>{let t=e.target;t instanceof Node&&(g.current?.contains(t)||_e())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[_e,he.length,me.length]),(0,v.useLayoutEffect)(()=>{HT(_.current)},[i]);let ve=e=>{if(!se||!_.current)return;let t=i.slice(0,se.startPos),n=i.slice(se.endPos);c(t+`$`+e+n),ge(PT(se.startPos,`$${e}`));let r=se.startPos+1+e.length;O(r),requestAnimationFrame(()=>{_.current?.setSelectionRange(r,r),O(r)})},ye=e=>{c(e),requestAnimationFrame(()=>{let e=_.current;if(!e)return;let t=e.value.length;e.setSelectionRange(t,t),O(t)})},be=e=>{let t=C.current;if(!t){if(e===`next`||i!==``)return!1;let t=kT();if(!t.length)return!1;let n=e===`previous`?t.length-1:0;return C.current={entries:t,index:n,draft:i},ye(t[n]),!0}if(e===`previous`){let e=Math.max(0,t.index-1);return C.current={...t,index:e},ye(t.entries[e]),!0}let n=t.index+1;return n>=t.entries.length?(C.current=null,ye(t.draft),!0):(C.current={...t,index:n},ye(t.entries[n]),!0)},xe=()=>{t||re||y.current?.click()},j=()=>{A(null)},Se=e=>{if(t||re)return;let n=IT(e.clipboardData);if(!n.length)return;e.preventDefault(),_e(),oe(null);let r=n[0];A(e=>(e&&URL.revokeObjectURL(e.previewUrl),{file:r,previewUrl:URL.createObjectURL(r)}))},Ce=async()=>{if(!k||re)return;let e=k.file;A(null),await we([e])},we=async e=>{if(e.length){ie(!0),oe({message:`Uploading ${e.length} file${e.length===1?``:`s`}...`,error:!1});try{f((await de(e)).files),oe(null)}catch(e){oe({message:e instanceof Error?e.message:String(e),error:!0})}finally{ie(!1)}}},Te=async()=>{if(t)return;let e=i.trim();if(e){if(me.length){ve(me[Math.min(E,me.length-1)].name);return}if(he.length&&!n.some(t=>t.slash===e.split(/\s+/)[0])){let e=he[Math.min(w,he.length-1)].slash;c(e),ge(FT(e));return}if(C.current=null,AT(e),c(``),e.split(/\s+/)[0]===`/upload`){xe();return}e.startsWith(`/`)&&await l(e)||await h(e)}};return(0,M.jsxs)(`div`,{ref:g,"data-pibo-debug":`composer`,"data-pibo-session-id":e??void 0,"data-pibo-state":t?`disabled`:i?`non-empty`:`empty`,className:`relative p-3 bg-[#151f24] border-t border-slate-800 max-[980px]:p-2`,children:[(0,M.jsx)(`input`,{ref:y,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,we(t)}}),ae?(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-sm border px-3 py-2 text-xs ${ae.error?`border-red-900 bg-red-950/40 text-red-200`:ae.copyText?`border-green-900/60 bg-green-950/30 text-green-300`:`border-slate-700 bg-[#0e1116] text-slate-300`}`,children:[(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:ae.message}),ae.copyText?(0,M.jsx)(`button`,{type:`button`,onClick:()=>void jT(ae.copyText),title:`Copy uploaded file path`,"aria-label":`Copy uploaded file path`,className:`shrink-0 rounded-sm p-0.5 text-slate-400 hover:bg-slate-800 hover:text-[#11a4d4]`,children:(0,M.jsx)(We,{size:13})}):null,(0,M.jsx)(`button`,{type:`button`,onClick:()=>oe(null),title:`Hide upload status`,"aria-label":`Hide upload status`,className:`shrink-0 rounded-sm p-0.5 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,children:(0,M.jsx)(vt,{size:13})})]}):null,k?(0,M.jsx)(`div`,{className:`fixed inset-0 z-50 grid place-items-center bg-black/60 px-4`,role:`dialog`,"aria-modal":`true`,"aria-label":`Upload pasted image`,onKeyDown:e=>{e.key===`Escape`&&j()},children:(0,M.jsxs)(`div`,{className:`w-full max-w-md rounded-sm border border-slate-700 bg-[#151f24] shadow-2xl`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800 px-4 py-3`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Pasted image detected`}),(0,M.jsx)(`div`,{className:`mt-1 text-xs text-slate-400`,children:`Upload this clipboard image to ~/.pibo/uploads?`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:j,className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":`Cancel pasted image upload`,children:(0,M.jsx)(vt,{size:14})})]}),(0,M.jsxs)(`div`,{className:`space-y-3 px-4 py-4`,children:[(0,M.jsx)(`img`,{src:k.previewUrl,alt:`Pasted clipboard image preview`,className:`max-h-64 w-full rounded-sm border border-slate-800 bg-[#0e1116] object-contain`}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-slate-400`,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate font-mono`,children:k.file.name}),(0,M.jsx)(`span`,{className:`shrink-0 font-mono`,children:VT(k.file.size)})]})]}),(0,M.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-slate-800 px-4 py-3`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:j,className:`h-8 rounded-sm border border-slate-700 px-3 text-xs text-slate-300 hover:border-slate-500 hover:text-slate-100`,children:`Cancel`}),(0,M.jsx)(`button`,{ref:b,type:`button`,onClick:()=>void Ce(),disabled:re,className:`h-8 rounded-sm bg-[#11a4d4] px-3 text-xs font-medium text-white disabled:opacity-50`,children:`Upload image`})]})]})}):null,me.length?(0,M.jsx)(`div`,{className:`absolute left-3 bottom-full mb-2 w-[min(520px,calc(100%-24px))] max-h-72 overflow-auto bg-[#0e1116] border border-emerald-500 rounded-sm shadow-xl`,children:me.map((e,t)=>(0,M.jsxs)(`button`,{ref:t===E?S:null,type:`button`,onClick:()=>ve(e.name),className:`w-full grid grid-cols-[120px_1fr] gap-2 px-3 py-2 text-left border-b border-slate-800 ${t===E?`bg-emerald-500/15`:``}`,children:[(0,M.jsxs)(`span`,{className:`font-mono text-emerald-400`,children:[`$`,e.name]}),(0,M.jsx)(`span`,{className:`text-xs text-slate-400`,children:e.description??e.path??``})]},e.name))}):null,s.length?(0,M.jsxs)(`div`,{className:`mb-2 rounded-sm border border-slate-800 bg-[#0e1116] px-2.5 py-1.5`,"data-pibo-debug":`composer-upload-attachments`,"data-upload-attachment-count":s.length,children:[(0,M.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Attached uploads`}),(0,M.jsx)(`button`,{type:`button`,onClick:m,className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Clear`})]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map(e=>(0,M.jsxs)(`div`,{title:e.path,className:`inline-flex max-w-80 items-center gap-1 rounded-sm border border-emerald-500/45 bg-emerald-500/10 px-2 py-1 text-left text-[11px] text-slate-200`,"data-pibo-debug":`composer-upload-attachment-chip`,"data-upload-path":e.path,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:MT(e.name||e.path,100)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void jT(e.path),title:`Copy uploaded file path`,"aria-label":`Copy uploaded file path`,className:`shrink-0 rounded-sm p-0.5 text-emerald-300 hover:bg-slate-800 hover:text-[#11a4d4]`,children:(0,M.jsx)(We,{size:11})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>p(e.id),title:`Detach ${e.name||e.path}`,"aria-label":`Detach ${e.name||e.path}`,className:`shrink-0 rounded-sm p-0.5 text-emerald-300 hover:bg-slate-800 hover:text-slate-100`,children:(0,M.jsx)(vt,{size:11})})]},e.id))})]}):null,o.length?(0,M.jsxs)(`div`,{className:`mb-2 rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2`,"data-pibo-debug":`composer-web-annotations`,"data-web-annotation-count":o.length,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Attached web annotations`}),(0,M.jsx)(`button`,{type:`button`,onClick:d,className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Clear`})]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:o.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),title:`Detach ${e.id}`,className:`inline-flex max-w-72 items-center gap-1 rounded-sm border border-[#11a4d4]/50 bg-[#11a4d4]/10 px-2 py-1 text-left text-[11px] text-slate-200`,"data-pibo-debug":`composer-web-annotation-chip`,"data-web-annotation-id":e.id,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:MT(e.primaryTarget||e.label||e.note||e.id,100)}),(0,M.jsx)(vt,{size:11,className:`shrink-0 text-[#11a4d4]`})]},e.id))})]}):null,he.length?(0,M.jsx)(`div`,{className:`absolute left-3 bottom-full mb-2 w-[min(520px,calc(100%-24px))] max-h-72 overflow-auto bg-[#0e1116] border border-[#11a4d4] rounded-sm shadow-xl`,children:he.map((e,t)=>(0,M.jsxs)(`button`,{ref:t===w?x:null,type:`button`,onClick:()=>{c(e.slash),ge(FT(e.slash)),T(t)},className:`w-full grid grid-cols-[120px_1fr] gap-2 px-3 py-2 text-left border-b border-slate-800 ${t===w?`bg-[#11a4d4]/15`:``}`,children:[(0,M.jsx)(`span`,{className:`font-mono text-[#11a4d4]`,children:e.slash}),(0,M.jsx)(`span`,{className:`text-xs text-slate-400`,children:e.description})]},e.slash))}):null,(0,M.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-end gap-2`,children:[(0,M.jsx)(`textarea`,{ref:_,"data-pibo-debug":`composer-input`,"data-pibo-session-id":e??void 0,"data-pibo-state":t?`disabled`:i?`non-empty`:`empty`,rows:1,value:i,disabled:t,onChange:e=>{C.current=null,c(e.target.value),O(e.target.selectionStart)},onKeyDown:e=>{if(e.key===`Escape`&&(me.length||he.length)){e.preventDefault(),e.stopPropagation(),_e();return}if(me.length&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){e.preventDefault(),ee(t=>e.key===`ArrowDown`?(t+1)%me.length:(t-1+me.length)%me.length);return}if(he.length&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){e.preventDefault(),T(t=>e.key===`ArrowDown`?(t+1)%he.length:(t-1+he.length)%he.length);return}if((e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&be(e.key===`ArrowUp`?`previous`:`next`)){e.preventDefault();return}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Te())},onPaste:Se,placeholder:t?`Select a session to message`:`Send Message (/ for commands or $ for skills)`,className:`h-10 min-h-10 resize-none overflow-hidden bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm leading-5 outline-none focus:border-[#11a4d4] disabled:opacity-50 [scrollbar-gutter:stable]`}),(0,M.jsx)(`button`,{type:`button`,disabled:t||re,onClick:()=>void Te(),title:`Send message`,"aria-label":`Send message`,className:`h-10 w-10 self-end inline-flex items-center justify-center bg-[#11a4d4] rounded-sm text-white disabled:opacity-50`,children:(0,M.jsx)(mt,{size:16})})]})]})}function PT(e,t){return`skill:${e}:${t}`}function FT(e){return`command:${e}`}function IT(e){let t=Array.from(e.items).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);return(t.length?t:Array.from(e.files).filter(e=>e.type.startsWith(`image/`))).map(LT)}function LT(e){return e.name&&e.name!==`image.png`?e:new File([e],RT(e.type),{type:e.type||`image/png`,lastModified:Date.now()})}function RT(e){let t=zT(e),n=new Date;return`screenshot-${[n.getFullYear(),BT(n.getMonth()+1),BT(n.getDate()),`-`,BT(n.getHours()),BT(n.getMinutes()),BT(n.getSeconds())].join(``)}${t}`}function zT(e){switch(e){case`image/jpeg`:return`.jpg`;case`image/gif`:return`.gif`;case`image/webp`:return`.webp`;case`image/svg+xml`:return`.svg`;default:return`.png`}}function BT(e){return String(e).padStart(2,`0`)}function VT(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:`${(e/(1024*1024)).toFixed(1)} MiB`}function HT(e){if(!e)return;if(!e.value.includes(`
41
- `)&&e.value.length<80){e.style.height=``,e.style.overflowY=`hidden`;return}let t=window.getComputedStyle(e),n=UT(t.lineHeight,20),r=UT(t.borderTopWidth)+UT(t.borderBottomWidth),i=n*5+UT(t.paddingTop)+UT(t.paddingBottom);e.style.height=`auto`;let a=e.scrollHeight,o=a>i;e.style.height=`${Math.min(a,i)+r}px`,e.style.overflowY=o?`auto`:`hidden`,o&&e.selectionStart===e.value.length&&e.selectionEnd===e.value.length&&(e.scrollTop=a)}function UT(e,t=0){let n=Number.parseFloat(e);return Number.isFinite(n)?n:t}var WT=`pibo.chat.webAnnotations.cdpUrl`,GT=`pibo.chat.webAnnotations.selected.`,KT=`pibo.chat.webAnnotations.overlay.`,qT=`pibo.chat.webAnnotations.panelCollapsed`,JT=`pibo.chat.shortcuts.webAnnotationsToggle`,YT=`Alt+Shift+A`;function XT(){try{return localStorage.getItem(WT)??``}catch{return``}}function ZT(e){try{e.trim()?localStorage.setItem(WT,e.trim()):localStorage.removeItem(WT)}catch{}}function QT(){try{return localStorage.getItem(JT)||`Alt+Shift+A`}catch{return YT}}function $T(e){try{return tE(localStorage.getItem(eE(e)))}catch{return null}}function eE(e){return KT+e}function tE(e){if(!e)return null;try{return nE(JSON.parse(e))}catch{return null}}function nE(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.piboSessionId==`string`?t.piboSessionId.trim():``;return n?{bindingId:typeof t.bindingId==`string`?t.bindingId:void 0,piboSessionId:n,installed:t.installed!==!1,active:t.active===!0,toolbarExpanded:t.toolbarExpanded===!0,mode:typeof t.mode==`string`?t.mode:void 0,reason:typeof t.reason==`string`?t.reason:void 0,updatedAt:typeof t.updatedAt==`string`?t.updatedAt:void 0}:null}function rE(e){try{let t=localStorage.getItem(GT+e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`&&!!e.trim()).slice(0,5):[]}catch{return[]}}function iE(e,t){try{let n=GT+e,r=[...new Set(t.filter(e=>e.trim()))].slice(0,5);r.length?localStorage.setItem(n,JSON.stringify(r)):localStorage.removeItem(n)}catch{}}function aE(){try{return localStorage.getItem(qT)===`true`}catch{return!1}}function oE(e){try{localStorage.setItem(qT,String(e))}catch{}}function sE({piboSessionId:e,annotations:t,selectedIds:n,loading:r,error:i,collapsed:a,onRefresh:o,onToggle:s,onClear:c,onCollapse:l,onClose:u}){return e?(0,M.jsxs)(`section`,{className:`border-t border-slate-800 bg-[#101d22] px-3 py-2 sm:px-4`,"data-pibo-debug":`web-annotations-session-panel`,"data-pibo-session-id":e,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web annotations`}),(0,M.jsx)(`span`,{className:`rounded-sm border border-slate-700 px-1.5 py-0.5 text-[10px] text-slate-400`,children:t.length}),n.length?(0,M.jsxs)(`span`,{className:`rounded-sm border border-[#11a4d4]/50 px-1.5 py-0.5 text-[10px] text-[#11a4d4]`,children:[n.length,` attached`]}):null]}),a?null:(0,M.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Global annotation list. Selected attachments are remembered per session.`})]}),(0,M.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:o,disabled:r,title:`Refresh annotations`,"aria-label":`Refresh annotations`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50 sm:h-7 sm:w-7`,"data-pibo-debug":`web-annotations-refresh`,children:(0,M.jsx)(ut,{size:12,className:r?`animate-spin`:void 0})}),(0,M.jsx)(`button`,{type:`button`,onClick:c,disabled:r||!t.length,title:`Clear visible annotations`,"aria-label":`Clear visible annotations`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-red-500 hover:text-red-300 disabled:opacity-50 sm:h-7 sm:w-7`,children:(0,M.jsx)(ht,{size:12})}),(0,M.jsx)(`button`,{type:`button`,onClick:l,title:a?`Expand annotations panel`:`Collapse annotations panel`,"aria-label":a?`Expand annotations panel`:`Collapse annotations panel`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] sm:h-7 sm:w-7`,children:a?(0,M.jsx)(Le,{size:12}):(0,M.jsx)(Fe,{size:12})}),(0,M.jsx)(`button`,{type:`button`,onClick:u,title:`Hide annotations panel`,"aria-label":`Hide annotations panel`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] sm:h-7 sm:w-7`,children:(0,M.jsx)(vt,{size:12})})]})]}),a?null:i?(0,M.jsx)(`div`,{className:`rounded-sm border border-red-900 bg-red-950/40 px-3 py-2 text-xs text-red-200`,"data-pibo-debug":`web-annotations-error`,children:gE(i,220)}):r&&!t.length?(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2 text-xs text-slate-400`,"data-pibo-debug":`web-annotations-loading`,children:`Loading annotations…`}):t.length?(0,M.jsx)(`div`,{className:`mt-2 grid max-h-[min(40svh,18rem)] grid-cols-1 gap-2 overflow-y-auto pr-1 sm:max-h-56 sm:grid-cols-[repeat(auto-fill,minmax(16rem,1fr))]`,"data-pibo-debug":`web-annotations-list`,children:t.map(e=>{let t=n.includes(e.id);return(0,M.jsxs)(`div`,{"data-pibo-debug":`web-annotation-chip`,"data-web-annotation-id":e.id,"data-web-annotation-session-id":e.piboSessionId,"data-web-annotation-selected":t?`true`:`false`,className:`min-w-0 rounded-sm border px-3 py-2 text-xs ${t?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#0e1116]`}`,children:[(0,M.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,M.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-slate-500`,children:[e.status,` · `,e.targetKind]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>s(e.id),className:`inline-flex h-8 shrink-0 items-center gap-1 rounded-sm border px-2 text-[11px] sm:h-6 sm:px-1.5 ${t?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:[t?(0,M.jsx)(vt,{size:11}):(0,M.jsx)(lt,{size:11}),` `,t?`Detach`:`Attach`]})]}),(0,M.jsx)(`div`,{className:`truncate text-slate-200`,title:e.primaryTarget||e.label||e.selector||e.id,children:gE(e.primaryTarget||e.label||e.selector||e.id,120)}),e.piboContext?(0,M.jsx)(`div`,{className:`truncate font-mono text-[11px] text-[#11a4d4]`,title:e.piboContext,children:gE(e.piboContext,140)}):null,(0,M.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:hE(e.url)}),(0,M.jsx)(`div`,{className:`mt-1 line-clamp-2 text-slate-400`,title:e.note,children:gE(e.note,180)}),(0,M.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-600`,children:_E(e.createdAt)})]},e.id)})}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2 text-xs text-slate-500`,"data-pibo-debug":`web-annotations-empty`,children:`No open annotations for this session.`})]}):null}function cE({piboSessionId:e,piboRoomId:t,disabled:n,panelVisible:r,onShowPanel:i,onHidePanel:a,onError:o}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(()=>XT()),[p,m]=(0,v.useState)([]),[h,g]=(0,v.useState)(`idle`),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)(null);(0,v.useEffect)(()=>{n&&c(!1)},[n]),(0,v.useEffect)(()=>{ZT(d)},[d]);let S=async()=>{if(e){g(`loading`),x(null);try{m((await vb(d)).targets.filter(e=>e.type===`page`||e.attachable)),g(`loaded`)}catch(e){let t=pE(e,`CDP unavailable`);m([]),g(`error`),x({kind:`error`,message:t}),o(t)}}},C=async n=>{if(!e)throw Error(`No active session context`);return bb(n.binding.id,uE({piboSessionId:e,piboRoomId:t,cdpUrl:d,annotationShortcut:QT()}))},w=async()=>{if(!(!e||_)){i(),y(!0),x({kind:`info`,message:`Injecting annotation overlay into this Pibo page…`});try{let n=await yb({piboSessionId:e,piboRoomId:t,url:window.location.href,title:document.title,sameOrigin:!0,annotationShortcut:QT()});if(!n.overlay)throw Error(`Overlay config missing from same-origin binding response`);await fE(n.overlay),x({kind:`success`,message:`Annotation overlay is ready on this Pibo page. Open the overlay controls or use the shortcut to start annotating.`}),o(null)}catch(e){let t=pE(e,`Current-page annotation failed`);x({kind:`error`,message:t}),o(t)}finally{y(!1)}}},T=async()=>{if(!e||_)return;i();let n=l.trim();if(!n){x({kind:`error`,message:`URL is required`});return}if(dE(n)){let e=`That looks like a CDP endpoint. Put it in CDP URL, and put the page you want to annotate in Annotate URL.`;x({kind:`error`,message:e}),o(e);return}y(!0),x({kind:`info`,message:`Opening target and injecting overlay…`});try{let r=await yb(uE({piboSessionId:e,piboRoomId:t,url:n,cdpUrl:d})),i=await C(r);x({kind:`success`,message:`Annotation overlay injected for ${mE(i.target??r.target,i.binding.url)}`}),u(``),o(null)}catch(e){let t=pE(e,`Annotation failed`);x({kind:`error`,message:t}),o(t)}finally{y(!1)}},E=async n=>{if(!(!e||_)){i(),y(!0),x({kind:`info`,message:`Binding selected target and injecting overlay…`});try{let r=await C(await yb(uE({piboSessionId:e,piboRoomId:t,targetId:n.id,cdpUrl:d})));x({kind:`success`,message:`Annotation overlay injected for ${mE(r.target??n,r.binding.url)}`}),o(null)}catch(e){let t=pE(e,n.attachable?`Target annotation failed`:`Target not attachable`);x({kind:`error`,message:t}),o(t)}finally{y(!1)}}};return(0,M.jsxs)(`div`,{className:`relative`,"data-pibo-debug":`web-annotations-entry`,"data-pibo-session-id":e??void 0,children:[(0,M.jsx)(lE,{onClick:()=>{n||(c(e=>!e),r||i())},title:n?`Select an active session to annotate a web page`:r?`Web Annotations`:`Show Web Annotations`,ariaLabel:`Web Annotations`,active:s||r,children:(0,M.jsx)(De,{size:14})}),s&&!n?(0,M.jsxs)(`div`,{className:`fixed inset-x-2 bottom-3 z-40 max-h-[calc(100svh-1.5rem)] overflow-y-auto rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-sm shadow-xl sm:absolute sm:inset-auto sm:right-0 sm:top-full sm:bottom-auto sm:mt-2 sm:w-[min(420px,calc(100vw-24px))] sm:max-h-[calc(100svh-5rem)]`,role:`dialog`,"aria-label":`Web Annotations`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web Annotations`}),(0,M.jsx)(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Start an inactive overlay for this Pibo page, or bind a CDP target for external pages.`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:r?a:i,className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":r?`Hide annotation list`:`Show annotation list`,title:r?`Hide annotation list`:`Show annotation list`,children:(0,M.jsx)(ft,{size:14})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":`Close Web Annotations panel`,children:(0,M.jsx)(vt,{size:14})})]})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void w(),disabled:_,className:`mb-3 h-10 w-full rounded-sm bg-emerald-600 px-3 text-xs font-medium text-white hover:bg-emerald-500 disabled:opacity-50 sm:h-9`,"data-pibo-debug":`web-annotations-current-page`,children:`Annotate this Pibo page`}),(0,M.jsx)(`label`,{className:`mb-2 block text-[11px] font-bold uppercase tracking-wider text-slate-500`,htmlFor:`web-annotation-url`,children:`Annotate URL via CDP`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[1fr_auto]`,children:[(0,M.jsx)(`input`,{id:`web-annotation-url`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T()},placeholder:`http://localhost:5173`,disabled:_,className:`h-10 min-w-0 rounded-sm border border-slate-700 bg-[#151f24] px-2 text-base text-slate-100 outline-none focus:border-[#11a4d4] disabled:opacity-60 sm:h-9 sm:text-xs`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void T(),disabled:_||!l.trim(),className:`h-10 rounded-sm bg-[#11a4d4] px-3 text-xs font-medium text-white disabled:opacity-50 sm:h-9`,children:`Annotate`})]}),(0,M.jsx)(`label`,{className:`mt-3 mb-1 block text-[11px] font-bold uppercase tracking-wider text-slate-500`,htmlFor:`web-annotation-cdp-url`,children:`CDP URL (optional)`}),(0,M.jsx)(`input`,{id:`web-annotation-cdp-url`,value:d,onChange:e=>f(e.target.value),placeholder:`Use gateway default`,disabled:_,className:`h-10 w-full rounded-sm border border-slate-800 bg-[#151f24] px-2 font-mono text-base text-slate-300 outline-none focus:border-[#11a4d4] disabled:opacity-60 sm:h-8 sm:text-[11px]`}),(0,M.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-slate-500`,children:`Existing targets`}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>void S(),disabled:_||h===`loading`,className:`inline-flex h-7 items-center gap-1 rounded-sm border border-slate-700 px-2 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[(0,M.jsx)(ut,{size:12,className:h===`loading`?`animate-spin`:void 0}),` Refresh`]})]}),(0,M.jsxs)(`div`,{className:`mt-2 max-h-[min(34svh,14rem)] overflow-auto rounded-sm border border-slate-800 sm:max-h-56`,children:[h===`idle`?(0,M.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`Refresh to list reachable browser targets.`}):null,h===`loading`?(0,M.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-400`,children:`Loading targets…`}):null,h===`loaded`&&!p.length?(0,M.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`No attachable browser targets found.`}):null,p.map(e=>(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 border-b border-slate-800 px-3 py-2 last:border-b-0 sm:grid-cols-[1fr_auto]`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-xs text-slate-200`,title:e.title||e.url,children:gE(e.title||`Untitled target`,120)}),(0,M.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:gE(e.url||e.id,160)})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void E(e),disabled:_||!e.attachable,title:e.attachable?`Attach selected target`:`Target is not attachable`,className:`h-9 rounded-sm border border-slate-700 px-2 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-40 sm:h-8`,children:`Attach`})]},e.id))]}),b?(0,M.jsx)(`div`,{className:`mt-2 rounded-sm border px-2 py-2 text-xs ${b.kind===`error`?`border-red-900 bg-red-950/40 text-red-200`:b.kind===`success`?`border-emerald-900/60 bg-emerald-950/30 text-emerald-300`:`border-slate-700 bg-[#151f24] text-slate-300`}`,children:b.message}):null]}):null]})}function lE({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,M.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function uE(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e&&e.trim()))}function dE(e){try{let t=new URL(e);return t.port===`56663`||t.pathname.startsWith(`/json/`)}catch{return!1}}function fE(e){return new Promise((t,n)=>{let r=window;try{r.__piboWebAnnotations?.remove?.(),r.__piboWebAnnotationConfig=e;let i=document.createElement(`script`);i.src=`/apps/web-annotations/overlay.js?ts=${Date.now()}`,i.async=!0,i.onload=()=>t(),i.onerror=()=>n(Error(`Could not load Web Annotation overlay script`)),document.head.appendChild(i)}catch(e){n(e)}})}function pE(e,t){let n=vE(e);return!n||n===`undefined`?t:/target.*not found|selected cdp target/i.test(n)?`Target not found: ${n}`:/inject|overlay|evaluation/i.test(n)?`Injection failed: ${n}`:/cdp endpoint.*is unreachable|failed to fetch|fetch failed|chrome target discovery|cdp unavailable|econnrefused|connect/i.test(n)?`CDP unavailable: ${n}`:`${t}: ${n}`}function mE(e,t){let n=e?.url||t||e?.title||`target`;return hE(e?.title||n)}function hE(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return gE(e,80)}}function gE(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function _E(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`short`,timeStyle:`short`})}function vE(e){return e instanceof Error?e.message:String(e)}function yE(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function bE(e,t){return{workflowId:e.workflowId,state:SE(e,t),...e.workflowRunId?{workflowRunId:e.workflowRunId}:{}}}function xE({summary:e}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,M.jsxs)(`span`,{className:`min-w-0 max-w-52 truncate rounded border border-[#11a4d4]/35 bg-[#11a4d4]/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-[#11a4d4]`,title:e.workflowId,children:[`workflow `,e.workflowId]}),(0,M.jsxs)(`span`,{className:CE(e.state),children:[`state `,e.state]}),e.workflowRunId?(0,M.jsxs)(`span`,{className:`min-w-0 max-w-40 truncate rounded border border-slate-700 bg-slate-900/40 px-1.5 py-0.5 text-[10px] text-slate-400`,title:e.workflowRunId,children:[`run `,wE(e.workflowRunId)]}):null]})}function SE(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.state?e.state.replace(/_/g,` `):e.workflowRunId?`workflow`:e.kind}function CE(e,t=!1){let n=e.toLowerCase(),r=`shrink-0 rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide`;return t?`${r} border-slate-700 text-slate-500`:n.includes(`failed`)||n.includes(`error`)?`${r} border-red-500/40 text-red-300 bg-red-500/10`:n.includes(`waiting`)?`${r} border-amber-500/40 text-amber-300 bg-amber-500/10`:n.includes(`complete`)||n.includes(`done`)?`${r} border-emerald-500/40 text-emerald-300 bg-emerald-500/10`:`${r} border-[#11a4d4]/40 text-[#11a4d4] bg-[#11a4d4]/10`}function wE(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function TE({title:e,roomLabel:t,headerPiboSessionId:n,piboSessionId:r,piboRoomId:i,webAnnotationsDisabled:a,webAnnotationsPanelRendered:o,workflowHeader:s,sessionViewId:c,sessionViews:l,currentSessionView:u,allowedSessionViewIds:d,showRawEvents:f,showThinking:p,expandThinking:m,onShowWebAnnotationsPanel:h,onHideWebAnnotationsPanel:g,onSelectSessionView:_,onToggleRawEvents:y,onToggleThinking:b,onToggleExpandThinking:x,onError:S}){let[C,w]=(0,v.useState)(null),T=(0,v.useRef)(void 0),E=C===n,ee=(0,v.useMemo)(()=>d?new Set(d):null,[d]);(0,v.useEffect)(()=>()=>{T.current&&window.clearTimeout(T.current)},[]);let D=()=>{n&&(jT(n).catch(()=>void 0),w(n),T.current&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>w(null),900))};return(0,M.jsxs)(`div`,{className:`h-14 px-4 bg-[#151f24] border-b border-slate-800 flex items-center justify-between max-[980px]:h-auto max-[980px]:flex-wrap max-[980px]:py-2 max-[980px]:gap-2`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`h1`,{className:`text-base font-semibold truncate`,children:e}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 font-mono text-[11px] text-slate-500`,children:[(0,M.jsx)(`span`,{className:`truncate`,children:t}),n?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,M.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>void D(),title:E?`Copied Pibo session ID`:`Copy Pibo session ID`,"aria-label":E?`Copied Pibo session ID`:`Copy Pibo session ID`,className:`min-w-0 max-w-48 truncate rounded-sm px-1 font-mono underline-offset-2 transition-colors duration-150 focus:outline-none focus:ring-1 focus:ring-[#11a4d4] ${E?`bg-emerald-500/15 text-emerald-300 ring-1 ring-emerald-400/50`:`text-slate-400 hover:text-[#11a4d4] hover:underline`}`,children:n})]}):null,s?(0,M.jsx)(xE,{summary:s}):null]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(cE,{piboSessionId:r,piboRoomId:i,disabled:a,panelVisible:o,onShowPanel:h,onHidePanel:g,onError:S}),(0,M.jsx)(`div`,{className:`flex items-center rounded-sm border border-slate-700 bg-[#0e1116] p-0.5`,children:l.map(e=>{let t=!!(ee&&!ee.has(e.id));return(0,M.jsx)(`button`,{type:`button`,onClick:()=>{t||_(e.id)},disabled:t,title:t?`Project session routing uses the ${u.label} view for this session kind.`:e.description??e.label,"aria-label":t?`${e.label} view unavailable for this Project session kind`:`Switch to ${e.label} view`,className:`min-w-20 px-2.5 py-1 text-[11px] font-bold tracking-wide max-[980px]:min-w-0 max-[980px]:px-1.5 disabled:cursor-not-allowed disabled:text-slate-600 ${c===e.id?`bg-[#11a4d4]/10 text-[#11a4d4]`:`text-slate-400 hover:text-[#11a4d4] disabled:hover:text-slate-600`}`,children:e.label},e.id)})}),(0,M.jsx)(EE,{onClick:y,title:f?`Hide Raw Events`:`Show Raw Events`,ariaLabel:f?`Hide Raw Events`:`Show Raw Events`,active:f,children:(0,M.jsx)(Ae,{size:14})}),(0,M.jsx)(EE,{onClick:b,title:p?`Hide Thinking`:`Show Thinking`,ariaLabel:p?`Hide Thinking`:`Show Thinking`,active:p,children:p?(0,M.jsx)(ke,{size:14}):(0,M.jsx)(Je,{size:14})}),p?(0,M.jsx)(EE,{onClick:x,title:m?`Collapse Thinking`:`Expand Thinking`,ariaLabel:m?`Collapse Thinking`:`Expand Thinking`,active:m,children:m?(0,M.jsx)(Fe,{size:14}):(0,M.jsx)(Le,{size:14})}):null]})]})}function EE({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,M.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function DE(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&OE(e,n)){e.count+=1,e.createdAt=n.createdAt,e.payload={...jE(e.payload)?e.payload:{},text:`${kE(e.payload)}${kE(n.payload)}`};continue}t.push({...n,count:1})}return t}function OE(e,t){if(e.type!==t.type||e.type!==`assistant_delta`&&e.type!==`thinking_delta`&&e.type!==`TEXT_MESSAGE_CONTENT`&&e.type!==`REASONING_MESSAGE_CONTENT`)return!1;let n=jE(e.payload)?e.payload:{},r=jE(t.payload)?t.payload:{};return AE(n)===AE(r)}function kE(e){return jE(e)?typeof e.text==`string`?e.text:typeof e.delta==`string`?e.delta:``:``}function AE(e){return e.eventId??e.messageId}function jE(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ME({traceView:e,eventLimit:t,isFetching:n,visible:r,onLoadOlder:i}){let a=(0,v.useMemo)(()=>r?DE(e?.rawEvents??[]):[],[e?.rawEvents,r]);return r?(0,M.jsxs)(`aside`,{className:`min-h-0 overflow-auto bg-[#0e1116] border-l border-slate-800 max-[980px]:hidden`,children:[(0,M.jsx)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center text-xs font-bold uppercase tracking-wider`,children:`Raw Events`}),(0,M.jsxs)(`div`,{className:`p-3 flex flex-col gap-2`,children:[e&&a.length>=t?(0,M.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`mb-1 rounded-sm border border-slate-700 px-2 py-1 text-xs text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:n?`Loading raw events…`:`Load older raw events (${a.length})`}):null,a.slice(-t).reverse().map(e=>(0,M.jsxs)(`div`,{className:`border-l-2 border-[#11a4d4] bg-[#151f24] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[#11a4d4] font-mono text-[11px] mb-1`,children:[(0,M.jsx)(`span`,{children:e.type}),e.count>1?(0,M.jsxs)(`span`,{className:`text-slate-500`,children:[`x`,e.count]}):null]}),(0,M.jsx)(Sc,{value:e.payload,showControls:!1})]},e.id))]})]}):null}function NE({traceView:e,eventLimit:t,isFetching:n,onLoadOlder:r}){if(!e?.hasOlderEvents)return null;let i=Math.min(e.eventLimit??t,e.eventCount??t),a=e.eventCount??`many`;return(0,M.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-2 text-center`,children:(0,M.jsx)(`button`,{type:`button`,onClick:r,disabled:n,className:`rounded-sm border border-slate-700 px-3 py-1 text-xs text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:n?`Loading history…`:`Load older trace history (${i} of ${a} events)`})})}function PE({selectedPiboSessionId:e,selectedRoomId:t,fallbackRoomId:n,sessionViewId:r,loadingTrace:i,traceError:a,showRawEvents:o,currentTraceView:s,traceEventLimit:c,rawEventLimit:l,tracePageFetching:u,onLoadOlderTracePage:d,onLoadMoreRawEvents:f,headerProps:p,projectSessionCreatePanel:m,workflowStartPanel:h,currentSessionView:g,sessionViewProps:_,webAnnotationsPanelRendered:v,webAnnotationsPanelProps:y,composerProps:b}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`main`,{"data-pibo-debug":`chat-shell`,"data-pibo-session-id":e??void 0,"data-pibo-room-id":t??n??void 0,"data-pibo-view-id":r,"data-pibo-state":i?`loading`:a?`error`:e?`ready`:`empty`,className:`min-h-0 flex flex-col`,children:[(0,M.jsx)(TE,{...p}),m?(0,M.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:m}):null,h?(0,M.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:h}):null,(0,M.jsx)(NE,{traceView:s,eventLimit:c,isFetching:u,onLoadOlder:()=>d(s?.nextBeforeSequence)}),a&&!s?(0,M.jsx)(`div`,{className:`min-h-0 flex-1 p-4 text-sm text-red-200`,children:a}):g.render(_),v?(0,M.jsx)(sE,{...y}):null,(0,M.jsx)(NT,{...b})]}),(0,M.jsx)(ME,{traceView:s,eventLimit:l,isFetching:u,visible:o,onLoadOlder:f})]})}function FE(e){let t=new Map;if(BE(e.nodes,t),!t.size)return e;let{nodes:n,changed:r}=VE(e.nodes,t);return r?{...e,nodes:n}:e}function IE(e){return e.some(zE)}function LE(e){let t=new Map;return UE(e,e=>{if(e.type!==`user.message`||!e.entryId)return;let n=WE(e),r=t.get(n);r?r.push(e.entryId):t.set(n,[e.entryId])}),t}function RE(e,t){if(!t.size)return;let n=new Map;UE(e,e=>{if(e.type!==`user.message`||e.entryId)return;let r=WE(e),i=t.get(r);if(!i?.length)return;let a=n.get(r)??0,o=i[a];o&&(e.entryId=o,n.set(r,a+1))})}function zE(e){let t=e.payload;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&`type`in t&&t.type===`message_queued`&&`source`in t&&t.source===`user`&&`text`in t&&typeof t.text==`string`)}function BE(e,t){for(let n of e){if(n.type===`user.message`&&!HE(n)){let e=WE(n);e&&t.set(e,(t.get(e)??0)+1)}BE(n.children,t)}}function VE(e,t){let n=!1,r=[];for(let i of e){if(HE(i)){let e=WE(i),r=e?t.get(e)??0:0;if(r>0){t.set(e,r-1),n=!0;continue}}let e=VE(i.children,t);n||=e.changed,r.push(e.changed?{...i,children:e.nodes}:i)}return{nodes:n?r:e,changed:n}}function HE(e){return e.type===`user.message`?e.source===`event-log`&&e.id.startsWith(`event:message_queued:`)?!0:[e.id,e.stableKey,e.eventId].filter(e=>typeof e==`string`).some(e=>e.startsWith(`optimistic:user-message:`)||e.includes(`:optimistic:user-message:`)):!1}function UE(e,t){for(let n of e)t(n),UE(n.children,t)}function WE(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function GE({selectedPiboSessionId:e,reconciledBaseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:i,now:a}){if(!e||t?.piboSessionId!==e)return{traceView:null};let o=n?.piboSessionId===e?n.events:[];if(!o.length)return{traceView:t};let s=a?.(),c=CS(t,o,r??`idle`),l=IE(o);return l&&RE(c.nodes,i),{traceView:l?FE(c):c,liveTraceComputeDurationMs:s!==void 0&&a?a()-s:void 0}}function KE(e,t){for(let n of e)t(n),KE(n.children,t)}function qE(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function JE(e){if(!e)return;let t=0;return KE(e.nodes,e=>{e.type===`assistant.message`&&(t+=qE(e).length)}),t}function YE({selectedPiboSessionId:e,baseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r}){let i=(0,v.useMemo)(()=>t?FE(t):null,[t]),a=(0,v.useMemo)(()=>i?LE(i.nodes):new Map,[i]),o=(0,v.useMemo)(()=>GE({selectedPiboSessionId:e,reconciledBaseTraceView:i,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:a,now:pv()?()=>performance.now():void 0}),[n,e,r,i,a]),s=o.traceView;return(0,v.useEffect)(()=>{!e||!s?.piboSessionId||!pv()||(Sv(s.piboSessionId,{overlayEventCount:n?.piboSessionId===s.piboSessionId?n.events.length:0,traceBaseOutputLength:JE(t),currentOutputLength:JE(s)}),o.liveTraceComputeDurationMs!==void 0&&yv(s.piboSessionId,o.liveTraceComputeDurationMs))},[t,o.liveTraceComputeDurationMs,s,n,e]),(0,v.useEffect)(()=>{let e=()=>{!s?.piboSessionId||!Ny()||Ly(s.piboSessionId,`tab:${document.visibilityState}`,s.nodes,{traceVersion:s.version,latestStreamId:s.latestStreamId,lastRawEventId:s.rawEvents.at(-1)?.id})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[s]),s}var XE=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},ZE=new class extends XE{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},QE={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},$E=new class{#e=QE;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function eD(e){setTimeout(e,0)}var tD=typeof window>`u`||`Deno`in globalThis;function nD(){}function rD(e){return typeof e==`number`&&e>=0&&e!==1/0}function iD(e,t){return Math.max(e+(t||0)-Date.now(),0)}function aD(e,t){return typeof e==`function`?e(t):e}function oD(e,t){return typeof e==`function`?e(t):e}var sD=Object.prototype.hasOwnProperty;function cD(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=uD(e)&&uD(t);if(!r&&!(dD(e)&&dD(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:sD.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=cD(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function lD(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function uD(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function dD(e){if(!fD(e))return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(!fD(n)||!n.hasOwnProperty(`isPrototypeOf`)||Object.getPrototypeOf(e)!==Object.prototype)}function fD(e){return Object.prototype.toString.call(e)===`[object Object]`}function pD(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:cD(e,t)}function mD(e,t){return typeof e==`function`?e(...t):!!e}var hD=(()=>{let e=()=>tD;return{isServer(){return e()},setIsServer(t){e=t}}})();function gD(){let e,t,n=new Promise((n,r)=>{e=n,t=r});n.status=`pending`,n.catch(()=>{});function r(e){Object.assign(n,e),delete n.resolve,delete n.reject}return n.resolve=t=>{r({status:`fulfilled`,value:t}),e(t)},n.reject=e=>{r({status:`rejected`,reason:e}),t(e)},n}var _D=eD;function vD(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=_D,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var yD=vD(),bD=new class extends XE{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function xD(e){return(e??`online`)===`online`?bD.isOnline():!0}function SD(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:xD(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}var CD=class extends XE{constructor(e,t){super(),this.options=t,this.#e=e,this.#s=null,this.#o=gD(),this.bindMethods(),this.setOptions(t)}#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),TD(this.#t,this.options)?this.#h():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return ED(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return ED(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof oD(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!lD(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&DD(this.#t,n,this.options,t)&&this.#h(),this.updateResult(),r&&(this.#t!==n||oD(this.options.enabled,this.#t)!==oD(t.enabled,this.#t)||aD(this.options.staleTime,this.#t)!==aD(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||oD(this.options.enabled,this.#t)!==oD(t.enabled,this.#t)||i!==this.#p)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return kD(this,n)&&(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),n===`promise`&&(this.trackProp(`data`),!this.options.experimental_prefetchInRender&&this.#o.status===`pending`&&this.#o.reject(Error(`experimental_prefetchInRender feature flag is not enabled`))),Reflect.get(e,n))})}trackProp(e){this.#m.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t);return n.fetch().then(()=>this.createResult(n,t))}fetch(e){return this.#h({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#h(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(nD)),t}#g(){this.#b();let e=aD(this.options.staleTime,this.#t);if(hD.isServer()||this.#r.isStale||!rD(e))return;let t=iD(this.#r.dataUpdatedAt,e)+1;this.#d=$E.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return(typeof this.options.refetchInterval==`function`?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(e){this.#x(),this.#p=e,!(hD.isServer()||oD(this.options.enabled,this.#t)===!1||!rD(this.#p)||this.#p===0)&&(this.#f=$E.setInterval(()=>{(this.options.refetchIntervalInBackground||ZE.isFocused())&&this.#h()},this.#p))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#d!==void 0&&($E.clearTimeout(this.#d),this.#d=void 0)}#x(){this.#f!==void 0&&($E.clearInterval(this.#f),this.#f=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&TD(e,t),o=i&&DD(e,n,t,r);(a||o)&&(l={...l,...SD(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#u?.state.data,this.#u):t.placeholderData,e!==void 0&&(m=`success`,d=pD(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h)if(i&&d===a?.data&&t.select===this.#c)d=this.#l;else try{this.#c=t.select,d=t.select(d),d=pD(i?.data,d,t),this.#l=d,this.#s=null}catch(e){this.#s=e}this.#s&&(f=this.#s,d=this.#l,p=Date.now(),m=`error`);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0,x={status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:OD(e,t),refetch:this.refetch,promise:this.#o,isEnabled:oD(t.enabled,e)!==!1};if(this.options.experimental_prefetchInRender){let t=x.data!==void 0,r=x.status===`error`&&!t,i=e=>{r?e.reject(x.error):t&&e.resolve(x.data)},a=()=>{i(this.#o=x.promise=gD())},o=this.#o;switch(o.status){case`pending`:e.queryHash===n.queryHash&&i(o);break;case`fulfilled`:(r||x.data!==o.value)&&a();break;case`rejected`:(!r||x.error!==o.reason)&&a();break}}return x}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#u=this.#t),!lD(t,e)&&(this.#r=t,this.#C({listeners:(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#m.size)return!0;let r=new Set(n??this.#m);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})()}))}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}#C(e){yD.batch(()=>{e.listeners&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}};function wD(e,t){return oD(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status===`error`&&oD(t.retryOnMount,e)===!1)}function TD(e,t){return wD(e,t)||e.state.data!==void 0&&ED(e,t,t.refetchOnMount)}function ED(e,t,n){if(oD(t.enabled,e)!==!1&&aD(t.staleTime,e)!==`static`){let r=typeof n==`function`?n(e):n;return r===`always`||r!==!1&&OD(e,t)}return!1}function DD(e,t,n,r){return(e!==t||oD(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&OD(e,n)}function OD(e,t){return oD(t.enabled,e)!==!1&&e.isStaleByTime(aD(t.staleTime,e))}function kD(e,t){return!lD(e.getCurrentResult(),t)}var AD=v.createContext(void 0),jD=e=>{let t=v.useContext(AD);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},MD=v.createContext(!1),ND=()=>v.useContext(MD);MD.Provider;function PD(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var FD=v.createContext(PD()),ID=()=>v.useContext(FD),LD=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?mD(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(t.isReset()||(e.retryOnMount=!1))},RD=e=>{v.useEffect(()=>{e.clearReset()},[e])},zD=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||mD(n,[e.error,r])),BD=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},VD=(e,t)=>e.isLoading&&e.isFetching&&!t,HD=(e,t)=>e?.suspense&&t.isPending,UD=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function WD(e,t,n){let r=ND(),i=ID(),a=jD(n),o=a.defaultQueryOptions(e);a.getDefaultOptions().queries?._experimental_beforeQuery?.(o);let s=a.getQueryCache().get(o.queryHash);o._optimisticResults=r?`isRestoring`:`optimistic`,BD(o),LD(o,i,s),RD(i);let c=!a.getQueryCache().get(o.queryHash),[l]=v.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&e.subscribed!==!1;if(v.useSyncExternalStore(v.useCallback(e=>{let t=d?l.subscribe(yD.batchCalls(e)):nD;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),v.useEffect(()=>{l.setOptions(o)},[o,l]),HD(o,u))throw UD(o,l,i);if(zD({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return a.getDefaultOptions().queries?._experimental_afterQuery?.(o,u),o.experimental_prefetchInRender&&!hD.isServer()&&VD(u,r)&&(c?UD(o,l,i):s?.promise)?.catch(nD).finally(()=>{l.updateResult()}),o.notifyOnChangeProps?u:l.trackResult(u)}function GD(e,t){return WD(e,CD,t)}var KD=1e4,qD=30*6e4,JD=2e3;function YD(e){return[`chat`,`trace-summary`,e]}function XD(e,t={}){let n=t.pageSize??t.eventLimit??2e3;return[`chat`,`trace-page`,e,t.includeRawEvents?`raw`:`compact`,t.rawEventsLimit??80,n,t.beforeSequence===void 0?`tail`:String(t.beforeSequence)]}function ZD(e,t){if(!e||e.piboSessionId!==t.piboSessionId)return e;let n=t.latestStreamId,r=$D(t),i=QD(t.nodes),a=e.events.filter(e=>{if(n!==void 0&&e.streamId!==void 0&&e.streamId<=n||zE(e)&&i.has(e.payload.text))return!1;let t=tO(e);return!t||!r.has(t)});return a.length?{...e,events:a}:null}function QD(e){let t=new Set;for(let n of e){if(n.type===`user.message`&&n.source===`transcript`){let e=nO(n);e&&t.add(e)}for(let e of QD(n.children))t.add(e)}return t}function $D(e){let t=new Set;for(let n of e.rawEvents){let e=tO(n);e&&t.add(e)}return eO(e.nodes,t),t}function eO(e,t){for(let n of e){if(n.type===`user.message`){let e=n.id.startsWith(`event:message_queued:`)?n.id.slice(21):void 0;e&&t.add(`${n.piboSessionId}:message_queued:${e}`),n.source===`transcript`&&n.entryId&&t.add(`${n.piboSessionId}:message_queued:${n.entryId}`)}n.eventId&&n.type===`assistant.message`&&(t.add(`${n.piboSessionId}:assistant_delta:${n.eventId}`),t.add(`${n.piboSessionId}:assistant_message:${n.eventId}`)),n.eventId&&n.type===`model.reasoning`&&(t.add(`${n.piboSessionId}:thinking_delta:${n.eventId}`),t.add(`${n.piboSessionId}:thinking_finished:${n.eventId}`)),eO(n.children,t)}}function tO(e){let t=e.payload;if(!t||typeof t!=`object`||Array.isArray(t))return;let n=`eventId`in t&&typeof t.eventId==`string`?t.eventId:e.eventId,r=`piboSessionId`in t&&typeof t.piboSessionId==`string`?t.piboSessionId:e.piboSessionId;if(!(!n||!r))return`${r}:${e.type}:${n}`}function nO(e){return typeof e.output==`string`?e.output:e.output&&typeof e.output==`object`&&`text`in e.output&&typeof e.output.text==`string`?e.output.text:``}function rO(e,t){if(e.piboSessionId!==t.piboSessionId)return e;let n=new Set,r=[...t.nodes,...e.nodes].filter(e=>n.has(e.id)?!1:(n.add(e.id),!0)),i=new Set,a=[...t.rawEvents,...e.rawEvents].filter(e=>{let t=e.id||`${e.eventSequence??``}:${e.type}:${e.createdAt}`;return i.has(t)?!1:(i.add(t),!0)});return{...e,version:e.version,nodes:r,rawEvents:a,firstEventSequence:t.firstEventSequence??e.firstEventSequence,nextBeforeSequence:t.nextBeforeSequence,hasOlderEvents:t.hasOlderEvents,eventLimit:(e.eventLimit??0)+(t.eventLimit??t.pageSize??0)}}function iO({selectedPiboSessionId:e,showRawEvents:t,setLiveTraceOverlay:n}){let r=jD(),[i,a]=(0,v.useState)(JD),[o,s]=(0,v.useState)(80),[c,l]=(0,v.useState)(null),u=(0,v.useMemo)(()=>e?YD(e):null,[e]),d=(0,v.useMemo)(()=>e?XD(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:JD}):null,[o,e,t]),f=GD({queryKey:u??[`chat`,`trace-summary`,`idle`],queryFn:async()=>{if(!e||!u)throw Error(`Session is required`);let t=r.getQueryData(u),n=await fb(e,t?.version);if(n.notModified&&t)return t;if(!n.summary)throw Error(`Trace summary response missing payload.`);return n.summary},enabled:!!e,staleTime:KD,gcTime:qD,refetchOnWindowFocus:!1,retry:1}),p=GD({queryKey:d??[`chat`,`trace-page`,`idle`,`compact`,o,2e3,`tail`],queryFn:async()=>{if(!e||!d)throw Error(`Session is required`);let n=r.getQueryData(d),i=await pb(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:JD,knownVersion:n?.version});if(i.notModified&&n)return n;if(!i.trace)throw Error(`Trace page response missing payload.`);return i.trace},enabled:!!e,staleTime:KD,gcTime:qD,refetchOnWindowFocus:!1,retry:1});(0,v.useEffect)(()=>{a(JD),s(80),l(null),n(null)},[e,n]),(0,v.useEffect)(()=>{let t=p.data;!t||t.piboSessionId!==e||(pv()&&Sv(t.piboSessionId,{overlayEventCount:0,traceBaseOutputLength:JE(t),traceBaseUpdated:!0}),(0,v.startTransition)(()=>{l(t),n(e=>ZD(e,t))}))},[e,n,p.data]);let m=(0,v.useCallback)(async n=>{if(!e||!n)return;let i=XD(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:JD,beforeSequence:n}),s=await r.fetchQuery({queryKey:i,queryFn:async()=>{let a=r.getQueryData(i),s=await pb(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:JD,beforeSequence:n,knownVersion:a?.version});if(s.notModified&&a)return a;if(!s.trace)throw Error(`Trace page response missing payload.`);return s.trace},staleTime:KD,gcTime:qD});(0,v.startTransition)(()=>{l(e=>e?rO(e,s):s),a(e=>e+(s.pageSize??2e3))})},[r,o,e,t]),h=(0,v.useCallback)(()=>{s(e=>e+80)},[]);return{baseTraceView:c,traceEventLimit:i,rawEventLimit:o,traceSummaryQuery:f,tracePageQuery:p,tracePageReady:!!d,loadOlderTracePage:m,loadMoreRawEvents:h}}function aO(e){let t=e.currentEvents,n,r,i=()=>(r??=new Set(t.map(dO)),r),a=e=>{n??=t.slice(),n.push(e),t=n};for(let o of e.streamEvents){let s=cO(o,e.piboSessionId,e.nextSequence,e.now??(()=>new Date().toISOString()));if(!s)continue;if(oO(s)){t=sO(t,s),n=t,r=void 0;continue}let c=dO(s),l=i();l.has(c)||(l.add(c),a(s))}return t}function oO(e){return e.type===`assistant_message`||e.type===`thinking_finished`||e.type===`tool_execution_finished`}function sO(e,t){return t.type===`assistant_message`?[...uO(e,t,`assistant_delta`),t]:t.type===`thinking_finished`?[...uO(e,t,`thinking_delta`),t]:t.type===`tool_execution_finished`?[...uO(e,t,`tool_execution_updated`),t]:e}function cO(e,t,n,r){if(e.type===`RAW_EVENT`&&mO(e.event)&&typeof e.event.type==`string`){let i=e.event;return lO(e,t,e.event.type,i,n,r)}if(e.type===`TEXT_MESSAGE_CONTENT`&&typeof e.delta==`string`)return lO(e,t,`assistant_delta`,{type:`assistant_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...pO(typeof e.messageId==`string`?e.messageId:void 0,`assistant`),text:e.delta},n,r);if(e.type===`REASONING_MESSAGE_CONTENT`&&typeof e.delta==`string`)return lO(e,t,`thinking_delta`,{type:`thinking_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...pO(typeof e.messageId==`string`?e.messageId:void 0,`thinking`),text:e.delta},n,r);if(e.type===`TOOL_CALL_START`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return lO(e,t,`tool_execution_started`,{type:`tool_execution_started`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args},n,r);if(e.type===`TOOL_CALL_ARGS`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`){let i=typeof e.runId==`string`?e.runId:void 0,a=e.sourceEventType===`tool_execution_updated`?`tool_execution_updated`:`tool_call`;return lO(e,t,a,a===`tool_execution_updated`?{type:`tool_execution_updated`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,partialResult:e.partialResult}:{type:`tool_call`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,argsComplete:!!e.argsComplete},n,r)}if(e.type===`TOOL_CALL_RESULT`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return lO(e,t,`tool_execution_finished`,{type:`tool_execution_finished`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,toolCallId:e.toolCallId,toolName:e.toolName,result:e.result,isError:!!e.isError},n,r);if(e.type===`RUN_ERROR`&&typeof e.message==`string`)return lO(e,t,`session_error`,{type:`session_error`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,error:e.message,errorDetails:e.errorDetails},n,r)}function lO(e,t,n,r,i,a){let o=typeof e.streamFrameId==`string`?e.streamFrameId:void 0,s=typeof e.streamFrameIndex==`number`?e.streamFrameIndex:void 0,c=typeof e.liveReplayId==`number`&&Number.isFinite(e.liveReplayId)?e.liveReplayId:void 0,l=i();return{id:typeof e.streamId==`number`?`stream:${e.streamId}:${s??`raw`}:${n}`:c===void 0?o?`stream:${o}:${n}`:`live:${l}:${n}`:`live-replay:${c}:${n}`,piboSessionId:t,eventSequence:l,streamId:typeof e.streamId==`number`?e.streamId:void 0,streamFrameIndex:s,eventId:typeof r.eventId==`string`?r.eventId:void 0,type:n,createdAt:a(),payload:r}}function uO(e,t,n){let r=fO(t);return e.filter(e=>e.type!==n||fO(e)!==r)}function dO(e){return e.streamId===void 0?`${e.id}:${e.type}`:e.streamFrameIndex===void 0?`stream:${e.streamId}:${e.id}:${e.type}`:`stream:${e.streamId}:${e.streamFrameIndex}:${e.type}`}function fO(e){let t=mO(e.payload)?e.payload:{},n=typeof t.piboSessionId==`string`?t.piboSessionId:e.piboSessionId??``,r=typeof t.eventId==`string`?t.eventId:e.eventId??``;if(typeof t.toolCallId==`string`)return`${n}:${r}:tool:${t.toolCallId}`;let i=typeof t.assistantIndex==`number`?t.assistantIndex:void 0,a=typeof t.thinkingIndex==`number`?t.thinkingIndex:void 0,o=typeof t.contentIndex==`number`?t.contentIndex:0;return`${n}:${r}:${i??a??o}`}function pO(e,t){let n=e?.match(RegExp(`:${t}:(\\d+)$`));if(!n)return{};let r=Number(n[1]);return Number.isInteger(r)?t===`assistant`?{assistantIndex:r}:{thinkingIndex:r}:{}}function mO(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function hO(e){try{let t=JSON.parse(e.data);if(typeof t.type!=`string`)return;let n=e.lastEventId?cx(e.lastEventId):void 0;return{...t,...e.lastEventId?{streamFrameId:e.lastEventId}:{},...n?{streamId:n.streamId,streamFrameIndex:n.frameIndex}:{}}}catch{return}}function gO(e,t,n){let r=e.get(t);r?.streamId!==void 0&&r.streamId>=n||e.set(t,{streamId:n,frameIndex:2**53-1,cursor:vO(n),exact:!1,...r?.liveReplayId===void 0?{}:{liveReplayId:r.liveReplayId}})}function _O(e,t,n){let r=e.get(t),i=typeof n.liveReplayId==`number`&&Number.isFinite(n.liveReplayId)?Math.max(r?.liveReplayId??0,n.liveReplayId):r?.liveReplayId;if(n.streamId===void 0||n.streamFrameIndex===void 0){i!==void 0&&i!==r?.liveReplayId&&e.set(t,{...r??{exact:!1},liveReplayId:i});return}if(r&&(r.streamId!==void 0&&r.streamId>n.streamId||r.streamId===n.streamId&&r.exact&&r.frameIndex!==void 0&&r.frameIndex>=n.streamFrameIndex)){i!==void 0&&i!==r.liveReplayId&&e.set(t,{...r,liveReplayId:i});return}e.set(t,{streamId:n.streamId,frameIndex:n.streamFrameIndex,cursor:n.streamFrameId??`${n.streamId}:${n.streamFrameIndex}`,exact:!0,...i===void 0?{}:{liveReplayId:i}})}function vO(e){return`${e}:999999`}function yO(e){if(e.type===`RUN_FINISHED`||e.type===`TEXT_MESSAGE_END`)return 300;if(e.type===`RUN_ERROR`)return 0}function bO(e){return e.type===`RUN_STARTED`||e.type===`RUN_FINISHED`||e.type===`RUN_ERROR`||e.type===`TEXT_MESSAGE_END`}function xO(e){return e.type===`TEXT_MESSAGE_CONTENT`||e.type===`REASONING_MESSAGE_CONTENT`||e.type===`TOOL_CALL_START`||e.type===`TOOL_CALL_ARGS`||e.type===`TOOL_CALL_RESULT`||e.type===`RUN_ERROR`||e.type===`RAW_EVENT`}function SO(e,t,n){if(n.type===`RUN_STARTED`||n.type===`RUN_FINISHED`||n.type===`RUN_ERROR`){e.delete(t);return}let r=TO(n);r&&e.get(t)?.delete(r)}function CO(e,t,n){let r=wO(n);if(!r)return!1;let i=e.get(t);return i||(i=new Set,e.set(t,i)),i.has(r)?!1:(i.add(r),!0)}function wO(e){if(e.type===`TEXT_MESSAGE_CONTENT`||e.type===`REASONING_MESSAGE_CONTENT`)return`${e.type}:${e.messageId}`}function TO(e){if(e.type===`TEXT_MESSAGE_START`)return`TEXT_MESSAGE_CONTENT:${e.messageId}`;if(e.type===`REASONING_MESSAGE_START`)return`REASONING_MESSAGE_CONTENT:${e.messageId}`}var EO=500,DO=1e4,OO=45e3,kO=100;function AO({selectedPiboSessionId:e,tracePageData:t,currentTraceView:n,liveEventSeqRef:r,selectedSessionStatus:i,tracePageReady:a,setLiveTraceOverlay:o,onRefreshTrace:s,onRefreshBootstrap:c,onError:l}){let u=(0,v.useRef)(new Map),d=(0,v.useRef)(void 0),f=(0,v.useRef)(void 0),p=(0,v.useRef)(new Map),m=(0,v.useRef)(new Map),h=(0,v.useRef)(null),g=(0,v.useRef)(void 0),_=(0,v.useRef)(0),[y,b]=(0,v.useState)(0);(0,v.useEffect)(()=>{let n=t;if(!n||n.piboSessionId!==e)return;let i=n.rawEvents.map(e=>e.eventSequence??0).reduce((e,t)=>Math.max(e,t),0);r.current=Math.max(r.current,i+1),n.latestStreamId!==void 0&&gO(m.current,n.piboSessionId,n.latestStreamId)},[r,e,t]);let x=(0,v.useCallback)(e=>{let t=u.current.get(e);t?.length&&(o(n=>{let i=aO({currentEvents:n?.piboSessionId===e?n.events:[],streamEvents:t,piboSessionId:e,nextSequence:()=>r.current++});return vv(e,t.length,i.length),{piboSessionId:e,events:i}}),u.current.delete(e))},[]),S=(0,v.useCallback)(()=>{if(!(d.current!==void 0||f.current!==void 0||!e)){if(document.hidden){f.current=setTimeout(()=>{f.current=void 0,x(e)},kO);return}d.current=requestAnimationFrame(()=>{d.current=void 0,x(e)})}},[x,e]),C=(0,v.useCallback)((t,n,r=!1)=>{SO(p.current,t,n);let i=r||CO(p.current,t,n),a=u.current.get(t)??[];a.push(n),u.current.set(t,a),_v(t,n,a.length,i),i||t!==e?x(t):S()},[x,S,e]);(0,v.useEffect)(()=>()=>{d.current!==void 0&&cancelAnimationFrame(d.current),f.current!==void 0&&clearTimeout(f.current),g.current!==void 0&&clearTimeout(g.current)},[]);let w=(0,v.useCallback)((e,t)=>{_O(m.current,e,t)},[]),T=(0,v.useCallback)((e=0)=>{if(g.current!==void 0){if(e>0)return;clearTimeout(g.current)}g.current=setTimeout(()=>{g.current=void 0,b(e=>e+1)},e)},[]),E=(0,v.useCallback)(()=>{if(!e)return;x(e),s().catch(e=>l(jO(e))),c().catch(e=>l(jO(e)));let t=h.current;(!t||t.piboSessionId!==e||t.events.readyState===2||Date.now()-t.lastActivityAt>OO)&&T()},[x,l,c,s,T,e]);(0,v.useEffect)(()=>{if(!e||!a||!n||n.piboSessionId!==e)return;let t=new URLSearchParams({piboSessionId:e});t.set(`mode`,`live`);let r=m.current.get(e),i=r?.cursor??(n.latestStreamId===void 0?void 0:vO(n.latestStreamId));i!==void 0&&t.set(`since`,i),r?.liveReplayId!==void 0&&t.set(`liveSince`,String(r.liveReplayId));let o=new EventSource(`/api/chat/events?${t.toString()}`),u=Date.now();h.current={piboSessionId:e,events:o,openedAt:u,lastActivityAt:u};let d=!1,f,p,v=!1,y=!1,b=(t,n=!1)=>{if(f){if(!n)return;clearTimeout(f)}xv(e,t),f=setTimeout(()=>{f=void 0,s().catch(e=>l(jO(e)))},t)},S=()=>{if(v){y=!0;return}v=!0,c().catch(e=>l(jO(e))).finally(()=>{v=!1,y&&(y=!1,E(250,!0))})},E=(e,t=!1)=>{if(p){if(!t)return;clearTimeout(p)}p=setTimeout(()=>{p=void 0,S()},e)},ee=()=>{E(900,!0)};return o.onopen=()=>{_.current=0,g.current!==void 0&&(clearTimeout(g.current),g.current=void 0),mv(e,o.readyState);let t=h.current;t?.events===o&&(t.lastActivityAt=Date.now())},o.onerror=()=>{if(d)return;hv(e,o.readyState);let t=h.current;t?.events===o&&(t.lastErrorAt=Date.now());let n=_.current++;T(Math.min(DO,EO*2**n))},o.addEventListener(`pibo`,t=>{if(d)return;let n=hO(t);if(!n)return;let r=n.piboSessionId||e,i=h.current;if(i?.events===o&&(i.lastActivityAt=Date.now()),w(r,n),gv(r,n,t.lastEventId,o.readyState),r===e&&n.type===`ready`&&n.liveReplay?.missed&&b(0,!0),Cv(n))return;let a=n.type!==`TEXT_MESSAGE_CONTENT`&&n.type!==`REASONING_MESSAGE_CONTENT`;r===e&&xO(n)&&C(r,n,a);let s=yO(n);r===e&&s!==void 0?b(s,!0):r===e&&n.type!==`ready`&&n.type!==`RAW_EVENT`&&b(1500,!0),bO(n)&&(n.type===`RUN_FINISHED`||n.type===`RUN_ERROR`||n.type===`TEXT_MESSAGE_END`?ee():E(r===e?0:150))}),()=>{d=!0,f&&clearTimeout(f),p&&clearTimeout(p),x(e),h.current?.events===o&&(h.current=null),o.close()}},[n?.piboSessionId,C,x,l,c,s,w,T,y,e,a]),(0,v.useEffect)(()=>{n?.piboSessionId&&x(n.piboSessionId)},[n?.piboSessionId,x]),(0,v.useEffect)(()=>{let e=()=>E(),t=()=>{document.hidden||E()};return window.addEventListener(`focus`,e),window.addEventListener(`online`,e),window.addEventListener(`pageshow`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`online`,e),window.removeEventListener(`pageshow`,e),document.removeEventListener(`visibilitychange`,t)}},[E]),(0,v.useEffect)(()=>{if(!e||i!==`running`)return;let t=window.setInterval(()=>{x(e),s().catch(e=>l(jO(e)))},1e3);return()=>window.clearInterval(t)},[x,l,s,e,i])}function jO(e){return e instanceof Error?e.message:String(e)}var MO=10;function NO(e,t,n,r){if(!t||!n.length)return e;let i=e[t]??[],a=new Set(i.map(e=>e.path)),o=n.filter(e=>e.path&&!a.has(e.path)).map(e=>({...e,id:r()}));return o.length?{...e,[t]:[...i,...o].slice(0,MO)}:e}function PO(e,t,n){if(!t)return e;let r=e[t]??[],i=r.filter(e=>e.id!==n);return i.length===r.length?e:{...e,[t]:i}}function FO(e,t){return!t||!e[t]?.length?e:{...e,[t]:[]}}function IO(e,t){let[n,r]=(0,v.useState)({});return{selectedUploadAttachments:(0,v.useMemo)(()=>e?n[e]??[]:[],[e,n]),attachUploadedFiles:(0,v.useCallback)(n=>{r(r=>NO(r,e,n,t))},[t,e]),detachUploadAttachment:(0,v.useCallback)(t=>{r(n=>PO(n,e,t))},[e]),clearSelectedUploadAttachments:(0,v.useCallback)(()=>{r(t=>FO(t,e))},[e])}}function LO({selectedPiboSessionId:e,onError:t,formatError:n}){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(()=>e?$T(e):null),[l,u]=(0,v.useState)(()=>aE()),[d,f]=(0,v.useState)(!1),p=!!(e&&s?.piboSessionId===e&&s.installed),m=!!e&&(a||p),h=GD({queryKey:[`web-annotations`,`app`,e],queryFn:async()=>{if(!e)throw Error(`Session is required`);return gb(e,{limit:100,scope:`app`})},enabled:!!e&&(m||r.length>0),staleTime:1e3,refetchOnWindowFocus:m,refetchInterval:m?5e3:!1,retry:1}),g=h.refetch,_=(0,v.useMemo)(()=>(h.data?.annotations??[]).filter(e=>e.status!==`resolved`&&e.status!==`dismissed`),[h.data?.annotations]),y=(0,v.useMemo)(()=>r.map(e=>_.find(t=>t.id===e)).filter(e=>!!e),[r,_]);(0,v.useEffect)(()=>{i(e?rE(e):[]),c(e?$T(e):null)},[e]),(0,v.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.piboSessionId!==e||(c(e=>t.installed?t:e?.installed&&e.bindingId&&t.bindingId&&e.bindingId!==t.bindingId?e:t),t.installed?g():o(!1))},n=e=>t(nE(e.detail)),r=n=>{n.key===eE(e)&&t(tE(n.newValue))},i=()=>t($T(e));return window.addEventListener(`pibo:web-annotation-overlay-state`,n),window.addEventListener(`storage`,r),window.addEventListener(`focus`,i),document.addEventListener(`visibilitychange`,i),i(),()=>{window.removeEventListener(`pibo:web-annotation-overlay-state`,n),window.removeEventListener(`storage`,r),window.removeEventListener(`focus`,i),document.removeEventListener(`visibilitychange`,i)}},[g,e]),(0,v.useEffect)(()=>{if(!h.data)return;if(!_.length){i(t=>(t.length&&e&&iE(e,[]),t.length?[]:t));return}let t=new Set(_.map(e=>e.id));i(n=>{let r=n.filter(e=>t.has(e));return r.length!==n.length&&e&&iE(e,r),r.length===n.length?n:r})},[e,_,h.data]),(0,v.useEffect)(()=>{let e=()=>{o(!0),g()};return window.addEventListener(`pibo:web-annotation-saved`,e),()=>window.removeEventListener(`pibo:web-annotation-saved`,e)},[g]);let b=(0,v.useCallback)(t=>{i(n=>{let r=t(n);return e&&iE(e,r),r})},[e]),x=(0,v.useCallback)(e=>{b(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].slice(0,5))},[b]),S=(0,v.useCallback)(()=>b(()=>[]),[b]);return{selectedWebAnnotationIds:r,selectedWebAnnotations:y,visibleWebAnnotations:_,webAnnotationsPanelCollapsed:l,webAnnotationsPanelRendered:m,webAnnotationsPanelVisible:a,webAnnotationsQuery:h,clearingWebAnnotations:d,setWebAnnotationsPanelVisible:o,toggleWebAnnotationAttachment:x,detachWebAnnotationAttachment:(0,v.useCallback)(e=>{b(t=>t.filter(t=>t!==e))},[b]),clearSelectedWebAnnotationAttachments:S,toggleWebAnnotationsPanelCollapsed:(0,v.useCallback)(()=>{u(e=>{let t=!e;return oE(t),t})},[]),clearVisibleWebAnnotations:(0,v.useCallback)(async()=>{if(!(!_.length||d)&&window.confirm(`Dismiss ${_.length} visible web annotations? This keeps sent messages but clears the annotation list.`)){f(!0);try{await Promise.all(_.map(e=>_b(e.id,{piboSessionId:e.piboSessionId,status:`dismissed`,summary:`Cleared from Chat Web UI`}))),S(),await g()}catch(e){t(n(e,`Could not clear web annotations`))}finally{f(!1)}}},[d,S,n,t,g,_])}}function RO(e,t){return t?{sessionBreadcrumbs:UO(e,t),originSession:VO(e,t),derivedSessions:HO(e,t)}:{sessionBreadcrumbs:[],originSession:void 0,derivedSessions:[]}}function zO(e){let t=e.selectedPiboSessionId?S(e.bootstrap.sessions,e.selectedPiboSessionId):void 0,n=qO(e.currentTraceView);return KO(e.selectedSessionActiveModel,e.bootstrap.runtimeStatus?.thinkingLevel??n.level??WO(e.bootstrap,e.selectedSessionProfile,!!t?.parentId),e.bootstrap.runtimeStatus?.fastMode??n.fast??GO(e.bootstrap,e.selectedSessionProfile,!!t?.parentId)??!1)}function BO(e){return{traceView:e.currentTraceView,selectedTrace:null,isLoading:e.isLoading,showThinking:e.showThinking,expandThinking:e.expandThinking,sessionAgentProfile:e.selectedSessionProfile,sessionActiveModel:e.sessionActiveModelBadge,selectedSessionStatus:e.selectedSessionStatus,selectedSessionSignal:e.selectedSessionSignal,workflowProjectSession:e.workflowProjectSession,workflowLifecycleEvents:e.workflowLifecycleEvents,sessionNodes:e.sessionNodes,sessionBreadcrumbs:e.sessionLinks.sessionBreadcrumbs,originSession:e.sessionLinks.originSession,derivedSessions:e.sessionLinks.derivedSessions,agentProfiles:e.agentProfiles,sessionProfileChangeDisabled:e.sessionProfileChangeDisabled,onSessionAgentProfileChange:e.onSessionAgentProfileChange,onFork:e.onFork,onOpenSession:e.onOpenSession,onThinkingLevelChange:e.onThinkingLevelChange,onModelChanged:async()=>{await e.onRefreshBootstrap(),await e.onRefreshTrace()},onRefreshBootstrap:e.onRefreshBootstrap,onError:e.onError}}function VO(e,t){let n=S(e,t);if(!n?.originId)return;let r=S(e,n.originId);return{piboSessionId:n.originId,label:r?XO(r,0):n.originId}}function HO(e,t){return S(e,t)?.derivedSessions.map(e=>({piboSessionId:e.piboSessionId,label:ZO(e),profile:e.profile,status:e.status}))??[]}function UO(e,t){return C(e,t).map((e,t)=>({piboSessionId:e.piboSessionId,label:XO(e,t)}))}function WO(e,t,n=!1){let r=e.agents.find(e=>e.name===t),i=e.customAgents.find(e=>e.profileName===t),a=r??i;return n?a?.subagentThinkingLevel??a?.thinkingLevel??e.modelDefaults?.subagentThinking??e.modelDefaults?.thinking:a?.mainThinkingLevel??a?.thinkingLevel??e.modelDefaults?.mainThinking??e.modelDefaults?.thinking}function GO(e,t,n=!1){let r=e.agents.find(e=>e.name===t),i=e.customAgents.find(e=>e.profileName===t),a=r??i;return n?a?.subagentFast??a?.fast??e.modelDefaults?.subagentFast??e.modelDefaults?.fast:a?.mainFast??a?.fast??e.modelDefaults?.mainFast??e.modelDefaults?.fast}function KO(e,t,n){if(e)return[e,t,n?`fast`:void 0].filter(Boolean).join(` `)}function qO(e){let t={};if(!e)return t;for(let n of JO(e.nodes)){if(n.type!==`execution.command`||n.title!==`thinking`&&n.title!==`fast_mode`)continue;let e=n.output&&typeof n.output==`object`?n.output:void 0;t={level:(typeof e?.level==`string`&&YO(e.level)?e.level:void 0)??t.level,fast:n.title===`fast_mode`?e?.mode===`fast`:t.fast}}return t}function JO(e){return e.flatMap(e=>[e,...JO(e.children)])}function YO(e){return AC.includes(e)}function XO(e,t){return t?e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.profile||e.subagentName||e.title:e.profile||e.title}function ZO(e){return e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.title||e.profile||e.subagentName||`Untitled Session`}function QO({piboSessionId:e,text:t,selectedWebAnnotations:n,selectedUploadAttachments:r,eventSequence:i,now:a,clientTxnId:o}){let s=n.map(e=>e.id),c=r.map(e=>e.path);return{text:t,webAnnotationIds:s,fileAttachmentPaths:c,clientTxnId:o,optimisticEvent:{id:o,piboSessionId:e,eventSequence:i,eventId:o,type:`message_queued`,createdAt:a,payload:{type:`message_queued`,piboSessionId:e,eventId:o,clientTxnId:o,queuedMessages:1,text:t,...c.length?{fileAttachmentPaths:c}:{},source:`user`}}}}function $O(e,t,n){return{piboSessionId:t,events:[...e?.piboSessionId===t?e.events:[],n]}}function ek(e){return e instanceof Error?e.message:String(e)}function tk({bootstrap:e,selectedPiboSessionId:t,selectedRoomId:n,selectedRoomArchived:r,selectedSessionProfile:i,selectedSessionActiveModel:a,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,projectSessionCreatePanel:u,workflowStartPanel:d,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,creatingSession:g,showRawEvents:_,showThinking:y,expandThinking:b,commands:x,skills:S,composerText:C,composerFocusSignal:T,onComposerTextChange:E,onToggleRawEvents:ee,onToggleThinking:D,onToggleExpandThinking:O,onSessionAgentProfileChange:te,onFork:ne,onOpenSession:re,onSelectSessionView:ie,onCommand:ae,onThinkingLevelChange:oe,onRefreshTrace:k,onRefreshBootstrap:A,onSend:se,onError:ce}){let le=(0,v.useRef)(0),[ue,de]=(0,v.useState)(null),{baseTraceView:fe,traceEventLimit:pe,rawEventLimit:me,traceSummaryQuery:he,tracePageQuery:ge,tracePageReady:_e,loadOlderTracePage:ve,loadMoreRawEvents:ye}=iO({selectedPiboSessionId:t,showRawEvents:_,setLiveTraceOverlay:de}),{selectedWebAnnotationIds:be,selectedWebAnnotations:xe,visibleWebAnnotations:j,webAnnotationsPanelCollapsed:Se,webAnnotationsPanelRendered:Ce,webAnnotationsPanelVisible:we,webAnnotationsQuery:Te,clearingWebAnnotations:Ee,setWebAnnotationsPanelVisible:De,toggleWebAnnotationAttachment:Oe,detachWebAnnotationAttachment:ke,clearSelectedWebAnnotationAttachments:Ae,toggleWebAnnotationsPanelCollapsed:je,clearVisibleWebAnnotations:Me}=LO({selectedPiboSessionId:t,onError:ce,formatError:pE}),{selectedUploadAttachments:Ne,attachUploadedFiles:Pe,detachUploadAttachment:Fe,clearSelectedUploadAttachments:Ie}=IO(t,(0,v.useCallback)(()=>`upload-${w()}`,[])),Le=YE({selectedPiboSessionId:t,baseTraceView:fe,liveTraceOverlay:ue,selectedSessionStatus:o});AO({selectedPiboSessionId:t,tracePageData:ge.data,currentTraceView:Le,liveEventSeqRef:le,selectedSessionStatus:o,tracePageReady:_e,setLiveTraceOverlay:de,onRefreshTrace:k,onRefreshBootstrap:A,onError:ce});let Re=zO({bootstrap:e,selectedPiboSessionId:t,selectedSessionProfile:i,selectedSessionActiveModel:a,currentTraceView:Le}),ze=(0,v.useMemo)(()=>RO(e.sessions,t),[e.sessions,t]),Be=!!t&&ge.isFetching&&!Le,Ve=ge.error?ek(ge.error):he.error?ek(he.error):null,He=Le?.piboSessionId??t??``,Ue=c&&yE(c)?bE(c,o):null,We=async e=>{if(!t)return;let n=QO({piboSessionId:t,text:e,selectedWebAnnotations:xe,selectedUploadAttachments:Ne,eventSequence:le.current++,now:new Date().toISOString(),clientTxnId:w()});de(e=>$O(e,t,n.optimisticEvent)),await se(n.text,n.webAnnotationIds,n.fileAttachmentPaths,n.clientTxnId),Ae(),Ie(),await Promise.all([ge.refetch(),Te.refetch()])},Ge=BO({currentTraceView:Le,isLoading:Be,showThinking:y,expandThinking:b,selectedSessionProfile:i,sessionActiveModelBadge:Re,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,sessionNodes:e.sessions,sessionLinks:ze,agentProfiles:e.agents,sessionProfileChangeDisabled:g||r,onSessionAgentProfileChange:te,onFork:ne,onOpenSession:re,onThinkingLevelChange:oe,onRefreshTrace:k,onRefreshBootstrap:A,onError:ce});return(0,M.jsx)(PE,{selectedPiboSessionId:t,selectedRoomId:n,fallbackRoomId:e.selectedRoomId??void 0,sessionViewId:f,loadingTrace:Be,traceError:Ve,showRawEvents:_,currentTraceView:Le,traceEventLimit:pe,rawEventLimit:me,tracePageFetching:ge.isFetching,onLoadOlderTracePage:e=>void ve(e),onLoadMoreRawEvents:ye,headerProps:{title:Le?.title??t??e.room?.name??n,roomLabel:e.room?.name??n??`Room`,headerPiboSessionId:He,piboSessionId:t,piboRoomId:n??e.selectedRoomId??void 0,webAnnotationsDisabled:!t||r,webAnnotationsPanelRendered:Ce,workflowHeader:Ue,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,showRawEvents:_,showThinking:y,expandThinking:b,onShowWebAnnotationsPanel:()=>De(!0),onHideWebAnnotationsPanel:()=>De(!1),onSelectSessionView:ie,onToggleRawEvents:ee,onToggleThinking:D,onToggleExpandThinking:O,onError:ce},projectSessionCreatePanel:u,workflowStartPanel:d,currentSessionView:m,sessionViewProps:Ge,webAnnotationsPanelRendered:Ce,webAnnotationsPanelProps:{piboSessionId:t,annotations:j,selectedIds:be,loading:Te.isLoading||Te.isFetching||Ee,error:Te.error?ek(Te.error):null,collapsed:Se,onRefresh:()=>void Te.refetch(),onToggle:Oe,onClear:()=>void Me(),onCollapse:je,onClose:()=>De(!1)},composerProps:{sessionId:t,disabled:!t||r,commands:x,skills:S,value:C,focusSignal:T,selectedWebAnnotations:xe,selectedUploadAttachments:Ne,onValueChange:E,onCommand:ae,onDetachWebAnnotation:ke,onClearWebAnnotations:Ae,onAttachUploadedFiles:Pe,onDetachUploadAttachment:Fe,onClearUploadAttachments:Ie,onSend:We}})}function nk({mode:e,onSelectSession:t,onNewSession:n,onDeleteSession:r,onRenameSession:i,onSelectRoom:a}){return e.kind===`rooms`?(0,M.jsx)(lk,{candidates:e.candidates,workspace:e.workspace,onSelectRoom:a}):(0,M.jsx)(sk,{sessions:e.sessions,selectedPiboSessionId:e.selectedPiboSessionId,onSelectSession:t,onNewSession:n,onDeleteSession:r,onRenameSession:i})}function rk(e){return e===`running`?`running`:e===`error`?`error`:e===`completed`?`completed`:`idle`}var ik={running:`bg-cyan-400`,idle:`bg-slate-500`,error:`bg-rose-500`,completed:`bg-emerald-500`},ak={running:`running`,idle:`idle`,error:`error`,completed:`completed`};function ok({status:e}){let t=rk(e);return(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] uppercase tracking-wider text-slate-400`,children:[(0,M.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full ${ik[t]}`,"aria-hidden":`true`}),ak[t]]})}function sk({sessions:e,selectedPiboSessionId:t,onSelectSession:n,onNewSession:r,onDeleteSession:i,onRenameSession:a}){let o=[...e].sort((e,t)=>{let n=e.lastActivityAt??``;return(t.lastActivityAt??``).localeCompare(n)});return(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-slate-800 px-3 py-2 bg-[#0c1820]`,"data-testid":`session-list`,children:[(0,M.jsx)(`button`,{type:`button`,className:`shrink-0 w-7 h-7 inline-flex items-center justify-center rounded border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`New session`,onClick:()=>void r(`default`),children:`+`}),(0,M.jsxs)(`ul`,{className:`flex gap-1 overflow-x-auto min-w-0`,children:[o.map(e=>(0,M.jsx)(`li`,{className:`shrink-0`,children:(0,M.jsx)(ck,{session:e,isActive:e.piboSessionId===t,onSelect:()=>n(e.piboSessionId),onDelete:()=>void i(e.piboSessionId),onRename:t=>void a(e.piboSessionId,t)})},e.piboSessionId)),o.length===0&&(0,M.jsx)(`li`,{className:`text-xs text-slate-500 px-2 py-1`,children:`No sessions yet — click + to start one.`})]})]})}function ck({session:e,isActive:t,onSelect:n,onDelete:r,onRename:i}){let[a,o]=(0,v.useState)(!1);return(0,M.jsxs)(`div`,{className:`group inline-flex items-center gap-2 rounded px-2 py-1 border ${t?`border-[#11a4d4] bg-[#102834]`:`border-slate-700 bg-[#0a1418] hover:border-slate-500`}`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-2 text-left`,children:[(0,M.jsx)(ok,{status:e.status}),(0,M.jsx)(`span`,{className:`text-xs text-slate-200 max-w-[180px] truncate`,children:e.title||`Untitled`})]}),(0,M.jsx)(`button`,{type:`button`,className:`text-slate-500 hover:text-slate-200 text-xs px-1`,title:`Session actions`,"aria-label":`Session actions`,onClick:e=>{e.stopPropagation(),o(e=>!e)},children:`…`}),a&&(0,M.jsxs)(`div`,{className:`absolute z-10 mt-12 -ml-20 bg-[#0a1418] border border-slate-700 rounded shadow-lg text-xs`,children:[(0,M.jsx)(`button`,{type:`button`,className:`block w-full text-left px-3 py-1.5 hover:bg-[#102834]`,onClick:t=>{t.stopPropagation(),o(!1);let n=window.prompt(`Rename session`,e.title??``);n&&n!==e.title&&i(n)},children:`Rename`}),(0,M.jsx)(`button`,{type:`button`,className:`block w-full text-left px-3 py-1.5 hover:bg-rose-900/30 text-rose-300`,onClick:t=>{t.stopPropagation(),o(!1),window.confirm(`Delete session "${e.title??`Untitled`}"?`)&&r()},children:`Delete`})]})]})}function lk({candidates:e,workspace:t,onSelectRoom:n}){return(0,M.jsxs)(`div`,{className:`border-b border-slate-800 px-3 py-3 bg-[#0c1820]`,"data-testid":`room-picker`,children:[(0,M.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wider text-slate-400 mb-2`,children:[`Multiple rooms found for `,(0,M.jsx)(`span`,{className:`font-mono text-slate-300`,children:t})]}),(0,M.jsx)(`ul`,{className:`flex flex-col gap-1`,children:e.map(e=>(0,M.jsx)(`li`,{children:(0,M.jsxs)(`button`,{type:`button`,className:`w-full text-left px-3 py-2 border border-slate-700 rounded hover:border-[#11a4d4] bg-[#0a1418]`,onClick:()=>n(e.id),children:[(0,M.jsx)(`div`,{className:`font-semibold text-slate-200 text-sm`,children:e.name}),e.topic&&(0,M.jsx)(`div`,{className:`text-xs text-slate-400 mt-0.5`,children:e.topic}),(0,M.jsxs)(`div`,{className:`text-[10px] text-slate-500 mt-1`,children:[`Created `,uk(e.createdAt),` · Updated `,uk(e.updatedAt)]})]})},e.id))})]})}function uk(e){try{return new Date(e).toLocaleString()}catch{return e}}function dk(){return new URLSearchParams(window.location.search).get(`workspace`)}function fk(){return new URLSearchParams(window.location.search).get(`roomId`)}function pk(){let e=(0,v.useMemo)(()=>dk(),[]),[t,n]=(0,v.useState)(()=>fk()),[r,i]=(0,v.useState)(()=>fk()?{kind:`sessions`,roomId:fk(),sessions:[],selectedPiboSessionId:null}:{kind:`rooms`,candidates:[],workspace:e??``}),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(0),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(!1),_=(0,v.useMemo)(()=>{let e=a?.sessionNodes;return Array.isArray(e)?e:[]},[a]);(0,v.useEffect)(()=>{if(!t)return;let e=!1;return(async()=>{try{let n=await te(void 0,!1,t);if(e)return;o(n);let r=n.sessions.find(e=>!e.archived)??n.sessions[0];r&&!s&&c(r.piboSessionId),i({kind:`sessions`,roomId:t,sessions:n.sessions,selectedPiboSessionId:r?.piboSessionId??null})}catch(t){e||m(ek(t))}})(),()=>{e=!0}},[t]);let y=(0,v.useCallback)(async()=>{if(t)try{o(await te(s??void 0,!1,t,!0))}catch(e){m(ek(e))}},[t,s]),b=(0,v.useCallback)(async()=>{await y()},[y]);(0,v.useEffect)(()=>{if(!t)return;let e=`/api/chat/events?${new URLSearchParams({roomId:t,mode:`summary`,since:`0:999999`}).toString()}`,n=new EventSource(e),r,i=()=>{r&&clearTimeout(r),r=setTimeout(()=>{r=void 0,y()},200)};return n.addEventListener(`change`,i),n.addEventListener(`trace`,i),n.addEventListener(`message`,i),n.onerror=()=>{},()=>{r&&clearTimeout(r),n.close()}},[t,y]),(0,v.useEffect)(()=>{let e=e=>{let t=e.data;!t||typeof t!=`object`||(t.type===`pibo/set-selector-mode`?(i(t.mode),t.mode.kind===`sessions`&&n(t.mode.roomId)):t.type===`pibo/refresh-bootstrap`&&y())};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[y]);let S=(0,v.useMemo)(()=>a?ee(a.capabilities.actions):[],[a]),C=(0,v.useMemo)(()=>D(a,s),[a,s]),T=(0,v.useMemo)(()=>r.kind===`sessions`?r.sessions:_,[r,_]),E=(0,v.useCallback)(e=>{c(e),f(e=>e+1)},[]),O=(0,v.useCallback)(async e=>{if(t)try{let n=await ne(e,t);await y(),n.session?.id&&c(n.session.id)}catch(e){m(ek(e))}},[t,y]),k=(0,v.useCallback)(async e=>{try{await ie(e,`delete`),await y(),s===e&&c(null)}catch(e){m(ek(e))}},[y,s]),A=(0,v.useCallback)(async(e,t)=>{try{await re(e,{title:t}),await y()}catch(e){m(ek(e))}},[y]),se=(0,v.useCallback)(e=>{n(e),c(null),o(null),i({kind:`sessions`,roomId:e,sessions:[],selectedPiboSessionId:null});let t=new URLSearchParams(window.location.search);t.set(`roomId`,e),window.history.replaceState(null,``,`${window.location.pathname}?${t.toString()}`)},[]),ue=(0,v.useCallback)(async e=>{if(!(!s||!t))try{await ae(s,e,w(),t),u(``),f(e=>e+1),await y()}catch(e){m(ek(e))}},[s,t,y]),de=(0,v.useCallback)(async e=>{if(!s)return!1;let n=e.trim();if(!n)return!1;let r=n.split(/\s+/)[0],i=S.find(e=>e.slash===r);if(!i)return m(`Unknown command: ${r}`),!1;if(i.action===`thinking-show`)return g(e=>!e),!0;if(i.action===`download`){let e=ce(n.slice(r.length));if(!e)return m(`Usage: /download <path>`),!0;try{await fe(e,{piboSessionId:s,roomId:t??void 0})}catch(e){m(ek(e))}return!0}try{let e=le(i.action,n.slice(r.length).trim());await oe(s,i.action,e),await y()}catch(e){m(ek(e))}return!0},[S,s,t,y]),pe=(0,v.useMemo)(()=>TT(),[]),he=(0,v.useMemo)(()=>ET(me),[]);if(!a)return(0,M.jsxs)(`div`,{className:`pibo-vscode-panel h-full flex flex-col bg-[#0c1820] text-slate-200`,children:[(0,M.jsx)(nk,{mode:r,onSelectSession:E,onNewSession:O,onDeleteSession:k,onRenameSession:A,onSelectRoom:se}),(0,M.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-slate-400 text-sm`,children:p?`Error: ${p}`:t?`Loading Pibo…`:`Waiting for room…`})]});if(r.kind===`rooms`)return(0,M.jsxs)(`div`,{className:`pibo-vscode-panel h-full flex flex-col bg-[#0c1820] text-slate-200`,children:[(0,M.jsx)(nk,{mode:{kind:`rooms`,candidates:a.rooms??r.candidates,workspace:r.workspace},onSelectSession:E,onNewSession:O,onDeleteSession:k,onRenameSession:A,onSelectRoom:se}),(0,M.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-slate-400 text-sm`,children:`Multiple rooms found — pick one above to continue.`})]});let ge=a.sessions.find(e=>e.piboSessionId===s);return(0,M.jsxs)(`div`,{className:`pibo-vscode-panel h-full flex flex-col bg-[#0c1820] text-slate-200`,children:[(0,M.jsx)(nk,{mode:{kind:`sessions`,roomId:t??``,sessions:T,selectedPiboSessionId:s},onSelectSession:E,onNewSession:O,onDeleteSession:k,onRenameSession:A,onSelectRoom:se}),p&&(0,M.jsxs)(`div`,{className:`bg-rose-900/40 border-b border-rose-700 text-rose-200 text-xs px-3 py-1.5`,role:`alert`,children:[p,(0,M.jsx)(`button`,{type:`button`,className:`ml-3 underline`,onClick:()=>m(null),children:`dismiss`})]}),(0,M.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,M.jsx)(tk,{bootstrap:a,selectedPiboSessionId:s,selectedRoomId:t,selectedRoomArchived:!1,selectedSessionProfile:ge?.profile??`default`,selectedSessionActiveModel:ge?x(a,ge)??void 0:void 0,selectedSessionStatus:ge?.status,sessionViewId:me,sessionViews:pe,currentSessionView:he,allowedSessionViewIds:[`terminal`],creatingSession:!1,showRawEvents:!1,showThinking:h,expandThinking:!1,commands:S,skills:C,composerText:l,composerFocusSignal:d,onComposerTextChange:u,onToggleRawEvents:()=>void 0,onToggleThinking:()=>g(e=>!e),onToggleExpandThinking:()=>void 0,onSessionAgentProfileChange:()=>void 0,onFork:()=>void 0,onOpenSession:e=>c(e),onSelectSessionView:()=>void 0,onCommand:de,onThinkingLevelChange:e=>void de(`/thinking ${e}`),onRefreshTrace:b,onRefreshBootstrap:y,onSend:ue,onError:m})})]})}var mk=document.getElementById(`root`);mk&&(0,y.createRoot)(mk).render((0,M.jsx)(v.StrictMode,{children:(0,M.jsx)(pk,{})}));
39
+ `).trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))continue;let n=eb(t);if(n!==void 0)return $y(n,r.slice(0,e).join(` `).trim()||void 0)}}function $y(e,t){let n=Hy(e);if(n.kind===`text`){let e=Qy(n.text);return e?.kind===`json`?{...e,meta:e.meta??t}:{kind:`text`,text:n.text}}return{kind:`json`,value:e,meta:t}}function eb(e){if(!(!e.startsWith(`{`)&&!e.startsWith(`[`)))try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}function tb(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function nb({name:e,input:t}){return(0,M.jsxs)(`span`,{className:`compact-terminal-function-call`,children:[(0,M.jsx)(`span`,{className:`text-[#facc15] font-semibold`,children:e}),(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`(`}),t===void 0?null:(0,M.jsx)(rb,{value:t}),(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`)`})]})}function rb({value:e}){let[t,n]=(0,v.useState)(()=>new Set([`$`])),[r,i]=(0,v.useState)(()=>new Set);return(0,M.jsx)(ib,{value:e,path:`$`,expandedPaths:t,expandedStrings:r,onTogglePath:e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onToggleString:e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}})}function ib({value:e,path:t,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a}){if(Array.isArray(e))return(0,M.jsx)(ab,{value:e,path:t,open:`[`,close:`]`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(sb(e))return(0,M.jsx)(ab,{value:e,path:t,open:`{`,close:`}`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(typeof e==`string`){let n=r.has(t),i=e.length>140&&!n,o=i?`${e.slice(0,140)}...`:e,s=(0,M.jsx)(`span`,{className:`text-[#fb923c]`,children:JSON.stringify(o)});return!i&&e.length<=140?s:(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a(t)},className:`compact-terminal-json-toggle text-left align-baseline`,title:n?`Collapse string`:`Expand string`,children:s})}return typeof e==`number`||typeof e==`boolean`||e===null?(0,M.jsx)(`span`,{className:`text-[#60a5fa]`,children:String(e)}):(0,M.jsx)(`span`,{className:`text-[#737373]`,children:JSON.stringify(String(e))})}function ab({value:e,path:t,open:n,close:r,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s}){let c=Array.isArray(e)?e.map((e,t)=>[String(t),e]):Object.entries(e);return i.has(t)?(0,M.jsxs)(`span`,{children:[(0,M.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Collapse JSON`,"aria-label":`Collapse JSON at ${t}`,"data-inline-json-path":t,children:[(0,M.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▾`}),n]}),c.map(([n,r],c)=>{let l=`${t}.${ob(n)}`;return(0,M.jsxs)(`span`,{children:[c>0?(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`, `}):null,Array.isArray(e)?null:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:JSON.stringify(n)}),(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`:`})]}),(0,M.jsx)(ib,{value:r,path:l,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s})]},l)}),(0,M.jsx)(`span`,{className:`text-[#737373]`,children:r})]}):(0,M.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Expand JSON`,"aria-label":`Expand JSON at ${t}`,"data-inline-json-path":t,children:[(0,M.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▸`}),n,`...`,r]})}function ob(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`.`,`\\.`)}function sb(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function cb({line:e,status:t,clampLines:n}){let r=`min-w-0 whitespace-pre-wrap break-words ${n?`block overflow-hidden`:``}`;return(0,M.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,M.jsx)(`span`,{className:`whitespace-pre ${ub(e.prefix,t)}`,children:lb(e.prefix)}),(0,M.jsxs)(`span`,{className:r,style:n?{maxHeight:`${n*1.45}em`}:void 0,children:[e.tokens.map((e,t)=>(0,M.jsx)(`span`,{className:db(e),children:e.text},`${t}:${e.text}`)),e.functionCall?(0,M.jsx)(nb,{name:e.functionCall.name,input:e.functionCall.input}):null]})]})}function lb(e=`none`){switch(e){case`bullet`:return`•`;case`detail`:return`└`;case`continuation`:return` `;case`prompt`:return`›`;default:return` `}}function ub(e=`none`,t){if(e===`bullet`){if(t===`running`)return`text-[#38bdf8]`;if(t===`error`)return`text-[#ef4444]`;if(t===`done`)return`text-[#22c55e]`}return`text-[#737373]`}function db(e){return`${e.tone===`dim`?`text-[#737373]`:e.tone===`cyan`?`text-[#38bdf8]`:e.tone===`green`?`text-[#22c55e]`:e.tone===`red`?`text-[#ef4444]`:e.tone===`magenta`?`text-[#d946ef]`:e.tone===`yellow`?`text-[#facc15]`:e.tone===`blue`?`text-[#60a5fa]`:e.tone===`amber`?`text-[#f59e0b]`:`text-[#d4d4d4]`} ${e.weight===`bold`?`font-bold`:e.weight===`semibold`?`font-semibold`:`font-normal`} ${e.italic?`italic`:``}`.trim()}async function fb(e,t){let n=new URLSearchParams({piboSessionId:e}),r=await fetch(`/api/chat/trace/summary?${n.toString()}`,{headers:t?{"if-none-match":mb(t)}:void 0});if(r.status===304)return{notModified:!0,version:hb(r.headers.get(`etag`))??t};let i=await r.json().catch(()=>void 0);if(!r.ok){let e=i&&typeof i==`object`&&`error`in i?String(i.error):`Request failed`,t=Error(e);throw t.status=r.status,t.data=i,t}return{summary:i,notModified:!1,version:hb(r.headers.get(`etag`))??i.version}}async function pb(e,t={}){let n=new URLSearchParams({piboSessionId:e});t.includeRawEvents&&n.set(`includeRawEvents`,`true`),t.rawEventsLimit&&n.set(`rawEventsLimit`,String(t.rawEventsLimit)),t.pageSize&&n.set(`pageSize`,String(t.pageSize)),t.beforeSequence===void 0?t.eventLimit&&n.set(`eventLimit`,String(t.eventLimit)):n.set(`beforeSequence`,String(t.beforeSequence));let r=await fetch(`/api/chat/trace?${n.toString()}`,{headers:t.knownVersion?{"if-none-match":mb(t.knownVersion)}:void 0});if(r.status===304)return{notModified:!0,version:hb(r.headers.get(`etag`))??t.knownVersion};let i=await r.json().catch(()=>void 0);if(!r.ok){let e=i&&typeof i==`object`&&`error`in i?String(i.error):`Request failed`,t=Error(e);throw t.status=r.status,t.data=i,t}return{trace:i,notModified:!1,version:hb(r.headers.get(`etag`))??i.version}}function mb(e){return`"${e}"`}function hb(e){if(!e)return;let t=e.trim();return t.startsWith(`W/`)?hb(t.slice(2)):t.startsWith(`"`)&&t.endsWith(`"`)?t.slice(1,-1):t}async function gb(e,t={}){let n=new URLSearchParams({piboSessionId:e});return t.status&&n.set(`status`,t.status),t.limit&&n.set(`limit`,String(t.limit)),t.scope&&n.set(`scope`,t.scope),O(`/api/web-annotations?${n.toString()}`)}async function _b(e,t){return O(`/api/web-annotations/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(xb(t))})}async function vb(e){let t=new URLSearchParams;return e?.trim()&&t.set(`cdpUrl`,e.trim()),O(`/api/web-annotations/targets${t.size?`?${t.toString()}`:``}`)}async function yb(e){return O(`/api/web-annotations/bindings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(xb(e))})}async function bb(e,t){return O(`/api/web-annotations/bindings/${encodeURIComponent(e)}/inject`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(xb(t))})}function xb(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``))}async function Sb(e,t,n){return O(`/api/chat/projects/${encodeURIComponent(e)}/workflow-sessions/${encodeURIComponent(t)}/human-actions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)})}function Cb(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function wb(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function Tb(e){return Eb(e)?e.result:e}function Eb(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}var Db={device_code:`Device code`,api_key:`API key`,oauth:`Browser OAuth`};function Ob({row:e,piboSessionId:t}){let n=Cb(e.output)?e.output:void 0,r=(0,v.useMemo)(()=>n?.providers??[],[n?.providers]),[i,a]=(0,v.useState)({type:`select_provider`}),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(null),m=(0,v.useCallback)(()=>{a({type:`select_provider`}),l(``),d(``)},[]),h=(0,v.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),p(e),window.setTimeout(()=>p(t=>t===e?null:t),1600)}catch{}},[]),g=(0,v.useCallback)(async e=>{if(!t){a({type:`error`,provider:e,message:`Select a chat session before starting login.`});return}s(!0),a({type:`device_starting`,provider:e});try{let n=Tb(await oe(t,`login.start`,{provider:e.id}));if(!n?.url){a({type:`error`,provider:e,message:`No login URL returned.`});return}a({type:`device_flow`,provider:e,url:n.url,state:n.state,userCode:n.userCode,instructions:n.instructions})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t]),_=(0,v.useCallback)(async(e,n,r)=>{if(t){s(!0);try{await oe(t,`login.complete`,{provider:e.id,state:n??``,...r?{code:r}:{}}),a({type:`success`,provider:e,message:`${e.name} login completed.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[t]),y=(0,v.useCallback)(async e=>{if(!t)return;let n=c.trim();if(n){s(!0);try{await oe(t,`login.apikey`,{provider:e.id,apiKey:n}),l(``),a({type:`success`,provider:e,message:`${e.name} API key saved.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[c,t]);return n?(0,M.jsx)(kb,{title:i.type===`select_provider`?`Login`:Mb(i),tone:i.type===`error`?`red`:i.type===`success`?`green`:`cyan`,action:i.type===`select_provider`?void 0:(0,M.jsx)(Ab,{onClick:m,disabled:o}),children:i.type===`select_provider`?(0,M.jsxs)(`div`,{className:`grid gap-2`,children:[(0,M.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a provider. Use `,(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` anytime.`]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>a({type:`select_method`,provider:e}),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[(0,M.jsx)(`span`,{children:e.name}),e.configured?(0,M.jsx)(`span`,{className:`text-[#22c55e]`,children:`●`}):null]},e.id))})]}):i.type===`select_method`?(0,M.jsxs)(`div`,{className:`grid gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Provider:`}),(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.provider.name}),i.provider.configured?(0,M.jsx)(jb,{tone:`green`,children:`Configured`}):(0,M.jsx)(jb,{tone:`neutral`,children:`Not configured`})]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.provider.authMethods.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>e===`api_key`?a({type:`api_key`,provider:i.provider}):void g(i.provider),className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-2 py-1 text-[11px] text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[e===`api_key`?(0,M.jsx)(nt,{size:11}):(0,M.jsx)(st,{size:11}),Db[e]]},e))})]}):i.type===`device_starting`?(0,M.jsxs)(`div`,{className:`inline-flex items-center gap-2 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(ot,{size:13,className:`animate-spin`}),` Starting device login...`]}):i.type===`device_flow`?(0,M.jsxs)(`div`,{className:`grid gap-2 text-[11px]`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Open:`}),(0,M.jsxs)(`a`,{href:i.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[#38bdf8] hover:underline`,children:[Nb(i.url),` `,(0,M.jsx)(qe,{size:11})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>void h(i.url),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:[f===i.url?(0,M.jsx)(Be,{size:10}):(0,M.jsx)(We,{size:10}),` `,f===i.url?`Copied`:`Copy`]})]}),i.userCode?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Code:`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void h(i.userCode),className:`border border-[#1f4960] px-2 py-0.5 font-semibold tracking-widest text-[#38bdf8] hover:border-[#38bdf8]`,children:i.userCode}),(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`then`}),(0,M.jsxs)(`button`,{type:`button`,disabled:o,onClick:()=>void _(i.provider,i.state),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-0.5 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,M.jsx)(ot,{size:11,className:`animate-spin`}):(0,M.jsx)(Be,{size:11}),` Complete`]})]}):(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,M.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),placeholder:`authorization code`,className:`min-w-0 flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,M.jsxs)(`button`,{type:`button`,disabled:o||!u.trim(),onClick:()=>void _(i.provider,i.state,u.trim()),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,M.jsx)(ot,{size:11,className:`animate-spin`}):(0,M.jsx)(Be,{size:11}),` Complete`]})]}),i.instructions?(0,M.jsx)(`div`,{className:`text-[#737373]`,children:i.instructions}):null]}):i.type===`api_key`?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`API key:`}),(0,M.jsx)(`input`,{type:`password`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y(i.provider)},placeholder:`sk-...`,className:`min-w-[12rem] flex-1 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[11px] text-[#d4d4d4] outline-none focus:border-[#38bdf8]`}),(0,M.jsxs)(`button`,{type:`button`,disabled:o||!c.trim(),onClick:()=>void y(i.provider),className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[o?(0,M.jsx)(ot,{size:11,className:`animate-spin`}):(0,M.jsx)(Be,{size:11}),` Save`]})]}):i.type===`success`?(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-[#22c55e]`,children:[(0,M.jsx)(Be,{size:13}),` `,i.message]}):(0,M.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-[#ef4444]`,children:[(0,M.jsx)(Re,{size:13,className:`mt-0.5 shrink-0`}),` `,(0,M.jsx)(`span`,{children:i.message})]})}):(0,M.jsx)(kb,{title:`Login`,tone:`red`,children:`Unparseable login payload.`})}function kb({title:e,tone:t,action:n,children:r}){return(0,M.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`login`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,M.jsx)(st,{size:14,className:t===`red`?`text-[#ef4444]`:t===`green`?`text-[#22c55e]`:`text-[#38bdf8]`}),(0,M.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e}),n?(0,M.jsx)(`div`,{className:`ml-auto`,children:n}):null]}),r]})}function Ab({onClick:e,disabled:t}){return(0,M.jsxs)(`button`,{type:`button`,disabled:t,onClick:e,className:`inline-flex items-center gap-1 border border-[#3a3a3a] bg-transparent px-1.5 py-0.5 text-[11px] text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:[(0,M.jsx)(we,{size:10}),` Back`]})}function jb({tone:e,children:t}){return(0,M.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[10px] ${e===`green`?`border-[#14532d] text-[#22c55e]`:`border-[#3a3a3a] text-[#737373]`}`,children:t})}function Mb(e){return`provider`in e&&e.provider?e.provider.name:`Login`}function Nb(e){try{let t=new URL(e);return`${t.host}${t.pathname}`}catch{return e.length>42?`${e.slice(0,39)}...`:e}}function Pb({row:e,piboSessionId:t,onModelChanged:n}){let r=Tb(e.output),i=(wb(r)?r:void 0)?.providers??[],a=(0,v.useMemo)(()=>i.flatMap(e=>e.models.map(t=>({...t,providerLabel:e.label}))),[i]),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=(0,v.useMemo)(()=>{let e=o.trim().toLowerCase();return e?a.filter(t=>`${t.providerLabel} ${t.provider} ${t.label} ${t.id}`.toLowerCase().includes(e)):a},[a,o]),h=async e=>{if(!(!t||u)){d(!0),l(e),p(null);try{await re(t,{activeModel:{provider:e.provider,id:e.id}}),p(`Selected ${e.provider}/${e.id}.`),await n?.()}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}};return(0,M.jsxs)(`div`,{className:`ml-[1.9rem] max-w-3xl border border-[#3a3a3a] bg-[#111111] text-[12px] shadow-lg`,"data-shared-terminal-card":`model`,children:[(0,M.jsx)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[#2a2a2a] px-3 py-2`,children:(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`text-[#d4d4d4]`,children:`Model`}),(0,M.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a model from authenticated providers. Use `,(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` to add providers.`]})]})}),(0,M.jsxs)(`div`,{className:`space-y-2 p-3`,children:[i.length?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`label`,{className:`flex items-center gap-2 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[#737373]`,children:[(0,M.jsx)(pt,{size:13}),(0,M.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),placeholder:`Search models`,className:`min-w-0 flex-1 bg-transparent text-[#d4d4d4] outline-none placeholder:text-[#525252]`})]}),(0,M.jsx)(`div`,{className:`max-h-72 overflow-auto border border-[#2a2a2a]`,children:m.length?m.map(e=>(0,M.jsxs)(`button`,{type:`button`,disabled:u,onClick:()=>void h(e),className:`grid w-full grid-cols-[150px_1fr_auto] gap-2 border-b border-[#1f1f1f] px-3 py-2 text-left hover:bg-[#38bdf8]/10 disabled:opacity-50`,children:[(0,M.jsx)(`span`,{className:`truncate text-[#737373]`,children:e.providerLabel}),(0,M.jsxs)(`span`,{className:`min-w-0`,children:[(0,M.jsx)(`span`,{className:`block truncate text-[#d4d4d4]`,children:e.label}),(0,M.jsxs)(`span`,{className:`block truncate text-[11px] text-[#737373]`,children:[e.provider,`/`,e.id]})]}),c?.provider===e.provider&&c?.id===e.id?(0,M.jsx)(je,{size:14,className:`text-[#22c55e]`}):null]},`${e.provider}:${e.id}`)):(0,M.jsx)(`div`,{className:`px-3 py-2 text-[#737373]`,children:`No matching models.`})})]}):(0,M.jsxs)(`div`,{className:`text-[#737373]`,children:[`No authenticated model providers found. Run `,(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` first.`]}),f?(0,M.jsx)(`div`,{className:`text-[11px] text-[#a3a3a3]`,children:f}):null]})]})}function Fb(e={}){let t=[],n=[],r=Hb(e.warnings),i=Hb(e.errors);(e.session?.id||e.session?.title)&&t.push({id:`session`,label:`Session`,value:Ib([e.session?.title,e.session?.id].filter(Boolean).join(` | `))}),e.session?.profile&&t.push({id:`profile`,label:`Profile`,value:Ib(e.session.profile)}),e.session?.status&&t.push({id:`session-status`,label:`Session status`,value:Ib(e.session.status),tone:e.session.status===`error`||e.session.status===`disposed`?`red`:`neutral`}),(e.model?.provider||e.model?.id||e.model?.label)&&t.push({id:`model`,label:`Model`,value:Ib(e.model.label??[e.model.provider,e.model.id].filter(Boolean).join(`/`))}),e.runtime?.state&&t.push({id:`runtime`,label:`Runtime`,value:Ib(e.runtime.state),tone:e.runtime.connected===!1||e.runtime.disposed?`red`:`green`}),e.runtime?.disposed!==void 0&&t.push({id:`disposed`,label:`Disposed`,value:e.runtime.disposed?`yes`:`no`,tone:e.runtime.disposed?`red`:`neutral`}),typeof e.runtime?.queuedMessages==`number`&&t.push({id:`queue`,label:`Queue`,value:String(e.runtime.queuedMessages)}),e.runtime?.processing!==void 0&&t.push({id:`processing`,label:`Processing`,value:e.runtime.processing?`yes`:`no`,tone:e.runtime.processing?`cyan`:`neutral`}),e.runtime?.streaming!==void 0&&t.push({id:`streaming`,label:`Streaming`,value:e.runtime.streaming?`yes`:`no`,tone:e.runtime.streaming?`cyan`:`neutral`}),e.cwd&&t.push({id:`cwd`,label:`CWD`,value:Ib(e.cwd)});let a=typeof e.thinking==`string`?{level:e.thinking}:e.thinking;(a?.level||a?.supported!==void 0)&&t.push({id:`thinking`,label:`Thinking`,value:Ib(a.level??(a.supported===!1?`unsupported`:`available`)),tone:a.supported===!1?`red`:`yellow`}),e.fastMode!==void 0&&t.push({id:`fast-mode`,label:`Fast mode`,value:typeof e.fastMode==`string`?Ib(e.fastMode):e.fastMode?`on`:`off`,tone:e.fastMode?`green`:`neutral`});let o=Hb(e.tools?.enabled),s=Hb(e.tools?.active);o.length&&t.push({id:`enabled-tools`,label:`Enabled tools`,value:`${o.length}${o.length<=4?` (${o.join(`, `)})`:``}`}),s.length&&t.push({id:`active-tools`,label:`Active tools`,value:`${s.length}${s.length<=4?` (${s.join(`, `)})`:``}`,tone:`cyan`}),e.providerUsage?.planType&&t.push({id:`provider-plan`,label:`Provider plan`,value:Ib(e.providerUsage.planType)}),e.providerUsage?.credits&&t.push({id:`provider-credits`,label:`Credits`,value:e.providerUsage.credits.unlimited?`unlimited`:Ib(e.providerUsage.credits.balance??`available`)}),e.message&&t.push({id:`message`,label:`Message`,value:Ib(e.message)}),n.push(Lb(e.contextUsage));for(let t of Rb(e.providerUsage))n.push(t);return{kind:`status`,title:`Status`,fields:t,progress:n,warnings:r,errors:i}}function Ib(e){return e.replace(/\b([A-Z0-9_]*(?:API[_-]?KEY|TOKEN|SECRET|PASSWORD)[A-Z0-9_]*)\s*=\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(api[_-]?key|token|secret|password)\s*[:=]\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(?:sk|pk|pibo|ghp|github_pat)_[A-Za-z0-9_\-]{8,}\b/g,`[redacted]`)}function Lb(e){if(!e||e.tokens===void 0&&e.contextWindow===void 0&&e.percent===void 0)return{id:`context`,label:`Context`,state:`unavailable`,text:`Context usage unavailable`,tone:`neutral`};let t=zb(e.percent??(e.tokens!==void 0&&e.contextWindow?e.tokens/e.contextWindow*100:void 0));return{id:`context`,label:`Context`,state:t===void 0?`unavailable`:`available`,value:e.tokens,max:e.contextWindow,percent:t,text:t===void 0?`Context usage unavailable`:`${e.tokens??`?`}/${e.contextWindow??`?`} tokens (${t.toFixed(1)}%)`,tone:Bb(t)}}function Rb(e){return e?.limits?.length?e.limits.map((t,n)=>{let r=zb(t.usedPercent),i=zb(t.remainingPercent??(r===void 0?void 0:100-r)),a=e.provider?`${e.provider} `:``,o=[i===void 0?void 0:`${i.toFixed(1)}% remaining`,t.resetsAt?`resets ${Ib(t.resetsAt)}`:void 0].filter(Boolean).join(`, `);return{id:`provider-${n}`,label:`${a}${t.label??`quota`}`.trim(),state:i===void 0?`unavailable`:`available`,percent:i,text:i===void 0?`Provider usage unavailable`:o,tone:Vb(i)}}):[{id:`provider`,label:`Provider quota`,state:`unavailable`,text:`Provider usage unavailable`,tone:`neutral`}]}function zb(e){if(!(typeof e!=`number`||!Number.isFinite(e)))return Math.max(0,Math.min(100,e))}function Bb(e){return e===void 0?`neutral`:e>=80?`red`:e>=50?`yellow`:`green`}function Vb(e){return e===void 0?`neutral`:e<=20?`red`:e<=50?`yellow`:`green`}function Hb(e){return(e??[]).map(e=>Ib(e)).filter(e=>e.length>0)}function Ub(e){switch(e.kind){case`tool.status`:return Wb(e);case`tool.thinking`:return Gb(e);case`tool.model`:return Kb(e);case`tool.login`:return qb(e);case`tool.call`:case`tool.image`:case`tool.group.exploring`:case`tool.group.images`:return Jb(e);case`yielded.run`:return Yb(e,`yielded-run`,`Yielded run`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`);case`execution.compaction`:return Yb(e,`compaction`,e.status===`error`?`Compaction failed`:e.status===`running`?`Compacting`:`Compaction`,e.status===`error`?`red`:`magenta`);case`execution.command`:return Yb(e,`command`,`Command`,e.status===`error`?`red`:`yellow`);case`error`:return Yb(e,`error`,`Error`,`red`);default:return}}function Wb(e){let t=Zb(e.output),n=Qb(t,`activeModel`)??Qb(t,`model`),r=Fb({session:{id:tx(t,`piboSessionId`)??tx(t,`sessionId`),title:tx(t,`sessionTitle`)??tx(t,`title`),profile:tx(t,`profile`)??tx(t,`activeAgentId`)??tx(t,`agentId`),status:rx(t,`disposed`)?`disposed`:tx(t,`sessionStatus`)},model:n?{provider:tx(n,`provider`),id:tx(n,`id`),label:tx(n,`label`)}:void 0,runtime:{state:rx(t,`disposed`)?`disposed`:rx(t,`processing`)?`processing`:rx(t,`streaming`)?`streaming`:tx(t,`mode`)??`idle`,connected:rx(t,`connected`),queuedMessages:nx(t,`queuedMessages`),processing:rx(t,`processing`),streaming:rx(t,`streaming`),disposed:rx(t,`disposed`)},cwd:tx(t,`cwd`),contextUsage:Qb(t,`contextUsage`),providerUsage:Qb(t,`providerUsage`),tools:{enabled:ex(t,`enabledTools`),active:ex(t,`activeTools`)},thinking:tx(t,`thinkingLevel`)?{level:tx(t,`thinkingLevel`)}:void 0,fastMode:rx(t,`fastMode`),warnings:ex(t,`warnings`),errors:ex(t,`errors`),message:tx(t,`message`)});return{id:e.id,kind:`status`,title:`Status`,status:e.status,tone:e.status===`error`?`red`:`green`,rows:r.fields.map(e=>({label:e.label,value:e.value,tone:e.tone})),statusView:r,sourceRowKind:e.kind}}function Gb(e){let t=Zb(e.output),n=tx(t,`level`)??`unknown`,r=t?.supported!==!1,i=ex(t,`availableLevels`);return{id:e.id,kind:`thinking`,title:`Thinking`,status:e.status,tone:r?`yellow`:`red`,rows:[{label:`Current`,value:Ib(n)},{label:`Supported`,value:r?`yes`:`no`,tone:r?`green`:`red`}],actions:i.map(e=>({id:`thinking:${e}`,label:e,action:`thinking.set`,value:e,disabled:!r})),sourceRowKind:e.kind}}function Kb(e){let t=$b(Zb(e.output),`providers`),n=t.flatMap(e=>{let t=tx(e,`id`)??tx(e,`provider`)??`provider`,n=tx(e,`label`)??tx(e,`name`)??t;return $b(e,`models`).map(e=>{let r=tx(e,`id`)??`model`,i=tx(e,`label`)??r;return{id:`model:${t}:${r}`,label:`${n} / ${i}`,action:`model.select`,value:`${t}/${r}`}})});return{id:e.id,kind:`model`,title:`Model`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)},{label:`Models`,value:String(n.length)}],actions:n,sourceRowKind:e.kind}}function qb(e){let t=$b(Zb(e.output),`providers`),n=t.map(e=>{let t=tx(e,`id`)??`provider`;return{id:`login:${t}`,label:tx(e,`name`)??tx(e,`label`)??t,action:`login.selectProvider`,value:t,description:ex(e,`authMethods`).join(`, `)}});return{id:e.id,kind:`login`,title:`Login`,status:e.status,tone:n.length?`cyan`:`neutral`,rows:[{label:`Providers`,value:String(t.length)}],actions:n,sourceRowKind:e.kind}}function Jb(e){return Yb(e,`tool`,e.kind===`tool.group.exploring`?`Exploring`:e.kind===`tool.image`||e.kind===`tool.group.images`?`Image`:`Tool`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`)}function Yb(e,t,n,r){let i=e.lines.flatMap(e=>{let t=`${e.tokens.map(e=>e.text).join(``)}${e.functionCall?`${e.functionCall.name}${e.functionCall.input===void 0?``:` ${Xb(e.functionCall.input)}`}`:``}`.trim();return t?[{value:Ib(t)}]:[]}),a=e.lines.length===0&&typeof e.output==`string`&&e.output.trim()?[{value:Ib(e.output.trim())}]:[],o=[e.error?{label:`Error`,value:Ib(e.error),tone:`red`}:void 0].filter(e=>!!e);return{id:e.id,kind:t,title:n,status:e.status,tone:r,rows:[...i,...a,...o],sourceRowKind:e.kind}}function Xb(e){try{return JSON.stringify(e)}catch{return String(e)}}function Zb(e){if(e){if(typeof e==`string`)try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}catch{return}return typeof e==`object`&&!Array.isArray(e)?e:void 0}}function Qb(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function $b(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)):[]}function ex(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function tx(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function nx(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function rx(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}var ix={transcript:0,"event-log":1,live:2},ax={"user.message":0,"execution.command":1,"execution.compaction":1,"agent.turn":2,"model.reasoning":3,"tool.call":4,"agent.delegation":4,"agent.async":5,"tool.result":6,"yielded.run":7,"assistant.message":8,error:9};function ox(e,t){return{sourceRank:ix[`event-log`],turnSeq:e??2**53-1,eventSequence:e,phaseRank:ax[t]}}function sx(e,t,n){let r=e??2**53-1,i=t??2**53-1;return{sourceRank:ix.live,turnSeq:r,streamId:r,streamFrameIndex:i,phaseRank:ax[n]}}function cx(e){let[t,n]=e.split(`:`);if(t===void 0||n===void 0)return;let r=Number(t),i=Number(n);if(!(!Number.isInteger(r)||r<0)&&!(!Number.isInteger(i)||i<0))return{streamId:r,frameIndex:i}}function lx(e,t){if(e)return{...e,contentPartIndex:(e.contentPartIndex??0)+.1,phaseRank:ax[t]}}function ux(e,t){return!e&&!t?0:e?t?e.sourceRank-t.sourceRank||e.turnSeq-t.turnSeq||(e.transcriptIndex??2**53-1)-(t.transcriptIndex??2**53-1)||(e.eventSequence??2**53-1)-(t.eventSequence??2**53-1)||(e.streamId??2**53-1)-(t.streamId??2**53-1)||(e.streamFrameIndex??2**53-1)-(t.streamFrameIndex??2**53-1)||(e.contentPartIndex??0)-(t.contentPartIndex??0)||e.phaseRank-t.phaseRank:-1:1}function dx(e){let t=!1,n=e.map(e=>e.children.length?(t=!0,{...e,children:dx(e.children)}):e);return fx(n)?t?n:[...e]:[...n].sort(px)}function fx(e){for(let t=1;t<e.length;t+=1)if(px(e[t-1],e[t])>0)return!1;return!0}function px(e,t){let n=mx(e.startedAt,t.startedAt);if(n!==0)return n;let r=ux(e.orderKey,t.orderKey);return r===0?e.id.localeCompare(t.id):r}function mx(e,t){return!e&&!t?0:e?t?e.localeCompare(t):-1:1}function hx(e){let t=[],n=[...e].reverse();for(;n.length;){let e=n.pop();if(e){t.push(e);for(let t=e.children.length-1;t>=0;--t)n.push(e.children[t])}}return t}function gx(e,t,n,r){if(!_x(t))return;let i=r.get(e)?.filter(e=>e.metadata?.subagentToolName===t)??[],a=yx(n);return a?i.find(e=>e.metadata?.threadKey===a)?.id:i.length===1?i[0].id:void 0}function _x(e){return e.startsWith(`pibo_subagent_`)}function vx(e){return e.slice(14)}function yx(e){let t=`args`in e&&e.args&&typeof e.args==`object`&&!Array.isArray(e.args)?e.args:void 0,n=t&&`threadKey`in t?t.threadKey:void 0;return typeof n==`string`&&n.trim()?n.trim():void 0}function bx(e,t,n,r){let i=Sx(e,t,n,r);if(!i)return;let a=e.children.find(e=>e.id===i.id);if(a){wx(a,i),a.runId=i.runId??a.runId;return}e.children.push(i)}function xx(e){let t=new Map;for(let n of hx(e)){let e=Tx(n.output);if(!e)continue;let r=Dx(e.runId);r&&t.set(r,{snapshot:e,completedAt:Dx(e.completedAt)??Dx(e.updatedAt)??n.completedAt})}for(let n of hx(e)){if(n.type!==`agent.async`||!n.runId)continue;let e=t.get(n.runId);if(!e)continue;let r=Dx(e.snapshot.status);r!==`completed`&&r!==`cancelled`&&r!==`failed`||(n.status=r===`failed`?`error`:`done`,n.completedAt=e.completedAt??n.completedAt,n.output=e.snapshot,r===`failed`&&(n.error=Dx(e.snapshot.summary)??n.error))}}function Sx(e,t,n,r){if(!Cx(e))return;let i=Tx(e.output),a=kx(e.input)?e.input:{},o=Dx(i?.toolName)??Dx(a.toolName)??r?.title;if(!o||!_x(o))return;let s=Dx(r?.summary)??vx(o),c=Dx(i?.runId),l=Dx(i?.status),u=a.arguments,d=Dx(i?.completionPolicy)??Dx(a.completionPolicy);return{id:`${e.id}:async-agent`,parentId:e.id,piboSessionId:t,eventId:e.eventId,toolCallId:e.toolCallId,runId:c,type:`agent.async`,title:s,status:Ox(e,l),startedAt:r?.startedAt??n??e.startedAt,completedAt:l===`completed`||l===`cancelled`?e.completedAt:void 0,summary:`Started by ${e.title}`,input:{startedBy:e.title,startToolCallId:e.toolCallId,toolName:o,subagentName:s,runId:c,completionPolicy:d,arguments:u,threadKey:kx(r?.input)?r.input.threadKey:void 0},output:i,error:e.error,linkedPiboSessionId:r?.linkedPiboSessionId??e.linkedPiboSessionId,source:e.source,stableKey:c?`async-agent:${c}`:`${e.stableKey??e.id}:async-agent`,orderKey:lx(e.orderKey,`agent.async`),children:[]}}function Cx(e){return e.type===`tool.call`&&e.title===`pibo_run_start`}function wx(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt,e.linkedPiboSessionId=t.linkedPiboSessionId??e.linkedPiboSessionId}function Tx(e){if(kx(e)){if(Ex(e))return e;if(kx(e.details)&&Ex(e.details))return e.details}}function Ex(e){return typeof e.runId==`string`&&typeof e.toolName==`string`}function Dx(e){return typeof e==`string`?e:void 0}function Ox(e,t){return e.status===`error`||t===`failed`?`error`:t===`completed`||t===`cancelled`?`done`:`running`}function kx(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Ax(e){let t=(e??``).trim();if(!t.startsWith(`<pibo_run_notification>`)||!t.endsWith(`</pibo_run_notification>`))return;let n=t.slice(23,t.length-24).trim();try{let e=JSON.parse(n);return!e||typeof e!=`object`||Array.isArray(e)?void 0:e}catch{return}}function jx(e){let t=Mx(e.notification),n=t.length===1?t[0]:void 0,r=Px(e.notification.failed),i=Px(e.notification.running);return{id:e.id,entryId:e.entryId,piboSessionId:e.piboSessionId,eventId:e.eventId,runId:typeof n?.runId==`string`?n.runId:void 0,type:`yielded.run`,title:`Run Notification`,status:r>0?`error`:i>0?`running`:`done`,startedAt:e.startedAt,summary:Fx(e.notification),output:e.notification,source:e.source,stableKey:e.stableKey??e.id,orderKey:e.orderKey,children:[]}}function Mx(e){return[...Nx(e.completed),...Nx(e.failed),...Nx(e.cancelled),...Nx(e.running)]}function Nx(e){return Array.isArray(e)?e.filter(Ix):[]}function Px(e){return Array.isArray(e)?e.length:0}function Fx(e){let t=[[Px(e.completed),`completed`],[Px(e.failed),`failed`],[Px(e.cancelled),`cancelled`],[Px(e.running),`running`]].filter(([e])=>Number(e)>0).map(([e,t])=>`${e} ${t}`);return t.length?t.join(`, `):`No yielded run updates`}function Ix(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Lx(e,t,n,r,i,a,o,s,c){let l=r.payload;if(o&&eS(l)&&!tS(l,s)||o&&nS(l,c))return;if(l.type===`assistant_delta`){Jx(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`thinking_delta`){Xx(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`assistant_message`){let i=Rx(n,l,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex),a=t.get(i.id);if(a){Yx(a,i),Qx(t,a);return}Qx(t,i),e.push(i),t.set(i.id,i);return}let u=qx(n,l,i,a,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);if(u){if(u.type===`agent.turn`&&u.eventId){let e=[...t.values()].find(e=>e.type===`agent.turn`&&e.eventId===u.eventId);if(e){e.status=u.status,e.completedAt=u.completedAt??e.completedAt;return}}if(u.type===`assistant.message`){let e=t.get(u.id);if(e){Yx(e,u),Qx(t,e);return}Qx(t,u)}if(u.type===`execution.compaction`){let t=fS(e);if(t){pS(t,u);return}}if(u.type===`model.reasoning`){let e=t.get(u.id);if(e){Zx(e,u);return}}if(u.toolCallId){let e=[...t.values()].find(e=>e.toolCallId===u.toolCallId&&(e.type===`tool.call`||e.type===`agent.delegation`));if(e){if(Cx(e)&&u.type===`agent.delegation`){bx(e,n,r.createdAt,u);return}dS(e,u),bx(e,n,r.createdAt);return}}if(!(u.eventId&&t.has(u.id))){zx(u,t),bx(u,n,r.createdAt),e.push(u);for(let e of hx([u]))t.set(e.id,e)}}}function Rx(e,t,n,r,i,a){let o=typeof t.eventId==`string`?t.eventId:void 0,s=cS(t);return{id:s?sS(s):`event:${t.type}:${gS(t)}`,piboSessionId:e,eventId:o,parentId:o?oS(o):void 0,type:`assistant.message`,title:`Agent Message`,status:`done`,startedAt:n,summary:t.text,output:t.text,source:`event-log`,stableKey:s?`assistant:${s}`:aS(t),orderKey:rS(r,t.type,i,a),children:[]}}function zx(e,t){if(e.type!==`execution.command`||e.parentId&&t.has(e.parentId))return;let n=[...t.values()].filter(n=>{if(n.type!==`agent.turn`||!n.startedAt||!e.startedAt||n.startedAt>e.startedAt)return!1;let r=Bx(n,t);return r===void 0||e.startedAt<=r}).sort(px).at(-1);n&&(e.parentId=n.id)}function Bx(e,t){return e.completedAt?e.completedAt:[...t.values()].filter(t=>t.type===`error`&&t.eventId!==void 0&&t.eventId===e.eventId&&t.startedAt!==void 0).sort(px).at(0)?.startedAt}function Vx(e){return e.some(e=>{let t=e.payload.type;return t!==`assistant_delta`&&t!==`thinking_delta`})}function Hx(e){if(e.type===`assistant_delta`){if(e.text.length===0)return;let t=cS(e);return t?sS(t):void 0}if(e.type===`thinking_delta`){if(e.text.length===0)return;let t=uS(e);return t?lS(t):void 0}}function Ux(e,t){let n=t.payload;if(n.type!==`message_queued`||n.source!==`user`)return!1;let r=typeof n.eventId==`string`?n.eventId:t.eventId,i=typeof n.text==`string`?n.text:void 0;return e.some(e=>e.type!==`user.message`||e.source!==`transcript`?!1:r&&(e.entryId===r||e.stableKey===`entry:${r}`)?!0:!!(i&&Wx(e)===i))}function Wx(e){if(typeof e.output==`string`)return e.output;if(typeof e.summary==`string`)return e.summary}function Gx(e){if(e.streamId!==void 0){let t=e.payload;return e.streamFrameIndex===void 0?`stream:${e.streamId}:${t.type}`:`stream:${e.streamId}:${e.streamFrameIndex}:${t.type}`}return e.eventSequence===void 0?`id:${e.id}`:`sequence:${e.piboSessionId??``}:${e.eventSequence}`}function Kx(e,t){let n=t;for(let t of e)t.streamId!==void 0&&(n=n===void 0?t.streamId:Math.max(n,t.streamId));return n}function qx(e,t,n,r,i,a,o,s,c){let l=`eventId`in t&&typeof t.eventId==`string`?t.eventId:void 0,u=`event:${t.type}:${l??gS(t)}`,d=l?oS(l):void 0,f={id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:aS(t),orderKey:rS(o,t.type,s,c),children:[]};switch(t.type){case`message_queued`:{let n=Ax(t.text);return t.source===`service`&&n?jx({id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:l?`run-notification:${l}`:u,orderKey:rS(o,t.type,s,c),notification:n}):{...f,type:`user.message`,title:`User Message`,status:`done`,summary:t.text,output:t.text}}case`message_started`:case`message_finished`:return t.source===`service`?void 0:{...f,id:l?oS(l):u,type:`agent.turn`,title:`Agent Turn`,status:t.type===`message_finished`||i!==`running`?`done`:`running`,completedAt:t.type===`message_finished`?a:void 0,stableKey:l?`turn:${l}`:f.stableKey};case`thinking_finished`:{if(!mS(t.text))return;let e=uS(t);return{...f,id:e?lS(e):u,parentId:d,type:`model.reasoning`,title:`Thinking`,status:`done`,summary:t.text,output:t.text,stableKey:e?`reasoning:${e}`:f.stableKey}}case`assistant_message`:{let e=cS(t);return{...f,id:e?sS(e):u,parentId:d,type:`assistant.message`,title:`Agent Message`,status:`done`,summary:t.text,output:t.text,stableKey:e?`assistant:${e}`:f.stableKey}}case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:{let o=_x(t.toolName),s=r.get(t.toolCallId)??(o?gx(e,t.toolName,t,n):void 0);return{...f,id:`tool:${t.toolCallId}`,parentId:d,toolCallId:t.toolCallId,type:o?`agent.delegation`:`tool.call`,title:t.toolName,status:t.type===`tool_execution_finished`?t.isError?`error`:`done`:i===`running`&&(t.type===`tool_execution_started`||t.type===`tool_execution_updated`)?`running`:`done`,completedAt:t.type===`tool_execution_finished`?a:void 0,input:`args`in t?t.args:void 0,output:t.type===`tool_execution_finished`?t.result:t.type===`tool_execution_updated`?t.partialResult:void 0,error:t.type===`tool_execution_finished`&&t.isError?hS(t.result):void 0,linkedPiboSessionId:s,stableKey:`tool:${t.toolCallId}`,children:[]}}case`subagent_session`:return{...f,id:t.toolCallId?`tool:${t.toolCallId}`:u,eventId:l,toolCallId:t.toolCallId,type:`agent.delegation`,title:t.toolName,status:i===`running`?`running`:`done`,summary:t.subagentName,input:{subagentName:t.subagentName,threadKey:t.threadKey},linkedPiboSessionId:t.childPiboSessionId,stableKey:t.toolCallId?`tool:${t.toolCallId}`:`subagent:${t.childPiboSessionId}`,children:[]};case`execution_result`:return $x(t.action)?void 0:{...f,type:`execution.command`,title:t.action,status:`done`,input:{action:t.action},output:t.result};case`compaction_start`:return{...f,id:`event:compaction:${o??s??gS(t)}`,type:`execution.compaction`,title:`compact`,status:`running`,summary:`Compacting`,input:{reason:t.reason},stableKey:`compaction:active`};case`compaction_end`:return{...f,id:`event:compaction:end:${o??s??gS(t)}`,type:`execution.compaction`,title:`compact`,status:t.errorMessage?`error`:`done`,completedAt:a,summary:t.aborted?`Compaction skipped`:t.errorMessage?`Compaction failed`:`Compacted`,input:{reason:t.reason},output:t.result,error:t.errorMessage,stableKey:`compaction:active`};case`session_error`:return{...f,type:`error`,title:`Session Error`,status:`error`,summary:t.errorDetails?.userMessage,input:t.errorDetails,error:t.error,output:t.error};default:return}}function Jx(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=cS(n),l=c?sS(c):`event:assistant_delta:${gS(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?oS(n.eventId):void 0,piboSessionId:n.piboSessionId,eventId:n.eventId,type:`assistant.message`,title:`Agent Message`,status:r===`running`?`running`:`done`,startedAt:i,summary:n.text,output:n.text,source:`event-log`,stableKey:c?`assistant:${c}`:l,orderKey:rS(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function Yx(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt}function Xx(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=uS(n),l=c?lS(c):`event:thinking_delta:${gS(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?oS(n.eventId):void 0,piboSessionId:n.piboSessionId,eventId:n.eventId,type:`model.reasoning`,title:`Thinking`,status:r===`running`?`running`:`done`,startedAt:i,summary:n.text,output:n.text,source:`event-log`,stableKey:c?`reasoning:${c}`:l,orderKey:rS(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function Zx(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.output=t.output??e.output,e.completedAt=t.completedAt??e.completedAt}function Qx(e,t){if(!t.parentId||t.status!==`done`)return;let n=e.get(t.parentId);!n||n.type!==`agent.turn`||(n.status=`done`,n.completedAt=t.completedAt??t.startedAt??n.completedAt)}function $x(e){return e===`session.fork`||e===`session.clone`||e===`session.switch`}function eS(e){return e.type===`message_queued`||e.type===`message_started`||e.type===`message_finished`||e.type===`assistant_delta`||e.type===`assistant_message`||e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`}function tS(e,t){let n=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;return!!(n&&t.has(n))}function nS(e,t){return t!==`running`&&e.type===`tool_call`}function rS(e,t,n,r){return e===void 0&&(n!==void 0||r!==void 0)?sx(n,r,iS(t)):ox(e,iS(t))}function iS(e){switch(e){case`message_queued`:return`user.message`;case`message_started`:case`message_finished`:return`agent.turn`;case`thinking_started`:case`thinking_delta`:case`thinking_finished`:return`model.reasoning`;case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:case`subagent_session`:return`tool.call`;case`assistant_delta`:case`assistant_message`:return`assistant.message`;case`execution_result`:return`execution.command`;case`compaction_start`:case`compaction_end`:return`execution.compaction`;case`session_error`:return`error`;default:return`execution.command`}}function aS(e){let t=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;if(e.type===`tool_call`||e.type===`tool_execution_started`||e.type===`tool_execution_updated`||e.type===`tool_execution_finished`||e.type===`subagent_session`&&e.toolCallId)return`tool:${e.toolCallId}`;if(t&&(e.type===`message_started`||e.type===`message_finished`))return`turn:${t}`;if(e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`){let t=uS(e);if(t)return`reasoning:${t}`}if(e.type===`assistant_delta`||e.type===`assistant_message`){let t=cS(e);if(t)return`assistant:${t}`}return`event:${e.type}:${t??gS(e)}`}function oS(e){return`event:message:${e}`}function sS(e){return`event:assistant:${e}`}function cS(e){if(!e.eventId)return;let t=typeof e.assistantIndex==`number`?e.assistantIndex:e.contentIndex;return typeof t==`number`?`${e.eventId}:assistant:${t}`:e.eventId}function lS(e){return`event:thinking:${e}`}function uS(e){if(!e.eventId)return;let t=typeof e.thinkingIndex==`number`?e.thinkingIndex:e.contentIndex;return typeof t==`number`?`${e.eventId}:thinking:${t}`:e.eventId}function dS(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt,e.linkedPiboSessionId=t.linkedPiboSessionId??e.linkedPiboSessionId}function fS(e){return hx([...e]).reverse().find(e=>e.type===`execution.compaction`&&e.status===`running`)}function pS(e,t){e.status=t.status,e.summary=t.summary??e.summary,e.input=t.input??e.input,e.output=t.output??e.output,e.error=t.error??e.error,e.completedAt=t.completedAt??e.completedAt}function mS(e){return typeof e==`string`&&e.trim().length>0}function hS(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function gS(e){return _S(new TextEncoder().encode(JSON.stringify(e))).slice(0,48)}function _S(e){let t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,n=``,r=0;for(;r+2<e.length;r+=3){let i=e[r]<<16|e[r+1]<<8|e[r+2];n+=t[i>>18&63]+t[i>>12&63]+t[i>>6&63]+t[i&63]}if(r<e.length){let i=e[r],a=r+1<e.length?e[r+1]:0,o=i<<16|a<<8;n+=t[o>>18&63]+t[o>>12&63],r+1<e.length&&(n+=t[o>>6&63])}return n}function vS(e){let t=new Map;for(let n of e)t.set(n.id,n);let n=[];for(let r of e){if(!r.parentId){n.push(r);continue}let e=t.get(r.parentId);e?e.children.push(r):n.push(r)}return dx(n)}function yS(e,t,n){return t.map(t=>bS(e,t,n))}function bS(e,t,n){let r=e.get(t.id);if(t.children.length===0){let e=r!==void 0&&r.children.length===0;return r&&e&&(n&&!n.has(t.id)||xS(r,t))?r:e?{...t,children:r.children}:{...t,children:[]}}let i=t.children.map(t=>bS(e,t,n)),a=r!==void 0&&r.children.length===i.length&&r.children.every((e,t)=>e===i[t]);return r&&a&&(n&&!n.has(t.id)||xS(r,t))?r:a?{...t,children:r?.children??i}:{...t,children:i}}function xS(e,t){return e.id===t.id&&e.parentId===t.parentId&&e.entryId===t.entryId&&e.piboSessionId===t.piboSessionId&&e.eventId===t.eventId&&e.toolCallId===t.toolCallId&&e.runId===t.runId&&e.type===t.type&&e.title===t.title&&e.status===t.status&&e.startedAt===t.startedAt&&e.completedAt===t.completedAt&&e.durationMs===t.durationMs&&e.summary===t.summary&&e.input===t.input&&e.output===t.output&&e.error===t.error&&e.linkedPiboSessionId===t.linkedPiboSessionId&&e.source===t.source&&e.stableKey===t.stableKey&&SS(e.orderKey,t.orderKey)}function SS(e,t){return e===t?!0:!e||!t?!1:e.sourceRank===t.sourceRank&&e.turnSeq===t.turnSeq&&e.transcriptIndex===t.transcriptIndex&&e.contentPartIndex===t.contentPartIndex&&e.eventSequence===t.eventSequence&&e.streamId===t.streamId&&e.streamFrameIndex===t.streamFrameIndex&&e.phaseRank===t.phaseRank}function CS(e,t,n){if(!t.length)return e;let r=new Set(e.rawEvents.map(e=>Gx(e))),i=[];for(let e of t){let t=Gx(e);r.has(t)||(r.add(t),i.push(e))}if(!i.length)return e;let a=hx(e.nodes),o=[],s=new Map,c=new Map;for(let e of a){c.set(e.id,e);let t={...e,children:[]};o.push(t),s.set(t.id,t)}let l=new Map,u=new Map,d=new Set,f=[],p=new Set;for(let t of i){if(Ux(o,t))continue;f.push(t);let r=Hx(t.payload);p&&r?p.add(r):p=void 0,Lx(o,s,e.piboSessionId,t,l,u,!1,d,n)}if(!f.length)return e;let m=vS(o);Vx(f)&&xx(m);let h=yS(c,m,p);return{...e,rawEvents:e.rawEvents.length?[...e.rawEvents,...f]:f,nodes:h,latestStreamId:Kx(f,e.latestStreamId)}}function wS(e,t){return e?XS(TS(e.nodes).sort((e,t)=>px(e.node,t.node)).filter(e=>e.node.type!==`agent.turn`&&(t.showThinking||e.node.type!==`model.reasoning`)).map(e=>ES(e.node,e.turnId))).map(e=>e.row):[]}function TS(e,t){let n=[];for(let r of e)r.type!==`agent.turn`&&n.push({node:r,turnId:t}),n.push(...TS(r.children,r.type===`agent.turn`?r.id:t));return n}function ES(e,t){let n;switch(e.type){case`user.message`:n={row:OS(e),turnId:t};break;case`assistant.message`:n={row:kS(e),turnId:t};break;case`model.reasoning`:n={row:AS(e),turnId:t};break;case`tool.call`:n=jS(e,t);break;case`tool.result`:n=NS(e,t);break;case`agent.delegation`:n={row:FS(e),turnId:t};break;case`agent.async`:n={row:IS(e),turnId:t};break;case`yielded.run`:n={row:LS(e),turnId:t};break;case`execution.command`:n={row:zS(e),turnId:t};break;case`execution.compaction`:n={row:RS(e),turnId:t};break;case`error`:n={row:JS(e),turnId:t};break;case`agent.turn`:n={row:{id:e.id,kind:`error`,status:`neutral`,lines:[],sourceNodeIds:[e.id]},turnId:t};break}return{...n,row:{...n.row,...DS(e)}}}function DS(e){return{eventId:e.eventId,runId:e.runId,orderSource:e.source,orderStreamId:e.orderKey?.streamId,orderStreamFrameIndex:e.orderKey?.streamFrameIndex}}function OS(e){let t=EC(e.output)||EC(e.summary)||e.title;return{id:e.id,kind:`message.user`,status:wC(e.status),lines:[{prefix:`prompt`,tokens:[$(t)]}],sourceNodeIds:[e.id],forkEntryId:e.entryId,output:t}}function kS(e){return{id:e.id,kind:`message.assistant`,status:wC(e.status),lines:[],sourceNodeIds:[e.id],output:EC(e.output)||EC(e.summary)||``,error:e.error}}function AS(e){let t=gC(e.output??e.summary);return{id:e.id,kind:`reasoning`,status:wC(e.status),lines:[{prefix:`bullet`,tokens:[$(e.status===`running`?`Thinking`:`Thought`,`amber`,`semibold`)]}],sourceNodeIds:[e.id],markdown:t}}function jS(e,t){let n=yC(e.input);if(n&&vC(e.title))return{row:qS(e,n),turnId:t,exploring:void 0};let r=tC(e);if(r)return{row:MS(e,r),turnId:t,image:r.groupable?r.detail:void 0};let i=mC(e.error??e.output,5,e.error?`red`:`dim`);return{row:{id:e.id,kind:`tool.call`,status:wC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(xC(e.status),TC(e.status),`semibold`),$(` `)],functionCall:{name:e.title,input:e.input}},...i.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:hC(i,e.error?`error`:`output`)},turnId:t,exploring:lC(e)}}function MS(e,t){let n=wC(e.status),r=t.path?`Path: ${t.path}`:t.artifactId?`Artifact: ${t.artifactId}`:t.query?`Query: ${t.query}`:t.mimeType?`Type: ${t.mimeType}`:`Image content returned`;return{id:e.id,kind:`tool.image`,status:n,errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(t.verb,TC(e.status),`semibold`)]},{prefix:`detail`,tokens:[$(r,e.status===`error`?`red`:`cyan`)]}],sourceNodeIds:[e.id],input:rC(e.input),output:t.summary,error:e.error,expandable:e.input!==void 0||t.summary!==void 0||!!e.error}}function NS(e,t){let n=tC(e);return n?{row:MS(e,n),turnId:t,image:n.groupable?n.detail:void 0}:{row:PS(e),turnId:t}}function PS(e){let t=mC(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`tool.call`,status:wC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(e.status===`error`?`Tool failed`:`Returned`,TC(e.status),`semibold`),$(` ${e.title}`)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:hC(t,e.error?`error`:`output`)}}function FS(e){let t=EC(DC(e.input)?e.input.subagentName:void 0)||e.summary||e.title,n=_C((DC(e.input)?e.input.arguments:void 0)??e.input),r=n?[{prefix:`detail`,tokens:[$(n,`dim`)]}]:[];return{id:e.id,kind:`agent.delegation`,status:wC(e.status),lines:[{prefix:`bullet`,tokens:[$(SC(e.status),TC(e.status),`semibold`),$(` ${t}`,`cyan`)]},...r],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function IS(e){let t=mC(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`agent.async`,status:wC(e.status),lines:[{prefix:`bullet`,tokens:[$(CC(e.status),TC(e.status),`semibold`),$(` ${e.title}`,`cyan`)]},...t.lines],sourceNodeIds:[e.id],linkedPiboSessionId:e.linkedPiboSessionId,input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:hC(t,e.error?`error`:`output`)}}function LS(e){let t=mC(e.output,5);return{id:e.id,kind:`yielded.run`,status:wC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(e.status===`running`?`Waiting on runs`:`Run update`,TC(e.status),`semibold`),$(e.summary?` ${e.summary}`:``)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:hC(t,`output`)}}function RS(e){let t=e.status===`running`?`Compacting`:e.status===`error`?`Compaction failed`:EC(e.summary)||`Compacted`;return{id:e.id,kind:`execution.compaction`,status:wC(e.status),lines:[{prefix:`bullet`,tokens:[$(t,TC(e.status),e.status===`error`?`bold`:`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function zS(e){if(e.title===`status`)return BS(e);if(e.title===`thinking`)return VS(e);if(e.title===`fast_mode`)return HS(e);if(e.title===`login`&&GS(e.output))return US(e);if(e.title===`model`&&KS(e.output))return WS(e);yC(e.output)??yC(e.input)??e.title;let t=mC(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:wC(e.status),lines:[{prefix:`bullet`,tokens:[$(`Command`,`yellow`,`semibold`),$(` /${e.title}`,`yellow`)]},...t.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:hC(t,e.error?`error`:`output`)}}function BS(e){return{id:e.id,kind:`tool.status`,status:wC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function VS(e){return{id:e.id,kind:`tool.thinking`,status:wC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function HS(e){let t=DC(e.output)?e.output:void 0,n=t?.mode===`fast`?`fast`:t?.mode===`normal`?`normal`:void 0,r=t?.changed!==!1,i=t?.supported!==!1,a=i?n===`fast`?r?`Switched to Fast mode.`:`Fast mode is already on.`:n===`normal`?r?`Switched to Normal mode.`:`Normal mode is already on.`:`Fast mode updated.`:`Fast mode is not supported by this model.`;return{id:e.id,kind:`execution.command`,status:wC(e.status),lines:[{prefix:`bullet`,tokens:[$(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function US(e){return{id:e.id,kind:`tool.login`,status:wC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function WS(e){return{id:e.id,kind:`tool.model`,status:wC(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function GS(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_login_menu`&&Array.isArray(t.providers)}function KS(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.action===`show_model_menu`&&Array.isArray(t.providers)}function qS(e,t){let n=mC(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:wC(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(e.status===`running`?`Running`:`Ran`,TC(e.status),`semibold`),$(` `),...bC(t)]},...n.lines],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:e.input!==void 0||e.output!==void 0||!!e.error,previewOmission:hC(n,e.error?`error`:`output`)}}function JS(e){return{id:e.id,kind:`error`,status:`error`,errorKind:`system`,lines:[{prefix:`bullet`,tokens:[$(e.title||`Error`,`red`,`bold`),$(e.error?` ${e.error}`:``,`red`)]},...YS(e.input)],sourceNodeIds:[e.id],input:e.input,error:e.error,output:e.output,expandable:e.input!==void 0||e.output!==void 0||!!e.error}}function YS(e){return DC(e)?[[`Class`,EC(e.errorClass)??EC(e.category)],[`Code`,EC(e.code)??EC(e.providerCode)],[`Origin`,EC(e.origin)],[`Provider`,[EC(e.api),EC(e.provider),EC(e.model)].filter(Boolean).join(` / `)||void 0],[`Retryable`,typeof e.retryable==`boolean`?e.retryable?`yes`:`no`:void 0]].filter(e=>typeof e[1]==`string`&&e[1].length>0).map(([e,t],n)=>({prefix:n===0?`detail`:`continuation`,tokens:[$(`${e}: `,`dim`),$(t,`red`)]})):[]}function XS(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],i=ZS(r);if(!i){t.push(r);continue}let a=[r],o=n+1;for(;o<e.length&&ZS(e[o])===i&&e[o].turnId===r.turnId;)a.push(e[o]),o+=1;if(a.length===1){t.push(r);continue}t.push({row:i===`images`?$S(a):QS(a),turnId:r.turnId}),n=o-1}return t}function ZS(e){if(e.image)return`images`;if(e.exploring)return`exploring`}function QS(e){let t=eC(e,`exploring`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`exploring`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:exploring:${a}:${o}`,kind:`tool.group.exploring`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(s===`running`?`Exploring`:s===`error`?`Exploring failed`:`Explored`,TC(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[$(e.label,e.status===`error`?`red`:`dim`)]})),...r>0?[{prefix:`continuation`,tokens:[$(`+${r} more explorations`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function $S(e){let t=eC(e,`images`),n=t.slice(0,6),r=Math.max(0,t.length-n.length),i=e[0]?.row,a=i?.id??`images`,o=e[e.length-1]?.row.id??a,s=e.some(e=>e.row.status===`running`)?`running`:e.some(e=>e.row.status===`error`)?`error`:`done`;return{id:`group:images:${a}:${o}`,kind:`tool.group.images`,status:s,errorKind:s===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[$(s===`running`?`Viewing images`:s===`error`?`Image reads failed`:`Viewed images`,TC(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[$(e.label,e.status===`error`?`red`:`cyan`)]})),...r>0?[{prefix:`continuation`,tokens:[$(`+${r} more image reads`,`dim`,`normal`,!0)]}]:[]],sourceNodeIds:e.flatMap(e=>e.row.sourceNodeIds),eventId:i?.eventId,runId:i?.runId,orderSource:i?.orderSource,orderStreamId:i?.orderStreamId,orderStreamFrameIndex:i?.orderStreamFrameIndex,detailItems:t,expandable:t.some(e=>e.input!==void 0||e.output!==void 0||!!e.error),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function eC(e,t){return e.map(e=>{let n=t===`images`?e.image:e.exploring;return{id:e.row.id,label:n?.label??e.row.lines[0]?.tokens.map(e=>e.text).join(``)??e.row.id,status:e.row.status,input:e.row.input,output:e.row.output,error:e.row.error,linkedPiboSessionId:e.row.linkedPiboSessionId,previewOmission:e.row.previewOmission}})}function tC(e){let t=(e.title??``).trim().toLowerCase(),n=DC(e.input)?e.input:void 0,r=DC(e.output)?e.output:void 0,i=cC(r,`details`),a=t===`codex_image_generation`?aC(i)??oC(n):void 0,o=a?EC(i?.savedPath)??dC(i):dC(n)??dC(i)??dC(r),s=a?EC(i?.artifactId):void 0,c=fC(n),l=nC(e.output),u=uC(t,[`view_image`,`image`,`screenshot`]);if(!l.length&&!u&&!a)return;let d=l.map(e=>e.mimeType).find(e=>!!e),f=Math.max(1,l.length),p={type:l.length>1?`images`:l.length===1?`image`:`image_reference`,toolName:a?e.title:void 0,operation:a,path:o,savedPath:a?o:void 0,artifactId:s,model:a?EC(i?.model):void 0,referencedImageCount:a?pC(i?.referencedImageCount):void 0,query:c,mimeType:d,count:f>1?f:void 0,detail:l.length?`Image data hidden in terminal view.`:`Image path only; binary data is hidden in terminal view.`},m=o??s??c??d??`image`,h=a?sC(e.status,a):iC(e.status,f);return{count:f,path:o,artifactId:s,query:c,mimeType:d,verb:h,groupable:!a,summary:p,detail:{id:e.id,label:`${h} ${m}`,status:wC(e.status),input:rC(e.input),output:p,error:e.error}}}function nC(e,t=0,n=new Set){if(t>5||typeof e!=`object`||!e||n.has(e))return[];if(n.add(e),Array.isArray(e))return e.flatMap(e=>nC(e,t+1,n));let r=e,i=typeof r.type==`string`?r.type.toLowerCase():void 0,a=typeof r.mimeType==`string`?r.mimeType:typeof r.mime_type==`string`?r.mime_type:void 0,o=typeof r.data==`string`||typeof r.image_url==`string`||DC(r.image_url);if((i===`image`||i===`input_image`||i===`output_image`||i===`image_url`)&&(o||a?.startsWith(`image/`))||a?.startsWith(`image/`)&&o)return[{mimeType:a}];let s=[];return`content`in r&&s.push(r.content),`message`in r&&s.push(r.message),`result`in r&&s.push(r.result),`output`in r&&s.push(r.output),s.flatMap(e=>nC(e,t+1,n))}function rC(e){if(Array.isArray(e))return e.map(rC);if(!DC(e))return e;let t={};for(let[n,r]of Object.entries(e)){if((n===`data`||n===`image_url`)&&typeof r==`string`&&r.length>120){t[n]=`[hidden ${n}]`;continue}t[n]=rC(r)}return t}function iC(e,t){return e===`running`?t>1?`Viewing images`:`Viewing image`:e===`error`?t>1?`Image reads failed`:`Image read failed`:t>1?`Viewed images`:`Viewed image`}function aC(e){let t=EC(e?.operation);return t===`generate`||t===`edit`?t:void 0}function oC(e){if(!e)return;let t=e.referenced_image_paths;return Array.isArray(t)&&t.length>0||pC(e.num_last_images_to_include)!==void 0?`edit`:`generate`}function sC(e,t){return t===`edit`?e===`running`?`Editing image`:e===`error`?`Image edit failed`:`Edited image`:e===`running`?`Generating image`:e===`error`?`Image generation failed`:`Generated image`}function cC(e,t){let n=e?.[t];return DC(n)?n:void 0}function lC(e){let t=(e.title??``).trim().toLowerCase(),n=DC(e.input)?e.input:void 0;if(uC(t,[`read`,`open`]))return{id:e.id,label:`Read ${dC(n)??_C(e.input)}`,status:wC(e.status),input:e.input,output:e.output,error:e.error};if(uC(t,[`list`,`ls`,`glob`]))return{id:e.id,label:`List ${dC(n)??_C(e.input)}`,status:wC(e.status),input:e.input,output:e.output,error:e.error};if(uC(t,[`search`,`find`,`grep`,`rg`])){let t=fC(n),r=dC(n);return{id:e.id,label:`Search ${t??_C(e.input)}${r?` in ${r}`:``}`,status:wC(e.status),input:e.input,output:e.output,error:e.error}}}function uC(e,t){return t.some(t=>e===t||e.startsWith(`${t}_`)||e.endsWith(`_${t}`)||e.includes(t))}function dC(e){if(e)for(let t of[`path`,`file`,`filePath`,`filepath`,`url`,`uri`,`cwd`,`pattern`,`glob`]){let n=EC(e[t]);if(n)return n}}function fC(e){if(e)for(let t of[`query`,`pattern`,`text`,`name`,`q`,`regex`]){let n=EC(e[t]);if(n)return n}}function pC(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function mC(e,t,n=`dim`,r=160){let i={lines:[],visibleLineCount:0,omittedLineCount:0,totalLineCount:0,maxVisibleLineCount:t},a=gC(e);if(!a)return i;let o=a.split(/\r?\n/).map(e=>e.trimEnd()).filter((e,t,n)=>e.length>0||n.length===1);if(!o.length)return i;let s=o.slice(0,t),c=Math.max(0,o.length-s.length),l=s.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[$(e,n)]}));return c>0&&l.push({prefix:`continuation`,tokens:[$(`+${c} more lines`,`dim`,`normal`,!0)]}),{lines:l,visibleLineCount:s.length,omittedLineCount:c,totalLineCount:o.length,maxVisibleLineCount:t}}function hC(e,t){if(!(e.omittedLineCount<=0))return{source:t,visibleLineCount:e.visibleLineCount,omittedLineCount:e.omittedLineCount,totalLineCount:e.totalLineCount,maxVisibleLineCount:e.maxVisibleLineCount}}function gC(e){let t=Uy(e);if(t!==void 0)return t.trim();if(typeof e==`string`)return e.trim();if(e==null)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function _C(e){return(typeof e==`string`?e:gC(e)).replace(/\s+/g,` `).trim()}function vC(e){let t=(e??``).trim().toLowerCase();return t===`shell`||t===`bash`||t===`terminal`}function yC(e){if(DC(e))for(let t of[`cmd`,`command`,`script`]){let n=EC(e[t]);if(n)return n}}function bC(e){let t=e.match(/\s+|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s]+/g)??[e],n=!1;return t.map(e=>/^\s+$/.test(e)?$(e):/^(?:&&|\|\||[|;<>]|2>&1)$/.test(e)?$(e,`red`,`semibold`):e.startsWith(`-`)?$(e,`magenta`):e.startsWith(`$`)||e.includes(`=`)?$(e,`yellow`):/^['"]/.test(e)?$(e,`green`):n?e.includes(`/`)||e.startsWith(`.`)?$(e,`cyan`):$(e,`default`):(n=!0,$(e,`green`,`semibold`)))}function xC(e){return e===`running`?`Calling`:e===`error`?`Call failed`:`Called`}function SC(e){return e===`running`?`Spawning`:e===`error`?`Spawn failed`:`Spawned`}function CC(e){return e===`running`?`Waiting for`:`Finished waiting for`}function wC(e){return e===`running`?`running`:e===`error`?`error`:`done`}function TC(e){return e===`running`?`cyan`:e===`error`?`red`:e===`done`?`green`:`default`}function $(e,t=`default`,n=`normal`,r=!1){return{text:e,tone:t,weight:n,italic:r}}function EC(e){return typeof e==`string`&&e.trim().length?e:void 0}function DC(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function OC(e){if(!e)return;let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else typeof e==`object`&&!Array.isArray(e)&&(t=e);if(!t)return;let n=typeof t.contextUsage==`object`&&t.contextUsage!==null?t.contextUsage:void 0,r=typeof t.providerUsage==`object`&&t.providerUsage!==null?t.providerUsage:void 0,i=Array.isArray(r?.limits)?r.limits.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)).map(e=>{let t=typeof e.usedPercent==`number`?e.usedPercent:void 0,n=typeof e.remainingPercent==`number`?e.remainingPercent:t===void 0?0:Math.max(0,Math.min(100,100-t));return{label:typeof e.label==`string`?e.label:`limit`,usedPercent:t??0,remainingPercent:n,resetsAt:typeof e.resetsAt==`string`?e.resetsAt:void 0}}):[],a=typeof r?.credits==`object`&&r.credits!==null?r.credits:void 0;return{piboSessionId:typeof t.piboSessionId==`string`?t.piboSessionId:void 0,queuedMessages:typeof t.queuedMessages==`number`?t.queuedMessages:void 0,processing:typeof t.processing==`boolean`?t.processing:void 0,streaming:typeof t.streaming==`boolean`?t.streaming:void 0,enabledTools:Array.isArray(t.enabledTools)?t.enabledTools.filter(e=>typeof e==`string`):Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,activeTools:Array.isArray(t.activeTools)?t.activeTools.filter(e=>typeof e==`string`):void 0,cwd:typeof t.cwd==`string`?t.cwd:void 0,disposed:typeof t.disposed==`boolean`?t.disposed:void 0,contextUsage:n?{tokens:typeof n.tokens==`number`?n.tokens:void 0,contextWindow:typeof n.contextWindow==`number`?n.contextWindow:void 0,percent:typeof n.percent==`number`?n.percent:void 0}:void 0,providerUsage:r&&(i.length>0||a)?{provider:typeof r.provider==`string`?r.provider:void 0,planType:typeof r.planType==`string`?r.planType:void 0,fetchedAt:typeof r.fetchedAt==`string`?r.fetchedAt:void 0,limits:i,credits:a?{unlimited:a.unlimited===!0,balance:typeof a.balance==`string`?a.balance:void 0}:void 0}:void 0}}function kC(e,t,n){return n?{id:e,label:t,value:n}:void 0}function AC({field:e,icon:t}){let n=t===`session`?et:Xe;return(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,M.jsx)(n,{size:11,className:`shrink-0 text-[#737373]`}),(0,M.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,M.jsx)(`span`,{className:`truncate font-mono ${e.id===`session`?`text-[#38bdf8]`:`text-[#d4d4d4]`}`,children:e.value})]})}function jC({progress:e,label:t}){let n=e.percent??0,r=e.tone===`red`?`bg-[#ef4444]`:e.tone===`yellow`?`bg-[#facc15]`:e.tone===`cyan`?`bg-[#38bdf8]`:`bg-[#22c55e]`;return(0,M.jsxs)(`div`,{className:`mt-3 space-y-1`,"data-shared-progress":e.id,"data-shared-progress-state":e.state,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:t??e.label}),(0,M.jsx)(`span`,{className:`font-mono text-[#d4d4d4]`,children:e.state===`available`?e.text:`unavailable`})]}),e.state===`available`?(0,M.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,M.jsx)(`div`,{className:`h-full rounded-full ${r} transition-all`,style:{width:`${Math.min(Math.max(n,0),100)}%`}})}):null]})}function MC(e){if(!e)return;let t=new Date(e);if(!Number.isNaN(t.getTime()))return t.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function NC({row:e}){let t=OC(e.output),n=Ub(e),r=n?.kind===`status`?n.statusView:void 0,[i,a]=(0,v.useState)(!1);if(!t||!r)return(0,M.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:(0,M.jsx)(`div`,{className:`text-[#737373]`,children:`Status (unparseable)`})});let o=new Map(r.fields.map(e=>[e.id,e])),s=o.get(`session`)??kC(`session`,`Session`,t.piboSessionId),c=o.get(`cwd`)??kC(`cwd`,`CWD`,t.cwd),l=r.progress.find(e=>e.id===`context`),u=r.progress.filter(e=>e.id.startsWith(`provider`)),d=t.providerUsage?.limits.length?t.providerUsage.limits:void 0,f=t.enabledTools??t.activeTools??[],p=r.fields.filter(e=>!new Set([`session`,`cwd`]).has(e.id)),m=t.providerUsage?.provider?`${t.providerUsage.provider} quota`:`Provider quota`;return(0,M.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-pibo-component":`TerminalStatusCard`,"data-pibo-debug":`terminal-status-card`,"data-shared-terminal-card":`status`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,M.jsx)(Se,{size:14,className:`text-[#22c55e]`}),(0,M.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:r.title})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-1.5 sm:grid-cols-2`,children:[s?(0,M.jsx)(AC,{field:s,icon:`session`}):null,c?(0,M.jsx)(AC,{field:c,icon:`cwd`}):null,p.slice(0,8).map(e=>(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,M.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,M.jsx)(`span`,{className:`truncate font-mono text-[#d4d4d4]`,children:e.value})]},e.id))]}),(0,M.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[t.processing?(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(Ge,{size:10}),` Processing`]}):null,t.streaming?(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(Se,{size:10}),` Streaming`]}):null,typeof t.queuedMessages==`number`&&t.queuedMessages>0?(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[11px] text-[#d4d4d4]`,children:[(0,M.jsx)(rt,{size:10}),` Queued: `,t.queuedMessages]}):null,t.disposed?(0,M.jsx)(`span`,{className:`inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:`Disposed`}):null]}),l?(0,M.jsx)(jC,{progress:l,label:`Context Usage`}):null,u.length?(0,M.jsxs)(`div`,{className:`mt-3 space-y-1.5 border-t border-[#2a2a2a] pt-2`,"data-shared-provider-progress":u.length,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-[#737373]`,"data-shared-status-field":`provider-quota`,children:[(0,M.jsx)(Ze,{size:11}),(0,M.jsxs)(`span`,{children:[m,t.providerUsage?.planType?` (${t.providerUsage.planType})`:``]})]}),d?d.map(e=>{let t=MC(e.resetsAt);return(0,M.jsxs)(`div`,{className:`space-y-1`,"data-shared-progress":`provider-limit:${e.label}`,"data-shared-progress-state":`available`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,M.jsx)(`span`,{className:`text-[#a3a3a3]`,children:e.label}),(0,M.jsxs)(`span`,{className:`shrink-0 font-mono text-[#d4d4d4]`,children:[e.remainingPercent.toFixed(0),`% left`,t?` · resets ${t}`:``]})]}),(0,M.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,M.jsx)(`div`,{className:`h-full rounded-full bg-[#38bdf8] transition-all`,style:{width:`${Math.min(Math.max(e.remainingPercent,0),100)}%`}})})]},`${e.label}-${e.resetsAt??``}`)}):u.map(e=>(0,M.jsx)(jC,{progress:e},e.id)),t.providerUsage?.credits?(0,M.jsxs)(`div`,{className:`text-[11px] text-[#a3a3a3]`,"data-shared-status-field":`provider-credits`,children:[`Credits: `,t.providerUsage.credits.unlimited?`unlimited`:t.providerUsage.credits.balance??`available`]}):null]}):null,r.warnings.length||r.errors.length?(0,M.jsxs)(`div`,{className:`mt-3 space-y-1 border-t border-[#2a2a2a] pt-2`,children:[r.warnings.map((e,t)=>(0,M.jsxs)(`div`,{"data-shared-status-warning":!0,className:`text-[11px] text-[#facc15]`,children:[`⚠ `,e]},`warning-${t}`)),r.errors.map((e,t)=>(0,M.jsxs)(`div`,{"data-shared-status-error":!0,className:`text-[11px] text-[#ef4444]`,children:[`✕ `,e]},`error-${t}`))]}):null,f.length>0?(0,M.jsxs)(`div`,{className:`mt-3`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1.5 text-[11px] text-[#737373] hover:text-[#d4d4d4]`,children:[(0,M.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i?`▾`:`▸`}),(0,M.jsxs)(`span`,{children:[`Enabled tools (`,f.length,`)`]})]}),i?(0,M.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:f.map(e=>(0,M.jsx)(`span`,{className:`inline-block rounded-sm border border-[#2a2a2a] bg-[#0b0b0b] px-1.5 py-0.5 font-mono text-[11px] text-[#a3a3a3]`,children:e},e))}):null]}):null]})}var PC=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`];function FC(e){let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else e&&typeof e==`object`&&!Array.isArray(e)&&(t=e);if(t)return{level:typeof t.level==`string`?t.level:void 0,availableLevels:Array.isArray(t.availableLevels)?t.availableLevels.filter(e=>typeof e==`string`):[],supported:typeof t.supported==`boolean`?t.supported:void 0}}function IC(e){return PC.includes(e)?e:void 0}function LC({row:e,onLevelSelect:t}){let n=FC(e.output);return n?(0,M.jsxs)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,M.jsx)(ke,{size:14,className:`text-[#f59e0b]`}),(0,M.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:`Thinking`}),n.supported===!1?(0,M.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#5f2222] px-1.5 py-0.5 text-[11px] text-[#ef4444]`,children:[(0,M.jsx)(vt,{size:10}),` Unsupported`]}):(0,M.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,M.jsx)(je,{size:10}),` Supported`]})]}),(0,M.jsxs)(`div`,{className:`grid gap-1.5 text-[11px]`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`text-[#737373]`,children:`Current:`}),(0,M.jsx)(`span`,{className:`font-mono font-semibold text-[#f59e0b]`,children:n.level??`unknown`})]}),n.availableLevels.length?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,M.jsx)(`span`,{className:`mr-1 text-[#737373]`,children:`Available:`}),n.availableLevels.map(e=>{let r=IC(e),i=n.supported===!1||!r||!t;return(0,M.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>{r&&t?.(r)},className:`border bg-transparent px-1.5 py-0.5 ${e===n.level?`border-[#f59e0b] text-[#f59e0b]`:`border-[#3a3a3a] text-[#d4d4d4]`} ${i?`cursor-default`:`cursor-pointer`}`,children:e},e)})]}):null,(0,M.jsxs)(`div`,{className:`text-[#737373]`,children:[`Click a level or use `,(0,M.jsx)(`span`,{className:`text-[#f59e0b]`,children:`/thinking <level>`}),`.`]})]})]}):(0,M.jsx)(`div`,{className:`mt-2 border border-[#2a2a2a] bg-[#111111] px-3 py-2 text-[12px] text-[#d4d4d4]`,"data-shared-terminal-card":`thinking`,children:(0,M.jsx)(`div`,{className:`text-[#737373]`,children:`Thinking (unparseable)`})})}var RC=180,zC={index:`LAST`,align:`end`},BC={top:2400,bottom:2400},VC=84,HC=6;function UC({traceView:e,selectedTrace:t,isLoading:n,showThinking:r,expandThinking:i,sessionAgentProfile:a,sessionActiveModel:o,selectedSessionStatus:s,selectedSessionSignal:c,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,agentProfiles:f,sessionProfileChangeDisabled:p,onSessionAgentProfileChange:m,onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:y}){let b=(0,v.useMemo)(()=>wS(e,{showThinking:r}),[r,e]),[x,S]=(0,v.useState)(new Set),[C,w]=(0,v.useState)(null),T=(0,v.useRef)({}),E=b.filter(e=>e.status===`running`).length,ee=b.filter(e=>QC(e,`user`)).length,D=b.filter(e=>QC(e,`tool`)).length,O=b.filter(e=>QC(e,`system`)).length,te=c?c.isTreeActive:s===`running`||E>0||t?.status===`UNSET`,ne=ka({itemCount:b.length,resetKey:e?.piboSessionId,contentKey:b,atBottomThreshold:RC});(0,v.useEffect)(()=>{S(e=>ZC(e,b,i))},[i,b]),(0,v.useEffect)(()=>{let e=new Set(b.map(e=>e.id));w(t=>t&&e.has(t)?t:null);for(let t of[`system`,`tool`,`user`]){let n=T.current[t];n&&!e.has(n)&&delete T.current[t]}},[b]);let re=(0,v.useCallback)(e=>{let t=$C(b,e,T.current[e]);t&&(T.current[e]=t.row.id,w(t.row.id),ne.scrollToIndex(t.index,`start`,`fast-smooth`,{fromIndex:t.fromIndex,stagingAlign:e===`tool`?`end`:void 0}),ew(t.row.id))},[b,ne]),ie=e=>{e.expandable&&S(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},ae=(0,v.useCallback)((t,n)=>(0,M.jsx)(`div`,{className:`px-4`,children:(0,M.jsx)(KC,{row:n,expanded:x.has(n.id),focused:C===n.id,piboSessionId:e?.piboSessionId??``,onToggle:()=>ie(n),onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:y})}),[x,C,h,y,g,_,e?.piboSessionId]),oe=(0,v.useMemo)(()=>({Footer:te?sw:void 0}),[te]);return(0,M.jsxs)(`section`,{className:`relative min-w-0 flex-1 flex flex-col overflow-hidden bg-[#0b0b0b] text-[#d4d4d4]`,"data-pibo-component":`CompactTerminalSessionView`,"data-pibo-debug":`compact-terminal-session-view`,"data-pibo-session-id":e?.piboSessionId??void 0,children:[(0,M.jsx)(WC,{errorCount:O,toolErrorCount:D,userMessageCount:ee,onNavigate:re,sessionAgentProfile:a,sessionActiveModel:o,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,onOpenSession:g}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e?b.length?(0,M.jsx)(Li,{ref:ne.virtuosoRef,data:b,initialTopMostItemIndex:zC,increaseViewportBy:BC,defaultItemHeight:VC,className:`min-h-0 h-full overflow-x-hidden font-mono text-[12px] leading-[1.45]`,computeItemKey:(e,t)=>t.id,scrollerRef:ne.scrollerRef,atBottomStateChange:ne.atBottomStateChange,atBottomThreshold:ne.atBottomThreshold,followOutput:ne.followOutput,totalListHeightChanged:ne.totalListHeightChanged,alignToBottom:!0,components:oe,itemContent:ae},e.piboSessionId):(0,M.jsx)(_w,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m,message:`No visible trace rows yet.`}):(0,M.jsx)(_w,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m})}),ne.isSticky?null:(0,M.jsx)(`button`,{type:`button`,onClick:()=>ne.stickToBottom(`auto`),title:`Scroll to latest`,"aria-label":`Scroll to latest`,className:`absolute right-4 bottom-4 z-30 inline-flex h-9 w-9 items-center justify-center rounded-sm border border-[#38bdf8] bg-[#111111]/95 text-[#38bdf8] shadow-lg shadow-black/30 hover:bg-[#161616]`,children:(0,M.jsx)(Me,{size:18})})]})}function WC({errorCount:e,toolErrorCount:t,userMessageCount:n,onNavigate:r,sessionAgentProfile:i,sessionActiveModel:a,sessionBreadcrumbs:o,originSession:s,derivedSessions:c,onOpenSession:l}){return(0,M.jsxs)(`div`,{className:`border-b border-[#2a2a2a] bg-[#111111] px-4 py-2 text-[11px]`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i?(0,M.jsx)(hw,{tone:`neutral`,children:i}):null,a?(0,M.jsx)(hw,{tone:`purple`,children:a}):null,n>0?(0,M.jsxs)(hw,{tone:`cyan`,label:`${n} user messages · jump to previous user message`,onClick:()=>r(`user`),children:[n,(0,M.jsx)(ct,{size:12})]}):null,e>0?(0,M.jsxs)(hw,{tone:`red`,label:`${e} errors · jump to previous error`,onClick:()=>r(`system`),children:[e,(0,M.jsx)(Ve,{size:12})]}):null,t>0?(0,M.jsxs)(hw,{tone:`amber`,label:`${t} tool call errors · jump to previous tool error`,onClick:()=>r(`tool`),children:[t,(0,M.jsx)($e,{size:12})]}):null,s?(0,M.jsxs)(GC,{onClick:()=>l(s.piboSessionId),children:[`Origin `,s.label]}):null,c.map(e=>(0,M.jsxs)(GC,{onClick:()=>l(e.piboSessionId),children:[`Derived `,e.label]},e.piboSessionId))]}),o.length?(0,M.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1 text-[#737373]`,children:o.map((e,t)=>(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,M.jsx)(Ne,{size:12,className:`text-[#525252]`}):null,(0,M.jsx)(`button`,{type:`button`,onClick:()=>l(e.piboSessionId),className:`hover:text-[#38bdf8]`,children:e.label})]},e.piboSessionId))}):null]})}function GC({children:e,onClick:t}){return(0,M.jsx)(`button`,{type:`button`,onClick:t,className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e})}function KC({row:e,expanded:t,focused:n,piboSessionId:r,onToggle:i,onFork:a,onOpenSession:o,onThinkingLevelChange:s,onModelChanged:c}){let l=!t&&nw(e),u=l?tw(e):e.lines;return(0,M.jsxs)(`div`,{className:XC(e,n),"data-pibo-component":`TerminalRow`,"data-pibo-debug":`terminal-row`,"data-pibo-terminal-row":`true`,"data-row-id":e.id,"data-row-kind":e.kind,"data-row-status":e.status,"data-trace-node-id":e.sourceNodeIds.join(` `),"data-event-id":e.eventId,"data-run-id":e.runId,"data-order-source":e.orderSource,"data-order-stream-id":e.orderStreamId,"data-order-frame-index":e.orderStreamFrameIndex,onDoubleClick:e.expandable?t=>{!e.expandable||rw(t)||i()}:void 0,onKeyDown:e.expandable?t=>{!e.expandable||rw(t)||(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),i())}:void 0,role:e.expandable?`button`:void 0,tabIndex:e.expandable||n?0:void 0,"aria-expanded":e.expandable?t:void 0,"aria-current":n?`true`:void 0,children:[(0,M.jsxs)(`div`,{className:`flex gap-3`,children:[(0,M.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,M.jsx)(qC,{row:e,visibleLines:u,collapseToolCallPreview:l,piboSessionId:r,onThinkingLevelChange:s,onModelChanged:c})}),(0,M.jsx)(YC,{row:e,onFork:a,onOpenSession:o})]}),t?(0,M.jsx)(Ky,{row:e,onOpenSession:o}):null]})}function qC({row:e,visibleLines:t,collapseToolCallPreview:n,piboSessionId:r,onThinkingLevelChange:i,onModelChanged:a}){return e.kind===`message.assistant`?(0,M.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalAssistantMessage`,children:(0,M.jsx)(`div`,{className:`compact-terminal-markdown`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`assistant-message`,children:(0,M.jsx)(uy,{streaming:e.status===`running`,children:typeof e.output==`string`?e.output:``})})}):e.kind===`tool.status`?(0,M.jsx)(NC,{row:e}):e.kind===`tool.thinking`?(0,M.jsx)(LC,{row:e,onLevelSelect:i}):e.kind===`tool.login`?(0,M.jsx)(Ob,{row:e,piboSessionId:r}):e.kind===`tool.model`?(0,M.jsx)(Pb,{row:e,piboSessionId:r,onModelChanged:a}):e.kind===`execution.compaction`&&e.status===`running`?(0,M.jsx)(pw,{}):e.kind===`reasoning`&&e.markdown?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(JC,{lines:t,status:e.status,clampPreview:n}),(0,M.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalReasoningMarkdown`,children:(0,M.jsx)(`div`,{className:`compact-terminal-markdown compact-terminal-reasoning`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`reasoning`,children:(0,M.jsx)(uy,{streaming:e.status===`running`,children:e.markdown})})})]}):(0,M.jsx)(JC,{lines:t,status:e.status,clampPreview:n})}function JC({lines:e,status:t,clampPreview:n}){return e.map((e,r)=>(0,M.jsx)(cb,{line:e,status:t,clampLines:n&&r===0?5:void 0},r))}function YC({row:e,onFork:t,onOpenSession:n}){return(0,M.jsxs)(`div`,{className:`flex shrink-0 items-start gap-1 transition-opacity ${e.forkEntryId?`opacity-100`:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:[e.linkedPiboSessionId?(0,M.jsx)(gw,{label:`Open linked session`,onClick:()=>n(e.linkedPiboSessionId),children:`Open`}):null,e.forkEntryId?(0,M.jsxs)(gw,{label:`Fork from this user message`,onClick:()=>t(e.forkEntryId),children:[(0,M.jsx)(Qe,{size:13}),`Fork`]}):null]})}function XC(e,t=!1){let n=e.kind===`message.user`?`group border-b border-[#141414] bg-[#11a4d4]/10 py-2 last:border-b-0 hover:bg-[#11a4d4]/15`:e.kind===`execution.command`?`group border-b border-[#141414] bg-[#f59e0b]/5 py-2 last:border-b-0 hover:bg-[#f59e0b]/10`:`group border-b border-[#141414] py-2 last:border-b-0 hover:bg-[#161616]`,r=e.expandable||t?` focus:outline-none focus:ring-1 focus:ring-[#38bdf8]/50`:``;return t?`${n}${r} ring-1 ring-[#38bdf8] bg-[#123040]`:`${n}${r}`}function ZC(e,t,n){let r=new Set;for(let i of t)e.has(i.id)&&r.add(i.id),n&&i.kind===`reasoning`&&i.expandable&&r.add(i.id);return vw(e,r)?e:r}function QC(e,t){return t===`user`?e.kind===`message.user`:e.status===`error`?t===`tool`?e.errorKind===`tool`:e.errorKind!==`tool`:!1}function $C(e,t,n){let r=e.map((e,t)=>({row:e,index:t})).filter(({row:e})=>QC(e,t));if(!r.length)return;let i=n?e.findIndex(e=>e.id===n):-1,a=i>=0?i:e.length;return{...r.filter(e=>e.index<a).at(-1)??r[r.length-1],fromIndex:a}}function ew(e){let t=0,n=()=>{let r=Array.from(document.querySelectorAll(`[data-pibo-component="TerminalRow"]`)).find(t=>t.dataset.rowId===e);if(r){r.scrollIntoView({block:`start`,inline:`nearest`,behavior:`smooth`}),r.focus({preventScroll:!0});return}t+=1,t<8&&requestAnimationFrame(n)};requestAnimationFrame(()=>requestAnimationFrame(n))}function tw(e){return e.kind===`tool.group.exploring`||e.kind===`tool.group.images`?e.lines.slice(0,HC):e.lines}function nw(e){return!!e.expandable&&(e.kind===`tool.call`||e.kind===`tool.image`||e.kind===`tool.group.exploring`||e.kind===`tool.group.images`||e.kind===`agent.delegation`||e.kind===`agent.async`||e.kind===`yielded.run`||e.kind===`execution.command`||e.kind===`execution.compaction`)}function rw(e){let t=e.target;if(!(t instanceof Element)||t===e.currentTarget)return!1;let n=t.closest(`button, a, input, textarea, select, summary, [role='button'], [tabindex]:not([tabindex='-1'])`);return!!(n&&n!==e.currentTarget)}var iw=`Working...`,aw=33,ow=126;function sw(){let{chars:e,activeIndex:t}=cw(iw);return(0,M.jsx)(`div`,{className:`border-t border-[#141414] px-4 py-2`,role:`status`,"aria-live":`polite`,"aria-label":`Working`,children:(0,M.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,M.jsx)(`span`,{className:`whitespace-pre text-[#737373]`,children:`•`}),(0,M.jsx)(`span`,{className:`compact-terminal-working-scramble`,"aria-hidden":`true`,children:e.map((e,n)=>(0,M.jsx)(`span`,{className:n===t?`compact-terminal-working-scramble-active`:void 0,children:e},n))})]})})}function cw(e){let t=(0,v.useMemo)(()=>Array.from(e),[e]),[n,r]=(0,v.useState)(()=>uw(t)),[i,a]=(0,v.useState)(0);return(0,v.useEffect)(()=>{let e=0,n=0,i=fw(),o=0;r(uw(t));let s=window.setInterval(()=>{if(o>0){o--;return}if(e>=t.length){e=0,n=0,i=fw(),r(uw(t)),a(0);return}let s=e,c=t[s]??` `;if(a(s),n++,n<i){r(e=>lw(e,s,dw(c)));return}r(e=>lw(e,s,c)),e++,n=0,i=fw(),e>=t.length&&(r(t),a(-1),o=18)},55);return()=>window.clearInterval(s)},[t]),{chars:n,activeIndex:i}}function lw(e,t,n){let r=[...e];return r[t]=n,r}function uw(e){return e.map(e=>dw(e))}function dw(e){let t=``;do{let e=aw+Math.floor(Math.random()*(ow-aw+1));t=String.fromCharCode(e)}while(t===e);return t}function fw(){return 2+Math.floor(Math.random()*11)}function pw(){let e=mw();return(0,M.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,M.jsx)(`span`,{className:`whitespace-pre text-[#38bdf8]`,children:`•`}),(0,M.jsxs)(`span`,{className:`min-w-0`,children:[(0,M.jsx)(`span`,{className:`font-semibold text-[#38bdf8]`,children:`Compacting`}),(0,M.jsx)(`span`,{className:`text-[#38bdf8]`,children:e})]})]})}function mw(){let[e,t]=(0,v.useState)(0);return(0,v.useEffect)(()=>{let e=window.setInterval(()=>t(e=>(e+1)%4),400);return()=>window.clearInterval(e)},[]),`.`.repeat(e)}function hw({tone:e,label:t,onClick:n,children:r}){let i=`inline-flex items-center gap-1 border px-2 py-0.5 ${e===`cyan`?`border-[#1f4960] text-[#38bdf8]`:e===`red`?`border-[#5f2222] text-[#ef4444]`:e===`amber`?`border-[#6b4e16] text-[#f59e0b]`:e===`purple`?`border-purple-500/40 text-purple-300`:`border-[#3a3a3a] text-[#d4d4d4]`}`;return n?(0,M.jsx)(`button`,{type:`button`,onClick:n,className:`${i} hover:bg-white/5 focus:outline-none focus:ring-1 focus:ring-[#38bdf8]`,title:t,"aria-label":t,children:r}):(0,M.jsx)(`span`,{className:i,title:t,"aria-label":t,children:r})}function gw({label:e,onClick:t,children:n}){return(0,M.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e,title:e,className:`inline-flex min-h-7 min-w-7 items-center gap-1 border border-[#3a3a3a] px-2 text-[11px] text-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:n})}function _w({isLoading:e,agentProfiles:t,disabled:n,onSelectAgentProfile:r,message:i}){return(0,M.jsxs)(`div`,{className:`flex min-h-full flex-col items-center justify-center gap-4 px-6 py-10 text-center text-[12px] text-[#737373]`,children:[(0,M.jsx)(`div`,{children:e?`Loading trace…`:i??`No trace selected.`}),t.length?(0,M.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:t.map(e=>(0,M.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>r(e.name),className:`border border-[#3a3a3a] px-2 py-1 text-[#d4d4d4] hover:border-[#38bdf8] hover:text-[#38bdf8] disabled:opacity-50`,children:e.name},e.name))}):null]})}function vw(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function yw({traceView:e,isLoading:t,selectedSessionStatus:n,selectedSessionSignal:r,workflowProjectSession:i,workflowLifecycleEvents:a,sessionNodes:o,onOpenSession:s,onRefreshBootstrap:c,onError:l}){let u=i?zw(i,e,n,r,a??[],o):null;return u?(0,M.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,M.jsxs)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-4`,children:[(0,M.jsx)(bw,{model:u}),(0,M.jsx)(xw,{}),(0,M.jsx)(Sw,{model:u,onRefreshBootstrap:c,onError:l}),(0,M.jsx)(ww,{model:u}),(0,M.jsx)(Tw,{model:u,onOpenSession:s}),(0,M.jsx)(Mw,{nodes:u.nodes,edges:u.edges}),(0,M.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,M.jsx)(Pw,{model:u}),(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,M.jsx)(Fw,{model:u}),(0,M.jsx)(Iw,{model:u}),(0,M.jsx)(Lw,{model:u})]})]})]})}):(0,M.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,M.jsxs)(`div`,{className:`mx-auto flex max-w-4xl flex-col gap-4`,children:[(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,M.jsx)(rt,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState`]}),(0,M.jsx)(`p`,{className:`mt-2 text-sm text-slate-400`,children:t?`Loading session trace…`:`This session is not linked to a workflow run, so no Workflow/XState projection is available.`})]}),(0,M.jsx)(xw,{})]})})}function bw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,M.jsx)(rt,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState Projection`]}),(0,M.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2 text-xs`,children:[(0,M.jsx)(xT,{tone:`blue`,children:e.workflowId}),e.workflowRunId?(0,M.jsxs)(xT,{tone:`slate`,children:[`run `,ET(e.workflowRunId)]}):null,(0,M.jsx)(xT,{tone:ST(e.status),children:e.state})]})]}),(0,M.jsxs)(`div`,{className:`min-w-0 text-right font-mono text-[11px] text-slate-500`,children:[(0,M.jsxs)(`div`,{className:`truncate`,children:[`session `,ET(e.piboSessionId)]}),e.latestStreamId===void 0?null:(0,M.jsxs)(`div`,{children:[`stream `,e.latestStreamId]})]})]}),(0,M.jsx)(`p`,{className:`mt-3 text-sm text-slate-400`,children:`Dedicated Project workflow execution surface. This view derives the current XState-style UI snapshot from project-session workflow linkage and live session state while keeping kernel records as durable truth.`})]})}function xw(){return(0,M.jsx)(`div`,{className:`rounded-sm border border-amber-500/30 bg-amber-500/10 p-4 text-sm`,children:(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-amber-200`,children:[(0,M.jsx)(gt,{size:14}),`Workflow IR source-of-truth boundary`]}),(0,M.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-amber-100/80`,children:`Projects inspect configured sessions, workflow runs, and the XState-style projection derived from Pibo Workflow IR. Authoring stays in the Workflows tab; raw XState editing and inline executable code are not exposed here.`})]}),(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[(0,M.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`IR: source of truth`}),(0,M.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`XState: projection only`})]})]})})}function Sw({model:e,onRefreshBootstrap:t,onError:n}){let r=e.workflowRunId?jw(e):void 0,i=`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`;return(0,M.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,"aria-label":`Projects workflow execution shell`,children:[(0,M.jsx)(kw,{title:`Workflow configured-session view`,icon:(0,M.jsx)(at,{size:14}),children:(0,M.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,M.jsx)(Aw,{label:`selected workflow`,value:i}),(0,M.jsx)(Aw,{label:`session state`,value:e.workflowRunId?`started`:`configured/not-started`}),(0,M.jsx)(Aw,{label:`input keys`,value:String(e.configuration.inputKeys.length)}),(0,M.jsx)(Aw,{label:`prompt overrides`,value:String(e.configuration.promptOverrideNodeIds.length)}),(0,M.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`Saved configuration is reviewed here before Start. Workflow selection and session overrides remain immutable for this configured Project session.`})]})}),(0,M.jsx)(kw,{title:`Workflow run view`,icon:(0,M.jsx)(Se,{size:14}),children:(0,M.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,M.jsx)(Aw,{label:`run id`,value:e.workflowRunId?ET(e.workflowRunId):`not started`}),(0,M.jsx)(Aw,{label:`status`,value:e.state}),(0,M.jsx)(Aw,{label:`current node`,value:r?.label??`none`}),(0,M.jsx)(Aw,{label:`output`,value:e.finalOutput?`available`:`empty`}),(0,M.jsx)(Aw,{label:`error`,value:e.runtimeErrors.length?`${e.runtimeErrors.length} runtime errors`:e.validationErrors.length?`${e.validationErrors.length} validation diagnostics`:`none`}),(0,M.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This workflow run view container is the stable Project home for status, current node, output, and error sections.`})]})}),(0,M.jsx)(kw,{title:`Human action area`,icon:(0,M.jsx)(Ue,{size:14}),children:(0,M.jsx)(Cw,{model:e,onRefreshBootstrap:t,onError:n})})]})}function Cw({model:e,onRefreshBootstrap:t,onError:n}){let[r,i]=(0,v.useState)({}),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)({}),[l,u]=(0,v.useState)({}),d=(e,t)=>{i(n=>({...n,[e]:t}))},f=async(i,a)=>{if(!i.waitTokenId||!a.registered)return;let s=`${i.waitTokenId}:${a.id}`,l=a.kind??`resume`,d;if(l===`resume`){let e=r[i.waitTokenId]??(i.payloadRequirements?.required?`{}`:``);if(e.trim())try{d=JSON.parse(e)}catch{let e=[{code:`WorkflowRuntimeError.invalidHumanActionPayload`,message:`Resume payload must be valid JSON before it can be submitted.`,severity:`error`,path:`$.payload`,hint:`Enter JSON such as {"comment":"Approved"}.`}];c(t=>({...t,[i.waitTokenId]:e})),n?.(`Resume payload must be valid JSON.`);return}}o(s),c(e=>({...e,[i.waitTokenId]:[]}));try{await Sb(e.projectId,e.piboSessionId,{waitTokenId:i.waitTokenId,actionId:a.id,...a.kind?{kind:a.kind}:{},...d===void 0?{}:{payload:d}}),u(e=>({...e,[i.waitTokenId]:`${a.displayName} submitted.`})),n?.(null),await t?.()}catch(e){let t=lT(e);c(e=>({...e,[i.waitTokenId]:t})),n?.(t[0]?.message??uT(e))}finally{o(null)}};return(0,M.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[e.pendingHumanActions.length?(0,M.jsx)(`div`,{className:`space-y-3`,children:e.pendingHumanActions.map(e=>{let t=[...e.diagnostics,...e.waitTokenId?s[e.waitTokenId]??[]:[]];return(0,M.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-amber-100`,"aria-label":`Pending workflow human action wait token`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`font-semibold`,children:e.label}),(0,M.jsx)(`div`,{className:`mt-1 break-words text-[11px] leading-5 text-amber-100/80`,children:e.prompt})]}),(0,M.jsx)(`span`,{className:`shrink-0 rounded border border-amber-400/40 bg-[#0b0f14]/40 px-1.5 py-0.5 font-mono text-[10px] text-amber-100/70`,children:e.waitTokenId?ET(e.waitTokenId):e.source})]}),(0,M.jsxs)(`div`,{className:`mt-2 grid gap-2 text-[11px] text-amber-100/75`,children:[(0,M.jsx)(Aw,{label:`human node`,value:e.humanNodeId??`unspecified`}),(0,M.jsx)(Aw,{label:`payload`,value:e.payloadRequirements?.description??`No persisted payload schema.`}),e.expiresAt?(0,M.jsx)(Aw,{label:`expires`,value:e.expiresAt}):null]}),e.payloadRequirements?.schema?(0,M.jsxs)(`div`,{className:`mt-2 rounded-sm border border-amber-400/25 bg-[#0b0f14]/50 p-2`,children:[(0,M.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider text-amber-100/70`,children:`Resume payload schema`}),(0,M.jsx)(Sc,{value:e.payloadRequirements.schema,defaultExpandLevel:1,maxHeight:`10rem`,showControls:!1})]}):null,e.availableActions.some(e=>e.kind===`resume`)?(0,M.jsxs)(`label`,{className:`mt-3 block text-[11px] text-amber-100/80`,children:[(0,M.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Resume payload JSON`}),(0,M.jsx)(`textarea`,{className:`min-h-20 w-full rounded-sm border border-amber-500/30 bg-[#0b0f14] px-2 py-1.5 font-mono text-[11px] text-amber-50 outline-none focus:border-[#11a4d4]`,value:r[e.waitTokenId??e.id]??(e.payloadRequirements?.required?`{}`:``),onChange:t=>d(e.waitTokenId??e.id,t.target.value),placeholder:`{"comment":"Approved"}`})]}):null,(0,M.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,"aria-label":`Workflow wait token actions`,children:e.availableActions.length?e.availableActions.map(t=>{let n=`${e.waitTokenId}:${t.id}`;return(0,M.jsx)(`button`,{type:`button`,disabled:!e.waitTokenId||!t.registered||a!==null,onClick:()=>void f(e,t),className:`rounded-sm border border-amber-400/40 bg-[#0b0f14]/70 px-2.5 py-1 text-[11px] font-semibold text-amber-100 transition hover:border-[#11a4d4] hover:text-[#8bdcf4] disabled:cursor-not-allowed disabled:opacity-50`,title:t.description??t.id,children:a===n?`Submitting…`:t.displayName},t.id)}):(0,M.jsx)(`span`,{className:`text-amber-100/60`,children:`No registered human actions are available for this wait token.`})}),e.waitTokenId&&l[e.waitTokenId]?(0,M.jsx)(`div`,{className:`mt-2 text-[11px] text-emerald-200`,children:l[e.waitTokenId]}):null,t.length?(0,M.jsx)(`div`,{className:`mt-2 space-y-1`,"aria-label":`Human action diagnostics`,children:t.map((e,t)=>(0,M.jsxs)(`div`,{className:`rounded border border-red-400/35 bg-red-500/15 p-2 text-[11px] leading-5 text-red-100`,children:[(0,M.jsx)(`div`,{children:e.message}),(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-red-100/70`,children:[e.code,e.path?` · ${e.path}`:``]})]},`${e.code}:${t}`))}):null]},e.id)})}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-slate-500`,children:`No pending human action. Approval, rejection, resume, and cancel controls render here when a persisted workflow wait token exists.`}),(0,M.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This human action area lives inside the workflow run context, validates wait-token state and resume payloads, and stays separate from normal Terminal chat controls.`})]})}function ww({model:e}){let t=e.workflowRunId?jw(e):void 0,n=[...e.runtimeErrors.map(e=>({...e,source:e.source??`runtime`})),...e.validationErrors.map(e=>({...e,source:e.source??`validation`}))].slice(0,8);return(0,M.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow run inspection panel`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(Ke,{size:14}),`Workflow run inspection`]}),(0,M.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Status, current node, history, attempts, transfers, output, and errors are rendered from Project session and workflow run facts when a run is linked. The XState graph remains a visualization projection only.`})]}),(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2 text-[10px] uppercase tracking-wide`,children:[(0,M.jsx)(`span`,{className:`rounded border border-emerald-500/40 bg-emerald-500/10 px-2 py-1 text-emerald-200`,children:`kernel/run records: truth`}),(0,M.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-amber-500/10 px-2 py-1 text-amber-100`,children:`XState projection only`})]})]}),(0,M.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-3`,children:[(0,M.jsxs)(Ew,{title:`Status`,badge:e.state,icon:(0,M.jsx)(Se,{size:14}),children:[(0,M.jsx)(Dw,{label:`run id`,value:e.workflowRunId?ET(e.workflowRunId):`not started`}),(0,M.jsx)(Dw,{label:`status`,value:e.state}),(0,M.jsx)(Dw,{label:`record source`,value:e.workflowRunId?`Project workflow run id`:`no run record yet`})]}),(0,M.jsxs)(Ew,{title:`Current node`,badge:t?.status??`none`,icon:(0,M.jsx)(dt,{size:14}),children:[(0,M.jsx)(Dw,{label:`node`,value:t?.label??`none`}),(0,M.jsx)(Dw,{label:`node id`,value:t?.id??`none`}),(0,M.jsx)(Dw,{label:`source`,value:`project/session run cursor`})]}),(0,M.jsx)(Ew,{title:`Run history`,badge:`${e.runHistory.length}`,icon:(0,M.jsx)(tt,{size:14}),children:e.runHistory.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.runHistory.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:ET(e.id)}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${TT(e.status)}`,children:e.status})]}),(0,M.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.currentNodeId?`current ${e.currentNodeId}`:`no current node`,` · `,e.source]}),(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-600`,children:[`updated `,e.updatedAt]})]},e.id))}):(0,M.jsx)(Ow,{children:e.workflowRunId?`No workflow run history for this selected Project session yet.`:`No current run attempts; this configured Project session has not been started.`})})]}),(0,M.jsxs)(`div`,{className:`mt-3 grid gap-3 lg:grid-cols-2`,children:[(0,M.jsx)(Ew,{title:`Node attempts`,badge:`${e.nodeAttempts.length}`,icon:(0,M.jsx)(at,{size:14}),children:e.nodeAttempts.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.nodeAttempts.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.label}),(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:[e.nodeId,` · attempt `,e.attempt]})]}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${TT(e.status)}`,children:e.status})]}),(0,M.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.kind,` · `,e.source]})]},e.id))}):(0,M.jsx)(Ow,{children:e.workflowRunId?`No node attempts recorded for this workflow run yet.`:`No current node attempts; Start has not created a workflow run.`})}),(0,M.jsx)(Ew,{title:`Edge transfers`,badge:`${e.edgeTransfers.length}`,icon:(0,M.jsx)(Qe,{size:14}),children:e.edgeTransfers.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.edgeTransfers.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:e.edgeId}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${TT(e.status)}`,children:e.status})]}),(0,M.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.source,e.createdAt?` · ${e.createdAt}`:``]})]},e.id))}):(0,M.jsx)(Ow,{children:`No edge transfers recorded for this workflow run yet.`})}),(0,M.jsx)(Ew,{title:`Output`,badge:e.finalOutput?`available`:`empty`,icon:(0,M.jsx)(ze,{size:14}),children:e.finalOutput?(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,M.jsx)(`div`,{className:`mb-2 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}),(0,M.jsx)(Sc,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`12rem`,showControls:!1})]}):(0,M.jsx)(Ow,{children:`No workflow output has been recorded for this run yet.`})}),(0,M.jsx)(Ew,{title:`Error`,badge:n.length?`${n.length}`:`none`,icon:(0,M.jsx)(gt,{size:14}),children:n.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2 text-xs text-red-100`,children:[(0,M.jsx)(`div`,{className:`break-words`,children:e.message}),(0,M.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,M.jsx)(`span`,{children:e.code}):null,e.source?(0,M.jsx)(`span`,{children:e.source}):null]})]},e.id))}):(0,M.jsx)(Ow,{children:`No workflow run errors are recorded.`})})]})]})}function Tw({model:e,onOpenSession:t}){let n=Uw(e.definitionLink);return(0,M.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow navigation links`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(qe,{size:14}),`Workflow navigation links`]}),(0,M.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Use these run-view links to move between real nested workflow sessions and the Workflows tab definition. Snapshot-only history is shown when the live definition is deleted or unavailable.`})]}),e.definitionLink.status===`live`&&n?(0,M.jsxs)(`a`,{className:`inline-flex shrink-0 items-center justify-center gap-1 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100`,href:n,children:[(0,M.jsx)(qe,{size:13}),`Open live workflow definition`]}):null]}),(0,M.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-2`,children:[(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Nested workflow child session links`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Nested workflow child sessions`}),(0,M.jsx)(`span`,{className:`rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:e.nestedSessionLinks.length})]}),e.nestedSessionLinks.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.nestedSessionLinks.map(e=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>t(e.piboSessionId),className:`w-full rounded-sm border border-slate-800 bg-[#0b0f14] p-2 text-left transition hover:border-[#11a4d4]/60 hover:bg-[#102331]`,children:(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.title}),(0,M.jsx)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:ET(e.piboSessionId)})]}),(0,M.jsx)(`span`,{className:`rounded border border-[#11a4d4]/40 bg-[#11a4d4]/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-[#8bdcf4]`,children:`open session`})]})},e.piboSessionId))}):(0,M.jsx)(Ow,{children:`No nested workflow child sessions are linked under this selected Project session yet.`})]}),(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Workflow definition link state`,children:[(0,M.jsx)(`div`,{className:`mb-3 text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Workflow definition link`}),e.definitionLink.status===`live`&&n?(0,M.jsxs)(`div`,{className:`rounded-sm border border-emerald-500/35 bg-emerald-500/10 p-3 text-xs leading-5 text-emerald-100`,children:[(0,M.jsx)(`div`,{className:`font-semibold`,children:`Live workflow definition exists`}),(0,M.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-emerald-100/80`,children:Gw(e.definitionLink)}),e.definitionLink.definitionHash?(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-emerald-100/60`,children:[`snapshot `,ET(e.definitionLink.definitionHash)]}):null]}):(0,M.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-5 text-amber-100`,children:[(0,M.jsx)(`div`,{className:`font-semibold`,children:`Definition deleted — snapshot-only definition-deleted state`}),(0,M.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-amber-100/80`,children:Gw(e.definitionLink)}),(0,M.jsx)(`div`,{className:`mt-1 text-amber-100/80`,children:e.definitionLink.tombstoneLabel??`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}),e.definitionLink.definitionHash?(0,M.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-amber-100/60`,children:[`snapshot `,ET(e.definitionLink.definitionHash)]}):null]})]})]})]})}function Ew({title:e,badge:t,icon:n,children:r}){return(0,M.jsxs)(`section`,{className:`min-w-0 rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":e,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(`span`,{className:`text-[#11a4d4]`,children:n}),e]}),(0,M.jsx)(`span`,{className:`shrink-0 rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:t})]}),r]})}function Dw({label:e,value:t}){return(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 py-2 first:pt-0 last:border-b-0 last:pb-0`,children:[(0,M.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-slate-500`,children:e}),(0,M.jsx)(`span`,{className:`min-w-0 max-w-[14rem] truncate text-right font-mono text-xs text-slate-300`,title:t,children:t})]})}function Ow({children:e}){return(0,M.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-800 bg-[#0b0f14] p-3 text-xs leading-5 text-slate-500`,children:e})}function kw({title:e,icon:t,children:n}){return(0,M.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,"aria-label":e,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(`span`,{className:`text-[#11a4d4]`,children:t}),e]}),n]})}function Aw({label:e,value:t}){return(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,M.jsx)(`span`,{className:`uppercase tracking-wide text-slate-500`,children:e}),(0,M.jsx)(`span`,{className:`min-w-0 max-w-[12rem] truncate text-right font-mono text-slate-300`,title:t,children:t})]})}function jw(e){return e.nodes.find(e=>e.status===`active`||e.status===`waiting`)??e.nodes[0]}function Mw({nodes:e,edges:t}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-4`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(dt,{size:14}),`Visual State Flow`]}),(0,M.jsx)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_auto_1fr_auto_1fr]`,children:e.map((e,n)=>(0,M.jsx)(Nw,{node:e,edge:t[n]},e.id))})]})}function Nw({node:e,edge:t}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`rounded-sm border p-3 ${CT(e.status)}`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,M.jsx)(bT,{status:e.status}),(0,M.jsx)(`div`,{className:`min-w-0 truncate text-sm font-semibold text-slate-100`,children:e.label})]}),(0,M.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]}),(0,M.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]}),t?(0,M.jsx)(`div`,{className:`hidden items-center justify-center text-center text-[10px] uppercase tracking-wide text-slate-500 md:flex`,children:(0,M.jsxs)(`div`,{children:[(0,M.jsx)(Qe,{size:14,className:`mx-auto mb-1 text-[#11a4d4]`}),t.label]})}):null]})}function Pw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(Se,{size:14}),`Current UI Snapshot`]}),(0,M.jsx)(Sc,{value:e.snapshot,showControls:!1})]})}function Fw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(at,{size:14}),`Node Statuses`]}),(0,M.jsxs)(`span`,{className:`font-mono text-[11px] text-slate-500`,children:[e.nodes.length,` nodes`]})]}),(0,M.jsx)(`div`,{className:`space-y-2`,children:e.nodes.map(e=>(0,M.jsxs)(`div`,{className:`rounded-sm border px-3 py-2 ${CT(e.status)}`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,M.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:(0,M.jsx)(bT,{status:e.status})}),(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-sm font-semibold text-slate-100`,children:e.label}),(0,M.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-slate-500`,children:e.id})]})]}),(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${wT(e.status)}`,children:e.status}),(0,M.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]})]}),(0,M.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]},e.id))}),(0,M.jsx)(`p`,{className:`mt-3 text-xs text-slate-500`,children:`Node status is reconstructed from the workflow run linkage and live session state; persisted kernel records remain the durable source of truth.`})]})}function Iw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(ze,{size:14}),`Final Output & Validation`]}),(0,M.jsxs)(`div`,{className:`space-y-4`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Final output`}),e.finalOutput?(0,M.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}):null]}),e.finalOutput?(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:(0,M.jsx)(Sc,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`14rem`,showControls:!1})}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No final workflow output is available yet. Completed workflow-backed sessions show the final assistant output here.`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Validation errors`}),(0,M.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 font-mono text-[10px] ${e.validationErrors.length?`border-red-500/40 bg-red-500/10 text-red-300`:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`}`,children:e.validationErrors.length?`${e.validationErrors.length} found`:`none`})]}),e.validationErrors.length?(0,M.jsx)(`div`,{className:`space-y-2`,children:e.validationErrors.map(e=>(0,M.jsx)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2`,children:(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2 text-xs text-red-200`,children:[(0,M.jsx)(gt,{size:14,className:`mt-0.5 shrink-0 text-red-300`}),(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`break-words`,children:e.message}),(0,M.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,M.jsx)(`span`,{children:e.code}):null,e.path?(0,M.jsx)(`span`,{children:e.path}):null,e.source?(0,M.jsx)(`span`,{children:e.source}):null]})]})]})},e.id))}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No workflow validation diagnostics were found in the current session trace.`})]})]})]})}function Lw({model:e}){return(0,M.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,M.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,M.jsx)(He,{size:14}),`Projection Facts`]}),(0,M.jsxs)(`dl`,{className:`space-y-3`,children:[(0,M.jsx)(Rw,{label:`projection kind`,value:`pibo.workflow.xstateUiModel`}),(0,M.jsx)(Rw,{label:`schema`,value:`v1`}),(0,M.jsx)(Rw,{label:`durable truth`,value:`kernel`}),(0,M.jsx)(Rw,{label:`private payloads`,value:`not exposed`}),(0,M.jsx)(Rw,{label:`states`,value:String(e.nodes.length)}),(0,M.jsx)(Rw,{label:`transitions`,value:String(e.edges.length)}),(0,M.jsx)(Rw,{label:`trace`,value:e.traceVersion??`pending`})]})]})}function Rw({label:e,value:t}){return(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,M.jsx)(`dt`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:e}),(0,M.jsx)(`dd`,{className:`min-w-0 truncate text-right font-mono text-xs text-slate-300`,children:t})]})}function zw(e,t,n,r,i,a){if(!pT(e))return null;let o=mT(e,n),s=hT(e,n),c=gT(s),l=tT(t,s),u=[...rT(t),...nT(e,i)],d=Jw(e,o,c),f=Yw(t,e.workflowRunId),p=Qw(t,e.workflowRunId),m=$w(t,r),h=Bw(e),g=Vw(a,e.piboSessionId),_=[{id:`workflow.entry`,label:`workflow entry`,kind:`initial`,status:s===`idle`?`active`:`completed`,description:`Project session is linked to a workflow-capable route.`},{id:`node.session`,label:t?.title??`pibo session actor`,kind:`agent`,status:c===`node.session`?s:s===`completed`?`completed`:`idle`,description:`Normal Pibo routed session used as the visible workflow actor.`},{id:_T(s),label:vT(s),kind:`terminal`,status:c.startsWith(`workflow.`)?s:`idle`,description:`Terminal state projected from the current workflow/session state.`}];return{projectId:e.projectId,workflowId:e.workflowId,...e.workflowVersion?{workflowVersion:e.workflowVersion}:{},...e.workflowRunId?{workflowRunId:e.workflowRunId}:{},piboSessionId:e.piboSessionId,state:o,status:s,traceTitle:t?.title,traceVersion:t?.version,latestStreamId:t?.latestStreamId,nodes:_,edges:[{id:`workflow.transition.entry.session`,source:`workflow.entry`,target:`node.session`,label:`WORKFLOW.START`},{id:`workflow.transition.session.terminal`,source:`node.session`,target:_T(s),label:yT(s)}],configuration:Kw(e),definitionLink:h,nestedSessionLinks:g,pendingHumanActions:qw(e,r),runHistory:d,nodeAttempts:f,edgeTransfers:p,runtimeErrors:m,...l?{finalOutput:l}:{},validationErrors:u,snapshot:{kind:`pibo.workflow.xstateUiModel`,schemaVersion:1,projection:{workflowId:e.workflowId,initialStateId:`workflow.entry`,durableTruth:`kernel`,exposesPrivatePayloads:!1},authoring:{location:`workflows_tab`,rawXStateEditingUi:`not_exposed`,inlineExecutableCodeUi:`not_exposed`},current:{snapshotKind:`ui`,...e.workflowRunId?{runId:e.workflowRunId}:{},status:o,stateIds:[c],nodeId:c===`node.session`?`session`:void 0},nodeStatuses:_.map(e=>({id:e.id,kind:e.kind,status:e.status})),runInspection:{durableTruth:`kernel_run_records`,xstateProjectionOnly:!0,runHistoryCount:d.length,nodeAttemptCount:f.length,edgeTransferCount:p.length,runtimeErrorCount:m.length},result:{hasFinalOutput:!!l,validationErrorCount:u.length},actors:[{id:`workflow.actor.session`,kind:`agent`,piboSessionId:e.piboSessionId}],definitionLink:{status:h.status,workflowId:h.workflowId,workflowVersion:h.workflowVersion,hasLiveLink:h.status===`live`&&!!Uw(h)},nestedWorkflowSessionCount:g.length}}}function Bw(e){return e.workflowDefinitionLink?e.workflowDefinitionLink:e.workflowVersion?{status:`live`,workflowId:e.workflowId,workflowVersion:e.workflowVersion,title:e.title??e.workflowId,href:Ww(e.workflowId,e.workflowVersion)}:{status:`snapshot_only_definition_deleted`,workflowId:e.workflowId,title:e.title??e.workflowId,tombstoneLabel:`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}}function Vw(e,t){let n=Hw(e,t);if(!n)return[];let r=[],i=e=>{for(let t of e)t.workflowSessionKind===`nested_workflow`&&r.push({piboSessionId:t.piboSessionId,title:t.title,kind:t.workflowSessionKind??t.profile??`workflow`,...t.workflowSessionKind?{workflowSessionKind:t.workflowSessionKind}:{}}),i(t.children)};return i(n.children),r}function Hw(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=Hw(n.children,t);if(e)return e}}function Uw(e){if(e.status===`live`){if(e.href)return e.href;if(e.workflowVersion)return Ww(e.workflowId,e.workflowVersion)}}function Ww(e,t){return`/apps/chat/workflows/view/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function Gw(e){return`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`}function Kw(e){let t=e.configuration;return{inputKeys:Object.keys(t?.inputValues??{}).sort(),promptOverrideNodeIds:Object.keys(t?.promptOverrides??{}).sort()}}function qw(e,t){if(e.pendingHumanActions?.length)return e.pendingHumanActions.map(e=>({id:`wait-token:${e.waitTokenId}`,waitTokenId:e.waitTokenId,workflowRunId:e.workflowRunId,...e.nodeAttemptId?{nodeAttemptId:e.nodeAttemptId}:{},...e.humanNodeId?{humanNodeId:e.humanNodeId}:{},prompt:e.prompt,label:`Pending registered human action`,source:`persisted wait token`,...e.schema?{schema:e.schema}:{},payloadRequirements:e.payloadRequirements,availableActions:e.availableActions,diagnostics:e.diagnostics,createdAt:e.createdAt,...e.expiresAt?{expiresAt:e.expiresAt}:{}}));let n=mT(e,void 0).toLowerCase(),r=[t?.aggregateStatus,t?.localStatus].filter(e=>typeof e==`string`).join(` `).toLowerCase();return n.includes(`waiting`)||n.includes(`blocked`)||r.includes(`waiting`)||r.includes(`blocked`)||t?.hasBlockedDescendant?[{id:`human-action:${e.piboSessionId}`,prompt:`Session signal indicates a wait, but no persisted workflow wait token is available in the Project run store.`,label:`Awaiting human action`,source:t?`session signal`:`project session state`,availableActions:[],diagnostics:[]}]:[]}function Jw(e,t,n){return e.workflowRunId?[{id:e.workflowRunId,status:t,currentNodeId:n,updatedAt:e.updatedAt,source:`project session run record`}]:[]}function Yw(e,t){return!t||!e?[]:iT(e.nodes).filter(Xw).slice(0,8).map((e,t)=>({id:e.id,nodeId:e.stableKey??e.entryId??e.type,label:e.title||e.type,kind:e.type,status:Zw(e.status),attempt:t+1,source:`session trace fact`,...e.startedAt?{startedAt:e.startedAt}:{},...e.completedAt?{completedAt:e.completedAt}:{}}))}function Xw(e){return e.type===`agent.turn`||e.type===`tool.call`||e.type===`execution.command`||e.type===`agent.delegation`||e.type===`agent.async`||e.type===`yielded.run`||e.type===`error`}function Zw(e){return e===`done`?`completed`:e===`error`?`failed`:`running`}function Qw(e,t){if(!t||!e)return[];let n=[];for(let r of e.rawEvents){if(!fT(r.payload))continue;let e=dT(r.payload.type),i=dT(r.payload.runId);if(e!==`edge.transferred`||i&&i!==t)continue;let a=dT(r.payload.edgeId);a&&n.push({id:dT(r.payload.edgeTransferId)??r.id,edgeId:a,status:`transferred`,source:r.type,createdAt:r.createdAt})}return n.slice(0,8)}function $w(e,t){let n=[];for(let e of t?.errors??[])n.push({id:`signal:${n.length}`,message:e.message,...e.code?{code:e.code}:{},source:e.source??`session signal`});if(e){for(let t of iT(e.nodes)){let e=t.error??(t.status===`error`?oT(t.output)??oT(t.summary):void 0);e&&n.push({id:`node:${t.id}`,message:e,source:t.type})}for(let t of e.rawEvents){if(!fT(t.payload))continue;let e=t.payload.error,r=fT(e)?dT(e.message):dT(e),i=fT(e)?dT(e.code):void 0;r&&n.push({id:`event:${t.id}`,message:r,...i?{code:i}:{},source:t.type})}}return eT(n).slice(0,8)}function eT(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.message}:${e.source??``}`;return t.has(n)?!1:(t.add(n),!0)})}function tT(e,t){if(t!==`completed`||!e)return;let n=iT(e.nodes),r=[...n].reverse().find(e=>e.type===`assistant.message`&&e.status===`done`&&(e.output!==void 0||e.summary));if(r)return{value:r.output??r.summary??``,source:`assistant.message`};let i=[...n].reverse().find(e=>e.status===`done`&&e.type!==`user.message`&&e.type!==`model.reasoning`&&e.output!==void 0);return i?{value:i.output,source:i.type}:void 0}function nT(e,t){let n=[];for(let r of t)if(r.piboSessionId===e.piboSessionId&&!(r.type!==`project.workflow_start.blocked`&&r.validation?.trigger!==`before_workflow_start`))for(let e of r.diagnostics)e.severity===`error`&&n.push({id:`lifecycle:${r.id}:${n.length}`,message:e.message,code:e.code,path:e.path,source:`start lifecycle event`});return cT(n).slice(0,8)}function rT(e){if(!e)return[];let t=[];for(let n of iT(e.nodes)){let e=n.error??oT(n.output)??oT(n.summary);e&&(!sT([n.title,n.summary,n.error,n.type].filter(e=>typeof e==`string`).join(` `))&&!sT(e)||t.push({id:`node:${n.id}`,message:e,...n.type?{source:n.type}:{}}))}for(let n of e.rawEvents)aT(n.payload,`event:${n.id}`,t);return cT(t).slice(0,8)}function iT(e){let t=[],n=e=>{for(let r of e)t.push(r),n(r.children)};return n(e),t}function aT(e,t,n,r=0){if(r>4||!fT(e))return;let i=Array.isArray(e.diagnostics)?e.diagnostics:void 0;if(i)for(let e of i){if(!fT(e))continue;let r=dT(e.message)??oT(e);r&&n.push({id:`${t}:diagnostic:${n.length}`,message:r,...dT(e.code)?{code:dT(e.code)}:{},...dT(e.path)?{path:dT(e.path)}:{},source:`workflow.diagnostic`})}let a=e.error;if(fT(a)){let e=dT(a.code),r=dT(a.message)??oT(a);r&&sT([e,r].filter(Boolean).join(` `))&&n.push({id:`${t}:error:${n.length}`,message:r,...e?{code:e}:{},source:`workflow.error`})}else typeof a==`string`&&sT(a)&&n.push({id:`${t}:error:${n.length}`,message:a,source:`workflow.error`});for(let[i,a]of Object.entries(e))i===`diagnostics`||i===`error`||i!==`payload`&&i!==`output`&&i!==`result`&&i!==`data`||aT(a,`${t}:${i}`,n,r+1)}function oT(e){if(typeof e==`string`)return e;if(fT(e))return dT(e.message)??dT(e.error)??dT(e.summary)}function sT(e){let t=e.toLowerCase();return t.includes(`validation`)||t.includes(`validate`)||t.includes(`diagnostic`)||t.includes(`workflowinterfaceerror`)||t.includes(`workflowruntimeerror.validation`)}function cT(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.path??``}:${e.message}`;return t.has(n)?!1:(t.add(n),!0)})}function lT(e){return fT(e)&&fT(e.data)&&Array.isArray(e.data.diagnostics)?e.data.diagnostics.filter(fT).map(t=>({code:dT(t.code)??`WorkflowRuntimeError.humanActionRejected`,message:dT(t.message)??uT(e),severity:t.severity===`info`||t.severity===`warning`||t.severity===`error`?t.severity:`error`,...dT(t.path)?{path:dT(t.path)}:{},...dT(t.registryRef)?{registryRef:dT(t.registryRef)}:{},...dT(t.hint)?{hint:dT(t.hint)}:{}})):[{code:`WorkflowRuntimeError.humanActionRejected`,message:uT(e),severity:`error`}]}function uT(e){return e instanceof Error?e.message:String(e)}function dT(e){return typeof e==`string`&&e.trim()?e:void 0}function fT(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function pT(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function mT(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.workflowRunId?`workflow`:e.kind}function hT(e,t){let n=mT(e,t).toLowerCase();return e.archived?`cancelled`:n.includes(`complete`)||n.includes(`done`)?`completed`:n.includes(`fail`)||n.includes(`error`)?`failed`:n.includes(`cancel`)?`cancelled`:n.includes(`wait`)||n.includes(`blocked`)?`waiting`:!e.workflowRunId&&n.includes(`configured`)?`idle`:`active`}function gT(e){return e===`completed`?`workflow.completed`:e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`node.session`}function _T(e){return e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`workflow.completed`}function vT(e){return e===`failed`?`failed`:e===`cancelled`?`cancelled`:`completed`}function yT(e){return e===`failed`?`WORKFLOW.FAIL`:e===`cancelled`?`WORKFLOW.CANCEL`:`WORKFLOW.NODE.DONE`}function bT({status:e}){return e===`completed`?(0,M.jsx)(ze,{size:16,className:`text-emerald-300`}):e===`failed`?(0,M.jsx)(Ve,{size:16,className:`text-red-300`}):e===`cancelled`?(0,M.jsx)(gt,{size:16,className:`text-slate-400`}):e===`waiting`?(0,M.jsx)(Ue,{size:16,className:`text-amber-300`}):e===`active`?(0,M.jsx)(Se,{size:16,className:`text-[#11a4d4]`}):(0,M.jsx)(He,{size:16,className:`text-slate-500`})}function xT({tone:e,children:t}){return(0,M.jsx)(`span`,{className:`rounded border px-2 py-1 font-mono ${{blue:`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`,slate:`border-slate-700 bg-slate-900/50 text-slate-300`,green:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`,amber:`border-amber-500/40 bg-amber-500/10 text-amber-300`,red:`border-red-500/40 bg-red-500/10 text-red-300`}[e]}`,children:t})}function ST(e){return e===`completed`?`green`:e===`failed`||e===`cancelled`?`red`:e===`waiting`?`amber`:`blue`}function CT(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10`:e===`failed`?`border-red-500/40 bg-red-500/10`:e===`cancelled`?`border-slate-600 bg-slate-800/40`:e===`waiting`?`border-amber-500/40 bg-amber-500/10`:e===`active`?`border-[#11a4d4]/50 bg-[#11a4d4]/10 shadow-[0_0_0_1px_rgba(17,164,212,0.18)]`:`border-slate-800 bg-[#111820]`}function wT(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:e===`failed`||e===`cancelled`?`border-red-500/40 bg-red-500/10 text-red-300`:e===`waiting`?`border-amber-500/40 bg-amber-500/10 text-amber-300`:e===`active`?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function TT(e){let t=e.toLowerCase();return t.includes(`complete`)||t.includes(`done`)||t.includes(`transferred`)?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:t.includes(`fail`)||t.includes(`error`)||t.includes(`cancel`)?`border-red-500/40 bg-red-500/10 text-red-300`:t.includes(`wait`)||t.includes(`blocked`)?`border-amber-500/40 bg-amber-500/10 text-amber-300`:t.includes(`run`)||t.includes(`active`)||t.includes(`workflow`)?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function ET(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}var DT=[{id:`terminal`,label:`Terminal`,description:`Compact Codex-style terminal transcript.`,render:e=>(0,M.jsx)(UC,{...e})},{id:`workflow`,label:`Workflow`,description:`Workflow/XState visualization for workflow-backed project sessions.`,render:e=>(0,M.jsx)(yw,{...e})}],OT=new Map(DT.map(e=>[e.id,e]));function kT(){return DT}function AT(e){return OT.get(e)??OT.get(`terminal`)}var jT=`pibo.chat.composerHistory`,MT=100;function NT(){try{let e=localStorage.getItem(jT);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.trim().length>0).slice(-MT):[]}catch{return[]}}function PT(e){let t=e.trim();if(!t)return;let n=NT();if(n.at(-1)!==t)try{localStorage.setItem(jT,JSON.stringify([...n,t].slice(-MT)))}catch{}}function FT(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{return document.execCommand(`copy`),Promise.resolve()}finally{document.body.removeChild(t)}}function IT(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function LT({sessionId:e,disabled:t=!1,commands:n,skills:r,value:i,focusSignal:a,selectedWebAnnotations:o,selectedUploadAttachments:s,onValueChange:c,onCommand:l,onDetachWebAnnotation:u,onClearWebAnnotations:d,onAttachUploadedFiles:f,onDetachUploadAttachment:p,onClearUploadAttachments:m,onSend:h}){let g=(0,v.useRef)(null),_=(0,v.useRef)(null),y=(0,v.useRef)(null),b=(0,v.useRef)(null),x=(0,v.useRef)(null),S=(0,v.useRef)(null),C=(0,v.useRef)(null),[w,T]=(0,v.useState)(0),[E,ee]=(0,v.useState)(0),[D,O]=(0,v.useState)(0),[te,ne]=(0,v.useState)([]),[re,ie]=(0,v.useState)(!1),[ae,oe]=(0,v.useState)(null),[k,A]=(0,v.useState)(null),se=(0,v.useMemo)(()=>{for(let e=D-1;e>=0;e--){let t=i[e];if(t===` `||t===`
40
+ `||t===` `)break;if(t===`$`){if(e>0&&i[e-1]===`\\`)continue;return{query:i.slice(e+1,D).toLowerCase(),startPos:e,endPos:D}}}return null},[i,D]),ce=i.trim().startsWith(`/`)?i.trim().split(/\s+/)[0]:null,le=se?RT(se.startPos,i.slice(se.startPos,D)):null,ue=ce?zT(ce):null,fe=(0,v.useMemo)(()=>se?r.filter(e=>e.name.toLowerCase().startsWith(se.query)):[],[se,r]),pe=(0,v.useMemo)(()=>ce?n.filter(e=>e.slash.startsWith(ce)):[],[ce,n]),me=le&&te.includes(le)?[]:fe,he=ue&&te.includes(ue)?[]:pe,ge=(0,v.useCallback)(e=>{e&&ne(t=>t.includes(e)?t:[...t,e])},[]),_e=(0,v.useCallback)(()=>{let e=[fe.length?le:null,pe.length?ue:null].filter(e=>!!e);e.length&&ne(t=>{let n=new Set(t);for(let t of e)n.add(t);return n.size===t.length?t:[...n]})},[ue,pe.length,fe.length,le]);(0,v.useEffect)(()=>{let e=[le,ue].filter(e=>!!e);ne(t=>t.filter(t=>e.includes(t)))},[ue,le]),(0,v.useEffect)(()=>{!he.length||w<he.length||T(0)},[w,he.length]),(0,v.useEffect)(()=>{!me.length||E<me.length||ee(0)},[E,me.length]),(0,v.useEffect)(()=>{let e=requestAnimationFrame(()=>x.current?.scrollIntoView({block:`nearest`}));return()=>cancelAnimationFrame(e)},[w,he.length]),(0,v.useEffect)(()=>{let e=requestAnimationFrame(()=>S.current?.scrollIntoView({block:`nearest`}));return()=>cancelAnimationFrame(e)},[E,me.length]),(0,v.useEffect)(()=>{C.current=null},[e]),(0,v.useEffect)(()=>{if(!k)return;let e=requestAnimationFrame(()=>b.current?.focus());return()=>{cancelAnimationFrame(e),URL.revokeObjectURL(k.previewUrl)}},[k]),(0,v.useEffect)(()=>{if(a<=0)return;let e=_.current;if(!e)return;let t=e.value.length;e.focus(),e.setSelectionRange(t,t),O(t)},[a]),(0,v.useEffect)(()=>{if(!he.length&&!me.length)return;let e=e=>{let t=e.target;t instanceof Node&&(g.current?.contains(t)||_e())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[_e,he.length,me.length]),(0,v.useLayoutEffect)(()=>{KT(_.current)},[i]);let ve=e=>{if(!se||!_.current)return;let t=i.slice(0,se.startPos),n=i.slice(se.endPos);c(t+`$`+e+n),ge(RT(se.startPos,`$${e}`));let r=se.startPos+1+e.length;O(r),requestAnimationFrame(()=>{_.current?.setSelectionRange(r,r),O(r)})},ye=e=>{c(e),requestAnimationFrame(()=>{let e=_.current;if(!e)return;let t=e.value.length;e.setSelectionRange(t,t),O(t)})},be=e=>{let t=C.current;if(!t){if(e===`next`||i!==``)return!1;let t=NT();if(!t.length)return!1;let n=e===`previous`?t.length-1:0;return C.current={entries:t,index:n,draft:i},ye(t[n]),!0}if(e===`previous`){let e=Math.max(0,t.index-1);return C.current={...t,index:e},ye(t.entries[e]),!0}let n=t.index+1;return n>=t.entries.length?(C.current=null,ye(t.draft),!0):(C.current={...t,index:n},ye(t.entries[n]),!0)},xe=()=>{t||re||y.current?.click()},j=()=>{A(null)},Se=e=>{if(t||re)return;let n=BT(e.clipboardData);if(!n.length)return;e.preventDefault(),_e(),oe(null);let r=n[0];A(e=>(e&&URL.revokeObjectURL(e.previewUrl),{file:r,previewUrl:URL.createObjectURL(r)}))},Ce=async()=>{if(!k||re)return;let e=k.file;A(null),await we([e])},we=async e=>{if(e.length){ie(!0),oe({message:`Uploading ${e.length} file${e.length===1?``:`s`}...`,error:!1});try{f((await de(e)).files),oe(null)}catch(e){oe({message:e instanceof Error?e.message:String(e),error:!0})}finally{ie(!1)}}},Te=async()=>{if(t)return;let e=i.trim();if(e){if(me.length){ve(me[Math.min(E,me.length-1)].name);return}if(he.length&&!n.some(t=>t.slash===e.split(/\s+/)[0])){let e=he[Math.min(w,he.length-1)].slash;c(e),ge(zT(e));return}if(C.current=null,PT(e),c(``),e.split(/\s+/)[0]===`/upload`){xe();return}e.startsWith(`/`)&&await l(e)||await h(e)}};return(0,M.jsxs)(`div`,{ref:g,"data-pibo-debug":`composer`,"data-pibo-session-id":e??void 0,"data-pibo-state":t?`disabled`:i?`non-empty`:`empty`,className:`relative p-3 bg-[#151f24] border-t border-slate-800 max-[980px]:p-2`,children:[(0,M.jsx)(`input`,{ref:y,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,we(t)}}),ae?(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-sm border px-3 py-2 text-xs ${ae.error?`border-red-900 bg-red-950/40 text-red-200`:ae.copyText?`border-green-900/60 bg-green-950/30 text-green-300`:`border-slate-700 bg-[#0e1116] text-slate-300`}`,children:[(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:ae.message}),ae.copyText?(0,M.jsx)(`button`,{type:`button`,onClick:()=>void FT(ae.copyText),title:`Copy uploaded file path`,"aria-label":`Copy uploaded file path`,className:`shrink-0 rounded-sm p-0.5 text-slate-400 hover:bg-slate-800 hover:text-[#11a4d4]`,children:(0,M.jsx)(We,{size:13})}):null,(0,M.jsx)(`button`,{type:`button`,onClick:()=>oe(null),title:`Hide upload status`,"aria-label":`Hide upload status`,className:`shrink-0 rounded-sm p-0.5 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,children:(0,M.jsx)(vt,{size:13})})]}):null,k?(0,M.jsx)(`div`,{className:`fixed inset-0 z-50 grid place-items-center bg-black/60 px-4`,role:`dialog`,"aria-modal":`true`,"aria-label":`Upload pasted image`,onKeyDown:e=>{e.key===`Escape`&&j()},children:(0,M.jsxs)(`div`,{className:`w-full max-w-md rounded-sm border border-slate-700 bg-[#151f24] shadow-2xl`,children:[(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800 px-4 py-3`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Pasted image detected`}),(0,M.jsx)(`div`,{className:`mt-1 text-xs text-slate-400`,children:`Upload this clipboard image to ~/.pibo/uploads?`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:j,className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":`Cancel pasted image upload`,children:(0,M.jsx)(vt,{size:14})})]}),(0,M.jsxs)(`div`,{className:`space-y-3 px-4 py-4`,children:[(0,M.jsx)(`img`,{src:k.previewUrl,alt:`Pasted clipboard image preview`,className:`max-h-64 w-full rounded-sm border border-slate-800 bg-[#0e1116] object-contain`}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-slate-400`,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate font-mono`,children:k.file.name}),(0,M.jsx)(`span`,{className:`shrink-0 font-mono`,children:GT(k.file.size)})]})]}),(0,M.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-slate-800 px-4 py-3`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:j,className:`h-8 rounded-sm border border-slate-700 px-3 text-xs text-slate-300 hover:border-slate-500 hover:text-slate-100`,children:`Cancel`}),(0,M.jsx)(`button`,{ref:b,type:`button`,onClick:()=>void Ce(),disabled:re,className:`h-8 rounded-sm bg-[#11a4d4] px-3 text-xs font-medium text-white disabled:opacity-50`,children:`Upload image`})]})]})}):null,me.length?(0,M.jsx)(`div`,{className:`absolute left-3 bottom-full mb-2 w-[min(520px,calc(100%-24px))] max-h-72 overflow-auto bg-[#0e1116] border border-emerald-500 rounded-sm shadow-xl`,children:me.map((e,t)=>(0,M.jsxs)(`button`,{ref:t===E?S:null,type:`button`,onClick:()=>ve(e.name),className:`w-full grid grid-cols-[120px_1fr] gap-2 px-3 py-2 text-left border-b border-slate-800 ${t===E?`bg-emerald-500/15`:``}`,children:[(0,M.jsxs)(`span`,{className:`font-mono text-emerald-400`,children:[`$`,e.name]}),(0,M.jsx)(`span`,{className:`text-xs text-slate-400`,children:e.description??e.path??``})]},e.name))}):null,s.length?(0,M.jsxs)(`div`,{className:`mb-2 rounded-sm border border-slate-800 bg-[#0e1116] px-2.5 py-1.5`,"data-pibo-debug":`composer-upload-attachments`,"data-upload-attachment-count":s.length,children:[(0,M.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Attached uploads`}),(0,M.jsx)(`button`,{type:`button`,onClick:m,className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Clear`})]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map(e=>(0,M.jsxs)(`div`,{title:e.path,className:`inline-flex max-w-80 items-center gap-1 rounded-sm border border-emerald-500/45 bg-emerald-500/10 px-2 py-1 text-left text-[11px] text-slate-200`,"data-pibo-debug":`composer-upload-attachment-chip`,"data-upload-path":e.path,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:IT(e.name||e.path,100)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void FT(e.path),title:`Copy uploaded file path`,"aria-label":`Copy uploaded file path`,className:`shrink-0 rounded-sm p-0.5 text-emerald-300 hover:bg-slate-800 hover:text-[#11a4d4]`,children:(0,M.jsx)(We,{size:11})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>p(e.id),title:`Detach ${e.name||e.path}`,"aria-label":`Detach ${e.name||e.path}`,className:`shrink-0 rounded-sm p-0.5 text-emerald-300 hover:bg-slate-800 hover:text-slate-100`,children:(0,M.jsx)(vt,{size:11})})]},e.id))})]}):null,o.length?(0,M.jsxs)(`div`,{className:`mb-2 rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2`,"data-pibo-debug":`composer-web-annotations`,"data-web-annotation-count":o.length,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Attached web annotations`}),(0,M.jsx)(`button`,{type:`button`,onClick:d,className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Clear`})]}),(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:o.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),title:`Detach ${e.id}`,className:`inline-flex max-w-72 items-center gap-1 rounded-sm border border-[#11a4d4]/50 bg-[#11a4d4]/10 px-2 py-1 text-left text-[11px] text-slate-200`,"data-pibo-debug":`composer-web-annotation-chip`,"data-web-annotation-id":e.id,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:IT(e.primaryTarget||e.label||e.note||e.id,100)}),(0,M.jsx)(vt,{size:11,className:`shrink-0 text-[#11a4d4]`})]},e.id))})]}):null,he.length?(0,M.jsx)(`div`,{className:`absolute left-3 bottom-full mb-2 w-[min(520px,calc(100%-24px))] max-h-72 overflow-auto bg-[#0e1116] border border-[#11a4d4] rounded-sm shadow-xl`,children:he.map((e,t)=>(0,M.jsxs)(`button`,{ref:t===w?x:null,type:`button`,onClick:()=>{c(e.slash),ge(zT(e.slash)),T(t)},className:`w-full grid grid-cols-[120px_1fr] gap-2 px-3 py-2 text-left border-b border-slate-800 ${t===w?`bg-[#11a4d4]/15`:``}`,children:[(0,M.jsx)(`span`,{className:`font-mono text-[#11a4d4]`,children:e.slash}),(0,M.jsx)(`span`,{className:`text-xs text-slate-400`,children:e.description})]},e.slash))}):null,(0,M.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-end gap-2`,children:[(0,M.jsx)(`textarea`,{ref:_,"data-pibo-debug":`composer-input`,"data-pibo-session-id":e??void 0,"data-pibo-state":t?`disabled`:i?`non-empty`:`empty`,rows:1,value:i,disabled:t,onChange:e=>{C.current=null,c(e.target.value),O(e.target.selectionStart)},onKeyDown:e=>{if(e.key===`Escape`&&(me.length||he.length)){e.preventDefault(),e.stopPropagation(),_e();return}if(me.length&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){e.preventDefault(),ee(t=>e.key===`ArrowDown`?(t+1)%me.length:(t-1+me.length)%me.length);return}if(he.length&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){e.preventDefault(),T(t=>e.key===`ArrowDown`?(t+1)%he.length:(t-1+he.length)%he.length);return}if((e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&be(e.key===`ArrowUp`?`previous`:`next`)){e.preventDefault();return}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Te())},onPaste:Se,placeholder:t?`Select a session to message`:`Send Message (/ for commands or $ for skills)`,className:`h-10 min-h-10 resize-none overflow-hidden bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm leading-5 outline-none focus:border-[#11a4d4] disabled:opacity-50 [scrollbar-gutter:stable]`}),(0,M.jsx)(`button`,{type:`button`,disabled:t||re,onClick:()=>void Te(),title:`Send message`,"aria-label":`Send message`,className:`h-10 w-10 self-end inline-flex items-center justify-center bg-[#11a4d4] rounded-sm text-white disabled:opacity-50`,children:(0,M.jsx)(mt,{size:16})})]})]})}function RT(e,t){return`skill:${e}:${t}`}function zT(e){return`command:${e}`}function BT(e){let t=Array.from(e.items).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);return(t.length?t:Array.from(e.files).filter(e=>e.type.startsWith(`image/`))).map(VT)}function VT(e){return e.name&&e.name!==`image.png`?e:new File([e],HT(e.type),{type:e.type||`image/png`,lastModified:Date.now()})}function HT(e){let t=UT(e),n=new Date;return`screenshot-${[n.getFullYear(),WT(n.getMonth()+1),WT(n.getDate()),`-`,WT(n.getHours()),WT(n.getMinutes()),WT(n.getSeconds())].join(``)}${t}`}function UT(e){switch(e){case`image/jpeg`:return`.jpg`;case`image/gif`:return`.gif`;case`image/webp`:return`.webp`;case`image/svg+xml`:return`.svg`;default:return`.png`}}function WT(e){return String(e).padStart(2,`0`)}function GT(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:`${(e/(1024*1024)).toFixed(1)} MiB`}function KT(e){if(!e)return;if(!e.value.includes(`
41
+ `)&&e.value.length<80){e.style.height=``,e.style.overflowY=`hidden`;return}let t=window.getComputedStyle(e),n=qT(t.lineHeight,20),r=qT(t.borderTopWidth)+qT(t.borderBottomWidth),i=n*5+qT(t.paddingTop)+qT(t.paddingBottom);e.style.height=`auto`;let a=e.scrollHeight,o=a>i;e.style.height=`${Math.min(a,i)+r}px`,e.style.overflowY=o?`auto`:`hidden`,o&&e.selectionStart===e.value.length&&e.selectionEnd===e.value.length&&(e.scrollTop=a)}function qT(e,t=0){let n=Number.parseFloat(e);return Number.isFinite(n)?n:t}var JT=`pibo.chat.webAnnotations.cdpUrl`,YT=`pibo.chat.webAnnotations.selected.`,XT=`pibo.chat.webAnnotations.overlay.`,ZT=`pibo.chat.webAnnotations.panelCollapsed`,QT=`pibo.chat.shortcuts.webAnnotationsToggle`,$T=`Alt+Shift+A`;function eE(){try{return localStorage.getItem(JT)??``}catch{return``}}function tE(e){try{e.trim()?localStorage.setItem(JT,e.trim()):localStorage.removeItem(JT)}catch{}}function nE(){try{return localStorage.getItem(QT)||`Alt+Shift+A`}catch{return $T}}function rE(e){try{return aE(localStorage.getItem(iE(e)))}catch{return null}}function iE(e){return XT+e}function aE(e){if(!e)return null;try{return oE(JSON.parse(e))}catch{return null}}function oE(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.piboSessionId==`string`?t.piboSessionId.trim():``;return n?{bindingId:typeof t.bindingId==`string`?t.bindingId:void 0,piboSessionId:n,installed:t.installed!==!1,active:t.active===!0,toolbarExpanded:t.toolbarExpanded===!0,mode:typeof t.mode==`string`?t.mode:void 0,reason:typeof t.reason==`string`?t.reason:void 0,updatedAt:typeof t.updatedAt==`string`?t.updatedAt:void 0}:null}function sE(e){try{let t=localStorage.getItem(YT+e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`&&!!e.trim()).slice(0,5):[]}catch{return[]}}function cE(e,t){try{let n=YT+e,r=[...new Set(t.filter(e=>e.trim()))].slice(0,5);r.length?localStorage.setItem(n,JSON.stringify(r)):localStorage.removeItem(n)}catch{}}function lE(){try{return localStorage.getItem(ZT)===`true`}catch{return!1}}function uE(e){try{localStorage.setItem(ZT,String(e))}catch{}}function dE({piboSessionId:e,annotations:t,selectedIds:n,loading:r,error:i,collapsed:a,onRefresh:o,onToggle:s,onClear:c,onCollapse:l,onClose:u}){return e?(0,M.jsxs)(`section`,{className:`border-t border-slate-800 bg-[#101d22] px-3 py-2 sm:px-4`,"data-pibo-debug":`web-annotations-session-panel`,"data-pibo-session-id":e,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web annotations`}),(0,M.jsx)(`span`,{className:`rounded-sm border border-slate-700 px-1.5 py-0.5 text-[10px] text-slate-400`,children:t.length}),n.length?(0,M.jsxs)(`span`,{className:`rounded-sm border border-[#11a4d4]/50 px-1.5 py-0.5 text-[10px] text-[#11a4d4]`,children:[n.length,` attached`]}):null]}),a?null:(0,M.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Global annotation list. Selected attachments are remembered per session.`})]}),(0,M.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:o,disabled:r,title:`Refresh annotations`,"aria-label":`Refresh annotations`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50 sm:h-7 sm:w-7`,"data-pibo-debug":`web-annotations-refresh`,children:(0,M.jsx)(ut,{size:12,className:r?`animate-spin`:void 0})}),(0,M.jsx)(`button`,{type:`button`,onClick:c,disabled:r||!t.length,title:`Clear visible annotations`,"aria-label":`Clear visible annotations`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-red-500 hover:text-red-300 disabled:opacity-50 sm:h-7 sm:w-7`,children:(0,M.jsx)(ht,{size:12})}),(0,M.jsx)(`button`,{type:`button`,onClick:l,title:a?`Expand annotations panel`:`Collapse annotations panel`,"aria-label":a?`Expand annotations panel`:`Collapse annotations panel`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] sm:h-7 sm:w-7`,children:a?(0,M.jsx)(Le,{size:12}):(0,M.jsx)(Fe,{size:12})}),(0,M.jsx)(`button`,{type:`button`,onClick:u,title:`Hide annotations panel`,"aria-label":`Hide annotations panel`,className:`inline-flex h-8 w-8 items-center justify-center rounded-sm border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] sm:h-7 sm:w-7`,children:(0,M.jsx)(vt,{size:12})})]})]}),a?null:i?(0,M.jsx)(`div`,{className:`rounded-sm border border-red-900 bg-red-950/40 px-3 py-2 text-xs text-red-200`,"data-pibo-debug":`web-annotations-error`,children:bE(i,220)}):r&&!t.length?(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2 text-xs text-slate-400`,"data-pibo-debug":`web-annotations-loading`,children:`Loading annotations…`}):t.length?(0,M.jsx)(`div`,{className:`mt-2 grid max-h-[min(40svh,18rem)] grid-cols-1 gap-2 overflow-y-auto pr-1 sm:max-h-56 sm:grid-cols-[repeat(auto-fill,minmax(16rem,1fr))]`,"data-pibo-debug":`web-annotations-list`,children:t.map(e=>{let t=n.includes(e.id);return(0,M.jsxs)(`div`,{"data-pibo-debug":`web-annotation-chip`,"data-web-annotation-id":e.id,"data-web-annotation-session-id":e.piboSessionId,"data-web-annotation-selected":t?`true`:`false`,className:`min-w-0 rounded-sm border px-3 py-2 text-xs ${t?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#0e1116]`}`,children:[(0,M.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,M.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-slate-500`,children:[e.status,` · `,e.targetKind]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>s(e.id),className:`inline-flex h-8 shrink-0 items-center gap-1 rounded-sm border px-2 text-[11px] sm:h-6 sm:px-1.5 ${t?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:[t?(0,M.jsx)(vt,{size:11}):(0,M.jsx)(lt,{size:11}),` `,t?`Detach`:`Attach`]})]}),(0,M.jsx)(`div`,{className:`truncate text-slate-200`,title:e.primaryTarget||e.label||e.selector||e.id,children:bE(e.primaryTarget||e.label||e.selector||e.id,120)}),e.piboContext?(0,M.jsx)(`div`,{className:`truncate font-mono text-[11px] text-[#11a4d4]`,title:e.piboContext,children:bE(e.piboContext,140)}):null,(0,M.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:yE(e.url)}),(0,M.jsx)(`div`,{className:`mt-1 line-clamp-2 text-slate-400`,title:e.note,children:bE(e.note,180)}),(0,M.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-600`,children:xE(e.createdAt)})]},e.id)})}):(0,M.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2 text-xs text-slate-500`,"data-pibo-debug":`web-annotations-empty`,children:`No open annotations for this session.`})]}):null}function fE({piboSessionId:e,piboRoomId:t,disabled:n,panelVisible:r,onShowPanel:i,onHidePanel:a,onError:o}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(()=>eE()),[p,m]=(0,v.useState)([]),[h,g]=(0,v.useState)(`idle`),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)(null);(0,v.useEffect)(()=>{n&&c(!1)},[n]),(0,v.useEffect)(()=>{tE(d)},[d]);let S=async()=>{if(e){g(`loading`),x(null);try{m((await vb(d)).targets.filter(e=>e.type===`page`||e.attachable)),g(`loaded`)}catch(e){let t=_E(e,`CDP unavailable`);m([]),g(`error`),x({kind:`error`,message:t}),o(t)}}},C=async n=>{if(!e)throw Error(`No active session context`);return bb(n.binding.id,mE({piboSessionId:e,piboRoomId:t,cdpUrl:d,annotationShortcut:nE()}))},w=async()=>{if(!(!e||_)){i(),y(!0),x({kind:`info`,message:`Injecting annotation overlay into this Pibo page…`});try{let n=await yb({piboSessionId:e,piboRoomId:t,url:window.location.href,title:document.title,sameOrigin:!0,annotationShortcut:nE()});if(!n.overlay)throw Error(`Overlay config missing from same-origin binding response`);await gE(n.overlay),x({kind:`success`,message:`Annotation overlay is ready on this Pibo page. Open the overlay controls or use the shortcut to start annotating.`}),o(null)}catch(e){let t=_E(e,`Current-page annotation failed`);x({kind:`error`,message:t}),o(t)}finally{y(!1)}}},T=async()=>{if(!e||_)return;i();let n=l.trim();if(!n){x({kind:`error`,message:`URL is required`});return}if(hE(n)){let e=`That looks like a CDP endpoint. Put it in CDP URL, and put the page you want to annotate in Annotate URL.`;x({kind:`error`,message:e}),o(e);return}y(!0),x({kind:`info`,message:`Opening target and injecting overlay…`});try{let r=await yb(mE({piboSessionId:e,piboRoomId:t,url:n,cdpUrl:d})),i=await C(r);x({kind:`success`,message:`Annotation overlay injected for ${vE(i.target??r.target,i.binding.url)}`}),u(``),o(null)}catch(e){let t=_E(e,`Annotation failed`);x({kind:`error`,message:t}),o(t)}finally{y(!1)}},E=async n=>{if(!(!e||_)){i(),y(!0),x({kind:`info`,message:`Binding selected target and injecting overlay…`});try{let r=await C(await yb(mE({piboSessionId:e,piboRoomId:t,targetId:n.id,cdpUrl:d})));x({kind:`success`,message:`Annotation overlay injected for ${vE(r.target??n,r.binding.url)}`}),o(null)}catch(e){let t=_E(e,n.attachable?`Target annotation failed`:`Target not attachable`);x({kind:`error`,message:t}),o(t)}finally{y(!1)}}};return(0,M.jsxs)(`div`,{className:`relative`,"data-pibo-debug":`web-annotations-entry`,"data-pibo-session-id":e??void 0,children:[(0,M.jsx)(pE,{onClick:()=>{n||(c(e=>!e),r||i())},title:n?`Select an active session to annotate a web page`:r?`Web Annotations`:`Show Web Annotations`,ariaLabel:`Web Annotations`,active:s||r,children:(0,M.jsx)(De,{size:14})}),s&&!n?(0,M.jsxs)(`div`,{className:`fixed inset-x-2 bottom-3 z-40 max-h-[calc(100svh-1.5rem)] overflow-y-auto rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-sm shadow-xl sm:absolute sm:inset-auto sm:right-0 sm:top-full sm:bottom-auto sm:mt-2 sm:w-[min(420px,calc(100vw-24px))] sm:max-h-[calc(100svh-5rem)]`,role:`dialog`,"aria-label":`Web Annotations`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-start justify-between gap-3`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web Annotations`}),(0,M.jsx)(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Start an inactive overlay for this Pibo page, or bind a CDP target for external pages.`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:r?a:i,className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":r?`Hide annotation list`:`Show annotation list`,title:r?`Hide annotation list`:`Show annotation list`,children:(0,M.jsx)(ft,{size:14})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":`Close Web Annotations panel`,children:(0,M.jsx)(vt,{size:14})})]})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void w(),disabled:_,className:`mb-3 h-10 w-full rounded-sm bg-emerald-600 px-3 text-xs font-medium text-white hover:bg-emerald-500 disabled:opacity-50 sm:h-9`,"data-pibo-debug":`web-annotations-current-page`,children:`Annotate this Pibo page`}),(0,M.jsx)(`label`,{className:`mb-2 block text-[11px] font-bold uppercase tracking-wider text-slate-500`,htmlFor:`web-annotation-url`,children:`Annotate URL via CDP`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[1fr_auto]`,children:[(0,M.jsx)(`input`,{id:`web-annotation-url`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T()},placeholder:`http://localhost:5173`,disabled:_,className:`h-10 min-w-0 rounded-sm border border-slate-700 bg-[#151f24] px-2 text-base text-slate-100 outline-none focus:border-[#11a4d4] disabled:opacity-60 sm:h-9 sm:text-xs`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void T(),disabled:_||!l.trim(),className:`h-10 rounded-sm bg-[#11a4d4] px-3 text-xs font-medium text-white disabled:opacity-50 sm:h-9`,children:`Annotate`})]}),(0,M.jsx)(`label`,{className:`mt-3 mb-1 block text-[11px] font-bold uppercase tracking-wider text-slate-500`,htmlFor:`web-annotation-cdp-url`,children:`CDP URL (optional)`}),(0,M.jsx)(`input`,{id:`web-annotation-cdp-url`,value:d,onChange:e=>f(e.target.value),placeholder:`Use gateway default`,disabled:_,className:`h-10 w-full rounded-sm border border-slate-800 bg-[#151f24] px-2 font-mono text-base text-slate-300 outline-none focus:border-[#11a4d4] disabled:opacity-60 sm:h-8 sm:text-[11px]`}),(0,M.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2`,children:[(0,M.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-slate-500`,children:`Existing targets`}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>void S(),disabled:_||h===`loading`,className:`inline-flex h-7 items-center gap-1 rounded-sm border border-slate-700 px-2 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[(0,M.jsx)(ut,{size:12,className:h===`loading`?`animate-spin`:void 0}),` Refresh`]})]}),(0,M.jsxs)(`div`,{className:`mt-2 max-h-[min(34svh,14rem)] overflow-auto rounded-sm border border-slate-800 sm:max-h-56`,children:[h===`idle`?(0,M.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`Refresh to list reachable browser targets.`}):null,h===`loading`?(0,M.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-400`,children:`Loading targets…`}):null,h===`loaded`&&!p.length?(0,M.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`No attachable browser targets found.`}):null,p.map(e=>(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 border-b border-slate-800 px-3 py-2 last:border-b-0 sm:grid-cols-[1fr_auto]`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`truncate text-xs text-slate-200`,title:e.title||e.url,children:bE(e.title||`Untitled target`,120)}),(0,M.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:bE(e.url||e.id,160)})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void E(e),disabled:_||!e.attachable,title:e.attachable?`Attach selected target`:`Target is not attachable`,className:`h-9 rounded-sm border border-slate-700 px-2 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-40 sm:h-8`,children:`Attach`})]},e.id))]}),b?(0,M.jsx)(`div`,{className:`mt-2 rounded-sm border px-2 py-2 text-xs ${b.kind===`error`?`border-red-900 bg-red-950/40 text-red-200`:b.kind===`success`?`border-emerald-900/60 bg-emerald-950/30 text-emerald-300`:`border-slate-700 bg-[#151f24] text-slate-300`}`,children:b.message}):null]}):null]})}function pE({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,M.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function mE(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e&&e.trim()))}function hE(e){try{let t=new URL(e);return t.port===`56663`||t.pathname.startsWith(`/json/`)}catch{return!1}}function gE(e){return new Promise((t,n)=>{let r=window;try{r.__piboWebAnnotations?.remove?.(),r.__piboWebAnnotationConfig=e;let i=document.createElement(`script`);i.src=`/apps/web-annotations/overlay.js?ts=${Date.now()}`,i.async=!0,i.onload=()=>t(),i.onerror=()=>n(Error(`Could not load Web Annotation overlay script`)),document.head.appendChild(i)}catch(e){n(e)}})}function _E(e,t){let n=SE(e);return!n||n===`undefined`?t:/target.*not found|selected cdp target/i.test(n)?`Target not found: ${n}`:/inject|overlay|evaluation/i.test(n)?`Injection failed: ${n}`:/cdp endpoint.*is unreachable|failed to fetch|fetch failed|chrome target discovery|cdp unavailable|econnrefused|connect/i.test(n)?`CDP unavailable: ${n}`:`${t}: ${n}`}function vE(e,t){let n=e?.url||t||e?.title||`target`;return yE(e?.title||n)}function yE(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return bE(e,80)}}function bE(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function xE(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`short`,timeStyle:`short`})}function SE(e){return e instanceof Error?e.message:String(e)}function CE(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function wE(e,t){return{workflowId:e.workflowId,state:EE(e,t),...e.workflowRunId?{workflowRunId:e.workflowRunId}:{}}}function TE({summary:e}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,M.jsxs)(`span`,{className:`min-w-0 max-w-52 truncate rounded border border-[#11a4d4]/35 bg-[#11a4d4]/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-[#11a4d4]`,title:e.workflowId,children:[`workflow `,e.workflowId]}),(0,M.jsxs)(`span`,{className:DE(e.state),children:[`state `,e.state]}),e.workflowRunId?(0,M.jsxs)(`span`,{className:`min-w-0 max-w-40 truncate rounded border border-slate-700 bg-slate-900/40 px-1.5 py-0.5 text-[10px] text-slate-400`,title:e.workflowRunId,children:[`run `,OE(e.workflowRunId)]}):null]})}function EE(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.state?e.state.replace(/_/g,` `):e.workflowRunId?`workflow`:e.kind}function DE(e,t=!1){let n=e.toLowerCase(),r=`shrink-0 rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide`;return t?`${r} border-slate-700 text-slate-500`:n.includes(`failed`)||n.includes(`error`)?`${r} border-red-500/40 text-red-300 bg-red-500/10`:n.includes(`waiting`)?`${r} border-amber-500/40 text-amber-300 bg-amber-500/10`:n.includes(`complete`)||n.includes(`done`)?`${r} border-emerald-500/40 text-emerald-300 bg-emerald-500/10`:`${r} border-[#11a4d4]/40 text-[#11a4d4] bg-[#11a4d4]/10`}function OE(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function kE({title:e,roomLabel:t,headerPiboSessionId:n,piboSessionId:r,piboRoomId:i,webAnnotationsDisabled:a,webAnnotationsPanelRendered:o,workflowHeader:s,sessionViewId:c,sessionViews:l,currentSessionView:u,allowedSessionViewIds:d,showRawEvents:f,showThinking:p,expandThinking:m,onShowWebAnnotationsPanel:h,onHideWebAnnotationsPanel:g,onSelectSessionView:_,onToggleRawEvents:y,onToggleThinking:b,onToggleExpandThinking:x,onError:S}){let[C,w]=(0,v.useState)(null),T=(0,v.useRef)(void 0),E=C===n,ee=(0,v.useMemo)(()=>d?new Set(d):null,[d]);(0,v.useEffect)(()=>()=>{T.current&&window.clearTimeout(T.current)},[]);let D=()=>{n&&(FT(n).catch(()=>void 0),w(n),T.current&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>w(null),900))};return(0,M.jsxs)(`div`,{className:`h-14 px-4 bg-[#151f24] border-b border-slate-800 flex items-center justify-between max-[980px]:h-auto max-[980px]:flex-wrap max-[980px]:py-2 max-[980px]:gap-2`,children:[(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`h1`,{className:`text-base font-semibold truncate`,children:e}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 font-mono text-[11px] text-slate-500`,children:[(0,M.jsx)(`span`,{className:`truncate`,children:t}),n?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,M.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>void D(),title:E?`Copied Pibo session ID`:`Copy Pibo session ID`,"aria-label":E?`Copied Pibo session ID`:`Copy Pibo session ID`,className:`min-w-0 max-w-48 truncate rounded-sm px-1 font-mono underline-offset-2 transition-colors duration-150 focus:outline-none focus:ring-1 focus:ring-[#11a4d4] ${E?`bg-emerald-500/15 text-emerald-300 ring-1 ring-emerald-400/50`:`text-slate-400 hover:text-[#11a4d4] hover:underline`}`,children:n})]}):null,s?(0,M.jsx)(TE,{summary:s}):null]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(fE,{piboSessionId:r,piboRoomId:i,disabled:a,panelVisible:o,onShowPanel:h,onHidePanel:g,onError:S}),(0,M.jsx)(`div`,{className:`flex items-center rounded-sm border border-slate-700 bg-[#0e1116] p-0.5`,children:l.map(e=>{let t=!!(ee&&!ee.has(e.id));return(0,M.jsx)(`button`,{type:`button`,onClick:()=>{t||_(e.id)},disabled:t,title:t?`Project session routing uses the ${u.label} view for this session kind.`:e.description??e.label,"aria-label":t?`${e.label} view unavailable for this Project session kind`:`Switch to ${e.label} view`,className:`min-w-20 px-2.5 py-1 text-[11px] font-bold tracking-wide max-[980px]:min-w-0 max-[980px]:px-1.5 disabled:cursor-not-allowed disabled:text-slate-600 ${c===e.id?`bg-[#11a4d4]/10 text-[#11a4d4]`:`text-slate-400 hover:text-[#11a4d4] disabled:hover:text-slate-600`}`,children:e.label},e.id)})}),(0,M.jsx)(AE,{onClick:y,title:f?`Hide Raw Events`:`Show Raw Events`,ariaLabel:f?`Hide Raw Events`:`Show Raw Events`,active:f,children:(0,M.jsx)(Ae,{size:14})}),(0,M.jsx)(AE,{onClick:b,title:p?`Hide Thinking`:`Show Thinking`,ariaLabel:p?`Hide Thinking`:`Show Thinking`,active:p,children:p?(0,M.jsx)(ke,{size:14}):(0,M.jsx)(Je,{size:14})}),p?(0,M.jsx)(AE,{onClick:x,title:m?`Collapse Thinking`:`Expand Thinking`,ariaLabel:m?`Collapse Thinking`:`Expand Thinking`,active:m,children:m?(0,M.jsx)(Fe,{size:14}):(0,M.jsx)(Le,{size:14})}):null]})]})}function AE({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,M.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function jE(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&ME(e,n)){e.count+=1,e.createdAt=n.createdAt,e.payload={...FE(e.payload)?e.payload:{},text:`${NE(e.payload)}${NE(n.payload)}`};continue}t.push({...n,count:1})}return t}function ME(e,t){if(e.type!==t.type||e.type!==`assistant_delta`&&e.type!==`thinking_delta`&&e.type!==`TEXT_MESSAGE_CONTENT`&&e.type!==`REASONING_MESSAGE_CONTENT`)return!1;let n=FE(e.payload)?e.payload:{},r=FE(t.payload)?t.payload:{};return PE(n)===PE(r)}function NE(e){return FE(e)?typeof e.text==`string`?e.text:typeof e.delta==`string`?e.delta:``:``}function PE(e){return e.eventId??e.messageId}function FE(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function IE({traceView:e,eventLimit:t,isFetching:n,visible:r,onLoadOlder:i}){let a=(0,v.useMemo)(()=>r?jE(e?.rawEvents??[]):[],[e?.rawEvents,r]);return r?(0,M.jsxs)(`aside`,{className:`min-h-0 overflow-auto bg-[#0e1116] border-l border-slate-800 max-[980px]:hidden`,children:[(0,M.jsx)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center text-xs font-bold uppercase tracking-wider`,children:`Raw Events`}),(0,M.jsxs)(`div`,{className:`p-3 flex flex-col gap-2`,children:[e&&a.length>=t?(0,M.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`mb-1 rounded-sm border border-slate-700 px-2 py-1 text-xs text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:n?`Loading raw events…`:`Load older raw events (${a.length})`}):null,a.slice(-t).reverse().map(e=>(0,M.jsxs)(`div`,{className:`border-l-2 border-[#11a4d4] bg-[#151f24] p-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[#11a4d4] font-mono text-[11px] mb-1`,children:[(0,M.jsx)(`span`,{children:e.type}),e.count>1?(0,M.jsxs)(`span`,{className:`text-slate-500`,children:[`x`,e.count]}):null]}),(0,M.jsx)(Sc,{value:e.payload,showControls:!1})]},e.id))]})]}):null}function LE({traceView:e,eventLimit:t,isFetching:n,onLoadOlder:r}){if(!e?.hasOlderEvents)return null;let i=Math.min(e.eventLimit??t,e.eventCount??t),a=e.eventCount??`many`;return(0,M.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-2 text-center`,children:(0,M.jsx)(`button`,{type:`button`,onClick:r,disabled:n,className:`rounded-sm border border-slate-700 px-3 py-1 text-xs text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:n?`Loading history…`:`Load older trace history (${i} of ${a} events)`})})}function RE({selectedPiboSessionId:e,selectedRoomId:t,fallbackRoomId:n,sessionViewId:r,loadingTrace:i,traceError:a,showRawEvents:o,currentTraceView:s,traceEventLimit:c,rawEventLimit:l,tracePageFetching:u,onLoadOlderTracePage:d,onLoadMoreRawEvents:f,headerProps:p,projectSessionCreatePanel:m,workflowStartPanel:h,currentSessionView:g,sessionViewProps:_,webAnnotationsPanelRendered:v,webAnnotationsPanelProps:y,composerProps:b}){return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`main`,{"data-pibo-debug":`chat-shell`,"data-pibo-session-id":e??void 0,"data-pibo-room-id":t??n??void 0,"data-pibo-view-id":r,"data-pibo-state":i?`loading`:a?`error`:e?`ready`:`empty`,className:`min-h-0 flex flex-col`,children:[(0,M.jsx)(kE,{...p}),m?(0,M.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:m}):null,h?(0,M.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:h}):null,(0,M.jsx)(LE,{traceView:s,eventLimit:c,isFetching:u,onLoadOlder:()=>d(s?.nextBeforeSequence)}),a&&!s?(0,M.jsx)(`div`,{className:`min-h-0 flex-1 p-4 text-sm text-red-200`,children:a}):g.render(_),v?(0,M.jsx)(dE,{...y}):null,(0,M.jsx)(LT,{...b})]}),(0,M.jsx)(IE,{traceView:s,eventLimit:l,isFetching:u,visible:o,onLoadOlder:f})]})}function zE(e){let t=new Map;if(WE(e.nodes,t),!t.size)return e;let{nodes:n,changed:r}=GE(e.nodes,t);return r?{...e,nodes:n}:e}function BE(e){return e.some(UE)}function VE(e){let t=new Map;return qE(e,e=>{if(e.type!==`user.message`||!e.entryId)return;let n=JE(e),r=t.get(n);r?r.push(e.entryId):t.set(n,[e.entryId])}),t}function HE(e,t){if(!t.size)return;let n=new Map;qE(e,e=>{if(e.type!==`user.message`||e.entryId)return;let r=JE(e),i=t.get(r);if(!i?.length)return;let a=n.get(r)??0,o=i[a];o&&(e.entryId=o,n.set(r,a+1))})}function UE(e){let t=e.payload;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&`type`in t&&t.type===`message_queued`&&`source`in t&&t.source===`user`&&`text`in t&&typeof t.text==`string`)}function WE(e,t){for(let n of e){if(n.type===`user.message`&&!KE(n)){let e=JE(n);e&&t.set(e,(t.get(e)??0)+1)}WE(n.children,t)}}function GE(e,t){let n=!1,r=[];for(let i of e){if(KE(i)){let e=JE(i),r=e?t.get(e)??0:0;if(r>0){t.set(e,r-1),n=!0;continue}}let e=GE(i.children,t);n||=e.changed,r.push(e.changed?{...i,children:e.nodes}:i)}return{nodes:n?r:e,changed:n}}function KE(e){return e.type===`user.message`?e.source===`event-log`&&e.id.startsWith(`event:message_queued:`)?!0:[e.id,e.stableKey,e.eventId].filter(e=>typeof e==`string`).some(e=>e.startsWith(`optimistic:user-message:`)||e.includes(`:optimistic:user-message:`)):!1}function qE(e,t){for(let n of e)t(n),qE(n.children,t)}function JE(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function YE({selectedPiboSessionId:e,reconciledBaseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:i,now:a}){if(!e||t?.piboSessionId!==e)return{traceView:null};let o=n?.piboSessionId===e?n.events:[];if(!o.length)return{traceView:t};let s=a?.(),c=CS(t,o,r??`idle`),l=BE(o);return l&&HE(c.nodes,i),{traceView:l?zE(c):c,liveTraceComputeDurationMs:s!==void 0&&a?a()-s:void 0}}function XE(e,t){for(let n of e)t(n),XE(n.children,t)}function ZE(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function QE(e){if(!e)return;let t=0;return XE(e.nodes,e=>{e.type===`assistant.message`&&(t+=ZE(e).length)}),t}function $E({selectedPiboSessionId:e,baseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r}){let i=(0,v.useMemo)(()=>t?zE(t):null,[t]),a=(0,v.useMemo)(()=>i?VE(i.nodes):new Map,[i]),o=(0,v.useMemo)(()=>YE({selectedPiboSessionId:e,reconciledBaseTraceView:i,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:a,now:pv()?()=>performance.now():void 0}),[n,e,r,i,a]),s=o.traceView;return(0,v.useEffect)(()=>{!e||!s?.piboSessionId||!pv()||(Sv(s.piboSessionId,{overlayEventCount:n?.piboSessionId===s.piboSessionId?n.events.length:0,traceBaseOutputLength:QE(t),currentOutputLength:QE(s)}),o.liveTraceComputeDurationMs!==void 0&&yv(s.piboSessionId,o.liveTraceComputeDurationMs))},[t,o.liveTraceComputeDurationMs,s,n,e]),(0,v.useEffect)(()=>{let e=()=>{!s?.piboSessionId||!Ny()||Ly(s.piboSessionId,`tab:${document.visibilityState}`,s.nodes,{traceVersion:s.version,latestStreamId:s.latestStreamId,lastRawEventId:s.rawEvents.at(-1)?.id})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[s]),s}var eD=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},tD=new class extends eD{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},nD={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},rD=new class{#e=nD;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function iD(e){setTimeout(e,0)}var aD=typeof window>`u`||`Deno`in globalThis;function oD(){}function sD(e){return typeof e==`number`&&e>=0&&e!==1/0}function cD(e,t){return Math.max(e+(t||0)-Date.now(),0)}function lD(e,t){return typeof e==`function`?e(t):e}function uD(e,t){return typeof e==`function`?e(t):e}var dD=Object.prototype.hasOwnProperty;function fD(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=mD(e)&&mD(t);if(!r&&!(hD(e)&&hD(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:dD.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=fD(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function pD(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function mD(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function hD(e){if(!gD(e))return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(!gD(n)||!n.hasOwnProperty(`isPrototypeOf`)||Object.getPrototypeOf(e)!==Object.prototype)}function gD(e){return Object.prototype.toString.call(e)===`[object Object]`}function _D(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:fD(e,t)}function vD(e,t){return typeof e==`function`?e(...t):!!e}var yD=(()=>{let e=()=>aD;return{isServer(){return e()},setIsServer(t){e=t}}})();function bD(){let e,t,n=new Promise((n,r)=>{e=n,t=r});n.status=`pending`,n.catch(()=>{});function r(e){Object.assign(n,e),delete n.resolve,delete n.reject}return n.resolve=t=>{r({status:`fulfilled`,value:t}),e(t)},n.reject=e=>{r({status:`rejected`,reason:e}),t(e)},n}var xD=iD;function SD(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=xD,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var CD=SD(),wD=new class extends eD{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function TD(e){return(e??`online`)===`online`?wD.isOnline():!0}function ED(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:TD(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}var DD=class extends eD{constructor(e,t){super(),this.options=t,this.#e=e,this.#s=null,this.#o=bD(),this.bindMethods(),this.setOptions(t)}#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),kD(this.#t,this.options)?this.#h():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return AD(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return AD(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof uD(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!pD(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&jD(this.#t,n,this.options,t)&&this.#h(),this.updateResult(),r&&(this.#t!==n||uD(this.options.enabled,this.#t)!==uD(t.enabled,this.#t)||lD(this.options.staleTime,this.#t)!==lD(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||uD(this.options.enabled,this.#t)!==uD(t.enabled,this.#t)||i!==this.#p)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return ND(this,n)&&(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),n===`promise`&&(this.trackProp(`data`),!this.options.experimental_prefetchInRender&&this.#o.status===`pending`&&this.#o.reject(Error(`experimental_prefetchInRender feature flag is not enabled`))),Reflect.get(e,n))})}trackProp(e){this.#m.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t);return n.fetch().then(()=>this.createResult(n,t))}fetch(e){return this.#h({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#h(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(oD)),t}#g(){this.#b();let e=lD(this.options.staleTime,this.#t);if(yD.isServer()||this.#r.isStale||!sD(e))return;let t=cD(this.#r.dataUpdatedAt,e)+1;this.#d=rD.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return(typeof this.options.refetchInterval==`function`?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(e){this.#x(),this.#p=e,!(yD.isServer()||uD(this.options.enabled,this.#t)===!1||!sD(this.#p)||this.#p===0)&&(this.#f=rD.setInterval(()=>{(this.options.refetchIntervalInBackground||tD.isFocused())&&this.#h()},this.#p))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#d!==void 0&&(rD.clearTimeout(this.#d),this.#d=void 0)}#x(){this.#f!==void 0&&(rD.clearInterval(this.#f),this.#f=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&kD(e,t),o=i&&jD(e,n,t,r);(a||o)&&(l={...l,...ED(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#u?.state.data,this.#u):t.placeholderData,e!==void 0&&(m=`success`,d=_D(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h)if(i&&d===a?.data&&t.select===this.#c)d=this.#l;else try{this.#c=t.select,d=t.select(d),d=_D(i?.data,d,t),this.#l=d,this.#s=null}catch(e){this.#s=e}this.#s&&(f=this.#s,d=this.#l,p=Date.now(),m=`error`);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0,x={status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:MD(e,t),refetch:this.refetch,promise:this.#o,isEnabled:uD(t.enabled,e)!==!1};if(this.options.experimental_prefetchInRender){let t=x.data!==void 0,r=x.status===`error`&&!t,i=e=>{r?e.reject(x.error):t&&e.resolve(x.data)},a=()=>{i(this.#o=x.promise=bD())},o=this.#o;switch(o.status){case`pending`:e.queryHash===n.queryHash&&i(o);break;case`fulfilled`:(r||x.data!==o.value)&&a();break;case`rejected`:(!r||x.error!==o.reason)&&a();break}}return x}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#u=this.#t),!pD(t,e)&&(this.#r=t,this.#C({listeners:(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#m.size)return!0;let r=new Set(n??this.#m);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})()}))}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}#C(e){CD.batch(()=>{e.listeners&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}};function OD(e,t){return uD(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status===`error`&&uD(t.retryOnMount,e)===!1)}function kD(e,t){return OD(e,t)||e.state.data!==void 0&&AD(e,t,t.refetchOnMount)}function AD(e,t,n){if(uD(t.enabled,e)!==!1&&lD(t.staleTime,e)!==`static`){let r=typeof n==`function`?n(e):n;return r===`always`||r!==!1&&MD(e,t)}return!1}function jD(e,t,n,r){return(e!==t||uD(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&MD(e,n)}function MD(e,t){return uD(t.enabled,e)!==!1&&e.isStaleByTime(lD(t.staleTime,e))}function ND(e,t){return!pD(e.getCurrentResult(),t)}var PD=v.createContext(void 0),FD=e=>{let t=v.useContext(PD);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},ID=v.createContext(!1),LD=()=>v.useContext(ID);ID.Provider;function RD(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var zD=v.createContext(RD()),BD=()=>v.useContext(zD),VD=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?vD(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(t.isReset()||(e.retryOnMount=!1))},HD=e=>{v.useEffect(()=>{e.clearReset()},[e])},UD=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||vD(n,[e.error,r])),WD=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},GD=(e,t)=>e.isLoading&&e.isFetching&&!t,KD=(e,t)=>e?.suspense&&t.isPending,qD=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function JD(e,t,n){let r=LD(),i=BD(),a=FD(n),o=a.defaultQueryOptions(e);a.getDefaultOptions().queries?._experimental_beforeQuery?.(o);let s=a.getQueryCache().get(o.queryHash);o._optimisticResults=r?`isRestoring`:`optimistic`,WD(o),VD(o,i,s),HD(i);let c=!a.getQueryCache().get(o.queryHash),[l]=v.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&e.subscribed!==!1;if(v.useSyncExternalStore(v.useCallback(e=>{let t=d?l.subscribe(CD.batchCalls(e)):oD;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),v.useEffect(()=>{l.setOptions(o)},[o,l]),KD(o,u))throw qD(o,l,i);if(UD({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return a.getDefaultOptions().queries?._experimental_afterQuery?.(o,u),o.experimental_prefetchInRender&&!yD.isServer()&&GD(u,r)&&(c?qD(o,l,i):s?.promise)?.catch(oD).finally(()=>{l.updateResult()}),o.notifyOnChangeProps?u:l.trackResult(u)}function YD(e,t){return JD(e,DD,t)}var XD=1e4,ZD=30*6e4,QD=2e3;function $D(e){return[`chat`,`trace-summary`,e]}function eO(e,t={}){let n=t.pageSize??t.eventLimit??2e3;return[`chat`,`trace-page`,e,t.includeRawEvents?`raw`:`compact`,t.rawEventsLimit??80,n,t.beforeSequence===void 0?`tail`:String(t.beforeSequence)]}function tO(e,t){if(!e||e.piboSessionId!==t.piboSessionId)return e;let n=t.latestStreamId,r=rO(t),i=nO(t.nodes),a=e.events.filter(e=>{if(n!==void 0&&e.streamId!==void 0&&e.streamId<=n||UE(e)&&i.has(e.payload.text))return!1;let t=aO(e);return!t||!r.has(t)});return a.length?{...e,events:a}:null}function nO(e){let t=new Set;for(let n of e){if(n.type===`user.message`&&n.source===`transcript`){let e=oO(n);e&&t.add(e)}for(let e of nO(n.children))t.add(e)}return t}function rO(e){let t=new Set;for(let n of e.rawEvents){let e=aO(n);e&&t.add(e)}return iO(e.nodes,t),t}function iO(e,t){for(let n of e){if(n.type===`user.message`){let e=n.id.startsWith(`event:message_queued:`)?n.id.slice(21):void 0;e&&t.add(`${n.piboSessionId}:message_queued:${e}`),n.source===`transcript`&&n.entryId&&t.add(`${n.piboSessionId}:message_queued:${n.entryId}`)}n.eventId&&n.type===`assistant.message`&&(t.add(`${n.piboSessionId}:assistant_delta:${n.eventId}`),t.add(`${n.piboSessionId}:assistant_message:${n.eventId}`)),n.eventId&&n.type===`model.reasoning`&&(t.add(`${n.piboSessionId}:thinking_delta:${n.eventId}`),t.add(`${n.piboSessionId}:thinking_finished:${n.eventId}`)),iO(n.children,t)}}function aO(e){let t=e.payload;if(!t||typeof t!=`object`||Array.isArray(t))return;let n=`eventId`in t&&typeof t.eventId==`string`?t.eventId:e.eventId,r=`piboSessionId`in t&&typeof t.piboSessionId==`string`?t.piboSessionId:e.piboSessionId;if(!(!n||!r))return`${r}:${e.type}:${n}`}function oO(e){return typeof e.output==`string`?e.output:e.output&&typeof e.output==`object`&&`text`in e.output&&typeof e.output.text==`string`?e.output.text:``}function sO(e,t){if(e.piboSessionId!==t.piboSessionId)return e;let n=new Set,r=[...t.nodes,...e.nodes].filter(e=>n.has(e.id)?!1:(n.add(e.id),!0)),i=new Set,a=[...t.rawEvents,...e.rawEvents].filter(e=>{let t=e.id||`${e.eventSequence??``}:${e.type}:${e.createdAt}`;return i.has(t)?!1:(i.add(t),!0)});return{...e,version:e.version,nodes:r,rawEvents:a,firstEventSequence:t.firstEventSequence??e.firstEventSequence,nextBeforeSequence:t.nextBeforeSequence,hasOlderEvents:t.hasOlderEvents,eventLimit:(e.eventLimit??0)+(t.eventLimit??t.pageSize??0)}}function cO({selectedPiboSessionId:e,showRawEvents:t,setLiveTraceOverlay:n}){let r=FD(),[i,a]=(0,v.useState)(QD),[o,s]=(0,v.useState)(80),[c,l]=(0,v.useState)(null),u=(0,v.useMemo)(()=>e?$D(e):null,[e]),d=(0,v.useMemo)(()=>e?eO(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:QD}):null,[o,e,t]),f=YD({queryKey:u??[`chat`,`trace-summary`,`idle`],queryFn:async()=>{if(!e||!u)throw Error(`Session is required`);let t=r.getQueryData(u),n=await fb(e,t?.version);if(n.notModified&&t)return t;if(!n.summary)throw Error(`Trace summary response missing payload.`);return n.summary},enabled:!!e,staleTime:XD,gcTime:ZD,refetchOnWindowFocus:!1,retry:1}),p=YD({queryKey:d??[`chat`,`trace-page`,`idle`,`compact`,o,2e3,`tail`],queryFn:async()=>{if(!e||!d)throw Error(`Session is required`);let n=r.getQueryData(d),i=await pb(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:QD,knownVersion:n?.version});if(i.notModified&&n)return n;if(!i.trace)throw Error(`Trace page response missing payload.`);return i.trace},enabled:!!e,staleTime:XD,gcTime:ZD,refetchOnWindowFocus:!1,retry:1});(0,v.useEffect)(()=>{a(QD),s(80),l(null),n(null)},[e,n]),(0,v.useEffect)(()=>{let t=p.data;!t||t.piboSessionId!==e||(pv()&&Sv(t.piboSessionId,{overlayEventCount:0,traceBaseOutputLength:QE(t),traceBaseUpdated:!0}),(0,v.startTransition)(()=>{l(t),n(e=>tO(e,t))}))},[e,n,p.data]);let m=(0,v.useCallback)(async n=>{if(!e||!n)return;let i=eO(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:QD,beforeSequence:n}),s=await r.fetchQuery({queryKey:i,queryFn:async()=>{let a=r.getQueryData(i),s=await pb(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:QD,beforeSequence:n,knownVersion:a?.version});if(s.notModified&&a)return a;if(!s.trace)throw Error(`Trace page response missing payload.`);return s.trace},staleTime:XD,gcTime:ZD});(0,v.startTransition)(()=>{l(e=>e?sO(e,s):s),a(e=>e+(s.pageSize??2e3))})},[r,o,e,t]),h=(0,v.useCallback)(()=>{s(e=>e+80)},[]);return{baseTraceView:c,traceEventLimit:i,rawEventLimit:o,traceSummaryQuery:f,tracePageQuery:p,tracePageReady:!!d,loadOlderTracePage:m,loadMoreRawEvents:h}}function lO(e){let t=e.currentEvents,n,r,i=()=>(r??=new Set(t.map(hO)),r),a=e=>{n??=t.slice(),n.push(e),t=n};for(let o of e.streamEvents){let s=fO(o,e.piboSessionId,e.nextSequence,e.now??(()=>new Date().toISOString()));if(!s)continue;if(uO(s)){t=dO(t,s),n=t,r=void 0;continue}let c=hO(s),l=i();l.has(c)||(l.add(c),a(s))}return t}function uO(e){return e.type===`assistant_message`||e.type===`thinking_finished`||e.type===`tool_execution_finished`}function dO(e,t){return t.type===`assistant_message`?[...mO(e,t,`assistant_delta`),t]:t.type===`thinking_finished`?[...mO(e,t,`thinking_delta`),t]:t.type===`tool_execution_finished`?[...mO(e,t,`tool_execution_updated`),t]:e}function fO(e,t,n,r){if(e.type===`RAW_EVENT`&&vO(e.event)&&typeof e.event.type==`string`){let i=e.event;return pO(e,t,e.event.type,i,n,r)}if(e.type===`TEXT_MESSAGE_CONTENT`&&typeof e.delta==`string`)return pO(e,t,`assistant_delta`,{type:`assistant_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,..._O(typeof e.messageId==`string`?e.messageId:void 0,`assistant`),text:e.delta},n,r);if(e.type===`REASONING_MESSAGE_CONTENT`&&typeof e.delta==`string`)return pO(e,t,`thinking_delta`,{type:`thinking_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,..._O(typeof e.messageId==`string`?e.messageId:void 0,`thinking`),text:e.delta},n,r);if(e.type===`TOOL_CALL_START`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return pO(e,t,`tool_execution_started`,{type:`tool_execution_started`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args},n,r);if(e.type===`TOOL_CALL_ARGS`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`){let i=typeof e.runId==`string`?e.runId:void 0,a=e.sourceEventType===`tool_execution_updated`?`tool_execution_updated`:`tool_call`;return pO(e,t,a,a===`tool_execution_updated`?{type:`tool_execution_updated`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,partialResult:e.partialResult}:{type:`tool_call`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,argsComplete:!!e.argsComplete},n,r)}if(e.type===`TOOL_CALL_RESULT`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return pO(e,t,`tool_execution_finished`,{type:`tool_execution_finished`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,toolCallId:e.toolCallId,toolName:e.toolName,result:e.result,isError:!!e.isError},n,r);if(e.type===`RUN_ERROR`&&typeof e.message==`string`)return pO(e,t,`session_error`,{type:`session_error`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,error:e.message,errorDetails:e.errorDetails},n,r)}function pO(e,t,n,r,i,a){let o=typeof e.streamFrameId==`string`?e.streamFrameId:void 0,s=typeof e.streamFrameIndex==`number`?e.streamFrameIndex:void 0,c=typeof e.liveReplayId==`number`&&Number.isFinite(e.liveReplayId)?e.liveReplayId:void 0,l=i();return{id:typeof e.streamId==`number`?`stream:${e.streamId}:${s??`raw`}:${n}`:c===void 0?o?`stream:${o}:${n}`:`live:${l}:${n}`:`live-replay:${c}:${n}`,piboSessionId:t,eventSequence:l,streamId:typeof e.streamId==`number`?e.streamId:void 0,streamFrameIndex:s,eventId:typeof r.eventId==`string`?r.eventId:void 0,type:n,createdAt:a(),payload:r}}function mO(e,t,n){let r=gO(t);return e.filter(e=>e.type!==n||gO(e)!==r)}function hO(e){return e.streamId===void 0?`${e.id}:${e.type}`:e.streamFrameIndex===void 0?`stream:${e.streamId}:${e.id}:${e.type}`:`stream:${e.streamId}:${e.streamFrameIndex}:${e.type}`}function gO(e){let t=vO(e.payload)?e.payload:{},n=typeof t.piboSessionId==`string`?t.piboSessionId:e.piboSessionId??``,r=typeof t.eventId==`string`?t.eventId:e.eventId??``;if(typeof t.toolCallId==`string`)return`${n}:${r}:tool:${t.toolCallId}`;let i=typeof t.assistantIndex==`number`?t.assistantIndex:void 0,a=typeof t.thinkingIndex==`number`?t.thinkingIndex:void 0,o=typeof t.contentIndex==`number`?t.contentIndex:0;return`${n}:${r}:${i??a??o}`}function _O(e,t){let n=e?.match(RegExp(`:${t}:(\\d+)$`));if(!n)return{};let r=Number(n[1]);return Number.isInteger(r)?t===`assistant`?{assistantIndex:r}:{thinkingIndex:r}:{}}function vO(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function yO(e){try{let t=JSON.parse(e.data);if(typeof t.type!=`string`)return;let n=e.lastEventId?cx(e.lastEventId):void 0;return{...t,...e.lastEventId?{streamFrameId:e.lastEventId}:{},...n?{streamId:n.streamId,streamFrameIndex:n.frameIndex}:{}}}catch{return}}function bO(e,t,n){let r=e.get(t);r?.streamId!==void 0&&r.streamId>=n||e.set(t,{streamId:n,frameIndex:2**53-1,cursor:SO(n),exact:!1,...r?.liveReplayId===void 0?{}:{liveReplayId:r.liveReplayId}})}function xO(e,t,n){let r=e.get(t),i=typeof n.liveReplayId==`number`&&Number.isFinite(n.liveReplayId)?Math.max(r?.liveReplayId??0,n.liveReplayId):r?.liveReplayId;if(n.streamId===void 0||n.streamFrameIndex===void 0){i!==void 0&&i!==r?.liveReplayId&&e.set(t,{...r??{exact:!1},liveReplayId:i});return}if(r&&(r.streamId!==void 0&&r.streamId>n.streamId||r.streamId===n.streamId&&r.exact&&r.frameIndex!==void 0&&r.frameIndex>=n.streamFrameIndex)){i!==void 0&&i!==r.liveReplayId&&e.set(t,{...r,liveReplayId:i});return}e.set(t,{streamId:n.streamId,frameIndex:n.streamFrameIndex,cursor:n.streamFrameId??`${n.streamId}:${n.streamFrameIndex}`,exact:!0,...i===void 0?{}:{liveReplayId:i}})}function SO(e){return`${e}:999999`}function CO(e){if(e.type===`RUN_FINISHED`||e.type===`TEXT_MESSAGE_END`)return 300;if(e.type===`RUN_ERROR`)return 0}function wO(e){return e.type===`RUN_STARTED`||e.type===`RUN_FINISHED`||e.type===`RUN_ERROR`||e.type===`TEXT_MESSAGE_END`}function TO(e){return e.type===`TEXT_MESSAGE_CONTENT`||e.type===`REASONING_MESSAGE_CONTENT`||e.type===`TOOL_CALL_START`||e.type===`TOOL_CALL_ARGS`||e.type===`TOOL_CALL_RESULT`||e.type===`RUN_ERROR`||e.type===`RAW_EVENT`}function EO(e,t,n){if(n.type===`RUN_STARTED`||n.type===`RUN_FINISHED`||n.type===`RUN_ERROR`){e.delete(t);return}let r=kO(n);r&&e.get(t)?.delete(r)}function DO(e,t,n){let r=OO(n);if(!r)return!1;let i=e.get(t);return i||(i=new Set,e.set(t,i)),i.has(r)?!1:(i.add(r),!0)}function OO(e){if(e.type===`TEXT_MESSAGE_CONTENT`||e.type===`REASONING_MESSAGE_CONTENT`)return`${e.type}:${e.messageId}`}function kO(e){if(e.type===`TEXT_MESSAGE_START`)return`TEXT_MESSAGE_CONTENT:${e.messageId}`;if(e.type===`REASONING_MESSAGE_START`)return`REASONING_MESSAGE_CONTENT:${e.messageId}`}var AO=500,jO=1e4,MO=45e3,NO=100;function PO({selectedPiboSessionId:e,tracePageData:t,currentTraceView:n,liveEventSeqRef:r,selectedSessionStatus:i,tracePageReady:a,setLiveTraceOverlay:o,onRefreshTrace:s,onRefreshBootstrap:c,onError:l}){let u=(0,v.useRef)(new Map),d=(0,v.useRef)(void 0),f=(0,v.useRef)(void 0),p=(0,v.useRef)(new Map),m=(0,v.useRef)(new Map),h=(0,v.useRef)(null),g=(0,v.useRef)(void 0),_=(0,v.useRef)(0),[y,b]=(0,v.useState)(0);(0,v.useEffect)(()=>{let n=t;if(!n||n.piboSessionId!==e)return;let i=n.rawEvents.map(e=>e.eventSequence??0).reduce((e,t)=>Math.max(e,t),0);r.current=Math.max(r.current,i+1),n.latestStreamId!==void 0&&bO(m.current,n.piboSessionId,n.latestStreamId)},[r,e,t]);let x=(0,v.useCallback)(e=>{let t=u.current.get(e);t?.length&&(o(n=>{let i=lO({currentEvents:n?.piboSessionId===e?n.events:[],streamEvents:t,piboSessionId:e,nextSequence:()=>r.current++});return vv(e,t.length,i.length),{piboSessionId:e,events:i}}),u.current.delete(e))},[]),S=(0,v.useCallback)(()=>{if(!(d.current!==void 0||f.current!==void 0||!e)){if(document.hidden){f.current=setTimeout(()=>{f.current=void 0,x(e)},NO);return}d.current=requestAnimationFrame(()=>{d.current=void 0,x(e)})}},[x,e]),C=(0,v.useCallback)((t,n,r=!1)=>{EO(p.current,t,n);let i=r||DO(p.current,t,n),a=u.current.get(t)??[];a.push(n),u.current.set(t,a),_v(t,n,a.length,i),i||t!==e?x(t):S()},[x,S,e]);(0,v.useEffect)(()=>()=>{d.current!==void 0&&cancelAnimationFrame(d.current),f.current!==void 0&&clearTimeout(f.current),g.current!==void 0&&clearTimeout(g.current)},[]);let w=(0,v.useCallback)((e,t)=>{xO(m.current,e,t)},[]),T=(0,v.useCallback)((e=0)=>{if(g.current!==void 0){if(e>0)return;clearTimeout(g.current)}g.current=setTimeout(()=>{g.current=void 0,b(e=>e+1)},e)},[]),E=(0,v.useCallback)(()=>{if(!e)return;x(e),s().catch(e=>l(FO(e))),c().catch(e=>l(FO(e)));let t=h.current;(!t||t.piboSessionId!==e||t.events.readyState===2||Date.now()-t.lastActivityAt>MO)&&T()},[x,l,c,s,T,e]);(0,v.useEffect)(()=>{if(!e||!a||!n||n.piboSessionId!==e)return;let t=new URLSearchParams({piboSessionId:e});t.set(`mode`,`live`);let r=m.current.get(e),i=r?.cursor??(n.latestStreamId===void 0?void 0:SO(n.latestStreamId));i!==void 0&&t.set(`since`,i),r?.liveReplayId!==void 0&&t.set(`liveSince`,String(r.liveReplayId));let o=new EventSource(`/api/chat/events?${t.toString()}`),u=Date.now();h.current={piboSessionId:e,events:o,openedAt:u,lastActivityAt:u};let d=!1,f,p,v=!1,y=!1,b=(t,n=!1)=>{if(f){if(!n)return;clearTimeout(f)}xv(e,t),f=setTimeout(()=>{f=void 0,s().catch(e=>l(FO(e)))},t)},S=()=>{if(v){y=!0;return}v=!0,c().catch(e=>l(FO(e))).finally(()=>{v=!1,y&&(y=!1,E(250,!0))})},E=(e,t=!1)=>{if(p){if(!t)return;clearTimeout(p)}p=setTimeout(()=>{p=void 0,S()},e)},ee=()=>{E(900,!0)};return o.onopen=()=>{_.current=0,g.current!==void 0&&(clearTimeout(g.current),g.current=void 0),mv(e,o.readyState);let t=h.current;t?.events===o&&(t.lastActivityAt=Date.now())},o.onerror=()=>{if(d)return;hv(e,o.readyState);let t=h.current;t?.events===o&&(t.lastErrorAt=Date.now());let n=_.current++;T(Math.min(jO,AO*2**n))},o.addEventListener(`pibo`,t=>{if(d)return;let n=yO(t);if(!n)return;let r=n.piboSessionId||e,i=h.current;if(i?.events===o&&(i.lastActivityAt=Date.now()),w(r,n),gv(r,n,t.lastEventId,o.readyState),r===e&&n.type===`ready`&&n.liveReplay?.missed&&b(0,!0),Cv(n))return;let a=n.type!==`TEXT_MESSAGE_CONTENT`&&n.type!==`REASONING_MESSAGE_CONTENT`;r===e&&TO(n)&&C(r,n,a);let s=CO(n);r===e&&s!==void 0?b(s,!0):r===e&&n.type!==`ready`&&n.type!==`RAW_EVENT`&&b(1500,!0),wO(n)&&(n.type===`RUN_FINISHED`||n.type===`RUN_ERROR`||n.type===`TEXT_MESSAGE_END`?ee():E(r===e?0:150))}),()=>{d=!0,f&&clearTimeout(f),p&&clearTimeout(p),x(e),h.current?.events===o&&(h.current=null),o.close()}},[n?.piboSessionId,C,x,l,c,s,w,T,y,e,a]),(0,v.useEffect)(()=>{n?.piboSessionId&&x(n.piboSessionId)},[n?.piboSessionId,x]),(0,v.useEffect)(()=>{let e=()=>E(),t=()=>{document.hidden||E()};return window.addEventListener(`focus`,e),window.addEventListener(`online`,e),window.addEventListener(`pageshow`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`online`,e),window.removeEventListener(`pageshow`,e),document.removeEventListener(`visibilitychange`,t)}},[E]),(0,v.useEffect)(()=>{if(!e||i!==`running`)return;let t=window.setInterval(()=>{x(e),s().catch(e=>l(FO(e)))},1e3);return()=>window.clearInterval(t)},[x,l,s,e,i])}function FO(e){return e instanceof Error?e.message:String(e)}var IO=10;function LO(e,t,n,r){if(!t||!n.length)return e;let i=e[t]??[],a=new Set(i.map(e=>e.path)),o=n.filter(e=>e.path&&!a.has(e.path)).map(e=>({...e,id:r()}));return o.length?{...e,[t]:[...i,...o].slice(0,IO)}:e}function RO(e,t,n){if(!t)return e;let r=e[t]??[],i=r.filter(e=>e.id!==n);return i.length===r.length?e:{...e,[t]:i}}function zO(e,t){return!t||!e[t]?.length?e:{...e,[t]:[]}}function BO(e,t){let[n,r]=(0,v.useState)({});return{selectedUploadAttachments:(0,v.useMemo)(()=>e?n[e]??[]:[],[e,n]),attachUploadedFiles:(0,v.useCallback)(n=>{r(r=>LO(r,e,n,t))},[t,e]),detachUploadAttachment:(0,v.useCallback)(t=>{r(n=>RO(n,e,t))},[e]),clearSelectedUploadAttachments:(0,v.useCallback)(()=>{r(t=>zO(t,e))},[e])}}function VO({selectedPiboSessionId:e,onError:t,formatError:n}){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(()=>e?rE(e):null),[l,u]=(0,v.useState)(()=>lE()),[d,f]=(0,v.useState)(!1),p=!!(e&&s?.piboSessionId===e&&s.installed),m=!!e&&(a||p),h=YD({queryKey:[`web-annotations`,`app`,e],queryFn:async()=>{if(!e)throw Error(`Session is required`);return gb(e,{limit:100,scope:`app`})},enabled:!!e&&(m||r.length>0),staleTime:1e3,refetchOnWindowFocus:m,refetchInterval:m?5e3:!1,retry:1}),g=h.refetch,_=(0,v.useMemo)(()=>(h.data?.annotations??[]).filter(e=>e.status!==`resolved`&&e.status!==`dismissed`),[h.data?.annotations]),y=(0,v.useMemo)(()=>r.map(e=>_.find(t=>t.id===e)).filter(e=>!!e),[r,_]);(0,v.useEffect)(()=>{i(e?sE(e):[]),c(e?rE(e):null)},[e]),(0,v.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.piboSessionId!==e||(c(e=>t.installed?t:e?.installed&&e.bindingId&&t.bindingId&&e.bindingId!==t.bindingId?e:t),t.installed?g():o(!1))},n=e=>t(oE(e.detail)),r=n=>{n.key===iE(e)&&t(aE(n.newValue))},i=()=>t(rE(e));return window.addEventListener(`pibo:web-annotation-overlay-state`,n),window.addEventListener(`storage`,r),window.addEventListener(`focus`,i),document.addEventListener(`visibilitychange`,i),i(),()=>{window.removeEventListener(`pibo:web-annotation-overlay-state`,n),window.removeEventListener(`storage`,r),window.removeEventListener(`focus`,i),document.removeEventListener(`visibilitychange`,i)}},[g,e]),(0,v.useEffect)(()=>{if(!h.data)return;if(!_.length){i(t=>(t.length&&e&&cE(e,[]),t.length?[]:t));return}let t=new Set(_.map(e=>e.id));i(n=>{let r=n.filter(e=>t.has(e));return r.length!==n.length&&e&&cE(e,r),r.length===n.length?n:r})},[e,_,h.data]),(0,v.useEffect)(()=>{let e=()=>{o(!0),g()};return window.addEventListener(`pibo:web-annotation-saved`,e),()=>window.removeEventListener(`pibo:web-annotation-saved`,e)},[g]);let b=(0,v.useCallback)(t=>{i(n=>{let r=t(n);return e&&cE(e,r),r})},[e]),x=(0,v.useCallback)(e=>{b(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].slice(0,5))},[b]),S=(0,v.useCallback)(()=>b(()=>[]),[b]);return{selectedWebAnnotationIds:r,selectedWebAnnotations:y,visibleWebAnnotations:_,webAnnotationsPanelCollapsed:l,webAnnotationsPanelRendered:m,webAnnotationsPanelVisible:a,webAnnotationsQuery:h,clearingWebAnnotations:d,setWebAnnotationsPanelVisible:o,toggleWebAnnotationAttachment:x,detachWebAnnotationAttachment:(0,v.useCallback)(e=>{b(t=>t.filter(t=>t!==e))},[b]),clearSelectedWebAnnotationAttachments:S,toggleWebAnnotationsPanelCollapsed:(0,v.useCallback)(()=>{u(e=>{let t=!e;return uE(t),t})},[]),clearVisibleWebAnnotations:(0,v.useCallback)(async()=>{if(!(!_.length||d)&&window.confirm(`Dismiss ${_.length} visible web annotations? This keeps sent messages but clears the annotation list.`)){f(!0);try{await Promise.all(_.map(e=>_b(e.id,{piboSessionId:e.piboSessionId,status:`dismissed`,summary:`Cleared from Chat Web UI`}))),S(),await g()}catch(e){t(n(e,`Could not clear web annotations`))}finally{f(!1)}}},[d,S,n,t,g,_])}}function HO(e,t){return t?{sessionBreadcrumbs:qO(e,t),originSession:GO(e,t),derivedSessions:KO(e,t)}:{sessionBreadcrumbs:[],originSession:void 0,derivedSessions:[]}}function UO(e){let t=e.selectedPiboSessionId?S(e.bootstrap.sessions,e.selectedPiboSessionId):void 0,n=ZO(e.currentTraceView);return XO(e.selectedSessionActiveModel,e.bootstrap.runtimeStatus?.thinkingLevel??n.level??JO(e.bootstrap,e.selectedSessionProfile,!!t?.parentId),e.bootstrap.runtimeStatus?.fastMode??n.fast??YO(e.bootstrap,e.selectedSessionProfile,!!t?.parentId)??!1)}function WO(e){return{traceView:e.currentTraceView,selectedTrace:null,isLoading:e.isLoading,showThinking:e.showThinking,expandThinking:e.expandThinking,sessionAgentProfile:e.selectedSessionProfile,sessionActiveModel:e.sessionActiveModelBadge,selectedSessionStatus:e.selectedSessionStatus,selectedSessionSignal:e.selectedSessionSignal,workflowProjectSession:e.workflowProjectSession,workflowLifecycleEvents:e.workflowLifecycleEvents,sessionNodes:e.sessionNodes,sessionBreadcrumbs:e.sessionLinks.sessionBreadcrumbs,originSession:e.sessionLinks.originSession,derivedSessions:e.sessionLinks.derivedSessions,agentProfiles:e.agentProfiles,sessionProfileChangeDisabled:e.sessionProfileChangeDisabled,onSessionAgentProfileChange:e.onSessionAgentProfileChange,onFork:e.onFork,onOpenSession:e.onOpenSession,onThinkingLevelChange:e.onThinkingLevelChange,onModelChanged:async()=>{await e.onRefreshBootstrap(),await e.onRefreshTrace()},onRefreshBootstrap:e.onRefreshBootstrap,onError:e.onError}}function GO(e,t){let n=S(e,t);if(!n?.originId)return;let r=S(e,n.originId);return{piboSessionId:n.originId,label:r?ek(r,0):n.originId}}function KO(e,t){return S(e,t)?.derivedSessions.map(e=>({piboSessionId:e.piboSessionId,label:tk(e),profile:e.profile,status:e.status}))??[]}function qO(e,t){return C(e,t).map((e,t)=>({piboSessionId:e.piboSessionId,label:ek(e,t)}))}function JO(e,t,n=!1){let r=e.agents.find(e=>e.name===t),i=e.customAgents.find(e=>e.profileName===t),a=r??i;return n?a?.subagentThinkingLevel??a?.thinkingLevel??e.modelDefaults?.subagentThinking??e.modelDefaults?.thinking:a?.mainThinkingLevel??a?.thinkingLevel??e.modelDefaults?.mainThinking??e.modelDefaults?.thinking}function YO(e,t,n=!1){let r=e.agents.find(e=>e.name===t),i=e.customAgents.find(e=>e.profileName===t),a=r??i;return n?a?.subagentFast??a?.fast??e.modelDefaults?.subagentFast??e.modelDefaults?.fast:a?.mainFast??a?.fast??e.modelDefaults?.mainFast??e.modelDefaults?.fast}function XO(e,t,n){if(e)return[e,t,n?`fast`:void 0].filter(Boolean).join(` `)}function ZO(e){let t={};if(!e)return t;for(let n of QO(e.nodes)){if(n.type!==`execution.command`||n.title!==`thinking`&&n.title!==`fast_mode`)continue;let e=n.output&&typeof n.output==`object`?n.output:void 0;t={level:(typeof e?.level==`string`&&$O(e.level)?e.level:void 0)??t.level,fast:n.title===`fast_mode`?e?.mode===`fast`:t.fast}}return t}function QO(e){return e.flatMap(e=>[e,...QO(e.children)])}function $O(e){return PC.includes(e)}function ek(e,t){return t?e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.profile||e.subagentName||e.title:e.profile||e.title}function tk(e){return e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.title||e.profile||e.subagentName||`Untitled Session`}function nk({piboSessionId:e,text:t,selectedWebAnnotations:n,selectedUploadAttachments:r,eventSequence:i,now:a,clientTxnId:o}){let s=n.map(e=>e.id),c=r.map(e=>e.path);return{text:t,webAnnotationIds:s,fileAttachmentPaths:c,clientTxnId:o,optimisticEvent:{id:o,piboSessionId:e,eventSequence:i,eventId:o,type:`message_queued`,createdAt:a,payload:{type:`message_queued`,piboSessionId:e,eventId:o,clientTxnId:o,queuedMessages:1,text:t,...c.length?{fileAttachmentPaths:c}:{},source:`user`}}}}function rk(e,t,n){return{piboSessionId:t,events:[...e?.piboSessionId===t?e.events:[],n]}}function ik(e){return e instanceof Error?e.message:String(e)}function ak({bootstrap:e,selectedPiboSessionId:t,selectedRoomId:n,selectedRoomArchived:r,selectedSessionProfile:i,selectedSessionActiveModel:a,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,projectSessionCreatePanel:u,workflowStartPanel:d,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,creatingSession:g,showRawEvents:_,showThinking:y,expandThinking:b,commands:x,skills:S,composerText:C,composerFocusSignal:T,onComposerTextChange:E,onToggleRawEvents:ee,onToggleThinking:D,onToggleExpandThinking:O,onSessionAgentProfileChange:te,onFork:ne,onOpenSession:re,onSelectSessionView:ie,onCommand:ae,onThinkingLevelChange:oe,onRefreshTrace:k,onRefreshBootstrap:A,onSend:se,onError:ce}){let le=(0,v.useRef)(0),[ue,de]=(0,v.useState)(null),{baseTraceView:fe,traceEventLimit:pe,rawEventLimit:me,traceSummaryQuery:he,tracePageQuery:ge,tracePageReady:_e,loadOlderTracePage:ve,loadMoreRawEvents:ye}=cO({selectedPiboSessionId:t,showRawEvents:_,setLiveTraceOverlay:de}),{selectedWebAnnotationIds:be,selectedWebAnnotations:xe,visibleWebAnnotations:j,webAnnotationsPanelCollapsed:Se,webAnnotationsPanelRendered:Ce,webAnnotationsPanelVisible:we,webAnnotationsQuery:Te,clearingWebAnnotations:Ee,setWebAnnotationsPanelVisible:De,toggleWebAnnotationAttachment:Oe,detachWebAnnotationAttachment:ke,clearSelectedWebAnnotationAttachments:Ae,toggleWebAnnotationsPanelCollapsed:je,clearVisibleWebAnnotations:Me}=VO({selectedPiboSessionId:t,onError:ce,formatError:_E}),{selectedUploadAttachments:Ne,attachUploadedFiles:Pe,detachUploadAttachment:Fe,clearSelectedUploadAttachments:Ie}=BO(t,(0,v.useCallback)(()=>`upload-${w()}`,[])),Le=$E({selectedPiboSessionId:t,baseTraceView:fe,liveTraceOverlay:ue,selectedSessionStatus:o});PO({selectedPiboSessionId:t,tracePageData:ge.data,currentTraceView:Le,liveEventSeqRef:le,selectedSessionStatus:o,tracePageReady:_e,setLiveTraceOverlay:de,onRefreshTrace:k,onRefreshBootstrap:A,onError:ce});let Re=UO({bootstrap:e,selectedPiboSessionId:t,selectedSessionProfile:i,selectedSessionActiveModel:a,currentTraceView:Le}),ze=(0,v.useMemo)(()=>HO(e.sessions,t),[e.sessions,t]),Be=!!t&&ge.isFetching&&!Le,Ve=ge.error?ik(ge.error):he.error?ik(he.error):null,He=Le?.piboSessionId??t??``,Ue=c&&CE(c)?wE(c,o):null,We=async e=>{if(!t)return;let n=nk({piboSessionId:t,text:e,selectedWebAnnotations:xe,selectedUploadAttachments:Ne,eventSequence:le.current++,now:new Date().toISOString(),clientTxnId:w()});de(e=>rk(e,t,n.optimisticEvent)),await se(n.text,n.webAnnotationIds,n.fileAttachmentPaths,n.clientTxnId),Ae(),Ie(),await Promise.all([ge.refetch(),Te.refetch()])},Ge=WO({currentTraceView:Le,isLoading:Be,showThinking:y,expandThinking:b,selectedSessionProfile:i,sessionActiveModelBadge:Re,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,sessionNodes:e.sessions,sessionLinks:ze,agentProfiles:e.agents,sessionProfileChangeDisabled:g||r,onSessionAgentProfileChange:te,onFork:ne,onOpenSession:re,onThinkingLevelChange:oe,onRefreshTrace:k,onRefreshBootstrap:A,onError:ce});return(0,M.jsx)(RE,{selectedPiboSessionId:t,selectedRoomId:n,fallbackRoomId:e.selectedRoomId??void 0,sessionViewId:f,loadingTrace:Be,traceError:Ve,showRawEvents:_,currentTraceView:Le,traceEventLimit:pe,rawEventLimit:me,tracePageFetching:ge.isFetching,onLoadOlderTracePage:e=>void ve(e),onLoadMoreRawEvents:ye,headerProps:{title:Le?.title??t??e.room?.name??n,roomLabel:e.room?.name??n??`Room`,headerPiboSessionId:He,piboSessionId:t,piboRoomId:n??e.selectedRoomId??void 0,webAnnotationsDisabled:!t||r,webAnnotationsPanelRendered:Ce,workflowHeader:Ue,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,showRawEvents:_,showThinking:y,expandThinking:b,onShowWebAnnotationsPanel:()=>De(!0),onHideWebAnnotationsPanel:()=>De(!1),onSelectSessionView:ie,onToggleRawEvents:ee,onToggleThinking:D,onToggleExpandThinking:O,onError:ce},projectSessionCreatePanel:u,workflowStartPanel:d,currentSessionView:m,sessionViewProps:Ge,webAnnotationsPanelRendered:Ce,webAnnotationsPanelProps:{piboSessionId:t,annotations:j,selectedIds:be,loading:Te.isLoading||Te.isFetching||Ee,error:Te.error?ik(Te.error):null,collapsed:Se,onRefresh:()=>void Te.refetch(),onToggle:Oe,onClear:()=>void Me(),onCollapse:je,onClose:()=>De(!1)},composerProps:{sessionId:t,disabled:!t||r,commands:x,skills:S,value:C,focusSignal:T,selectedWebAnnotations:xe,selectedUploadAttachments:Ne,onValueChange:E,onCommand:ae,onDetachWebAnnotation:ke,onClearWebAnnotations:Ae,onAttachUploadedFiles:Pe,onDetachUploadAttachment:Fe,onClearUploadAttachments:Ie,onSend:We}})}function ok({mode:e,onSelectSession:t,onNewSession:n,onDeleteSession:r,onRenameSession:i,onSelectRoom:a}){return e.kind===`rooms`?(0,M.jsx)(pk,{candidates:e.candidates,workspace:e.workspace,onSelectRoom:a}):(0,M.jsx)(dk,{sessions:e.sessions,selectedPiboSessionId:e.selectedPiboSessionId,onSelectSession:t,onNewSession:n,onDeleteSession:r,onRenameSession:i})}function sk(e){return e===`running`?`running`:e===`error`?`error`:e===`completed`?`completed`:`idle`}var ck={running:`bg-cyan-400`,idle:`bg-slate-500`,error:`bg-rose-500`,completed:`bg-emerald-500`},lk={running:`running`,idle:`idle`,error:`error`,completed:`completed`};function uk({status:e}){let t=sk(e);return(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] uppercase tracking-wider text-slate-400`,children:[(0,M.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full ${ck[t]}`,"aria-hidden":`true`}),lk[t]]})}function dk({sessions:e,selectedPiboSessionId:t,onSelectSession:n,onNewSession:r,onDeleteSession:i,onRenameSession:a}){let o=[...e].sort((e,t)=>{let n=e.lastActivityAt??``;return(t.lastActivityAt??``).localeCompare(n)});return(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-slate-800 px-3 py-2 bg-[#0c1820]`,"data-testid":`session-list`,children:[(0,M.jsx)(`button`,{type:`button`,className:`shrink-0 w-7 h-7 inline-flex items-center justify-center rounded border border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`New session`,onClick:()=>void r(`default`),children:`+`}),(0,M.jsxs)(`ul`,{className:`flex gap-1 overflow-x-auto min-w-0`,children:[o.map(e=>(0,M.jsx)(`li`,{className:`shrink-0`,children:(0,M.jsx)(fk,{session:e,isActive:e.piboSessionId===t,onSelect:()=>n(e.piboSessionId),onDelete:()=>void i(e.piboSessionId),onRename:t=>void a(e.piboSessionId,t)})},e.piboSessionId)),o.length===0&&(0,M.jsx)(`li`,{className:`text-xs text-slate-500 px-2 py-1`,children:`No sessions yet — click + to start one.`})]})]})}function fk({session:e,isActive:t,onSelect:n,onDelete:r,onRename:i}){let[a,o]=(0,v.useState)(!1);return(0,M.jsxs)(`div`,{className:`group inline-flex items-center gap-2 rounded px-2 py-1 border ${t?`border-[#11a4d4] bg-[#102834]`:`border-slate-700 bg-[#0a1418] hover:border-slate-500`}`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-2 text-left`,children:[(0,M.jsx)(uk,{status:e.status}),(0,M.jsx)(`span`,{className:`text-xs text-slate-200 max-w-[180px] truncate`,children:e.title||`Untitled`})]}),(0,M.jsx)(`button`,{type:`button`,className:`text-slate-500 hover:text-slate-200 text-xs px-1`,title:`Session actions`,"aria-label":`Session actions`,onClick:e=>{e.stopPropagation(),o(e=>!e)},children:`…`}),a&&(0,M.jsxs)(`div`,{className:`absolute z-10 mt-12 -ml-20 bg-[#0a1418] border border-slate-700 rounded shadow-lg text-xs`,children:[(0,M.jsx)(`button`,{type:`button`,className:`block w-full text-left px-3 py-1.5 hover:bg-[#102834]`,onClick:t=>{t.stopPropagation(),o(!1);let n=window.prompt(`Rename session`,e.title??``);n&&n!==e.title&&i(n)},children:`Rename`}),(0,M.jsx)(`button`,{type:`button`,className:`block w-full text-left px-3 py-1.5 hover:bg-rose-900/30 text-rose-300`,onClick:t=>{t.stopPropagation(),o(!1),window.confirm(`Delete session "${e.title??`Untitled`}"?`)&&r()},children:`Delete`})]})]})}function pk({candidates:e,workspace:t,onSelectRoom:n}){return(0,M.jsxs)(`div`,{className:`border-b border-slate-800 px-3 py-3 bg-[#0c1820]`,"data-testid":`room-picker`,children:[(0,M.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wider text-slate-400 mb-2`,children:[`Multiple rooms found for `,(0,M.jsx)(`span`,{className:`font-mono text-slate-300`,children:t})]}),(0,M.jsx)(`ul`,{className:`flex flex-col gap-1`,children:e.map(e=>(0,M.jsx)(`li`,{children:(0,M.jsxs)(`button`,{type:`button`,className:`w-full text-left px-3 py-2 border border-slate-700 rounded hover:border-[#11a4d4] bg-[#0a1418]`,onClick:()=>n(e.id),children:[(0,M.jsx)(`div`,{className:`font-semibold text-slate-200 text-sm`,children:e.name}),e.topic&&(0,M.jsx)(`div`,{className:`text-xs text-slate-400 mt-0.5`,children:e.topic}),(0,M.jsxs)(`div`,{className:`text-[10px] text-slate-500 mt-1`,children:[`Created `,mk(e.createdAt),` · Updated `,mk(e.updatedAt)]})]})},e.id))})]})}function mk(e){try{return new Date(e).toLocaleString()}catch{return e}}function hk(){return new URLSearchParams(window.location.search).get(`workspace`)}function gk(){return new URLSearchParams(window.location.search).get(`roomId`)}function _k(){let e=(0,v.useMemo)(()=>hk(),[]),[t,n]=(0,v.useState)(()=>gk()),[r,i]=(0,v.useState)(()=>gk()?{kind:`sessions`,roomId:gk(),sessions:[],selectedPiboSessionId:null}:{kind:`rooms`,candidates:[],workspace:e??``}),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(0),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(!1),_=(0,v.useMemo)(()=>{let e=a?.sessionNodes;return Array.isArray(e)?e:[]},[a]);(0,v.useEffect)(()=>{if(!t)return;let e=!1;return(async()=>{try{let n=await te(void 0,!1,t);if(e)return;o(n);let r=n.sessions.find(e=>!e.archived)??n.sessions[0];r&&!s&&c(r.piboSessionId),i({kind:`sessions`,roomId:t,sessions:n.sessions,selectedPiboSessionId:r?.piboSessionId??null})}catch(t){e||m(ik(t))}})(),()=>{e=!0}},[t]);let y=(0,v.useCallback)(async()=>{if(t)try{o(await te(s??void 0,!1,t,!0))}catch(e){m(ik(e))}},[t,s]),b=(0,v.useCallback)(async()=>{await y()},[y]);(0,v.useEffect)(()=>{if(!t)return;let e=`/api/chat/events?${new URLSearchParams({roomId:t,mode:`summary`,since:`0:999999`}).toString()}`,n=new EventSource(e),r,i=()=>{r&&clearTimeout(r),r=setTimeout(()=>{r=void 0,y()},200)};return n.addEventListener(`change`,i),n.addEventListener(`trace`,i),n.addEventListener(`message`,i),n.onerror=()=>{},()=>{r&&clearTimeout(r),n.close()}},[t,y]),(0,v.useEffect)(()=>{let e=e=>{let t=e.data;!t||typeof t!=`object`||(t.type===`pibo/set-selector-mode`?(i(t.mode),t.mode.kind===`sessions`&&n(t.mode.roomId)):t.type===`pibo/refresh-bootstrap`&&y())};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[y]);let S=(0,v.useMemo)(()=>a?ee(a.capabilities.actions):[],[a]),C=(0,v.useMemo)(()=>D(a,s),[a,s]),T=(0,v.useMemo)(()=>r.kind===`sessions`?r.sessions:_,[r,_]),E=(0,v.useCallback)(e=>{c(e),f(e=>e+1)},[]),O=(0,v.useCallback)(async e=>{if(t)try{let n=await ne(e,t);await y(),n.session?.id&&c(n.session.id)}catch(e){m(ik(e))}},[t,y]),k=(0,v.useCallback)(async e=>{try{await ie(e,`delete`),await y(),s===e&&c(null)}catch(e){m(ik(e))}},[y,s]),A=(0,v.useCallback)(async(e,t)=>{try{await re(e,{title:t}),await y()}catch(e){m(ik(e))}},[y]),se=(0,v.useCallback)(e=>{n(e),c(null),o(null),i({kind:`sessions`,roomId:e,sessions:[],selectedPiboSessionId:null});let t=new URLSearchParams(window.location.search);t.set(`roomId`,e),window.history.replaceState(null,``,`${window.location.pathname}?${t.toString()}`)},[]),ue=(0,v.useCallback)(async e=>{if(!(!s||!t))try{await ae(s,e,w(),t),u(``),f(e=>e+1),await y()}catch(e){m(ik(e))}},[s,t,y]),de=(0,v.useCallback)(async e=>{if(!s)return!1;let n=e.trim();if(!n)return!1;let r=n.split(/\s+/)[0],i=S.find(e=>e.slash===r);if(!i)return m(`Unknown command: ${r}`),!1;if(i.action===`thinking-show`)return g(e=>!e),!0;if(i.action===`download`){let e=ce(n.slice(r.length));if(!e)return m(`Usage: /download <path>`),!0;try{await fe(e,{piboSessionId:s,roomId:t??void 0})}catch(e){m(ik(e))}return!0}try{let e=le(i.action,n.slice(r.length).trim());await oe(s,i.action,e),await y()}catch(e){m(ik(e))}return!0},[S,s,t,y]),pe=(0,v.useMemo)(()=>kT(),[]),he=(0,v.useMemo)(()=>AT(me),[]);if(!a)return(0,M.jsxs)(`div`,{className:`pibo-vscode-panel h-full flex flex-col bg-[#0c1820] text-slate-200`,children:[(0,M.jsx)(ok,{mode:r,onSelectSession:E,onNewSession:O,onDeleteSession:k,onRenameSession:A,onSelectRoom:se}),(0,M.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-slate-400 text-sm`,children:p?`Error: ${p}`:t?`Loading Pibo…`:`Waiting for room…`})]});if(r.kind===`rooms`)return(0,M.jsxs)(`div`,{className:`pibo-vscode-panel h-full flex flex-col bg-[#0c1820] text-slate-200`,children:[(0,M.jsx)(ok,{mode:{kind:`rooms`,candidates:a.rooms??r.candidates,workspace:r.workspace},onSelectSession:E,onNewSession:O,onDeleteSession:k,onRenameSession:A,onSelectRoom:se}),(0,M.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-slate-400 text-sm`,children:`Multiple rooms found — pick one above to continue.`})]});let ge=a.sessions.find(e=>e.piboSessionId===s);return(0,M.jsxs)(`div`,{className:`pibo-vscode-panel h-full flex flex-col bg-[#0c1820] text-slate-200`,children:[(0,M.jsx)(ok,{mode:{kind:`sessions`,roomId:t??``,sessions:T,selectedPiboSessionId:s},onSelectSession:E,onNewSession:O,onDeleteSession:k,onRenameSession:A,onSelectRoom:se}),p&&(0,M.jsxs)(`div`,{className:`bg-rose-900/40 border-b border-rose-700 text-rose-200 text-xs px-3 py-1.5`,role:`alert`,children:[p,(0,M.jsx)(`button`,{type:`button`,className:`ml-3 underline`,onClick:()=>m(null),children:`dismiss`})]}),(0,M.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,M.jsx)(ak,{bootstrap:a,selectedPiboSessionId:s,selectedRoomId:t,selectedRoomArchived:!1,selectedSessionProfile:ge?.profile??`default`,selectedSessionActiveModel:ge?x(a,ge)??void 0:void 0,selectedSessionStatus:ge?.status,sessionViewId:me,sessionViews:pe,currentSessionView:he,allowedSessionViewIds:[`terminal`],creatingSession:!1,showRawEvents:!1,showThinking:h,expandThinking:!1,commands:S,skills:C,composerText:l,composerFocusSignal:d,onComposerTextChange:u,onToggleRawEvents:()=>void 0,onToggleThinking:()=>g(e=>!e),onToggleExpandThinking:()=>void 0,onSessionAgentProfileChange:()=>void 0,onFork:()=>void 0,onOpenSession:e=>c(e),onSelectSessionView:()=>void 0,onCommand:de,onThinkingLevelChange:e=>void de(`/thinking ${e}`),onRefreshTrace:b,onRefreshBootstrap:y,onSend:ue,onError:m})})]})}var vk=document.getElementById(`root`);vk&&(0,y.createRoot)(vk).render((0,M.jsx)(v.StrictMode,{children:(0,M.jsx)(_k,{})}));