@rekayasa/erica-bubble 1.2.6 → 1.2.7

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.
package/dist/index.cjs CHANGED
@@ -74,5 +74,5 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
74
74
  `),c+=a.move(n.containerFlow(r,a.current()))),c+=a.move(`
75
75
  `+o)}return s(),c}function r(e,n){let r=e.attributes||{},a=[],o,s,c,l;for(l in r)if(Ev.call(r,l)&&r[l]!==void 0&&r[l]!==null){let u=String(r[l]);if(l===`id`)c=t.preferShortcut!==!1&&Ov.test(u)?`#`+u:i(`id`,u,e,n);else if(l===`class`){let r=u.split(/[\t\n\r ]+/g),a=[],c=[],l=-1;for(;++l<r.length;)(t.preferShortcut!==!1&&Ov.test(r[l])?c:a).push(r[l]);o=a.length>0?i(`class`,a.join(` `),e,n):``,s=c.length>0?`.`+c.join(`.`):``}else a.push(i(l,u,e,n))}return o&&a.unshift(o),s&&a.unshift(s),c&&a.unshift(c),a.length>0?`{`+a.join(` `)+`}`:``}function i(e,n,r,i){if(t.collapseEmptyAttributes!==!1&&!n)return e;if(t.preferUnquoted&&kv.test(n))return e+`=`+n;let a=t.quote||i.options.quote||`"`,o=a===`"`?`'`:`"`,s=t.quoteSmart&&oh(n,a)>oh(n,o)?o:a,c=r.type===`textDirective`?[s]:[s,`
