bazilion 0.25.0 → 0.26.1
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/README.md +41 -140
- package/dist/cli.js +5001 -2
- package/dist/cli.js.map +1 -0
- package/dist/daemon.js +17836 -2
- package/dist/daemon.js.map +1 -0
- package/dist/schema.sql +382 -0
- package/dist/web/client/assets/{AgentAvatar-JYijLvZ2.js → AgentAvatar-DWx-bM6n.js} +1 -1
- package/dist/web/client/assets/ChatPane-DOV_HJg-.js +72 -0
- package/dist/web/client/assets/ConfigPage-Dfu9DzFX.js +1 -0
- package/dist/web/client/assets/ConfirmDialog-536ziJ5P.js +1 -0
- package/dist/web/client/assets/FieldRow-z1JqCdqn.js +1 -0
- package/dist/web/client/assets/ModelSelect-CvOHjUyB.js +1 -0
- package/dist/web/client/assets/ResultCard-X4nTbjYY.js +1 -0
- package/dist/web/client/assets/SectionTabs-DXHzXmmb.js +1 -0
- package/dist/web/client/assets/SkillFindings-8LX6bYf_.js +1 -0
- package/dist/web/client/assets/SkillsPicker-Cr87y_W-.js +1 -0
- package/dist/web/client/assets/SpawnDialog-DoZl-yes.js +1 -0
- package/dist/web/client/assets/SpawnTeamModal-C638hEoN.js +1 -0
- package/dist/web/client/assets/Tabs-D0LgBNIk.js +1 -0
- package/dist/web/client/assets/TeamForm-C-WzvOl4.js +1 -0
- package/dist/web/client/assets/TeamPolicyEditor-CSKBx0oK.js +7 -0
- package/dist/web/client/assets/UnsavedChangesGuard-GC-vzw7h.js +1 -0
- package/dist/web/client/assets/_id-BKLynswT.js +1 -0
- package/dist/web/client/assets/_id-BYM_NORr.js +1 -0
- package/dist/web/client/assets/_id-Cxa98a9m.js +1 -0
- package/dist/web/client/assets/_id-D4hV1U1t.js +1 -0
- package/dist/web/client/assets/agent-actions-CXQCoxKO.js +1 -0
- package/dist/web/client/assets/agents-BxPS1_Bp.js +1 -0
- package/dist/web/client/assets/agents-GozAWW-l.js +1 -0
- package/dist/web/client/assets/attention-Cz9rZcrr.js +1 -0
- package/dist/web/client/assets/chevron-right-CPAb1zac.js +1 -0
- package/dist/web/client/assets/config-9vv9Lipb.js +3 -0
- package/dist/web/client/assets/entities-xVoB-p2j.js +1 -0
- package/dist/web/client/assets/inbox-DHLArXxl.js +1 -0
- package/dist/web/client/assets/index-1YXquAq8.js +52 -0
- package/dist/web/client/assets/jsx-runtime-bzQ4Vb5N.js +1 -0
- package/dist/web/client/assets/learning-PvtXm8Ne.js +1 -0
- package/dist/web/client/assets/login-DIJpNQFo.js +1 -0
- package/dist/web/client/assets/mcp-pKBL0xIf.js +1 -0
- package/dist/web/client/assets/members-DHWsgsEs.js +1 -0
- package/dist/web/client/assets/memory-CEVppPyU.js +1 -0
- package/dist/web/client/assets/plus-BaIRdB10.js +1 -0
- package/dist/web/client/assets/policy-DEh4BLSw.js +1 -0
- package/dist/web/client/assets/preload-helper-eUUcpe2S.js +1 -0
- package/dist/web/client/assets/results-DgJPjEZF.js +1 -0
- package/dist/web/client/assets/review-BbshafTQ.js +1 -0
- package/dist/web/client/assets/route-Ccb8v41z.js +1 -0
- package/dist/web/client/assets/route-D1d6kCEV.js +1 -0
- package/dist/web/client/assets/routes-g7V4ru7T.js +1 -0
- package/dist/web/client/assets/services-B2f7e5jV.js +1 -0
- package/dist/web/client/assets/settings-B6elpcYm.js +1 -0
- package/dist/web/client/assets/skills-CngE7TF8.js +1 -0
- package/dist/web/client/assets/styles-xUnZ-ep_.css +2 -0
- package/dist/web/client/assets/teams-BdJZXOan.js +1 -0
- package/dist/web/client/assets/teams-c496ISsT.js +1 -0
- package/dist/web/client/assets/telegram-B_-hK6EC.js +1 -0
- package/dist/web/client/assets/tokens-CKz8gx4-.js +1 -0
- package/dist/web/client/assets/triggers-DCEPciGW.js +1 -0
- package/dist/web/client/assets/welcome-D-zVOLGA.js +1 -0
- package/dist/web/client/baziu.svg +176 -7
- package/dist/web/server/assets/ChatPane-De_FPEoD.js +1887 -0
- package/dist/web/server/assets/ConfigPage-CGld_wCK.js +28 -0
- package/dist/web/server/assets/ConfirmDialog-LdVlEanK.js +132 -0
- package/dist/web/server/assets/{FieldRow-DPO8x_le.js → FieldRow-Dah2KKqo.js} +8 -15
- package/dist/web/server/assets/ModelSelect-Vwro6OkL.js +43 -0
- package/dist/web/server/assets/{Page-DJNoI4Gn.js → Page-CMSYKXWJ.js} +51 -2
- package/dist/web/server/assets/ResultCard-CZn1w4KA.js +97 -0
- package/dist/web/server/assets/SectionTabs-CqFg9Vwx.js +53 -0
- package/dist/web/server/assets/Sidebar-puq47KyR.js +430 -0
- package/dist/web/server/assets/SkillFindings-Bd6e81Wu.js +46 -0
- package/dist/web/server/assets/SkillsPicker-DlqEfRWh.js +67 -0
- package/dist/web/server/assets/SpawnDialog-BGNaMfFb.js +111 -0
- package/dist/web/server/assets/SpawnTeamModal-C6GbfScI.js +97 -0
- package/dist/web/server/assets/Tabs-BhF41MfQ.js +20 -0
- package/dist/web/server/assets/TeamForm-C93tpn9r.js +96 -0
- package/dist/web/server/assets/TeamPolicyEditor-BHS3J0R9.js +738 -0
- package/dist/web/server/assets/{UnsavedChangesGuard-BfSyMhiD.js → UnsavedChangesGuard-Dm4a27_5.js} +1 -1
- package/dist/web/server/assets/_id-B0x1ffz3.js +12 -0
- package/dist/web/server/assets/_id-BR6tnR6I.js +23 -0
- package/dist/web/server/assets/_id-Bdf_Rg62.js +19 -0
- package/dist/web/server/assets/_id-Bm611NQz.js +13 -0
- package/dist/web/server/assets/{_id-4fEeAcp0.js → _id-ByiXeIPS.js} +9 -8
- package/dist/web/server/assets/_id-D5UCoyES.js +359 -0
- package/dist/web/server/assets/_id-DHx5UmmL.js +12 -0
- package/dist/web/server/assets/_id-DLpGmOVm.js +19 -0
- package/dist/web/server/assets/_id-Y5ctILG2.js +13 -0
- package/dist/web/server/assets/_id-dDA0pdVo.js +54 -0
- package/dist/web/server/assets/_id-lOVnT5sS.js +383 -0
- package/dist/web/server/assets/{_id-BhJCnRR1.js → _id-sW6zXrTP.js} +4 -4
- package/dist/web/server/assets/_tanstack-start-manifest_v-B8u80HjK.js +292 -0
- package/dist/web/server/assets/agent-actions-BBdFVdoa.js +20 -0
- package/dist/web/server/assets/{agents-Cmw-sUUD.js → agents-BK8OmB8g.js} +7 -6
- package/dist/web/server/assets/{agents-DOrzqCXg.js → agents-BNPkidbH.js} +8 -10
- package/dist/web/server/assets/{agents-BitDk_C5.js → agents-Cn9GkXFX.js} +1 -3
- package/dist/web/server/assets/agents-D4tqK1kH.js +131 -0
- package/dist/web/server/assets/agents-DycxHDt8.js +327 -0
- package/dist/web/server/assets/{agents-DmmuOHw8.js → agents-lOqc6VGd.js} +4 -4
- package/dist/web/server/assets/api-WWxPqx67.js +85 -0
- package/dist/web/server/assets/attention-BIm455bC.js +216 -0
- package/dist/web/server/assets/{attention-Cy3Xu-Su.js → attention-DULVjdmF.js} +2 -4
- package/dist/web/server/assets/{attention-CsYqmV0L.js → attention-YWnLKA2E.js} +4 -2
- package/dist/web/server/assets/{auth-DChuQIh4.js → auth-DiN92ydD.js} +7 -8
- package/dist/web/server/assets/{config-0_5yhRKg.js → config-BNEgu7WG.js} +141 -432
- package/dist/web/server/assets/{config-VsmvCulS.js → config-C1VB28se.js} +1 -1
- package/dist/web/server/assets/{config-CpHD812q.js → config-TdVqnqNL.js} +3 -7
- package/dist/web/server/assets/cookies-HnTYjKRp.js +17 -0
- package/dist/web/server/assets/daemon-client-DL2ik2Em.js +146 -0
- package/dist/web/server/assets/entities-Dn2xzKIw.js +16 -0
- package/dist/web/server/assets/inbox-4Vj5jTT8.js +245 -0
- package/dist/web/server/assets/inbox-D4IqUv3l.js +38 -0
- package/dist/web/server/assets/inbox-Dle24AfV.js +23 -0
- package/dist/web/server/assets/learning-BScq7VbO.js +12 -0
- package/dist/web/server/assets/learning-CBWFEnhg.js +263 -0
- package/dist/web/server/assets/{learning-BuL0c1vH.js → learning-DWAKevhF.js} +6 -14
- package/dist/web/server/assets/{login-rDox7PRD.js → login-JoIjlcmu.js} +2 -5
- package/dist/web/server/assets/{login-B_-9L8TU.js → login-VV10kZBl.js} +15 -17
- package/dist/web/server/assets/mcp-B09_O05r.js +250 -0
- package/dist/web/server/assets/{mcp-B8ErRiR_.js → mcp-BwmpNQPN.js} +1 -1
- package/dist/web/server/assets/{mcp-BEdnl_TT.js → mcp-CqdTfXcn.js} +1 -3
- package/dist/web/server/assets/members-B8QBF6TF.js +12 -0
- package/dist/web/server/assets/{members-DFLi2nQg.js → members-DsF02Wp7.js} +2 -2
- package/dist/web/server/assets/members-tWZA9b15.js +36 -0
- package/dist/web/server/assets/memory-BNN0b-0x.js +12 -0
- package/dist/web/server/assets/memory-CTl1E1Rm.js +267 -0
- package/dist/web/server/assets/memory-CV5uCBb2.js +12 -0
- package/dist/web/server/assets/policy-C9M6zV6w.js +79 -0
- package/dist/web/server/assets/policy-h-6NpU3m.js +19 -0
- package/dist/web/server/assets/policy-xEw9X0DK.js +12 -0
- package/dist/web/server/assets/public-origin-BpDkdS5Q.js +34 -0
- package/dist/web/server/assets/results-D3A3UA4d.js +182 -0
- package/dist/web/server/assets/results-D6Ui5S8D.js +12 -0
- package/dist/web/server/assets/results-DWmxvfyn.js +15 -0
- package/dist/web/server/assets/review-CyQky-WQ.js +40 -0
- package/dist/web/server/assets/review-Sq0GGcPV.js +322 -0
- package/dist/web/server/assets/review-XWbSF8cF.js +12 -0
- package/dist/web/server/assets/route-BErtkz6t.js +19 -0
- package/dist/web/server/assets/route-CLoV-An_.js +48 -0
- package/dist/web/server/assets/route-WQ19JkBa.js +19 -0
- package/dist/web/server/assets/route-dEK_2GLj.js +203 -0
- package/dist/web/server/assets/route-iHTkhO81.js +16 -0
- package/dist/web/server/assets/route-zs8uUQtB.js +16 -0
- package/dist/web/server/assets/router-BI9gmY3S.js +751 -0
- package/dist/web/server/assets/routes-081s4n24.js +45 -0
- package/dist/web/server/assets/routes-CWo5WPsr.js +15 -0
- package/dist/web/server/assets/routes-Cqp1ufHm.js +56 -0
- package/dist/web/server/assets/{services-ZeEIgTn0.js → services-BLvAvb8g.js} +1 -1
- package/dist/web/server/assets/{services-UL_2b8PP.js → services-Q9HYQXXB.js} +2 -8
- package/dist/web/server/assets/{services-T8adll3y.js → services-tCfB1B83.js} +21 -38
- package/dist/web/server/assets/settings-CVaGv-xF.js +12 -0
- package/dist/web/server/assets/settings-D9viV-86.js +561 -0
- package/dist/web/server/assets/settings-DaZNZ_CC.js +27 -0
- package/dist/web/server/assets/{skills-D1oy3JAH.js → skills-BZg_txbf.js} +1 -3
- package/dist/web/server/assets/skills-C7fqRPna.js +275 -0
- package/dist/web/server/assets/{skills-kfqhxYmf.js → skills-C_g8IKag.js} +1 -1
- package/dist/web/server/assets/start-DTX6aKCi.js +100 -0
- package/dist/web/server/assets/teams-BHkhnt6b.js +12 -0
- package/dist/web/server/assets/teams-BS-oweRl.js +80 -0
- package/dist/web/server/assets/teams-BSflKBP8.js +108 -0
- package/dist/web/server/assets/teams-CNyB5nM9.js +12 -0
- package/dist/web/server/assets/{teams-BW2ARIvk.js → teams-D4CaU76n.js} +3 -5
- package/dist/web/server/assets/teams-DX2HmKqi.js +21 -0
- package/dist/web/server/assets/{telegram-U9UAdUEx.js → telegram-BUdnc8oF.js} +1 -1
- package/dist/web/server/assets/{telegram-ByHqeAGC.js → telegram-C4v1HhyJ.js} +1 -1
- package/dist/web/server/assets/{telegram-IMfV34-w.js → telegram-CrJiygCX.js} +223 -471
- package/dist/web/server/assets/{tokens-CiThDMwM.js → tokens-B1twAJdd.js} +5 -5
- package/dist/web/server/assets/tokens-DdjEyALj.js +232 -0
- package/dist/web/server/assets/tokens-DqldzPUq.js +14 -0
- package/dist/web/server/assets/triggers-B7LW784F.js +214 -0
- package/dist/web/server/assets/triggers-C5sMCZXv2.js +12 -0
- package/dist/web/server/assets/triggers-DMfVdImD.js +12 -0
- package/dist/web/server/assets/{welcome-BFWKx138.js → welcome-D0d38Pzx.js} +5 -6
- package/dist/web/server/server.js +55 -159
- package/dist/web-server.js +3 -3
- package/dist/worker.js +1692 -6375
- package/dist/worker.js.map +1 -1
- package/package.json +8 -18
- package/dist/browser-keychain.js +0 -83
- package/dist/browser-keychain.js.map +0 -1
- package/dist/cli-main.js +0 -9211
- package/dist/cli-main.js.map +0 -1
- package/dist/daemon-main.js +0 -50664
- package/dist/daemon-main.js.map +0 -1
- package/dist/migrations/0001_init.sql +0 -1103
- package/dist/migrations/0002_device_token_scopes.sql +0 -8
- package/dist/migrations/0003_web_pairing_tokens.sql +0 -18
- package/dist/migrations/0004_image_generation.sql +0 -25
- package/dist/native-darwin-entry.js +0 -692
- package/dist/native-darwin-entry.js.map +0 -1
- package/dist/native-linux-entry.js +0 -60
- package/dist/native-linux-entry.js.map +0 -1
- package/dist/runtime-version.js +0 -28
- package/dist/runtime-version.js.map +0 -1
- package/dist/web/client/assets/AgentTabs-kEd-oDRM.js +0 -1
- package/dist/web/client/assets/ChatPane-DhvlzNPJ.js +0 -76
- package/dist/web/client/assets/ConfigPage-CMKsWDjh.js +0 -1
- package/dist/web/client/assets/ConfirmDialog-DpAzoNG8.js +0 -1
- package/dist/web/client/assets/FieldRow-OQ-Ezw5t.js +0 -1
- package/dist/web/client/assets/ProductionTeamPolicyEditor-DhT-Q13a.js +0 -7
- package/dist/web/client/assets/ProfileCommunicationEditor-CnQIp4e6.js +0 -1
- package/dist/web/client/assets/RecoveryState-B4Rne9N_.js +0 -1
- package/dist/web/client/assets/ResultCard-BxAlMky1.js +0 -1
- package/dist/web/client/assets/ResultSourceConversation-BzIw43-r.js +0 -1
- package/dist/web/client/assets/SectionTabs-D3M6F_HR.js +0 -1
- package/dist/web/client/assets/TeamTabs-BZbg-UFx.js +0 -1
- package/dist/web/client/assets/TemplatesTabs-D8geEOte.js +0 -1
- package/dist/web/client/assets/UnsavedChangesGuard-CPQe9VLw.js +0 -1
- package/dist/web/client/assets/_id-1RIodFdi.js +0 -1
- package/dist/web/client/assets/_id-BV3w2kDj.js +0 -1
- package/dist/web/client/assets/_id-C9zxKqvQ.js +0 -1
- package/dist/web/client/assets/_id-CLG_POnZ.js +0 -1
- package/dist/web/client/assets/_id-Cha845UH.js +0 -1
- package/dist/web/client/assets/_id-DssxcwBl.js +0 -1
- package/dist/web/client/assets/_id-IDHR-MEm.js +0 -1
- package/dist/web/client/assets/_id-SGs5zOcT.js +0 -1
- package/dist/web/client/assets/activity-0srO4qbd.js +0 -1
- package/dist/web/client/assets/activity-DxQGr6eP.js +0 -1
- package/dist/web/client/assets/agents-CVTYoXKu.js +0 -1
- package/dist/web/client/assets/agents-DPTu6Sm_.js +0 -1
- package/dist/web/client/assets/agents-nHiIbumu.js +0 -1
- package/dist/web/client/assets/approvals-Di_Bux_Q.js +0 -1
- package/dist/web/client/assets/approvals-ScNrQg7q.js +0 -1
- package/dist/web/client/assets/attention-BF-Llt9z.js +0 -1
- package/dist/web/client/assets/attention-D7xB17sN.js +0 -1
- package/dist/web/client/assets/chevron-right-CJ2wat15.js +0 -1
- package/dist/web/client/assets/config-BOuIcP1T.js +0 -3
- package/dist/web/client/assets/context-wo9lNjHx.js +0 -1
- package/dist/web/client/assets/git-review-presentation-CzHQulDk.js +0 -1
- package/dist/web/client/assets/inbox-CNLmz0Jp.js +0 -1
- package/dist/web/client/assets/inbox-De6HOll3.js +0 -1
- package/dist/web/client/assets/index-CjI7_vB3.js +0 -52
- package/dist/web/client/assets/jsx-runtime-DGeXAQPT.js +0 -1
- package/dist/web/client/assets/learning-591SFAKg.js +0 -1
- package/dist/web/client/assets/learning-D6bO0NeB.js +0 -1
- package/dist/web/client/assets/login-Q7uP-v0M.js +0 -1
- package/dist/web/client/assets/mcp-BGy64VOv.js +0 -1
- package/dist/web/client/assets/mcp-DSCjhc5I.js +0 -1
- package/dist/web/client/assets/members-CBVor-P4.js +0 -1
- package/dist/web/client/assets/members-CCcecjC3.js +0 -1
- package/dist/web/client/assets/memory-CSE8EQ48.js +0 -1
- package/dist/web/client/assets/memory-DgGz0wh4.js +0 -1
- package/dist/web/client/assets/policy-6j-NQvBj.js +0 -1
- package/dist/web/client/assets/policy-Do0TvNWc.js +0 -1
- package/dist/web/client/assets/preload-helper-bztXdkDj.js +0 -1
- package/dist/web/client/assets/react-3W8R1pOO.js +0 -1
- package/dist/web/client/assets/results-CCQGn0dE.js +0 -1
- package/dist/web/client/assets/results-Cx6_ChIY.js +0 -1
- package/dist/web/client/assets/review-CyS5b0fz.js +0 -1
- package/dist/web/client/assets/review-qG-2gqEp.js +0 -1
- package/dist/web/client/assets/routes-DRic0xNy.js +0 -1
- package/dist/web/client/assets/services-B_7lf-mx.js +0 -1
- package/dist/web/client/assets/services-ByBA_yA-.js +0 -1
- package/dist/web/client/assets/skills--lnDzPWe.js +0 -1
- package/dist/web/client/assets/skills-C70btgIg.js +0 -1
- package/dist/web/client/assets/styles-e_ADuRbs.css +0 -2
- package/dist/web/client/assets/team-policy-D0jpnn2b.js +0 -1
- package/dist/web/client/assets/teams-BL-Fr2xF.js +0 -1
- package/dist/web/client/assets/teams-BeoxArzy.js +0 -1
- package/dist/web/client/assets/teams-C4mb790r.js +0 -1
- package/dist/web/client/assets/teams-DHStw3OS.js +0 -1
- package/dist/web/client/assets/telegram-BIMiebJl.js +0 -1
- package/dist/web/client/assets/templates-CzHXXiA_.js +0 -1
- package/dist/web/client/assets/tokens-B9ehOc1o.js +0 -1
- package/dist/web/client/assets/tokens-DhaMzFWK.js +0 -1
- package/dist/web/client/assets/triggers--xMpHFW7.js +0 -1
- package/dist/web/client/assets/triggers-DLzZu8bB.js +0 -1
- package/dist/web/client/assets/verifications-FzypGVwW.js +0 -2
- package/dist/web/client/assets/verifications-fR9W-adv.js +0 -1
- package/dist/web/client/assets/welcome-pjZD7pq4.js +0 -1
- package/dist/web/client/assets/wire-constants-CBD-lTaa.js +0 -1
- package/dist/web/client/assets/x-CZxV4X-6.js +0 -1
- package/dist/web/server/assets/AgentTabs-DVVkxBks.js +0 -49
- package/dist/web/server/assets/ChatPane-CeDUEjmn.js +0 -2962
- package/dist/web/server/assets/ConfigPage-J3s_PX4o.js +0 -69
- package/dist/web/server/assets/ConfirmDialog-C-2cbcmQ.js +0 -99
- package/dist/web/server/assets/ProductionTeamPolicyEditor-DNtdMn2a.js +0 -1026
- package/dist/web/server/assets/ProfileCommunicationEditor-C2RU-2QB.js +0 -107
- package/dist/web/server/assets/RecoveryState-DFPWxMIo.js +0 -37
- package/dist/web/server/assets/ResultCard-BtVFqdRU.js +0 -162
- package/dist/web/server/assets/ResultSourceConversation-xn4EKjaP.js +0 -64
- package/dist/web/server/assets/SectionTabs-DQWPEk1x.js +0 -8
- package/dist/web/server/assets/Sidebar-Dk9bErQV.js +0 -1243
- package/dist/web/server/assets/TeamTabs-XybMRm3w.js +0 -59
- package/dist/web/server/assets/TemplatesTabs-BiJt7Fjx.js +0 -31
- package/dist/web/server/assets/WorkspaceRecoveryCard-B-6gfg0D.js +0 -18
- package/dist/web/server/assets/_id-6aGxCNlp.js +0 -37
- package/dist/web/server/assets/_id-BJeSZ4DF.js +0 -11
- package/dist/web/server/assets/_id-BSkg6FJC.js +0 -45
- package/dist/web/server/assets/_id-BfT3umhN.js +0 -14
- package/dist/web/server/assets/_id-Bk4SHXs4.js +0 -626
- package/dist/web/server/assets/_id-C0C6wOt8.js +0 -42
- package/dist/web/server/assets/_id-CAxK6pln.js +0 -6
- package/dist/web/server/assets/_id-CGMvV1p5.js +0 -1183
- package/dist/web/server/assets/_id-CI33J2xv.js +0 -11
- package/dist/web/server/assets/_id-C_FnWQ61.js +0 -11
- package/dist/web/server/assets/_id-CmS2d0me.js +0 -17
- package/dist/web/server/assets/_id-D9VWEfdp.js +0 -28
- package/dist/web/server/assets/_id-DhheAcWL.js +0 -1035
- package/dist/web/server/assets/_id-t8AepTB2.js +0 -26
- package/dist/web/server/assets/_id-ujm4R5OF.js +0 -18
- package/dist/web/server/assets/_tanstack-start-manifest_v-CXwNJhX2.js +0 -376
- package/dist/web/server/assets/activity-BKb_BIx7.js +0 -168
- package/dist/web/server/assets/activity-CDNYyLBC.js +0 -11
- package/dist/web/server/assets/activity-DhzxlXUk.js +0 -12
- package/dist/web/server/assets/activity-lf7L7wiL.js +0 -14
- package/dist/web/server/assets/agents-BzJDqrC8.js +0 -11
- package/dist/web/server/assets/agents-C65TunMF.js +0 -505
- package/dist/web/server/assets/agents-uXBu1F5L.js +0 -387
- package/dist/web/server/assets/approvals-CcU_pIWW.js +0 -11
- package/dist/web/server/assets/approvals-CpDs6ASO.js +0 -14
- package/dist/web/server/assets/approvals-FyuTjfdY.js +0 -332
- package/dist/web/server/assets/approvals-szknIxB6.js +0 -12
- package/dist/web/server/assets/attention-BeA3zGve.js +0 -268
- package/dist/web/server/assets/attention-jtJ9PIMp.js +0 -11
- package/dist/web/server/assets/browser-BiDvr0fy.js +0 -66
- package/dist/web/server/assets/context-DuxjdpaW.js +0 -11
- package/dist/web/server/assets/daemon-client-C-RlJHYO.js +0 -301
- package/dist/web/server/assets/git-review-BB3M9nYg.js +0 -26
- package/dist/web/server/assets/git-review-CqZTrIWS.js +0 -179
- package/dist/web/server/assets/git-review-presentation-TJiHJhen.js +0 -81
- package/dist/web/server/assets/inbox-Be3CUU4o.js +0 -11
- package/dist/web/server/assets/inbox-D1ROE7jB.js +0 -44
- package/dist/web/server/assets/inbox-DsH5oRK0.js +0 -168
- package/dist/web/server/assets/inbox-qKMkeprB.js +0 -29
- package/dist/web/server/assets/learning-BYCwIOzZ.js +0 -18
- package/dist/web/server/assets/learning-C3pqLE5b.js +0 -11
- package/dist/web/server/assets/learning-D7jWRhqD.js +0 -365
- package/dist/web/server/assets/mcp-BQ4KvXp1.js +0 -11
- package/dist/web/server/assets/mcp-Dhryb75M.js +0 -328
- package/dist/web/server/assets/members-8aWhtn4G.js +0 -100
- package/dist/web/server/assets/members-Cjpysp35.js +0 -14
- package/dist/web/server/assets/members-DWedYCMh.js +0 -11
- package/dist/web/server/assets/memory-BH7L-l65.js +0 -11
- package/dist/web/server/assets/memory-Bq0s1fr7.js +0 -18
- package/dist/web/server/assets/memory-CS-9Bb6q.js +0 -28
- package/dist/web/server/assets/memory-DN5iMDQL.js +0 -389
- package/dist/web/server/assets/policy-CK3VuVuv.js +0 -11
- package/dist/web/server/assets/policy-DDi8AjcD.js +0 -21
- package/dist/web/server/assets/policy-DcYIJaHW.js +0 -490
- package/dist/web/server/assets/policy-JF7ZI2-i.js +0 -40
- package/dist/web/server/assets/public-origin-xV0lm0Ty.js +0 -25
- package/dist/web/server/assets/publications-DV2uRrvJ.js +0 -57
- package/dist/web/server/assets/results-CkNoVDrY.js +0 -362
- package/dist/web/server/assets/results-DSGwi3vj.js +0 -14
- package/dist/web/server/assets/results-DlOsdBE7.js +0 -11
- package/dist/web/server/assets/results-vtkmZPro.js +0 -12
- package/dist/web/server/assets/review-BG71IaCa.js +0 -1061
- package/dist/web/server/assets/review-Bs6AbrSn.js +0 -40
- package/dist/web/server/assets/review-CPmUi4PR.js +0 -11
- package/dist/web/server/assets/review-packets-CO69K-FK.js +0 -172
- package/dist/web/server/assets/router-BFqyjkYu.js +0 -921
- package/dist/web/server/assets/routes-B6TnJyQ8.js +0 -57
- package/dist/web/server/assets/routes-BfEa101d.js +0 -14
- package/dist/web/server/assets/routes-pUMIGzyy.js +0 -53
- package/dist/web/server/assets/services-Ba6tFlZz.js +0 -16
- package/dist/web/server/assets/skills-CGvPejPD.js +0 -11
- package/dist/web/server/assets/skills-cVlLDnvf.js +0 -399
- package/dist/web/server/assets/start-D4Wq9iTa.js +0 -70
- package/dist/web/server/assets/team-policy-vPG01onj.js +0 -180
- package/dist/web/server/assets/teams-6c5B9wnI.js +0 -11
- package/dist/web/server/assets/teams-BEIUG9fI.js +0 -112
- package/dist/web/server/assets/teams-Bi3CeEM5.js +0 -11
- package/dist/web/server/assets/teams-C9tfV3IC.js +0 -12
- package/dist/web/server/assets/teams-DKROLgw-.js +0 -36
- package/dist/web/server/assets/teams-DLt48Vxw.js +0 -284
- package/dist/web/server/assets/teams-DuhXk1M5.js +0 -14
- package/dist/web/server/assets/templates-CuqFhsiO.js +0 -11
- package/dist/web/server/assets/tokens-DDJYBy6R.js +0 -16
- package/dist/web/server/assets/tokens-qVijmBxr.js +0 -11
- package/dist/web/server/assets/tokens-zSK57Trr.js +0 -452
- package/dist/web/server/assets/triggers-B9CIl4Co.js +0 -27
- package/dist/web/server/assets/triggers-Cr9af7Xw.js +0 -367
- package/dist/web/server/assets/triggers-DIruOyMb.js +0 -18
- package/dist/web/server/assets/triggers-x_OA9u5f.js +0 -11
- package/dist/web/server/assets/utils-ySbqTi3g.js +0 -24
- package/dist/web/server/assets/verification-DBsJYadO.js +0 -97
- package/dist/web/server/assets/verifications-DjZsx65b.js +0 -12
- package/dist/web/server/assets/verifications-DvOyI3Mr.js +0 -28
- package/dist/web/server/assets/verifications-YrEdiZmk.js +0 -326
- package/dist/web/server/assets/web-search-dgw10fLn.js +0 -12
- package/dist/web/server/assets/wire-constants-C8nBJcU3.js +0 -16
- /package/{LICENSE → dist/LICENSE} +0 -0
- /package/dist/web/client/assets/{ProductionTeamPolicyEditor-DLioOiRN.css → TeamPolicyEditor-DLioOiRN.css} +0 -0
|
@@ -0,0 +1,1887 @@
|
|
|
1
|
+
import { i as errorMessage, n as api, o as Button, r as apiFetch, t as ApiError } from "./api-WWxPqx67.js";
|
|
2
|
+
import { t as ResultCard } from "./ResultCard-CZn1w4KA.js";
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import DOMPurify from "dompurify";
|
|
6
|
+
import { marked } from "marked";
|
|
7
|
+
//#region src/components/chat/AgentQuestions.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Questions the Agent is waiting on. The chat reloads them when it opens, when a turn starts or
|
|
10
|
+
* ends and when its stream carries a new question (`refreshKey` changes).
|
|
11
|
+
*/
|
|
12
|
+
function AgentQuestions({ agentId, refreshKey }) {
|
|
13
|
+
const [items, setItems] = useState([]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
api(`/api/agents/${encodeURIComponent(agentId)}/questions`, { signal: controller.signal }).then((body) => setItems(body.questions)).catch(() => {});
|
|
17
|
+
return () => controller.abort();
|
|
18
|
+
}, [agentId, refreshKey]);
|
|
19
|
+
if (!items.length) return null;
|
|
20
|
+
return /* @__PURE__ */ jsx("section", {
|
|
21
|
+
"aria-label": "Agent questions",
|
|
22
|
+
className: "max-h-[40vh] min-w-0 shrink-0 space-y-3 overflow-y-auto border-t border-frost px-5 py-3",
|
|
23
|
+
children: items.map((item) => /* @__PURE__ */ jsx(QuestionCard, { item }, item.id))
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function QuestionCard({ item }) {
|
|
27
|
+
const [choice, setChoice] = useState("");
|
|
28
|
+
const [text, setText] = useState("");
|
|
29
|
+
const [busy, setBusy] = useState(false);
|
|
30
|
+
const [done, setDone] = useState(false);
|
|
31
|
+
const [error, setError] = useState("");
|
|
32
|
+
async function submit(answer) {
|
|
33
|
+
setBusy(true);
|
|
34
|
+
setError("");
|
|
35
|
+
try {
|
|
36
|
+
await api(`/api/agents/${encodeURIComponent(item.agentId)}/questions/${encodeURIComponent(item.id)}/answer`, { body: { answer } });
|
|
37
|
+
setDone(true);
|
|
38
|
+
} catch (cause) {
|
|
39
|
+
setError(cause instanceof ApiError && cause.status === 404 ? "This question is no longer open." : errorMessage(cause));
|
|
40
|
+
} finally {
|
|
41
|
+
setBusy(false);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const disabled = busy || done;
|
|
45
|
+
return /* @__PURE__ */ jsxs("article", {
|
|
46
|
+
className: "flex min-w-0 flex-col gap-3 rounded-lg border border-frost bg-ivory p-3",
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsx("p", {
|
|
49
|
+
className: "m-0 break-words font-medium",
|
|
50
|
+
children: item.question.prompt
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ jsxs("form", {
|
|
53
|
+
className: "flex min-w-0 flex-col gap-3",
|
|
54
|
+
onSubmit: (event) => {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
if (choice === "other") submit({
|
|
57
|
+
kind: "text",
|
|
58
|
+
text
|
|
59
|
+
});
|
|
60
|
+
else if (choice !== "") submit({
|
|
61
|
+
kind: "choice",
|
|
62
|
+
index: Number(choice)
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsxs("fieldset", {
|
|
67
|
+
disabled,
|
|
68
|
+
className: "m-0 grid min-w-0 gap-2 border-0 p-0 sm:grid-cols-2",
|
|
69
|
+
children: [
|
|
70
|
+
/* @__PURE__ */ jsx("legend", {
|
|
71
|
+
className: "sr-only",
|
|
72
|
+
children: "Answer this question"
|
|
73
|
+
}),
|
|
74
|
+
item.question.choices.map((option, index) => /* @__PURE__ */ jsxs("label", {
|
|
75
|
+
className: "m-0 flex min-w-0 cursor-pointer items-center gap-2 rounded-md border border-frost px-3 py-2.5 has-[:checked]:border-sapphire has-[:checked]:bg-sapphire-glow",
|
|
76
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
77
|
+
className: "m-0 h-4 w-4 shrink-0 accent-sapphire",
|
|
78
|
+
type: "radio",
|
|
79
|
+
name: `question-${item.id}`,
|
|
80
|
+
value: index,
|
|
81
|
+
checked: choice === String(index),
|
|
82
|
+
onChange: () => setChoice(String(index))
|
|
83
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
84
|
+
className: "min-w-0 break-words [overflow-wrap:anywhere]",
|
|
85
|
+
children: [
|
|
86
|
+
option.label,
|
|
87
|
+
item.question.recommendedIndex === index ? " (Recommended)" : "",
|
|
88
|
+
option.description && /* @__PURE__ */ jsx("small", {
|
|
89
|
+
className: "block",
|
|
90
|
+
children: option.description
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
})]
|
|
94
|
+
}, option.label)),
|
|
95
|
+
/* @__PURE__ */ jsxs("label", {
|
|
96
|
+
className: "m-0 flex min-w-0 cursor-pointer items-center gap-2 rounded-md border border-frost px-3 py-2.5 has-[:checked]:border-sapphire has-[:checked]:bg-sapphire-glow",
|
|
97
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
98
|
+
className: "m-0 h-4 w-4 shrink-0 accent-sapphire",
|
|
99
|
+
type: "radio",
|
|
100
|
+
name: `question-${item.id}`,
|
|
101
|
+
checked: choice === "other",
|
|
102
|
+
onChange: () => setChoice("other")
|
|
103
|
+
}), /* @__PURE__ */ jsx("span", { children: "Other" })]
|
|
104
|
+
}),
|
|
105
|
+
choice === "other" && /* @__PURE__ */ jsxs("label", {
|
|
106
|
+
className: "m-0 grid gap-2 sm:col-span-2",
|
|
107
|
+
children: ["Your answer", /* @__PURE__ */ jsx("textarea", {
|
|
108
|
+
rows: 2,
|
|
109
|
+
className: "w-full resize-y",
|
|
110
|
+
value: text,
|
|
111
|
+
maxLength: 4096,
|
|
112
|
+
onChange: (event) => setText(event.target.value)
|
|
113
|
+
})]
|
|
114
|
+
})
|
|
115
|
+
]
|
|
116
|
+
}),
|
|
117
|
+
/* @__PURE__ */ jsxs("div", {
|
|
118
|
+
className: "flex flex-wrap gap-2",
|
|
119
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
120
|
+
variant: "primary",
|
|
121
|
+
type: "submit",
|
|
122
|
+
disabled: disabled || !choice || choice === "other" && !text.trim(),
|
|
123
|
+
children: "Send answer"
|
|
124
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
125
|
+
variant: "ghost",
|
|
126
|
+
disabled,
|
|
127
|
+
onClick: () => {
|
|
128
|
+
submit({ kind: "skip" });
|
|
129
|
+
},
|
|
130
|
+
children: "Skip"
|
|
131
|
+
})]
|
|
132
|
+
}),
|
|
133
|
+
/* @__PURE__ */ jsx("p", {
|
|
134
|
+
className: "m-0 text-xs text-mocha",
|
|
135
|
+
children: done ? "Answered." : `Waiting until ${new Date(item.expiresAt).toLocaleTimeString()}. Answering grants no permission.`
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
}),
|
|
139
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
140
|
+
role: "alert",
|
|
141
|
+
children: error
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/components/chat/entries.ts
|
|
148
|
+
/** A browser turn: risky shell commands and agent questions wait for the user in the chat. */
|
|
149
|
+
function interactiveChatRequest(message, attachments) {
|
|
150
|
+
return {
|
|
151
|
+
message,
|
|
152
|
+
attachments,
|
|
153
|
+
bashApprovalMode: "interactive",
|
|
154
|
+
questionMode: "web"
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function shellApprovalsUrl(agentId) {
|
|
158
|
+
return `/api/shell-approvals?agentId=${encodeURIComponent(agentId)}`;
|
|
159
|
+
}
|
|
160
|
+
var isImageMime = (mimeType) => mimeType.startsWith("image/");
|
|
161
|
+
/**
|
|
162
|
+
* Persisted messages as entries: assistant text, then its tool calls and the tool results that
|
|
163
|
+
* answer them grouped into one tool box. Saved results and images are deliverables, so they stand
|
|
164
|
+
* outside the box.
|
|
165
|
+
*/
|
|
166
|
+
function projectMessages(messages) {
|
|
167
|
+
const entries = [];
|
|
168
|
+
let openTool = null;
|
|
169
|
+
const toolBox = () => {
|
|
170
|
+
if (!openTool) {
|
|
171
|
+
openTool = {
|
|
172
|
+
type: "tool",
|
|
173
|
+
items: []
|
|
174
|
+
};
|
|
175
|
+
entries.push(openTool);
|
|
176
|
+
}
|
|
177
|
+
return openTool;
|
|
178
|
+
};
|
|
179
|
+
for (const message of messages) if (message.role === "user") {
|
|
180
|
+
openTool = null;
|
|
181
|
+
entries.push({
|
|
182
|
+
type: "user",
|
|
183
|
+
content: message.content,
|
|
184
|
+
...message.images?.length ? { images: message.images } : {}
|
|
185
|
+
});
|
|
186
|
+
} else if (message.role === "assistant") {
|
|
187
|
+
if (message.content) {
|
|
188
|
+
openTool = null;
|
|
189
|
+
entries.push({
|
|
190
|
+
type: "assistant",
|
|
191
|
+
content: message.content
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
for (const call of message.toolCalls ?? []) toolBox().items.push({
|
|
195
|
+
kind: "call",
|
|
196
|
+
id: call.id,
|
|
197
|
+
name: call.name,
|
|
198
|
+
body: call.arguments
|
|
199
|
+
});
|
|
200
|
+
} else if (message.role === "tool") {
|
|
201
|
+
toolBox().items.push({
|
|
202
|
+
kind: /^error:/i.test(message.content) ? "error" : "result",
|
|
203
|
+
id: message.toolCallId ?? "",
|
|
204
|
+
name: message.toolName ?? "",
|
|
205
|
+
body: message.content
|
|
206
|
+
});
|
|
207
|
+
for (const result of message.results ?? []) {
|
|
208
|
+
entries.push({
|
|
209
|
+
type: "result",
|
|
210
|
+
resultId: result.resultId
|
|
211
|
+
});
|
|
212
|
+
openTool = null;
|
|
213
|
+
}
|
|
214
|
+
if (message.images?.length) {
|
|
215
|
+
entries.push({
|
|
216
|
+
type: "images",
|
|
217
|
+
images: message.images
|
|
218
|
+
});
|
|
219
|
+
openTool = null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return entries;
|
|
223
|
+
}
|
|
224
|
+
/** Keep one card per shell approval, in the position it first appeared. */
|
|
225
|
+
function upsertCommandApprovalEntry(entries, approval) {
|
|
226
|
+
const index = entries.findIndex((entry) => entry.type === "command_approval" && entry.approval.id === approval.id);
|
|
227
|
+
if (index === -1) return [...entries, {
|
|
228
|
+
type: "command_approval",
|
|
229
|
+
approval
|
|
230
|
+
}];
|
|
231
|
+
const next = [...entries];
|
|
232
|
+
next[index] = {
|
|
233
|
+
type: "command_approval",
|
|
234
|
+
approval
|
|
235
|
+
};
|
|
236
|
+
return next;
|
|
237
|
+
}
|
|
238
|
+
/** Insert or replace the live output tail of one running tool call, right after its call line. */
|
|
239
|
+
function upsertToolProgress(entries, event) {
|
|
240
|
+
const progress = {
|
|
241
|
+
kind: "progress",
|
|
242
|
+
id: event.id,
|
|
243
|
+
name: event.name,
|
|
244
|
+
body: event.output
|
|
245
|
+
};
|
|
246
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
247
|
+
const entry = entries[i];
|
|
248
|
+
if (entry?.type !== "tool") continue;
|
|
249
|
+
const call = entry.items.findIndex((item) => item.id === event.id);
|
|
250
|
+
if (call < 0) continue;
|
|
251
|
+
const items = [...entry.items];
|
|
252
|
+
const existing = items.findIndex((item) => item.kind === "progress" && item.id === event.id);
|
|
253
|
+
if (existing >= 0) items[existing] = progress;
|
|
254
|
+
else items.splice(call + 1, 0, progress);
|
|
255
|
+
const next = [...entries];
|
|
256
|
+
next[i] = {
|
|
257
|
+
type: "tool",
|
|
258
|
+
items
|
|
259
|
+
};
|
|
260
|
+
return next;
|
|
261
|
+
}
|
|
262
|
+
return appendToolItem(entries, progress);
|
|
263
|
+
}
|
|
264
|
+
function appendToolItem(entries, item) {
|
|
265
|
+
const last = entries[entries.length - 1];
|
|
266
|
+
if (last?.type === "tool") return [...entries.slice(0, -1), {
|
|
267
|
+
type: "tool",
|
|
268
|
+
items: [...last.items, item]
|
|
269
|
+
}];
|
|
270
|
+
return [...entries, {
|
|
271
|
+
type: "tool",
|
|
272
|
+
items: [item]
|
|
273
|
+
}];
|
|
274
|
+
}
|
|
275
|
+
function setAssistantText(entries, text) {
|
|
276
|
+
const last = entries[entries.length - 1];
|
|
277
|
+
if (last?.type === "assistant") return [...entries.slice(0, -1), {
|
|
278
|
+
type: "assistant",
|
|
279
|
+
content: text(last.content)
|
|
280
|
+
}];
|
|
281
|
+
return [...entries, {
|
|
282
|
+
type: "assistant",
|
|
283
|
+
content: text("")
|
|
284
|
+
}];
|
|
285
|
+
}
|
|
286
|
+
/** Fold one live event into the turn's entries. Events without a visible entry change nothing. */
|
|
287
|
+
function applyEvent(entries, event) {
|
|
288
|
+
switch (event.type) {
|
|
289
|
+
case "assistant_delta": return setAssistantText(entries, (previous) => previous + event.delta);
|
|
290
|
+
case "assistant_message": return setAssistantText(entries, () => event.text);
|
|
291
|
+
case "command_approval": return upsertCommandApprovalEntry(entries, event.approval);
|
|
292
|
+
case "tool_progress": return upsertToolProgress(entries, event);
|
|
293
|
+
case "tool_call": return appendToolItem(entries, {
|
|
294
|
+
kind: "call",
|
|
295
|
+
id: event.id,
|
|
296
|
+
name: event.name,
|
|
297
|
+
body: event.arguments
|
|
298
|
+
});
|
|
299
|
+
case "tool_result":
|
|
300
|
+
case "tool_error": {
|
|
301
|
+
const next = appendToolItem(entries.map((entry) => entry.type === "tool" ? {
|
|
302
|
+
...entry,
|
|
303
|
+
items: entry.items.filter((i) => !(i.kind === "progress" && i.id === event.id))
|
|
304
|
+
} : entry), event.type === "tool_result" ? {
|
|
305
|
+
kind: "result",
|
|
306
|
+
id: event.id,
|
|
307
|
+
name: event.name,
|
|
308
|
+
body: event.result
|
|
309
|
+
} : {
|
|
310
|
+
kind: "error",
|
|
311
|
+
id: event.id,
|
|
312
|
+
name: event.name,
|
|
313
|
+
body: event.error
|
|
314
|
+
});
|
|
315
|
+
return event.type === "tool_result" && event.images?.length ? [...next, {
|
|
316
|
+
type: "images",
|
|
317
|
+
images: event.images
|
|
318
|
+
}] : next;
|
|
319
|
+
}
|
|
320
|
+
case "file": return [...entries, {
|
|
321
|
+
type: "result",
|
|
322
|
+
resultId: event.result.resultId
|
|
323
|
+
}];
|
|
324
|
+
case "error": return [...entries, {
|
|
325
|
+
type: "error",
|
|
326
|
+
content: `[error] ${event.error}`
|
|
327
|
+
}];
|
|
328
|
+
default: return entries;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/** Pending shell approvals become terminal when the turn dies. */
|
|
332
|
+
function cancelPendingApprovals(entries) {
|
|
333
|
+
return entries.map((entry) => entry.type === "command_approval" && entry.approval.status === "pending" ? {
|
|
334
|
+
type: "command_approval",
|
|
335
|
+
approval: {
|
|
336
|
+
...entry.approval,
|
|
337
|
+
status: "cancelled"
|
|
338
|
+
}
|
|
339
|
+
} : entry);
|
|
340
|
+
}
|
|
341
|
+
/** Parse an NDJSON response body into frames; malformed lines are skipped. */
|
|
342
|
+
async function* readFrames(body) {
|
|
343
|
+
const reader = body.getReader();
|
|
344
|
+
const decoder = new TextDecoder();
|
|
345
|
+
let buffer = "";
|
|
346
|
+
for (;;) {
|
|
347
|
+
const { done, value } = await reader.read();
|
|
348
|
+
buffer += done ? decoder.decode() : decoder.decode(value, { stream: true });
|
|
349
|
+
const lines = buffer.split("\n");
|
|
350
|
+
buffer = done ? "" : lines.pop() ?? "";
|
|
351
|
+
for (const line of lines) {
|
|
352
|
+
if (!line.trim()) continue;
|
|
353
|
+
try {
|
|
354
|
+
yield JSON.parse(line);
|
|
355
|
+
} catch {}
|
|
356
|
+
}
|
|
357
|
+
if (done) return;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/components/chat/Composer.tsx
|
|
362
|
+
var MAX_INPUT_HEIGHT = 200;
|
|
363
|
+
/** A file as a base64 attachment; the daemon sends images to the model and stores the rest. */
|
|
364
|
+
function fileToAttachment(file) {
|
|
365
|
+
return new Promise((resolve, reject) => {
|
|
366
|
+
const reader = new FileReader();
|
|
367
|
+
reader.onload = () => {
|
|
368
|
+
const url = String(reader.result);
|
|
369
|
+
resolve({
|
|
370
|
+
name: file.name,
|
|
371
|
+
data: url.slice(url.indexOf(",") + 1),
|
|
372
|
+
mimeType: file.type || "application/octet-stream"
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
reader.onerror = () => reject(reader.error);
|
|
376
|
+
reader.readAsDataURL(file);
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function encodeFiles(files) {
|
|
380
|
+
return Promise.all(Array.from(files).map(fileToAttachment));
|
|
381
|
+
}
|
|
382
|
+
/** The message box: text, attachments, the edit banner, Send and Stop. */
|
|
383
|
+
function Composer({ agentName, value, onChange, onSubmit, attachments, onAddFiles, onRemoveAttachment, editing, onCancelEdit, agentBusy, onStop, inputRef }) {
|
|
384
|
+
const fileInput = useRef(null);
|
|
385
|
+
useLayoutEffect(() => {
|
|
386
|
+
const element = inputRef.current;
|
|
387
|
+
if (!element) return;
|
|
388
|
+
element.style.height = "auto";
|
|
389
|
+
element.style.height = `${Math.min(element.scrollHeight, MAX_INPUT_HEIGHT)}px`;
|
|
390
|
+
}, [value]);
|
|
391
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
392
|
+
editing && /* @__PURE__ */ jsxs("div", {
|
|
393
|
+
className: "flex items-center gap-2 border-t border-frost bg-sapphire-glow px-5 py-2 text-[0.85em] text-sapphire-deep",
|
|
394
|
+
children: [/* @__PURE__ */ jsx("span", { children: "editing last message — submit to replace, or" }), /* @__PURE__ */ jsx("button", {
|
|
395
|
+
type: "button",
|
|
396
|
+
onClick: onCancelEdit,
|
|
397
|
+
className: "ml-auto rounded-sm border border-sapphire-light bg-transparent px-2 py-0.5 text-[0.92em] text-sapphire-deep hover:bg-snow",
|
|
398
|
+
children: "cancel"
|
|
399
|
+
})]
|
|
400
|
+
}),
|
|
401
|
+
attachments.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
402
|
+
className: "flex max-h-24 shrink-0 flex-wrap gap-2 overflow-y-auto border-t border-frost bg-ivory px-5 pt-3",
|
|
403
|
+
children: attachments.map((attachment, index) => isImageMime(attachment.mimeType) ? /* @__PURE__ */ jsxs("div", {
|
|
404
|
+
className: "relative",
|
|
405
|
+
children: [/* @__PURE__ */ jsx("img", {
|
|
406
|
+
src: `data:${attachment.mimeType};base64,${attachment.data}`,
|
|
407
|
+
alt: "pending attachment",
|
|
408
|
+
className: "h-16 w-16 rounded-md border border-frost object-cover"
|
|
409
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
410
|
+
type: "button",
|
|
411
|
+
onClick: () => onRemoveAttachment(index),
|
|
412
|
+
className: "absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full border border-frost bg-snow text-[0.7em] text-mocha hover:border-sapphire hover:text-sapphire",
|
|
413
|
+
"aria-label": "remove attachment",
|
|
414
|
+
children: "✕"
|
|
415
|
+
})]
|
|
416
|
+
}, index) : /* @__PURE__ */ jsxs("div", {
|
|
417
|
+
className: "flex items-center gap-1.5 rounded-md border border-frost bg-snow px-2 py-1 text-[0.82em] text-mocha",
|
|
418
|
+
children: [
|
|
419
|
+
/* @__PURE__ */ jsx("span", { children: "📄" }),
|
|
420
|
+
/* @__PURE__ */ jsx("span", {
|
|
421
|
+
className: "max-w-[160px] truncate",
|
|
422
|
+
children: attachment.name ?? "file"
|
|
423
|
+
}),
|
|
424
|
+
/* @__PURE__ */ jsx("button", {
|
|
425
|
+
type: "button",
|
|
426
|
+
onClick: () => onRemoveAttachment(index),
|
|
427
|
+
className: "text-[0.85em] text-mocha hover:text-sapphire",
|
|
428
|
+
"aria-label": "remove attachment",
|
|
429
|
+
children: "✕"
|
|
430
|
+
})
|
|
431
|
+
]
|
|
432
|
+
}, index))
|
|
433
|
+
}),
|
|
434
|
+
/* @__PURE__ */ jsxs("form", {
|
|
435
|
+
className: "grid shrink-0 grid-cols-[auto_minmax(0,1fr)] items-end gap-2 border-t border-frost bg-ivory px-3 py-3 sm:grid-cols-[auto_minmax(0,1fr)_auto] sm:px-5",
|
|
436
|
+
onSubmit: (event) => {
|
|
437
|
+
event.preventDefault();
|
|
438
|
+
onSubmit();
|
|
439
|
+
},
|
|
440
|
+
children: [
|
|
441
|
+
/* @__PURE__ */ jsx("input", {
|
|
442
|
+
ref: fileInput,
|
|
443
|
+
type: "file",
|
|
444
|
+
multiple: true,
|
|
445
|
+
className: "hidden",
|
|
446
|
+
onChange: (event) => {
|
|
447
|
+
if (event.target.files) onAddFiles(event.target.files);
|
|
448
|
+
event.target.value = "";
|
|
449
|
+
}
|
|
450
|
+
}),
|
|
451
|
+
/* @__PURE__ */ jsx("button", {
|
|
452
|
+
type: "button",
|
|
453
|
+
onClick: () => fileInput.current?.click(),
|
|
454
|
+
title: "attach images or files",
|
|
455
|
+
"aria-label": "attach files",
|
|
456
|
+
className: "flex h-11 items-center justify-center rounded-md border-[1.5px] border-frost bg-snow px-3 py-2 text-[1em] text-mocha transition-colors hover:border-sapphire hover:text-sapphire",
|
|
457
|
+
children: "📎"
|
|
458
|
+
}),
|
|
459
|
+
/* @__PURE__ */ jsx("textarea", {
|
|
460
|
+
ref: inputRef,
|
|
461
|
+
rows: 1,
|
|
462
|
+
value,
|
|
463
|
+
onChange: (event) => onChange(event.target.value),
|
|
464
|
+
onKeyDown: (event) => {
|
|
465
|
+
if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
|
|
466
|
+
event.preventDefault();
|
|
467
|
+
onSubmit();
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
onPaste: (event) => {
|
|
471
|
+
const files = Array.from(event.clipboardData.files);
|
|
472
|
+
if (files.some((file) => isImageMime(file.type))) {
|
|
473
|
+
event.preventDefault();
|
|
474
|
+
onAddFiles(files);
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
placeholder: "Write a message…",
|
|
478
|
+
title: "Shift+Enter for a new line. Paste or attach files with the paperclip.",
|
|
479
|
+
autoComplete: "off",
|
|
480
|
+
"aria-label": `Message ${agentName}`,
|
|
481
|
+
className: "max-h-[200px] min-h-11 min-w-0 flex-1 resize-none overflow-y-auto rounded-md border-[1.5px] border-frost bg-snow px-3 py-2 text-[0.93em] leading-[1.45] text-chocolate outline-none transition-colors focus:border-sapphire focus:shadow-[0_0_0_3px_var(--color-sapphire-glow)]"
|
|
482
|
+
}),
|
|
483
|
+
/* @__PURE__ */ jsxs("div", {
|
|
484
|
+
className: "col-span-2 flex flex-wrap justify-end gap-2 sm:col-span-1",
|
|
485
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
486
|
+
variant: "primary",
|
|
487
|
+
type: "submit",
|
|
488
|
+
className: "min-h-11 whitespace-normal text-center",
|
|
489
|
+
disabled: !value.trim() && attachments.length === 0,
|
|
490
|
+
children: agentBusy ? "Queue follow-up" : "Send"
|
|
491
|
+
}), agentBusy && /* @__PURE__ */ jsx(Button, {
|
|
492
|
+
variant: "danger",
|
|
493
|
+
className: "min-h-11",
|
|
494
|
+
onClick: onStop,
|
|
495
|
+
"aria-label": "Stop response",
|
|
496
|
+
children: "Stop"
|
|
497
|
+
})]
|
|
498
|
+
})
|
|
499
|
+
]
|
|
500
|
+
})
|
|
501
|
+
] });
|
|
502
|
+
}
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/lib/inbox-presentation.ts
|
|
505
|
+
function inboxUpdateLabel(body) {
|
|
506
|
+
const header = body.split("\n").find((line) => line.startsWith("--- from "));
|
|
507
|
+
if (!header) return "Teammate update received";
|
|
508
|
+
const match = /^--- from (.+?) \(message [0-9a-f-]+(?:, reply to [0-9a-f-]+)?\) ---$/.exec(header);
|
|
509
|
+
if (!match) return "Teammate update received";
|
|
510
|
+
const name = match[1]?.replace(/ \([0-9a-f-]{36}\)$/, "").trim();
|
|
511
|
+
if (!name || /^[0-9a-f-]{36}$/.test(name)) return "Teammate update received";
|
|
512
|
+
return `Update from ${name.slice(0, 100)}`;
|
|
513
|
+
}
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region src/lib/md.ts
|
|
516
|
+
var installed = false;
|
|
517
|
+
function install() {
|
|
518
|
+
if (installed) return;
|
|
519
|
+
marked.setOptions({
|
|
520
|
+
breaks: true,
|
|
521
|
+
gfm: true
|
|
522
|
+
});
|
|
523
|
+
DOMPurify.addHook("afterSanitizeAttributes", (node) => {
|
|
524
|
+
if (node.nodeName === "A") {
|
|
525
|
+
node.setAttribute("target", "_blank");
|
|
526
|
+
node.setAttribute("rel", "noopener noreferrer");
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
installed = true;
|
|
530
|
+
}
|
|
531
|
+
function renderMd(text, domReady) {
|
|
532
|
+
if (!text) return "";
|
|
533
|
+
if (!domReady || typeof window === "undefined") return escapeHtml(text);
|
|
534
|
+
try {
|
|
535
|
+
install();
|
|
536
|
+
const html = marked.parse(text, { async: false });
|
|
537
|
+
return DOMPurify.sanitize(html);
|
|
538
|
+
} catch {
|
|
539
|
+
return escapeHtml(text);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function escapeHtml(s) {
|
|
543
|
+
return String(s).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
544
|
+
}
|
|
545
|
+
//#endregion
|
|
546
|
+
//#region src/components/chat/CommandApprovalCard.tsx
|
|
547
|
+
var OUTCOME = {
|
|
548
|
+
pending: "Waiting for a decision.",
|
|
549
|
+
allowed: "Allowed once — the command may run for this tool call only.",
|
|
550
|
+
denied: "Denied — the command was not run.",
|
|
551
|
+
auto_denied: "Automatically denied — no interactive approval path was available.",
|
|
552
|
+
expired: "Expired — the command was not run.",
|
|
553
|
+
cancelled: "Cancelled — the command was not run."
|
|
554
|
+
};
|
|
555
|
+
/** A risky shell command waiting for the user; Allow and Deny apply to this one call only. */
|
|
556
|
+
function CommandApprovalCard({ approval, busy = false, error, onDecision }) {
|
|
557
|
+
const pending = approval.status === "pending";
|
|
558
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
559
|
+
className: "my-3 rounded-lg border border-danger/50 bg-danger/5 p-4 text-chocolate",
|
|
560
|
+
"aria-label": "Shell command approval",
|
|
561
|
+
children: [
|
|
562
|
+
/* @__PURE__ */ jsxs("div", {
|
|
563
|
+
className: "flex flex-wrap items-start justify-between gap-2",
|
|
564
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
|
|
565
|
+
className: "m-0 text-[0.72em] font-semibold uppercase tracking-wider text-danger",
|
|
566
|
+
children: "Shell command approval"
|
|
567
|
+
}), /* @__PURE__ */ jsx("h2", {
|
|
568
|
+
className: "m-0 mt-1 font-body text-[0.95em] font-semibold",
|
|
569
|
+
children: pending ? "A risky command is waiting for you" : "Command decision recorded"
|
|
570
|
+
})] }), /* @__PURE__ */ jsx("span", {
|
|
571
|
+
className: "rounded-full border border-danger/30 px-2 py-0.5 text-[0.75em] font-semibold uppercase tracking-wide text-danger",
|
|
572
|
+
children: approval.status.replaceAll("_", " ")
|
|
573
|
+
})]
|
|
574
|
+
}),
|
|
575
|
+
/* @__PURE__ */ jsx("pre", {
|
|
576
|
+
className: "mt-3 max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md border border-fawn bg-snow p-3 font-mono text-[0.82em] leading-[1.45] text-charcoal",
|
|
577
|
+
children: approval.command
|
|
578
|
+
}),
|
|
579
|
+
/* @__PURE__ */ jsx("ul", {
|
|
580
|
+
className: "mt-3 space-y-1.5 pl-5 text-[0.84em] leading-[1.4] text-mocha",
|
|
581
|
+
children: approval.risks.map((risk) => /* @__PURE__ */ jsxs("li", { children: [
|
|
582
|
+
/* @__PURE__ */ jsx("span", {
|
|
583
|
+
className: "font-medium text-chocolate",
|
|
584
|
+
children: risk.message
|
|
585
|
+
}),
|
|
586
|
+
" ",
|
|
587
|
+
/* @__PURE__ */ jsx("code", {
|
|
588
|
+
className: "text-[0.9em]",
|
|
589
|
+
children: risk.code
|
|
590
|
+
})
|
|
591
|
+
] }, `${risk.code}:${risk.span.start}:${risk.span.end}`))
|
|
592
|
+
}),
|
|
593
|
+
pending ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
594
|
+
/* @__PURE__ */ jsxs("p", {
|
|
595
|
+
className: "mt-3 text-[0.78em] text-mocha-light",
|
|
596
|
+
children: [
|
|
597
|
+
"This approval expires",
|
|
598
|
+
" ",
|
|
599
|
+
/* @__PURE__ */ jsx("time", {
|
|
600
|
+
dateTime: new Date(approval.expiresAt).toISOString(),
|
|
601
|
+
children: new Date(approval.expiresAt).toLocaleString()
|
|
602
|
+
}),
|
|
603
|
+
". Deny blocks only this command; Stop ends the whole turn."
|
|
604
|
+
]
|
|
605
|
+
}),
|
|
606
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
607
|
+
role: "alert",
|
|
608
|
+
className: "mt-2 rounded-md bg-danger/10 px-3 py-2 text-[0.82em] text-danger",
|
|
609
|
+
children: error
|
|
610
|
+
}),
|
|
611
|
+
onDecision && /* @__PURE__ */ jsxs("div", {
|
|
612
|
+
className: "mt-3 flex flex-wrap gap-2",
|
|
613
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
614
|
+
variant: "primary",
|
|
615
|
+
disabled: busy,
|
|
616
|
+
onClick: () => onDecision(approval, "deny"),
|
|
617
|
+
children: "Deny"
|
|
618
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
619
|
+
variant: "danger",
|
|
620
|
+
disabled: busy,
|
|
621
|
+
onClick: () => onDecision(approval, "allow"),
|
|
622
|
+
children: "Allow once"
|
|
623
|
+
})]
|
|
624
|
+
})
|
|
625
|
+
] }) : /* @__PURE__ */ jsx("p", {
|
|
626
|
+
role: "status",
|
|
627
|
+
className: "mt-3 text-[0.84em] font-medium text-mocha",
|
|
628
|
+
children: OUTCOME[approval.status]
|
|
629
|
+
})
|
|
630
|
+
]
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region src/components/chat/Transcript.tsx
|
|
635
|
+
var INBOX_WAKE_PREFIX = "[[bazilion:inbox-wake]]\n";
|
|
636
|
+
var COMPACTION_REPLAY_PREFIX = "[conversation summary]";
|
|
637
|
+
var TOOL_GROUP_MAX_HEIGHT_PX = 320;
|
|
638
|
+
var noSubscription = () => () => {};
|
|
639
|
+
/**
|
|
640
|
+
* False during SSR and the hydration pass, true afterwards. Markdown renders as escaped text until
|
|
641
|
+
* then, so the server HTML and the first client render match byte for byte.
|
|
642
|
+
*/
|
|
643
|
+
function useMarkdownReady() {
|
|
644
|
+
return useSyncExternalStore(noSubscription, () => true, () => false);
|
|
645
|
+
}
|
|
646
|
+
function Bubble({ entry, markdownReady, onEdit, dropped = false, approvals }) {
|
|
647
|
+
const dropClass = dropped ? "opacity-40 [&_.bubble-content]:line-through" : "";
|
|
648
|
+
switch (entry.type) {
|
|
649
|
+
case "user":
|
|
650
|
+
if (entry.content.startsWith(INBOX_WAKE_PREFIX)) {
|
|
651
|
+
const body = entry.content.slice(24);
|
|
652
|
+
return /* @__PURE__ */ jsxs("details", {
|
|
653
|
+
className: `my-3 rounded-lg border border-fawn bg-ivory px-3 py-2 text-sm text-mocha ${dropClass}`,
|
|
654
|
+
"aria-label": "Teammate update",
|
|
655
|
+
children: [
|
|
656
|
+
/* @__PURE__ */ jsx("summary", {
|
|
657
|
+
className: "cursor-pointer font-medium",
|
|
658
|
+
children: inboxUpdateLabel(body)
|
|
659
|
+
}),
|
|
660
|
+
/* @__PURE__ */ jsx("p", {
|
|
661
|
+
className: "mt-2 text-xs",
|
|
662
|
+
children: "Original message and Agent instructions"
|
|
663
|
+
}),
|
|
664
|
+
/* @__PURE__ */ jsx("pre", {
|
|
665
|
+
className: "mt-1 max-h-64 overflow-auto whitespace-pre-wrap break-words text-xs",
|
|
666
|
+
children: body
|
|
667
|
+
})
|
|
668
|
+
]
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
672
|
+
className: `group relative my-4 flex flex-col items-end ${dropClass}`,
|
|
673
|
+
children: [
|
|
674
|
+
/* @__PURE__ */ jsx("span", {
|
|
675
|
+
className: "sr-only",
|
|
676
|
+
children: "you"
|
|
677
|
+
}),
|
|
678
|
+
entry.images && entry.images.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
679
|
+
className: "mb-1 flex max-w-[85%] flex-wrap justify-end gap-1",
|
|
680
|
+
children: entry.images.map((image, index) => /* @__PURE__ */ jsx("img", {
|
|
681
|
+
src: `data:${image.mimeType};base64,${image.data}`,
|
|
682
|
+
alt: "attachment",
|
|
683
|
+
className: "max-h-48 rounded-lg border border-sapphire-light"
|
|
684
|
+
}, index))
|
|
685
|
+
}),
|
|
686
|
+
entry.files && entry.files.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
687
|
+
className: "mb-1 flex max-w-[85%] flex-wrap justify-end gap-1",
|
|
688
|
+
children: entry.files.map((file, index) => /* @__PURE__ */ jsxs("span", {
|
|
689
|
+
className: "flex items-center gap-1 rounded-md border border-sapphire-light bg-sapphire-glow px-2 py-1 text-[0.8em] text-chocolate",
|
|
690
|
+
children: ["📄 ", /* @__PURE__ */ jsx("span", {
|
|
691
|
+
className: "max-w-[180px] truncate",
|
|
692
|
+
children: file.name
|
|
693
|
+
})]
|
|
694
|
+
}, index))
|
|
695
|
+
}),
|
|
696
|
+
entry.content && /* @__PURE__ */ jsx("div", {
|
|
697
|
+
className: "bubble-content max-w-[85%] whitespace-pre-wrap break-words rounded-[14px_14px_4px_14px] border border-sapphire-light bg-sapphire-glow px-3 py-2 text-chocolate",
|
|
698
|
+
children: entry.content
|
|
699
|
+
}),
|
|
700
|
+
onEdit && /* @__PURE__ */ jsx("button", {
|
|
701
|
+
type: "button",
|
|
702
|
+
onClick: onEdit,
|
|
703
|
+
title: "Edit and resend: replaces the last turn",
|
|
704
|
+
className: "absolute left-1 top-1 rounded-sm border border-fawn bg-ivory px-2 py-0.5 text-[0.78em] font-medium text-mocha opacity-65 transition hover:border-sapphire hover:bg-sapphire-glow hover:text-sapphire hover:opacity-100 group-hover:opacity-100 group-focus-within:opacity-100",
|
|
705
|
+
children: "edit"
|
|
706
|
+
})
|
|
707
|
+
]
|
|
708
|
+
});
|
|
709
|
+
case "assistant":
|
|
710
|
+
if (entry.content.startsWith(COMPACTION_REPLAY_PREFIX)) {
|
|
711
|
+
const summary = entry.content.slice(22).trim();
|
|
712
|
+
return /* @__PURE__ */ jsx("div", {
|
|
713
|
+
className: `my-3 border-y border-dashed border-frost py-2 text-[0.85em] italic text-mocha-light ${dropClass}`,
|
|
714
|
+
children: /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", {
|
|
715
|
+
className: "cursor-pointer select-none text-center [&::-webkit-details-marker]:hidden",
|
|
716
|
+
children: "— conversation summary (click to expand) —"
|
|
717
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
718
|
+
className: "md-content mt-2 rounded-sm bg-frost/40 p-2 not-italic",
|
|
719
|
+
dangerouslySetInnerHTML: { __html: renderMd(summary, markdownReady) }
|
|
720
|
+
})] })
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
724
|
+
className: `my-4 flex flex-col items-start ${dropClass}`,
|
|
725
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
726
|
+
className: "sr-only",
|
|
727
|
+
children: "agent"
|
|
728
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
729
|
+
className: "md-content bubble-content w-full leading-[1.55] text-chocolate",
|
|
730
|
+
dangerouslySetInnerHTML: { __html: renderMd(entry.content, markdownReady) }
|
|
731
|
+
})]
|
|
732
|
+
});
|
|
733
|
+
case "tool": return /* @__PURE__ */ jsx(ToolGroup, {
|
|
734
|
+
items: entry.items,
|
|
735
|
+
className: dropClass
|
|
736
|
+
});
|
|
737
|
+
case "images": return /* @__PURE__ */ jsx("div", {
|
|
738
|
+
className: `my-2 space-y-2 ${dropClass}`,
|
|
739
|
+
children: entry.images.map((image, index) => /* @__PURE__ */ jsx("img", {
|
|
740
|
+
src: `data:${image.mimeType};base64,${image.data}`,
|
|
741
|
+
alt: "screenshot",
|
|
742
|
+
className: "block max-w-full rounded-lg border border-fawn"
|
|
743
|
+
}, index))
|
|
744
|
+
});
|
|
745
|
+
case "result": return /* @__PURE__ */ jsx(ResultCard, { resultId: entry.resultId });
|
|
746
|
+
case "command_approval": return /* @__PURE__ */ jsx(CommandApprovalCard, {
|
|
747
|
+
approval: entry.approval,
|
|
748
|
+
busy: approvals?.busy[entry.approval.id] ?? false,
|
|
749
|
+
error: approvals?.errors[entry.approval.id],
|
|
750
|
+
onDecision: approvals?.decide
|
|
751
|
+
});
|
|
752
|
+
case "system": return /* @__PURE__ */ jsxs("div", {
|
|
753
|
+
className: "my-3 rounded-r-sm border-l-[3px] border-sapphire bg-sapphire-glow px-3 py-1 font-mono text-[0.88em] text-sapphire-deep",
|
|
754
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
755
|
+
className: "mr-2 font-semibold uppercase tracking-wider opacity-80",
|
|
756
|
+
children: "system"
|
|
757
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
758
|
+
className: "whitespace-pre-wrap",
|
|
759
|
+
children: entry.content
|
|
760
|
+
})]
|
|
761
|
+
});
|
|
762
|
+
case "error": return /* @__PURE__ */ jsx("div", {
|
|
763
|
+
className: "my-3 rounded-r-sm border-l-[3px] border-danger bg-danger/10 px-3 py-1 text-[0.92em] text-danger",
|
|
764
|
+
children: entry.content
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
function prettyArgs(raw) {
|
|
769
|
+
if (!raw) return "";
|
|
770
|
+
try {
|
|
771
|
+
return JSON.stringify(JSON.parse(raw), null, 2);
|
|
772
|
+
} catch {
|
|
773
|
+
return raw;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function ToolGroup({ items, className }) {
|
|
777
|
+
const visible = items.filter((item) => !(item.kind === "call" && item.name === "send_message" && items.some((other) => other.id === item.id && other.kind !== "call")));
|
|
778
|
+
const live = items.some((item) => item.kind === "progress");
|
|
779
|
+
const [expanded, setExpanded] = useState(false);
|
|
780
|
+
const [overflows, setOverflows] = useState(false);
|
|
781
|
+
const contentRef = useRef(null);
|
|
782
|
+
useLayoutEffect(() => {
|
|
783
|
+
const element = contentRef.current;
|
|
784
|
+
if (element) setOverflows(element.scrollHeight > 324);
|
|
785
|
+
}, [items.map((item) => `${item.kind}:${item.body.length}`).join()]);
|
|
786
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
787
|
+
className: `my-1.5 rounded-r-sm border-l-[3px] border-fawn bg-ivory px-3 py-2 font-mono text-[0.82em] leading-[1.5] text-mocha-light ${className}`,
|
|
788
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
789
|
+
ref: contentRef,
|
|
790
|
+
className: "relative overflow-hidden",
|
|
791
|
+
style: { maxHeight: expanded || live ? "none" : `${TOOL_GROUP_MAX_HEIGHT_PX}px` },
|
|
792
|
+
children: [visible.map((item, index) => /* @__PURE__ */ jsx(ToolLine, { item }, index)), overflows && !expanded && !live && /* @__PURE__ */ jsx("div", {
|
|
793
|
+
className: "pointer-events-none absolute inset-x-0 bottom-0 h-10",
|
|
794
|
+
style: { background: "linear-gradient(to bottom, transparent, var(--color-ivory))" }
|
|
795
|
+
})]
|
|
796
|
+
}), overflows && !live && /* @__PURE__ */ jsx("button", {
|
|
797
|
+
type: "button",
|
|
798
|
+
onClick: () => setExpanded((value) => !value),
|
|
799
|
+
className: "mt-2 rounded-sm border border-fawn bg-transparent px-2 py-0.5 text-[0.9em] text-mocha hover:border-sapphire hover:text-sapphire-deep",
|
|
800
|
+
children: expanded ? "show less ↑" : "show more ↓"
|
|
801
|
+
})]
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
function ToolLine({ item }) {
|
|
805
|
+
if (item.name === "send_message" && item.kind !== "error") return /* @__PURE__ */ jsxs("details", {
|
|
806
|
+
className: "py-1 font-sans text-sm",
|
|
807
|
+
children: [/* @__PURE__ */ jsx("summary", {
|
|
808
|
+
className: "cursor-pointer",
|
|
809
|
+
children: item.kind === "call" ? "Sending teammate message…" : item.body.startsWith("sent message ") ? "Teammate message sent" : "Teammate message status"
|
|
810
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
811
|
+
className: "mt-1 max-h-64 overflow-auto whitespace-pre-wrap break-words text-xs",
|
|
812
|
+
children: item.body
|
|
813
|
+
})]
|
|
814
|
+
});
|
|
815
|
+
if (item.kind === "progress") return /* @__PURE__ */ jsx(LiveToolOutput, { output: item.body });
|
|
816
|
+
if (item.kind === "call") {
|
|
817
|
+
const args = prettyArgs(item.body);
|
|
818
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
819
|
+
className: "whitespace-pre-wrap break-words py-0.5",
|
|
820
|
+
children: [
|
|
821
|
+
/* @__PURE__ */ jsx("span", {
|
|
822
|
+
className: "mr-1 opacity-45",
|
|
823
|
+
children: "→"
|
|
824
|
+
}),
|
|
825
|
+
/* @__PURE__ */ jsx("span", {
|
|
826
|
+
className: "font-medium text-mocha",
|
|
827
|
+
children: item.name
|
|
828
|
+
}),
|
|
829
|
+
args.includes("\n") ? /* @__PURE__ */ jsx("pre", {
|
|
830
|
+
className: "ml-4 mt-0.5 rounded-sm bg-[rgba(42,31,22,0.04)] px-2 py-1 font-mono text-[0.95em] leading-[1.4] text-mocha",
|
|
831
|
+
children: args
|
|
832
|
+
}) : args ? /* @__PURE__ */ jsxs("span", { children: [
|
|
833
|
+
" (",
|
|
834
|
+
args,
|
|
835
|
+
")"
|
|
836
|
+
] }) : null
|
|
837
|
+
]
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
841
|
+
className: `whitespace-pre-wrap break-words py-0.5 ${item.kind === "error" ? "text-rose-baziu" : ""}`,
|
|
842
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
843
|
+
className: "mr-1 opacity-45",
|
|
844
|
+
children: "←"
|
|
845
|
+
}), item.body]
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
/** Latest output of a running tool, kept scrolled to its end. */
|
|
849
|
+
function LiveToolOutput({ output }) {
|
|
850
|
+
const ref = useRef(null);
|
|
851
|
+
useLayoutEffect(() => {
|
|
852
|
+
if (ref.current) ref.current.scrollTop = ref.current.scrollHeight;
|
|
853
|
+
}, [output]);
|
|
854
|
+
return /* @__PURE__ */ jsx("pre", {
|
|
855
|
+
ref,
|
|
856
|
+
className: "my-0.5 ml-4 max-h-64 overflow-auto whitespace-pre-wrap break-words rounded-sm bg-[rgba(42,31,22,0.04)] px-2 py-1",
|
|
857
|
+
children: output
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
/** A conversation's messages, read-only (the conversation library). */
|
|
861
|
+
function ReadOnlyTranscript({ messages }) {
|
|
862
|
+
const markdownReady = useMarkdownReady();
|
|
863
|
+
return /* @__PURE__ */ jsx("section", {
|
|
864
|
+
"aria-label": "Conversation history",
|
|
865
|
+
children: projectMessages(messages).map((entry, index) => /* @__PURE__ */ jsx(Bubble, {
|
|
866
|
+
entry,
|
|
867
|
+
markdownReady
|
|
868
|
+
}, index))
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
//#endregion
|
|
872
|
+
//#region src/components/chat/ConversationLibrary.tsx
|
|
873
|
+
var PAGE = 20;
|
|
874
|
+
/** An Agent's conversations: start a new one, read and rename earlier ones (read-only). */
|
|
875
|
+
function ConversationLibrary({ agentId, turnBusy, onCreated, initialConversationId }) {
|
|
876
|
+
const base = `/api/agents/${encodeURIComponent(agentId)}/conversations`;
|
|
877
|
+
const [library, setLibrary] = useState(null);
|
|
878
|
+
const [offset, setOffset] = useState(0);
|
|
879
|
+
const [refresh, setRefresh] = useState(0);
|
|
880
|
+
const [selectedId, setSelectedId] = useState(initialConversationId ?? null);
|
|
881
|
+
const [opened, setOpened] = useState(null);
|
|
882
|
+
const [title, setTitle] = useState("");
|
|
883
|
+
const [error, setError] = useState("");
|
|
884
|
+
const [busy, setBusy] = useState(false);
|
|
885
|
+
useEffect(() => {
|
|
886
|
+
const controller = new AbortController();
|
|
887
|
+
setLibrary(null);
|
|
888
|
+
api(`${base}?limit=${PAGE}&offset=${offset}`, { signal: controller.signal }).then(setLibrary).catch((cause) => {
|
|
889
|
+
if (!controller.signal.aborted) setError(errorMessage(cause));
|
|
890
|
+
});
|
|
891
|
+
return () => controller.abort();
|
|
892
|
+
}, [
|
|
893
|
+
base,
|
|
894
|
+
offset,
|
|
895
|
+
refresh
|
|
896
|
+
]);
|
|
897
|
+
useEffect(() => {
|
|
898
|
+
if (!selectedId) return;
|
|
899
|
+
const controller = new AbortController();
|
|
900
|
+
setOpened(null);
|
|
901
|
+
api(`${base}/${encodeURIComponent(selectedId)}`, { signal: controller.signal }).then((body) => {
|
|
902
|
+
setOpened(body);
|
|
903
|
+
setTitle(body.conversation?.title ?? "");
|
|
904
|
+
}).catch((cause) => {
|
|
905
|
+
if (controller.signal.aborted) return;
|
|
906
|
+
const conversation = cause instanceof ApiError ? cause.body.conversation ?? null : null;
|
|
907
|
+
setOpened({
|
|
908
|
+
conversation,
|
|
909
|
+
messages: null
|
|
910
|
+
});
|
|
911
|
+
setTitle(conversation?.title ?? "");
|
|
912
|
+
});
|
|
913
|
+
return () => controller.abort();
|
|
914
|
+
}, [base, selectedId]);
|
|
915
|
+
async function run(request) {
|
|
916
|
+
setBusy(true);
|
|
917
|
+
setError("");
|
|
918
|
+
try {
|
|
919
|
+
return await request();
|
|
920
|
+
} catch (cause) {
|
|
921
|
+
setError(errorMessage(cause));
|
|
922
|
+
return null;
|
|
923
|
+
} finally {
|
|
924
|
+
setBusy(false);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
async function create() {
|
|
928
|
+
if (await run(() => api(base, { body: {} })) === null) return;
|
|
929
|
+
setSelectedId(null);
|
|
930
|
+
setOffset(0);
|
|
931
|
+
setRefresh((value) => value + 1);
|
|
932
|
+
await onCreated();
|
|
933
|
+
}
|
|
934
|
+
async function rename() {
|
|
935
|
+
if (!selectedId) return;
|
|
936
|
+
const body = await run(() => api(`${base}/${encodeURIComponent(selectedId)}`, {
|
|
937
|
+
method: "PATCH",
|
|
938
|
+
body: { title }
|
|
939
|
+
}));
|
|
940
|
+
if (!body) return;
|
|
941
|
+
setOpened((current) => current && {
|
|
942
|
+
...current,
|
|
943
|
+
conversation: body.conversation
|
|
944
|
+
});
|
|
945
|
+
setRefresh((value) => value + 1);
|
|
946
|
+
}
|
|
947
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
948
|
+
"aria-live": "off",
|
|
949
|
+
className: "mx-5 mt-2 max-h-[45%] min-w-0 shrink-0 space-y-4 overflow-y-auto rounded-lg border border-fawn bg-ivory p-4",
|
|
950
|
+
"aria-label": "Conversation library",
|
|
951
|
+
children: [
|
|
952
|
+
/* @__PURE__ */ jsxs("div", {
|
|
953
|
+
className: "flex flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between",
|
|
954
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
955
|
+
className: "m-0 text-lg",
|
|
956
|
+
children: "Conversations"
|
|
957
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
958
|
+
variant: "primary",
|
|
959
|
+
disabled: !library || busy || turnBusy,
|
|
960
|
+
onClick: () => void create(),
|
|
961
|
+
children: "New conversation"
|
|
962
|
+
})]
|
|
963
|
+
}),
|
|
964
|
+
/* @__PURE__ */ jsx("p", {
|
|
965
|
+
className: "m-0 text-sm",
|
|
966
|
+
children: "A new conversation starts with an empty history. Earlier ones and their saved files stay here to read; messages always go to the active conversation."
|
|
967
|
+
}),
|
|
968
|
+
turnBusy && /* @__PURE__ */ jsx("p", {
|
|
969
|
+
role: "status",
|
|
970
|
+
children: "Wait for the current turn to finish before starting a new conversation."
|
|
971
|
+
}),
|
|
972
|
+
error && /* @__PURE__ */ jsxs("p", {
|
|
973
|
+
role: "alert",
|
|
974
|
+
children: [
|
|
975
|
+
error,
|
|
976
|
+
" ",
|
|
977
|
+
/* @__PURE__ */ jsx(Button, {
|
|
978
|
+
variant: "ghost",
|
|
979
|
+
disabled: busy,
|
|
980
|
+
onClick: () => {
|
|
981
|
+
setError("");
|
|
982
|
+
setRefresh((value) => value + 1);
|
|
983
|
+
},
|
|
984
|
+
children: "Refresh"
|
|
985
|
+
})
|
|
986
|
+
]
|
|
987
|
+
}),
|
|
988
|
+
!library ? /* @__PURE__ */ jsx("p", {
|
|
989
|
+
role: "status",
|
|
990
|
+
children: "Loading conversations…"
|
|
991
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
992
|
+
library.total === 0 && /* @__PURE__ */ jsx("p", { children: "No conversations yet." }),
|
|
993
|
+
/* @__PURE__ */ jsx("ul", {
|
|
994
|
+
className: "mt-4 grid list-none gap-2 p-0",
|
|
995
|
+
children: library.conversations.map((item) => /* @__PURE__ */ jsxs("li", {
|
|
996
|
+
className: "flex min-w-0 flex-col items-start gap-3 rounded border border-fawn p-3 sm:flex-row sm:items-center sm:justify-between",
|
|
997
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
998
|
+
className: "flex min-w-0 flex-1 flex-wrap items-center gap-2",
|
|
999
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1000
|
+
className: "min-w-0 break-words [overflow-wrap:anywhere]",
|
|
1001
|
+
children: item.title
|
|
1002
|
+
}), item.id === library.selectedId && /* @__PURE__ */ jsx("strong", {
|
|
1003
|
+
className: "shrink-0 rounded-full bg-frost px-2 py-0.5 text-xs",
|
|
1004
|
+
children: "Active"
|
|
1005
|
+
})]
|
|
1006
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
1007
|
+
variant: "ghost",
|
|
1008
|
+
className: "max-w-full whitespace-normal break-words text-left sm:max-w-[50%]",
|
|
1009
|
+
disabled: busy,
|
|
1010
|
+
"aria-pressed": selectedId === item.id,
|
|
1011
|
+
onClick: () => setSelectedId(item.id),
|
|
1012
|
+
children: ["View ", item.title]
|
|
1013
|
+
})]
|
|
1014
|
+
}, item.id))
|
|
1015
|
+
}),
|
|
1016
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1017
|
+
className: "mt-4 flex flex-wrap items-center gap-2",
|
|
1018
|
+
children: [
|
|
1019
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1020
|
+
variant: "ghost",
|
|
1021
|
+
disabled: busy || offset === 0,
|
|
1022
|
+
onClick: () => setOffset(Math.max(0, offset - PAGE)),
|
|
1023
|
+
children: "Previous"
|
|
1024
|
+
}),
|
|
1025
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1026
|
+
variant: "ghost",
|
|
1027
|
+
disabled: busy || offset + library.conversations.length >= library.total,
|
|
1028
|
+
onClick: () => setOffset(offset + PAGE),
|
|
1029
|
+
children: "Next"
|
|
1030
|
+
}),
|
|
1031
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1032
|
+
className: "text-sm",
|
|
1033
|
+
children: [library.total, " conversations"]
|
|
1034
|
+
})
|
|
1035
|
+
]
|
|
1036
|
+
})
|
|
1037
|
+
] }),
|
|
1038
|
+
selectedId && /* @__PURE__ */ jsx("section", {
|
|
1039
|
+
className: "space-y-4 border-t border-fawn pt-4",
|
|
1040
|
+
"aria-label": "Earlier conversation",
|
|
1041
|
+
children: opened === null ? /* @__PURE__ */ jsx("p", {
|
|
1042
|
+
role: "status",
|
|
1043
|
+
children: "Loading history…"
|
|
1044
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
1045
|
+
className: "grid min-w-0 grid-cols-2 items-end gap-2 sm:grid-cols-[minmax(0,1fr)_auto_auto]",
|
|
1046
|
+
children: [
|
|
1047
|
+
/* @__PURE__ */ jsxs("label", {
|
|
1048
|
+
className: "col-span-2 m-0 grid min-w-0 gap-2 sm:col-span-1",
|
|
1049
|
+
children: ["Conversation title", /* @__PURE__ */ jsx("input", {
|
|
1050
|
+
className: "h-11",
|
|
1051
|
+
value: title,
|
|
1052
|
+
maxLength: 200,
|
|
1053
|
+
disabled: !opened.conversation,
|
|
1054
|
+
onChange: (event) => setTitle(event.target.value)
|
|
1055
|
+
})]
|
|
1056
|
+
}),
|
|
1057
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1058
|
+
variant: "ghost",
|
|
1059
|
+
className: "h-11",
|
|
1060
|
+
disabled: busy || !opened.conversation || !title.trim(),
|
|
1061
|
+
onClick: () => void rename(),
|
|
1062
|
+
children: "Rename"
|
|
1063
|
+
}),
|
|
1064
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1065
|
+
variant: "ghost",
|
|
1066
|
+
className: "h-11",
|
|
1067
|
+
disabled: busy,
|
|
1068
|
+
onClick: () => setSelectedId(null),
|
|
1069
|
+
children: "Close history"
|
|
1070
|
+
})
|
|
1071
|
+
]
|
|
1072
|
+
}), opened.messages === null ? /* @__PURE__ */ jsx("p", {
|
|
1073
|
+
role: "alert",
|
|
1074
|
+
children: "This conversation history is unavailable. You can still start a new conversation."
|
|
1075
|
+
}) : opened.messages.length > 0 ? /* @__PURE__ */ jsx(ReadOnlyTranscript, { messages: opened.messages }) : /* @__PURE__ */ jsx("p", { children: "This conversation is empty." })] })
|
|
1076
|
+
})
|
|
1077
|
+
]
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
//#endregion
|
|
1081
|
+
//#region src/components/chat/FollowUps.tsx
|
|
1082
|
+
/** Follow-ups waiting for the Agent's current turn. Hidden while there are none. */
|
|
1083
|
+
function FollowUps({ agentId, queue, onChanged, onViewConversation }) {
|
|
1084
|
+
const [editing, setEditing] = useState(null);
|
|
1085
|
+
const [busy, setBusy] = useState(false);
|
|
1086
|
+
const [error, setError] = useState("");
|
|
1087
|
+
if (!queue || queue.items.length === 0 && !queue.paused) return null;
|
|
1088
|
+
const base = `/api/agents/${encodeURIComponent(agentId)}/queue`;
|
|
1089
|
+
async function act(path, init) {
|
|
1090
|
+
setBusy(true);
|
|
1091
|
+
setError("");
|
|
1092
|
+
try {
|
|
1093
|
+
await api(`${base}${path}`, init);
|
|
1094
|
+
setEditing(null);
|
|
1095
|
+
} catch (cause) {
|
|
1096
|
+
setError(errorMessage(cause));
|
|
1097
|
+
} finally {
|
|
1098
|
+
setBusy(false);
|
|
1099
|
+
onChanged();
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
const pending = queue.items.some((item) => item.status === "pending");
|
|
1103
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1104
|
+
"aria-label": "Follow-up queue",
|
|
1105
|
+
className: "max-h-[35%] min-w-0 shrink-0 space-y-3 overflow-y-auto border-t border-frost px-5 py-3 text-sm",
|
|
1106
|
+
children: [
|
|
1107
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1108
|
+
className: "flex flex-wrap items-center justify-between gap-2",
|
|
1109
|
+
children: [/* @__PURE__ */ jsxs("strong", { children: ["Follow-ups", queue.paused ? " · paused" : ""] }), (queue.paused || pending) && /* @__PURE__ */ jsx(Button, {
|
|
1110
|
+
variant: "ghost",
|
|
1111
|
+
disabled: busy,
|
|
1112
|
+
onClick: () => void act("/control", { body: { paused: !queue.paused } }),
|
|
1113
|
+
children: queue.paused ? "Resume queue" : "Pause queue"
|
|
1114
|
+
})]
|
|
1115
|
+
}),
|
|
1116
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
1117
|
+
role: "alert",
|
|
1118
|
+
className: "m-0 break-words text-danger",
|
|
1119
|
+
children: error
|
|
1120
|
+
}),
|
|
1121
|
+
queue.items.map((item) => /* @__PURE__ */ jsxs("article", {
|
|
1122
|
+
className: "flex min-w-0 flex-col gap-2 rounded-lg border border-frost bg-ivory p-3",
|
|
1123
|
+
children: [
|
|
1124
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1125
|
+
className: "flex flex-wrap items-center gap-2",
|
|
1126
|
+
children: [
|
|
1127
|
+
/* @__PURE__ */ jsx("strong", {
|
|
1128
|
+
className: "rounded-full bg-frost px-2 py-0.5 text-xs capitalize",
|
|
1129
|
+
children: item.status
|
|
1130
|
+
}),
|
|
1131
|
+
/* @__PURE__ */ jsx("span", {
|
|
1132
|
+
className: "text-xs text-mocha",
|
|
1133
|
+
children: item.source === "telegram" ? "Telegram" : "Web / API"
|
|
1134
|
+
}),
|
|
1135
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1136
|
+
variant: "ghost",
|
|
1137
|
+
className: "ml-auto",
|
|
1138
|
+
onClick: () => onViewConversation(item.conversationId),
|
|
1139
|
+
children: "View conversation"
|
|
1140
|
+
})
|
|
1141
|
+
]
|
|
1142
|
+
}),
|
|
1143
|
+
editing?.id === item.id ? /* @__PURE__ */ jsxs("form", {
|
|
1144
|
+
className: "flex min-w-0 flex-col gap-2",
|
|
1145
|
+
onSubmit: (event) => {
|
|
1146
|
+
event.preventDefault();
|
|
1147
|
+
act(`/${encodeURIComponent(item.id)}`, {
|
|
1148
|
+
method: "PATCH",
|
|
1149
|
+
body: { message: editing.text }
|
|
1150
|
+
});
|
|
1151
|
+
},
|
|
1152
|
+
children: [/* @__PURE__ */ jsx("textarea", {
|
|
1153
|
+
"aria-label": "Edit follow-up",
|
|
1154
|
+
rows: 3,
|
|
1155
|
+
className: "w-full resize-y",
|
|
1156
|
+
value: editing.text,
|
|
1157
|
+
onChange: (event) => setEditing({
|
|
1158
|
+
id: item.id,
|
|
1159
|
+
text: event.target.value
|
|
1160
|
+
})
|
|
1161
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1162
|
+
className: "flex flex-wrap gap-2",
|
|
1163
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1164
|
+
variant: "primary",
|
|
1165
|
+
type: "submit",
|
|
1166
|
+
disabled: busy,
|
|
1167
|
+
children: "Save"
|
|
1168
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1169
|
+
variant: "ghost",
|
|
1170
|
+
onClick: () => setEditing(null),
|
|
1171
|
+
children: "Cancel"
|
|
1172
|
+
})]
|
|
1173
|
+
})]
|
|
1174
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
1175
|
+
className: "m-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",
|
|
1176
|
+
children: item.text
|
|
1177
|
+
}),
|
|
1178
|
+
item.attachments.map((file, index) => /* @__PURE__ */ jsxs("p", {
|
|
1179
|
+
className: "m-0 break-all text-xs text-mocha",
|
|
1180
|
+
children: [
|
|
1181
|
+
file.name ?? "Attachment",
|
|
1182
|
+
" · ",
|
|
1183
|
+
file.byteLength,
|
|
1184
|
+
" bytes"
|
|
1185
|
+
]
|
|
1186
|
+
}, index)),
|
|
1187
|
+
item.diagnostic && /* @__PURE__ */ jsx("p", {
|
|
1188
|
+
className: "m-0 break-words",
|
|
1189
|
+
children: item.diagnostic
|
|
1190
|
+
}),
|
|
1191
|
+
item.status !== "running" && editing?.id !== item.id && /* @__PURE__ */ jsxs("div", {
|
|
1192
|
+
className: "flex flex-wrap gap-2",
|
|
1193
|
+
children: [item.status === "pending" && /* @__PURE__ */ jsx(Button, {
|
|
1194
|
+
variant: "ghost",
|
|
1195
|
+
disabled: busy,
|
|
1196
|
+
onClick: () => setEditing({
|
|
1197
|
+
id: item.id,
|
|
1198
|
+
text: item.text
|
|
1199
|
+
}),
|
|
1200
|
+
children: "Edit"
|
|
1201
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1202
|
+
variant: "danger",
|
|
1203
|
+
disabled: busy,
|
|
1204
|
+
onClick: () => void act(`/${encodeURIComponent(item.id)}`, { method: "DELETE" }),
|
|
1205
|
+
children: "Remove"
|
|
1206
|
+
})]
|
|
1207
|
+
})
|
|
1208
|
+
]
|
|
1209
|
+
}, item.id))
|
|
1210
|
+
]
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
//#endregion
|
|
1214
|
+
//#region src/components/chat/slash-commands.ts
|
|
1215
|
+
var SLASH_HELP = [
|
|
1216
|
+
"slash commands:",
|
|
1217
|
+
" /context — context breakdown (system prompt, tools, skills, history)",
|
|
1218
|
+
" /compact [N] — summarize the head; keep the last N messages verbatim (default 10)",
|
|
1219
|
+
" /new — open the conversation library",
|
|
1220
|
+
" /help — show this list"
|
|
1221
|
+
].join("\n");
|
|
1222
|
+
function parseSlashCommand(text) {
|
|
1223
|
+
const trimmed = text.trim();
|
|
1224
|
+
if (!trimmed.startsWith("/")) return null;
|
|
1225
|
+
const [command = "", ...rest] = trimmed.split(/\s+/);
|
|
1226
|
+
return {
|
|
1227
|
+
command: command.toLowerCase(),
|
|
1228
|
+
rest: rest.join(" ")
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
/** `/compact N`: the number of trailing messages to keep, or undefined for the daemon default. */
|
|
1232
|
+
function parseKeepTail(rest) {
|
|
1233
|
+
const value = Number(rest.trim());
|
|
1234
|
+
return rest.trim() && Number.isFinite(value) && value >= 0 ? Math.floor(value) : void 0;
|
|
1235
|
+
}
|
|
1236
|
+
function formatBytes(n) {
|
|
1237
|
+
if (n < 1024) return `${n} B`;
|
|
1238
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KiB`;
|
|
1239
|
+
return `${(n / (1024 * 1024)).toFixed(2)} MiB`;
|
|
1240
|
+
}
|
|
1241
|
+
function formatContext(context) {
|
|
1242
|
+
const size = (chars, tokens) => `${chars.toLocaleString()} chars (~${tokens.toLocaleString()} tok)`;
|
|
1243
|
+
const lines = [
|
|
1244
|
+
`context for ${context.agentId}`,
|
|
1245
|
+
`model: ${context.model}`,
|
|
1246
|
+
"",
|
|
1247
|
+
`system prompt: ${size(context.systemPrompt.chars, context.systemPrompt.tokens)}`,
|
|
1248
|
+
...context.systemPrompt.files.map((f) => ` - ${f.name}: ${f.chars.toLocaleString()} chars`),
|
|
1249
|
+
"",
|
|
1250
|
+
`tools: ${context.tools.count} (${context.tools.schemaChars.toLocaleString()} chars of schema)`,
|
|
1251
|
+
...context.tools.entries.slice(0, 5).map((t) => ` - ${t.name}: ${t.schemaChars.toLocaleString()} chars`)
|
|
1252
|
+
];
|
|
1253
|
+
if (context.skills.count > 0) {
|
|
1254
|
+
lines.push("", `skills: ${context.skills.count}`);
|
|
1255
|
+
for (const skill of context.skills.entries.slice(0, 10)) lines.push(` - ${skill.name}: ${skill.blockChars.toLocaleString()} chars`);
|
|
1256
|
+
}
|
|
1257
|
+
lines.push("", `history: ${context.history.messageEntries} messages / ${context.history.compactionEntries} compactions`, ` ${size(context.history.chars, context.history.tokensEstimate)}`, ` bytes on disk: ${formatBytes(context.history.bytes)}`, "", `TOTAL: ${size(context.totals.chars, context.totals.tokens)}`);
|
|
1258
|
+
return lines.join("\n");
|
|
1259
|
+
}
|
|
1260
|
+
function formatCompaction(result) {
|
|
1261
|
+
return `/compact: ${result.before} → ${result.after} entries (${result.summarized} summarized, ${result.keptTail} kept verbatim; ~${result.tokensBefore.toLocaleString()} → ~${result.tokensAfter.toLocaleString()} tok). reloading…`;
|
|
1262
|
+
}
|
|
1263
|
+
//#endregion
|
|
1264
|
+
//#region src/components/chat/useChatSession.ts
|
|
1265
|
+
var SESSION_POLL_MS = 1e4;
|
|
1266
|
+
var QUEUE_POLL_MS = 5e3;
|
|
1267
|
+
var EMPTY_HEAD = {
|
|
1268
|
+
file: null,
|
|
1269
|
+
size: 0,
|
|
1270
|
+
conversationId: null
|
|
1271
|
+
};
|
|
1272
|
+
function openFollowUps(queue) {
|
|
1273
|
+
return queue?.items.filter((item) => item.status === "pending" || item.status === "running").length ?? 0;
|
|
1274
|
+
}
|
|
1275
|
+
function useChatSession({ agentId, initialMessages, initialSessionHead, onOpenLibrary }) {
|
|
1276
|
+
const base = `/api/agents/${encodeURIComponent(agentId)}`;
|
|
1277
|
+
const [messages, setMessages] = useState(initialMessages);
|
|
1278
|
+
const [live, setLive] = useState([]);
|
|
1279
|
+
const [notes, setNotes] = useState([]);
|
|
1280
|
+
const [thinking, setThinking] = useState(false);
|
|
1281
|
+
const [streaming, setStreaming] = useState(false);
|
|
1282
|
+
const [recoveredTurn, setRecoveredTurn] = useState(false);
|
|
1283
|
+
const [editing, setEditing] = useState(false);
|
|
1284
|
+
const [stale, setStale] = useState(false);
|
|
1285
|
+
const [historyUnavailable, setHistoryUnavailable] = useState(initialSessionHead?.unavailable ?? false);
|
|
1286
|
+
const [queue, setQueue] = useState(null);
|
|
1287
|
+
const [questionsKey, setQuestionsKey] = useState(0);
|
|
1288
|
+
const [approvalBusy, setApprovalBusy] = useState({});
|
|
1289
|
+
const [approvalErrors, setApprovalErrors] = useState({});
|
|
1290
|
+
const abortRef = useRef(null);
|
|
1291
|
+
const approvalTurnRef = useRef(false);
|
|
1292
|
+
const knownHeadRef = useRef(initialSessionHead ?? EMPTY_HEAD);
|
|
1293
|
+
const queueRef = useRef(null);
|
|
1294
|
+
const noteIdRef = useRef(0);
|
|
1295
|
+
const entryCountRef = useRef(0);
|
|
1296
|
+
const streamingRef = useRef(false);
|
|
1297
|
+
streamingRef.current = streaming;
|
|
1298
|
+
const turnBusy = streaming || recoveredTurn;
|
|
1299
|
+
const agentBusy = turnBusy || Boolean(queue?.turnActive);
|
|
1300
|
+
const queueWorking = queue?.turnActive || queue?.items.some((item) => item.status === "running" || item.status === "pending" && !queue.paused);
|
|
1301
|
+
function pushNote(content) {
|
|
1302
|
+
const note = {
|
|
1303
|
+
id: noteIdRef.current++,
|
|
1304
|
+
content,
|
|
1305
|
+
afterIndex: entryCountRef.current
|
|
1306
|
+
};
|
|
1307
|
+
setNotes((current) => [...current, note]);
|
|
1308
|
+
}
|
|
1309
|
+
async function refreshHistory() {
|
|
1310
|
+
if (streamingRef.current) return;
|
|
1311
|
+
try {
|
|
1312
|
+
const body = await api(`${base}/sessions/messages`);
|
|
1313
|
+
setHistoryUnavailable(body.head.unavailable ?? false);
|
|
1314
|
+
setMessages(body.messages);
|
|
1315
|
+
setLive([]);
|
|
1316
|
+
setEditing(false);
|
|
1317
|
+
knownHeadRef.current = body.head;
|
|
1318
|
+
setStale(false);
|
|
1319
|
+
} catch {
|
|
1320
|
+
pushNote("Conversation history is unavailable. Your draft is preserved.");
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
async function refreshKnownHead() {
|
|
1324
|
+
try {
|
|
1325
|
+
const head = await api(`${base}/sessions/head`);
|
|
1326
|
+
const prior = knownHeadRef.current.conversationId;
|
|
1327
|
+
if (prior && prior !== head.conversationId) {
|
|
1328
|
+
setStale(true);
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
setHistoryUnavailable(head.unavailable ?? false);
|
|
1332
|
+
knownHeadRef.current = head;
|
|
1333
|
+
} catch {}
|
|
1334
|
+
}
|
|
1335
|
+
async function refreshQueue() {
|
|
1336
|
+
try {
|
|
1337
|
+
const next = await api(`${base}/queue`);
|
|
1338
|
+
if (openFollowUps(next) < openFollowUps(queueRef.current) && !streamingRef.current) refreshHistory();
|
|
1339
|
+
queueRef.current = next;
|
|
1340
|
+
setQueue(next);
|
|
1341
|
+
} catch {}
|
|
1342
|
+
}
|
|
1343
|
+
useEffect(() => () => abortRef.current?.abort(), []);
|
|
1344
|
+
useEffect(() => {
|
|
1345
|
+
refreshQueue();
|
|
1346
|
+
}, []);
|
|
1347
|
+
useEffect(() => {
|
|
1348
|
+
if (!queueWorking) return;
|
|
1349
|
+
const timer = setInterval(() => {
|
|
1350
|
+
if (!document.hidden) refreshQueue();
|
|
1351
|
+
}, QUEUE_POLL_MS);
|
|
1352
|
+
return () => clearInterval(timer);
|
|
1353
|
+
}, [queueWorking]);
|
|
1354
|
+
useEffect(() => {
|
|
1355
|
+
if (!initialSessionHead || stale) return;
|
|
1356
|
+
const timer = setInterval(async () => {
|
|
1357
|
+
if (document.hidden || streamingRef.current) return;
|
|
1358
|
+
try {
|
|
1359
|
+
const head = await api(`${base}/sessions/head`);
|
|
1360
|
+
const known = knownHeadRef.current;
|
|
1361
|
+
if (Boolean(head.unavailable) !== Boolean(known.unavailable) || head.file !== known.file || head.size !== known.size) {
|
|
1362
|
+
setStale(true);
|
|
1363
|
+
refreshQueue();
|
|
1364
|
+
}
|
|
1365
|
+
} catch {}
|
|
1366
|
+
}, SESSION_POLL_MS);
|
|
1367
|
+
return () => clearInterval(timer);
|
|
1368
|
+
}, [
|
|
1369
|
+
base,
|
|
1370
|
+
initialSessionHead,
|
|
1371
|
+
stale
|
|
1372
|
+
]);
|
|
1373
|
+
useEffect(() => {
|
|
1374
|
+
const controller = new AbortController();
|
|
1375
|
+
api(shellApprovalsUrl(agentId), { signal: controller.signal }).then(({ approvals }) => {
|
|
1376
|
+
const pending = approvals.filter((approval) => approval.agentId === agentId && approval.status === "pending");
|
|
1377
|
+
if (pending.length === 0) return;
|
|
1378
|
+
approvalTurnRef.current = true;
|
|
1379
|
+
setLive((entries) => pending.reduce(upsertCommandApprovalEntry, entries));
|
|
1380
|
+
setRecoveredTurn(true);
|
|
1381
|
+
}).catch(() => {});
|
|
1382
|
+
return () => controller.abort();
|
|
1383
|
+
}, [agentId]);
|
|
1384
|
+
async function enqueue(draft) {
|
|
1385
|
+
try {
|
|
1386
|
+
await api(`${base}/queue`, { body: {
|
|
1387
|
+
message: draft.text,
|
|
1388
|
+
attachments: draft.attachments
|
|
1389
|
+
} });
|
|
1390
|
+
refreshQueue();
|
|
1391
|
+
return null;
|
|
1392
|
+
} catch (error) {
|
|
1393
|
+
pushNote(`The follow-up was not queued: ${errorMessage(error)}. Your draft is kept.`);
|
|
1394
|
+
return draft;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
async function compact(rest) {
|
|
1398
|
+
if (messages.length < 2) {
|
|
1399
|
+
pushNote("/compact: need ≥2 messages to compact");
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
setEditing(false);
|
|
1403
|
+
setStreaming(true);
|
|
1404
|
+
setThinking(true);
|
|
1405
|
+
try {
|
|
1406
|
+
pushNote(formatCompaction(await api(`${base}/chat/compact`, { body: { keepTail: parseKeepTail(rest) } })));
|
|
1407
|
+
setTimeout(() => window.location.reload(), 400);
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
pushNote(`/compact failed: ${errorMessage(error)}`);
|
|
1410
|
+
} finally {
|
|
1411
|
+
setThinking(false);
|
|
1412
|
+
setStreaming(false);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
/** True when `command` is a slash command, which then ran. */
|
|
1416
|
+
async function runSlashCommand(command, rest) {
|
|
1417
|
+
switch (command) {
|
|
1418
|
+
case "/help":
|
|
1419
|
+
pushNote(SLASH_HELP);
|
|
1420
|
+
return true;
|
|
1421
|
+
case "/context":
|
|
1422
|
+
try {
|
|
1423
|
+
pushNote(formatContext(await api(`${base}/chat/context`)));
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
pushNote(`/context failed: ${errorMessage(error)}`);
|
|
1426
|
+
}
|
|
1427
|
+
return true;
|
|
1428
|
+
case "/new":
|
|
1429
|
+
onOpenLibrary();
|
|
1430
|
+
return true;
|
|
1431
|
+
case "/compact":
|
|
1432
|
+
await compact(rest);
|
|
1433
|
+
return true;
|
|
1434
|
+
default: return false;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
function lastUserMessage() {
|
|
1438
|
+
return messages.findLastIndex((message) => message.role === "user");
|
|
1439
|
+
}
|
|
1440
|
+
function handleFrame(frame) {
|
|
1441
|
+
if (frame.kind === "fatal") {
|
|
1442
|
+
approvalTurnRef.current = false;
|
|
1443
|
+
setLive((entries) => [...cancelPendingApprovals(entries), {
|
|
1444
|
+
type: "error",
|
|
1445
|
+
content: `[fatal] ${frame.error}`
|
|
1446
|
+
}]);
|
|
1447
|
+
setRecoveredTurn(false);
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
if (frame.kind === "done") {
|
|
1451
|
+
approvalTurnRef.current = false;
|
|
1452
|
+
setMessages(frame.messages);
|
|
1453
|
+
setLive([]);
|
|
1454
|
+
setRecoveredTurn(false);
|
|
1455
|
+
setApprovalBusy({});
|
|
1456
|
+
setApprovalErrors({});
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
const event = frame.event;
|
|
1460
|
+
if (event.type === "command_approval") {
|
|
1461
|
+
if (event.approval.agentId !== agentId) return;
|
|
1462
|
+
approvalTurnRef.current = true;
|
|
1463
|
+
setThinking(event.approval.status !== "pending" && event.approval.status !== "cancelled");
|
|
1464
|
+
} else if (event.type === "agent_question") setQuestionsKey((key) => key + 1);
|
|
1465
|
+
else if (event.type === "assistant_delta" || event.type === "assistant_message" || event.type === "tool_call") setThinking(false);
|
|
1466
|
+
else if (event.type === "tool_result" || event.type === "tool_error") setThinking(true);
|
|
1467
|
+
setLive((entries) => applyEvent(entries, event));
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Send a message (a slash command, a follow-up while the Agent is busy, or a new turn). Returns
|
|
1471
|
+
* the draft to give back to the composer when it was not accepted.
|
|
1472
|
+
*/
|
|
1473
|
+
async function send(draft) {
|
|
1474
|
+
const slash = parseSlashCommand(draft.text);
|
|
1475
|
+
if (slash && await runSlashCommand(slash.command, slash.rest)) return draft.attachments.length > 0 ? {
|
|
1476
|
+
text: "",
|
|
1477
|
+
attachments: draft.attachments
|
|
1478
|
+
} : null;
|
|
1479
|
+
if (turnBusy) {
|
|
1480
|
+
if (!editing) return enqueue(draft);
|
|
1481
|
+
pushNote("Wait for the current turn to finish before replacing the last message.");
|
|
1482
|
+
return draft;
|
|
1483
|
+
}
|
|
1484
|
+
if (editing) {
|
|
1485
|
+
const keepCount = lastUserMessage();
|
|
1486
|
+
try {
|
|
1487
|
+
await api(`${base}/chat/truncate`, { body: {
|
|
1488
|
+
keepCount,
|
|
1489
|
+
conversationId: knownHeadRef.current.conversationId ?? void 0
|
|
1490
|
+
} });
|
|
1491
|
+
} catch (error) {
|
|
1492
|
+
pushNote(`Could not replace the last turn: ${errorMessage(error)}`);
|
|
1493
|
+
return draft;
|
|
1494
|
+
}
|
|
1495
|
+
setMessages((current) => current.slice(0, keepCount));
|
|
1496
|
+
setEditing(false);
|
|
1497
|
+
}
|
|
1498
|
+
const images = draft.attachments.filter((file) => isImageMime(file.mimeType));
|
|
1499
|
+
const files = draft.attachments.filter((file) => !isImageMime(file.mimeType)).map((file) => ({ name: file.name ?? "file" }));
|
|
1500
|
+
setLive([{
|
|
1501
|
+
type: "user",
|
|
1502
|
+
content: draft.text,
|
|
1503
|
+
...images.length > 0 ? { images } : {},
|
|
1504
|
+
...files.length > 0 ? { files } : {}
|
|
1505
|
+
}]);
|
|
1506
|
+
setRecoveredTurn(false);
|
|
1507
|
+
setApprovalBusy({});
|
|
1508
|
+
setApprovalErrors({});
|
|
1509
|
+
approvalTurnRef.current = false;
|
|
1510
|
+
const abort = new AbortController();
|
|
1511
|
+
abortRef.current = abort;
|
|
1512
|
+
setStreaming(true);
|
|
1513
|
+
setThinking(true);
|
|
1514
|
+
let finished = false;
|
|
1515
|
+
let restore = null;
|
|
1516
|
+
try {
|
|
1517
|
+
const response = await apiFetch(`${base}/chat`, {
|
|
1518
|
+
body: interactiveChatRequest(draft.text, draft.attachments),
|
|
1519
|
+
signal: abort.signal
|
|
1520
|
+
});
|
|
1521
|
+
if (!response.body) throw new Error("the chat response has no body");
|
|
1522
|
+
for await (const frame of readFrames(response.body)) {
|
|
1523
|
+
if (frame.kind !== "event") finished = true;
|
|
1524
|
+
handleFrame(frame);
|
|
1525
|
+
}
|
|
1526
|
+
await refreshKnownHead();
|
|
1527
|
+
} catch (error) {
|
|
1528
|
+
if (error instanceof ApiError) if (error.code === "agent_turn_active") {
|
|
1529
|
+
setLive([]);
|
|
1530
|
+
restore = await enqueue(draft);
|
|
1531
|
+
} else {
|
|
1532
|
+
setLive([{
|
|
1533
|
+
type: "error",
|
|
1534
|
+
content: `[error] ${error.message}`
|
|
1535
|
+
}]);
|
|
1536
|
+
restore = draft;
|
|
1537
|
+
}
|
|
1538
|
+
else if (error.name !== "AbortError") setLive((entries) => [...entries, {
|
|
1539
|
+
type: "error",
|
|
1540
|
+
content: `[network error] ${errorMessage(error)}`
|
|
1541
|
+
}]);
|
|
1542
|
+
} finally {
|
|
1543
|
+
if (abortRef.current === abort) {
|
|
1544
|
+
if (!finished && approvalTurnRef.current) setRecoveredTurn(true);
|
|
1545
|
+
setThinking(false);
|
|
1546
|
+
setStreaming(false);
|
|
1547
|
+
abortRef.current = null;
|
|
1548
|
+
refreshQueue();
|
|
1549
|
+
setQuestionsKey((key) => key + 1);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return restore;
|
|
1553
|
+
}
|
|
1554
|
+
/** Stop the running turn, wherever it came from. */
|
|
1555
|
+
async function stop() {
|
|
1556
|
+
try {
|
|
1557
|
+
await api(`${base}/cancel`, { method: "POST" });
|
|
1558
|
+
} catch (error) {
|
|
1559
|
+
if (!(error instanceof ApiError && error.status === 409)) pushNote("Stop was not confirmed; the response may still be running.");
|
|
1560
|
+
}
|
|
1561
|
+
refreshQueue();
|
|
1562
|
+
}
|
|
1563
|
+
async function reconcileApproval(id) {
|
|
1564
|
+
try {
|
|
1565
|
+
const { approvals } = await api(shellApprovalsUrl(agentId));
|
|
1566
|
+
const approval = approvals.find((item) => item.id === id && item.agentId === agentId);
|
|
1567
|
+
if (approval) setLive((entries) => upsertCommandApprovalEntry(entries, approval));
|
|
1568
|
+
return approval ?? null;
|
|
1569
|
+
} catch {
|
|
1570
|
+
return null;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
async function decide(approval, decision) {
|
|
1574
|
+
if (approval.agentId !== agentId || approval.status !== "pending") return;
|
|
1575
|
+
setApprovalBusy((current) => ({
|
|
1576
|
+
...current,
|
|
1577
|
+
[approval.id]: true
|
|
1578
|
+
}));
|
|
1579
|
+
setApprovalErrors(({ [approval.id]: _cleared, ...rest }) => rest);
|
|
1580
|
+
try {
|
|
1581
|
+
const body = await api(`/api/shell-approvals/${encodeURIComponent(approval.id)}`, { body: { decision } });
|
|
1582
|
+
if (body.approval.agentId === agentId) setLive((entries) => upsertCommandApprovalEntry(entries, body.approval));
|
|
1583
|
+
} catch (error) {
|
|
1584
|
+
const current = await reconcileApproval(approval.id);
|
|
1585
|
+
if (!current || current.status === "pending") setApprovalErrors((errors) => ({
|
|
1586
|
+
...errors,
|
|
1587
|
+
[approval.id]: errorMessage(error)
|
|
1588
|
+
}));
|
|
1589
|
+
} finally {
|
|
1590
|
+
setApprovalBusy((current) => ({
|
|
1591
|
+
...current,
|
|
1592
|
+
[approval.id]: false
|
|
1593
|
+
}));
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
/** Put the last user message back in the composer; sending it replaces the last turn. */
|
|
1597
|
+
function startEdit() {
|
|
1598
|
+
if (live.length > 0 || turnBusy) return null;
|
|
1599
|
+
const index = lastUserMessage();
|
|
1600
|
+
if (index < 0) return null;
|
|
1601
|
+
setEditing(true);
|
|
1602
|
+
return messages[index]?.content ?? null;
|
|
1603
|
+
}
|
|
1604
|
+
const history = projectMessages(messages);
|
|
1605
|
+
const entries = [...history, ...live];
|
|
1606
|
+
entryCountRef.current = entries.length;
|
|
1607
|
+
const lastUserEntry = history.findLastIndex((entry) => entry.type === "user");
|
|
1608
|
+
return {
|
|
1609
|
+
entries,
|
|
1610
|
+
notes,
|
|
1611
|
+
/** While editing, history from this entry on is about to be replaced (-1 otherwise). */
|
|
1612
|
+
replacedFrom: editing ? lastUserEntry : -1,
|
|
1613
|
+
/** The entry that offers "edit" (-1 when editing is not possible now). */
|
|
1614
|
+
editableEntry: !editing && live.length === 0 && !turnBusy ? lastUserEntry : -1,
|
|
1615
|
+
thinking,
|
|
1616
|
+
turnBusy,
|
|
1617
|
+
agentBusy,
|
|
1618
|
+
editing,
|
|
1619
|
+
stale,
|
|
1620
|
+
recoveredTurn,
|
|
1621
|
+
historyUnavailable,
|
|
1622
|
+
queue,
|
|
1623
|
+
questionsKey,
|
|
1624
|
+
approvals: {
|
|
1625
|
+
busy: approvalBusy,
|
|
1626
|
+
errors: approvalErrors,
|
|
1627
|
+
decide
|
|
1628
|
+
},
|
|
1629
|
+
send,
|
|
1630
|
+
stop,
|
|
1631
|
+
startEdit,
|
|
1632
|
+
cancelEdit: () => setEditing(false),
|
|
1633
|
+
refreshHistory,
|
|
1634
|
+
refreshQueue,
|
|
1635
|
+
dismissStale: () => setStale(false)
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
//#endregion
|
|
1639
|
+
//#region src/components/chat/ChatPane.tsx
|
|
1640
|
+
var AUTOSCROLL_THRESHOLD_PX = 40;
|
|
1641
|
+
/** One pane per Agent: switching Agents starts a fresh one. */
|
|
1642
|
+
function ChatPane(props) {
|
|
1643
|
+
return /* @__PURE__ */ jsx(AgentChat, { ...props }, props.agentId);
|
|
1644
|
+
}
|
|
1645
|
+
function AgentChat({ agentId, agentName, initialMessages, initialSessionHead, openConversationId }) {
|
|
1646
|
+
const markdownReady = useMarkdownReady();
|
|
1647
|
+
const [libraryOpen, setLibraryOpen] = useState(Boolean(openConversationId));
|
|
1648
|
+
const [libraryConversation, setLibraryConversation] = useState(openConversationId);
|
|
1649
|
+
const chat = useChatSession({
|
|
1650
|
+
agentId,
|
|
1651
|
+
initialMessages,
|
|
1652
|
+
initialSessionHead,
|
|
1653
|
+
onOpenLibrary: () => setLibraryOpen(true)
|
|
1654
|
+
});
|
|
1655
|
+
const [input, setInput] = useState("");
|
|
1656
|
+
const [attachments, setAttachments] = useState([]);
|
|
1657
|
+
const [dragging, setDragging] = useState(false);
|
|
1658
|
+
const inputRef = useRef(null);
|
|
1659
|
+
const logRef = useRef(null);
|
|
1660
|
+
const nearBottomRef = useRef(true);
|
|
1661
|
+
useLayoutEffect(() => {
|
|
1662
|
+
const log = logRef.current;
|
|
1663
|
+
if (log && nearBottomRef.current) log.scrollTop = log.scrollHeight;
|
|
1664
|
+
});
|
|
1665
|
+
async function addFiles(files) {
|
|
1666
|
+
const added = await encodeFiles(files);
|
|
1667
|
+
setAttachments((current) => [...current, ...added].slice(0, 16));
|
|
1668
|
+
}
|
|
1669
|
+
async function submit() {
|
|
1670
|
+
const draft = {
|
|
1671
|
+
text: input,
|
|
1672
|
+
attachments
|
|
1673
|
+
};
|
|
1674
|
+
if (!draft.text.trim() && draft.attachments.length === 0) return;
|
|
1675
|
+
setInput("");
|
|
1676
|
+
setAttachments([]);
|
|
1677
|
+
const restore = await chat.send(draft);
|
|
1678
|
+
if (restore) {
|
|
1679
|
+
setInput((current) => current || restore.text);
|
|
1680
|
+
setAttachments((current) => current.length > 0 ? current : restore.attachments);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
function edit() {
|
|
1684
|
+
const text = chat.startEdit();
|
|
1685
|
+
if (text === null) return;
|
|
1686
|
+
setInput(text);
|
|
1687
|
+
inputRef.current?.focus();
|
|
1688
|
+
}
|
|
1689
|
+
const empty = !chat.historyUnavailable && chat.entries.length === 0 && chat.notes.length === 0;
|
|
1690
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1691
|
+
"aria-label": `Chat with ${agentName}`,
|
|
1692
|
+
className: "relative flex h-full flex-col overflow-hidden rounded-[16px] border border-frost bg-snow shadow-baziu-sm",
|
|
1693
|
+
onDragOver: (event) => {
|
|
1694
|
+
if (!Array.from(event.dataTransfer.types).includes("Files")) return;
|
|
1695
|
+
event.preventDefault();
|
|
1696
|
+
setDragging(true);
|
|
1697
|
+
},
|
|
1698
|
+
onDragLeave: (event) => {
|
|
1699
|
+
if (event.currentTarget === event.target) setDragging(false);
|
|
1700
|
+
},
|
|
1701
|
+
onDrop: (event) => {
|
|
1702
|
+
if (event.dataTransfer.files.length === 0) return;
|
|
1703
|
+
event.preventDefault();
|
|
1704
|
+
setDragging(false);
|
|
1705
|
+
addFiles(event.dataTransfer.files);
|
|
1706
|
+
},
|
|
1707
|
+
children: [
|
|
1708
|
+
dragging && /* @__PURE__ */ jsx("div", {
|
|
1709
|
+
className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-[16px] border-2 border-dashed border-sapphire bg-sapphire-glow/80 text-[0.95em] font-medium text-sapphire-deep",
|
|
1710
|
+
children: "drop images or files to attach"
|
|
1711
|
+
}),
|
|
1712
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1713
|
+
className: "flex items-center justify-between gap-3 border-b border-frost px-4 py-2.5",
|
|
1714
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1715
|
+
className: "flex min-w-0 items-center gap-2",
|
|
1716
|
+
children: [/* @__PURE__ */ jsx("a", {
|
|
1717
|
+
href: "/",
|
|
1718
|
+
className: "inline-flex h-7 items-center rounded-md border border-frost px-2 text-xs font-semibold text-mocha lg:hidden",
|
|
1719
|
+
children: "← agents"
|
|
1720
|
+
}), /* @__PURE__ */ jsx("h1", {
|
|
1721
|
+
className: "truncate font-display text-[1.2rem] text-charcoal",
|
|
1722
|
+
children: agentName
|
|
1723
|
+
})]
|
|
1724
|
+
}), /* @__PURE__ */ jsx("a", {
|
|
1725
|
+
href: `/agents/${encodeURIComponent(agentId)}/settings`,
|
|
1726
|
+
className: "shrink-0 text-xs text-mocha-light hover:text-sapphire",
|
|
1727
|
+
children: "Manage agent →"
|
|
1728
|
+
})]
|
|
1729
|
+
}),
|
|
1730
|
+
/* @__PURE__ */ jsx("div", {
|
|
1731
|
+
className: "mx-5 mt-2",
|
|
1732
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
1733
|
+
variant: "ghost",
|
|
1734
|
+
"aria-expanded": libraryOpen,
|
|
1735
|
+
onClick: () => {
|
|
1736
|
+
setLibraryConversation(void 0);
|
|
1737
|
+
setLibraryOpen((open) => !open);
|
|
1738
|
+
},
|
|
1739
|
+
children: libraryOpen ? "Close conversations" : "Conversations"
|
|
1740
|
+
})
|
|
1741
|
+
}),
|
|
1742
|
+
libraryOpen && /* @__PURE__ */ jsx(ConversationLibrary, {
|
|
1743
|
+
agentId,
|
|
1744
|
+
initialConversationId: libraryConversation,
|
|
1745
|
+
turnBusy: chat.agentBusy,
|
|
1746
|
+
onCreated: chat.refreshHistory
|
|
1747
|
+
}, libraryConversation ?? ""),
|
|
1748
|
+
chat.historyUnavailable && /* @__PURE__ */ jsx("p", {
|
|
1749
|
+
role: "alert",
|
|
1750
|
+
className: "mx-5 mt-2 text-sm",
|
|
1751
|
+
children: "The selected conversation's history is unavailable. Open Conversations to start a new one; earlier conversations and their files stay listed."
|
|
1752
|
+
}),
|
|
1753
|
+
chat.stale && /* @__PURE__ */ jsxs("div", {
|
|
1754
|
+
role: "status",
|
|
1755
|
+
"aria-live": "polite",
|
|
1756
|
+
"aria-atomic": "true",
|
|
1757
|
+
className: "mx-5 mt-2 flex items-center gap-2 rounded-md border border-sapphire bg-frost px-4 py-2 text-[0.86em] text-mocha",
|
|
1758
|
+
children: [
|
|
1759
|
+
/* @__PURE__ */ jsx("span", {
|
|
1760
|
+
className: "h-2 w-2 flex-none rounded-full bg-sapphire",
|
|
1761
|
+
"aria-hidden": "true"
|
|
1762
|
+
}),
|
|
1763
|
+
/* @__PURE__ */ jsx("span", {
|
|
1764
|
+
className: "flex-1",
|
|
1765
|
+
children: chat.recoveredTurn ? "the recovered turn has new activity — reload to see it" : "new activity from another source — reload to see it"
|
|
1766
|
+
}),
|
|
1767
|
+
/* @__PURE__ */ jsx("button", {
|
|
1768
|
+
type: "button",
|
|
1769
|
+
onClick: () => void chat.refreshHistory(),
|
|
1770
|
+
className: "rounded-sm bg-sapphire px-3 py-1 text-[0.92em] text-snow hover:opacity-90",
|
|
1771
|
+
children: "reload"
|
|
1772
|
+
}),
|
|
1773
|
+
/* @__PURE__ */ jsx("button", {
|
|
1774
|
+
type: "button",
|
|
1775
|
+
onClick: chat.dismissStale,
|
|
1776
|
+
className: "px-1 text-mocha-light hover:text-mocha",
|
|
1777
|
+
"aria-label": "dismiss",
|
|
1778
|
+
children: "×"
|
|
1779
|
+
})
|
|
1780
|
+
]
|
|
1781
|
+
}),
|
|
1782
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1783
|
+
ref: logRef,
|
|
1784
|
+
onScroll: (event) => {
|
|
1785
|
+
const log = event.currentTarget;
|
|
1786
|
+
nearBottomRef.current = log.scrollHeight - log.scrollTop - log.clientHeight < AUTOSCROLL_THRESHOLD_PX;
|
|
1787
|
+
},
|
|
1788
|
+
role: "log",
|
|
1789
|
+
"aria-label": `Conversation with ${agentName}`,
|
|
1790
|
+
"aria-live": "polite",
|
|
1791
|
+
"aria-relevant": "additions",
|
|
1792
|
+
"aria-busy": chat.turnBusy,
|
|
1793
|
+
className: "min-h-0 flex-1 overflow-y-auto px-5 py-5",
|
|
1794
|
+
children: [
|
|
1795
|
+
empty && /* @__PURE__ */ jsx("p", {
|
|
1796
|
+
className: "py-12 text-center italic text-mocha-light",
|
|
1797
|
+
children: "Start a conversation…"
|
|
1798
|
+
}),
|
|
1799
|
+
withNotes(chat.entries.map((entry, index) => /* @__PURE__ */ jsx(Bubble, {
|
|
1800
|
+
entry,
|
|
1801
|
+
markdownReady,
|
|
1802
|
+
dropped: chat.replacedFrom >= 0 && index >= chat.replacedFrom,
|
|
1803
|
+
onEdit: index === chat.editableEntry ? edit : void 0,
|
|
1804
|
+
approvals: chat.approvals
|
|
1805
|
+
}, index)), chat.notes, markdownReady),
|
|
1806
|
+
chat.thinking && /* @__PURE__ */ jsxs("div", {
|
|
1807
|
+
className: "flex items-center gap-2 px-1 py-1 text-[0.85em] text-mocha-light",
|
|
1808
|
+
children: [
|
|
1809
|
+
/* @__PURE__ */ jsx(Dot, {}),
|
|
1810
|
+
/* @__PURE__ */ jsx(Dot, { delay: "0.15s" }),
|
|
1811
|
+
/* @__PURE__ */ jsx(Dot, { delay: "0.3s" }),
|
|
1812
|
+
/* @__PURE__ */ jsx("span", { children: "agent is thinking…" })
|
|
1813
|
+
]
|
|
1814
|
+
})
|
|
1815
|
+
]
|
|
1816
|
+
}),
|
|
1817
|
+
/* @__PURE__ */ jsx("p", {
|
|
1818
|
+
className: "sr-only",
|
|
1819
|
+
role: "status",
|
|
1820
|
+
"aria-live": "polite",
|
|
1821
|
+
"aria-atomic": "true",
|
|
1822
|
+
children: chat.turnBusy ? `${agentName} is responding.` : "Conversation ready."
|
|
1823
|
+
}),
|
|
1824
|
+
/* @__PURE__ */ jsx(FollowUps, {
|
|
1825
|
+
agentId,
|
|
1826
|
+
queue: chat.queue,
|
|
1827
|
+
onChanged: () => void chat.refreshQueue(),
|
|
1828
|
+
onViewConversation: (id) => {
|
|
1829
|
+
setLibraryConversation(id);
|
|
1830
|
+
setLibraryOpen(true);
|
|
1831
|
+
}
|
|
1832
|
+
}),
|
|
1833
|
+
/* @__PURE__ */ jsx(AgentQuestions, {
|
|
1834
|
+
agentId,
|
|
1835
|
+
refreshKey: chat.questionsKey
|
|
1836
|
+
}),
|
|
1837
|
+
/* @__PURE__ */ jsx(Composer, {
|
|
1838
|
+
agentName,
|
|
1839
|
+
value: input,
|
|
1840
|
+
onChange: setInput,
|
|
1841
|
+
onSubmit: () => void submit(),
|
|
1842
|
+
attachments,
|
|
1843
|
+
onAddFiles: (files) => void addFiles(files),
|
|
1844
|
+
onRemoveAttachment: (index) => setAttachments((current) => current.filter((_, i) => i !== index)),
|
|
1845
|
+
editing: chat.editing,
|
|
1846
|
+
onCancelEdit: chat.cancelEdit,
|
|
1847
|
+
agentBusy: chat.agentBusy,
|
|
1848
|
+
onStop: () => void chat.stop(),
|
|
1849
|
+
inputRef
|
|
1850
|
+
})
|
|
1851
|
+
]
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
/** Each slash-command note goes after the entry that was last when it was produced. */
|
|
1855
|
+
function withNotes(bubbles, notes, markdownReady) {
|
|
1856
|
+
const out = [];
|
|
1857
|
+
let next = 0;
|
|
1858
|
+
const flush = (upTo) => {
|
|
1859
|
+
while (next < notes.length && (notes[next]?.afterIndex ?? 0) <= upTo) {
|
|
1860
|
+
const note = notes[next];
|
|
1861
|
+
out.push(/* @__PURE__ */ jsx(Bubble, {
|
|
1862
|
+
entry: {
|
|
1863
|
+
type: "system",
|
|
1864
|
+
content: note.content
|
|
1865
|
+
},
|
|
1866
|
+
markdownReady
|
|
1867
|
+
}, `note-${note.id}`));
|
|
1868
|
+
next++;
|
|
1869
|
+
}
|
|
1870
|
+
};
|
|
1871
|
+
flush(0);
|
|
1872
|
+
bubbles.forEach((bubble, index) => {
|
|
1873
|
+
out.push(bubble);
|
|
1874
|
+
flush(index + 1);
|
|
1875
|
+
});
|
|
1876
|
+
flush(Number.POSITIVE_INFINITY);
|
|
1877
|
+
return out;
|
|
1878
|
+
}
|
|
1879
|
+
function Dot({ delay = "0s" }) {
|
|
1880
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1881
|
+
className: "inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-mocha-light/60",
|
|
1882
|
+
style: { animationDelay: delay },
|
|
1883
|
+
"aria-hidden": "true"
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
//#endregion
|
|
1887
|
+
export { ChatPane as t };
|