@lobu/runtime-server 24.8.0 → 24.9.0
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/catalogs/connectors.json +83 -6
- package/dist/catalogs/skills.json +1 -1
- package/dist/component.json +1 -1
- package/dist/connectors/README.md +6 -2
- package/dist/connectors/github.ts +16 -3
- package/dist/connectors/market_quotes.ts +388 -91
- package/dist/connectors/postgres.ts +21 -14
- package/dist/connectors/x-dm-adapter.js +55 -21
- package/dist/connectors/x.ts +1 -1
- package/dist/db/migrations/20261109010000_workspace_navigation.sql +14 -0
- package/dist/db/migrations/20261110010000_view_resources.sql +11 -0
- package/dist/dependencies.bun.lock +61 -61
- package/dist/owletto/dist/assets/_-B2C9B2RM.js +2 -0
- package/dist/owletto/dist/assets/_-CjyiGzwB.js +3 -0
- package/dist/owletto/dist/assets/_agentId-DKHXGvS2.js +2 -0
- package/dist/owletto/dist/assets/_agentId-bna2tPsW.js +2 -0
- package/dist/owletto/dist/assets/_automationId-CowRFD4E.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey._connectionId-dE6im18z.js +2 -0
- package/dist/owletto/dist/assets/{_connectorKey.index-DM5MTO8c.js → _connectorKey.index-DqwSv8Zs.js} +2 -2
- package/dist/owletto/dist/assets/{_conversationId-OJrZjd0o.js → _conversationId-zcs-S3dY.js} +2 -2
- package/dist/owletto/dist/assets/_eventId-BVOVizs4.js +2 -0
- package/dist/owletto/dist/assets/_owner-DsvIC94q.js +3 -0
- package/dist/owletto/dist/assets/_shape-CWjpzcvv.js +2 -0
- package/dist/owletto/dist/assets/_slug-DuCxYsJk.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-BqVeHB6Z.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-DzyOCG5U.js +2 -0
- package/dist/owletto/dist/assets/{accept-invitation-BC-ZIsrf.js → accept-invitation-k1u3zBcn.js} +2 -2
- package/dist/owletto/dist/assets/activity-route-view-jTBMW7a9.js +2 -0
- package/dist/owletto/dist/assets/{agent-connect-pages-CdDjrHjn.js → agent-connect-pages-D3mVM_q4.js} +4 -4
- package/dist/owletto/dist/assets/{agent-editor-form-CDAHRNWl.js → agent-editor-form-Bnc_q5WD.js} +2 -2
- package/dist/owletto/dist/assets/{agent-loading-shells-BupiSjR-.js → agent-loading-shells-xteN-pyK.js} +2 -2
- package/dist/owletto/dist/assets/{agent-permissions-matrix-ju7L2M0l.js → agent-permissions-matrix-C_ayr0pd.js} +2 -2
- package/dist/owletto/dist/assets/{agent-skill-context-B0ZYVE3n.js → agent-skill-context-r0O0BVOu.js} +2 -2
- package/dist/owletto/dist/assets/{agent-subpage-shell-ByU0xhXn.js → agent-subpage-shell-C2KpYdu3.js} +2 -2
- package/dist/owletto/dist/assets/{agent-thread-DiVKn1WX.js → agent-thread-Bv_chdPy.js} +3 -3
- package/dist/owletto/dist/assets/{app._appId-BQWElSoP.js → app._appId-BUcNaSMS.js} +2 -2
- package/dist/owletto/dist/assets/{assist-composer-igTXq3DL.js → assist-composer-B1LykXpD.js} +2 -2
- package/dist/owletto/dist/assets/automation-run-now-CjkJIkaZ.js +2 -0
- package/dist/owletto/dist/assets/{callback-Dmaio9CX.js → callback-kSLa4n5s.js} +2 -2
- package/dist/owletto/dist/assets/{card-rE4Ctuy6.js → card-C01y1O-W.js} +2 -2
- package/dist/owletto/dist/assets/{claim-BN17CPYh.js → claim-Dnux9Lqf.js} +2 -2
- package/dist/owletto/dist/assets/{client-activity-scopes-B7xVaUA-.js → client-activity-scopes-BBIq16tG.js} +2 -2
- package/dist/owletto/dist/assets/{client-rows-B3LULJxW.js → client-rows-DGh1O-Fu.js} +2 -2
- package/dist/owletto/dist/assets/{clients-CydgUHrc.js → clients-BCvjAJDT.js} +2 -2
- package/dist/owletto/dist/assets/{code-editor-UppEMWpt.js → code-editor-BdRMYojw.js} +2 -2
- package/dist/owletto/dist/assets/connect-DZeFSGIH.js +2 -0
- package/dist/owletto/dist/assets/connect-menu-D4w-JhJW.js +2 -0
- package/dist/owletto/dist/assets/connect._clientId-IZEMQJ64.js +2 -0
- package/dist/owletto/dist/assets/{connected._clientId-CaF-ZWlZ.js → connected._clientId-BsDzltNz.js} +2 -2
- package/dist/owletto/dist/assets/{connection-D8ZAMHBT.js → connection-C7glVpPE.js} +2 -2
- package/dist/owletto/dist/assets/{connection-feed-detail-CJYqryAV.js → connection-feed-detail-CJju0qiw.js} +2 -2
- package/dist/owletto/dist/assets/{connector-page-shell-C23dWdKz.js → connector-page-shell-BeuyjiB2.js} +2 -2
- package/dist/owletto/dist/assets/{connector-provenance-CW4CXtCz.js → connector-provenance-B2C2cjBg.js} +2 -2
- package/dist/owletto/dist/assets/{connectors-Bp08_KPq.js → connectors-DSQ5AWPf.js} +2 -2
- package/dist/owletto/dist/assets/{consent-_PpYI1cT.js → consent-B6Aw_89N.js} +2 -2
- package/dist/owletto/dist/assets/{copy-button-1ALlvZU1.js → copy-button-BhXeXLIm.js} +2 -2
- package/dist/owletto/dist/assets/{core.esm-6koO33th.js → core.esm-CJUp2aNZ.js} +3 -3
- package/dist/owletto/dist/assets/create-CWcza8NT.js +2 -0
- package/dist/owletto/dist/assets/{create-kUevP9Xx.js → create-DUlRsFNn.js} +2 -2
- package/dist/owletto/dist/assets/{create-automation-form-BhujNbRr.js → create-automation-form-D141prEG.js} +3 -3
- package/dist/owletto/dist/assets/{create-Drx9tcnG.js → create-bGOYifof.js} +2 -2
- package/dist/owletto/dist/assets/create._connectorKey-Ds4tpwHP.js +2 -0
- package/dist/owletto/dist/assets/{custom-guardrail-edits-B_aCgvoZ.js → custom-guardrail-edits-DuQ28xv3.js} +2 -2
- package/dist/owletto/dist/assets/{definition-comparison-3zKUSTt8.js → definition-comparison-BUDNuAN_.js} +2 -2
- package/dist/owletto/dist/assets/{detail-page-skeleton-BmxqqIsH.js → detail-page-skeleton-BRHaq5Sj.js} +2 -2
- package/dist/owletto/dist/assets/{device-D2eUt_nr.js → device-D3fzoIrM.js} +2 -2
- package/dist/owletto/dist/assets/{device-pin-tombstone-BFPbTM_o.js → device-pin-tombstone-BIM-ziCH.js} +2 -2
- package/dist/owletto/dist/assets/{device._deviceId-Dqtmb1Xp.js → device._deviceId-BnPqTgK1.js} +2 -2
- package/dist/owletto/dist/assets/{dynamic-schema-form-D3KnzCsW.js → dynamic-schema-form-OkIZImgp.js} +2 -2
- package/dist/owletto/dist/assets/entity-options-CpeX7iiX.js +2 -0
- package/dist/owletto/dist/assets/entity-page-Cjc8oXA2.js +2 -0
- package/dist/owletto/dist/assets/{entity-pages-DJNSQrfB.js → entity-pages-18xSANrS.js} +2 -2
- package/dist/owletto/dist/assets/entity-schema-graph-uwZ-P0t8.js +2 -0
- package/dist/owletto/dist/assets/{entity-type-page-CouHZbc9.js → entity-type-page-MgZ7_0oh.js} +2 -2
- package/dist/owletto/dist/assets/event-detail-D6AH6a2C.js +2 -0
- package/dist/owletto/dist/assets/events-feed-BI7wNRUY.js +2 -0
- package/dist/owletto/dist/assets/filter-editors-DDTwyYt0.js +3 -0
- package/dist/owletto/dist/assets/{full-page-spinner-B7A6Ycyi.js → full-page-spinner-DWo519BU.js} +2 -2
- package/dist/owletto/dist/assets/index-9tTjJo_J.css +1 -0
- package/dist/owletto/dist/assets/{index-B-dZruj6.js → index-BW7IFKXC.js} +2 -2
- package/dist/owletto/dist/assets/{index-C7QM3aqU.js → index-BYcFrinP.js} +2 -2
- package/dist/owletto/dist/assets/index-BhJsTy-C.js +2 -0
- package/dist/owletto/dist/assets/index-CEcsgXDj.js +2 -0
- package/dist/owletto/dist/assets/index-CPscKk2u.js +2 -0
- package/dist/owletto/dist/assets/{index-DXfYVs5m.js → index-Cd8jMsz8.js} +2 -2
- package/dist/owletto/dist/assets/index-CdDNNAx2.js +7906 -0
- package/dist/owletto/dist/assets/index-CfJ2-EpK.js +2 -0
- package/dist/owletto/dist/assets/{index-BztXeLBN.js → index-D1UCJQl1.js} +2 -2
- package/dist/owletto/dist/assets/index-D5DM4g2w.js +2 -0
- package/dist/owletto/dist/assets/index-DmqnKGqW.js +2 -0
- package/dist/owletto/dist/assets/index-DznAbTOF.js +2 -0
- package/dist/owletto/dist/assets/{json-diff-CJK-gzCt.js → json-diff-C-WQqyIf.js} +2 -2
- package/dist/owletto/dist/assets/{list-skeleton-bQAZ0hQp.js → list-skeleton-0B1bTrAK.js} +2 -2
- package/dist/owletto/dist/assets/{login-DLqL54Rk.js → login-CH7P2AyR.js} +2 -2
- package/dist/owletto/dist/assets/{logout-H0F3IfiO.js → logout-D474YsYQ.js} +2 -2
- package/dist/owletto/dist/assets/{member-scope-gate-Doic_6qX.js → member-scope-gate-CH_0jHiM.js} +2 -2
- package/dist/owletto/dist/assets/memory-browse-page-Ba4aYavw.js +74 -0
- package/dist/owletto/dist/assets/{model-selector-BrfaDwIg.js → model-selector-XYmk7Iru.js} +2 -2
- package/dist/owletto/dist/assets/needs-you-list-Bd4iiiqm.js +2 -0
- package/dist/owletto/dist/assets/new-BOsrRqp8.js +2 -0
- package/dist/owletto/dist/assets/{new-5GkxlOuQ.js → new-CJ6TF3Vc.js} +2 -2
- package/dist/owletto/dist/assets/{new-BiA4DGoN.js → new-DGPOjak2.js} +2 -2
- package/dist/owletto/dist/assets/new-Q0XqiZq2.js +2 -0
- package/dist/owletto/dist/assets/{organization-CLrcmgNK.js → organization-hD_Z6TSd.js} +2 -2
- package/dist/owletto/dist/assets/peek-pane-content-Cc8YX1oy.js +2 -0
- package/dist/owletto/dist/assets/{pending-seed-DYYOoCvj.js → pending-seed-D7-ld7as.js} +2 -2
- package/dist/owletto/dist/assets/{proposal-review-shell-BVwOMoq9.js → proposal-review-shell-BWRJidwb.js} +2 -2
- package/dist/owletto/dist/assets/public-shell-ready-CRyAZATw.js +2 -0
- package/dist/owletto/dist/assets/record-activity-9ux6SfCd.js +2 -0
- package/dist/owletto/dist/assets/{record-session-KuEDuF3S.js → record-session-ClKBr1_C.js} +2 -2
- package/dist/owletto/dist/assets/{renderer-ucwCQmBk.js → renderer-DZ0w2k2r.js} +2 -2
- package/dist/owletto/dist/assets/{reset-password-BkiAmXZW.js → reset-password-D2RfrEVZ.js} +2 -2
- package/dist/owletto/dist/assets/{run-initiator-8vdkq-3o.js → run-initiator-B8IRlRd-.js} +2 -2
- package/dist/owletto/dist/assets/runs-CuC7WMtd.js +2 -0
- package/dist/owletto/dist/assets/runs-list-8gUPWjP4.js +2 -0
- package/dist/owletto/dist/assets/{schema-value-CefbtPIY.js → schema-value-k19Ata7u.js} +3 -3
- package/dist/owletto/dist/assets/scoped-feed-bar-L7h-Ca4u.js +2 -0
- package/dist/owletto/dist/assets/{settings-DvzkRYQy.js → settings-BZqntV3E.js} +2 -2
- package/dist/owletto/dist/assets/{source-record-panels-LJIWGtHb.js → source-record-panels-C4UItfdk.js} +2 -2
- package/dist/owletto/dist/assets/{status-variants-BxHtpMOj.js → status-variants-BR_iGWN5.js} +2 -2
- package/dist/owletto/dist/assets/subDays-hOwerOLo.js +2 -0
- package/dist/owletto/dist/assets/{table-1O-ik4_O.js → table-C3DMoL4K.js} +2 -2
- package/dist/owletto/dist/assets/use-automations-CdtiVLCv.js +2 -0
- package/dist/owletto/dist/assets/{use-login-redirect-CfCbEeJR.js → use-login-redirect-CYlVkAhE.js} +2 -2
- package/dist/owletto/dist/assets/{use-mention-search-CA-evCDf.js → use-mention-search-CtbixPEE.js} +2 -2
- package/dist/owletto/dist/assets/view-param-filters-BdN8OU35.js +2 -0
- package/dist/owletto/dist/assets/{views-access-required-BerT4Z1d.js → views-access-required-CvIIxdS_.js} +2 -2
- package/dist/owletto/dist/index.html +19 -12
- package/dist/server-main.bundle.mjs +4245 -2432
- package/npm-shrinkwrap.json +328 -328
- package/package.json +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +23 -2
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/classify-error.d.ts +3 -4
- package/vendor/core/dist/classify-error.js +8 -8
- package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +17 -1
- package/vendor/core/dist/contracts/tools/collection-presentation.js +27 -3
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +39 -0
- package/vendor/core/dist/contracts/tools/manage-automations.js +11 -1
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +249 -7
- package/vendor/core/dist/contracts/tools/manage-views.js +83 -21
- package/vendor/core/dist/contracts/tools/navigation.d.ts +248 -0
- package/vendor/core/dist/contracts/tools/navigation.js +284 -0
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +7 -0
- package/vendor/core/dist/contracts/tools/view-attach.js +15 -0
- package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +4 -1
- package/vendor/core/dist/contracts/tools/view-content-hash.js +4 -2
- package/vendor/core/dist/contracts/tools/view-definition.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/view-definition.js +52 -0
- package/vendor/core/dist/contracts/tools/view-host.d.ts +68 -0
- package/vendor/core/dist/contracts/tools/view-host.js +28 -1
- package/vendor/core/dist/contracts/tools/view-scope.d.ts +31 -0
- package/vendor/core/dist/contracts/tools/view-scope.js +45 -0
- package/vendor/core/dist/errors.d.ts +17 -24
- package/vendor/core/dist/errors.js +17 -24
- package/vendor/core/dist/types.d.ts +0 -6
- package/vendor/core/package.json +11 -1
- package/vendor/views/dist/api.d.ts +30 -5
- package/vendor/views/dist/api.js +22 -8
- package/vendor/views/dist/bridge.d.ts +17 -0
- package/vendor/views/dist/bridge.js +49 -1
- package/vendor/views/dist/components.d.ts +27 -5
- package/vendor/views/dist/components.js +57 -7
- package/vendor/views/dist/embed.d.ts +98 -0
- package/vendor/views/dist/embed.js +418 -0
- package/vendor/views/dist/index.d.ts +3 -1
- package/vendor/views/dist/index.js +1 -0
- package/vendor/views/package.json +1 -1
- package/dist/owletto/dist/assets/_-B0tmXZ86.js +0 -2
- package/dist/owletto/dist/assets/_-DwXULq4r.js +0 -3
- package/dist/owletto/dist/assets/_agentId-B1dNkhnr.js +0 -2
- package/dist/owletto/dist/assets/_agentId-sYjvnBaB.js +0 -2
- package/dist/owletto/dist/assets/_automationId-Bnw_CnT_.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey._connectionId-D7Z8DQ-B.js +0 -2
- package/dist/owletto/dist/assets/_eventId-CfB0_2zK.js +0 -2
- package/dist/owletto/dist/assets/_owner-BDvTUY0a.js +0 -3
- package/dist/owletto/dist/assets/_shape-BZidoJMB.js +0 -2
- package/dist/owletto/dist/assets/_slug-R989vOiM.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-BDUSrpe5.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-BnFqh5-t.js +0 -2
- package/dist/owletto/dist/assets/activity-route-view-CN2dOiCD.js +0 -2
- package/dist/owletto/dist/assets/automation-detail-content-BJwRU6qT.js +0 -2
- package/dist/owletto/dist/assets/connect-OdHpIVV9.js +0 -2
- package/dist/owletto/dist/assets/connect-menu-B9u86bb2.js +0 -2
- package/dist/owletto/dist/assets/connect._clientId-EI1tcdSE.js +0 -2
- package/dist/owletto/dist/assets/connector-boxes-BWPXijAk.js +0 -2
- package/dist/owletto/dist/assets/create-DULVO0HS.js +0 -2
- package/dist/owletto/dist/assets/create._connectorKey-N6fhcIPy.js +0 -2
- package/dist/owletto/dist/assets/entity-options-IUdQ-64R.js +0 -2
- package/dist/owletto/dist/assets/entity-page-B3Im65EI.js +0 -2
- package/dist/owletto/dist/assets/event-detail-CvaRN1qB.js +0 -2
- package/dist/owletto/dist/assets/events-feed-DwOkLk6A.js +0 -2
- package/dist/owletto/dist/assets/filter-editors-DQ5V4Cvh.js +0 -2
- package/dist/owletto/dist/assets/home-stream-Bg97PUBJ.js +0 -2
- package/dist/owletto/dist/assets/home-toolbar-CpCcHA6z.js +0 -2
- package/dist/owletto/dist/assets/index-9PGnv4-5.js +0 -2
- package/dist/owletto/dist/assets/index-C2TCKJDP.js +0 -7901
- package/dist/owletto/dist/assets/index-CWn46a4y.js +0 -2
- package/dist/owletto/dist/assets/index-CxJONizf.js +0 -2
- package/dist/owletto/dist/assets/index-DJhb3li3.js +0 -2
- package/dist/owletto/dist/assets/index-DY-YGnCe.js +0 -2
- package/dist/owletto/dist/assets/index-j3v7ITPb.js +0 -2
- package/dist/owletto/dist/assets/index-oiy6ygaI.js +0 -2
- package/dist/owletto/dist/assets/index-pEgtAY1t.js +0 -2
- package/dist/owletto/dist/assets/index-xAvK3IyQ.css +0 -1
- package/dist/owletto/dist/assets/memory-browse-page-CUea2Llz.js +0 -74
- package/dist/owletto/dist/assets/new-M-MX_T5C.js +0 -2
- package/dist/owletto/dist/assets/peek-pane-content-B29OcHwm.js +0 -2
- package/dist/owletto/dist/assets/public-shell-ready-BbjPgh3k.js +0 -2
- package/dist/owletto/dist/assets/record-activity-BCpNKaUo.js +0 -2
- package/dist/owletto/dist/assets/runs-B_iywKWb.js +0 -2
- package/dist/owletto/dist/assets/runs-list-CJJFRhTl.js +0 -2
- package/dist/owletto/dist/assets/schema-type-editor-panel-C4e8pq1A.js +0 -2
- package/dist/owletto/dist/assets/scoped-feed-bar-CapleZvS.js +0 -2
- package/dist/owletto/dist/assets/subDays-DwIOMzYC.js +0 -2
- package/dist/owletto/dist/assets/use-automations-lV8PuE8L.js +0 -2
- package/dist/owletto/dist/assets/view-param-filters-Bp84PUMd.js +0 -2
package/dist/owletto/dist/assets/{agent-editor-form-CDAHRNWl.js → agent-editor-form-Bnc_q5WD.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=agent-editor-form-
|
|
1
|
+
import{aX as ne,aY as ae,j as e,B as A,fB as re,fN as ie,cc as oe,i as le,gS as de,aP as B,a4 as U,cU as ce,i8 as me,i9 as ue,ia as ge,hh as fe,ib as xe,c6 as pe,aZ as he,r as be,bz as k,dy as O,eE as ve,cb as je,bT as ye,ic as V}from"./index-CdDNNAx2.js";import{D as Ne,A as we,e as Ce}from"./definition-comparison-BUDNuAN_.js";import{b as Se,s as Ae}from"./model-selector-XYmk7Iru.js";function Me(s){const t=s.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").replace(/-{2,}/g,"-");return(t?/^[a-z]/.test(t)&&t.length>=3?t:`agent-${t}`:"agent").slice(0,60).replace(/-+$/g,"")||"agent"}function Ie(s,t){const r=new Set(t),x=Me(s);let f=x,d=2;for(;r.has(f);){const g=`-${d}`;f=`${x.slice(0,Math.max(1,60-g.length)).replace(/-+$/g,"")||"agent"}${g}`,d+=1}return f}const Pe="__unresolved__";function G(s){return s.endsWith(`/${Pe}`)}function W(s){const t=s.indexOf("/");return t===-1?{slug:s,model:""}:{slug:s.slice(0,t),model:s.slice(t+1)}}function Fe(s,t){const{slug:r,model:x}=W(s);return{provider:t.find(g=>g.value===s)?.provider??t.find(g=>W(g.value).slug===r)?.provider??r,model:x}}function ke({value:s,onChange:t,disabled:r}){const{data:x=[]}=ne(),{data:f=[]}=ae(),d=Se(x,f),g=(n,l)=>{const i=n+l;if(i<0||i>=s.length)return;const u=[...s];[u[n],u[i]]=[u[i],u[n]],t(u)},b=n=>{t(s.filter((l,i)=>i!==n))},c=n=>{s.includes(n)||t([...s,n])},m=d.filter(n=>!s.includes(n.value)&&!G(n.value));return e.jsxs("div",{className:"grid gap-2",children:[s.length===0?e.jsx("p",{className:"rounded-lg border border-dashed bg-muted/20 px-3 py-4 text-center text-[11px] text-muted-foreground",children:"No models pinned — this agent uses the org default."}):e.jsx("ul",{className:"grid gap-1.5",children:s.map((n,l)=>{const i=G(n),{provider:u,model:a}=Fe(n,d);return e.jsxs("li",{className:le("flex items-center gap-2 rounded-lg border bg-muted/20 px-3 py-2",i&&"opacity-60"),children:[e.jsxs("div",{className:"grid min-w-0 flex-1 gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-sm",children:u}),l===0?e.jsx("span",{className:"shrink-0 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary",children:"Default"}):null]}),e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:i?"no model selected":a})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(A,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":"Move up",disabled:r||l===0,onClick:()=>g(l,-1),children:e.jsx(re,{className:"h-4 w-4"})}),e.jsx(A,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":"Move down",disabled:r||l===s.length-1,onClick:()=>g(l,1),children:e.jsx(ie,{className:"h-4 w-4"})}),e.jsx(A,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive hover:text-destructive","aria-label":"Remove model",disabled:r,onClick:()=>b(l),children:e.jsx(oe,{className:"h-4 w-4"})})]})]},n)})}),e.jsx(de,{contentClassName:"w-[--radix-popover-trigger-width] min-w-[280px]",searchPlaceholder:"Search or type a model ref…",emptyText:"Type a full provider/model ref to use it.",trigger:n=>e.jsxs(A,{type:"button",variant:"outline",role:"combobox","aria-expanded":n,disabled:r,className:"w-full justify-start font-normal text-muted-foreground",children:[e.jsx(ce,{className:"mr-2 h-4 w-4 shrink-0"}),"Add model"]}),children:(n,l)=>{const i=l.trim(),u=Ae(i,d)&&!s.includes(i);return e.jsxs(e.Fragment,{children:[m.map(a=>e.jsxs(B,{value:`${a.provider} ${a.model} ${a.value}`,onSelect:()=>{c(a.value),n()},className:"cursor-pointer",children:[e.jsx(U,{className:"mr-2 h-4 w-4 opacity-0"}),e.jsxs("span",{className:"truncate",children:[a.provider," ",e.jsx("span",{className:"text-muted-foreground text-xs",children:a.model}),a.isDefault?e.jsx("span",{className:"ml-1.5 text-muted-foreground text-xs",children:"· org default"}):null]})]},a.value)),u?e.jsxs(B,{value:`__custom__ ${i}`,onSelect:()=>{c(i),n()},className:"cursor-pointer",children:[e.jsx(U,{className:"mr-2 h-4 w-4 opacity-0"}),e.jsxs("span",{children:["Use ",e.jsx("span",{className:"font-mono text-xs",children:i})]})]}):null]})}})]})}const Ee=3;function X(s){return Array.from({length:Ee},(t,r)=>s?.[r]??{title:"",message:""})}function Y(s){return s.map(({title:t,message:r})=>({title:t.trim(),message:r.trim()})).filter(({title:t,message:r})=>t&&r)}function Z({settings:s,models:t}){return e.jsxs(e.Fragment,{children:[e.jsx(V,{id:"settings",title:"Settings",children:s}),e.jsx(V,{id:"models",title:"Models",children:t})]})}function $e({mode:s,existingAgentIds:t=[],onCreated:r,onCancel:x,onDone:f,reviewMode:d="none",reviewProposal:g=null,reviewControlsDisabled:b=!1}){const c=s.kind==="create",m=s.kind==="edit"?s.agent:null,n=!c&&!!m,l=me(),i=ue(m?.agentId??""),u=ge(m?.agentId??""),{data:a,isLoading:_}=fe(m?.agentId,{enabled:n}),$=!c&&d==="active",j=$?g:null,E=j?xe(j.proposal):void 0,v=a,q=m?.agentId??"create",o=pe(q,{name:E?.name??m?.name??"",description:E?.description??m?.description??"",identityMd:E?.identityMd??a?.identityMd??"",soulMd:a?.soulMd??"",userMd:a?.userMd??"",models:v?.models??v?.settings?.models??[],showToolCalls:v?.showToolCalls??v?.settings?.showToolCalls??!1,sandboxId:v?.sandboxId??v?.settings?.sandboxId??"builtin",starters:X(a?.starters)}),[h]=o.field("name"),[y]=o.field("description"),[M]=o.field("identityMd"),[I]=o.field("soulMd"),[P]=o.field("userMd"),[N,H]=o.field("models"),[F]=o.field("showToolCalls"),[w]=o.field("sandboxId"),[C]=o.field("starters"),{data:J}=he({enabled:!c}),K=be.useCallback(async S=>{if(S.preventDefault(),!(b||d==="active"||d==="loading"||d==="error"||!o.canSubmit)){if(c){const p=await l.mutateAsync({agentId:Ie(h,t),name:h.trim(),description:y.trim()||void 0});r?await r(p.agentId):f?.();return}if(m){if(!a){k.error("Still loading agent settings — try again in a moment");return}if(C.some(({title:p,message:T})=>!!p.trim()!=!!T.trim())){k.error("Add both a title and a message for each conversation starter");return}try{await Promise.all([i.mutateAsync({name:h.trim()||m.name,description:y.trim()||void 0}),u.mutateAsync({identityMd:M.trim(),soulMd:I.trim(),userMd:P.trim(),models:N,authProfiles:a.authProfiles??[],skillsConfig:a.skillsConfig,showToolCalls:F,sandboxId:w==="builtin"?void 0:w,starters:Y(C)})]),o.accept(o.values,{name:h.trim()||m.name,description:y.trim()||m.description||"",identityMd:M.trim(),soulMd:I.trim(),userMd:P.trim(),models:N,showToolCalls:F,sandboxId:w,starters:X(Y(C))}),k.success("Agent saved"),f?.()}catch(p){k.error(p instanceof Error?p.message:"Failed to save agent")}}}},[a,l,y,o.accept,o.values,o.canSubmit,b,d,w,t,M,c,N,h,r,f,m,F,I,C,i,u,P]),D=l.isPending||i.isPending||u.isPending,Q=c||!!a;if(n&&_)return e.jsx(Z,{settings:e.jsx(O,{rows:6}),models:e.jsx(O,{rows:2})});const R=D||b,ee=d==="none"||d==="gone",se=h.trim().length>0&&Q;if($&&j){const{current:S,proposed:p}=ve(j);return e.jsx(Ne,{current:S,proposed:p,render:T=>e.jsx(we,{value:T})},j.runId)}const L=S=>e.jsx(Ce,{value:{name:h,description:y,identityMd:M,soulMd:I,userMd:P,models:N,showToolCalls:F,sandboxId:w,starters:C},onChange:o.setValues,section:S,create:c,disabled:R,loading:_,sandboxes:J?.sandboxes,modelsEditor:e.jsx(ke,{value:N,onChange:H,disabled:R})}),z=L("settings"),te=L("models");return e.jsxs("form",{onSubmit:K,className:c?"flex min-h-0 flex-col":"space-y-7",children:[e.jsx(je,{visible:o.hasConflict,onReload:o.reset}),c?z:e.jsx(Z,{settings:z,models:te}),ee?e.jsx(ye,{className:c?"mt-6":void 0,onCancel:x,cancelDisabled:D,children:e.jsx(A,{type:"submit",disabled:!o.canSubmit||!se||D,children:c?l.isPending?"Creating...":"Create agent":i.isPending||u.isPending?"Saving...":"Save changes"})}):null]})}export{$e as A};
|
|
2
|
+
//# sourceMappingURL=agent-editor-form-Bnc_q5WD.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e,m as s,i as n}from"./index-
|
|
2
|
-
//# sourceMappingURL=agent-loading-shells-
|
|
1
|
+
import{j as e,m as s,i as n}from"./index-CdDNNAx2.js";const r="mx-auto w-full max-w-3xl px-4",d="gap-4",i="ml-8 self-end max-w-[80%]",o="mr-8 max-w-[90%]",c="mx-auto w-full max-w-3xl shrink-0 border-t border-border/50 bg-transparent px-4 pb-4 pt-3";function f({rows:l=3}){return e.jsx("div",{className:"space-y-2",role:"status","aria-label":"Loading list",children:Array.from({length:l}).map((a,x)=>e.jsx(s,{className:"h-16 w-full rounded-lg"},x))})}function t({readOnly:l=!1}){return e.jsxs("div",{role:"status","aria-label":l?"Loading run history":"Loading chat",className:l?"flex min-h-[24rem] min-w-0 flex-1 flex-col":"flex min-h-0 flex-1 flex-col",children:[e.jsx("div",{className:l?"flex flex-1 flex-col overflow-hidden":"flex min-h-0 flex-1 flex-col overflow-hidden",children:e.jsxs("div",{className:n(r,"flex flex-1 flex-col overflow-hidden",d),children:[e.jsx("div",{className:i,children:e.jsx(s,{className:"h-12 w-48 rounded-lg"})}),e.jsx("div",{className:o,children:e.jsx(s,{className:n(l?"h-20":"h-16","w-64 rounded-lg")})}),e.jsx("div",{className:i,children:e.jsx(s,{className:"h-10 w-36 rounded-lg"})}),l?e.jsx("div",{className:o,children:e.jsx(s,{className:"h-16 w-52 rounded-lg"})}):null]})}),l?null:e.jsx("div",{className:c,children:e.jsx(s,{className:"h-24 w-full rounded-lg"})})]})}function h(){return e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:e.jsx(t,{})})}function u(){return e.jsx("div",{className:"flex h-48 w-full items-end gap-2 px-2 pb-2",role:"status","aria-label":"Loading timeline",children:[40,65,45,80,55,70,50,85,60,75].map((l,a)=>e.jsx(s,{className:"flex-1 rounded-sm",style:{height:`${l}%`}},a))})}export{t as A,h as C,u as E,c as a,d as b,r as c,o as d,i as e,f};
|
|
2
|
+
//# sourceMappingURL=agent-loading-shells-xteN-pyK.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e,
|
|
2
|
-
//# sourceMappingURL=agent-permissions-matrix-
|
|
1
|
+
import{j as e,bV as B,i as k,dF as D,dG as R,dH as K,gW as G,ad as V,bO as Y,bN as Z,b_ as J,gX as ee,b$ as P,bz as F,c0 as se,bW as ne,c1 as te,bX as re,r as S,gY as ae,gZ as ie,bS as le,c2 as oe,L as w,g_ as de,g$ as ce,cT as W,h0 as ue,h1 as me,h2 as ge,h3 as A,aP as L,X as fe,h4 as q,h5 as z,gS as xe,cU as he,h6 as ye,h7 as pe,c5 as be,h8 as je}from"./index-CdDNNAx2.js";const ve={auto:"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400",approval:"bg-amber-500/15 text-amber-600 dark:text-amber-400",deny:"bg-red-500/15 text-red-600 dark:text-red-400"};function Ne({options:n,value:t,floor:o,onChange:a,disabled:i,ariaLabel:m,compact:u}){return e.jsx("div",{role:"radiogroup","aria-label":m,className:k("inline-flex shrink-0 items-stretch gap-0.5 rounded-lg border border-border bg-muted/40 p-0.5"),children:n.map(l=>{const y=G({option:l,floor:o}),h=l===t,g=y.disabled&&!h,p=B[l],f=e.jsx("button",{type:"button",role:"radio","aria-checked":h,disabled:i||g,onClick:()=>{!h&&!g&&!i&&a(l)},className:k("inline-flex shrink-0 items-center justify-center whitespace-nowrap font-medium transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",u?"min-w-[3rem] rounded-md px-2.5 py-1.5 text-xs leading-none":"min-w-[3.25rem] rounded-md px-3 py-1.5 text-sm leading-none",h?k(ve[l],""):"text-muted-foreground hover:bg-background/60 hover:text-foreground",g&&"cursor-not-allowed opacity-40",i&&!g&&"cursor-not-allowed opacity-60"),children:p},l);return g&&y.reason?e.jsxs(D,{children:[e.jsx(R,{asChild:!0,children:e.jsx("span",{className:"inline-flex shrink-0",children:f})}),e.jsx(K,{children:y.reason})]},l):f})})}function M({children:n,controls:t}){return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-2 px-3 py-2",children:[e.jsx("div",{className:"min-w-40 flex-1 text-sm",children:n}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:t})]})}const _e=[{resourceClass:"entity",title:"Entities",sub:"Defaults for every entity type."},{resourceClass:"agent_config",title:"Agents",sub:"Defaults for reading and managing agents."}];function Se(n,t,o,a,i=null){const m=q(n.floor,t,o,a,i),u=z(n.floor,t,o,a,i)?m:"auto";return(a!==null||i!==null)&&ye(n.agent,t,o)?pe(u,A(n,t,o,null)):u}function ke({label:n,response:t,resourceClass:o,action:a,entityTypeSlug:i,targetAgentId:m=null,dimmed:u,pending:l,onSave:y}){const h=q(t.floor,o,a,i,m),g=z(t.floor,o,a,i,m),p=A(t,o,a,i,m),f=Se(t,o,a,i,m),j=be(o,a),b=e.jsx("div",{className:k("inline-flex shrink-0",u&&"opacity-45"),children:e.jsx(Ne,{options:j,value:p,floor:f,disabled:l,compact:!0,ariaLabel:n,onChange:y})});return g?e.jsxs(D,{children:[e.jsx(R,{asChild:!0,children:e.jsx("span",{className:"inline-flex shrink-0",children:b})}),e.jsxs(K,{children:["Org floor ",B[h]," — can only go stricter"]})]}):b}function Ae(n,t){const o=i=>i.resource_class===t.resource_class&&(i.entity_type_slug??null)===(t.entity_type_slug??null)&&(i.operation_key??null)===(t.operation_key??null)&&(i.target_agent_id??null)===(t.target_agent_id??null),a=n.map(i=>o(i)?t:i);return a.some(o)?a:[...a,t]}function Ce(n,t,o,a,i,m){const u=je(n,t,o,a);return u[i]=m,u}const $="font-medium text-foreground hover:text-primary hover:underline";function Ee({type:n}){return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(W,{icon:n.icon,className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"font-medium",children:n.name}),e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:n.slug})]})}function Q({label:n,disabled:t,hint:o,searchPlaceholder:a,emptyText:i,children:m}){return t?e.jsxs("div",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:[n,o?` ${o}`:""]}):e.jsx(xe,{contentClassName:"w-[min(100vw-2rem,22rem)]",searchPlaceholder:a,emptyText:i,trigger:u=>e.jsxs("button",{type:"button","aria-expanded":u,className:"flex w-full items-center gap-1.5 px-3 py-1.5 text-left text-xs text-primary hover:bg-muted/50",children:[e.jsx(he,{className:"h-3 w-3"}),n]}),children:u=>m(u)})}function Te({pending:n,onClick:t,label:o}){return e.jsx("button",{type:"button",disabled:n,onClick:t,"aria-label":o,className:"rounded p-0.5 text-muted-foreground hover:bg-red-500/10 hover:text-red-600 disabled:opacity-50 dark:hover:text-red-400",children:e.jsx(fe,{className:"h-3 w-3"})})}function $e({owner:n,agentId:t,variant:o="agent"}){const a=o==="org-floor",i=V(),m=Y(n,t??"",{enabled:!a&&!!t}),u=Z(n,{enabled:a}),{data:l,isLoading:y,isError:h,error:g}=a?u:m,p=a?J(n):ee(n,t??""),f=P({mutationFn:r=>a?se(n,r):ne(n,t??"",r),onSuccess:r=>{i.setQueryData(p,c=>c&&{...c,agent:Ae(c.agent,r)}),i.invalidateQueries({queryKey:p}),a&&i.invalidateQueries({queryKey:["agent-permissions"]})},onError:r=>{F.error(r instanceof Error?r.message:"Failed to save permission")}}),j=P({mutationFn:r=>a?te(n,r):re(n,t??"",r),onSuccess:()=>{i.invalidateQueries({queryKey:p}),a&&i.invalidateQueries({queryKey:["agent-permissions"]})},onError:r=>{F.error(r instanceof Error?r.message:"Failed to remove override")}}),b=f.isPending||j.isPending,C=S.useMemo(()=>l?ae(l):[],[l]),E=S.useMemo(()=>{if(!l)return[];const r=new Set(C.map(c=>c.slug));return l.entity_types.filter(c=>!r.has(c.slug))},[l,C]),v=S.useMemo(()=>l?ie(l):[],[l]),N=S.useMemo(()=>{if(!l)return[];const r=new Set(v.map(c=>c.id));return l.agents.filter(c=>(a||c.id!==t)&&!r.has(c.id))},[l,v,t,a]);if(y)return e.jsx(le,{label:"permissions",variant:"cards",cards:2});if(h||!l)return e.jsx(oe,{label:g instanceof Error?g.message:"permissions"});const x=l,H=(r,c,T,_,s=null)=>{const d=Ce(x,r,c,s,T,_);f.mutate({resource_class:r,effects:d,entity_type_slug:c,target_agent_id:s})},X=x.entity_types.length===0?"— none yet":E.length===0?"— all covered":null,I=N.length===0&&v.length===0?"— no other agents":N.length===0?"— all covered":null;return e.jsxs("div",{className:"space-y-4",children:[a?null:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Manage connector rules and agent restrictions in"," ",e.jsx(w,{to:"/$owner/settings/organization",params:{owner:n},search:{section:"policies",agent:t},className:$,children:"Organization policies"}),"."]}),_e.map(r=>{const c=r.resourceClass==="entity",T=r.resourceClass==="agent_config",_=[{key:"default",label:"Default",name:"Default",entityTypeSlug:null,targetAgentId:null,owned:!1,diffs:0},...c?C.map(s=>({key:`entity:${s.slug}`,name:s.name,label:e.jsx(w,{to:"/$owner/entity-types/$slug",params:{owner:n,slug:s.slug},className:$,title:`Open ${s.name}`,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(W,{icon:s.icon,className:"h-3.5 w-3.5 shrink-0"}),s.name]})}),entityTypeSlug:s.slug,targetAgentId:null,owned:ce(x,s.slug),diffs:de(x,s.slug)})):v.map(s=>({key:`agent:${s.id}`,name:s.name,label:e.jsx(w,{to:"/$owner/agents/$agentId",params:{owner:n,agentId:s.id},className:$,title:`Open ${s.name}`,children:s.name}),entityTypeSlug:null,targetAgentId:s.id,owned:me(x,s.id),diffs:ue(x,s.id)}))];return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-sm font-medium",children:r.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.sub})]}),e.jsxs("div",{className:"divide-y overflow-hidden rounded-lg border",children:[_.map(s=>e.jsxs("div",{className:"divide-y",children:[_.length>1&&e.jsx("div",{className:"bg-muted/30",children:e.jsx(M,{controls:s.owned?e.jsx(Te,{pending:b,label:`Remove ${s.name} exception`,onClick:()=>j.mutate({resource_class:r.resourceClass,entity_type_slug:s.entityTypeSlug,target_agent_id:s.targetAgentId})}):null,children:e.jsxs("div",{className:"flex items-center gap-2",children:[s.label,s.key!=="default"&&!s.owned?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Organization minimum"}):s.diffs>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[s.diffs," ",s.diffs===1?"change":"changes"]}):null]})})}),e.jsx("div",{className:"divide-y",children:ge[r.resourceClass].filter(d=>!s.targetAgentId||d!=="create").map(d=>{const O=`${d.charAt(0).toUpperCase()+d.slice(1)} ${c?"entities":"agents"}`;return e.jsx(M,{controls:e.jsx(ke,{label:`${s.name}: ${O}`,response:x,resourceClass:r.resourceClass,action:d,entityTypeSlug:s.entityTypeSlug,targetAgentId:s.targetAgentId,dimmed:s.key!=="default"&&A(x,r.resourceClass,d,s.entityTypeSlug,s.targetAgentId)===A(x,r.resourceClass,d,null),pending:b,onSave:U=>H(r.resourceClass,s.entityTypeSlug,d,U,s.targetAgentId)}),children:O},d)})})]},s.key)),e.jsxs("div",{className:"border-t",children:[c?e.jsx(Q,{label:"Add type",disabled:b||E.length===0,hint:X,searchPlaceholder:"Search types…",emptyText:"No matching types.",children:s=>E.map(d=>e.jsx(L,{value:`${d.name} ${d.slug}`,onSelect:()=>{f.mutate({resource_class:"entity",effects:{},entity_type_slug:d.slug}),s()},className:"cursor-pointer",children:e.jsx(Ee,{type:d})},d.slug))}):null,T?e.jsx(Q,{label:"Add agent",disabled:b||N.length===0,hint:I,searchPlaceholder:"Search agents…",emptyText:"No matching agents.",children:s=>N.map(d=>e.jsxs(L,{value:`${d.name} ${d.id}`,onSelect:()=>{f.mutate({resource_class:"agent_config",effects:{},target_agent_id:d.id}),s()},className:"cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:d.name}),e.jsx("span",{className:"ml-1.5 font-mono text-[10px] text-muted-foreground",children:d.id})]},d.id))}):null]})]})]},r.resourceClass)})]})}export{$e as A,Ne as P,M as a};
|
|
2
|
+
//# sourceMappingURL=agent-permissions-matrix-C_ayr0pd.js.map
|
package/dist/owletto/dist/assets/{agent-skill-context-B0ZYVE3n.js → agent-skill-context-r0O0BVOu.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as p,
|
|
2
|
-
//# sourceMappingURL=agent-skill-context-
|
|
1
|
+
import{r as p,bH as G,hh as ge,hU as pe,ia as be,bz as F,j as ve}from"./index-CdDNNAx2.js";import{K as E,d as me,g as he,e as xe,s as Ce,f as Ie,h as Se,i as H,b as ke,c as ye,j as we,k as Re,C as Y,l as Ae}from"./core.esm-CJUp2aNZ.js";import{s as De,b as Ee}from"./skill-editor-D_W3QlRz.js";function U(e,n,t){const r=e.slice();return r.splice(t<0?r.length+t:t,0,r.splice(n,1)[0]),r}function Le(e,n){return e.reduce((t,r,s)=>{const u=n.get(r);return u&&(t[s]=u),t},Array(e.length))}function P(e){return e!==null&&e>=0}function Te(e,n){if(e===n)return!0;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}function Ne(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const V=e=>{let{rects:n,activeIndex:t,overIndex:r,index:s}=e;const u=U(n,r,t),o=n[s],i=u[s];return!i||!o?null:{x:i.left-o.left,y:i.top-o.top,scaleX:i.width/o.width,scaleY:i.height/o.height}},M={scaleX:1,scaleY:1},We=e=>{var n;let{activeIndex:t,activeNodeRect:r,index:s,rects:u,overIndex:o}=e;const i=(n=u[t])!=null?n:r;if(!i)return null;if(s===t){const f=u[o];return f?{x:0,y:t<o?f.top+f.height-(i.top+i.height):f.top-i.top,...M}:null}const m=Oe(u,s,t);return s>t&&s<=o?{x:0,y:-i.height-m,...M}:s<t&&s>=o?{x:0,y:i.height+m,...M}:{x:0,y:0,...M}};function Oe(e,n,t){const r=e[n],s=e[n-1],u=e[n+1];return r?t<n?s?r.top-(s.top+s.height):u?u.top-(r.top+r.height):0:u?u.top-(r.top+r.height):s?r.top-(s.top+s.height):0:0}const W="Sortable",J=G.createContext({activeIndex:-1,containerId:W,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:V,disabled:{draggable:!1,droppable:!1}});function Je(e){let{children:n,id:t,items:r,strategy:s=V,disabled:u=!1}=e;const{active:o,dragOverlay:i,droppableRects:m,over:f,measureDroppableContainers:a}=Ie(),l=Se(W,t),b=i.rect!==null,h=p.useMemo(()=>r.map(d=>typeof d=="object"&&"id"in d?d.id:d),[r]),k=o!=null,w=o?h.indexOf(o.id):-1,C=f?h.indexOf(f.id):-1,R=p.useRef(h),I=!Te(h,R.current),S=C!==-1&&w===-1||I,c=Ne(u);H(()=>{I&&k&&a(h)},[I,h,k,a]),p.useEffect(()=>{R.current=h},[h]);const g=p.useMemo(()=>({activeIndex:w,containerId:l,disabled:c,disableTransforms:S,items:h,overIndex:C,useDragOverlay:b,sortedRects:Le(h,m),strategy:s}),[w,l,c.draggable,c.droppable,S,h,C,m,b,s]);return G.createElement(J.Provider,{value:g},n)}const Pe=e=>{let{id:n,items:t,activeIndex:r,overIndex:s}=e;return U(t,r,s).indexOf(n)},Me=e=>{let{containerId:n,isSorting:t,wasDragging:r,index:s,items:u,newIndex:o,previousItems:i,previousContainerId:m,transition:f}=e;return!f||!r||i!==u&&s===o?!1:t?!0:o!==s&&n===m},je={duration:200,easing:"ease"},Q="transform",ze=Y.Transition.toString({property:Q,duration:0,easing:"linear"}),$e={roleDescription:"sortable"};function Fe(e){let{disabled:n,index:t,node:r,rect:s}=e;const[u,o]=p.useState(null),i=p.useRef(t);return H(()=>{if(!n&&t!==i.current&&r.current){const m=s.current;if(m){const f=Ae(r.current,{ignoreTransform:!0}),a={x:m.left-f.left,y:m.top-f.top,scaleX:m.width/f.width,scaleY:m.height/f.height};(a.x||a.y)&&o(a)}}t!==i.current&&(i.current=t)},[n,t,r,s]),p.useEffect(()=>{u&&o(null)},[u]),u}function Qe(e){let{animateLayoutChanges:n=Me,attributes:t,disabled:r,data:s,getNewIndex:u=Pe,id:o,strategy:i,resizeObserverConfig:m,transition:f=je}=e;const{items:a,containerId:l,activeIndex:b,disabled:h,disableTransforms:k,sortedRects:w,overIndex:C,useDragOverlay:R,strategy:I}=p.useContext(J),S=Ue(r,h),c=a.indexOf(o),g=p.useMemo(()=>({sortable:{containerId:l,index:c,items:a},...s}),[l,s,c,a]),d=p.useMemo(()=>a.slice(a.indexOf(o)),[a,o]),{rect:v,node:y,isOver:A,setNodeRef:L}=ke({id:o,data:g,disabled:S.droppable,resizeObserverConfig:{updateMeasurementsFor:d,...m}}),{active:D,activatorEvent:te,activeNodeRect:ne,attributes:re,setNodeRef:K,listeners:se,isDragging:z,over:oe,setActivatorNodeRef:ie,transform:ae}=ye({id:o,data:g,attributes:{...$e,...t},disabled:S.draggable}),le=we(L,K),T=!!D,X=T&&!k&&P(b)&&P(C),_=!R&&z,q=_&&X?ae:null,ce=X?q??(i??I)({rects:w,activeNodeRect:ne,activeIndex:b,overIndex:C,index:c}):null,O=P(b)&&P(C)?u({id:o,items:a,activeIndex:b,overIndex:C}):c,N=D?.id,x=p.useRef({activeId:N,items:a,newIndex:O,containerId:l}),ue=a!==x.current.items,B=n({active:D,containerId:l,isDragging:z,isSorting:T,id:o,index:c,items:a,newIndex:x.current.newIndex,previousItems:x.current.items,previousContainerId:x.current.containerId,transition:f,wasDragging:x.current.activeId!=null}),$=Fe({disabled:!B,index:c,node:y,rect:v});return p.useEffect(()=>{T&&x.current.newIndex!==O&&(x.current.newIndex=O),l!==x.current.containerId&&(x.current.containerId=l),a!==x.current.items&&(x.current.items=a)},[T,O,l,a]),p.useEffect(()=>{if(N===x.current.activeId)return;if(N!=null&&x.current.activeId==null){x.current.activeId=N;return}const fe=setTimeout(()=>{x.current.activeId=N},50);return()=>clearTimeout(fe)},[N]),{active:D,activeIndex:b,attributes:re,data:g,rect:v,index:c,newIndex:O,items:a,isOver:A,isSorting:T,isDragging:z,listeners:se,node:y,overIndex:C,over:oe,setNodeRef:le,setActivatorNodeRef:ie,setDroppableNodeRef:L,setDraggableNodeRef:K,transform:$??ce,transition:de()};function de(){if($||ue&&x.current.newIndex===c)return ze;if(!(_&&!Re(te)||!f)&&(T||B))return Y.Transition.toString({...f,property:Q})}}function Ue(e,n){var t,r;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(t=e?.draggable)!=null?t:n.draggable,droppable:(r=e?.droppable)!=null?r:n.droppable}}function j(e){if(!e)return!1;const n=e.data.current;return!!(n&&"sortable"in n&&typeof n.sortable=="object"&&"containerId"in n.sortable&&"items"in n.sortable&&"index"in n.sortable)}const Ke=[E.Down,E.Right,E.Up,E.Left],Ze=(e,n)=>{let{context:{active:t,collisionRect:r,droppableRects:s,droppableContainers:u,over:o,scrollableAncestors:i}}=n;if(Ke.includes(e.code)){if(e.preventDefault(),!t||!r)return;const m=[];u.getEnabled().forEach(l=>{if(!l||l!=null&&l.disabled)return;const b=s.get(l.id);if(b)switch(e.code){case E.Down:r.top<b.top&&m.push(l);break;case E.Up:r.top>b.top&&m.push(l);break;case E.Left:r.left>b.left&&m.push(l);break;case E.Right:r.left<b.left&&m.push(l);break}});const f=me({collisionRect:r,droppableRects:s,droppableContainers:m});let a=he(f,"id");if(a===o?.id&&f.length>1&&(a=f[1].id),a!=null){const l=u.get(t.id),b=u.get(a),h=b?s.get(b.id):null,k=b?.node.current;if(k&&h&&l&&b){const C=xe(k).some((d,v)=>i[v]!==d),R=Z(l,b),I=Xe(l,b),S=C||!R?{x:0,y:0}:{x:I?r.width-h.width:0,y:I?r.height-h.height:0},c={x:h.left,y:h.top};return S.x&&S.y?c:Ce(c,S)}}}};function Z(e,n){return!j(e)||!j(n)?!1:e.data.current.sortable.containerId===n.data.current.sortable.containerId}function Xe(e,n){return!j(e)||!j(n)||!Z(e,n)?!1:e.data.current.sortable.index<n.data.current.sortable.index}function _e(e){return{skillsConfig:De(e)}}function qe(e){return e.repo.startsWith("system/")?["System"]:[]}function et(e,n){return e.filter(t=>!t.hidden&&!n.has(t.repo)).map(t=>({key:t.repo,name:t.name,description:t.description||t.instructions||"Add this skill to give the agent tools and capabilities.",badges:qe(t)}))}function tt(e,n){const t=n.trim().toLowerCase();return t?e.filter(r=>r.name.toLowerCase().includes(t)||r.description.toLowerCase().includes(t)||r.key.toLowerCase().includes(t)):e}function Be(e){const n=e.instructions?.trim();return{repo:e.repo,skillId:e.skillId,name:e.name,description:e.description,instructions:n,content:n||e.name,enabled:!0,system:e.repo.startsWith("system/")}}const ee=p.createContext(null);function nt({agentId:e,children:n}){const{data:t,isLoading:r}=ge(e),{data:s,isLoading:u}=pe(e),o=be(e),i=p.useMemo(()=>t?Ee(t,s?.catalog??[]):[],[t,s]),[m,f]=p.useState(null),a=m??i,l=p.useCallback(async(c,g)=>{if(!t)return F.error("Still loading agent settings — try again in a moment"),!1;try{const d=_e(c);return await o.mutateAsync(d),F.success(g),!0}catch(d){return F.error(d instanceof Error?d.message:"Failed to save skills"),!1}},[t,o]),b=p.useCallback(c=>{const g=s?.catalog.find(d=>d.repo===c);g&&f(d=>{const v=d??i;return v.some(y=>y.repo===c)?v:[...v,Be(g)]})},[i,s?.catalog]),h=p.useCallback(c=>{const g=c.name.trim();if(!g)return null;const d=`custom/${g.toLowerCase().replace(/[^a-z0-9-]/g,"-")}`,v=c.instructions.trim();return f(y=>{const A=y??i;return A.some(L=>L.repo===d)?A:[...A,{repo:d,skillId:g,name:g,instructions:v||void 0,content:v||g,enabled:!0}]}),d},[i]),k=p.useCallback((c,g)=>{f(d=>(d??i).map(v=>v.repo===c?{...v,...g}:v))},[i]),w=p.useCallback((c,g)=>{f(d=>{const v=d??i,y=v.findIndex(D=>D.repo===c),A=v.findIndex(D=>D.repo===g);if(y<0||A<0||y===A)return v;const L=U(v,y,A);return l(L,"Skill order updated"),L})},[l,i]),C=p.useCallback(async c=>{const g=a.filter(d=>d.repo!==c);return f(g),l(g,"Skill removed")},[l,a]),R=p.useCallback(async(c,g)=>{const d=a.map(v=>v.repo===c?{...v,enabled:g}:v);return f(d),l(d,g?"Skill enabled":"Skill disabled")},[l,a]),I=p.useCallback(async()=>{await l(a,"Skills saved")},[l,a]),S=p.useMemo(()=>({agentId:e,skillRows:a,catalog:s,isLoading:r||u,isSaving:o.isPending,addSkillFromCatalog:b,addCustomSkill:h,updateSkillRow:k,reorderSkills:w,removeSkillAndSave:C,setSkillEnabledAndSave:R,saveSkills:I}),[h,b,e,u,r,w,C,R,I,a,s,o.isPending,k]);return ve.jsx(ee.Provider,{value:S,children:n})}function rt(){const e=p.useContext(ee);if(!e)throw new Error("useAgentSkillEditor must be used within AgentSkillEditorProvider");return e}export{nt as A,Je as S,Ze as a,Qe as b,et as c,tt as f,qe as s,rt as u,We as v};
|
|
2
|
+
//# sourceMappingURL=agent-skill-context-r0O0BVOu.js.map
|
package/dist/owletto/dist/assets/{agent-subpage-shell-ByU0xhXn.js → agent-subpage-shell-C2KpYdu3.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e,as as a,i as n}from"./index-
|
|
2
|
-
//# sourceMappingURL=agent-subpage-shell-
|
|
1
|
+
import{j as e,as as a,i as n}from"./index-CdDNNAx2.js";function c({children:t,className:s}){return e.jsx(a,{className:n("pb-8",s),children:t})}function x({title:t,description:s}){return e.jsxs("div",{className:"mb-2 space-y-1",children:[e.jsx("h1",{className:"text-center text-xl font-semibold",children:t}),e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:s})]})}export{x as A,c as a};
|
|
2
|
+
//# sourceMappingURL=agent-subpage-shell-C2KpYdu3.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{j as s,r as a,
|
|
1
|
+
import{j as s,r as a,b1 as Ht,ad as zt,hg as Wt,hh as Kt,aa as tt,$ as Be,ab as nt,cf as qt,hi as rt,hj as Gt,L as gt,i as P,fW as Yt,hk as bt,hl as Jt,hm as Qt,dj as Xt,hn as Zt,ho as en,aT as tn,B as fe,fN as nn,hp as rn,hq as He,X as on,ai as sn,fB as ln,e8 as Ne,hr as an,aF as cn,aG as un,hs as dn,aI as fn,ht as pn,hu as ot,hv as mn,hw as hn,eW as gn,a3 as bn,hx as xn,hy as vn}from"./index-CdDNNAx2.js";import{D as yn,E as Rn}from"./app-bridge-C4nPtae3.js";import{A as wn,a as Sn,b as Tn,c as Ge,d as xt,e as jn}from"./agent-loading-shells-xteN-pyK.js";import{t as Cn,P as Nn}from"./pending-seed-D7-ld7as.js";import{h as En,t as An,R as In,i as kn,u as _n,M as On,a as Pn}from"./use-mention-search-CtbixPEE.js";import{E as Mn,c as Ln}from"./events-feed-BI7wNRUY.js";const vt=a.createContext(null);function $n({extension:e,children:t}){return s.jsx(vt.Provider,{value:e??null,children:t})}function Ye(){return a.useContext(vt)}var Je=(e=>(e.PROVIDER_QUOTA_EXHAUSTED="PROVIDER_QUOTA_EXHAUSTED",e.PROVIDER_AUTH="PROVIDER_AUTH",e.PROVIDER_UNKNOWN_MODEL="PROVIDER_UNKNOWN_MODEL",e.PROVIDER_BASE_URL_UNRESOLVED="PROVIDER_BASE_URL_UNRESOLVED",e.NO_MODEL_CONFIGURED="NO_MODEL_CONFIGURED",e.WORKER_UNRESPONSIVE="WORKER_UNRESPONSIVE",e.WORKER_DIED="WORKER_DIED",e.WORKER_STARTUP_FAILED="WORKER_STARTUP_FAILED",e.PROVIDER_TOOL_CALL_FAILED="PROVIDER_TOOL_CALL_FAILED",e.SESSION_TIMEOUT="SESSION_TIMEOUT",e))(Je||{});const Dn={PROVIDER_QUOTA_EXHAUSTED:{cta:"provider-management",ctaLabel:"Manage provider"},PROVIDER_AUTH:{cta:"provider-management",ctaLabel:"Reconnect provider"},PROVIDER_UNKNOWN_MODEL:{cta:"agent-settings",ctaLabel:"Choose model"},PROVIDER_BASE_URL_UNRESOLVED:{cta:"provider-management",ctaLabel:"Manage provider"},PROVIDER_TOOL_CALL_FAILED:{message:"The model provider rejected its own tool call and ended the turn. This is usually temporary — please try again.",cta:"none"},NO_MODEL_CONFIGURED:{message:"No model is configured for this agent. Choose a model in agent settings.",cta:"agent-settings",ctaLabel:"Choose a model"},WORKER_UNRESPONSIVE:{message:"The agent didn't finish responding in time. This is usually temporary — please try again.",cta:"none"},WORKER_DIED:{message:"The agent stopped unexpectedly before it could reply. This is usually temporary — please try again.",cta:"none"},WORKER_STARTUP_FAILED:{message:"The agent couldn't start, so your request wasn't processed. Please try again in a moment.",cta:"none"},SESSION_TIMEOUT:{cta:"none",silent:!0}};function Un(e){if(typeof e=="string")return Object.values(Je).includes(e)?e:void 0}const Fn=Object.freeze(Object.defineProperty({__proto__:null,AGENT_ERRORS:Dn,AgentErrorCode:Je,toAgentErrorCode:Un},Symbol.toStringTag,{value:"Module"})),{AGENT_ERRORS:Vn,toAgentErrorCode:Bn}=Fn;function st(e,t){if(!t)return null;try{const n=new URL(t);return n.protocol!=="http:"&&n.protocol!=="https:"?null:new URL(e,`${n.origin}/`).toString()}catch{return null}}function yt(e,t){const n=Bn(e);if(!n)return null;const r=Vn[n];if(r.cta==="none"||!t.workspaceSlug)return null;const o=encodeURIComponent(t.workspaceSlug);if(r.cta==="provider-connect"||r.cta==="provider-management"){const i=t.provider?`/${o}/connectors/${encodeURIComponent(`${Ht}${t.provider}`)}`:`/${o}/connectors`,c=st(i,t.webOrigin);if(!c)return null;const u=new URL(c);return t.provider&&t.model&&u.searchParams.set("model",t.model),{label:r.ctaLabel??"Connect a provider",href:u.toString()}}if(!t.agentId)return null;const l=st(`/${o}/agents/${encodeURIComponent(t.agentId)}#models`,t.webOrigin);return l?{label:r.ctaLabel??"Open settings",href:l}:null}function Rt(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.subscribable;if(!t||typeof t!="object"||Array.isArray(t))return null;const n=t;if(typeof n.connector_key!="string"||!n.connector_key||typeof n.resource_type!="string"||!n.resource_type||typeof n.resource_ref!="string"||!n.resource_ref||typeof n.label!="string"||!n.label)return null;const r=Array.isArray(n.suggested_event_keys)?n.suggested_event_keys.filter(o=>typeof o=="string"&&!!o):void 0;return{connector_key:n.connector_key,resource_type:n.resource_type,resource_ref:n.resource_ref,label:n.label,...r?.length?{suggested_event_keys:r}:{}}}const lt=new Set(["localhost","127.0.0.1","::1","[::1]"]);function Hn(e){return e?.trim().toLowerCase().replace(/^\.+|\.+$/g,"")||null}function at(e,t){const n=Hn(t);if(!n)return!1;const r=e.toLowerCase().replace(/\.$/,"");return r===n||r.endsWith(`.${n}`)}function it(e,t,n){try{const r=new URL(t),o=new URL(e,t),l=lt.has(o.hostname)&<.has(r.hostname),i=o.protocol===r.protocol&&(o.protocol==="https:"||o.protocol==="http:")&&at(o.hostname,n)&&at(r.hostname,n);return o.origin!==r.origin&&(l||i)&&(o.protocol=r.protocol,o.host=r.host),o.origin===r.origin&&o.pathname.startsWith("/api/v1/agents")&&(o.pathname=`/lobu${o.pathname}`),o.toString()}catch{return e}}const zn=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,wt=new Set(["suggest_actions"]),Me="Thinking…";function Wn(e){const{textOut:t,statusLine:n,errorText:r,toolCalls:o}=e,l=[];n===Me&&l.push({type:"reasoning"}),r&&l.push({type:"error",text:r});let i=t;return n&&n!==Me&&(i=t?`${t}
|
|
2
2
|
|
|
3
3
|
${n}`:n),i&&l.push({type:"text",text:i}),l.push(...o),l}const St=[];function Kn(e,t,n){return e?.length?e:n===0?t:[]}const Qe=a.createContext(null);function Ee(){const e=a.useContext(Qe);if(!e)throw new Error("useLobuChat must be used within <LobuChatProvider>");return e}function Do({messages:e,workspaceSlug:t=null,children:n}){const r=a.useMemo(()=>({messages:e,running:!1,append:()=>{},cancel:()=>{},pendingAttachments:[],addAttachments:()=>{},removeAttachment:()=>{},agentId:null,conversationId:"",workspaceSlug:t,currentSuggestions:null,starters:St}),[e,t]);return s.jsx(Qe.Provider,{value:r,children:n})}const Tt=/\[([^\]]*)\]\((\S*?\/api\/v1\/files\/[^)\s]+)\)/g;function ct(e){return e.replace(/<lobu_internal_context>[\s\S]*?<\/lobu_internal_context>\n*/g,"").replace(Tt,"").replace(/\n{3,}/g,`
|
|
4
4
|
|
|
5
|
-
`).trim()}function qn(e){const t=[];for(const n of e.matchAll(Tt)){const r=n[1]?.trim()||"file",o=n[2];o&&t.push({name:r,url:o})}return t}function Gn(e,t={}){if(typeof e=="string"){const r=ct(e);return r?[{type:"text",text:r}]:[]}if(!Array.isArray(e))return[];const n=[];for(const r of e){if(!r||typeof r!="object")continue;const o=r;if(o.type==="text"&&typeof o.text=="string"){const l=ct(o.text);l&&n.push({type:"text",text:l})}else t.showToolCalls&&o.type==="toolCall"&&typeof o.name=="string"&&!wt.has(o.name)?n.push({type:"tool-call",toolCallId:o.id??`tc-${n.length}`,toolName:o.name,args:o.arguments??{},...o.result!==void 0?{result:o.result}:{}}):t.showToolCalls&&o.type==="tool_use"&&typeof o.name=="string"&&n.push({type:"tool-call",toolCallId:o.id??`tc-${n.length}`,toolName:o.name,args:o.input??{},...o.result!==void 0?{result:o.result}:{}})}return n}function Yn(e){const t=[],n=r=>{for(const{name:o,url:l}of qn(r))t.push({id:`file-${t.length}`,name:o,url:l,isImage:zn.test(o)})};if(typeof e=="string")return n(e),t.length>0?t:void 0;if(Array.isArray(e)){for(const r of e){if(!r||typeof r!="object")continue;const o=r;if(o.type==="image"&&typeof o.data=="string"){const l=o.mimeType||"image/png";t.push({id:`img-${t.length}`,name:`image-${t.length+1}`,imageDataUrl:`data:${l};base64,${o.data}`,isImage:!0})}else o.type==="text"&&typeof o.text=="string"&&n(o.text)}return t.length>0?t:void 0}}function Jn(e,t){if(e.type==="bashExecution"){const r=e.content??{},o=e.timestamp?new Date(e.timestamp).getTime():void 0;return{id:e.id,role:"user",parts:[{type:"bash",command:r.command??"",output:r.output??"",exitCode:r.exitCode,cancelled:r.cancelled??!1}],createdAt:o&&!Number.isNaN(o)?o:void 0}}if(e.type!=="message"||e.isVerbose||e.role!=="assistant"&&e.role!=="user"&&e.role!=="system")return null;const n=e.timestamp?new Date(e.timestamp).getTime():void 0;return{id:e.id,role:e.role,parts:Gn(e.content,t),attachments:Yn(e.content),createdAt:n&&!Number.isNaN(n)?n:void 0}}const Qn=[],Xn=[];function Zn(e){let t=null;for(const n of e)n.type==="suggestion"&&(t=n.prompts.length>0?n.prompts:null);return t}function er(e,t){if(e.length===0)return null;const n=[];for(const r of e)if(r.type!=="suggestion"){if(r.type==="agent-error"){n.push({type:"error",text:String(r.error??"Agent reported an error.")});const o=yt(r.errorCode,{...t,provider:r.errorContext?.provider,model:r.errorContext?.model});o&&n.push({type:"tool-call",toolCallId:`error-run-${r.runId}`,toolName:"link-button",args:{label:o.label,url:o.href}});continue}n.push({type:"tool-call",toolCallId:`approval-event-${r.eventId}`,toolName:"tool-approval",args:{runId:r.runId,action:r.action,proposal:r.proposal,current:r.current,fields:r.fields??null,attribution:r.attribution??null,resourceKind:r.resourceKind??null,reason:r.reason??null,status:r.status??"pending",reviewedByName:r.reviewedByName??null}})}return n.length===0?null:{id:"history-interactions",role:"assistant",parts:n}}const tr=3e4,nr=3*tr,rr=15e3;function ut(e){try{return JSON.parse(e.data)}catch{return{content:e.data}}}const be=e=>`${e}-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;function or(e){const t=[],n=new Set;for(const r of e){if(!r||typeof r!="object")continue;const{title:o,message:l}=r;if(typeof o!="string"||typeof l!="string")continue;const i=o.trim(),c=l.trim();if(i.length===0||c.length===0)continue;const u=`${i}\0${c}`;n.has(u)||(n.add(u),t.push({title:i,message:c}))}return t.length>0?t:null}function Uo({agentId:e,workspaceSlug:t,thread:n="agent-panel",loadHistory:r=!0,ephemeralContext:o,onFirstUserMessage:l,children:i,initialDraft:c}){const u=zt(),d=a.useRef(null),m=a.useRef(null),y=a.useRef(!1),h=a.useRef(o),g=a.useRef(!1),w=a.useRef(null);h.current=o;const{data:E,isLoading:v}=Wt(e,n,{orgSlug:t,enabled:r&&!!e&&!!n}),T=E?.messages??Qn,H=E?.interactions??Xn,{data:U}=Kt(e,{enabled:!!e}),K=U?.starters??St,z=!!(U?.showToolCalls??U?.settings?.showToolCalls),[N,L]=a.useState([]),[G,le]=a.useState(!1),[$,q]=a.useState([]),[Y,R]=a.useState(null),S=a.useRef(!1);S.current=G;const C=a.useMemo(()=>T.map(I=>Jn(I,{showToolCalls:z})).filter(I=>I!==null),[T,z]),O=a.useRef(!1);a.useEffect(()=>{if(O.current||v||S.current)return;O.current=!0;const I=er(H,{workspaceSlug:t,agentId:e,webOrigin:typeof window>"u"?null:window.location.origin});L(I?[...C,I]:C),R(Zn(H))},[e,v,C,H,t]);const A=a.useCallback(()=>{u.invalidateQueries({queryKey:["agent-thread-messages",t,e,n]}),u.invalidateQueries({queryKey:["agent-threads",t,e]})},[u,t,e,n]),Z=a.useCallback(async()=>{if(d.current)return d.current;if(m.current)return m.current;if(!e)throw new Error("No agent selected");const I=(async()=>{const M=await tt(`${Be}/lobu/api/v1/agents`,{method:"POST",headers:{"Content-Type":"application/json",...t?{"x-lobu-org":t}:{}},credentials:"include",body:JSON.stringify({agentId:e,thread:n}),timeoutMs:2e4});if(!M.ok)throw await nt(M);const V=await M.json(),j=qt(),Q={sessionId:V.agentId,sseUrl:it(V.sseUrl,Be,j),messagesUrl:it(V.messagesUrl,Be,j)};return d.current=Q,Q})();m.current=I;try{return await I}catch(M){throw d.current=null,M}finally{m.current=null}},[e,t,n]),te=a.useCallback(async(I,M,V)=>{const j=crypto.randomUUID(),Q=new AbortController;w.current=Q;const W=f=>{L(p=>p.map(b=>b.id===V?{...b,parts:f}:b))};let B;try{B=await Z()}catch(f){W([{type:"text",text:`Error: ${f instanceof Error?f.message:"Could not start a session."}`}]);return}let X=await rt(B.sseUrl,{throwOnFailure:!0});const pe=[];let ie=null;const Re=()=>{const f=ie;ie=null,f?.()},we=f=>{pe.push(f),Re()},Se=(f,p)=>{const k=["question","link-button","tool-approval"].includes(f)?p.turnMessageId===j:p.messageId===j||Array.isArray(p.processedMessageIds)&&p.processedMessageIds.includes(j);(f==="closed"||k)&&we({kind:f,payload:p})};let me=!1,Te=null;const Ie=new Promise(f=>{Te=f});let ce=0,he=Date.now();const ue=f=>{he=Date.now();const p=Number(f.lastEventId);Number.isFinite(p)&&p>ce&&(ce=p)},ke=["output","status","complete","closed","agent-error","question","link-button","tool-approval","tool_use"],Ce=f=>{f.addEventListener("open",()=>{me=!0,Te?.()}),f.addEventListener("connected",b=>{ue(b),me||(me=!0,Te?.())}),f.addEventListener("ping",ue);const p=b=>k=>{ue(k);const ee=k;typeof ee.data=="string"&&Se(b,ut(ee))};for(const b of ke)f.addEventListener(b,p(b));f.addEventListener("error",b=>{const k=b;if(typeof k.data=="string"&&k.data){ue(b),Se("error",ut(k));return}f.readyState===EventSource.CLOSED&&we({kind:"error",payload:{error:"Connection closed"}})})};Ce(X);const _e=async()=>{X.close();let f=B.sseUrl;if(ce){const p=new URL(B.sseUrl,window.location.origin);p.searchParams.set("since",String(ce)),f=p.toString()}X=await rt(f,{throwOnFailure:!1}),Ce(X),he=Date.now()};await Promise.race([Ie,new Promise(f=>setTimeout(f,1500))]);const Oe=()=>{X.close(),Re()};Q.signal.addEventListener("abort",Oe,{once:!0});try{const f=h.current?.trim(),p=!!f&&!g.current;p&&(g.current=!0);let b;if(M.length>0){const x=new FormData;x.set("content",I),x.set("messageId",j),p&&f&&x.set("ephemeralContext",f);for(const _ of M)x.append("files",_,_.name);b={method:"POST",credentials:"include",body:x,timeoutMs:12e4}}else{const x={content:I,messageId:j};p&&f&&(x.ephemeralContext=f),b={method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(x),timeoutMs:2e4}}const k=await tt(B.messagesUrl,b);if(!k.ok)throw d.current=null,await nt(k);let ee="",D=Me,et=null;const ge=[],de=()=>Wn({textOut:ee,statusLine:D,errorText:et,toolCalls:ge});for(W(de());!Q.signal.aborted;){if(pe.length===0){let _;const ne=await Promise.race([new Promise(Ve=>{ie=()=>Ve(!0)}),new Promise(Ve=>{_=setTimeout(()=>Ve(!1),rr)})]);_&&clearTimeout(_),!ne&&Date.now()-he>=nr&&(await _e(),A());continue}const x=pe.shift();if(x){if(x.kind==="output")D=null,ee+=String(x.payload.content??"");else if(x.kind==="status")D=Me;else if(x.kind==="complete"){D=null;const _=x.payload.finalText;typeof _=="string"&&_.length>0&&(ee=_);const ne=x.payload.suggestions;ne!==void 0&&R(Array.isArray(ne)?or(ne):null),A(),W(de());return}else if(x.kind==="closed"){d.current=null;const _=x.payload.reason;D=`Session ended${_?`: ${_}`:""}.`,A(),W(de());return}else if(x.kind==="error"||x.kind==="agent-error"){D=null,et=typeof x.payload.error=="string"&&x.payload.error?x.payload.error:"Agent reported an error.";const _=x.payload.errorContext&&typeof x.payload.errorContext=="object"?x.payload.errorContext:void 0,ne=yt(x.payload.errorCode,{workspaceSlug:t,agentId:e,webOrigin:typeof window>"u"?null:window.location.origin,provider:typeof _?.provider=="string"?_.provider:void 0,model:typeof _?.model=="string"?_.model:void 0});ne&&ge.push({type:"tool-call",toolCallId:be("l"),toolName:"link-button",args:{label:ne.label,url:ne.href}}),A(),W(de());return}else if(x.kind==="question")ge.push({type:"tool-call",toolCallId:be("q"),toolName:"question",args:{question:x.payload.question??"",options:x.payload.options??[]}});else if(x.kind==="tool_use"){if(D=null,wt.has(x.payload.name??"")){W(de());continue}const _=x.payload.result_summary,ne=Rt(_);if(!z&&!ne){W(de());continue}ge.push({type:"tool-call",toolCallId:x.payload.toolCallId??be("t"),toolName:z?x.payload.name??"tool":"subscription-candidate",args:z?x.payload.input??{}:null,result:_,isError:x.payload.isError})}else if(x.kind==="link-button")ge.push({type:"tool-call",toolCallId:be("l"),toolName:"link-button",args:{label:x.payload.label??"Open link",url:x.payload.url??""}});else if(x.kind==="tool-approval"){const _=x.payload.runId;if(typeof _!="number")continue;ge.push({type:"tool-call",toolCallId:`run-${_}`,toolName:"tool-approval",args:{runId:_,action:x.payload.action??null,proposal:x.payload.proposal??null,current:x.payload.current??null,fields:x.payload.fields??null,attribution:x.payload.attribution??null,resourceKind:x.payload.resourceKind??null}})}W(de())}}}catch(f){W([{type:"text",text:`Error: ${f instanceof Error?f.message:"Send failed."}`}])}finally{Q.signal.removeEventListener("abort",Oe),X.close()}},[e,Z,A,z,t]),re=a.useCallback(I=>{const M=I.trim(),V=$.map(B=>B.file);if(!M&&V.length===0||S.current||!e)return;y.current||(y.current=!0,l?.(M||V[0]?.name||""));const j={id:be("u"),role:"user",parts:M?[{type:"text",text:M}]:[],attachments:$.map(B=>({id:B.id,name:B.name,isImage:B.isImage,imageDataUrl:B.isImage?URL.createObjectURL(B.file):void 0})),createdAt:Date.now()},Q=be("asst"),W={id:Q,role:"assistant",parts:[{type:"reasoning"}],createdAt:Date.now()};L(B=>[...B,j,W]),q([]),le(!0),S.current=!0,te(M,V,Q).finally(()=>{le(!1),S.current=!1,w.current=null})},[e,l,$,te]),se=a.useCallback(()=>{w.current?.abort()},[]),ye=a.useCallback(I=>{const M=Array.from(I);q(V=>[...V,...M.map(j=>({id:crypto.randomUUID(),name:j.name,file:j,isImage:j.type.startsWith("image/")}))])},[]),J=a.useCallback(I=>{q(M=>M.filter(V=>V.id!==I))},[]),ae=a.useRef(!1);a.useEffect(()=>{if(ae.current)return;const I=jn(n);I&&(ae.current=!0,re(I))},[n,re]);const F=a.useMemo(()=>({messages:N,running:G,append:re,cancel:se,pendingAttachments:$,addAttachments:ye,removeAttachment:J,initialDraft:c,agentId:e,conversationId:n,workspaceSlug:t,currentSuggestions:Y,starters:K}),[N,G,re,se,$,ye,J,c,e,n,t,Y,K]);return r&&v?s.jsx(wn,{}):s.jsx(Qe.Provider,{value:F,children:i})}const dt="mx-0.5 inline-flex items-center gap-1 rounded-md bg-accent px-1.5 py-0.5 align-baseline font-medium text-[0.9em] text-accent-foreground no-underline";function sr({refItem:e}){const t=In[e.kind]??Gt;return kn(e.path)?s.jsxs("span",{className:dt,children:[s.jsx(t,{className:"h-3 w-3 shrink-0 opacity-70"}),e.label]}):s.jsxs(gt,{to:e.path,className:P(dt,"hover:bg-accent/80"),children:[s.jsx(t,{className:"h-3 w-3 shrink-0 opacity-70"}),e.label]})}const Xe=({text:e,renderText:t})=>En(e)?s.jsx(s.Fragment,{children:An(e).map((n,r)=>n.type==="ref"?s.jsx(sr,{refItem:n.ref},`r${r}`):s.jsx("span",{children:t(n.text)},`t${r}`))}):s.jsx(s.Fragment,{children:t(e)}),lr=({label:e="Thinking"})=>s.jsx("span",{className:"aui-thinking-shimmer inline-block text-sm","aria-live":"polite","aria-busy":"true",children:e}),Ct=a.createContext(null),jt=()=>{const e=a.useContext(Ct);if(!e)throw new Error("ChainOfThought components must be used within ChainOfThought");return e},Nt=a.memo(({className:e,open:t,defaultOpen:n=!1,onOpenChange:r,children:o,...l})=>{const[i,c]=Yt({prop:t,defaultProp:n,onChange:r}),u=a.useMemo(()=>({isOpen:i,setIsOpen:c}),[i,c]);return s.jsx(Ct.Provider,{value:u,children:s.jsx("div",{className:P("not-prose max-w-prose space-y-4",e),...l,children:o})})}),Et=a.memo(({className:e,children:t,...n})=>{const{isOpen:r,setIsOpen:o}=jt();return s.jsx(bt,{onOpenChange:o,open:r,children:s.jsxs(Jt,{className:P("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",e),...n,children:[s.jsx(Qt,{className:"size-4"}),s.jsx("span",{className:"flex-1 text-left",children:t??"Chain of Thought"}),s.jsx(Xt,{className:P("size-4 transition-transform",r?"rotate-180":"rotate-0")})]})})}),At=a.memo(({className:e,icon:t=en,label:n,description:r,status:o="complete",children:l,...i})=>{const c={complete:"text-muted-foreground",active:"text-foreground",pending:"text-muted-foreground/50"};return s.jsxs("div",{className:P("flex gap-2 text-sm",c[o],"fade-in-0 slide-in-from-top-2 animate-in",e),...i,children:[s.jsxs("div",{className:"relative mt-0.5",children:[s.jsx(t,{className:"size-4"}),s.jsx("div",{className:"-mx-px absolute top-7 bottom-0 left-1/2 w-px bg-border"})]}),s.jsxs("div",{className:"flex-1 space-y-2 overflow-hidden",children:[s.jsx("div",{children:n}),r&&s.jsx("div",{className:"text-muted-foreground text-xs",children:r}),l]})]})}),It=a.memo(({className:e,children:t,...n})=>{const{isOpen:r}=jt();return s.jsx(bt,{open:r,children:s.jsx(Zt,{className:P("mt-2 space-y-3","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",e),...n,children:t})})});Nt.displayName="ChainOfThought";Et.displayName="ChainOfThoughtHeader";At.displayName="ChainOfThoughtStep";It.displayName="ChainOfThoughtContent";function ar(e){return{contentIds:e.filter(n=>Number.isSafeInteger(n)&&n>0),sortBy:"date",sortOrder:"asc"}}function ir({ownerSlug:e,eventIds:t}){const n=t.join(","),r=a.useMemo(()=>ar(n.split(",").map(Number)),[n]);return r.contentIds.length===0?null:s.jsx(tn,{owner:e,children:({organizationId:o,ownerSlug:l})=>o?s.jsx(Mn,{organizationId:o,ownerSlug:l,filters:r,hideOriginator:!0}):null})}function cr({defaultTagName:e,props:t,render:n,state:r={},stateAttributesMapping:o}){let l=ze(ur(r,o),t);if(!n)return a.createElement(e,l);if(typeof n=="function")return n(l,r);if(!a.isValidElement(n))return null;let i=n.props,c={...ze(l,i),ref:Ae(l.ref,i.ref)};return a.cloneElement(n,c)}function ze(...e){let t={};for(let n of e){if(!n)continue;let r=n;for(let o of Object.keys(r)){let l=r[o];if(l===void 0)continue;let i=t[o];o==="className"?t[o]=[i,l].filter(Boolean).join(" "):o==="style"?t[o]={...i,...l}:o==="ref"?t[o]=Ae(i,l):fr(o)&&typeof i=="function"&&typeof l=="function"?t[o]=dr(l,i):t[o]=l}}return t}function ur(e,t){let n={};for(let r of Object.keys(e)){let o=e[r],l=t?.[r]?.(o);if(l){Object.assign(n,l);continue}if(r==="slot"){n["data-slot"]=o;continue}let i=`data-${String(r).replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`)}`;typeof o=="boolean"?n[i]=o?"":void 0:o!=null&&(n[i]=String(o))}return n}function dr(e,t){return function(n){e(n),n.defaultPrevented||t(n)}}function fr(e){return/^on[A-Z]/.test(e)}function Ae(...e){let t=e.filter(Boolean);if(t.length!==0)return n=>{for(let r of t)typeof r=="function"?r(n):r&&(r.current=n)}}var pr=8,mr=64,hr=0,Le=.5,gr=180,br=new Set(["ArrowDown","ArrowUp","End","Home","PageDown","PageUp"," "]),kt={start:!1,end:!1},xr=[],$e={currentAnchorId:null,visibleMessageIds:xr};function vr({content:e,scrollEdgeThreshold:t,spacer:n,viewport:r}){if(!r||!e)return kt;let o=Ze({content:e,spacer:n,viewport:r});return{start:r.scrollTop>t,end:o-r.scrollTop-r.clientHeight>t}}function yr({content:e,scrollMargin:t,scrollPreviousItemPeek:n,spacer:r,viewport:o,visibleMessageIds:l}){if(!e||!o)return $e;let i=o.getBoundingClientRect(),c=i.top+t+n,u=typeof IntersectionObserver>"u",d=[],m=null;for(let y of je(e,r)){let h=y.dataset.messageId;if(!h)continue;let g=y.dataset.scrollAnchor==="true",w=g||u?y.getBoundingClientRect():null;(u&&w?w.bottom>c&&w.top<i.bottom:l.has(h))&&d.push(h),g&&w&&w.top<=c+Le&&(m=h)}return d.length===0&&m===null?$e:{currentAnchorId:m,visibleMessageIds:d}}function je(e,t){return Array.from(e.children).filter(n=>n instanceof HTMLElement&&n!==t)}function Rr(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r?.dataset.scrollAnchor==="true")return r}return null}function wr(e,t){for(let n of e)if(n.dataset.scrollAnchor==="true"&&!t.has(n))return n;return null}function Sr(e,t){let n=0;for(let r=t;r<e.length;r++)if(e[r]?.dataset.scrollAnchor==="true"&&(n+=1,n>1))return!0;return!1}function Tr(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.dataset.scrollAnchor==="true")return n}return null}function Cr({content:e,spacer:t,viewport:n}){let r=n.getBoundingClientRect();for(let o of je(e,t)){if(!o.dataset.messageId)continue;let l=o.getBoundingClientRect();if(l.bottom>r.top&&l.top<r.bottom)return o}return null}function jr({align:e,element:t,scrollMargin:n,spacer:r,viewport:o}){let l=_t(t,o),i=t.getBoundingClientRect().height,c=Ar(r);if(e==="center"){let u=Math.max(0,o.clientHeight-c.start-c.end);return l-c.start-(u-i)/2-n}if(e==="end")return l-o.clientHeight+i+c.end+n;if(e==="nearest"){let u=l+i,d=o.scrollTop+c.start,m=o.scrollTop+o.clientHeight-c.end;return l>=d&&u<=m?o.scrollTop:l<d?l-c.start-n:u-o.clientHeight+c.end+n}return l-c.start-n}function _t(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.top-r.top+t.scrollTop}function Pe(e,t){return e.getBoundingClientRect().top-t.getBoundingClientRect().top}function Nr({content:e,scrollTop:t,spacer:n,viewport:r}){let o=Ze({content:e,spacer:n,viewport:r});return t+r.clientHeight-o}function Ze({content:e,spacer:t,viewport:n}){let r=je(e,t),o=Ot(e),l=n.getBoundingClientRect(),i=n.scrollTop,c=o.start+o.end;for(let u of r){let d=u.getBoundingClientRect();c=Math.max(c,d.bottom-l.top+i+o.end)}return c}function Er(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function Ot(e){let t=window.getComputedStyle(e);return{end:We(t.paddingBlockEnd||t.paddingBottom),start:We(t.paddingBlockStart||t.paddingTop)}}function Ar(e){let t=e?.parentElement;return t?Ot(t):{end:0,start:0}}function Ir(e){if(!e)return 0;let t=window.getComputedStyle(e),n=t.rowGap==="normal"?t.gap:t.rowGap;return We(n)}function We(e){if(!e)return 0;let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function kr({refs:e,commitScrollState:t,scheduleStateCommit:n,scheduleVisibilitySync:r}){let{streamingTurnRef:o,autoScrollRef:l,autoscrollingRef:i,autoscrollingTimeoutRef:c,contentRef:u,defaultScrollPositionAppliedRef:d,itemCountRef:m,messageElementsRef:y,modeRef:h,pendingScrollToMessageRef:g,prependRestoreRef:w,scrollMarginRef:E,scrollPreviousItemPeekRef:v,spacerGapRef:T,spacerHeightRef:H,spacerRef:U,viewportRef:K}=e,z=a.useCallback(R=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null),i.current!==R&&(i.current=R,t()),R&&(c.current=window.setTimeout(()=>{c.current=null,i.current=!1,t()},gr))},[t]),N=a.useCallback(R=>{let S=U.current;if(!S)return;let C=Math.max(0,Math.ceil(R));H.current!==C&&(H.current=C,S.hidden=C===0,S.style.height=`${C}px`,S.style.marginTop=C>0?`${-T.current}px`:"")},[]),L=a.useCallback((R,{behavior:S="auto",autoscrolling:C=!1}={})=>{let O=K.current;if(!O)return;let A=Math.max(0,R);if(Math.abs(O.scrollTop-A)<=Le){O.scrollTop=A,t();return}C&&z(!0),O.scrollTo({top:A,behavior:S}),n()},[t,n,z]),G=a.useCallback(({behavior:R="auto"}={})=>K.current?(N(0),o.current=null,h.current="free-scrolling",L(0,{behavior:R}),r(),!0):!1,[r,L,N]),le=a.useCallback(({behavior:R="auto"}={})=>{let S=K.current;return S?(N(0),o.current=null,h.current=l.current?"following-bottom":"free-scrolling",L(Er(S),{autoscrolling:!0,behavior:R}),r(),!0):!1},[r,L,N]),$=a.useCallback((R,{align:S="start",behavior:C="auto",scrollMargin:O=E.current}={},{keepPreviousPeek:A=!1}={})=>{let Z=u.current,te=K.current;if(!Z||!te||!Z.contains(R))return!1;let re=jr({align:S,element:R,scrollMargin:A?O+v.current:O,spacer:U.current,viewport:te}),se=Nr({content:Z,scrollTop:re,spacer:U.current,viewport:te});return N(se),w.current={element:R,viewportTop:Pe(R,te)},h.current=A?"anchored-to-message":"settling-jump",o.current=A?R:null,L(re,{behavior:C}),r(),!0},[r,L,N]),q=a.useCallback(()=>{let R=o.current;return!R||!R.isConnected||h.current!=="anchored-to-message"?!1:$(R,{align:"start"},{keepPreviousPeek:!0})},[$]),Y=a.useCallback((R,S)=>{let C=y.current.get(R);return C?(d.current=!0,$(C,S)?(g.current=null,!0):(g.current={messageId:R,options:S},!0)):m.current===0?(g.current={messageId:R,options:S},d.current=!0,!0):!1},[$]);return{flushPendingScrollToMessage:a.useCallback(()=>{let R=g.current;if(!R)return!1;let S=y.current.get(R.messageId);return!S||!$(S,R.options)?!1:(g.current=null,d.current=!0,!0)},[$]),reanchorToAnchoredMessage:q,scrollToElement:$,scrollToEnd:le,scrollToMessage:Y,scrollToStart:G}}function Pt(e,t){let n=e,r=new Set;return{getSnapshot:()=>n,hasListeners:()=>r.size>0,setSnapshot:o=>{t(n,o)||(n=o,r.forEach(l=>l()))},subscribe:(o,l,i)=>{let c=r.size===0;return r.add(o),c&&l?.(),()=>{r.delete(o),r.size===0&&i?.()}}}}function _r(e,t){return Pt(e,t)}function Or(){return Pt($e,Mr)}function Pr(e,t){return e.start===t.start&&e.end===t.end}function Mr(e,t){return e.currentAnchorId!==t.currentAnchorId||e.visibleMessageIds.length!==t.visibleMessageIds.length?!1:e.visibleMessageIds.every((n,r)=>n===t.visibleMessageIds[r])}function Lr({autoScroll:e,scrollEdgeThreshold:t,scrollMargin:n,scrollPreviousItemPeek:r}){let o=a.useRef(e),l=a.useRef(!1),i=a.useRef(null),c=a.useRef(!1),u=a.useRef(t),d=a.useRef(0),m=a.useRef(null),y=a.useRef(0),h=a.useRef(e?"following-bottom":"free-scrolling"),g=a.useRef(new Map),w=a.useRef(null),E=a.useRef(null),v=a.useRef(null),T=a.useRef(r),H=a.useRef(!0),U=a.useRef(null),K=a.useRef(n),z=a.useRef(null),N=a.useRef(0),L=a.useRef(0),G=a.useRef(null),le=a.useRef(null),$=a.useRef(null),q=a.useRef(null),Y=a.useRef(null),R=a.useRef(null),S=a.useRef(null),C=a.useRef(null),O=a.useRef(new Set),A=a.useRef(new WeakSet);return $.current===null&&($.current=_r(kt,Pr)),C.current===null&&(C.current=Or()),o.current=e,u.current=t,K.current=n,T.current=r,{autoScrollRef:o,autoscrollingRef:l,autoscrollingTimeoutRef:q,streamingTurnRef:v,contentRef:i,defaultScrollPositionAppliedRef:c,firstItemRef:m,itemCountRef:d,lastScrollTopRef:y,messageElementsRef:g,modeRef:h,pendingScrollFrameRef:z,pendingScrollToMessageRef:w,prependRestoreRef:E,preserveScrollOnPrependRef:H,rootRef:U,scrollEdgeThresholdRef:u,scrollMarginRef:K,scrollPreviousItemPeekRef:T,spacerGapRef:N,spacerHeightRef:L,spacerRef:G,stateFrameRef:le,stateStore:$.current,viewportRef:Y,visibilityFrameRef:R,visibilityObserverRef:S,visibilityStore:C.current,visibleMessageIdsRef:O,handledScrollAnchorsRef:A}}function ft(e,t){return a.useCallback(n=>{e.current=n,n&&t()},[e,t])}function $r({autoScroll:e=!1,defaultScrollPosition:t="end",scrollEdgeThreshold:n=pr,scrollPreviousItemPeek:r=mr,scrollMargin:o=hr}){let l=Lr({autoScroll:e,scrollEdgeThreshold:n,scrollMargin:o,scrollPreviousItemPeek:r}),{streamingTurnRef:i,autoScrollRef:c,autoscrollingRef:u,autoscrollingTimeoutRef:d,contentRef:m,defaultScrollPositionAppliedRef:y,firstItemRef:h,itemCountRef:g,lastScrollTopRef:w,messageElementsRef:E,modeRef:v,pendingScrollFrameRef:T,pendingScrollToMessageRef:H,prependRestoreRef:U,preserveScrollOnPrependRef:K,rootRef:z,scrollEdgeThresholdRef:N,scrollMarginRef:L,scrollPreviousItemPeekRef:G,spacerGapRef:le,spacerHeightRef:$,spacerRef:q,stateFrameRef:Y,stateStore:R,viewportRef:S,visibilityFrameRef:C,visibilityObserverRef:O,visibilityStore:A,visibleMessageIdsRef:Z,handledScrollAnchorsRef:te}=l,re=a.useRef(t);re.current!==t&&(re.current=t,y.current=!1);let se=a.useCallback(f=>{let p=z.current,b=S.current,k=[f.start&&"start",f.end&&"end"].filter(Boolean).join(" "),ee=u.current;for(let D of[p,b])D&&(k?D.setAttribute("data-scrollable",k):D.removeAttribute("data-scrollable"),D.toggleAttribute("data-autoscrolling",ee))},[]),ye=a.useCallback(f=>{let p=S.current?.scrollTop??0,b=p<w.current-Le;w.current=p,c.current&&!f.end&&v.current!=="settling-jump"&&v.current!=="anchored-to-message"?v.current="following-bottom":v.current==="following-bottom"&&f.end&&b&&!u.current&&(v.current="free-scrolling")},[]),J=a.useCallback(()=>{let f=vr({content:m.current,scrollEdgeThreshold:N.current,spacer:q.current,viewport:S.current});ye(f);let p=v.current==="following-bottom"?{...f,end:!1}:f;se(p),R.setSnapshot(p)},[ye,R,se]),ae=a.useCallback(()=>{Y.current===null&&(Y.current=window.requestAnimationFrame(()=>{Y.current=null,J()}))},[J]),F=a.useCallback(()=>{A.hasListeners()&&C.current===null&&(C.current=window.requestAnimationFrame(()=>{C.current=null,A.hasListeners()&&A.setSnapshot(yr({content:m.current,scrollMargin:L.current,scrollPreviousItemPeek:G.current,spacer:q.current,viewport:S.current,visibleMessageIds:Z.current}))}))},[A]),{flushPendingScrollToMessage:I,reanchorToAnchoredMessage:M,scrollToElement:V,scrollToEnd:j,scrollToMessage:Q,scrollToStart:W}=kr({refs:l,commitScrollState:J,scheduleStateCommit:ae,scheduleVisibilitySync:F}),B=a.useCallback(()=>{let f=U.current,p=S.current;if(!f||!p||!f.element.isConnected)return!1;let b=Pe(f.element,p)-f.viewportTop;return Math.abs(b)<=Le?!1:(p.scrollTop+=b,f.viewportTop=Pe(f.element,p),ae(),F(),!0)},[ae,F]),X=a.useCallback(()=>{let f=m.current,p=S.current;if(!f||!p){U.current=null;return}let b=Cr({content:f,spacer:q.current,viewport:p});U.current=b?{element:b,viewportTop:Pe(b,p)}:null},[]),pe=a.useCallback(()=>{T.current===null&&(T.current=window.requestAnimationFrame(()=>{T.current=null,I()&&X()}))},[X,I]),ie=a.useCallback(()=>{if(!t||y.current||g.current===0)return!1;let f=!1;if(t==="last-anchor"){let p=m.current,b=S.current,k=p&&b?Tr(je(p,q.current)):null;if(!p||!b||!k)f=j({behavior:"auto"});else{let ee=_t(k,b);f=Ze({content:p,spacer:q.current,viewport:b})-ee<=b.clientHeight?j({behavior:"auto"}):V(k,{align:"start"},{keepPreviousPeek:!0})}}else f=t==="end"?j({behavior:"auto"}):W({behavior:"auto"});return f?(y.current=!0,!0):!1},[t,V,j,W]),Re=a.useCallback(()=>{let f=m.current;if(!f)return;let p=je(f,q.current),b=g.current,k=h.current;g.current=p.length,h.current=p[0]??null,(()=>{if(I())return;if(b===0){if(ie()||p.length>0&&c.current&&j({behavior:"auto"}))return;J(),F();return}let ee=k?p.indexOf(k):-1;if(K.current&&ee>0){B();return}if(p.length>b){let D=Rr(p,b);if(D){if(c.current&&v.current==="following-bottom"&&Sr(p,b)){j({behavior:"auto"});return}V(D,{align:"start"},{keepPreviousPeek:!0}),te.current.add(D);return}}if(p.length===b){let D=wr(p,te.current);if(D){V(D,{align:"start"},{keepPreviousPeek:!0}),te.current.add(D);return}}v.current==="following-bottom"&&c.current?j({behavior:"auto"}):(J(),F())})(),X()},[ie,X,J,I,B,F,V,j]),we=a.useCallback(()=>{if(v.current==="following-bottom"&&c.current){j({behavior:"auto"});return}let f=$.current;if(M()){c.current&&f>0&&$.current===0&&j({behavior:"auto"});return}ae(),F()},[M,ae,F,j]),Se=a.useCallback(()=>{let f=S.current;if(!(!f||!A.hasListeners())){if(typeof IntersectionObserver>"u"){F();return}O.current||(O.current=new IntersectionObserver(p=>{for(let b of p){let k=b.target.dataset.messageId;k&&(b.isIntersecting?Z.current.add(k):Z.current.delete(k))}F()},{root:f,rootMargin:`${-(L.current+G.current)}px 0px 0px 0px`,threshold:[0,.01,.5,1]})),E.current.forEach(p=>{O.current?.observe(p)}),F()}},[F,A]),me=a.useCallback(()=>{C.current!==null&&(window.cancelAnimationFrame(C.current),C.current=null),O.current?.disconnect(),O.current=null,Z.current.clear(),A.setSnapshot($e)},[A]),Te=a.useCallback((f,p,b)=>{if(p){E.current.set(f,p),O.current?.observe(p),F(),H.current?.messageId===f&&pe();return}b&&E.current.get(f)===b&&(E.current.delete(f),Z.current.delete(f),O.current?.unobserve(b),F())},[pe,F]),Ie=a.useCallback(()=>{(v.current==="following-bottom"||v.current==="anchored-to-message"||v.current==="settling-jump")&&(i.current=null,v.current="free-scrolling")},[]),ce=a.useCallback(()=>se(R.getSnapshot()),[R,se]),he=ft(z,ce),ue=ft(S,ce),ke=a.useCallback(f=>{m.current=f},[]),Ce=a.useCallback(f=>{q.current=f,le.current=Ir(f?.parentElement??null)},[]),_e=a.useCallback(()=>{J(),F(),X()},[X,J,F]),Oe=a.useMemo(()=>({handleContentChange:Re,handleResize:we,observeVisibility:Se,preserveScrollOnPrependRef:K,scrollToEnd:j,scrollToMessage:Q,scrollToStart:W,setContentElement:ke,setRootElement:he,setSpacerElement:Ce,setViewportElement:ue,stateStore:R,syncAfterScroll:_e,unobserveVisibility:me,userScrollIntent:Ie,viewportRef:S,visibilityStore:A}),[Re,we,Se,j,Q,W,ke,he,Ce,ue,R,_e,me,Ie,A]);return a.useLayoutEffect(()=>{ie()},[ie]),a.useEffect(()=>()=>{Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null),C.current!==null&&(window.cancelAnimationFrame(C.current),C.current=null),d.current!==null&&(window.clearTimeout(d.current),d.current=null),T.current!==null&&(window.cancelAnimationFrame(T.current),T.current=null),O.current?.disconnect(),O.current=null},[]),a.useLayoutEffect(()=>{if(e&&v.current==="following-bottom"&&g.current>0){j({behavior:"auto"});return}J()},[e,J,j]),{context:Oe,registerMessage:Te}}function Dr(e){let t=a.useRef(e);return t.current=e,t}var Mt=a.createContext(null),Lt=a.createContext(null);function xe(){let e=a.useContext(Mt);if(!e)throw new Error("useMessageScroller must be used within a MessageScroller.");return e}function Ur(){let e=a.useContext(Lt);if(!e)throw new Error("MessageScrollerItem must be used within a MessageScroller.");return e}function $t(){let{scrollToEnd:e,scrollToMessage:t,scrollToStart:n}=xe();return a.useMemo(()=>({scrollToEnd:e,scrollToMessage:t,scrollToStart:n}),[e,t,n])}function Dt(){let{observeVisibility:e,unobserveVisibility:t,visibilityStore:n}=xe(),r=a.useCallback(o=>n.subscribe(o,e,t),[e,t,n]);return a.useSyncExternalStore(r,n.getSnapshot,n.getSnapshot)}function Fr({autoScroll:e=!1,children:t,defaultScrollPosition:n="end",scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:l}){let{context:i,registerMessage:c}=$r({autoScroll:e,defaultScrollPosition:n,scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:l});return s.jsx(Mt.Provider,{value:i,children:s.jsx(Lt.Provider,{value:c,children:t})})}function Vr({children:e,...t}){let{setRootElement:n}=xe();return s.jsx("div",{ref:n,...t,children:e})}function Br({"aria-label":e,children:t,onKeyDown:n,onScroll:r,onTouchMove:o,onWheel:l,preserveScrollOnPrepend:i=!0,ref:c,role:u,tabIndex:d,...m}){let{handleResize:y,preserveScrollOnPrependRef:h,setViewportElement:g,syncAfterScroll:w,userScrollIntent:E,viewportRef:v}=xe();h.current=i;let T=a.useCallback(N=>{g(N),Ae(c)?.(N)},[c,g]);function H(N){w(),r?.(N)}function U(N){E(),l?.(N)}function K(N){E(),o?.(N)}function z(N){br.has(N.key)&&E(),n?.(N)}return a.useEffect(()=>{let N=v.current;if(!N||typeof ResizeObserver>"u")return;let L=0,G=new ResizeObserver(()=>{window.cancelAnimationFrame(L),L=window.requestAnimationFrame(y)});return G.observe(N),()=>{window.cancelAnimationFrame(L),G.disconnect()}},[y,v]),s.jsx("div",{ref:T,role:u??"region","aria-label":e??"Messages",tabIndex:d??0,onKeyDown:z,onScroll:H,onTouchMove:K,onWheel:U,...m,children:t})}function Hr({"aria-relevant":e,children:t,ref:n,role:r,spacerClassName:o,...l}){let{handleContentChange:i,handleResize:c,setContentElement:u,setSpacerElement:d}=xe(),m=a.useRef(null),y=a.useCallback(h=>{m.current=h,u(h),Ae(n)?.(h)},[n,u]);return a.useLayoutEffect(()=>{let h=m.current;if(!h||(i(),typeof MutationObserver>"u"))return;let g=new MutationObserver(()=>{i()});return g.observe(h,{childList:!0}),()=>g.disconnect()},[i]),a.useEffect(()=>{let h=m.current;if(!h||typeof ResizeObserver>"u")return;let g=0,w=new ResizeObserver(()=>{window.cancelAnimationFrame(g),g=window.requestAnimationFrame(c)});return w.observe(h),()=>{window.cancelAnimationFrame(g),w.disconnect()}},[c]),s.jsxs("div",{ref:y,role:r??"log","aria-relevant":e??"additions",...l,children:[t,s.jsx("div",{ref:d,"aria-hidden":"true","data-message-scroller-spacer":"",hidden:!0,className:o})]})}function zr({messageId:e,ref:t,scrollAnchor:n=!1,...r}){let o=Ur(),l=a.useRef(null),i=a.useCallback(c=>{let u=l.current;l.current=c,e&&o(e,c,u),Ae(t)?.(c)},[e,t,o]);return s.jsx("div",{ref:i,"data-message-id":e,"data-scroll-anchor":n?"true":"false",...r})}function Wr({behavior:e="smooth",children:t,direction:n="end",onClick:r,render:o,tabIndex:l,type:i="button",...c}){let{scrollToEnd:u,scrollToStart:d,stateStore:m}=xe(),y=Dr(r),h=a.useCallback(v=>m.subscribe(v),[m]),g=a.useCallback(()=>{let v=m.getSnapshot();return n==="start"?v.start:v.end},[n,m]),w=a.useSyncExternalStore(h,g,g),E=a.useCallback(v=>{w&&(y.current?.(v),v.defaultPrevented||(v.currentTarget.blur(),n==="start"?d({behavior:e}):u({behavior:e})))},[e,n,w,y,u,d]);return cr({defaultTagName:"button",props:ze({type:i,inert:!w,tabIndex:w?l:-1,children:t??s.jsxs("span",{children:["Scroll to ",n]}),onClick:E},c),render:o,state:{active:w,direction:n},stateAttributesMapping:{active:v=>({"data-active":v?"true":"false"})}})}var ve={Provider:Fr,Root:Vr,Viewport:Br,Content:Hr,Item:zr,Button:Wr};const Kr=ve.Provider;function qr({className:e,...t}){return s.jsx(ve.Root,{className:P("relative flex size-full min-h-0 flex-col overflow-hidden",e),...t})}function Gr({className:e,...t}){return s.jsx(ve.Viewport,{className:P("size-full min-h-0 overflow-y-auto overscroll-contain [scrollbar-gutter:stable]",e),...t})}function Yr({className:e,...t}){return s.jsx(ve.Content,{className:P("flex h-max min-h-full flex-col",e),...t})}function Jr({className:e,...t}){return s.jsx(ve.Item,{className:P("min-w-0 shrink-0",e),...t})}function Qr({className:e,...t}){return s.jsx(ve.Button,{direction:"end",behavior:"smooth",render:({active:n,...r})=>n?s.jsx(fe,{...r,type:"button",variant:"outline",size:"icon",className:P("absolute right-4 bottom-4 z-20 rounded-full bg-background ",e),"aria-label":"Scroll to latest message",children:s.jsx(nn,{})}):null,...t})}function Xr(e){if(!e)return"";const t=e.startsWith("?")?e.slice(1):e,n=new URLSearchParams(t);return n.get("message_id")?.trim()||n.get("message")?.trim()||""}function Zr(e){const t=e.scrollTarget.trim();return t?e.alreadyScrolledTo===t?{scroll:!1}:e.messageIds.includes(t)?{scroll:!0,id:t}:{scroll:!1}:{scroll:!1}}const eo="lobu-spa";function pt(e){return typeof e=="string"&&/^https?:\/\//i.test(e.trim())}function De(e,t){return t.type==="tool-call"?`tc-${t.toolCallId}`:t.type==="reasoning"?`${e.id}-reasoning`:t.type==="bash"?`${e.id}-bash-${t.command.slice(0,24)}`:t.type==="error"?`${e.id}-error`:`${e.id}-text-${t.text.slice(0,24)}`}const Fo=({afterMessagesContent:e,readOnly:t=!1,readerPositionMode:n="messages",interactionExtension:r,onRunSelect:o})=>{const{messages:l,agentId:i,conversationId:c}=Ee(),{data:u=[]}=rn(i,{conversationId:c});return s.jsx($n,{extension:r,children:s.jsxs("div",{"data-agent-thread":!0,className:"flex min-h-0 flex-1 flex-col",children:[s.jsx(to,{messages:l,trips:u,mode:n,afterMessagesContent:e,onRunSelect:o}),t?null:s.jsx("div",{className:Sn,children:s.jsx(Io,{})})]})})},to=({messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})=>s.jsx(Kr,{autoScroll:!0,defaultScrollPosition:n==="runs"?"last-anchor":"end",scrollPreviousItemPeek:48,children:s.jsx(ro,{messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})});function no(e){if(!e.startsWith("sep:"))return null;const t=Number(e.slice(4));return Number.isFinite(t)&&t>0?t:null}const ro=({messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})=>{const{currentAnchorId:l}=Dt(),{scrollToMessage:i}=$t(),c=a.useRef(null);a.useEffect(()=>{if(e.length===0||typeof window>"u")return;const d=Zr({messageIds:e.map(m=>m.id),scrollTarget:Xr(window.location.search),alreadyScrolledTo:c.current});d.scroll&&(c.current=d.id,i(d.id,{align:"start",behavior:"smooth"}))},[e,i]);const u=d=>n==="runs"?d.id.startsWith("sep:"):d.role==="user";return s.jsxs(qr,{children:[s.jsx(Gr,{"aria-label":n==="runs"?"Automation run history":"Conversation",children:s.jsxs(Yr,{className:P(Ge,Tn),children:[e.map(d=>{const m=n==="runs"&&o?no(d.id):null;return s.jsx(Jr,{messageId:d.id,scrollAnchor:u(d),"aria-current":d.id===l?"location":void 0,className:P("flex flex-col",n==="runs"&&u(d)&&"border-l-2 border-transparent pl-2 transition-colors",n==="runs"&&d.id===l&&"border-primary"),children:m!=null?s.jsx(xo,{message:d,onClick:()=>o?.(m)}):s.jsx(ao,{message:d})},d.id)}),t.map(d=>s.jsx(so,{trip:d},d.id)),s.jsx(lo,{}),r?s.jsx("div",{className:"mt-auto shrink-0 py-2",children:r}):null]})}),e.length>0?s.jsx(oo,{messages:e,mode:n}):null,s.jsx(Qr,{})]})},oo=({messages:e,mode:t})=>{const{scrollToMessage:n}=$t(),{currentAnchorId:r,visibleMessageIds:o}=Dt(),l=t==="runs"?e.flatMap(c=>c.parts).filter(c=>c.type==="tool-call"&&c.toolName==="tool-approval"&&c.args!==null&&typeof c.args=="object"&&c.args.status==="pending").length:0,i=e.flatMap(c=>{if(!(t==="runs"?c.id.startsWith("sep:"):c.role==="user"))return[];const d=c.parts.find(m=>m.type==="text");return[{id:c.id,label:d?.type==="text"?d.text:"Automation run"}]});return i.length===0?null:s.jsxs(cn,{children:[s.jsx(un,{asChild:!0,children:s.jsxs(fe,{type:"button",variant:"outline",size:"icon",className:P("absolute top-1/2 right-4 z-20 -translate-y-1/2 rounded-full bg-background/95 ",l>0&&"w-auto px-3"),"aria-label":l>0?`Open transcript outline, ${l} ${l===1?"approval":"approvals"} waiting`:"Open transcript outline",children:[s.jsx(dn,{}),l>0?s.jsxs("span",{className:"text-xs tabular-nums",children:[l," waiting"]}):null]})}),s.jsxs(fn,{side:"left",align:"center",className:"w-80 space-y-3 p-3",children:[s.jsxs("div",{className:"px-1",children:[s.jsx("p",{className:"text-sm font-medium",children:"Transcript outline"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:t==="runs"?"Track and jump between Automation runs.":"Track and jump between your messages."})]}),s.jsx("div",{className:"max-h-80 space-y-1 overflow-y-auto",children:i.map(c=>{const u=c.id===r,d=o.includes(c.id);return s.jsxs(fe,{type:"button",variant:u?"secondary":"ghost",className:"h-auto w-full justify-start gap-2 px-2 py-2 text-left text-xs font-normal","aria-current":u?"location":void 0,onClick:()=>n(c.id,{align:"start",behavior:"smooth"}),children:[s.jsx("span",{className:P("size-1.5 shrink-0 rounded-full bg-muted-foreground/30",d&&"bg-primary/60",u&&"bg-primary")}),s.jsx("span",{className:"line-clamp-2",children:c.label})]},c.id)})})]})]})},so=({trip:e})=>s.jsxs("div",{className:P(Ge,"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive"),children:[s.jsx(an,{className:"mt-0.5 size-4 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"font-medium",children:["Guardrail blocked: ",e.guardrailName," ",s.jsxs("span",{className:"font-normal opacity-70",children:["(",e.stage,")"]})]}),e.reason?s.jsx("div",{className:"mt-0.5 break-words opacity-80",children:e.reason}):null]})]}),lo=()=>{const{currentSuggestions:e,starters:t,messages:n,running:r,append:o}=Ee(),l=Kn(e,t,n.length);return r||l.length===0?null:s.jsx(Nn,{prompts:l,className:P(Ge,n.length===0&&"mt-auto"),onPick:i=>o(i)})},ao=({message:e})=>e.role==="user"?s.jsx(io,{message:e}):e.role==="system"?s.jsx(vo,{message:e}):s.jsx(fo,{message:e}),Ut=({attachment:e})=>{const t=e.isImage?e.imageDataUrl??e.url:void 0;if(t)return s.jsx("a",{href:e.url??t,target:"_blank",rel:"noreferrer",children:s.jsx("img",{src:t,alt:e.name,className:"max-h-64 rounded-lg border object-contain"})});const n=s.jsxs(s.Fragment,{children:[s.jsx(He,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"max-w-[14rem] truncate",children:e.name})]});return s.jsx("div",{className:"flex items-center gap-1.5 rounded-md border bg-background px-2 py-1 text-xs",children:e.url?s.jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 hover:underline",children:n}):n})},io=({message:e})=>{const t=e.parts.filter(n=>n.type==="bash");return t.length>0?s.jsx("div",{className:xt,children:s.jsx("div",{className:"space-y-2",children:t.map(n=>s.jsx(co,{part:n},De(e,n)))})}):s.jsx("div",{className:Cn,children:s.jsxs("div",{className:P(Ne,"px-3 py-2 text-sm"),children:[e.attachments&&e.attachments.length>0?s.jsx("div",{className:"mb-1.5 flex flex-wrap gap-1.5",children:e.attachments.map(n=>s.jsx(Ut,{attachment:n},n.id))}):null,e.parts.map(n=>n.type==="text"?s.jsx("div",{className:"whitespace-pre-wrap break-words",children:s.jsx(Xe,{text:n.text,renderText:r=>r})},De(e,n)):null)]})})},co=({part:e})=>{const t=e.cancelled||e.exitCode!==void 0&&e.exitCode!==0;return s.jsxs("div",{className:P(Ne,"overflow-hidden text-xs"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-border/60 border-b px-3 py-1.5",children:[s.jsx(pn,{className:"size-3.5 shrink-0 text-muted-foreground"}),s.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-foreground/90",children:e.command}),e.cancelled?s.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 font-medium text-[10px] text-muted-foreground",children:"cancelled"}):t?s.jsxs("span",{className:"rounded bg-destructive/15 px-1.5 py-0.5 font-medium text-[10px] text-destructive",children:["exit ",e.exitCode]}):null]}),e.output.trim()?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-3 py-2 font-mono text-foreground/80",children:e.output}):null]})},Ft=new Set(["question","link-button","tool-approval"]),uo="subscription-candidate",fo=({message:e})=>{const t=Ye(),{agentId:n,workspaceSlug:r}=Ee(),o=u=>u.type==="tool-call"&&(Ft.has(u.toolName)||t?.toolNames.has(u.toolName)),l=e.parts.filter(u=>u.type==="tool-call"&&!o(u)&&u.toolName!==uo),i=e.parts.filter(u=>u.type!=="tool-call"||o(u)),c=e.parts.flatMap(u=>{if(u.type!=="tool-call")return[];const d=Rt(u.result);return d?[d]:[]});return s.jsx("div",{className:xt,children:s.jsxs("div",{className:"space-y-2 text-sm",children:[l.length>0?s.jsx(ho,{tools:l,workspaceSlug:r}):null,n&&r?c.map(u=>s.jsx(po,{candidate:u,agentId:n,workspaceSlug:r},`${u.connector_key}:${u.resource_ref}`)):null,i.map(u=>s.jsx(bo,{part:u},De(e,u))),e.attachments&&e.attachments.length>0?s.jsx("div",{className:"flex flex-wrap gap-2",children:e.attachments.map(u=>s.jsx(Ut,{attachment:u},u.id))}):null]})})},po=({candidate:e,agentId:t,workspaceSlug:n})=>s.jsxs("div",{className:P(Ne,"flex items-center justify-between gap-3 p-3"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"truncate text-sm font-medium",children:e.label}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Run this agent when the resource changes."})]}),s.jsx(fe,{asChild:!0,size:"sm",variant:"outline",className:"shrink-0",children:s.jsxs(gt,{to:"/$owner/automations/new",params:{owner:n},search:{agent:t,platform:e.connector_key,resource_type:e.resource_type,resource:e.resource_ref,events:e.suggested_event_keys?.join(","),label:e.label},children:[s.jsx(hn,{className:"mr-1.5 h-4 w-4"}),"Add automation"]})})]});function mo(e){try{return JSON.parse(e)}catch{return null}}function Vt(e){if(Array.isArray(e)){const o=e.flatMap(l=>l?.type==="text"&&typeof l.text=="string"?Vt(l.text)??[]:[]);return o.length>0?[...new Set(o)]:null}const t=typeof e=="string"&&e.trimStart().startsWith("{")?mo(e):e;if(!t||typeof t!="object")return null;const n=t.events_persisted;if(!Array.isArray(n))return null;const r=n.flatMap(o=>{const l=o&&typeof o=="object"?o.id:null;return typeof l=="number"&&Number.isSafeInteger(l)&&l>0?[l]:[]});return r.length>0?r:null}const ho=({tools:e,workspaceSlug:t})=>s.jsxs(Nt,{defaultOpen:!1,children:[s.jsx(Et,{children:e.length===1?ot(e[0].args,e[0].toolName)??e[0].toolName:`${e.length} tool calls`}),s.jsx(It,{children:e.map(n=>{const r=ot(n.args,n.toolName),o=n.args!==void 0&&n.args!==null,l=n.result!==void 0&&n.result!==null,i=Vt(n.result);return s.jsxs(At,{icon:mn,label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"font-medium",children:r??n.toolName}),r?s.jsx("span",{className:"text-muted-foreground",children:n.toolName}):null,n.isError?s.jsx("span",{className:"rounded bg-destructive/15 px-1.5 py-0.5 font-medium text-[10px] text-destructive",children:"error"}):null]}),status:n.isError?"active":"complete",children:[o?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-foreground/80 text-xs",children:Fe(n.args)}):null,l?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-foreground/80 text-xs",children:Fe(n.result)}):null,i&&t?s.jsx(ir,{ownerSlug:t,eventIds:i}):null]},n.toolCallId)})})]}),go=({text:e})=>{let t=e,n=null;const r=e.match(/\{[\s\S]*\}/);if(r)try{const l=JSON.parse(r[0])?.error?.message;typeof l=="string"&&l.trim()&&(t=l,n=e)}catch{}return s.jsxs("div",{className:"flex gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2.5 text-sm",children:[s.jsx(bn,{className:"mt-0.5 size-4 shrink-0 text-destructive"}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx("p",{className:"text-foreground/80",children:t}),n&&s.jsxs("details",{className:"text-xs text-muted-foreground",children:[s.jsx("summary",{className:"cursor-pointer select-none hover:text-foreground",children:"Technical details"}),s.jsx("pre",{className:"mt-1 overflow-x-auto whitespace-pre-wrap break-all font-mono",children:n})]})]})]})},bo=({part:e})=>{const t=Ye();return e.type==="reasoning"?s.jsx(lr,{}):e.type==="error"?s.jsx(go,{text:e.text}):e.type==="text"?e.text.trim()?s.jsx(Xe,{text:e.text,renderText:n=>s.jsx(gn,{text:n})}):null:e.type!=="tool-call"?null:Ft.has(e.toolName)||t?.toolNames.has(e.toolName)?s.jsx(Ao,{toolName:e.toolName,args:e.args}):null},xo=({message:e,onClick:t})=>{const n=e.parts.find(r=>r.type==="text");return s.jsx("button",{type:"button",onClick:t,className:P(Ne,"block w-full cursor-pointer whitespace-pre-wrap break-words px-3 py-2 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/50"),children:n?.type==="text"?n.text:"Automation run"})},vo=({message:e})=>s.jsx("div",{className:"self-stretch",children:s.jsx("div",{className:P(Ne,"px-3 py-2 text-xs text-muted-foreground"),children:e.parts.map(t=>t.type==="text"?s.jsx("div",{className:"whitespace-pre-wrap break-words",children:s.jsx(Xe,{text:t.text,renderText:n=>n})},De(e,t)):null)})}),yo="/mcp-apps/interaction/index.html";function mt(e){return new Promise(t=>{e({onSettled:(n,r)=>t(!!r)})})}const Ro=({src:e,title:t,renderPayload:n,onToolCall:r,onOpenLink:o})=>{const l=a.useRef(null),[i,c]=a.useState(48),u=a.useRef({renderPayload:n,onToolCall:r,onOpenLink:o});return u.current={renderPayload:n,onToolCall:r,onOpenLink:o},a.useEffect(()=>{const d=l.current;if(!d?.contentWindow)return;const m=new yn(null,{name:"Lobu",version:"1.0.0"},{openLinks:{},serverTools:{}},{hostContext:{theme:document.documentElement.classList.contains("dark")?"dark":"light",displayMode:"inline",platform:"web"}});m.addEventListener("sizechange",({height:g})=>{typeof g=="number"&&c(Math.max(32,Math.ceil(g)))}),m.oncalltool=async({name:g,arguments:w})=>{const E=await u.current.onToolCall(g,w??{});return{isError:E,content:[{type:"text",text:E?"Action failed.":"Action completed."}]}},m.onopenlink=async({url:g})=>({isError:await u.current.onOpenLink(g)}),m.addEventListener("initialized",()=>{(async()=>(await m.sendToolInput({arguments:{}}),await m.sendToolResult({content:[],structuredContent:{...u.current.renderPayload,version:1,source:eo}})))()});const y=new Rn(d.contentWindow,d.contentWindow);m.connect(y).catch(g=>{console.error("[mcp-app-host] failed to initialize",g)});const h=new MutationObserver(()=>{m.setHostContext({theme:document.documentElement.classList.contains("dark")?"dark":"light",displayMode:"inline",platform:"web"})});return h.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{h.disconnect(),y.close()}},[]),s.jsx("iframe",{ref:l,title:t,src:e,sandbox:"allow-scripts",style:{width:"100%",height:i,border:"none",display:"block"}})},wo=new Set(["action"]),So=["name","description","identity_md"];function oe(e){return e==null||e===""?"":typeof e=="string"?e:Fe(e)}function ht(e){return e===null?"(cleared)":e===void 0?"":typeof e=="string"?e===""?"":e:Fe(e)}function Ue(e){return e.length>0?e[0].toUpperCase()+e.slice(1):e}const Bt=new Set(["delete","disconnect","remove","remove_rule","reset","revoke"]);function Ke(e){return e&&Bt.has(e)?"warning":"default"}function qe(e,t){return e&&Bt.has(e)?{level:"high",reason:t}:{level:"normal"}}function To(e,t){const n=e.attribution==="automation"?"An Automation":"An agent",r=Object.keys(t),o=r.map(l=>({label:l,before:oe(e.current?.[l]),after:oe(t[l])}));return{title:`${n} proposes a change`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:o.length>0?[{type:"diff",fields:o}]:[{type:"text",value:"No field changes.",muted:!0}],actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${r.join(", ")} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${r.join(", ")} was not applied.`}]}}function Co(e){const t=e.action??"change",n=e.proposal?.slug??e.proposal?.name??(e.proposal?.automation_id!=null?String(e.proposal.automation_id):void 0)??e.current?.slug??e.current?.name??"automation",r=[];e.action==="delete"&&r.push({type:"text",value:"This will archive the Automation.",muted:!0});const o=e.proposal??{},l=Object.keys(o).filter(i=>!wo.has(i)&&o[i]!==void 0).map(i=>({label:i,...e.action==="update"&&e.current?.[i]!==void 0?{before:ht(e.current?.[i])}:{},after:ht(o[i])}));return r.push(l.length>0?{type:"diff",fields:l}:{type:"text",value:"No field changes.",muted:!0}),{title:`${Ue(t)} Automation ${n}`,icon:"automation",impact:qe(e.action,"This archives the Automation and stops future runs."),tone:Ke(e.action),blocks:r,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${t} ${n} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${t} ${n} was not applied.`}]}}function jo(e){if(e.resourceKind==="automation")return Co(e);if(e.fields&&Object.keys(e.fields).length>0)return To(e,e.fields);const t=e.resourceKind==="entity"||e.proposal?.entity_id!==void 0||e.current?.entity_type!==void 0||e.proposal?.entity_type!==void 0;if(t&&(e.action==="link"||e.action==="unlink"))return Ln({...e,action:e.action});if(t){const l=e.proposal?.name??e.current?.name??e.proposal?.entity_id??e.current?.id??"entity",i=e.action??"change",c=[];if(e.action==="delete")c.push({type:"text",value:"This will delete the entity.",muted:!0});else{const u=Object.keys(e.proposal??{}).filter(d=>!["entity_id","id"].includes(d)&&e.proposal?.[d]!==void 0&&oe(e.proposal?.[d])!==oe(e.current?.[d])).map(d=>({label:d,...e.action==="update"?{before:oe(e.current?.[d])}:{},after:oe(e.proposal?.[d])}));c.push(u.length>0?{type:"diff",fields:u}:{type:"text",value:"No field changes.",muted:!0})}return{title:`${Ue(i)} entity ${l}`,icon:"entity",impact:qe(e.action,"This deletes the entity."),tone:Ke(e.action),blocks:c,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${i} ${l} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${i} ${l} was not applied.`}]}}const n=e.proposal?.agent_id??e.current?.id??"agent",r=e.action??"change",o=[];if(e.action==="delete")o.push({type:"text",value:"This will permanently delete the agent.",muted:!0});else{const l=So.filter(i=>e.proposal?.[i]!==void 0&&oe(e.proposal?.[i])!==oe(e.current?.[i])).map(i=>({label:i,...e.action==="update"?{before:oe(e.current?.[i])}:{},after:oe(e.proposal?.[i])}));o.push(l.length>0?{type:"diff",fields:l}:{type:"text",value:"No field changes.",muted:!0})}return{title:`${Ue(r)} agent ${n}`,icon:"agent",impact:qe(e.action,"This permanently deletes the agent and its configuration."),tone:Ke(e.action),blocks:o,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${r} ${n} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${r} ${n} was not applied.`}]}}function No(e){const t=Array.isArray(e.options)?e.options.filter(o=>typeof o=="string"):[],n=[{type:"text",value:e.question||"The agent has a question."}];t.length===0&&n.push({type:"text",value:"Reply below to answer.",muted:!0});const r=t.map(o=>({id:o,label:o,variant:"outline",tool:"answer_question",args:{answer:o},resolvedLabel:`Answered: ${o}`}));return{title:"Input needed",icon:"question",tone:"default",blocks:n,actions:r}}function Eo(e,t){return{tone:"bare",actions:[{id:"open",label:e.label??"Open link",variant:"outline",icon:"external",terminal:!1,href:t}]}}const Ao=({toolName:e,args:t})=>{const n=xn(),r=vn(),{append:o}=Ee(),l=Ye(),i=t??{},c=l?.resolve(e,t)??null;let u=c?.view??null;const d={...c?.handlers??{}},m=new Set;if(!c){if(e==="tool-approval"&&typeof i.runId=="number"&&Number.isSafeInteger(i.runId)&&i.runId>0){const y=i.runId,h=typeof i.status=="string"?i.status:"pending",g=h==="pending",w=jo(i),E=h==="confirmed"?"Approved":Ue(h);u=g?w:{...w,title:`${w.title??"Approval"} · ${E}`,tone:h==="failed"?"warning":"default",blocks:[...w.blocks??[],{type:"text",value:typeof i.reviewedByName=="string"?`${h==="rejected"?"Rejected":"Approved"} by ${i.reviewedByName}.`:`${E}.`,muted:!0}],actions:(w.actions??[]).filter(v=>v.terminal===!1)},g&&(d.manage_operations=v=>{if(v.action==="approve")return mt(T=>n.mutate({run_id:y},T));if(v.action==="reject"){const T=typeof v.reason=="string"?v.reason:void 0;return mt(H=>r.mutate({run_id:y,...T?{reason:T}:{}},H))}return Promise.resolve(!0)})}else if(e==="question"){const y=Array.isArray(i.options)?i.options.filter(h=>typeof h=="string"):[];u=No(i),d.answer_question=h=>{const g=typeof h.answer=="string"?h.answer:"";return y.includes(g)?(o(g),Promise.resolve(!1)):Promise.resolve(!0)}}else if(e==="link-button"){if(!pt(i.url))return null;const y=i.url;m.add(y),u=Eo(i,y)}}return u?s.jsx(Ro,{src:yo,title:u.title??"Interaction",renderPayload:u,onToolCall:(y,h)=>d[y]?d[y](h):Promise.resolve(!0),onOpenLink:y=>!m.has(y)||!pt(y)?Promise.resolve(!0):(window.open(y,"_blank","noopener,noreferrer"),Promise.resolve(!1))}):null};function Fe(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}const Io=()=>{const{running:e,append:t,cancel:n,pendingAttachments:r,addAttachments:o,removeAttachment:l,initialDraft:i,currentSuggestions:c}=Ee(),u=ko({suggestions:e?null:c}),[d,m]=a.useState(i??""),y=a.useRef(null),h=a.useRef(null),g=_n(On),w=a.useRef(i??"");a.useEffect(()=>{const T=i??"";if(T===w.current)return;const H=w.current;w.current=T,T!==""&&m(U=>U===""||U===H?T:U)},[i]);const E=a.useRef(d);E.current=d;const v=()=>{e||(t(E.current),m(""),h.current?.clear())};return s.jsxs("div",{className:"rounded-2xl border bg-background transition-colors focus-within:ring-1 focus-within:ring-ring",children:[r.length>0?s.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 pt-3",children:r.map(T=>s.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border bg-muted/50 px-2 py-1 text-xs",children:[s.jsx(He,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"max-w-[12rem] truncate",children:T.name}),s.jsx("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground","aria-label":"Remove attachment",onClick:()=>l(T.id),children:s.jsx(on,{className:"h-3 w-3"})})]},T.id))}):null,s.jsx(Pn,{value:d,onChange:m,onSubmit:v,searchRefs:g,handleRef:h,placeholder:u,className:"max-h-48 overflow-y-auto"}),s.jsxs("div",{className:"flex items-center justify-between px-3 pb-2",children:[s.jsx("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:T=>{T.target.files&&o(T.target.files),T.target.value=""}}),s.jsxs(fe,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 rounded-full text-muted-foreground hover:text-foreground",onClick:()=>y.current?.click(),children:[s.jsx(He,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Attach files"})]}),e?s.jsxs(fe,{type:"button",size:"icon",variant:"secondary",className:"h-8 w-8 rounded-full",onClick:n,children:[s.jsx(sn,{size:"lg"}),s.jsx("span",{className:"sr-only",children:"Cancel"})]}):s.jsxs(fe,{type:"button",size:"icon",className:"h-8 w-8 rounded-full",onClick:v,children:[s.jsx(ln,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Send message"})]})]})]})};function ko({suggestions:e}){const t=e?.find(n=>n.message.trim().length>0)?.message;return t?`Recommended: ${t.trim()}`:"Chat… (@ to mention, / for commands)"}export{Fo as A,Uo as L,Do as R,er as h,Jn as s};
|
|
6
|
-
//# sourceMappingURL=agent-thread-
|
|
5
|
+
`).trim()}function qn(e){const t=[];for(const n of e.matchAll(Tt)){const r=n[1]?.trim()||"file",o=n[2];o&&t.push({name:r,url:o})}return t}function Gn(e,t={}){if(typeof e=="string"){const r=ct(e);return r?[{type:"text",text:r}]:[]}if(!Array.isArray(e))return[];const n=[];for(const r of e){if(!r||typeof r!="object")continue;const o=r;if(o.type==="text"&&typeof o.text=="string"){const l=ct(o.text);l&&n.push({type:"text",text:l})}else t.showToolCalls&&o.type==="toolCall"&&typeof o.name=="string"&&!wt.has(o.name)?n.push({type:"tool-call",toolCallId:o.id??`tc-${n.length}`,toolName:o.name,args:o.arguments??{},...o.result!==void 0?{result:o.result}:{}}):t.showToolCalls&&o.type==="tool_use"&&typeof o.name=="string"&&n.push({type:"tool-call",toolCallId:o.id??`tc-${n.length}`,toolName:o.name,args:o.input??{},...o.result!==void 0?{result:o.result}:{}})}return n}function Yn(e){const t=[],n=r=>{for(const{name:o,url:l}of qn(r))t.push({id:`file-${t.length}`,name:o,url:l,isImage:zn.test(o)})};if(typeof e=="string")return n(e),t.length>0?t:void 0;if(Array.isArray(e)){for(const r of e){if(!r||typeof r!="object")continue;const o=r;if(o.type==="image"&&typeof o.data=="string"){const l=o.mimeType||"image/png";t.push({id:`img-${t.length}`,name:`image-${t.length+1}`,imageDataUrl:`data:${l};base64,${o.data}`,isImage:!0})}else o.type==="text"&&typeof o.text=="string"&&n(o.text)}return t.length>0?t:void 0}}function Jn(e,t){if(e.type==="bashExecution"){const r=e.content??{},o=e.timestamp?new Date(e.timestamp).getTime():void 0;return{id:e.id,role:"user",parts:[{type:"bash",command:r.command??"",output:r.output??"",exitCode:r.exitCode,cancelled:r.cancelled??!1}],createdAt:o&&!Number.isNaN(o)?o:void 0}}if(e.type!=="message"||e.isVerbose||e.role!=="assistant"&&e.role!=="user"&&e.role!=="system")return null;const n=e.timestamp?new Date(e.timestamp).getTime():void 0;return{id:e.id,role:e.role,parts:Gn(e.content,t),attachments:Yn(e.content),createdAt:n&&!Number.isNaN(n)?n:void 0}}const Qn=[],Xn=[];function Zn(e){let t=null;for(const n of e)n.type==="suggestion"&&(t=n.prompts.length>0?n.prompts:null);return t}function er(e,t){if(e.length===0)return null;const n=[];for(const r of e)if(r.type!=="suggestion"){if(r.type==="agent-error"){n.push({type:"error",text:String(r.error??"Agent reported an error.")});const o=yt(r.errorCode,{...t,provider:r.errorContext?.provider,model:r.errorContext?.model});o&&n.push({type:"tool-call",toolCallId:`error-run-${r.runId}`,toolName:"link-button",args:{label:o.label,url:o.href}});continue}n.push({type:"tool-call",toolCallId:`approval-event-${r.eventId}`,toolName:"tool-approval",args:{runId:r.runId,action:r.action,proposal:r.proposal,current:r.current,fields:r.fields??null,attribution:r.attribution??null,resourceKind:r.resourceKind??null,reason:r.reason??null,status:r.status??"pending",reviewedByName:r.reviewedByName??null}})}return n.length===0?null:{id:"history-interactions",role:"assistant",parts:n}}const tr=3e4,nr=3*tr,rr=15e3;function ut(e){try{return JSON.parse(e.data)}catch{return{content:e.data}}}const be=e=>`${e}-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;function or(e){const t=[],n=new Set;for(const r of e){if(!r||typeof r!="object")continue;const{title:o,message:l}=r;if(typeof o!="string"||typeof l!="string")continue;const i=o.trim(),c=l.trim();if(i.length===0||c.length===0)continue;const u=`${i}\0${c}`;n.has(u)||(n.add(u),t.push({title:i,message:c}))}return t.length>0?t:null}function Uo({agentId:e,workspaceSlug:t,thread:n="agent-panel",loadHistory:r=!0,ephemeralContext:o,onFirstUserMessage:l,children:i,initialDraft:c}){const u=zt(),d=a.useRef(null),m=a.useRef(null),y=a.useRef(!1),h=a.useRef(o),g=a.useRef(!1),w=a.useRef(null);h.current=o;const{data:E,isLoading:v}=Wt(e,n,{orgSlug:t,enabled:r&&!!e&&!!n}),T=E?.messages??Qn,H=E?.interactions??Xn,{data:U}=Kt(e,{enabled:!!e}),K=U?.starters??St,z=!!(U?.showToolCalls??U?.settings?.showToolCalls),[N,L]=a.useState([]),[G,le]=a.useState(!1),[$,q]=a.useState([]),[Y,R]=a.useState(null),S=a.useRef(!1);S.current=G;const j=a.useMemo(()=>T.map(I=>Jn(I,{showToolCalls:z})).filter(I=>I!==null),[T,z]),O=a.useRef(!1);a.useEffect(()=>{if(O.current||v||S.current)return;O.current=!0;const I=er(H,{workspaceSlug:t,agentId:e,webOrigin:typeof window>"u"?null:window.location.origin});L(I?[...j,I]:j),R(Zn(H))},[e,v,j,H,t]);const A=a.useCallback(()=>{u.invalidateQueries({queryKey:["agent-thread-messages",t,e,n]}),u.invalidateQueries({queryKey:["agent-threads",t,e]})},[u,t,e,n]),Z=a.useCallback(async()=>{if(d.current)return d.current;if(m.current)return m.current;if(!e)throw new Error("No agent selected");const I=(async()=>{const M=await tt(`${Be}/lobu/api/v1/agents`,{method:"POST",headers:{"Content-Type":"application/json",...t?{"x-lobu-org":t}:{}},credentials:"include",body:JSON.stringify({agentId:e,thread:n}),timeoutMs:2e4});if(!M.ok)throw await nt(M);const V=await M.json(),C=qt(),Q={sessionId:V.agentId,sseUrl:it(V.sseUrl,Be,C),messagesUrl:it(V.messagesUrl,Be,C)};return d.current=Q,Q})();m.current=I;try{return await I}catch(M){throw d.current=null,M}finally{m.current=null}},[e,t,n]),te=a.useCallback(async(I,M,V)=>{const C=crypto.randomUUID(),Q=new AbortController;w.current=Q;const W=f=>{L(p=>p.map(b=>b.id===V?{...b,parts:f}:b))};let B;try{B=await Z()}catch(f){W([{type:"text",text:`Error: ${f instanceof Error?f.message:"Could not start a session."}`}]);return}let X=await rt(B.sseUrl,{throwOnFailure:!0});const pe=[];let ie=null;const Re=()=>{const f=ie;ie=null,f?.()},we=f=>{pe.push(f),Re()},Se=(f,p)=>{const k=["question","link-button","tool-approval"].includes(f)?p.turnMessageId===C:p.messageId===C||Array.isArray(p.processedMessageIds)&&p.processedMessageIds.includes(C);(f==="closed"||k)&&we({kind:f,payload:p})};let me=!1,Te=null;const Ie=new Promise(f=>{Te=f});let ce=0,he=Date.now();const ue=f=>{he=Date.now();const p=Number(f.lastEventId);Number.isFinite(p)&&p>ce&&(ce=p)},ke=["output","status","complete","closed","agent-error","question","link-button","tool-approval","tool_use"],je=f=>{f.addEventListener("open",()=>{me=!0,Te?.()}),f.addEventListener("connected",b=>{ue(b),me||(me=!0,Te?.())}),f.addEventListener("ping",ue);const p=b=>k=>{ue(k);const ee=k;typeof ee.data=="string"&&Se(b,ut(ee))};for(const b of ke)f.addEventListener(b,p(b));f.addEventListener("error",b=>{const k=b;if(typeof k.data=="string"&&k.data){ue(b),Se("error",ut(k));return}f.readyState===EventSource.CLOSED&&we({kind:"error",payload:{error:"Connection closed"}})})};je(X);const _e=async()=>{X.close();let f=B.sseUrl;if(ce){const p=new URL(B.sseUrl,window.location.origin);p.searchParams.set("since",String(ce)),f=p.toString()}X=await rt(f,{throwOnFailure:!1}),je(X),he=Date.now()};await Promise.race([Ie,new Promise(f=>setTimeout(f,1500))]);const Oe=()=>{X.close(),Re()};Q.signal.addEventListener("abort",Oe,{once:!0});try{const f=h.current?.trim(),p=!!f&&!g.current;p&&(g.current=!0);let b;if(M.length>0){const x=new FormData;x.set("content",I),x.set("messageId",C),p&&f&&x.set("ephemeralContext",f);for(const _ of M)x.append("files",_,_.name);b={method:"POST",credentials:"include",body:x,timeoutMs:12e4}}else{const x={content:I,messageId:C};p&&f&&(x.ephemeralContext=f),b={method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(x),timeoutMs:2e4}}const k=await tt(B.messagesUrl,b);if(!k.ok)throw d.current=null,await nt(k);let ee="",D=Me,et=null;const ge=[],de=()=>Wn({textOut:ee,statusLine:D,errorText:et,toolCalls:ge});for(W(de());!Q.signal.aborted;){if(pe.length===0){let _;const ne=await Promise.race([new Promise(Ve=>{ie=()=>Ve(!0)}),new Promise(Ve=>{_=setTimeout(()=>Ve(!1),rr)})]);_&&clearTimeout(_),!ne&&Date.now()-he>=nr&&(await _e(),A());continue}const x=pe.shift();if(x){if(x.kind==="output")D=null,ee+=String(x.payload.content??"");else if(x.kind==="status")D=Me;else if(x.kind==="complete"){D=null;const _=x.payload.finalText;typeof _=="string"&&_.length>0&&(ee=_);const ne=x.payload.suggestions;ne!==void 0&&R(Array.isArray(ne)?or(ne):null),A(),W(de());return}else if(x.kind==="closed"){d.current=null;const _=x.payload.reason;D=`Session ended${_?`: ${_}`:""}.`,A(),W(de());return}else if(x.kind==="error"||x.kind==="agent-error"){D=null,et=typeof x.payload.error=="string"&&x.payload.error?x.payload.error:"Agent reported an error.";const _=x.payload.errorContext&&typeof x.payload.errorContext=="object"?x.payload.errorContext:void 0,ne=yt(x.payload.errorCode,{workspaceSlug:t,agentId:e,webOrigin:typeof window>"u"?null:window.location.origin,provider:typeof _?.provider=="string"?_.provider:void 0,model:typeof _?.model=="string"?_.model:void 0});ne&&ge.push({type:"tool-call",toolCallId:be("l"),toolName:"link-button",args:{label:ne.label,url:ne.href}}),A(),W(de());return}else if(x.kind==="question")ge.push({type:"tool-call",toolCallId:be("q"),toolName:"question",args:{question:x.payload.question??"",options:x.payload.options??[]}});else if(x.kind==="tool_use"){if(D=null,wt.has(x.payload.name??"")){W(de());continue}const _=x.payload.result_summary,ne=Rt(_);if(!z&&!ne){W(de());continue}ge.push({type:"tool-call",toolCallId:x.payload.toolCallId??be("t"),toolName:z?x.payload.name??"tool":"subscription-candidate",args:z?x.payload.input??{}:null,result:_,isError:x.payload.isError})}else if(x.kind==="link-button")ge.push({type:"tool-call",toolCallId:be("l"),toolName:"link-button",args:{label:x.payload.label??"Open link",url:x.payload.url??""}});else if(x.kind==="tool-approval"){const _=x.payload.runId;if(typeof _!="number")continue;ge.push({type:"tool-call",toolCallId:`run-${_}`,toolName:"tool-approval",args:{runId:_,action:x.payload.action??null,proposal:x.payload.proposal??null,current:x.payload.current??null,fields:x.payload.fields??null,attribution:x.payload.attribution??null,resourceKind:x.payload.resourceKind??null}})}W(de())}}}catch(f){W([{type:"text",text:`Error: ${f instanceof Error?f.message:"Send failed."}`}])}finally{Q.signal.removeEventListener("abort",Oe),X.close()}},[e,Z,A,z,t]),re=a.useCallback(I=>{const M=I.trim(),V=$.map(B=>B.file);if(!M&&V.length===0||S.current||!e)return;y.current||(y.current=!0,l?.(M||V[0]?.name||""));const C={id:be("u"),role:"user",parts:M?[{type:"text",text:M}]:[],attachments:$.map(B=>({id:B.id,name:B.name,isImage:B.isImage,imageDataUrl:B.isImage?URL.createObjectURL(B.file):void 0})),createdAt:Date.now()},Q=be("asst"),W={id:Q,role:"assistant",parts:[{type:"reasoning"}],createdAt:Date.now()};L(B=>[...B,C,W]),q([]),le(!0),S.current=!0,te(M,V,Q).finally(()=>{le(!1),S.current=!1,w.current=null})},[e,l,$,te]),se=a.useCallback(()=>{w.current?.abort()},[]),ye=a.useCallback(I=>{const M=Array.from(I);q(V=>[...V,...M.map(C=>({id:crypto.randomUUID(),name:C.name,file:C,isImage:C.type.startsWith("image/")}))])},[]),J=a.useCallback(I=>{q(M=>M.filter(V=>V.id!==I))},[]),ae=a.useRef(!1);a.useEffect(()=>{if(ae.current)return;const I=Cn(n);I&&(ae.current=!0,re(I))},[n,re]);const F=a.useMemo(()=>({messages:N,running:G,append:re,cancel:se,pendingAttachments:$,addAttachments:ye,removeAttachment:J,initialDraft:c,agentId:e,conversationId:n,workspaceSlug:t,currentSuggestions:Y,starters:K}),[N,G,re,se,$,ye,J,c,e,n,t,Y,K]);return r&&v?s.jsx(wn,{}):s.jsx(Qe.Provider,{value:F,children:i})}const dt="mx-0.5 inline-flex items-center gap-1 rounded-md bg-accent px-1.5 py-0.5 align-baseline font-medium text-[0.9em] text-accent-foreground no-underline";function sr({refItem:e}){const t=In[e.kind]??Gt;return kn(e.path)?s.jsxs("span",{className:dt,children:[s.jsx(t,{className:"h-3 w-3 shrink-0 opacity-70"}),e.label]}):s.jsxs(gt,{to:e.path,className:P(dt,"hover:bg-accent/80"),children:[s.jsx(t,{className:"h-3 w-3 shrink-0 opacity-70"}),e.label]})}const Xe=({text:e,renderText:t})=>En(e)?s.jsx(s.Fragment,{children:An(e).map((n,r)=>n.type==="ref"?s.jsx(sr,{refItem:n.ref},`r${r}`):s.jsx("span",{children:t(n.text)},`t${r}`))}):s.jsx(s.Fragment,{children:t(e)}),lr=({label:e="Thinking"})=>s.jsx("span",{className:"aui-thinking-shimmer inline-block text-sm","aria-live":"polite","aria-busy":"true",children:e}),jt=a.createContext(null),Ct=()=>{const e=a.useContext(jt);if(!e)throw new Error("ChainOfThought components must be used within ChainOfThought");return e},Nt=a.memo(({className:e,open:t,defaultOpen:n=!1,onOpenChange:r,children:o,...l})=>{const[i,c]=Yt({prop:t,defaultProp:n,onChange:r}),u=a.useMemo(()=>({isOpen:i,setIsOpen:c}),[i,c]);return s.jsx(jt.Provider,{value:u,children:s.jsx("div",{className:P("not-prose max-w-prose space-y-4",e),...l,children:o})})}),Et=a.memo(({className:e,children:t,...n})=>{const{isOpen:r,setIsOpen:o}=Ct();return s.jsx(bt,{onOpenChange:o,open:r,children:s.jsxs(Jt,{className:P("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",e),...n,children:[s.jsx(Qt,{className:"size-4"}),s.jsx("span",{className:"flex-1 text-left",children:t??"Chain of Thought"}),s.jsx(Xt,{className:P("size-4 transition-transform",r?"rotate-180":"rotate-0")})]})})}),At=a.memo(({className:e,icon:t=en,label:n,description:r,status:o="complete",children:l,...i})=>{const c={complete:"text-muted-foreground",active:"text-foreground",pending:"text-muted-foreground/50"};return s.jsxs("div",{className:P("flex gap-2 text-sm",c[o],"fade-in-0 slide-in-from-top-2 animate-in",e),...i,children:[s.jsxs("div",{className:"relative mt-0.5",children:[s.jsx(t,{className:"size-4"}),s.jsx("div",{className:"-mx-px absolute top-7 bottom-0 left-1/2 w-px bg-border"})]}),s.jsxs("div",{className:"flex-1 space-y-2 overflow-hidden",children:[s.jsx("div",{children:n}),r&&s.jsx("div",{className:"text-muted-foreground text-xs",children:r}),l]})]})}),It=a.memo(({className:e,children:t,...n})=>{const{isOpen:r}=Ct();return s.jsx(bt,{open:r,children:s.jsx(Zt,{className:P("mt-2 space-y-3","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",e),...n,children:t})})});Nt.displayName="ChainOfThought";Et.displayName="ChainOfThoughtHeader";At.displayName="ChainOfThoughtStep";It.displayName="ChainOfThoughtContent";function ar(e){return{contentIds:e.filter(n=>Number.isSafeInteger(n)&&n>0),sortBy:"date",sortOrder:"asc"}}function ir({ownerSlug:e,eventIds:t}){const n=t.join(","),r=a.useMemo(()=>ar(n.split(",").map(Number)),[n]);return r.contentIds.length===0?null:s.jsx(tn,{owner:e,children:({organizationId:o,ownerSlug:l})=>o?s.jsx(Mn,{organizationId:o,ownerSlug:l,filters:r,hideOriginator:!0}):null})}function cr({defaultTagName:e,props:t,render:n,state:r={},stateAttributesMapping:o}){let l=ze(ur(r,o),t);if(!n)return a.createElement(e,l);if(typeof n=="function")return n(l,r);if(!a.isValidElement(n))return null;let i=n.props,c={...ze(l,i),ref:Ae(l.ref,i.ref)};return a.cloneElement(n,c)}function ze(...e){let t={};for(let n of e){if(!n)continue;let r=n;for(let o of Object.keys(r)){let l=r[o];if(l===void 0)continue;let i=t[o];o==="className"?t[o]=[i,l].filter(Boolean).join(" "):o==="style"?t[o]={...i,...l}:o==="ref"?t[o]=Ae(i,l):fr(o)&&typeof i=="function"&&typeof l=="function"?t[o]=dr(l,i):t[o]=l}}return t}function ur(e,t){let n={};for(let r of Object.keys(e)){let o=e[r],l=t?.[r]?.(o);if(l){Object.assign(n,l);continue}if(r==="slot"){n["data-slot"]=o;continue}let i=`data-${String(r).replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`)}`;typeof o=="boolean"?n[i]=o?"":void 0:o!=null&&(n[i]=String(o))}return n}function dr(e,t){return function(n){e(n),n.defaultPrevented||t(n)}}function fr(e){return/^on[A-Z]/.test(e)}function Ae(...e){let t=e.filter(Boolean);if(t.length!==0)return n=>{for(let r of t)typeof r=="function"?r(n):r&&(r.current=n)}}var pr=8,mr=64,hr=0,Le=.5,gr=180,br=new Set(["ArrowDown","ArrowUp","End","Home","PageDown","PageUp"," "]),kt={start:!1,end:!1},xr=[],$e={currentAnchorId:null,visibleMessageIds:xr};function vr({content:e,scrollEdgeThreshold:t,spacer:n,viewport:r}){if(!r||!e)return kt;let o=Ze({content:e,spacer:n,viewport:r});return{start:r.scrollTop>t,end:o-r.scrollTop-r.clientHeight>t}}function yr({content:e,scrollMargin:t,scrollPreviousItemPeek:n,spacer:r,viewport:o,visibleMessageIds:l}){if(!e||!o)return $e;let i=o.getBoundingClientRect(),c=i.top+t+n,u=typeof IntersectionObserver>"u",d=[],m=null;for(let y of Ce(e,r)){let h=y.dataset.messageId;if(!h)continue;let g=y.dataset.scrollAnchor==="true",w=g||u?y.getBoundingClientRect():null;(u&&w?w.bottom>c&&w.top<i.bottom:l.has(h))&&d.push(h),g&&w&&w.top<=c+Le&&(m=h)}return d.length===0&&m===null?$e:{currentAnchorId:m,visibleMessageIds:d}}function Ce(e,t){return Array.from(e.children).filter(n=>n instanceof HTMLElement&&n!==t)}function Rr(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r?.dataset.scrollAnchor==="true")return r}return null}function wr(e,t){for(let n of e)if(n.dataset.scrollAnchor==="true"&&!t.has(n))return n;return null}function Sr(e,t){let n=0;for(let r=t;r<e.length;r++)if(e[r]?.dataset.scrollAnchor==="true"&&(n+=1,n>1))return!0;return!1}function Tr(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.dataset.scrollAnchor==="true")return n}return null}function jr({content:e,spacer:t,viewport:n}){let r=n.getBoundingClientRect();for(let o of Ce(e,t)){if(!o.dataset.messageId)continue;let l=o.getBoundingClientRect();if(l.bottom>r.top&&l.top<r.bottom)return o}return null}function Cr({align:e,element:t,scrollMargin:n,spacer:r,viewport:o}){let l=_t(t,o),i=t.getBoundingClientRect().height,c=Ar(r);if(e==="center"){let u=Math.max(0,o.clientHeight-c.start-c.end);return l-c.start-(u-i)/2-n}if(e==="end")return l-o.clientHeight+i+c.end+n;if(e==="nearest"){let u=l+i,d=o.scrollTop+c.start,m=o.scrollTop+o.clientHeight-c.end;return l>=d&&u<=m?o.scrollTop:l<d?l-c.start-n:u-o.clientHeight+c.end+n}return l-c.start-n}function _t(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.top-r.top+t.scrollTop}function Pe(e,t){return e.getBoundingClientRect().top-t.getBoundingClientRect().top}function Nr({content:e,scrollTop:t,spacer:n,viewport:r}){let o=Ze({content:e,spacer:n,viewport:r});return t+r.clientHeight-o}function Ze({content:e,spacer:t,viewport:n}){let r=Ce(e,t),o=Ot(e),l=n.getBoundingClientRect(),i=n.scrollTop,c=o.start+o.end;for(let u of r){let d=u.getBoundingClientRect();c=Math.max(c,d.bottom-l.top+i+o.end)}return c}function Er(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function Ot(e){let t=window.getComputedStyle(e);return{end:We(t.paddingBlockEnd||t.paddingBottom),start:We(t.paddingBlockStart||t.paddingTop)}}function Ar(e){let t=e?.parentElement;return t?Ot(t):{end:0,start:0}}function Ir(e){if(!e)return 0;let t=window.getComputedStyle(e),n=t.rowGap==="normal"?t.gap:t.rowGap;return We(n)}function We(e){if(!e)return 0;let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function kr({refs:e,commitScrollState:t,scheduleStateCommit:n,scheduleVisibilitySync:r}){let{streamingTurnRef:o,autoScrollRef:l,autoscrollingRef:i,autoscrollingTimeoutRef:c,contentRef:u,defaultScrollPositionAppliedRef:d,itemCountRef:m,messageElementsRef:y,modeRef:h,pendingScrollToMessageRef:g,prependRestoreRef:w,scrollMarginRef:E,scrollPreviousItemPeekRef:v,spacerGapRef:T,spacerHeightRef:H,spacerRef:U,viewportRef:K}=e,z=a.useCallback(R=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null),i.current!==R&&(i.current=R,t()),R&&(c.current=window.setTimeout(()=>{c.current=null,i.current=!1,t()},gr))},[t]),N=a.useCallback(R=>{let S=U.current;if(!S)return;let j=Math.max(0,Math.ceil(R));H.current!==j&&(H.current=j,S.hidden=j===0,S.style.height=`${j}px`,S.style.marginTop=j>0?`${-T.current}px`:"")},[]),L=a.useCallback((R,{behavior:S="auto",autoscrolling:j=!1}={})=>{let O=K.current;if(!O)return;let A=Math.max(0,R);if(Math.abs(O.scrollTop-A)<=Le){O.scrollTop=A,t();return}j&&z(!0),O.scrollTo({top:A,behavior:S}),n()},[t,n,z]),G=a.useCallback(({behavior:R="auto"}={})=>K.current?(N(0),o.current=null,h.current="free-scrolling",L(0,{behavior:R}),r(),!0):!1,[r,L,N]),le=a.useCallback(({behavior:R="auto"}={})=>{let S=K.current;return S?(N(0),o.current=null,h.current=l.current?"following-bottom":"free-scrolling",L(Er(S),{autoscrolling:!0,behavior:R}),r(),!0):!1},[r,L,N]),$=a.useCallback((R,{align:S="start",behavior:j="auto",scrollMargin:O=E.current}={},{keepPreviousPeek:A=!1}={})=>{let Z=u.current,te=K.current;if(!Z||!te||!Z.contains(R))return!1;let re=Cr({align:S,element:R,scrollMargin:A?O+v.current:O,spacer:U.current,viewport:te}),se=Nr({content:Z,scrollTop:re,spacer:U.current,viewport:te});return N(se),w.current={element:R,viewportTop:Pe(R,te)},h.current=A?"anchored-to-message":"settling-jump",o.current=A?R:null,L(re,{behavior:j}),r(),!0},[r,L,N]),q=a.useCallback(()=>{let R=o.current;return!R||!R.isConnected||h.current!=="anchored-to-message"?!1:$(R,{align:"start"},{keepPreviousPeek:!0})},[$]),Y=a.useCallback((R,S)=>{let j=y.current.get(R);return j?(d.current=!0,$(j,S)?(g.current=null,!0):(g.current={messageId:R,options:S},!0)):m.current===0?(g.current={messageId:R,options:S},d.current=!0,!0):!1},[$]);return{flushPendingScrollToMessage:a.useCallback(()=>{let R=g.current;if(!R)return!1;let S=y.current.get(R.messageId);return!S||!$(S,R.options)?!1:(g.current=null,d.current=!0,!0)},[$]),reanchorToAnchoredMessage:q,scrollToElement:$,scrollToEnd:le,scrollToMessage:Y,scrollToStart:G}}function Pt(e,t){let n=e,r=new Set;return{getSnapshot:()=>n,hasListeners:()=>r.size>0,setSnapshot:o=>{t(n,o)||(n=o,r.forEach(l=>l()))},subscribe:(o,l,i)=>{let c=r.size===0;return r.add(o),c&&l?.(),()=>{r.delete(o),r.size===0&&i?.()}}}}function _r(e,t){return Pt(e,t)}function Or(){return Pt($e,Mr)}function Pr(e,t){return e.start===t.start&&e.end===t.end}function Mr(e,t){return e.currentAnchorId!==t.currentAnchorId||e.visibleMessageIds.length!==t.visibleMessageIds.length?!1:e.visibleMessageIds.every((n,r)=>n===t.visibleMessageIds[r])}function Lr({autoScroll:e,scrollEdgeThreshold:t,scrollMargin:n,scrollPreviousItemPeek:r}){let o=a.useRef(e),l=a.useRef(!1),i=a.useRef(null),c=a.useRef(!1),u=a.useRef(t),d=a.useRef(0),m=a.useRef(null),y=a.useRef(0),h=a.useRef(e?"following-bottom":"free-scrolling"),g=a.useRef(new Map),w=a.useRef(null),E=a.useRef(null),v=a.useRef(null),T=a.useRef(r),H=a.useRef(!0),U=a.useRef(null),K=a.useRef(n),z=a.useRef(null),N=a.useRef(0),L=a.useRef(0),G=a.useRef(null),le=a.useRef(null),$=a.useRef(null),q=a.useRef(null),Y=a.useRef(null),R=a.useRef(null),S=a.useRef(null),j=a.useRef(null),O=a.useRef(new Set),A=a.useRef(new WeakSet);return $.current===null&&($.current=_r(kt,Pr)),j.current===null&&(j.current=Or()),o.current=e,u.current=t,K.current=n,T.current=r,{autoScrollRef:o,autoscrollingRef:l,autoscrollingTimeoutRef:q,streamingTurnRef:v,contentRef:i,defaultScrollPositionAppliedRef:c,firstItemRef:m,itemCountRef:d,lastScrollTopRef:y,messageElementsRef:g,modeRef:h,pendingScrollFrameRef:z,pendingScrollToMessageRef:w,prependRestoreRef:E,preserveScrollOnPrependRef:H,rootRef:U,scrollEdgeThresholdRef:u,scrollMarginRef:K,scrollPreviousItemPeekRef:T,spacerGapRef:N,spacerHeightRef:L,spacerRef:G,stateFrameRef:le,stateStore:$.current,viewportRef:Y,visibilityFrameRef:R,visibilityObserverRef:S,visibilityStore:j.current,visibleMessageIdsRef:O,handledScrollAnchorsRef:A}}function ft(e,t){return a.useCallback(n=>{e.current=n,n&&t()},[e,t])}function $r({autoScroll:e=!1,defaultScrollPosition:t="end",scrollEdgeThreshold:n=pr,scrollPreviousItemPeek:r=mr,scrollMargin:o=hr}){let l=Lr({autoScroll:e,scrollEdgeThreshold:n,scrollMargin:o,scrollPreviousItemPeek:r}),{streamingTurnRef:i,autoScrollRef:c,autoscrollingRef:u,autoscrollingTimeoutRef:d,contentRef:m,defaultScrollPositionAppliedRef:y,firstItemRef:h,itemCountRef:g,lastScrollTopRef:w,messageElementsRef:E,modeRef:v,pendingScrollFrameRef:T,pendingScrollToMessageRef:H,prependRestoreRef:U,preserveScrollOnPrependRef:K,rootRef:z,scrollEdgeThresholdRef:N,scrollMarginRef:L,scrollPreviousItemPeekRef:G,spacerGapRef:le,spacerHeightRef:$,spacerRef:q,stateFrameRef:Y,stateStore:R,viewportRef:S,visibilityFrameRef:j,visibilityObserverRef:O,visibilityStore:A,visibleMessageIdsRef:Z,handledScrollAnchorsRef:te}=l,re=a.useRef(t);re.current!==t&&(re.current=t,y.current=!1);let se=a.useCallback(f=>{let p=z.current,b=S.current,k=[f.start&&"start",f.end&&"end"].filter(Boolean).join(" "),ee=u.current;for(let D of[p,b])D&&(k?D.setAttribute("data-scrollable",k):D.removeAttribute("data-scrollable"),D.toggleAttribute("data-autoscrolling",ee))},[]),ye=a.useCallback(f=>{let p=S.current?.scrollTop??0,b=p<w.current-Le;w.current=p,c.current&&!f.end&&v.current!=="settling-jump"&&v.current!=="anchored-to-message"?v.current="following-bottom":v.current==="following-bottom"&&f.end&&b&&!u.current&&(v.current="free-scrolling")},[]),J=a.useCallback(()=>{let f=vr({content:m.current,scrollEdgeThreshold:N.current,spacer:q.current,viewport:S.current});ye(f);let p=v.current==="following-bottom"?{...f,end:!1}:f;se(p),R.setSnapshot(p)},[ye,R,se]),ae=a.useCallback(()=>{Y.current===null&&(Y.current=window.requestAnimationFrame(()=>{Y.current=null,J()}))},[J]),F=a.useCallback(()=>{A.hasListeners()&&j.current===null&&(j.current=window.requestAnimationFrame(()=>{j.current=null,A.hasListeners()&&A.setSnapshot(yr({content:m.current,scrollMargin:L.current,scrollPreviousItemPeek:G.current,spacer:q.current,viewport:S.current,visibleMessageIds:Z.current}))}))},[A]),{flushPendingScrollToMessage:I,reanchorToAnchoredMessage:M,scrollToElement:V,scrollToEnd:C,scrollToMessage:Q,scrollToStart:W}=kr({refs:l,commitScrollState:J,scheduleStateCommit:ae,scheduleVisibilitySync:F}),B=a.useCallback(()=>{let f=U.current,p=S.current;if(!f||!p||!f.element.isConnected)return!1;let b=Pe(f.element,p)-f.viewportTop;return Math.abs(b)<=Le?!1:(p.scrollTop+=b,f.viewportTop=Pe(f.element,p),ae(),F(),!0)},[ae,F]),X=a.useCallback(()=>{let f=m.current,p=S.current;if(!f||!p){U.current=null;return}let b=jr({content:f,spacer:q.current,viewport:p});U.current=b?{element:b,viewportTop:Pe(b,p)}:null},[]),pe=a.useCallback(()=>{T.current===null&&(T.current=window.requestAnimationFrame(()=>{T.current=null,I()&&X()}))},[X,I]),ie=a.useCallback(()=>{if(!t||y.current||g.current===0)return!1;let f=!1;if(t==="last-anchor"){let p=m.current,b=S.current,k=p&&b?Tr(Ce(p,q.current)):null;if(!p||!b||!k)f=C({behavior:"auto"});else{let ee=_t(k,b);f=Ze({content:p,spacer:q.current,viewport:b})-ee<=b.clientHeight?C({behavior:"auto"}):V(k,{align:"start"},{keepPreviousPeek:!0})}}else f=t==="end"?C({behavior:"auto"}):W({behavior:"auto"});return f?(y.current=!0,!0):!1},[t,V,C,W]),Re=a.useCallback(()=>{let f=m.current;if(!f)return;let p=Ce(f,q.current),b=g.current,k=h.current;g.current=p.length,h.current=p[0]??null,(()=>{if(I())return;if(b===0){if(ie()||p.length>0&&c.current&&C({behavior:"auto"}))return;J(),F();return}let ee=k?p.indexOf(k):-1;if(K.current&&ee>0){B();return}if(p.length>b){let D=Rr(p,b);if(D){if(c.current&&v.current==="following-bottom"&&Sr(p,b)){C({behavior:"auto"});return}V(D,{align:"start"},{keepPreviousPeek:!0}),te.current.add(D);return}}if(p.length===b){let D=wr(p,te.current);if(D){V(D,{align:"start"},{keepPreviousPeek:!0}),te.current.add(D);return}}v.current==="following-bottom"&&c.current?C({behavior:"auto"}):(J(),F())})(),X()},[ie,X,J,I,B,F,V,C]),we=a.useCallback(()=>{if(v.current==="following-bottom"&&c.current){C({behavior:"auto"});return}let f=$.current;if(M()){c.current&&f>0&&$.current===0&&C({behavior:"auto"});return}ae(),F()},[M,ae,F,C]),Se=a.useCallback(()=>{let f=S.current;if(!(!f||!A.hasListeners())){if(typeof IntersectionObserver>"u"){F();return}O.current||(O.current=new IntersectionObserver(p=>{for(let b of p){let k=b.target.dataset.messageId;k&&(b.isIntersecting?Z.current.add(k):Z.current.delete(k))}F()},{root:f,rootMargin:`${-(L.current+G.current)}px 0px 0px 0px`,threshold:[0,.01,.5,1]})),E.current.forEach(p=>{O.current?.observe(p)}),F()}},[F,A]),me=a.useCallback(()=>{j.current!==null&&(window.cancelAnimationFrame(j.current),j.current=null),O.current?.disconnect(),O.current=null,Z.current.clear(),A.setSnapshot($e)},[A]),Te=a.useCallback((f,p,b)=>{if(p){E.current.set(f,p),O.current?.observe(p),F(),H.current?.messageId===f&&pe();return}b&&E.current.get(f)===b&&(E.current.delete(f),Z.current.delete(f),O.current?.unobserve(b),F())},[pe,F]),Ie=a.useCallback(()=>{(v.current==="following-bottom"||v.current==="anchored-to-message"||v.current==="settling-jump")&&(i.current=null,v.current="free-scrolling")},[]),ce=a.useCallback(()=>se(R.getSnapshot()),[R,se]),he=ft(z,ce),ue=ft(S,ce),ke=a.useCallback(f=>{m.current=f},[]),je=a.useCallback(f=>{q.current=f,le.current=Ir(f?.parentElement??null)},[]),_e=a.useCallback(()=>{J(),F(),X()},[X,J,F]),Oe=a.useMemo(()=>({handleContentChange:Re,handleResize:we,observeVisibility:Se,preserveScrollOnPrependRef:K,scrollToEnd:C,scrollToMessage:Q,scrollToStart:W,setContentElement:ke,setRootElement:he,setSpacerElement:je,setViewportElement:ue,stateStore:R,syncAfterScroll:_e,unobserveVisibility:me,userScrollIntent:Ie,viewportRef:S,visibilityStore:A}),[Re,we,Se,C,Q,W,ke,he,je,ue,R,_e,me,Ie,A]);return a.useLayoutEffect(()=>{ie()},[ie]),a.useEffect(()=>()=>{Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null),j.current!==null&&(window.cancelAnimationFrame(j.current),j.current=null),d.current!==null&&(window.clearTimeout(d.current),d.current=null),T.current!==null&&(window.cancelAnimationFrame(T.current),T.current=null),O.current?.disconnect(),O.current=null},[]),a.useLayoutEffect(()=>{if(e&&v.current==="following-bottom"&&g.current>0){C({behavior:"auto"});return}J()},[e,J,C]),{context:Oe,registerMessage:Te}}function Dr(e){let t=a.useRef(e);return t.current=e,t}var Mt=a.createContext(null),Lt=a.createContext(null);function xe(){let e=a.useContext(Mt);if(!e)throw new Error("useMessageScroller must be used within a MessageScroller.");return e}function Ur(){let e=a.useContext(Lt);if(!e)throw new Error("MessageScrollerItem must be used within a MessageScroller.");return e}function $t(){let{scrollToEnd:e,scrollToMessage:t,scrollToStart:n}=xe();return a.useMemo(()=>({scrollToEnd:e,scrollToMessage:t,scrollToStart:n}),[e,t,n])}function Dt(){let{observeVisibility:e,unobserveVisibility:t,visibilityStore:n}=xe(),r=a.useCallback(o=>n.subscribe(o,e,t),[e,t,n]);return a.useSyncExternalStore(r,n.getSnapshot,n.getSnapshot)}function Fr({autoScroll:e=!1,children:t,defaultScrollPosition:n="end",scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:l}){let{context:i,registerMessage:c}=$r({autoScroll:e,defaultScrollPosition:n,scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:l});return s.jsx(Mt.Provider,{value:i,children:s.jsx(Lt.Provider,{value:c,children:t})})}function Vr({children:e,...t}){let{setRootElement:n}=xe();return s.jsx("div",{ref:n,...t,children:e})}function Br({"aria-label":e,children:t,onKeyDown:n,onScroll:r,onTouchMove:o,onWheel:l,preserveScrollOnPrepend:i=!0,ref:c,role:u,tabIndex:d,...m}){let{handleResize:y,preserveScrollOnPrependRef:h,setViewportElement:g,syncAfterScroll:w,userScrollIntent:E,viewportRef:v}=xe();h.current=i;let T=a.useCallback(N=>{g(N),Ae(c)?.(N)},[c,g]);function H(N){w(),r?.(N)}function U(N){E(),l?.(N)}function K(N){E(),o?.(N)}function z(N){br.has(N.key)&&E(),n?.(N)}return a.useEffect(()=>{let N=v.current;if(!N||typeof ResizeObserver>"u")return;let L=0,G=new ResizeObserver(()=>{window.cancelAnimationFrame(L),L=window.requestAnimationFrame(y)});return G.observe(N),()=>{window.cancelAnimationFrame(L),G.disconnect()}},[y,v]),s.jsx("div",{ref:T,role:u??"region","aria-label":e??"Messages",tabIndex:d??0,onKeyDown:z,onScroll:H,onTouchMove:K,onWheel:U,...m,children:t})}function Hr({"aria-relevant":e,children:t,ref:n,role:r,spacerClassName:o,...l}){let{handleContentChange:i,handleResize:c,setContentElement:u,setSpacerElement:d}=xe(),m=a.useRef(null),y=a.useCallback(h=>{m.current=h,u(h),Ae(n)?.(h)},[n,u]);return a.useLayoutEffect(()=>{let h=m.current;if(!h||(i(),typeof MutationObserver>"u"))return;let g=new MutationObserver(()=>{i()});return g.observe(h,{childList:!0}),()=>g.disconnect()},[i]),a.useEffect(()=>{let h=m.current;if(!h||typeof ResizeObserver>"u")return;let g=0,w=new ResizeObserver(()=>{window.cancelAnimationFrame(g),g=window.requestAnimationFrame(c)});return w.observe(h),()=>{window.cancelAnimationFrame(g),w.disconnect()}},[c]),s.jsxs("div",{ref:y,role:r??"log","aria-relevant":e??"additions",...l,children:[t,s.jsx("div",{ref:d,"aria-hidden":"true","data-message-scroller-spacer":"",hidden:!0,className:o})]})}function zr({messageId:e,ref:t,scrollAnchor:n=!1,...r}){let o=Ur(),l=a.useRef(null),i=a.useCallback(c=>{let u=l.current;l.current=c,e&&o(e,c,u),Ae(t)?.(c)},[e,t,o]);return s.jsx("div",{ref:i,"data-message-id":e,"data-scroll-anchor":n?"true":"false",...r})}function Wr({behavior:e="smooth",children:t,direction:n="end",onClick:r,render:o,tabIndex:l,type:i="button",...c}){let{scrollToEnd:u,scrollToStart:d,stateStore:m}=xe(),y=Dr(r),h=a.useCallback(v=>m.subscribe(v),[m]),g=a.useCallback(()=>{let v=m.getSnapshot();return n==="start"?v.start:v.end},[n,m]),w=a.useSyncExternalStore(h,g,g),E=a.useCallback(v=>{w&&(y.current?.(v),v.defaultPrevented||(v.currentTarget.blur(),n==="start"?d({behavior:e}):u({behavior:e})))},[e,n,w,y,u,d]);return cr({defaultTagName:"button",props:ze({type:i,inert:!w,tabIndex:w?l:-1,children:t??s.jsxs("span",{children:["Scroll to ",n]}),onClick:E},c),render:o,state:{active:w,direction:n},stateAttributesMapping:{active:v=>({"data-active":v?"true":"false"})}})}var ve={Provider:Fr,Root:Vr,Viewport:Br,Content:Hr,Item:zr,Button:Wr};const Kr=ve.Provider;function qr({className:e,...t}){return s.jsx(ve.Root,{className:P("relative flex size-full min-h-0 flex-col overflow-hidden",e),...t})}function Gr({className:e,...t}){return s.jsx(ve.Viewport,{className:P("size-full min-h-0 overflow-y-auto overscroll-contain [scrollbar-gutter:stable]",e),...t})}function Yr({className:e,...t}){return s.jsx(ve.Content,{className:P("flex h-max min-h-full flex-col",e),...t})}function Jr({className:e,...t}){return s.jsx(ve.Item,{className:P("min-w-0 shrink-0",e),...t})}function Qr({className:e,...t}){return s.jsx(ve.Button,{direction:"end",behavior:"smooth",render:({active:n,...r})=>n?s.jsx(fe,{...r,type:"button",variant:"outline",size:"icon",className:P("absolute right-4 bottom-4 z-20 rounded-full bg-background ",e),"aria-label":"Scroll to latest message",children:s.jsx(nn,{})}):null,...t})}function Xr(e){if(!e)return"";const t=e.startsWith("?")?e.slice(1):e,n=new URLSearchParams(t);return n.get("message_id")?.trim()||n.get("message")?.trim()||""}function Zr(e){const t=e.scrollTarget.trim();return t?e.alreadyScrolledTo===t?{scroll:!1}:e.messageIds.includes(t)?{scroll:!0,id:t}:{scroll:!1}:{scroll:!1}}const eo="lobu-spa";function pt(e){return typeof e=="string"&&/^https?:\/\//i.test(e.trim())}function De(e,t){return t.type==="tool-call"?`tc-${t.toolCallId}`:t.type==="reasoning"?`${e.id}-reasoning`:t.type==="bash"?`${e.id}-bash-${t.command.slice(0,24)}`:t.type==="error"?`${e.id}-error`:`${e.id}-text-${t.text.slice(0,24)}`}const Fo=({afterMessagesContent:e,readOnly:t=!1,readerPositionMode:n="messages",interactionExtension:r,onRunSelect:o})=>{const{messages:l,agentId:i,conversationId:c}=Ee(),{data:u=[]}=rn(i,{conversationId:c});return s.jsx($n,{extension:r,children:s.jsxs("div",{"data-agent-thread":!0,className:"flex min-h-0 flex-1 flex-col",children:[s.jsx(to,{messages:l,trips:u,mode:n,afterMessagesContent:e,onRunSelect:o}),t?null:s.jsx("div",{className:Sn,children:s.jsx(Io,{})})]})})},to=({messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})=>s.jsx(Kr,{autoScroll:!0,defaultScrollPosition:n==="runs"?"last-anchor":"end",scrollPreviousItemPeek:48,children:s.jsx(ro,{messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})});function no(e){if(!e.startsWith("sep:"))return null;const t=Number(e.slice(4));return Number.isFinite(t)&&t>0?t:null}const ro=({messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})=>{const{currentAnchorId:l}=Dt(),{scrollToMessage:i}=$t(),c=a.useRef(null);a.useEffect(()=>{if(e.length===0||typeof window>"u")return;const d=Zr({messageIds:e.map(m=>m.id),scrollTarget:Xr(window.location.search),alreadyScrolledTo:c.current});d.scroll&&(c.current=d.id,i(d.id,{align:"start",behavior:"smooth"}))},[e,i]);const u=d=>n==="runs"?d.id.startsWith("sep:"):d.role==="user";return s.jsxs(qr,{children:[s.jsx(Gr,{"aria-label":n==="runs"?"Automation run history":"Conversation",children:s.jsxs(Yr,{className:P(Ge,Tn),children:[e.map(d=>{const m=n==="runs"&&o?no(d.id):null;return s.jsx(Jr,{messageId:d.id,scrollAnchor:u(d),"aria-current":d.id===l?"location":void 0,className:P("flex flex-col",n==="runs"&&u(d)&&"border-l-2 border-transparent pl-2 transition-colors",n==="runs"&&d.id===l&&"border-primary"),children:m!=null?s.jsx(xo,{message:d,onClick:()=>o?.(m)}):s.jsx(ao,{message:d})},d.id)}),t.map(d=>s.jsx(so,{trip:d},d.id)),s.jsx(lo,{}),r?s.jsx("div",{className:"mt-auto shrink-0 py-2",children:r}):null]})}),e.length>0?s.jsx(oo,{messages:e,mode:n}):null,s.jsx(Qr,{})]})},oo=({messages:e,mode:t})=>{const{scrollToMessage:n}=$t(),{currentAnchorId:r,visibleMessageIds:o}=Dt(),l=t==="runs"?e.flatMap(c=>c.parts).filter(c=>c.type==="tool-call"&&c.toolName==="tool-approval"&&c.args!==null&&typeof c.args=="object"&&c.args.status==="pending").length:0,i=e.flatMap(c=>{if(!(t==="runs"?c.id.startsWith("sep:"):c.role==="user"))return[];const d=c.parts.find(m=>m.type==="text");return[{id:c.id,label:d?.type==="text"?d.text:"Automation run"}]});return i.length===0?null:s.jsxs(cn,{children:[s.jsx(un,{asChild:!0,children:s.jsxs(fe,{type:"button",variant:"outline",size:"icon",className:P("absolute top-1/2 right-4 z-20 -translate-y-1/2 rounded-full bg-background/95 ",l>0&&"w-auto px-3"),"aria-label":l>0?`Open transcript outline, ${l} ${l===1?"approval":"approvals"} waiting`:"Open transcript outline",children:[s.jsx(dn,{}),l>0?s.jsxs("span",{className:"text-xs tabular-nums",children:[l," waiting"]}):null]})}),s.jsxs(fn,{side:"left",align:"center",className:"w-80 space-y-3 p-3",children:[s.jsxs("div",{className:"px-1",children:[s.jsx("p",{className:"text-sm font-medium",children:"Transcript outline"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:t==="runs"?"Track and jump between Automation runs.":"Track and jump between your messages."})]}),s.jsx("div",{className:"max-h-80 space-y-1 overflow-y-auto",children:i.map(c=>{const u=c.id===r,d=o.includes(c.id);return s.jsxs(fe,{type:"button",variant:u?"secondary":"ghost",className:"h-auto w-full justify-start gap-2 px-2 py-2 text-left text-xs font-normal","aria-current":u?"location":void 0,onClick:()=>n(c.id,{align:"start",behavior:"smooth"}),children:[s.jsx("span",{className:P("size-1.5 shrink-0 rounded-full bg-muted-foreground/30",d&&"bg-primary/60",u&&"bg-primary")}),s.jsx("span",{className:"line-clamp-2",children:c.label})]},c.id)})})]})]})},so=({trip:e})=>s.jsxs("div",{className:P(Ge,"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive"),children:[s.jsx(an,{className:"mt-0.5 size-4 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"font-medium",children:["Guardrail blocked: ",e.guardrailName," ",s.jsxs("span",{className:"font-normal opacity-70",children:["(",e.stage,")"]})]}),e.reason?s.jsx("div",{className:"mt-0.5 break-words opacity-80",children:e.reason}):null]})]}),lo=()=>{const{currentSuggestions:e,starters:t,messages:n,running:r,append:o}=Ee(),l=Kn(e,t,n.length);return r||l.length===0?null:s.jsx(Nn,{prompts:l,className:P(Ge,n.length===0&&"mt-auto"),onPick:i=>o(i)})},ao=({message:e})=>e.role==="user"?s.jsx(io,{message:e}):e.role==="system"?s.jsx(vo,{message:e}):s.jsx(fo,{message:e}),Ut=({attachment:e})=>{const t=e.isImage?e.imageDataUrl??e.url:void 0;if(t)return s.jsx("a",{href:e.url??t,target:"_blank",rel:"noreferrer",children:s.jsx("img",{src:t,alt:e.name,className:"max-h-64 rounded-lg border object-contain"})});const n=s.jsxs(s.Fragment,{children:[s.jsx(He,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"max-w-[14rem] truncate",children:e.name})]});return s.jsx("div",{className:"flex items-center gap-1.5 rounded-md border bg-background px-2 py-1 text-xs",children:e.url?s.jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 hover:underline",children:n}):n})},io=({message:e})=>{const t=e.parts.filter(n=>n.type==="bash");return t.length>0?s.jsx("div",{className:xt,children:s.jsx("div",{className:"space-y-2",children:t.map(n=>s.jsx(co,{part:n},De(e,n)))})}):s.jsx("div",{className:jn,children:s.jsxs("div",{className:P(Ne,"px-3 py-2 text-sm"),children:[e.attachments&&e.attachments.length>0?s.jsx("div",{className:"mb-1.5 flex flex-wrap gap-1.5",children:e.attachments.map(n=>s.jsx(Ut,{attachment:n},n.id))}):null,e.parts.map(n=>n.type==="text"?s.jsx("div",{className:"whitespace-pre-wrap break-words",children:s.jsx(Xe,{text:n.text,renderText:r=>r})},De(e,n)):null)]})})},co=({part:e})=>{const t=e.cancelled||e.exitCode!==void 0&&e.exitCode!==0;return s.jsxs("div",{className:P(Ne,"overflow-hidden text-xs"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-border/60 border-b px-3 py-1.5",children:[s.jsx(pn,{className:"size-3.5 shrink-0 text-muted-foreground"}),s.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-foreground/90",children:e.command}),e.cancelled?s.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 font-medium text-[10px] text-muted-foreground",children:"cancelled"}):t?s.jsxs("span",{className:"rounded bg-destructive/15 px-1.5 py-0.5 font-medium text-[10px] text-destructive",children:["exit ",e.exitCode]}):null]}),e.output.trim()?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-3 py-2 font-mono text-foreground/80",children:e.output}):null]})},Ft=new Set(["question","link-button","tool-approval"]),uo="subscription-candidate",fo=({message:e})=>{const t=Ye(),{agentId:n,workspaceSlug:r}=Ee(),o=u=>u.type==="tool-call"&&(Ft.has(u.toolName)||t?.toolNames.has(u.toolName)),l=e.parts.filter(u=>u.type==="tool-call"&&!o(u)&&u.toolName!==uo),i=e.parts.filter(u=>u.type!=="tool-call"||o(u)),c=e.parts.flatMap(u=>{if(u.type!=="tool-call")return[];const d=Rt(u.result);return d?[d]:[]});return s.jsx("div",{className:xt,children:s.jsxs("div",{className:"space-y-2 text-sm",children:[l.length>0?s.jsx(ho,{tools:l,workspaceSlug:r}):null,n&&r?c.map(u=>s.jsx(po,{candidate:u,agentId:n,workspaceSlug:r},`${u.connector_key}:${u.resource_ref}`)):null,i.map(u=>s.jsx(bo,{part:u},De(e,u))),e.attachments&&e.attachments.length>0?s.jsx("div",{className:"flex flex-wrap gap-2",children:e.attachments.map(u=>s.jsx(Ut,{attachment:u},u.id))}):null]})})},po=({candidate:e,agentId:t,workspaceSlug:n})=>s.jsxs("div",{className:P(Ne,"flex items-center justify-between gap-3 p-3"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"truncate text-sm font-medium",children:e.label}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Run this agent when the resource changes."})]}),s.jsx(fe,{asChild:!0,size:"sm",variant:"outline",className:"shrink-0",children:s.jsxs(gt,{to:"/$owner/automations/new",params:{owner:n},search:{agent:t,platform:e.connector_key,resource_type:e.resource_type,resource:e.resource_ref,events:e.suggested_event_keys?.join(","),label:e.label},children:[s.jsx(hn,{className:"mr-1.5 h-4 w-4"}),"Add automation"]})})]});function mo(e){try{return JSON.parse(e)}catch{return null}}function Vt(e){if(Array.isArray(e)){const o=e.flatMap(l=>l?.type==="text"&&typeof l.text=="string"?Vt(l.text)??[]:[]);return o.length>0?[...new Set(o)]:null}const t=typeof e=="string"&&e.trimStart().startsWith("{")?mo(e):e;if(!t||typeof t!="object")return null;const n=t.events_persisted;if(!Array.isArray(n))return null;const r=n.flatMap(o=>{const l=o&&typeof o=="object"?o.id:null;return typeof l=="number"&&Number.isSafeInteger(l)&&l>0?[l]:[]});return r.length>0?r:null}const ho=({tools:e,workspaceSlug:t})=>s.jsxs(Nt,{defaultOpen:!1,children:[s.jsx(Et,{children:e.length===1?ot(e[0].args,e[0].toolName)??e[0].toolName:`${e.length} tool calls`}),s.jsx(It,{children:e.map(n=>{const r=ot(n.args,n.toolName),o=n.args!==void 0&&n.args!==null,l=n.result!==void 0&&n.result!==null,i=Vt(n.result);return s.jsxs(At,{icon:mn,label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"font-medium",children:r??n.toolName}),r?s.jsx("span",{className:"text-muted-foreground",children:n.toolName}):null,n.isError?s.jsx("span",{className:"rounded bg-destructive/15 px-1.5 py-0.5 font-medium text-[10px] text-destructive",children:"error"}):null]}),status:n.isError?"active":"complete",children:[o?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-foreground/80 text-xs",children:Fe(n.args)}):null,l?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-foreground/80 text-xs",children:Fe(n.result)}):null,i&&t?s.jsx(ir,{ownerSlug:t,eventIds:i}):null]},n.toolCallId)})})]}),go=({text:e})=>{let t=e,n=null;const r=e.match(/\{[\s\S]*\}/);if(r)try{const l=JSON.parse(r[0])?.error?.message;typeof l=="string"&&l.trim()&&(t=l,n=e)}catch{}return s.jsxs("div",{className:"flex gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2.5 text-sm",children:[s.jsx(bn,{className:"mt-0.5 size-4 shrink-0 text-destructive"}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx("p",{className:"text-foreground/80",children:t}),n&&s.jsxs("details",{className:"text-xs text-muted-foreground",children:[s.jsx("summary",{className:"cursor-pointer select-none hover:text-foreground",children:"Technical details"}),s.jsx("pre",{className:"mt-1 overflow-x-auto whitespace-pre-wrap break-all font-mono",children:n})]})]})]})},bo=({part:e})=>{const t=Ye();return e.type==="reasoning"?s.jsx(lr,{}):e.type==="error"?s.jsx(go,{text:e.text}):e.type==="text"?e.text.trim()?s.jsx(Xe,{text:e.text,renderText:n=>s.jsx(gn,{text:n})}):null:e.type!=="tool-call"?null:Ft.has(e.toolName)||t?.toolNames.has(e.toolName)?s.jsx(Ao,{toolName:e.toolName,args:e.args}):null},xo=({message:e,onClick:t})=>{const n=e.parts.find(r=>r.type==="text");return s.jsx("button",{type:"button",onClick:t,className:P(Ne,"block w-full cursor-pointer whitespace-pre-wrap break-words px-3 py-2 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/50"),children:n?.type==="text"?n.text:"Automation run"})},vo=({message:e})=>s.jsx("div",{className:"self-stretch",children:s.jsx("div",{className:P(Ne,"px-3 py-2 text-xs text-muted-foreground"),children:e.parts.map(t=>t.type==="text"?s.jsx("div",{className:"whitespace-pre-wrap break-words",children:s.jsx(Xe,{text:t.text,renderText:n=>n})},De(e,t)):null)})}),yo="/mcp-apps/interaction/index.html";function mt(e){return new Promise(t=>{e({onSettled:(n,r)=>t(!!r)})})}const Ro=({src:e,title:t,renderPayload:n,onToolCall:r,onOpenLink:o})=>{const l=a.useRef(null),[i,c]=a.useState(48),u=a.useRef({renderPayload:n,onToolCall:r,onOpenLink:o});return u.current={renderPayload:n,onToolCall:r,onOpenLink:o},a.useEffect(()=>{const d=l.current;if(!d?.contentWindow)return;const m=new yn(null,{name:"Lobu",version:"1.0.0"},{openLinks:{},serverTools:{}},{hostContext:{theme:document.documentElement.classList.contains("dark")?"dark":"light",displayMode:"inline",platform:"web"}});m.addEventListener("sizechange",({height:g})=>{typeof g=="number"&&c(Math.max(32,Math.ceil(g)))}),m.oncalltool=async({name:g,arguments:w})=>{const E=await u.current.onToolCall(g,w??{});return{isError:E,content:[{type:"text",text:E?"Action failed.":"Action completed."}]}},m.onopenlink=async({url:g})=>({isError:await u.current.onOpenLink(g)}),m.addEventListener("initialized",()=>{(async()=>(await m.sendToolInput({arguments:{}}),await m.sendToolResult({content:[],structuredContent:{...u.current.renderPayload,version:1,source:eo}})))()});const y=new Rn(d.contentWindow,d.contentWindow);m.connect(y).catch(g=>{console.error("[mcp-app-host] failed to initialize",g)});const h=new MutationObserver(()=>{m.setHostContext({theme:document.documentElement.classList.contains("dark")?"dark":"light",displayMode:"inline",platform:"web"})});return h.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{h.disconnect(),y.close()}},[]),s.jsx("iframe",{ref:l,title:t,src:e,sandbox:"allow-scripts",style:{width:"100%",height:i,border:"none",display:"block"}})},wo=new Set(["action"]),So=["name","description","identity_md"];function oe(e){return e==null||e===""?"":typeof e=="string"?e:Fe(e)}function ht(e){return e===null?"(cleared)":e===void 0?"":typeof e=="string"?e===""?"":e:Fe(e)}function Ue(e){return e.length>0?e[0].toUpperCase()+e.slice(1):e}const Bt=new Set(["delete","disconnect","remove","remove_rule","reset","revoke"]);function Ke(e){return e&&Bt.has(e)?"warning":"default"}function qe(e,t){return e&&Bt.has(e)?{level:"high",reason:t}:{level:"normal"}}function To(e,t){const n=e.attribution==="automation"?"An Automation":"An agent",r=Object.keys(t),o=r.map(l=>({label:l,before:oe(e.current?.[l]),after:oe(t[l])}));return{title:`${n} proposes a change`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:o.length>0?[{type:"diff",fields:o}]:[{type:"text",value:"No field changes.",muted:!0}],actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${r.join(", ")} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${r.join(", ")} was not applied.`}]}}function jo(e){const t=e.action??"change",n=e.proposal?.slug??e.proposal?.name??(e.proposal?.automation_id!=null?String(e.proposal.automation_id):void 0)??e.current?.slug??e.current?.name??"automation",r=[];e.action==="delete"&&r.push({type:"text",value:"This will archive the Automation.",muted:!0});const o=e.proposal??{},l=Object.keys(o).filter(i=>!wo.has(i)&&o[i]!==void 0).map(i=>({label:i,...e.action==="update"&&e.current?.[i]!==void 0?{before:ht(e.current?.[i])}:{},after:ht(o[i])}));return r.push(l.length>0?{type:"diff",fields:l}:{type:"text",value:"No field changes.",muted:!0}),{title:`${Ue(t)} Automation ${n}`,icon:"automation",impact:qe(e.action,"This archives the Automation and stops future runs."),tone:Ke(e.action),blocks:r,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${t} ${n} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${t} ${n} was not applied.`}]}}function Co(e){if(e.resourceKind==="automation")return jo(e);if(e.fields&&Object.keys(e.fields).length>0)return To(e,e.fields);const t=e.resourceKind==="entity"||e.proposal?.entity_id!==void 0||e.current?.entity_type!==void 0||e.proposal?.entity_type!==void 0;if(t&&(e.action==="link"||e.action==="unlink"))return Ln({...e,action:e.action});if(t){const l=e.proposal?.name??e.current?.name??e.proposal?.entity_id??e.current?.id??"entity",i=e.action??"change",c=[];if(e.action==="delete")c.push({type:"text",value:"This will delete the entity.",muted:!0});else{const u=Object.keys(e.proposal??{}).filter(d=>!["entity_id","id"].includes(d)&&e.proposal?.[d]!==void 0&&oe(e.proposal?.[d])!==oe(e.current?.[d])).map(d=>({label:d,...e.action==="update"?{before:oe(e.current?.[d])}:{},after:oe(e.proposal?.[d])}));c.push(u.length>0?{type:"diff",fields:u}:{type:"text",value:"No field changes.",muted:!0})}return{title:`${Ue(i)} entity ${l}`,icon:"entity",impact:qe(e.action,"This deletes the entity."),tone:Ke(e.action),blocks:c,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${i} ${l} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${i} ${l} was not applied.`}]}}const n=e.proposal?.agent_id??e.current?.id??"agent",r=e.action??"change",o=[];if(e.action==="delete")o.push({type:"text",value:"This will permanently delete the agent.",muted:!0});else{const l=So.filter(i=>e.proposal?.[i]!==void 0&&oe(e.proposal?.[i])!==oe(e.current?.[i])).map(i=>({label:i,...e.action==="update"?{before:oe(e.current?.[i])}:{},after:oe(e.proposal?.[i])}));o.push(l.length>0?{type:"diff",fields:l}:{type:"text",value:"No field changes.",muted:!0})}return{title:`${Ue(r)} agent ${n}`,icon:"agent",impact:qe(e.action,"This permanently deletes the agent and its configuration."),tone:Ke(e.action),blocks:o,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${r} ${n} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${r} ${n} was not applied.`}]}}function No(e){const t=Array.isArray(e.options)?e.options.filter(o=>typeof o=="string"):[],n=[{type:"text",value:e.question||"The agent has a question."}];t.length===0&&n.push({type:"text",value:"Reply below to answer.",muted:!0});const r=t.map(o=>({id:o,label:o,variant:"outline",tool:"answer_question",args:{answer:o},resolvedLabel:`Answered: ${o}`}));return{title:"Input needed",icon:"question",tone:"default",blocks:n,actions:r}}function Eo(e,t){return{tone:"bare",actions:[{id:"open",label:e.label??"Open link",variant:"outline",icon:"external",terminal:!1,href:t}]}}const Ao=({toolName:e,args:t})=>{const n=xn(),r=vn(),{append:o}=Ee(),l=Ye(),i=t??{},c=l?.resolve(e,t)??null;let u=c?.view??null;const d={...c?.handlers??{}},m=new Set;if(!c){if(e==="tool-approval"&&typeof i.runId=="number"&&Number.isSafeInteger(i.runId)&&i.runId>0){const y=i.runId,h=typeof i.status=="string"?i.status:"pending",g=h==="pending",w=Co(i),E=h==="confirmed"?"Approved":Ue(h);u=g?w:{...w,title:`${w.title??"Approval"} · ${E}`,tone:h==="failed"?"warning":"default",blocks:[...w.blocks??[],{type:"text",value:typeof i.reviewedByName=="string"?`${h==="rejected"?"Rejected":"Approved"} by ${i.reviewedByName}.`:`${E}.`,muted:!0}],actions:(w.actions??[]).filter(v=>v.terminal===!1)},g&&(d.manage_operations=v=>{if(v.action==="approve")return mt(T=>n.mutate({run_id:y},T));if(v.action==="reject"){const T=typeof v.reason=="string"?v.reason:void 0;return mt(H=>r.mutate({run_id:y,...T?{reason:T}:{}},H))}return Promise.resolve(!0)})}else if(e==="question"){const y=Array.isArray(i.options)?i.options.filter(h=>typeof h=="string"):[];u=No(i),d.answer_question=h=>{const g=typeof h.answer=="string"?h.answer:"";return y.includes(g)?(o(g),Promise.resolve(!1)):Promise.resolve(!0)}}else if(e==="link-button"){if(!pt(i.url))return null;const y=i.url;m.add(y),u=Eo(i,y)}}return u?s.jsx(Ro,{src:yo,title:u.title??"Interaction",renderPayload:u,onToolCall:(y,h)=>d[y]?d[y](h):Promise.resolve(!0),onOpenLink:y=>!m.has(y)||!pt(y)?Promise.resolve(!0):(window.open(y,"_blank","noopener,noreferrer"),Promise.resolve(!1))}):null};function Fe(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}const Io=()=>{const{running:e,append:t,cancel:n,pendingAttachments:r,addAttachments:o,removeAttachment:l,initialDraft:i,currentSuggestions:c}=Ee(),u=ko({suggestions:e?null:c}),[d,m]=a.useState(i??""),y=a.useRef(null),h=a.useRef(null),g=_n(On),w=a.useRef(i??"");a.useEffect(()=>{const T=i??"";if(T===w.current)return;const H=w.current;w.current=T,T!==""&&m(U=>U===""||U===H?T:U)},[i]);const E=a.useRef(d);E.current=d;const v=()=>{e||(t(E.current),m(""),h.current?.clear())};return s.jsxs("div",{className:"rounded-2xl border bg-background transition-colors focus-within:ring-1 focus-within:ring-ring",children:[r.length>0?s.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 pt-3",children:r.map(T=>s.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border bg-muted/50 px-2 py-1 text-xs",children:[s.jsx(He,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"max-w-[12rem] truncate",children:T.name}),s.jsx("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground","aria-label":"Remove attachment",onClick:()=>l(T.id),children:s.jsx(on,{className:"h-3 w-3"})})]},T.id))}):null,s.jsx(Pn,{value:d,onChange:m,onSubmit:v,searchRefs:g,handleRef:h,placeholder:u,className:"max-h-48 overflow-y-auto"}),s.jsxs("div",{className:"flex items-center justify-between px-3 pb-2",children:[s.jsx("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:T=>{T.target.files&&o(T.target.files),T.target.value=""}}),s.jsxs(fe,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 rounded-full text-muted-foreground hover:text-foreground",onClick:()=>y.current?.click(),children:[s.jsx(He,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Attach files"})]}),e?s.jsxs(fe,{type:"button",size:"icon",variant:"secondary",className:"h-8 w-8 rounded-full",onClick:n,children:[s.jsx(sn,{size:"lg"}),s.jsx("span",{className:"sr-only",children:"Cancel"})]}):s.jsxs(fe,{type:"button",size:"icon",className:"h-8 w-8 rounded-full",onClick:v,children:[s.jsx(ln,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Send message"})]})]})]})};function ko({suggestions:e}){const t=e?.find(n=>n.message.trim().length>0)?.message;return t?`Recommended: ${t.trim()}`:"Chat… (@ to mention, / for commands)"}export{Fo as A,Uo as L,Do as R,er as h,Jn as s};
|
|
6
|
+
//# sourceMappingURL=agent-thread-Bv_chdPy.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as c,
|
|
2
|
-
//# sourceMappingURL=app._appId-
|
|
1
|
+
import{r as c,jh as g,bb as w,a_ as y,bk as C,a$ as u,j as e,as as k,L as o,ic as j,ij as A,B as N,ii as P,jv as $,jb as v,dt as B,dv as D,dw as R,A as I,a4 as L,f$ as M,jw as _,aT as E}from"./index-CdDNNAx2.js";import{C as O}from"./connector-page-shell-BeuyjiB2.js";function T({ownerSlug:s,appId:a}){const n=c.useMemo(()=>g(s,a,w()),[s,a]),{data:r=[],isLoading:l,isError:d,refetch:b}=y(),[m,x]=c.useMemo(()=>{const t=n?.devicePlatforms;if(!t?.length)return[[],[]];const h=r.filter(i=>{const f=C(i);return f!=null&&t.includes(f)});return[h.filter(i=>u(i,s)),h.filter(i=>!u(i,s))]},[n,r,s]);if(!n)return e.jsxs(k,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"There is no app by that name."}),e.jsx(o,{to:"/$owner/connectors",params:{owner:s},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const p=(n.devicePlatforms?.length??0)>0;return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(O,{header:e.jsx(B,{breadcrumb:e.jsx(D,{crumbs:[e.jsx(o,{to:"/$owner/connectors",params:{owner:s},search:{},className:R,children:"Connectors"},"connectors")]}),icon:e.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border text-muted-foreground",children:n.icon}),title:n.name,caption:n.description}),children:[e.jsx("div",{id:"setup",className:"scroll-mt-40",children:e.jsx(j,{title:m.length>0?a==="owletto-chrome"?"Connect another profile":"Connect another device":"Set up",children:e.jsx("div",{className:"space-y-3",children:n.steps.map(t=>e.jsx(z,{step:t},t.label))})})}),p?e.jsx(A,{entries:m.map(t=>({id:t.id,name:v(t),description:$(t,s),tone:t.online?null:"muted",link:P({to:"/$owner/connectors/device/$deviceId",params:{owner:s,deviceId:t.id}})})),isLoading:l,isError:d,onRetry:()=>void b(),action:e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx("a",{href:"#setup",children:"Add connection"})})}):null,p&&!l&&!d&&x.length>0?e.jsxs(j,{title:"Your devices in other workspaces",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Open a device to connect its capabilities here. Moving it is confirmed first and pauses its connections where it is now."}),e.jsx("ul",{className:"divide-y border-y",children:x.map(t=>e.jsx("li",{children:e.jsxs(o,{to:"/$owner/connectors/device/$deviceId",params:{owner:s,deviceId:t.id},className:"flex items-center justify-between gap-3 py-2.5 text-sm hover:text-primary",children:[e.jsx("span",{className:"font-medium",children:v(t)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Attached to"," ",t.organization_name??"another workspace"]})]})},t.id))})]}):null]})})}function z({step:s}){const[a,n]=c.useState(!1);if(s.href)return e.jsxs("a",{href:s.href,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs font-medium text-primary hover:bg-accent/50",children:[s.label,e.jsx(I,{className:"h-3 w-3"})]});const r=s.command??"";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.label}),e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border bg-muted/40 p-2.5",children:[e.jsx("pre",{className:"min-w-0 flex-1 overflow-x-auto font-mono text-xs leading-relaxed",children:r}),e.jsxs(N,{variant:"ghost",size:"sm",className:"h-6 shrink-0 px-1.5 text-xs",onClick:()=>{typeof navigator>"u"||!navigator.clipboard||navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),1500)})},children:[a?e.jsx(L,{className:"h-3.5 w-3.5"}):e.jsx(M,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"sr-only",children:"Copy"})]})]})]})}function G(){const{owner:s,appId:a}=_.useParams();return e.jsx(E,{owner:s,children:({ownerSlug:n})=>e.jsx(T,{ownerSlug:n,appId:a})})}export{G as component};
|
|
2
|
+
//# sourceMappingURL=app._appId-BUcNaSMS.js.map
|