76
76
  `,`\r`];return e+`=`+s+Tv(n,{subset:c})+s}}function Mv(e){Fv.call(this,`containerDirective`,e)}function Nv(e){Fv.call(this,`leafDirective`,e)}function Pv(e){Fv.call(this,`textDirective`,e)}function Fv(e,t){this.enter({type:e,name:``,attributes:{},children:[]},t)}function Iv(e){let t=this.stack[this.stack.length-1];t.type===`containerDirective`||t.type===`leafDirective`||t.type,t.name=this.sliceSerialize(e)}function Lv(e){this.enter({type:`paragraph`,data:{directiveLabel:!0},children:[]},e)}function Rv(e){this.exit(e)}function zv(){this.data.directiveAttributes=[],this.buffer()}function Bv(e){this.data.directiveAttributes.push([`id`,pv(this.sliceSerialize(e),{attribute:!0})])}function Vv(e){this.data.directiveAttributes.push([`class`,pv(this.sliceSerialize(e),{attribute:!0})])}function Hv(e){let t=this.data.directiveAttributes;t[t.length-1][1]=pv(this.sliceSerialize(e),{attribute:!0})}function Uv(e){this.data.directiveAttributes.push([this.sliceSerialize(e),``])}function Wv(){let e=this.data.directiveAttributes,t={},n=-1;for(;++n<e.length;){let r=e[n];r[0]===`class`&&t.class?t.class+=` `+r[1]:t[r[0]]=r[1]}this.data.directiveAttributes=void 0,this.resume();let r=this.stack[this.stack.length-1];r.type===`containerDirective`||r.type===`leafDirective`||r.type,r.attributes=t}function Gv(e){this.exit(e)}function Kv(){return`:`}function qv(e){return!!(e&&e.type===`paragraph`&&e.data&&e.data.directiveLabel)}function Jv(e){let t=0;return e.type===`containerDirective`?(tm(e,function(e,n){if(e.type===`containerDirective`){let e=n.length,r=0;for(;e--;)n[e].type===`containerDirective`&&r++;r>t&&(t=r)}}),t+=3):t=e.type===`leafDirective`?2:1,`:`.repeat(t)}function Yv(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){let h,g;return _;function _(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),v}function v(t){return t===35?(h=o,y(t)):t===46?(h=s,y(t)):m&&Z(t)?Q(e,v,`whitespace`)(t):!m&&X(t)?xd(e,v)(t):t===null||Y(t)||wu(t)||Cu(t)&&t!==45&&t!==95?te(t):(e.enter(a),e.enter(c),e.consume(t),S)}function y(t){let n=h+`Marker`;return e.enter(a),e.enter(h),e.enter(n),e.consume(t),e.exit(n),b}function b(t){if(t===null||t===34||t===35||t===39||t===46||t===60||t===61||t===62||t===96||t===125||X(t))return n(t);let r=h+`Value`;return e.enter(r),e.consume(t),x}function x(t){if(t===null||t===34||t===39||t===60||t===61||t===62||t===96)return n(t);if(t===35||t===46||t===125||X(t)){let n=h+`Value`;return e.exit(n),e.exit(h),e.exit(a),v(t)}return e.consume(t),x}function S(t){return t===null||Y(t)||wu(t)||Cu(t)&&t!==45&&t!==46&&t!==58&&t!==95?(e.exit(c),m&&Z(t)?Q(e,C,`whitespace`)(t):!m&&X(t)?xd(e,C)(t):C(t)):(e.consume(t),S)}function C(t){return t===61?(e.enter(l),e.consume(t),e.exit(l),w):(e.exit(a),v(t))}function w(t){return t===null||t===60||t===61||t===62||t===96||t===125||m&&Y(t)?n(t):t===34||t===39?(e.enter(u),e.enter(f),e.consume(t),e.exit(f),g=t,E):m&&Z(t)?Q(e,w,`whitespace`)(t):!m&&X(t)?xd(e,w)(t):(e.enter(d),e.enter(p),e.consume(t),g=void 0,T)}function T(t){return t===null||t===34||t===39||t===60||t===61||t===62||t===96?n(t):t===125||X(t)?(e.exit(p),e.exit(d),e.exit(a),v(t)):(e.consume(t),T)}function E(t){return t===g?(e.enter(f),e.consume(t),e.exit(f),e.exit(u),e.exit(a),ee):(e.enter(d),D(t))}function D(t){return t===g?(e.exit(d),E(t)):t===null?n(t):Y(t)?m?n(t):xd(e,D)(t):(e.enter(p),e.consume(t),O)}function O(t){return t===g||t===null||Y(t)?(e.exit(p),D(t)):(e.consume(t),O)}function ee(e){return e===125||X(e)?v(e):te(e)}function te(a){return a===125?(e.enter(i),e.consume(a),e.exit(i),e.exit(r),t):n(a)}}function Xv(e,t,n,r,i,a,o){let s=0,c=0,l;return u;function u(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),d}function d(n){return n===93?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),f(n))}function f(t){if(t===93&&!c)return h(t);let n=e.enter(`chunkText`,{_contentTypeTextTrailing:!0,contentType:`text`,previous:l});return l&&(l.next=n),l=n,p(t)}function p(t){return t===null||s>999||t===91&&++c>32?n(t):t===93&&!c--?(e.exit(`chunkText`),h(t)):Y(t)?o?n(t):(e.consume(t),e.exit(`chunkText`),f):(e.consume(t),t===92?m:p)}function m(t){return t===91||t===92||t===93?(e.consume(t),s++,p):p(t)}function h(n){return e.exit(a),e.enter(i),e.consume(n),e.exit(i),e.exit(r),t}}function Zv(e,t,n,r){let i=this;return a;function a(t){return t===null||Y(t)||Cu(t)||wu(t)?n(t):(e.enter(r),e.consume(t),o)}function o(a){return a===null||Y(a)||wu(a)||Cu(a)&&a!==45&&a!==95?(e.exit(r),i.previous===45||i.previous===95?n(a):t(a)):(e.consume(a),o)}}var Qv={tokenize:ny,concrete:!0},$v={tokenize:ry,partial:!0},ey={tokenize:iy,partial:!0},ty={tokenize:ay,partial:!0};function ny(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0,s;return c;function c(t){return e.enter(`directiveContainer`),e.enter(`directiveContainerFence`),e.enter(`directiveContainerSequence`),l(t)}function l(t){return t===58?(e.consume(t),o++,l):o<3?n(t):(e.exit(`directiveContainerSequence`),Zv.call(r,e,u,n,`directiveContainerName`)(t))}function u(t){return t===91?e.attempt($v,d,d)(t):d(t)}function d(t){return t===123?e.attempt(ey,f,f)(t):f(t)}function f(t){return Q(e,p,`whitespace`)(t)}function p(i){return e.exit(`directiveContainerFence`),i===null?C(i):Y(i)?r.interrupt?t(i):e.attempt(ty,m,C)(i):n(i)}function m(t){return t===null?C(t):Y(t)?e.check(ty,y,C)(t):(e.enter(`directiveContainerContent`),h(t))}function h(t){return e.attempt({tokenize:w,partial:!0},S,a?Q(e,g,`linePrefix`,a+1):g)(t)}function g(t){return t===null?S(t):Y(t)?e.check(ty,v,S)(t):v(t)}function _(t){if(t===null){let n=e.exit(`chunkDocument`);return r.parser.lazy[n.start.line]=!1,S(t)}return Y(t)?e.check(ty,b,x)(t):(e.consume(t),_)}function v(t){let n=e.enter(`chunkDocument`,{contentType:`document`,previous:s});return s&&(s.next=n),s=n,_(t)}function y(t){return e.enter(`directiveContainerContent`),h(t)}function b(t){e.consume(t);let n=e.exit(`chunkDocument`);return r.parser.lazy[n.start.line]=!1,h}function x(t){let n=e.exit(`chunkDocument`);return r.parser.lazy[n.start.line]=!1,S(t)}function S(t){return e.exit(`directiveContainerContent`),C(t)}function C(n){return e.exit(`directiveContainer`),t(n)}function w(e,t,n){let i=0;return Q(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4);function a(t){return e.enter(`directiveContainerFence`),e.enter(`directiveContainerSequence`),s(t)}function s(t){return t===58?(e.consume(t),i++,s):i<o?n(t):(e.exit(`directiveContainerSequence`),Q(e,c,`whitespace`)(t))}function c(r){return r===null||Y(r)?(e.exit(`directiveContainerFence`),t(r)):n(r)}}}function ry(e,t,n){return Xv(e,t,n,`directiveContainerLabel`,`directiveContainerLabelMarker`,`directiveContainerLabelString`,!0)}function iy(e,t,n){return Yv(e,t,n,`directiveContainerAttributes`,`directiveContainerAttributesMarker`,`directiveContainerAttribute`,`directiveContainerAttributeId`,`directiveContainerAttributeClass`,`directiveContainerAttributeName`,`directiveContainerAttributeInitializerMarker`,`directiveContainerAttributeValueLiteral`,`directiveContainerAttributeValue`,`directiveContainerAttributeValueMarker`,`directiveContainerAttributeValueData`,!0)}function ay(e,t,n){let r=this;return i;function i(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var oy={tokenize:ly},sy={tokenize:uy,partial:!0},cy={tokenize:dy,partial:!0};function ly(e,t,n){let r=this;return i;function i(t){return e.enter(`directiveLeaf`),e.enter(`directiveLeafSequence`),e.consume(t),a}function a(t){return t===58?(e.consume(t),e.exit(`directiveLeafSequence`),Zv.call(r,e,o,n,`directiveLeafName`)):n(t)}function o(t){return t===91?e.attempt(sy,s,s)(t):s(t)}function s(t){return t===123?e.attempt(cy,c,c)(t):c(t)}function c(t){return Q(e,l,`whitespace`)(t)}function l(r){return r===null||Y(r)?(e.exit(`directiveLeaf`),t(r)):n(r)}}function uy(e,t,n){return Xv(e,t,n,`directiveLeafLabel`,`directiveLeafLabelMarker`,`directiveLeafLabelString`,!0)}function dy(e,t,n){return Yv(e,t,n,`directiveLeafAttributes`,`directiveLeafAttributesMarker`,`directiveLeafAttribute`,`directiveLeafAttributeId`,`directiveLeafAttributeClass`,`directiveLeafAttributeName`,`directiveLeafAttributeInitializerMarker`,`directiveLeafAttributeValueLiteral`,`directiveLeafAttributeValue`,`directiveLeafAttributeValueMarker`,`directiveLeafAttributeValueData`,!0)}var fy={tokenize:gy,previous:hy},py={tokenize:_y,partial:!0},my={tokenize:vy,partial:!0};function hy(e){return e!==58||this.events[this.events.length-1][1].type===`characterEscape`}function gy(e,t,n){let r=this;return i;function i(t){return e.enter(`directiveText`),e.enter(`directiveTextMarker`),e.consume(t),e.exit(`directiveTextMarker`),Zv.call(r,e,a,n,`directiveTextName`)}function a(t){return t===58?n(t):t===91?e.attempt(py,o,o)(t):o(t)}function o(t){return t===123?e.attempt(my,s,s)(t):s(t)}function s(n){return e.exit(`directiveText`),t(n)}}function _y(e,t,n){return Xv(e,t,n,`directiveTextLabel`,`directiveTextLabelMarker`,`directiveTextLabelString`)}function vy(e,t,n){return Yv(e,t,n,`directiveTextAttributes`,`directiveTextAttributesMarker`,`directiveTextAttribute`,`directiveTextAttributeId`,`directiveTextAttributeClass`,`directiveTextAttributeName`,`directiveTextAttributeInitializerMarker`,`directiveTextAttributeValueLiteral`,`directiveTextAttributeValue`,`directiveTextAttributeValueMarker`,`directiveTextAttributeValueData`)}function yy(){return{text:{58:fy},flow:{58:[Qv,oy]}}}function by(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[],r=e.toMarkdownExtensions||=[];t.push(yy()),n.push(Av()),r.push(jv())}function xy({markdown:e}){return(0,f.jsx)(`div`,{className:`report-artifact`,children:(0,f.jsx)(th,{remarkPlugins:[by,()=>e=>{let t=e=>{let n=[`grid`,`column`].includes(e.name);[`containerDirective`,`leafDirective`,`textDirective`].includes(e.type)&&n&&(e.data=e.data||{},e.data.hName=e.name,e.data.hProperties=e.attributes||{}),e.children&&e.children.forEach(t)};t(e)},av],components:{h1:({children:e})=>(0,f.jsx)(`h1`,{children:e}),h2:({children:e})=>(0,f.jsx)(`h2`,{children:e}),h3:({children:e})=>(0,f.jsx)(`h3`,{children:e}),p:({children:e})=>(0,f.jsx)(`p`,{children:e}),ul:({children:e})=>(0,f.jsx)(`ul`,{children:e}),ol:({children:e})=>(0,f.jsx)(`ol`,{children:e}),li:({children:e})=>(0,f.jsx)(`li`,{children:e}),a:({children:e,href:t})=>(0,f.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,children:e}),blockquote:({children:e})=>(0,f.jsx)(`blockquote`,{children:e}),hr:()=>(0,f.jsx)(`hr`,{}),table:({children:e})=>(0,f.jsx)(`div`,{className:`report-artifact-table-wrapper`,children:(0,f.jsx)(`table`,{children:e})}),thead:({children:e})=>(0,f.jsx)(`thead`,{children:e}),th:({children:e})=>(0,f.jsx)(`th`,{children:e}),td:({children:e})=>(0,f.jsx)(`td`,{children:e}),code:e=>{let{children:t,className:n,...r}=e;return/language-(\w+)/.exec(n||``)?.[1]===`ericachart`?(0,f.jsx)(wc,{markdown:t}):(0,f.jsx)(`code`,{...r,className:n,children:t})},grid:({children:e,columns:t})=>(0,f.jsx)(`div`,{className:`report-grid report-grid--cols-${t?Number(t):2}`,children:e})},children:e})})}function Sy({title:e,reportContent:t}){let n=kc(),r=()=>{n.setTitle(e),n.setContent((0,f.jsx)(xy,{markdown:t})),n.onOpen()};return(0,f.jsx)(`div`,{onClick:r,className:`report-item-card`,children:(0,f.jsxs)(`div`,{className:`report-item-content`,children:[(0,f.jsx)(`div`,{className:`report-item-icon-wrapper`,children:(0,f.jsx)(`svg`,{className:`report-item-icon`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z`})})}),(0,f.jsxs)(`div`,{className:`report-item-text-wrapper`,children:[(0,f.jsx)(`span`,{className:`report-item-title`,children:e}),(0,f.jsx)(`span`,{className:`report-item-subtitle`,children:`Business Report`})]}),(0,f.jsx)(`button`,{onClick:r,className:`report-item-button`,children:`Show Report`})]})})}function Cy({path:e,title:t}){let n=e.split(`/`),r=n[5],i=n[6],{data:a,isLoading:o}=Lt({queryKey:[`artifact`,r,e],queryFn:()=>Xs.get(r,i),enabled:!!r&&!!e});return o?(0,f.jsx)(`div`,{className:`report-loader-loading`,children:`loading report...`}):a?(0,f.jsx)(Sy,{title:t,reportContent:a}):(0,f.jsx)(`div`,{className:`report-loader-no-data`,children:`No report data available`})}function wy({message:e,datasetUuid:t,upsertKey:n,rows:r,previewRows:i,hiddenCount:a,onApprove:o,onReject:s}){let[c,l]=(0,u.useState)(!1),[d,p]=(0,u.useState)(``),m=()=>{c?s(d||void 0):l(!0)},h=i.length>0?Object.keys(i[0]):[];return(0,f.jsxs)(`div`,{className:`dataset-approval-card`,children:[(0,f.jsxs)(`div`,{className:`dataset-approval-header`,children:[(0,f.jsx)(`h3`,{className:`dataset-approval-title`,children:e}),t&&(0,f.jsxs)(`p`,{className:`dataset-approval-meta`,children:[`Dataset: `,(0,f.jsx)(`code`,{className:`dataset-approval-code`,children:t})]}),n&&n.length>0&&(0,f.jsxs)(`p`,{className:`dataset-approval-meta`,children:[`Upsert Key: `,(0,f.jsx)(`code`,{className:`dataset-approval-code`,children:n.join(`, `)})]})]}),i.length>0&&(0,f.jsxs)(`div`,{className:`dataset-approval-table-wrapper`,children:[(0,f.jsxs)(`table`,{className:`dataset-approval-table`,children:[(0,f.jsx)(`thead`,{className:`dataset-approval-thead`,children:(0,f.jsx)(`tr`,{children:h.map(e=>(0,f.jsx)(`th`,{className:`dataset-approval-th`,children:e},e))})}),(0,f.jsx)(`tbody`,{children:i.map((e,t)=>(0,f.jsx)(`tr`,{className:`dataset-approval-tr`,children:h.map(t=>(0,f.jsx)(`td`,{className:`dataset-approval-td`,children:String(e[t]??``)},t))},t))})]}),a>0&&(0,f.jsxs)(`p`,{className:`dataset-approval-hidden-count`,children:[`... and `,a,` more row`,a===1?``:`s`]})]}),(0,f.jsxs)(`div`,{className:`dataset-approval-total`,children:[`Total rows: `,r.length]}),c&&(0,f.jsxs)(`div`,{className:`dataset-approval-reject-section`,children:[(0,f.jsx)(`label`,{className:`dataset-approval-reject-label`,children:`Rejection reason (optional):`}),(0,f.jsx)(`input`,{type:`text`,value:d,onChange:e=>p(e.target.value),className:`dataset-approval-reject-input`,placeholder:`Enter reason...`})]}),(0,f.jsxs)(`div`,{className:`dataset-approval-buttons`,children:[(0,f.jsx)(`button`,{onClick:o,className:`dataset-approval-btn dataset-approval-btn-approve`,children:`Approve`}),(0,f.jsx)(`button`,{onClick:m,className:`dataset-approval-btn dataset-approval-btn-reject`,children:c?`Confirm Reject`:`Reject`}),c&&(0,f.jsx)(`button`,{onClick:()=>{l(!1),p(``)},className:`dataset-approval-btn-cancel`,children:`Cancel`})]})]})}var Ty=e=>e==null||e===``?`—`:typeof e==`object`?JSON.stringify(e):String(e);function Ey({rows:e}){let t=e.length>0?Object.keys(e[0]):[];return e.length===0?(0,f.jsx)(`span`,{className:`template-approval-empty`,children:`[]`}):(0,f.jsxs)(`div`,{className:`template-approval-table-wrapper`,children:[(0,f.jsxs)(`table`,{className:`template-approval-table`,children:[(0,f.jsx)(`thead`,{className:`template-approval-thead`,children:(0,f.jsx)(`tr`,{children:t.map(e=>(0,f.jsx)(`th`,{className:`template-approval-th`,children:e},e))})}),(0,f.jsx)(`tbody`,{children:e.slice(0,5).map((e,n)=>(0,f.jsx)(`tr`,{className:`template-approval-tr`,children:t.map(t=>(0,f.jsx)(`td`,{className:`template-approval-td`,children:Ty(e[t])},t))},n))})]}),e.length>5&&(0,f.jsxs)(`p`,{className:`template-approval-hidden-count`,children:[`... and `,e.length-5,` more row`,e.length-5==1?``:`s`]})]})}function Dy({message:e,templateName:t,outputFilename:n,data:r,onApprove:i,onReject:a}){let[o,s]=(0,u.useState)(!1),[c,l]=(0,u.useState)(``),[d,p]=(0,u.useState)(null),m=()=>{p(`approved`),i()},h=()=>{if(!o){s(!0);return}p(`rejected`),a(c.trim()||void 0)},g=Object.entries(r);return(0,f.jsxs)(`div`,{className:`template-approval-card`,children:[(0,f.jsxs)(`div`,{className:`template-approval-header`,children:[(0,f.jsx)(`div`,{className:`template-approval-icon`,"aria-hidden":`true`,children:`📄`}),(0,f.jsxs)(`div`,{className:`template-approval-heading`,children:[(0,f.jsx)(`h3`,{className:`template-approval-title`,children:`Fill Template`}),t&&(0,f.jsx)(`p`,{className:`template-approval-meta`,children:t})]})]}),(0,f.jsx)(`p`,{className:`template-approval-message`,children:e}),n&&(0,f.jsxs)(`p`,{className:`template-approval-output`,children:[`Output: `,(0,f.jsx)(`strong`,{children:n})]}),g.length>0&&(0,f.jsx)(`div`,{className:`template-approval-data`,children:g.map(([e,t])=>{let n=Array.isArray(t)&&t.length>0&&typeof t[0]==`object`&&t[0]!==null;return(0,f.jsxs)(`div`,{className:`template-approval-field`,children:[(0,f.jsx)(`span`,{className:`template-approval-field-key`,children:e}),(0,f.jsx)(`div`,{className:`template-approval-field-value`,children:n?(0,f.jsx)(Ey,{rows:t}):Ty(t)})]},e)})}),o&&!d&&(0,f.jsxs)(`div`,{className:`template-approval-reject-section`,children:[(0,f.jsx)(`label`,{className:`template-approval-reject-label`,children:`Rejection reason (optional):`}),(0,f.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`template-approval-reject-input`,placeholder:`Enter reason...`})]}),d?(0,f.jsx)(`div`,{className:`template-approval-resolved template-approval-resolved-${d}`,children:d===`approved`?`Approved`:`Rejected${c.trim()?` — ${c.trim()}`:``}`}):(0,f.jsxs)(`div`,{className:`template-approval-buttons`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:m,className:`template-approval-btn template-approval-btn-approve`,children:`Approve`}),(0,f.jsx)(`button`,{type:`button`,onClick:h,className:`template-approval-btn template-approval-btn-reject`,children:o?`Confirm Reject`:`Reject`}),o&&(0,f.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),l(``)},className:`template-approval-btn-cancel`,children:`Cancel`})]})]})}var Oy=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),ky=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),Ay=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),jy=e=>{let t=Ay(e);return t.charAt(0).toUpperCase()+t.slice(1)},My={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},Ny=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},Py=(0,u.createContext)({}),Fy=()=>(0,u.useContext)(Py),Iy=(0,u.forwardRef)(({color:e,size:t,strokeWidth:n,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...s},c)=>{let{size:l=24,strokeWidth:d=2,absoluteStrokeWidth:f=!1,color:p=`currentColor`,className:m=``}=Fy()??{},h=r??f?Number(n??d)*24/Number(t??l):n??d;return(0,u.createElement)(`svg`,{ref:c,...My,width:t??l??My.width,height:t??l??My.height,stroke:e??p,strokeWidth:h,className:Oy(`lucide`,m,i),...!a&&!Ny(s)&&{"aria-hidden":`true`},...s},[...o.map(([e,t])=>(0,u.createElement)(e,t)),...Array.isArray(a)?a:[a]])}),Ly=(e,t)=>{let n=(0,u.forwardRef)(({className:n,...r},i)=>(0,u.createElement)(Iy,{ref:i,iconNode:t,className:Oy(`lucide-${ky(jy(e))}`,`lucide-${e}`,n),...r}));return n.displayName=jy(e),n},Ry=Ly(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),zy=Ly(`layout-template`,[[`rect`,{width:`18`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`f1a2em`}],[`rect`,{width:`9`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`jqznyg`}],[`rect`,{width:`5`,height:`7`,x:`16`,y:`14`,rx:`1`,key:`q5h2i8`}]]),By=Ly(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),Vy=Ly(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),Hy=Ly(`square-pen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),Uy=Ly(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),Wy={downloadGenerated:async(e,t)=>{let{data:n}=await me.get({url:`/templates/generated/${encodeURIComponent(e)}/download`,parseAs:`blob`,throwOnError:!0}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}};function Gy({templateName:e,outputFilename:t,s3Path:n}){let[r,i]=(0,u.useState)(!1),[a,o]=(0,u.useState)(null),s=(0,u.useMemo)(()=>n.split(`/`).pop()?.replace(/\.docx$/i,``)??``,[n]),c=async()=>{if(!s){o(`Generated file id is missing`);return}i(!0),o(null);try{await Wy.downloadGenerated(s,t||`${s}.docx`)}catch(e){o(e instanceof Error?e.message:`Download failed`)}finally{i(!1)}};return(0,f.jsxs)(`div`,{className:`filled-template-card`,children:[(0,f.jsx)(`div`,{className:`filled-template-icon`,"aria-hidden":`true`,children:(0,f.jsx)(zy,{size:24})}),(0,f.jsxs)(`div`,{className:`filled-template-content`,children:[(0,f.jsx)(`div`,{className:`filled-template-filename`,children:t}),(0,f.jsxs)(`div`,{className:`filled-template-meta`,children:[`Filled from `,e]}),a&&(0,f.jsx)(`div`,{className:`filled-template-error`,children:a})]}),(0,f.jsx)(`button`,{type:`button`,onClick:c,disabled:r||!s,className:`filled-template-download-btn`,children:r?`Downloading...`:`Download`})]})}function Ky({name:e}){let t=(0,u.useContext)(tn);return(0,u.useEffect)(()=>{t&&t.setStep(e)},[e,t]),null}function qy(){return(0,d.useRenderTool)({name:`show_chart`,parameters:qs,render:({parameters:e})=>e.compiled_chart?.path?(0,f.jsx)(Ec,{path:e.compiled_chart.path}):(0,f.jsx)(`div`,{children:`No chart path provided`})},[]),(0,d.useRenderTool)({name:`show_report`,parameters:Js,render:({parameters:e})=>e.compiled_report?.path?(0,f.jsx)(Cy,{path:e.compiled_report.path,title:e.compiled_report.title}):(0,f.jsx)(`div`,{children:`No report path provided`})},[]),(0,d.useRenderTool)({name:`show_template`,parameters:Ys,render:({parameters:e})=>{let{filled_template:t}=e;return t?.s3_path?(0,f.jsx)(Gy,{templateName:t.template_name,outputFilename:t.output_filename,s3Path:t.s3_path}):(0,f.jsx)(`div`,{children:`No template path provided`})}},[]),(0,d.useDefaultRenderTool)({render:({name:e})=>(0,f.jsx)(Ky,{name:e})},[]),(0,d.useInterrupt)({render:({event:e,resolve:t})=>{let n={};try{n=typeof e.value==`string`?JSON.parse(e.value):e.value}catch{}if(n?.type===`fill_template`){let{message:e,action:r}=n;return(0,f.jsx)(Dy,{message:e??`Approve this action?`,templateName:r?.template_name??``,outputFilename:r?.output_filename,data:r?.data??{},onApprove:()=>t({approved:!0}),onReject:e=>t({approved:!1,...e?{reason:e}:{}})})}if(n?.type===`write_to_dataset`){let{message:e,action:r}=n,i=r?.rows??[],a=i.slice(0,3),o=i.length-a.length;return(0,f.jsx)(wy,{message:e??`Approve this action?`,datasetUuid:r?.dataset_uuid,upsertKey:r?.upsert_key,rows:i,previewRows:a,hiddenCount:o,onApprove:()=>t({approved:!0}),onReject:e=>t({approved:!1,...e?{reason:e}:{}})})}return(0,f.jsx)(`div`,{className:`tools-interrupt-fallback`,children:(0,f.jsx)(`p`,{children:typeof e.value==`string`?e.value:JSON.stringify(e.value)})})}}),null}var Jy={search:async(e,t=Zt)=>{let{data:n}=await me.get({security:[{scheme:`bearer`,type:`http`}],url:`/chat/resources/search`,query:{query:e,agent:t},throwOnError:!0});return n.data??[]}},Yy={dataset:`dataset`,document:`document`,template:`template`},Xy=(0,u.forwardRef)(({items:e,command:t,isLoading:n=!1},r)=>{let[i,a]=(0,u.useState)(0),o=(0,u.useRef)(null);return(0,u.useEffect)(()=>{a(0)},[e]),(0,u.useEffect)(()=>{o.current?.scrollIntoView({block:`nearest`})},[i]),(0,u.useImperativeHandle)(r,()=>({onKeyDown:n=>n.key===`ArrowUp`?(e.length===0||a(t=>(t-1+e.length)%e.length),!0):n.key===`ArrowDown`?(e.length===0||a(t=>(t+1)%e.length),!0):n.key===`Enter`||n.key===`Tab`?(e[i]&&t(e[i]),!0):!1})),!n&&e.length===0?null:(0,f.jsxs)(`div`,{className:`erica-mention-list`,children:[(0,f.jsxs)(`div`,{className:`erica-mention-list-header`,children:[(0,f.jsx)(`span`,{className:`erica-mention-at`,children:`@`}),(0,f.jsx)(`span`,{children:`Mention`}),n&&(0,f.jsx)(`span`,{className:`erica-mention-spinner`})]}),(0,f.jsx)(`div`,{className:`erica-mention-list-body`,children:n&&e.length===0?(0,f.jsx)(`div`,{className:`erica-mention-empty`,children:`Searching…`}):e.map((e,n)=>(0,f.jsxs)(`button`,{ref:n===i?o:void 0,type:`button`,className:[`erica-mention-item`,n===i?`erica-mention-item-selected`:``].filter(Boolean).join(` `),onMouseEnter:()=>a(n),onMouseDown:n=>{n.preventDefault(),t(e)},children:[(0,f.jsx)(`span`,{className:`erica-mention-label`,children:e.label}),e.description&&(0,f.jsx)(`span`,{className:[`erica-mention-badge`,`erica-mention-badge-${e.description}`].join(` `),children:Yy[e.description]??e.description})]},e.id))})]})});Xy.displayName=`MentionSuggestionList`;function Zy(e){return e.nodeType===Node.TEXT_NODE?e.textContent??``:e instanceof HTMLElement?e.dataset.resourceUid&&e.dataset.resourceType?`:resource[${e.dataset.resourceLabel??e.textContent?.replace(/^@/,``)??``}]{uid="${e.dataset.resourceUid}" type="${e.dataset.resourceType}"}`:e.tagName===`BR`?`
77
- `:Array.from(e.childNodes).map(Zy).join(``):Array.from(e.childNodes).map(Zy).join(``)}function Qy(e){return Array.from(e.childNodes).map(Zy).join(``)}function $y(){let e=window.getSelection();if(!e||e.rangeCount===0)return null;let t=e.getRangeAt(0);if(!t.collapsed||t.startContainer.nodeType!==Node.TEXT_NODE)return null;let n=t.startContainer,r=n.data.slice(0,t.startOffset),i=/(?:^|\s)@([^@\s]*)$/.exec(r);return i?{node:n,start:r.length-i[1].length-1,end:t.startOffset,query:i[1]}:null}function eb(e,t){let n=document.createRange();n.setStart(e,Math.min(t,e.data.length)),n.collapse(!0);let r=window.getSelection();r?.removeAllRanges(),r?.addRange(n)}function tb({value:e,onChange:t,onSubmit:n,agentIdentifier:r,placeholder:i=`Ketik pertanyaan Anda di sini...`}){let a=(0,u.useRef)(null),o=(0,u.useRef)(null),s=(0,u.useRef)(null),c=(0,u.useRef)(null),l=(0,u.useRef)(null),d=(0,u.useRef)(null),p=(0,u.useRef)(0),h=(0,u.useRef)(n),g=(0,u.useRef)(t),_=(0,u.useRef)(r),[v,y]=(0,u.useState)(!0);(0,u.useEffect)(()=>{h.current=n},[n]),(0,u.useEffect)(()=>{g.current=t},[t]),(0,u.useEffect)(()=>{_.current=r},[r]),(0,u.useEffect)(()=>{e===``&&a.current&&a.current.textContent&&(a.current.innerHTML=``,y(!0))},[e]),(0,u.useEffect)(()=>()=>b(),[]);function b(){d.current&&=(clearTimeout(d.current),null),s.current?.unmount(),s.current=null,o.current?.remove(),o.current=null,l.current=null}function x(){let e=a.current;if(!e)return;let t=Qy(e);y(t.trim().length===0),g.current(t)}function S(e,t){let n=l.current;if(!n)return;o.current||(o.current=document.createElement(`div`),o.current.className=`erica-mention-popup`,o.current.setAttribute(`data-mention-suggestion`,``),document.body.appendChild(o.current),s.current=(0,m.createRoot)(o.current)),s.current.render((0,f.jsx)(Xy,{ref:c,items:e,isLoading:t,command:T}));let r=document.createRange();r.setStart(n.node,n.start),r.setEnd(n.node,n.end);let i=r.getBoundingClientRect();o.current.style.left=`${i.left}px`,o.current.style.bottom=`${window.innerHeight-i.top+6}px`}function C(e){let t=++p.current;S([],!0),d.current&&clearTimeout(d.current),d.current=setTimeout(async()=>{d.current=null;try{let n=await Jy.search(e.query,_.current);if(t!==p.current)return;S(n.filter(e=>[`dataset`,`document`,`template`].includes(e.type)).map(e=>({id:`${e.type}:${e.uid}`,label:e.name,description:e.type})),!1)}catch{if(t!==p.current)return;S([],!1)}},300)}function w(){let e=$y();if(l.current=e,!e){b();return}C(e)}function T(e){let t=l.current;if(!t)return;let[n,r]=e.id.split(`:`),i=t.node,a=i.data.slice(0,t.start),o=i.data.slice(t.end),s=i.parentNode;if(!s)return;let c=document.createElement(`span`);c.className=`erica-resource-tag erica-editor-resource-tag`,c.contentEditable=`false`,c.dataset.resourceType=n,c.dataset.resourceUid=r,c.dataset.resourceLabel=e.label,c.textContent=`@${e.label}`;let u=document.createTextNode(a),d=document.createTextNode(` ${o}`);s.insertBefore(u,i),s.insertBefore(c,i),s.insertBefore(d,i),s.removeChild(i),b(),eb(d,1),x()}return(0,f.jsxs)(`div`,{className:`erica-editor-wrap`,children:[v&&(0,f.jsx)(`div`,{className:`erica-editor-placeholder`,children:i}),(0,f.jsx)(`div`,{ref:a,className:`erica-chat-editor`,contentEditable:!0,role:`textbox`,"aria-multiline":`true`,"data-testid":`chat-editor`,onInput:()=>{x(),w()},onKeyDown:e=>{if(o.current){if(e.key===`Escape`){e.preventDefault(),b();return}if(c.current?.onKeyDown(e.nativeEvent)){e.preventDefault();return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),h.current())},onKeyUp:w,onBlur:()=>{window.setTimeout(()=>{document.querySelector(`[data-mention-suggestion]:hover`)||b()},150)}})]})}function nb({hasAttachments:e,disabled:t,onFilesSelected:n}){let r=(0,u.useRef)(null);function i(e){let t=Array.from(e.target.files??[]);t.length>0&&n(t),e.target.value=``}return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`input`,{ref:r,type:`file`,multiple:!0,className:`erica-attachment-input`,onChange:i,disabled:t}),(0,f.jsx)(`button`,{type:`button`,"aria-label":`Attach files`,className:[`erica-attachment-button`,e?`erica-attachment-button-active`:``].filter(Boolean).join(` `),disabled:t,onClick:()=>r.current?.click(),children:(0,f.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,f.jsx)(`path`,{d:`M21.44 11.05 12.25 20.24a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48`})})})]})}function rb(e){let t=(0,u.useContext)(tn),[n,r]=(0,u.useState)(!1),i=(0,u.useRef)(0);if(!t)return(0,f.jsx)(d.CopilotChatInput,{...e});let{attachedFiles:a,addFiles:o,removeFile:s,inputValue:c,setInputValue:l,handleSubmit:p,threadId:m}=t,h=Zt;function g(e){e.preventDefault(),i.current+=1,e.dataTransfer.types.includes(`Files`)&&r(!0)}function _(e){e.preventDefault(),--i.current,i.current===0&&r(!1)}function v(e){e.preventDefault()}function y(e){e.preventDefault(),i.current=0,r(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&o(t)}function b(){p(c)}return(0,f.jsx)(d.CopilotChatInput,{...e,value:c,onChange:l,onSubmitMessage:p,children:({sendButton:e,startTranscribeButton:r,cancelTranscribeButton:i,finishTranscribeButton:u,audioRecorder:d,disclaimer:p,mode:x,positioning:S,keyboardHeight:C,containerRef:w,showDisclaimer:T,onCancelTranscribe:E,onFinishTranscribe:D,onStartTranscribe:O})=>(0,f.jsxs)(`div`,{"data-copilotkit":!0,ref:w,className:[`erica-aware-input-shell`,S===`absolute`?`erica-aware-input-absolute`:``].filter(Boolean).join(` `),style:{transform:C>0?`translateY(-${C}px)`:void 0,transition:`transform 0.2s ease-out`},children:[(0,f.jsxs)(`div`,{className:[`erica-aware-input-card`,n?`erica-aware-input-dragging`:``].filter(Boolean).join(` `),onDragEnter:g,onDragLeave:_,onDragOver:v,onDrop:y,children:[n&&(0,f.jsx)(`div`,{className:`erica-aware-input-drop-overlay`,children:`Drop files to attach`}),a.length>0&&(0,f.jsx)(`div`,{className:`erica-attachment-chip-row`,children:a.map(e=>(0,f.jsxs)(`span`,{className:[`erica-attachment-chip`,`erica-attachment-chip-${e.status}`].join(` `),title:e.errorMessage??e.name,children:[e.status===`uploading`&&(0,f.jsx)(`span`,{className:`erica-attachment-chip-spinner`}),(0,f.jsx)(`span`,{className:`erica-attachment-chip-name`,children:e.name}),e.status!==`uploading`&&(0,f.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,className:`erica-attachment-chip-remove`,onClick:()=>s(e.id),children:`×`})]},e.id))}),t.validationError&&(0,f.jsx)(`div`,{className:`erica-validation-error`,style:{color:`#ef4444`,fontSize:`12px`,padding:`6px 10px`,backgroundColor:`#fee2e2`,borderRadius:`4px`,width:`100%`,boxSizing:`border-box`},children:t.validationError}),(0,f.jsx)(`div`,{className:`erica-aware-input-main`,children:x===`transcribe`?d:(0,f.jsx)(tb,{value:c,onChange:l,onSubmit:b,agentIdentifier:h,placeholder:`Ketik pertanyaan Anda di sini...`})}),(0,f.jsxs)(`div`,{className:`erica-aware-input-toolbar`,children:[(0,f.jsx)(nb,{hasAttachments:a.length>0,disabled:!m,onFilesSelected:o}),(0,f.jsx)(`div`,{className:`erica-aware-input-spacer`}),x===`transcribe`?(0,f.jsxs)(f.Fragment,{children:[E&&i,D&&u]}):(0,f.jsxs)(f.Fragment,{children:[O&&r,e]})]})]}),T&&p]})})}var ib=e=>e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/([A-Z])([A-Z][a-z])/g,`$1 $2`).replace(/[_-]/g,` `).toLowerCase().trim().replace(/\s+/g,` `);function ab(){let e=(0,u.useContext)(tn),t=`digesting`;return e?.step&&(t=e.step===`ls`?`listing files`:ib(e.step)),(0,f.jsxs)(`div`,{className:`chat-message-spinner-container`,children:[(0,f.jsx)(`div`,{className:`chat-message-spinner-icon`}),(0,f.jsxs)(`div`,{className:`chat-message-spinner-text`,children:[t,(0,f.jsxs)(`span`,{className:`chat-message-spinner-dots`,children:[(0,f.jsx)(`span`,{className:`chat-message-spinner-dot chat-message-spinner-dot--1`,children:`.`}),(0,f.jsx)(`span`,{className:`chat-message-spinner-dot chat-message-spinner-dot--2`,children:`.`}),(0,f.jsx)(`span`,{className:`chat-message-spinner-dot chat-message-spinner-dot--3`,children:`.`})]})]})]})}function ob({message:e}){return(0,f.jsxs)(`div`,{className:`loading-message-container`,children:[(0,f.jsx)(`div`,{className:`loading-message-spinner`}),(0,f.jsxs)(`div`,{className:`loading-message-text`,children:[e,(0,f.jsxs)(`span`,{className:`loading-message-dots`,children:[(0,f.jsx)(`span`,{className:`loading-message-dot loading-message-dot--1`,children:`.`}),(0,f.jsx)(`span`,{className:`loading-message-dot loading-message-dot--2`,children:`.`}),(0,f.jsx)(`span`,{className:`loading-message-dot loading-message-dot--3`,children:`.`})]})]})]})}function sb(e){if(!e)return``;let t=e.split(`:`);return(t.length>1?t.slice(1).join(` `):e).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function cb(e){if(!e)return``;let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return n<1?`just now`:n<60?`${n}m ago`:r<24?`${r}h ago`:i<7?`${i}d ago`:new Date(e).toLocaleDateString()}function lb({onNewChat:e,onThreadSelect:t,isMaximized:n=!1,onToggleMaximize:r}){let[i,a]=(0,u.useState)(!1),o=(0,u.useRef)(null),s=(0,d.useCopilotChatConfiguration)(),{data:c=[],isLoading:l}=Jt();(0,u.useEffect)(()=>{function e(e){o.current&&!o.current.contains(e.target)&&a(!1)}if(i)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[i]);function p(e){a(!1),t?.(e)}return(0,f.jsxs)(`div`,{className:`erica-header`,children:[(0,f.jsxs)(`h2`,{className:`erica-header-title`,children:[`SPP AI `,(0,f.jsxs)(`span`,{className:`erica-header-version`,children:[`v`,`1.2.6`]})]}),(0,f.jsxs)(`div`,{className:`erica-header-controls`,ref:o,children:[(0,f.jsx)(`button`,{onClick:e,className:`erica-new-chat-button`,title:`Start new chat`,children:(0,f.jsx)(Hy,{className:`erica-icon-sm`})}),(0,f.jsxs)(`button`,{onClick:()=>a(!i),className:`erica-threads-toggle`,title:`Recent threads`,children:[(0,f.jsxs)(`span`,{className:`erica-threads-toggle-text`,children:[`Riwayat `,c.length>0&&`(${c.length})`]}),(0,f.jsx)(Ry,{className:`erica-threads-toggle-icon ${i?`erica-threads-toggle-icon--open`:``}`})]}),r&&(0,f.jsx)(`button`,{onClick:e=>{e.stopPropagation(),e.preventDefault(),r()},className:`erica-maximize-button`,title:n?`Restore chat`:`Maximize chat`,children:n?(0,f.jsx)(Vy,{className:`erica-icon-sm`}):(0,f.jsx)(By,{className:`erica-icon-sm`})}),s?.setModalOpen&&(0,f.jsx)(`button`,{onClick:()=>s.setModalOpen(!1),className:`erica-close-button`,title:`Close sidebar`,children:(0,f.jsx)(Uy,{className:`erica-icon-sm`})}),i&&(0,f.jsx)(`div`,{className:`erica-threads-dropdown`,children:(0,f.jsxs)(`div`,{className:`erica-threads-dropdown-content`,children:[(0,f.jsx)(`div`,{className:`erica-threads-dropdown-header`,children:`Riwayat Terakhir`}),l&&(0,f.jsx)(`div`,{className:`erica-threads-empty`,children:`Loading threads...`}),!l&&c.length===0&&(0,f.jsx)(`div`,{className:`erica-threads-empty`,children:`No conversations yet`}),!l&&c.map(e=>{let t=sb(e.agent),n=cb(e.last_run_at??e.created_at);return(0,f.jsx)(`button`,{onClick:()=>p(e.uid??``),className:`erica-thread-item`,children:(0,f.jsxs)(`div`,{className:`erica-thread-item-content`,children:[(0,f.jsx)(`span`,{className:`erica-thread-title`,children:typeof e.thread_metadata?.title==`string`?e.thread_metadata.title:e.last_message??`New conversation`}),(0,f.jsxs)(`div`,{className:`erica-thread-meta`,children:[t&&(0,f.jsx)(`span`,{className:`erica-thread-agent`,children:t}),n&&(0,f.jsx)(`span`,{className:`erica-thread-time`,children:n})]})]})},e.uid)})]})})]})]})}function ub({attachment:e}){let[t,n]=(0,u.useState)(!1);async function r(){n(!0);try{await Qt.download(e.file_path,e.original_name)}finally{n(!1)}}return(0,f.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())},title:e.original_name,className:`attachment-item`,children:[t?(0,f.jsx)(`div`,{className:`attachment-item-spinner`}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`svg`,{className:`attachment-item-icon`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13`})}),(0,f.jsx)(`svg`,{className:`attachment-item-icon-download`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})]}),(0,f.jsx)(`span`,{className:`attachment-item-text`,children:e.original_name})]})}function db({children:e}){let t=String(e).trim(),n=[];try{n=JSON.parse(t)}catch{return null}return n.length===0?null:(0,f.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1.5 py-1`,children:n.map((e,t)=>(0,f.jsx)(ub,{attachment:e},t))})}function fb({message:e=`Hai! Saya SPP AI, siap membantu Anda!`,isOpen:t=!1,initialDelay:n=1e4}){let[r,i]=(0,u.useState)(!1),[a,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{let e=setTimeout(()=>{i(!0)},n);return()=>clearTimeout(e)},[n]),!r||t||a?null:(0,f.jsx)(`div`,{className:`chat-toggle-greeting-wrapper`,children:(0,f.jsxs)(`div`,{className:`chat-toggle-greeting-bubble`,children:[e,(0,f.jsx)(`button`,{onClick:()=>{i(!1),o(!0)},className:`chat-toggle-greeting-close`,"aria-label":`Dismiss greeting`,children:(0,f.jsx)(Uy,{})})]})})}function pb(e){ch(e,[/\r?\n|\r/g,mb])}function mb(){return{type:`break`}}function hb(){return function(e){pb(e)}}var gb=u.default.createContext(null);function _b(){let e=u.default.useContext(gb);return e?(0,f.jsx)(lb,{onNewChat:e.onNewChat,onThreadSelect:e.onThreadSelect,isMaximized:e.isMaximized,onToggleMaximize:e.toggleMaximize}):null}var vb=()=>e=>{let t=e=>{[`containerDirective`,`leafDirective`,`textDirective`].includes(e.type)&&e.name===`tool_call_content`&&(e.data=e.data||{},e.data.hName=e.name,e.data.hProperties=e.attributes||{},e.children=[]),e.children&&e.children.forEach(t)};t(e)},yb=()=>e=>{let t=e=>{e.type===`textDirective`&&e.name===`resource`&&(e.data=e.data||{},e.data.hName=`resource`,e.data.hProperties=e.attributes||{}),e.children&&e.children.forEach(t)};t(e)};function bb({threadId:e,isLoadingThreadId:t,isLoadingSandbox:n,isSandboxReady:r,isNewThread:i,requiresSandbox:a,isModalOpen:o}){let s=`Halo! Saya asisten AI SPP, ada yang bisa saya bantu?`;return t?s=(0,f.jsx)(ob,{message:`Initializing conversation`}):a&&i&&n?s=(0,f.jsx)(ob,{message:`Preparing workspace`}):a&&i&&!r&&(s=(0,f.jsx)(ob,{message:`Setting up environment`})),(0,f.jsxs)(`div`,{className:`erica-chat-container${u.default.useContext(gb)?.isMaximized?` erica-chat-maximized`:``}`,children:[(0,f.jsx)(qy,{}),(0,f.jsx)(fb,{message:`Hai! Saya SPP AI, siap membantu Anda!`,isOpen:o,initialDelay:1e4}),(0,f.jsx)(d.CopilotSidebar,{welcomeScreen:!0,header:_b,labels:{chatInputPlaceholder:`Ketik pertanyaan Anda di sini...`,welcomeMessageText:s,chatDisclaimerText:`AI dapat membuat kesalahan. Harap verifikasi informasi penting.`},threadId:e,input:rb,messageView:{cursor:ab,userMessage:{messageRenderer:({content:e,className:t})=>(0,f.jsx)(`div`,{className:[`cpk:prose cpk:dark:prose-invert cpk:bg-smi cpk:relative cpk:max-w-[80%] cpk:rounded-[18px] cpk:px-4 cpk:py-1.5 cpk:data-[multiline]:py-3 cpk:inline-block`,t].filter(Boolean).join(` `),children:(0,f.jsx)(th,{remarkPlugins:[hb,av,by,yb],components:{pre:({children:e})=>(0,f.jsx)(f.Fragment,{children:e}),code({children:e,className:t}){return/language-(\w+)/.exec(t||``)?.[1]===`attachments`?(0,f.jsx)(db,{children:e}):(0,f.jsx)(`code`,{className:t,style:{fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:`0.85em`},children:e})},resource:({children:e})=>(0,f.jsxs)(`span`,{className:`erica-resource-tag`,children:[`@`,e]}),table:({children:e})=>(0,f.jsx)(`div`,{className:`markdown-table-wrapper`,children:(0,f.jsx)(`table`,{children:e})})},children:e})})},assistantMessage:{className:`prose lg:prose-xl`,toolbarVisible:!1,markdownRenderer:({content:e})=>!e||e.trim()===``?(0,f.jsx)(f.Fragment,{}):(0,f.jsx)(th,{remarkPlugins:[hb,av,by,vb],components:{tool_call_content:({children:e,...t})=>(0,f.jsx)(`div`,{className:`tool-call-content`,...t,children:e}),table:({children:e})=>(0,f.jsx)(`div`,{className:`markdown-table-wrapper`,children:(0,f.jsx)(`table`,{children:e})})},children:e})}},defaultOpen:o})]})}function xb({runtimeUrl:e,widgetToken:t,requiresSandbox:n=!1}){let[r,i]=(0,u.useState)(void 0),[a,o]=(0,u.useState)(!0),[s,c]=(0,u.useState)(!1),[l,p]=(0,u.useState)(0),[m,h]=(0,u.useState)(!0),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(!1);console.log(`EricaChat Render:`,{threadId:r,shouldFetchNewId:a,isModalOpen:g,isMaximized:v});let b=(0,u.useMemo)(()=>{let t=new URL(e),n=t.pathname.split(`/`).filter(Boolean);return n.length>2&&n.pop(),t.pathname=`/`+n.join(`/`),t.toString()},[e]);(0,u.useMemo)(()=>{he(b,t)},[b,t]);let{data:x,isLoading:S}=Yt(a,l),{isLoading:C,isSuccess:w}=Xt(r||``,s);(0,u.useEffect)(()=>{w&&m&&g&&_(!0)},[w,m,g]),(0,u.useEffect)(()=>{x&&(i(x),o(!1),c(n),h(!0))},[x,n]),(0,u.useEffect)(()=>()=>{r&&m&&Kt.deleteSandbox(r).catch(()=>{})},[r,m]);let T=(0,u.useCallback)(()=>{i(void 0),o(!0),c(!1),p(e=>e+1),h(!0),_(!0)},[]),E=(0,u.useCallback)(e=>{i(e),o(!1),c(!1),h(!1),_(!0)},[]),D=(0,u.useCallback)(()=>{_(!0),y(e=>!e)},[]),O=(0,u.useMemo)(()=>({isMaximized:v,toggleMaximize:D,onNewChat:T,onThreadSelect:E}),[v,D,T,E]);return(0,f.jsx)(gb.Provider,{value:O,children:(0,f.jsx)(d.CopilotChatConfigurationProvider,{children:(0,f.jsx)(d.CopilotKit,{runtimeUrl:e,headers:{Authorization:`Bearer ${t}`},properties:{agent:Zt},threadId:r,enableInspector:!1,children:(0,f.jsx)(rn,{threadId:r,agentIdentifier:Zt,children:(0,f.jsx)(bb,{threadId:r,isLoadingThreadId:S,isLoadingSandbox:C,isSandboxReady:w,isNewThread:m,requiresSandbox:n,isModalOpen:g})})})})})}var Sb=(0,u.createContext)(void 0);function Cb({accountUid:e,children:t}){return(0,f.jsx)(Sb.Provider,{value:{accountUid:e},children:t})}var wb=new bt({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1,staleTime:3e4}}});function Tb({accountUid:e,children:t}){return(0,f.jsx)(Ct,{client:wb,children:(0,f.jsx)(Cb,{accountUid:e,children:(0,f.jsx)(Oc,{children:t})})})}function Eb(){let{isOpen:e,onClose:t,content:n,title:r}=kc(),[i,a]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{e?setTimeout(()=>a(!0),10):a(!1)},[e]),e?(0,f.jsxs)(`div`,{className:`erica-artifact-container`,children:[(0,f.jsx)(`div`,{className:`erica-artifact-backdrop ${i?`erica-artifact-backdrop--visible`:``}`,onClick:t}),(0,f.jsxs)(`div`,{className:`erica-artifact-drawer ${i?`erica-artifact-drawer--open`:``}`,children:[(0,f.jsxs)(`div`,{className:`erica-artifact-header`,children:[(0,f.jsx)(`h2`,{className:`erica-artifact-title`,children:r}),(0,f.jsx)(`button`,{onClick:t,className:`erica-artifact-close-button`,"aria-label":`Close drawer`,children:(0,f.jsx)(Uy,{className:`erica-icon-md`})})]}),(0,f.jsx)(`div`,{className:`erica-artifact-body`,children:n})]})]}):null}exports.ArtifactProvider=Oc,exports.EricaChat=xb,exports.EricaDrawer=Eb,exports.EricaProvider=Tb;
77
+ `:Array.from(e.childNodes).map(Zy).join(``):Array.from(e.childNodes).map(Zy).join(``)}function Qy(e){return Array.from(e.childNodes).map(Zy).join(``)}function $y(){let e=window.getSelection();if(!e||e.rangeCount===0)return null;let t=e.getRangeAt(0);if(!t.collapsed||t.startContainer.nodeType!==Node.TEXT_NODE)return null;let n=t.startContainer,r=n.data.slice(0,t.startOffset),i=/(?:^|\s)@([^@\s]*)$/.exec(r);return i?{node:n,start:r.length-i[1].length-1,end:t.startOffset,query:i[1]}:null}function eb(e,t){let n=document.createRange();n.setStart(e,Math.min(t,e.data.length)),n.collapse(!0);let r=window.getSelection();r?.removeAllRanges(),r?.addRange(n)}function tb({value:e,onChange:t,onSubmit:n,agentIdentifier:r,placeholder:i=`Ketik pertanyaan Anda di sini...`}){let a=(0,u.useRef)(null),o=(0,u.useRef)(null),s=(0,u.useRef)(null),c=(0,u.useRef)(null),l=(0,u.useRef)(null),d=(0,u.useRef)(null),p=(0,u.useRef)(0),h=(0,u.useRef)(n),g=(0,u.useRef)(t),_=(0,u.useRef)(r),[v,y]=(0,u.useState)(!0);(0,u.useEffect)(()=>{h.current=n},[n]),(0,u.useEffect)(()=>{g.current=t},[t]),(0,u.useEffect)(()=>{_.current=r},[r]),(0,u.useEffect)(()=>{e===``&&a.current&&a.current.textContent&&(a.current.innerHTML=``,y(!0))},[e]),(0,u.useEffect)(()=>()=>b(),[]);function b(){d.current&&=(clearTimeout(d.current),null),s.current?.unmount(),s.current=null,o.current?.remove(),o.current=null,l.current=null}function x(){let e=a.current;if(!e)return;let t=Qy(e);y(t.trim().length===0),g.current(t)}function S(e,t){let n=l.current;if(!n)return;o.current||(o.current=document.createElement(`div`),o.current.className=`erica-mention-popup`,o.current.setAttribute(`data-mention-suggestion`,``),document.body.appendChild(o.current),s.current=(0,m.createRoot)(o.current)),s.current.render((0,f.jsx)(Xy,{ref:c,items:e,isLoading:t,command:T}));let r=document.createRange();r.setStart(n.node,n.start),r.setEnd(n.node,n.end);let i=r.getBoundingClientRect();o.current.style.left=`${i.left}px`,o.current.style.bottom=`${window.innerHeight-i.top+6}px`}function C(e){let t=++p.current;S([],!0),d.current&&clearTimeout(d.current),d.current=setTimeout(async()=>{d.current=null;try{let n=await Jy.search(e.query,_.current);if(t!==p.current)return;S(n.filter(e=>[`dataset`,`document`,`template`].includes(e.type)).map(e=>({id:`${e.type}:${e.uid}`,label:e.name,description:e.type})),!1)}catch{if(t!==p.current)return;S([],!1)}},300)}function w(){let e=$y();if(l.current=e,!e){b();return}C(e)}function T(e){let t=l.current;if(!t)return;let[n,r]=e.id.split(`:`),i=t.node,a=i.data.slice(0,t.start),o=i.data.slice(t.end),s=i.parentNode;if(!s)return;let c=document.createElement(`span`);c.className=`erica-resource-tag erica-editor-resource-tag`,c.contentEditable=`false`,c.dataset.resourceType=n,c.dataset.resourceUid=r,c.dataset.resourceLabel=e.label,c.textContent=`@${e.label}`;let u=document.createTextNode(a),d=document.createTextNode(` ${o}`);s.insertBefore(u,i),s.insertBefore(c,i),s.insertBefore(d,i),s.removeChild(i),b(),eb(d,1),x()}return(0,f.jsxs)(`div`,{className:`erica-editor-wrap`,children:[v&&(0,f.jsx)(`div`,{className:`erica-editor-placeholder`,children:i}),(0,f.jsx)(`div`,{ref:a,className:`erica-chat-editor`,contentEditable:!0,role:`textbox`,"aria-multiline":`true`,"data-testid":`chat-editor`,onInput:()=>{x(),w()},onKeyDown:e=>{if(o.current){if(e.key===`Escape`){e.preventDefault(),b();return}if(c.current?.onKeyDown(e.nativeEvent)){e.preventDefault();return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),h.current())},onKeyUp:w,onBlur:()=>{window.setTimeout(()=>{document.querySelector(`[data-mention-suggestion]:hover`)||b()},150)}})]})}function nb({hasAttachments:e,disabled:t,onFilesSelected:n}){let r=(0,u.useRef)(null);function i(e){let t=Array.from(e.target.files??[]);t.length>0&&n(t),e.target.value=``}return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`input`,{ref:r,type:`file`,multiple:!0,className:`erica-attachment-input`,onChange:i,disabled:t}),(0,f.jsx)(`button`,{type:`button`,"aria-label":`Attach files`,className:[`erica-attachment-button`,e?`erica-attachment-button-active`:``].filter(Boolean).join(` `),disabled:t,onClick:()=>r.current?.click(),children:(0,f.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,f.jsx)(`path`,{d:`M21.44 11.05 12.25 20.24a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48`})})})]})}function rb({suggestions:e,onSelect:t}){return!e||e.length===0?null:(0,f.jsx)(`div`,{className:`erica-prompt-suggestions`,style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,padding:`8px 4px`,marginBottom:`8px`,pointerEvents:`auto`},children:e.map((e,n)=>(0,f.jsx)(`button`,{type:`button`,className:`erica-prompt-suggestion-pill`,onClick:()=>t(e),style:{backgroundColor:`#f3f4f6`,color:`#1f2937`,border:`1px solid #e5e7eb`,borderRadius:`16px`,padding:`6px 12px`,fontSize:`13px`,cursor:`pointer`,textAlign:`left`,transition:`background-color 0.2s ease, border-color 0.2s ease`},children:e},n))})}var ib=[`Saya akan melakukan pengadaan 500 unit laptop dengan nilai anggaran sekitar Rp7 miliar. Metode pemilihan penyedia apa yang paling tepat dan mengapa?`,`Analisa laporan keuangan vendor NUSANTARA TIGA TEKNOLOGI dan buatkan laporannya`,`Bantu analisa data vendor SINAR KERTA NEGARA yg belum terverifikasi, berikan rekomendasi action yg perlu di lakukan`,`Berikan 10 data vendor yg belum submit laporan keuangan 2025`,`Apakah BLUEHOUSE CAPITAL LTD terdaftar di dalam blacklist worldbank?`];function ab(e){let t=(0,u.useContext)(tn),[n,r]=(0,u.useState)(!1),i=(0,u.useRef)(0),{agent:a}=(0,d.useAgent)(),o=a?.messages||[];if(!t)return(0,f.jsx)(d.CopilotChatInput,{...e});let{attachedFiles:s,addFiles:c,removeFile:l,inputValue:p,setInputValue:m,handleSubmit:h,threadId:g}=t,_=Zt;function v(e){e.preventDefault(),i.current+=1,e.dataTransfer.types.includes(`Files`)&&r(!0)}function y(e){e.preventDefault(),--i.current,i.current===0&&r(!1)}function b(e){e.preventDefault()}function x(e){e.preventDefault(),i.current=0,r(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&c(t)}function S(){h(p)}return(0,f.jsx)(d.CopilotChatInput,{...e,value:p,onChange:m,onSubmitMessage:h,children:({sendButton:e,startTranscribeButton:r,cancelTranscribeButton:i,finishTranscribeButton:a,audioRecorder:u,disclaimer:d,mode:C,positioning:w,keyboardHeight:T,containerRef:E,showDisclaimer:D,onCancelTranscribe:O,onFinishTranscribe:ee,onStartTranscribe:te})=>(0,f.jsxs)(`div`,{"data-copilotkit":!0,ref:E,className:[`erica-aware-input-shell`,w===`absolute`?`erica-aware-input-absolute`:``].filter(Boolean).join(` `),style:{transform:T>0?`translateY(-${T}px)`:void 0,transition:`transform 0.2s ease-out`},children:[o.length===0&&(0,f.jsx)(rb,{suggestions:ib,onSelect:e=>{console.log(`[PromptSuggestions] clicked suggestion:`,e),h(e)}}),(0,f.jsxs)(`div`,{className:[`erica-aware-input-card`,n?`erica-aware-input-dragging`:``].filter(Boolean).join(` `),onDragEnter:v,onDragLeave:y,onDragOver:b,onDrop:x,children:[n&&(0,f.jsx)(`div`,{className:`erica-aware-input-drop-overlay`,children:`Drop files to attach`}),s.length>0&&(0,f.jsx)(`div`,{className:`erica-attachment-chip-row`,children:s.map(e=>(0,f.jsxs)(`span`,{className:[`erica-attachment-chip`,`erica-attachment-chip-${e.status}`].join(` `),title:e.errorMessage??e.name,children:[e.status===`uploading`&&(0,f.jsx)(`span`,{className:`erica-attachment-chip-spinner`}),(0,f.jsx)(`span`,{className:`erica-attachment-chip-name`,children:e.name}),e.status!==`uploading`&&(0,f.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,className:`erica-attachment-chip-remove`,onClick:()=>l(e.id),children:`×`})]},e.id))}),t.validationError&&(0,f.jsx)(`div`,{className:`erica-validation-error`,style:{color:`#ef4444`,fontSize:`12px`,padding:`6px 10px`,backgroundColor:`#fee2e2`,borderRadius:`4px`,width:`100%`,boxSizing:`border-box`},children:t.validationError}),(0,f.jsx)(`div`,{className:`erica-aware-input-main`,children:C===`transcribe`?u:(0,f.jsx)(tb,{value:p,onChange:m,onSubmit:S,agentIdentifier:_,placeholder:`Ketik pertanyaan Anda di sini...`})}),(0,f.jsxs)(`div`,{className:`erica-aware-input-toolbar`,children:[(0,f.jsx)(nb,{hasAttachments:s.length>0,disabled:!g,onFilesSelected:c}),(0,f.jsx)(`div`,{className:`erica-aware-input-spacer`}),C===`transcribe`?(0,f.jsxs)(f.Fragment,{children:[O&&i,ee&&a]}):(0,f.jsxs)(f.Fragment,{children:[te&&r,e]})]})]}),D&&d]})})}var ob=e=>e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/([A-Z])([A-Z][a-z])/g,`$1 $2`).replace(/[_-]/g,` `).toLowerCase().trim().replace(/\s+/g,` `);function sb(){let e=(0,u.useContext)(tn),t=`digesting`;return e?.step&&(t=e.step===`ls`?`listing files`:ob(e.step)),(0,f.jsxs)(`div`,{className:`chat-message-spinner-container`,children:[(0,f.jsx)(`div`,{className:`chat-message-spinner-icon`}),(0,f.jsxs)(`div`,{className:`chat-message-spinner-text`,children:[t,(0,f.jsxs)(`span`,{className:`chat-message-spinner-dots`,children:[(0,f.jsx)(`span`,{className:`chat-message-spinner-dot chat-message-spinner-dot--1`,children:`.`}),(0,f.jsx)(`span`,{className:`chat-message-spinner-dot chat-message-spinner-dot--2`,children:`.`}),(0,f.jsx)(`span`,{className:`chat-message-spinner-dot chat-message-spinner-dot--3`,children:`.`})]})]})]})}function cb({message:e}){return(0,f.jsxs)(`div`,{className:`loading-message-container`,children:[(0,f.jsx)(`div`,{className:`loading-message-spinner`}),(0,f.jsxs)(`div`,{className:`loading-message-text`,children:[e,(0,f.jsxs)(`span`,{className:`loading-message-dots`,children:[(0,f.jsx)(`span`,{className:`loading-message-dot loading-message-dot--1`,children:`.`}),(0,f.jsx)(`span`,{className:`loading-message-dot loading-message-dot--2`,children:`.`}),(0,f.jsx)(`span`,{className:`loading-message-dot loading-message-dot--3`,children:`.`})]})]})]})}function lb(e){if(!e)return``;let t=e.split(`:`);return(t.length>1?t.slice(1).join(` `):e).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function ub(e){if(!e)return``;let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return n<1?`just now`:n<60?`${n}m ago`:r<24?`${r}h ago`:i<7?`${i}d ago`:new Date(e).toLocaleDateString()}function db({onNewChat:e,onThreadSelect:t,isMaximized:n=!1,onToggleMaximize:r}){let[i,a]=(0,u.useState)(!1),o=(0,u.useRef)(null),s=(0,d.useCopilotChatConfiguration)(),{data:c=[],isLoading:l}=Jt();(0,u.useEffect)(()=>{function e(e){o.current&&!o.current.contains(e.target)&&a(!1)}if(i)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[i]);function p(e){a(!1),t?.(e)}return(0,f.jsxs)(`div`,{className:`erica-header`,children:[(0,f.jsxs)(`h2`,{className:`erica-header-title`,children:[`SPP AI `,(0,f.jsxs)(`span`,{className:`erica-header-version`,children:[`v`,`1.2.7`]})]}),(0,f.jsxs)(`div`,{className:`erica-header-controls`,ref:o,children:[(0,f.jsx)(`button`,{onClick:e,className:`erica-new-chat-button`,title:`Start new chat`,children:(0,f.jsx)(Hy,{className:`erica-icon-sm`})}),(0,f.jsxs)(`button`,{onClick:()=>a(!i),className:`erica-threads-toggle`,title:`Recent threads`,children:[(0,f.jsxs)(`span`,{className:`erica-threads-toggle-text`,children:[`Riwayat `,c.length>0&&`(${c.length})`]}),(0,f.jsx)(Ry,{className:`erica-threads-toggle-icon ${i?`erica-threads-toggle-icon--open`:``}`})]}),r&&(0,f.jsx)(`button`,{onClick:e=>{e.stopPropagation(),e.preventDefault(),r()},className:`erica-maximize-button`,title:n?`Restore chat`:`Maximize chat`,children:n?(0,f.jsx)(Vy,{className:`erica-icon-sm`}):(0,f.jsx)(By,{className:`erica-icon-sm`})}),s?.setModalOpen&&(0,f.jsx)(`button`,{onClick:()=>s.setModalOpen(!1),className:`erica-close-button`,title:`Close sidebar`,children:(0,f.jsx)(Uy,{className:`erica-icon-sm`})}),i&&(0,f.jsx)(`div`,{className:`erica-threads-dropdown`,children:(0,f.jsxs)(`div`,{className:`erica-threads-dropdown-content`,children:[(0,f.jsx)(`div`,{className:`erica-threads-dropdown-header`,children:`Riwayat Terakhir`}),l&&(0,f.jsx)(`div`,{className:`erica-threads-empty`,children:`Loading threads...`}),!l&&c.length===0&&(0,f.jsx)(`div`,{className:`erica-threads-empty`,children:`No conversations yet`}),!l&&c.map(e=>{let t=lb(e.agent),n=ub(e.last_run_at??e.created_at);return(0,f.jsx)(`button`,{onClick:()=>p(e.uid??``),className:`erica-thread-item`,children:(0,f.jsxs)(`div`,{className:`erica-thread-item-content`,children:[(0,f.jsx)(`span`,{className:`erica-thread-title`,children:typeof e.thread_metadata?.title==`string`?e.thread_metadata.title:e.last_message??`New conversation`}),(0,f.jsxs)(`div`,{className:`erica-thread-meta`,children:[t&&(0,f.jsx)(`span`,{className:`erica-thread-agent`,children:t}),n&&(0,f.jsx)(`span`,{className:`erica-thread-time`,children:n})]})]})},e.uid)})]})})]})]})}function fb({attachment:e}){let[t,n]=(0,u.useState)(!1);async function r(){n(!0);try{await Qt.download(e.file_path,e.original_name)}finally{n(!1)}}return(0,f.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())},title:e.original_name,className:`attachment-item`,children:[t?(0,f.jsx)(`div`,{className:`attachment-item-spinner`}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`svg`,{className:`attachment-item-icon`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13`})}),(0,f.jsx)(`svg`,{className:`attachment-item-icon-download`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})]}),(0,f.jsx)(`span`,{className:`attachment-item-text`,children:e.original_name})]})}function pb({children:e}){let t=String(e).trim(),n=[];try{n=JSON.parse(t)}catch{return null}return n.length===0?null:(0,f.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1.5 py-1`,children:n.map((e,t)=>(0,f.jsx)(fb,{attachment:e},t))})}function mb({message:e=`Hai! Saya SPP AI, siap membantu Anda!`,isOpen:t=!1,initialDelay:n=1e4}){let[r,i]=(0,u.useState)(!1),[a,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{let e=setTimeout(()=>{i(!0)},n);return()=>clearTimeout(e)},[n]),!r||t||a?null:(0,f.jsx)(`div`,{className:`chat-toggle-greeting-wrapper`,children:(0,f.jsxs)(`div`,{className:`chat-toggle-greeting-bubble`,children:[e,(0,f.jsx)(`button`,{onClick:()=>{i(!1),o(!0)},className:`chat-toggle-greeting-close`,"aria-label":`Dismiss greeting`,children:(0,f.jsx)(Uy,{})})]})})}function hb(e){ch(e,[/\r?\n|\r/g,gb])}function gb(){return{type:`break`}}function _b(){return function(e){hb(e)}}var vb=u.default.createContext(null);function yb(){let e=u.default.useContext(vb);return e?(0,f.jsx)(db,{onNewChat:e.onNewChat,onThreadSelect:e.onThreadSelect,isMaximized:e.isMaximized,onToggleMaximize:e.toggleMaximize}):null}var bb=()=>e=>{let t=e=>{[`containerDirective`,`leafDirective`,`textDirective`].includes(e.type)&&e.name===`tool_call_content`&&(e.data=e.data||{},e.data.hName=e.name,e.data.hProperties=e.attributes||{},e.children=[]),e.children&&e.children.forEach(t)};t(e)},xb=()=>e=>{let t=e=>{e.type===`textDirective`&&e.name===`resource`&&(e.data=e.data||{},e.data.hName=`resource`,e.data.hProperties=e.attributes||{}),e.children&&e.children.forEach(t)};t(e)};function Sb({threadId:e,isLoadingThreadId:t,isLoadingSandbox:n,isSandboxReady:r,isNewThread:i,requiresSandbox:a,isModalOpen:o}){let s=`Halo! Saya asisten AI SPP, ada yang bisa saya bantu?`;return t?s=(0,f.jsx)(cb,{message:`Initializing conversation`}):a&&i&&n?s=(0,f.jsx)(cb,{message:`Preparing workspace`}):a&&i&&!r&&(s=(0,f.jsx)(cb,{message:`Setting up environment`})),(0,f.jsxs)(`div`,{className:`erica-chat-container${u.default.useContext(vb)?.isMaximized?` erica-chat-maximized`:``}`,children:[(0,f.jsx)(qy,{}),(0,f.jsx)(mb,{message:`Hai! Saya SPP AI, siap membantu Anda!`,isOpen:o,initialDelay:1e4}),(0,f.jsx)(d.CopilotSidebar,{welcomeScreen:!0,header:yb,labels:{chatInputPlaceholder:`Ketik pertanyaan Anda di sini...`,welcomeMessageText:s,chatDisclaimerText:`AI dapat membuat kesalahan. Harap verifikasi informasi penting.`},threadId:e,input:ab,messageView:{cursor:sb,userMessage:{messageRenderer:({content:e,className:t})=>(0,f.jsx)(`div`,{className:[`cpk:prose cpk:dark:prose-invert cpk:bg-smi cpk:relative cpk:max-w-[80%] cpk:rounded-[18px] cpk:px-4 cpk:py-1.5 cpk:data-[multiline]:py-3 cpk:inline-block`,t].filter(Boolean).join(` `),children:(0,f.jsx)(th,{remarkPlugins:[_b,av,by,xb],components:{pre:({children:e})=>(0,f.jsx)(f.Fragment,{children:e}),code({children:e,className:t}){return/language-(\w+)/.exec(t||``)?.[1]===`attachments`?(0,f.jsx)(pb,{children:e}):(0,f.jsx)(`code`,{className:t,style:{fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:`0.85em`},children:e})},resource:({children:e})=>(0,f.jsxs)(`span`,{className:`erica-resource-tag`,children:[`@`,e]}),table:({children:e})=>(0,f.jsx)(`div`,{className:`markdown-table-wrapper`,children:(0,f.jsx)(`table`,{children:e})})},children:e})})},assistantMessage:{className:`prose lg:prose-xl`,toolbarVisible:!1,markdownRenderer:({content:e})=>!e||e.trim()===``?(0,f.jsx)(f.Fragment,{}):(0,f.jsx)(th,{remarkPlugins:[_b,av,by,bb],components:{tool_call_content:({children:e,...t})=>(0,f.jsx)(`div`,{className:`tool-call-content`,...t,children:e}),table:({children:e})=>(0,f.jsx)(`div`,{className:`markdown-table-wrapper`,children:(0,f.jsx)(`table`,{children:e})})},children:e})}},defaultOpen:o})]})}function Cb({runtimeUrl:e,widgetToken:t,requiresSandbox:n=!1}){let[r,i]=(0,u.useState)(void 0),[a,o]=(0,u.useState)(!0),[s,c]=(0,u.useState)(!1),[l,p]=(0,u.useState)(0),[m,h]=(0,u.useState)(!0),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(!1);console.log(`EricaChat Render:`,{threadId:r,shouldFetchNewId:a,isModalOpen:g,isMaximized:v});let b=(0,u.useMemo)(()=>{let t=new URL(e),n=t.pathname.split(`/`).filter(Boolean);return n.length>2&&n.pop(),t.pathname=`/`+n.join(`/`),t.toString()},[e]);(0,u.useMemo)(()=>{he(b,t)},[b,t]);let{data:x,isLoading:S}=Yt(a,l),{isLoading:C,isSuccess:w}=Xt(r||``,s);(0,u.useEffect)(()=>{w&&m&&g&&_(!0)},[w,m,g]),(0,u.useEffect)(()=>{x&&(i(x),o(!1),c(n),h(!0))},[x,n]),(0,u.useEffect)(()=>()=>{r&&m&&Kt.deleteSandbox(r).catch(()=>{})},[r,m]);let T=(0,u.useCallback)(()=>{i(void 0),o(!0),c(!1),p(e=>e+1),h(!0),_(!0)},[]),E=(0,u.useCallback)(e=>{i(e),o(!1),c(!1),h(!1),_(!0)},[]),D=(0,u.useCallback)(()=>{_(!0),y(e=>!e)},[]),O=(0,u.useMemo)(()=>({isMaximized:v,toggleMaximize:D,onNewChat:T,onThreadSelect:E}),[v,D,T,E]);return(0,f.jsx)(vb.Provider,{value:O,children:(0,f.jsx)(d.CopilotChatConfigurationProvider,{children:(0,f.jsx)(d.CopilotKit,{runtimeUrl:e,headers:{Authorization:`Bearer ${t}`},properties:{agent:Zt},threadId:r,enableInspector:!1,children:(0,f.jsx)(rn,{threadId:r,agentIdentifier:Zt,children:(0,f.jsx)(Sb,{threadId:r,isLoadingThreadId:S,isLoadingSandbox:C,isSandboxReady:w,isNewThread:m,requiresSandbox:n,isModalOpen:g})})})})})}var wb=(0,u.createContext)(void 0);function Tb({accountUid:e,children:t}){return(0,f.jsx)(wb.Provider,{value:{accountUid:e},children:t})}var Eb=new bt({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1,staleTime:3e4}}});function Db({accountUid:e,children:t}){return(0,f.jsx)(Ct,{client:Eb,children:(0,f.jsx)(Tb,{accountUid:e,children:(0,f.jsx)(Oc,{children:t})})})}function Ob(){let{isOpen:e,onClose:t,content:n,title:r}=kc(),[i,a]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{e?setTimeout(()=>a(!0),10):a(!1)},[e]),e?(0,f.jsxs)(`div`,{className:`erica-artifact-container`,children:[(0,f.jsx)(`div`,{className:`erica-artifact-backdrop ${i?`erica-artifact-backdrop--visible`:``}`,onClick:t}),(0,f.jsxs)(`div`,{className:`erica-artifact-drawer ${i?`erica-artifact-drawer--open`:``}`,children:[(0,f.jsxs)(`div`,{className:`erica-artifact-header`,children:[(0,f.jsx)(`h2`,{className:`erica-artifact-title`,children:r}),(0,f.jsx)(`button`,{onClick:t,className:`erica-artifact-close-button`,"aria-label":`Close drawer`,children:(0,f.jsx)(Uy,{className:`erica-icon-md`})})]}),(0,f.jsx)(`div`,{className:`erica-artifact-body`,children:n})]})]}):null}exports.ArtifactProvider=Oc,exports.EricaChat=Cb,exports.EricaDrawer=Ob,exports.EricaProvider=Db;
78
78
  //# sourceMappingURL=index.cjs.map