@backmatter/studio 0.0.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/dist/chunks/UiKitPage-CgNMOqfE.js +172 -0
- package/dist/chunks/WorkspaceRoutes-DgRtdie8.js +87297 -0
- package/dist/chunks/abap-Y8Dl9g_6.js +6 -0
- package/dist/chunks/actionscript-3-DQVEcJUW.js +6 -0
- package/dist/chunks/ada-vP6ak0IW.js +6 -0
- package/dist/chunks/andromeeda-BbmzSJq1.js +4 -0
- package/dist/chunks/angular-html-DPB4Rf0C.js +32 -0
- package/dist/chunks/angular-ts-CTOR2ofC.js +21 -0
- package/dist/chunks/apache-BUjz-sD2.js +6 -0
- package/dist/chunks/apex-OyTfjCYK.js +6 -0
- package/dist/chunks/apl-CjNiDgad.js +16 -0
- package/dist/chunks/applescript-BPx7YFFu.js +6 -0
- package/dist/chunks/ara-Z2fSOxSw.js +6 -0
- package/dist/chunks/asciidoc-C1T9ziH6.js +6 -0
- package/dist/chunks/asm-BTWLY5ym.js +6 -0
- package/dist/chunks/astro-CFFExE8Q.js +18 -0
- package/dist/chunks/aurora-x-BwoVEUWZ.js +4 -0
- package/dist/chunks/awk-Fb0P9dkn.js +6 -0
- package/dist/chunks/ayu-dark-DJoqd4M9.js +4 -0
- package/dist/chunks/ayu-light-BzXEJRJ-.js +4 -0
- package/dist/chunks/ayu-mirage-BJ2oZGzi.js +4 -0
- package/dist/chunks/ballerina-oZK-YekG.js +6 -0
- package/dist/chunks/bat-0FvbqU9S.js +6 -0
- package/dist/chunks/beancount-DqJEb89h.js +6 -0
- package/dist/chunks/berry-DODBq_Ff.js +6 -0
- package/dist/chunks/bibtex-EULQRLY5.js +6 -0
- package/dist/chunks/bicep-BorU73w0.js +6 -0
- package/dist/chunks/bird2-CIjBSNj3.js +6 -0
- package/dist/chunks/blade-D0HyNvCw.js +20 -0
- package/dist/chunks/bsl-NkNNwerW.js +8 -0
- package/dist/chunks/c-eeMepfLm.js +6 -0
- package/dist/chunks/c3-BY5XW5ym.js +6 -0
- package/dist/chunks/cadence-02UX7mW8.js +6 -0
- package/dist/chunks/cairo-DM6WF2e3.js +8 -0
- package/dist/chunks/catppuccin-frappe-D3cH2rXe.js +4 -0
- package/dist/chunks/catppuccin-latte-C0LRGUW4.js +4 -0
- package/dist/chunks/catppuccin-macchiato-c5wQ11TT.js +4 -0
- package/dist/chunks/catppuccin-mocha-WMD6Qvya.js +4 -0
- package/dist/chunks/clarity-PKm5CwqM.js +6 -0
- package/dist/chunks/clojure-CXJfHrL3.js +6 -0
- package/dist/chunks/cmake-BJz8BOTU.js +6 -0
- package/dist/chunks/cobol-HihOMwht.js +10 -0
- package/dist/chunks/codeowners-Bt9yU6NX.js +6 -0
- package/dist/chunks/codeql-DHkodjjI.js +6 -0
- package/dist/chunks/coffee-DGBR_nr_.js +8 -0
- package/dist/chunks/common-lisp-EVqT9Zhp.js +6 -0
- package/dist/chunks/coq-B0L9upzn.js +6 -0
- package/dist/chunks/cpp-Cj177cuW.js +18 -0
- package/dist/chunks/crystal-CRJyc4G-.js +18 -0
- package/dist/chunks/csharp-CCgA4A09.js +6 -0
- package/dist/chunks/css-CECN5uSL.js +6 -0
- package/dist/chunks/csv-CmYOceLb.js +6 -0
- package/dist/chunks/cue-ZzumE7IT.js +6 -0
- package/dist/chunks/cypher-jpdmjtA6.js +6 -0
- package/dist/chunks/d-CBagWSwH.js +6 -0
- package/dist/chunks/dark-plus-pUHDTVV0.js +4 -0
- package/dist/chunks/dart-6ObCrKr9.js +6 -0
- package/dist/chunks/dashboard-XKKZuJGm.js +1736 -0
- package/dist/chunks/dax-CcDT-8dH.js +6 -0
- package/dist/chunks/define-studio-BYtYDGLX.js +33 -0
- package/dist/chunks/desktop-B93p9R9O.js +6 -0
- package/dist/chunks/diff-BxzP2J8R.js +6 -0
- package/dist/chunks/docker-CsHqm9tx.js +6 -0
- package/dist/chunks/dotenv-BMjVjUL1.js +6 -0
- package/dist/chunks/dracula-BtZx2Kac.js +4 -0
- package/dist/chunks/dracula-soft-BKa-aqBv.js +4 -0
- package/dist/chunks/dream-maker-PAx17jaB.js +6 -0
- package/dist/chunks/edge-BYQkOzbF.js +12 -0
- package/dist/chunks/elixir-Dh036GMp.js +8 -0
- package/dist/chunks/elm-BtNbw_Cd.js +8 -0
- package/dist/chunks/emacs-lisp-Cfxdx5D-.js +6 -0
- package/dist/chunks/erb-ScVOXVpH.js +10 -0
- package/dist/chunks/erlang-DNcDT8Hi.js +8 -0
- package/dist/chunks/everforest-dark-DMCBqXCK.js +4 -0
- package/dist/chunks/everforest-light-BbXl82Em.js +4 -0
- package/dist/chunks/fennel-N4WcXuKx.js +6 -0
- package/dist/chunks/fish-BTDEUgqH.js +6 -0
- package/dist/chunks/fluent-BMXUxfv1.js +6 -0
- package/dist/chunks/fortran-fixed-form-B67KFkXH.js +8 -0
- package/dist/chunks/fortran-free-form-CwqYvCLJ.js +6 -0
- package/dist/chunks/fsharp-CYOiIVNx.js +8 -0
- package/dist/chunks/gdresource-CvCIUjhi.js +10 -0
- package/dist/chunks/gdscript-DSAxJ_aS.js +6 -0
- package/dist/chunks/gdshader-Bk8fF6yr.js +6 -0
- package/dist/chunks/genie-DzUvd7U9.js +6 -0
- package/dist/chunks/gherkin-DHRaV0YP.js +6 -0
- package/dist/chunks/git-commit-Bd32YZ0K.js +8 -0
- package/dist/chunks/git-rebase-ZWUFO_T4.js +8 -0
- package/dist/chunks/github-dark-DenFmJkN.js +4 -0
- package/dist/chunks/github-dark-default-BJPUVz4H.js +4 -0
- package/dist/chunks/github-dark-dimmed-DUshB20C.js +4 -0
- package/dist/chunks/github-dark-high-contrast-D3aGCnF8.js +4 -0
- package/dist/chunks/github-light-JYsPkUQd.js +4 -0
- package/dist/chunks/github-light-default-D99KPAby.js +4 -0
- package/dist/chunks/github-light-high-contrast-BbmZE-Mp.js +4 -0
- package/dist/chunks/gleam-Bv284lvN.js +6 -0
- package/dist/chunks/glimmer-js-DkxNrfPT.js +14 -0
- package/dist/chunks/glimmer-ts-D6YZEmK_.js +14 -0
- package/dist/chunks/glsl-CkUcVZNK.js +8 -0
- package/dist/chunks/gn-XtJxiLa4.js +6 -0
- package/dist/chunks/gnuplot-yPG9-sE_.js +6 -0
- package/dist/chunks/go-CvFNMTvu.js +6 -0
- package/dist/chunks/graphql-CBu2ehBn.js +14 -0
- package/dist/chunks/groovy-CJQTphOW.js +6 -0
- package/dist/chunks/gruvbox-dark-hard-C5HOtKIh.js +4 -0
- package/dist/chunks/gruvbox-dark-medium-FVgwJHuz.js +4 -0
- package/dist/chunks/gruvbox-dark-soft-B46F314v.js +4 -0
- package/dist/chunks/gruvbox-light-hard-CJD38wDZ.js +4 -0
- package/dist/chunks/gruvbox-light-medium-BlIhMYTA.js +4 -0
- package/dist/chunks/gruvbox-light-soft-DoPHyLVZ.js +4 -0
- package/dist/chunks/hack-ItRNKiEb.js +10 -0
- package/dist/chunks/haml-NZLVzu_R.js +10 -0
- package/dist/chunks/handlebars-mxStpSE7.js +14 -0
- package/dist/chunks/haskell-WeIwNIP6.js +6 -0
- package/dist/chunks/haxe-TztHsm5T.js +6 -0
- package/dist/chunks/hcl-D438OF-I.js +6 -0
- package/dist/chunks/hjson-DYBUbqOl.js +6 -0
- package/dist/chunks/hlsl-Bk8TCZNL.js +6 -0
- package/dist/chunks/horizon-CJQ10nlf.js +4 -0
- package/dist/chunks/horizon-bright-CdkBZOMB.js +4 -0
- package/dist/chunks/houston-BDYrDoDW.js +4 -0
- package/dist/chunks/html-B50bmoVb.js +10 -0
- package/dist/chunks/html-derivative-C6bxFbFW.js +8 -0
- package/dist/chunks/http-DLvAkeD-.js +14 -0
- package/dist/chunks/hurl-CgkFN90t.js +12 -0
- package/dist/chunks/hxml-GbqSQCLa.js +8 -0
- package/dist/chunks/hy-Brt5EZ7-.js +6 -0
- package/dist/chunks/imba-CimUv-Uh.js +6 -0
- package/dist/chunks/index-CFAIR8GH.js +18924 -0
- package/dist/chunks/ini-BZIuRIvJ.js +6 -0
- package/dist/chunks/java-DY6VlHhP.js +6 -0
- package/dist/chunks/javascript-C25yR2R2.js +6 -0
- package/dist/chunks/jinja-CFW5uAwY.js +11 -0
- package/dist/chunks/jison-DdreslRX.js +8 -0
- package/dist/chunks/json-DxJze_jm.js +6 -0
- package/dist/chunks/json5-BT4Fjg39.js +6 -0
- package/dist/chunks/jsonc-CHjZD8gR.js +6 -0
- package/dist/chunks/jsonl-BGuvDmy9.js +6 -0
- package/dist/chunks/jsonnet-Bx2cfsXg.js +6 -0
- package/dist/chunks/jssm-BcADi6EI.js +6 -0
- package/dist/chunks/jsx-BtKADgXT.js +6 -0
- package/dist/chunks/julia-CZiKXNNP.js +16 -0
- package/dist/chunks/just-CEK2SJ_k.js +18 -0
- package/dist/chunks/kanagawa-dragon-CiKur4Hl.js +4 -0
- package/dist/chunks/kanagawa-lotus-BKu-smKu.js +4 -0
- package/dist/chunks/kanagawa-wave-CQwozSzG.js +4 -0
- package/dist/chunks/kdl-BNOv9TC3.js +6 -0
- package/dist/chunks/kotlin-ByBMgTeR.js +6 -0
- package/dist/chunks/kusto-DH_XitHS.js +6 -0
- package/dist/chunks/laserwave-6a00oqik.js +4 -0
- package/dist/chunks/latex-B8Egmqc5.js +8 -0
- package/dist/chunks/lean-BnVxaZxY.js +6 -0
- package/dist/chunks/less-B1GLI2Di.js +6 -0
- package/dist/chunks/light-plus-CZuVqSLX.js +4 -0
- package/dist/chunks/liquid-CHzkx3jT.js +14 -0
- package/dist/chunks/llvm-Bk2XctFf.js +6 -0
- package/dist/chunks/log-Al8wyEFV.js +6 -0
- package/dist/chunks/logo-DBa4JDzV.js +6 -0
- package/dist/chunks/lua-Bp3IRv7I.js +8 -0
- package/dist/chunks/luau-UQyhudEE.js +6 -0
- package/dist/chunks/make-CsMclxtr.js +6 -0
- package/dist/chunks/markdown-CrScaQ96.js +6 -0
- package/dist/chunks/marko-CJBA24Ri.js +14 -0
- package/dist/chunks/material-theme-D6KBX41T.js +4 -0
- package/dist/chunks/material-theme-darker-CkRroheE.js +4 -0
- package/dist/chunks/material-theme-lighter-BUBw43Yz.js +4 -0
- package/dist/chunks/material-theme-ocean-ClGX14Ja.js +4 -0
- package/dist/chunks/material-theme-palenight-C1RVm8K1.js +4 -0
- package/dist/chunks/matlab-BOAaUVP0.js +6 -0
- package/dist/chunks/mdc-C9YSUwVC.js +12 -0
- package/dist/chunks/mdx-BOhZZUJ8.js +6 -0
- package/dist/chunks/mermaid-C3rz4dYh.js +6 -0
- package/dist/chunks/min-dark-C7ak0t6c.js +4 -0
- package/dist/chunks/min-light-CKFxVcPp.js +4 -0
- package/dist/chunks/mipsasm-CTx18fBl.js +6 -0
- package/dist/chunks/mojo-EIZIZRTQ.js +6 -0
- package/dist/chunks/monokai-C1KBYcO0.js +4 -0
- package/dist/chunks/moonbit-B1TV0fG3.js +6 -0
- package/dist/chunks/move-Db4ltDq1.js +6 -0
- package/dist/chunks/narrat-DmhDCBs-.js +6 -0
- package/dist/chunks/nextflow-47kAzSl1.js +8 -0
- package/dist/chunks/nextflow-groovy-Drz_2V0j.js +6 -0
- package/dist/chunks/nginx-D7O4WoB1.js +8 -0
- package/dist/chunks/night-owl-Bm2rzalh.js +4 -0
- package/dist/chunks/night-owl-light-CBI5u5kw.js +4 -0
- package/dist/chunks/nim-QAjRdh9w.js +20 -0
- package/dist/chunks/nix-fTRXMGic.js +9 -0
- package/dist/chunks/nord-CC5OiUXg.js +4 -0
- package/dist/chunks/nushell-BGCPRlV5.js +6 -0
- package/dist/chunks/objective-c-Itk8tzmv.js +6 -0
- package/dist/chunks/objective-cpp-DGt5UKRO.js +6 -0
- package/dist/chunks/ocaml-eSVK32Eg.js +6 -0
- package/dist/chunks/odin-BItnF517.js +6 -0
- package/dist/chunks/one-dark-pro-DTA3VF0_.js +4 -0
- package/dist/chunks/one-light-LkMrt1Cf.js +4 -0
- package/dist/chunks/openscad-Sp5uZ6f2.js +6 -0
- package/dist/chunks/pascal-xy8pJNns.js +6 -0
- package/dist/chunks/perl-DkVrgJBg.js +16 -0
- package/dist/chunks/php-BIzsF_5x.js +18 -0
- package/dist/chunks/pkl-C-zSNmaA.js +6 -0
- package/dist/chunks/plastic-CSTz3KZp.js +4 -0
- package/dist/chunks/plsql-pVbGZfOv.js +6 -0
- package/dist/chunks/po-BNfHvqmm.js +6 -0
- package/dist/chunks/poimandres-C-VADXHD.js +4 -0
- package/dist/chunks/polar-CAZahv3u.js +6 -0
- package/dist/chunks/postcss-05aHdL-n.js +6 -0
- package/dist/chunks/powerquery-DI9HkTvs.js +6 -0
- package/dist/chunks/powershell-Clc4ydu-.js +6 -0
- package/dist/chunks/prisma-FZjmVtSl.js +6 -0
- package/dist/chunks/prolog-C5-yg4TO.js +6 -0
- package/dist/chunks/proto-C7QgialS.js +6 -0
- package/dist/chunks/pug-XOw9Q1Ho.js +12 -0
- package/dist/chunks/puppet-CUJHmnxV.js +6 -0
- package/dist/chunks/purescript-rUfGld-4.js +6 -0
- package/dist/chunks/python-BFNSHbwJ.js +6 -0
- package/dist/chunks/qml-rTNXsquU.js +8 -0
- package/dist/chunks/qmldir-BInDYbpo.js +6 -0
- package/dist/chunks/qss-AeJTysr_.js +6 -0
- package/dist/chunks/r-CSmzDPi7.js +6 -0
- package/dist/chunks/racket-B83wSAja.js +6 -0
- package/dist/chunks/raku-nEQ4ZJJ7.js +6 -0
- package/dist/chunks/razor-Ci8D0dQK.js +10 -0
- package/dist/chunks/red-7y8PH7HH.js +4 -0
- package/dist/chunks/reg-m_s_Kiip.js +6 -0
- package/dist/chunks/regexp-BazyLpPg.js +6 -0
- package/dist/chunks/rel-BcRfyd6Q.js +6 -0
- package/dist/chunks/riscv-Ce8MAQLP.js +6 -0
- package/dist/chunks/ron-DCEEQypA.js +6 -0
- package/dist/chunks/rose-pine-BKc3yVeu.js +4 -0
- package/dist/chunks/rose-pine-dawn-BulJcPZT.js +4 -0
- package/dist/chunks/rose-pine-moon-j6jiXKV8.js +4 -0
- package/dist/chunks/rosmsg-Cz0w1km8.js +6 -0
- package/dist/chunks/rst-DM32Wy3O.js +22 -0
- package/dist/chunks/ruby-BeqCs27h.js +30 -0
- package/dist/chunks/rust-CLzF9zIN.js +6 -0
- package/dist/chunks/sas-fpEvgATw.js +8 -0
- package/dist/chunks/sass-DxHp5rTx.js +6 -0
- package/dist/chunks/scala-D4grkFkl.js +6 -0
- package/dist/chunks/scheme-BCRWuEm4.js +6 -0
- package/dist/chunks/scss-B1FaCqwR.js +8 -0
- package/dist/chunks/sdbl-B7T8abf4.js +6 -0
- package/dist/chunks/shaderlab-Cr62-Wb4.js +8 -0
- package/dist/chunks/shellscript-InADTalH.js +6 -0
- package/dist/chunks/shellsession-DiDJNQdy.js +8 -0
- package/dist/chunks/slack-dark-i7wN4OET.js +4 -0
- package/dist/chunks/slack-ochin-ndHf0LoP.js +4 -0
- package/dist/chunks/smalltalk-BlI1_OkM.js +6 -0
- package/dist/chunks/snazzy-light-BlSJXAu4.js +4 -0
- package/dist/chunks/solarized-dark-UTmkh7lw.js +4 -0
- package/dist/chunks/solarized-light-BheCkDPT.js +4 -0
- package/dist/chunks/solidity-DUWnFhS6.js +6 -0
- package/dist/chunks/soy-C1-6njHa.js +8 -0
- package/dist/chunks/sparql-B0KWFEri.js +8 -0
- package/dist/chunks/splunk-CRXR8A9s.js +6 -0
- package/dist/chunks/sql-Cn_v3PB0.js +6 -0
- package/dist/chunks/ssh-config-DP-hNVbF.js +6 -0
- package/dist/chunks/stata-B8c5fTjX.js +8 -0
- package/dist/chunks/stylus-CyKEU1Ej.js +6 -0
- package/dist/chunks/surrealql-CQi7GQN7.js +8 -0
- package/dist/chunks/svelte-rYri41WT.js +14 -0
- package/dist/chunks/swift-DJpUqPLg.js +6 -0
- package/dist/chunks/synthwave-84-NU3C_KFZ.js +4 -0
- package/dist/chunks/system-verilog-BCm7smPJ.js +6 -0
- package/dist/chunks/systemd-C-4qm6XH.js +6 -0
- package/dist/chunks/talonscript-CFF3LF_O.js +6 -0
- package/dist/chunks/tasl-Cg_WBUAe.js +6 -0
- package/dist/chunks/tcl-DN7buRTF.js +6 -0
- package/dist/chunks/templ-Crs9Ui8q.js +12 -0
- package/dist/chunks/terraform-DGvcn9zM.js +6 -0
- package/dist/chunks/tex-AHxmLTL0.js +8 -0
- package/dist/chunks/tokyo-night-DP4TmcQl.js +4 -0
- package/dist/chunks/toml-DY62mUL_.js +6 -0
- package/dist/chunks/ts-tags-ioVe2PKw.js +41 -0
- package/dist/chunks/tsv-BtvSkaG0.js +6 -0
- package/dist/chunks/tsx-B8rCNbgL.js +6 -0
- package/dist/chunks/turtle-_H59FV7D.js +6 -0
- package/dist/chunks/twig-DwV2Fi4L.js +18 -0
- package/dist/chunks/typescript-RycA9KXf.js +6 -0
- package/dist/chunks/typespec-DWqp-kUU.js +6 -0
- package/dist/chunks/typst-D_1QKWns.js +6 -0
- package/dist/chunks/v-BPCNiyYe.js +6 -0
- package/dist/chunks/vala-uxaPR7d1.js +6 -0
- package/dist/chunks/vb-D8_c5-KN.js +6 -0
- package/dist/chunks/verilog-B-bybjPF.js +6 -0
- package/dist/chunks/vesper-BckBta1U.js +4 -0
- package/dist/chunks/vhdl-CUlNa8ac.js +6 -0
- package/dist/chunks/viml-DsfA-sWm.js +6 -0
- package/dist/chunks/vitesse-black-BoGvW84i.js +4 -0
- package/dist/chunks/vitesse-dark-Cym-eLtO.js +4 -0
- package/dist/chunks/vitesse-light-CcmG315c.js +4 -0
- package/dist/chunks/vue-DXEmyXn9.js +31 -0
- package/dist/chunks/vue-html-j9xNEdu3.js +8 -0
- package/dist/chunks/vue-vine-D41-N99t.js +18 -0
- package/dist/chunks/vyper-CPQuu50u.js +6 -0
- package/dist/chunks/wasm-BBXxrAl7.js +6 -0
- package/dist/chunks/wasm-DQxwEHae.js +7 -0
- package/dist/chunks/wenyan-pbVjoM9_.js +6 -0
- package/dist/chunks/wgsl-DY4iK1q1.js +6 -0
- package/dist/chunks/wikitext-Z-MoUasO.js +6 -0
- package/dist/chunks/wit-CQMQOlTg.js +6 -0
- package/dist/chunks/wolfram-Dz4KXISs.js +6 -0
- package/dist/chunks/xml-C2J0sS9M.js +8 -0
- package/dist/chunks/xsl-BmSZphgC.js +8 -0
- package/dist/chunks/yaml-DaO7k5B1.js +6 -0
- package/dist/chunks/zenscript-CxBjpf9c.js +6 -0
- package/dist/chunks/zig-Vm0PO9wB.js +6 -0
- package/dist/dashboard.js +8 -0
- package/dist/define.js +4 -0
- package/dist/index.js +317 -0
- package/dist/studio.css +2272 -0
- package/dist/styles.js +1 -0
- package/package.json +88 -0
- package/prose-node-shims/fs.ts +6 -0
- package/prose-node-shims/path.ts +16 -0
- package/prose-node-shims/sharp.ts +4 -0
- package/prose-ui-node-shim.ts +26 -0
- package/src/App.tsx +173 -0
- package/src/WorkspaceRoutes.tsx +38 -0
- package/src/api.ts +833 -0
- package/src/auth-client.ts +15 -0
- package/src/chat/ChangeCard.tsx +330 -0
- package/src/chat/ChatBar.tsx +238 -0
- package/src/chat/ChatMessage.tsx +478 -0
- package/src/chat/ChatPanel.tsx +406 -0
- package/src/chat/ChatProvider.tsx +661 -0
- package/src/chat/Composer.tsx +461 -0
- package/src/chat/DocListCard.tsx +322 -0
- package/src/chat/LiveStatus.tsx +83 -0
- package/src/chat/MentionPopover.tsx +164 -0
- package/src/chat/ModelPicker.tsx +113 -0
- package/src/chat/Shimmer.tsx +39 -0
- package/src/chat/ThreadHistory.tsx +268 -0
- package/src/chat/chat-context.ts +41 -0
- package/src/chat/chat-helpers.ts +402 -0
- package/src/chat/chat-state.ts +59 -0
- package/src/chat/icons.tsx +171 -0
- package/src/chat/useStickToBottom.ts +110 -0
- package/src/chrome/AppShell.tsx +100 -0
- package/src/chrome/AppSidebar.tsx +305 -0
- package/src/chrome/CommandPalette.tsx +559 -0
- package/src/chrome/ContentApiPopover.tsx +215 -0
- package/src/chrome/EditorActionsContext.tsx +63 -0
- package/src/chrome/EditorFocusContext.tsx +80 -0
- package/src/chrome/EditorStatusContext.tsx +84 -0
- package/src/chrome/NavItem.tsx +75 -0
- package/src/chrome/OpenSiteButton.tsx +148 -0
- package/src/chrome/StatusBar.tsx +73 -0
- package/src/chrome/UserMenu.tsx +130 -0
- package/src/chrome/WorkspaceNavContext.tsx +60 -0
- package/src/chrome/WorkspaceStatusBar.tsx +940 -0
- package/src/chrome/content-api-url.ts +111 -0
- package/src/chrome/content-type-groups.ts +32 -0
- package/src/chrome/hotkeys.ts +79 -0
- package/src/chrome/icons.tsx +191 -0
- package/src/chrome/open-site.ts +30 -0
- package/src/chrome/status-bar-action.ts +24 -0
- package/src/components/AppChromeContext.tsx +32 -0
- package/src/components/Shell.tsx +18 -0
- package/src/components/WorkspaceSwitcher.tsx +345 -0
- package/src/content-blocks/index.tsx +262 -0
- package/src/css.d.ts +2 -0
- package/src/dashboard.ts +5 -0
- package/src/define-studio.tsx +98 -0
- package/src/define.ts +12 -0
- package/src/index.css +123 -0
- package/src/index.ts +19 -0
- package/src/last-user.ts +40 -0
- package/src/last-workspace.ts +57 -0
- package/src/mcp/McpConnectorsPanel.tsx +872 -0
- package/src/mcp/parse-json.ts +52 -0
- package/src/pages/AcceptInvitePage.tsx +99 -0
- package/src/pages/BlockSettingsDialog.tsx +303 -0
- package/src/pages/BlocksList.tsx +402 -0
- package/src/pages/BodyProse.tsx +236 -0
- package/src/pages/DocEditorPage.tsx +1394 -0
- package/src/pages/EmbedChatPage.tsx +110 -0
- package/src/pages/EmbedPublishPage.tsx +259 -0
- package/src/pages/EnterPage.tsx +96 -0
- package/src/pages/GithubConnectPage.tsx +142 -0
- package/src/pages/LegacyWorkspaceRedirect.tsx +57 -0
- package/src/pages/LoginPage.tsx +335 -0
- package/src/pages/NewWorkspacePage.tsx +74 -0
- package/src/pages/RenderedBody.tsx +598 -0
- package/src/pages/ResumeHome.tsx +18 -0
- package/src/pages/SelectionBar.tsx +277 -0
- package/src/pages/SettingsGeneralPage.tsx +403 -0
- package/src/pages/SettingsGithubPage.tsx +277 -0
- package/src/pages/SettingsLayout.tsx +127 -0
- package/src/pages/SettingsMcpPage.tsx +30 -0
- package/src/pages/SettingsSchemaPage.tsx +93 -0
- package/src/pages/SettingsUsersPage.tsx +363 -0
- package/src/pages/TypeDocsPage.tsx +225 -0
- package/src/pages/UiKitPage.tsx +331 -0
- package/src/pages/UserSettingsPage.tsx +94 -0
- package/src/pages/WorkspaceHomeRedirect.tsx +17 -0
- package/src/pages/WorkspaceLayout.tsx +103 -0
- package/src/pages/WorkspacesPage.tsx +35 -0
- package/src/pages/blocks-list.ts +73 -0
- package/src/pages/body-blocks.ts +233 -0
- package/src/pages/body-mdx.tsx +82 -0
- package/src/pages/compile-body.ts +37 -0
- package/src/pages/host-env.ts +22 -0
- package/src/pages/html-to-markdown.ts +99 -0
- package/src/pages/preview-bridge.ts +46 -0
- package/src/pages/preview-split.ts +30 -0
- package/src/pages/preview-url.ts +92 -0
- package/src/pages/selection-format.ts +179 -0
- package/src/pages/type-docs.ts +9 -0
- package/src/replica/BootstrapSplash.tsx +80 -0
- package/src/replica/ReplicaProvider.tsx +267 -0
- package/src/replica/cache.ts +30 -0
- package/src/replica/idb.ts +89 -0
- package/src/replica/instance.ts +39 -0
- package/src/replica/pull.ts +23 -0
- package/src/replica/store.ts +497 -0
- package/src/replica/sync-cache.ts +51 -0
- package/src/replica/types.ts +119 -0
- package/src/replica/useReplica.ts +13 -0
- package/src/site.tsx +230 -0
- package/src/studio-config.ts +81 -0
- package/src/styles/themes.ts +49 -0
- package/src/styles/tokens.stylex.ts +58 -0
- package/src/styles.ts +11 -0
- package/src/theme/AccentOverride.tsx +29 -0
- package/src/theme/ThemeProvider.tsx +130 -0
- package/src/theme/apply-theme-class.ts +12 -0
- package/src/ui/BackLink.tsx +28 -0
- package/src/ui/Button.tsx +167 -0
- package/src/ui/ConfirmDialog.tsx +141 -0
- package/src/ui/Field.tsx +45 -0
- package/src/ui/Input.tsx +183 -0
- package/src/ui/ListRow.tsx +88 -0
- package/src/ui/Page.tsx +151 -0
- package/src/ui/Text.tsx +77 -0
- package/src/ui/Tooltip.tsx +85 -0
- package/src/ui/popup.ts +216 -0
- package/src/workspace/permissions.ts +17 -0
- package/src/workspace/types.ts +12 -0
- package/src/workspace-path.ts +98 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
// packages/studio/src/chat/ChatProvider.tsx
|
|
2
|
+
//
|
|
3
|
+
// Global chat state: panel mode, thread selection, model, context chips, and the
|
|
4
|
+
// active chat session (AI SDK useChat). Mounted once in AppShell for workspace routes.
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useReducer,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from "react";
|
|
15
|
+
import { useChat } from "@ai-sdk/react";
|
|
16
|
+
import {
|
|
17
|
+
DefaultChatTransport,
|
|
18
|
+
getToolName,
|
|
19
|
+
isToolUIPart,
|
|
20
|
+
type UIMessage,
|
|
21
|
+
} from "ai";
|
|
22
|
+
import {
|
|
23
|
+
aiMessagesUrl,
|
|
24
|
+
createThread,
|
|
25
|
+
fetchAiModels,
|
|
26
|
+
fetchThread,
|
|
27
|
+
keepAllChanges,
|
|
28
|
+
keepChange,
|
|
29
|
+
notifyHeadChanged,
|
|
30
|
+
notifyTreeChanged,
|
|
31
|
+
undoAllChanges,
|
|
32
|
+
undoChange,
|
|
33
|
+
type AiModelInfo,
|
|
34
|
+
type AiTier,
|
|
35
|
+
type ApiError,
|
|
36
|
+
type ChatChangeSummary,
|
|
37
|
+
type ChatThread,
|
|
38
|
+
} from "../api";
|
|
39
|
+
import { apiCredentials, apiHeaders } from "../studio-config";
|
|
40
|
+
import {
|
|
41
|
+
docKey,
|
|
42
|
+
notifyDocChanged,
|
|
43
|
+
useEditorFocus,
|
|
44
|
+
type DocRef,
|
|
45
|
+
type EditorFocus,
|
|
46
|
+
} from "../chrome/EditorFocusContext";
|
|
47
|
+
import {
|
|
48
|
+
addMention as addMentionTo,
|
|
49
|
+
buildChatContext,
|
|
50
|
+
removeMention as removeMentionFrom,
|
|
51
|
+
type ChatRequestContext,
|
|
52
|
+
} from "./chat-context";
|
|
53
|
+
import {
|
|
54
|
+
changeIdsInMessage,
|
|
55
|
+
isWriteTool,
|
|
56
|
+
treeStatusPatches,
|
|
57
|
+
type TreeStatusPatch,
|
|
58
|
+
type WriteToolOutput,
|
|
59
|
+
} from "./chat-helpers";
|
|
60
|
+
import {
|
|
61
|
+
initialPanelState,
|
|
62
|
+
panelReducer,
|
|
63
|
+
type PanelAction,
|
|
64
|
+
type PanelState,
|
|
65
|
+
} from "./chat-state";
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// UI-level context (panel, thread selection, model, chips)
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
export type ChatUIValue = {
|
|
72
|
+
workspaceId: string;
|
|
73
|
+
panel: PanelState;
|
|
74
|
+
dispatch: (action: PanelAction) => void;
|
|
75
|
+
/** null while loading; false when the server has no AI provider configured. */
|
|
76
|
+
aiAvailable: boolean | null;
|
|
77
|
+
models: AiModelInfo[];
|
|
78
|
+
tier: AiTier;
|
|
79
|
+
model: string | null;
|
|
80
|
+
setModel: (id: string) => void;
|
|
81
|
+
threadId: string | null;
|
|
82
|
+
openThread: (threadId: string) => void;
|
|
83
|
+
newThread: () => void;
|
|
84
|
+
mentions: DocRef[];
|
|
85
|
+
addMention: (ref: DocRef) => void;
|
|
86
|
+
removeMention: (ref: DocRef) => void;
|
|
87
|
+
includeFocus: boolean;
|
|
88
|
+
setIncludeFocus: (v: boolean) => void;
|
|
89
|
+
focus: EditorFocus | null;
|
|
90
|
+
/** Bumped whenever a thread is created/renamed/deleted so history can refetch. */
|
|
91
|
+
threadsVersion: number;
|
|
92
|
+
bumpThreads: () => void;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const ChatUIContext = createContext<ChatUIValue | null>(null);
|
|
96
|
+
|
|
97
|
+
export function useChatUI(): ChatUIValue {
|
|
98
|
+
const ctx = useContext(ChatUIContext);
|
|
99
|
+
if (!ctx) throw new Error("useChatUI must be used within ChatProvider");
|
|
100
|
+
return ctx;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** For chrome that renders on routes with and without a workspace. */
|
|
104
|
+
export function useChatUIOptional(): ChatUIValue | null {
|
|
105
|
+
return useContext(ChatUIContext);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// Session-level context (messages, status, changes)
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
export type ChatSessionValue = {
|
|
113
|
+
threadId: string | null;
|
|
114
|
+
thread: ChatThread | null;
|
|
115
|
+
loading: boolean;
|
|
116
|
+
messages: UIMessage[];
|
|
117
|
+
status: "submitted" | "streaming" | "ready" | "error";
|
|
118
|
+
error: Error | undefined;
|
|
119
|
+
clearError: () => void;
|
|
120
|
+
send: (text: string) => Promise<void>;
|
|
121
|
+
stop: () => void;
|
|
122
|
+
changes: Record<string, ChatChangeSummary>;
|
|
123
|
+
keep: (changeId: string) => Promise<void>;
|
|
124
|
+
undo: (changeId: string) => Promise<void>;
|
|
125
|
+
keepAll: (messageId: string) => Promise<void>;
|
|
126
|
+
undoAll: (messageId: string) => Promise<void>;
|
|
127
|
+
/** Change ids attached to a message id (from tool outputs seen in this session). */
|
|
128
|
+
changeIdsForMessage: (message: UIMessage) => string[];
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const ChatSessionContext = createContext<ChatSessionValue | null>(null);
|
|
132
|
+
|
|
133
|
+
export function useChatSession(): ChatSessionValue {
|
|
134
|
+
const ctx = useContext(ChatSessionContext);
|
|
135
|
+
if (!ctx) throw new Error("useChatSession must be used within ChatProvider");
|
|
136
|
+
return ctx;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
const modelStorageKey = (ws: string) => `backmatter-chat-model:${ws}`;
|
|
142
|
+
|
|
143
|
+
/** Apply tool statuses locally so the top bar moves before the next git poll. */
|
|
144
|
+
function publishTreePatches(workspaceId: string, patches: TreeStatusPatch[]) {
|
|
145
|
+
let published = false;
|
|
146
|
+
for (const patch of patches) {
|
|
147
|
+
notifyTreeChanged({
|
|
148
|
+
workspaceId,
|
|
149
|
+
locale: patch.locale,
|
|
150
|
+
type: patch.type,
|
|
151
|
+
slug: patch.slug,
|
|
152
|
+
...(patch.absent ? { remove: true } : { status: patch.status }),
|
|
153
|
+
});
|
|
154
|
+
// A published file stays on screen; head-changed reloads it once. A file
|
|
155
|
+
// that disappeared still needs the open editor to drop it.
|
|
156
|
+
if (patch.absent || patch.status !== "clean") {
|
|
157
|
+
notifyDocChanged({ locale: patch.locale, type: patch.type, slug: patch.slug });
|
|
158
|
+
}
|
|
159
|
+
if (patch.status === "clean") published = true;
|
|
160
|
+
}
|
|
161
|
+
if (published) notifyHeadChanged();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function refFromInput(input: unknown): DocRef | null {
|
|
165
|
+
const ref = (input as { docRef?: Partial<DocRef> } | undefined)?.docRef;
|
|
166
|
+
if (!ref || !ref.locale || !ref.type || !ref.slug) return null;
|
|
167
|
+
return { locale: ref.locale, type: ref.type, slug: ref.slug };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function ChatProvider({
|
|
171
|
+
workspaceId,
|
|
172
|
+
startOpen = false,
|
|
173
|
+
children,
|
|
174
|
+
}: {
|
|
175
|
+
workspaceId: string;
|
|
176
|
+
startOpen?: boolean;
|
|
177
|
+
children: React.ReactNode;
|
|
178
|
+
}) {
|
|
179
|
+
const [panel, dispatch] = useReducer(
|
|
180
|
+
panelReducer,
|
|
181
|
+
startOpen ? { ...initialPanelState, mode: "open" as const } : initialPanelState,
|
|
182
|
+
);
|
|
183
|
+
const [aiAvailable, setAiAvailable] = useState<boolean | null>(null);
|
|
184
|
+
const [models, setModels] = useState<AiModelInfo[]>([]);
|
|
185
|
+
const [tier, setTier] = useState<AiTier>("ask");
|
|
186
|
+
const [model, setModelState] = useState<string | null>(null);
|
|
187
|
+
const [threadId, setThreadId] = useState<string | null>(null);
|
|
188
|
+
const [freshThread, setFreshThread] = useState(false);
|
|
189
|
+
const [pendingText, setPendingText] = useState<string | null>(null);
|
|
190
|
+
const [mentions, setMentions] = useState<DocRef[]>([]);
|
|
191
|
+
const [includeFocus, setIncludeFocus] = useState(true);
|
|
192
|
+
const [threadsVersion, setThreadsVersion] = useState(0);
|
|
193
|
+
const { focus } = useEditorFocus();
|
|
194
|
+
|
|
195
|
+
// Models + availability.
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
let cancelled = false;
|
|
198
|
+
setAiAvailable(null);
|
|
199
|
+
fetchAiModels(workspaceId)
|
|
200
|
+
.then((res) => {
|
|
201
|
+
if (cancelled) return;
|
|
202
|
+
setModels(res.models);
|
|
203
|
+
setTier(res.tier);
|
|
204
|
+
setAiAvailable(true);
|
|
205
|
+
const stored = window.localStorage.getItem(modelStorageKey(workspaceId));
|
|
206
|
+
const valid = res.models.some((m) => m.id === stored);
|
|
207
|
+
setModelState(valid ? stored : res.defaultModel);
|
|
208
|
+
})
|
|
209
|
+
.catch((err: ApiError) => {
|
|
210
|
+
if (cancelled) return;
|
|
211
|
+
setAiAvailable(false);
|
|
212
|
+
if (err.status !== 503) console.error("ai models failed", err);
|
|
213
|
+
});
|
|
214
|
+
return () => {
|
|
215
|
+
cancelled = true;
|
|
216
|
+
};
|
|
217
|
+
}, [workspaceId]);
|
|
218
|
+
|
|
219
|
+
// Reset per-workspace session state.
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
setThreadId(null);
|
|
222
|
+
setFreshThread(false);
|
|
223
|
+
setPendingText(null);
|
|
224
|
+
setMentions([]);
|
|
225
|
+
setIncludeFocus(true);
|
|
226
|
+
}, [workspaceId]);
|
|
227
|
+
|
|
228
|
+
const setModel = useCallback(
|
|
229
|
+
(id: string) => {
|
|
230
|
+
setModelState(id);
|
|
231
|
+
window.localStorage.setItem(modelStorageKey(workspaceId), id);
|
|
232
|
+
},
|
|
233
|
+
[workspaceId],
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const openThread = useCallback((id: string) => {
|
|
237
|
+
setThreadId(id);
|
|
238
|
+
setFreshThread(false);
|
|
239
|
+
setPendingText(null);
|
|
240
|
+
dispatch({ type: "showChat" });
|
|
241
|
+
}, []);
|
|
242
|
+
|
|
243
|
+
const newThread = useCallback(() => {
|
|
244
|
+
setThreadId(null);
|
|
245
|
+
setFreshThread(false);
|
|
246
|
+
setPendingText(null);
|
|
247
|
+
setMentions([]);
|
|
248
|
+
dispatch({ type: "showChat" });
|
|
249
|
+
}, []);
|
|
250
|
+
|
|
251
|
+
const addMention = useCallback((ref: DocRef) => {
|
|
252
|
+
setMentions((prev) => addMentionTo(prev, ref));
|
|
253
|
+
}, []);
|
|
254
|
+
const removeMention = useCallback((ref: DocRef) => {
|
|
255
|
+
setMentions((prev) => removeMentionFrom(prev, ref));
|
|
256
|
+
}, []);
|
|
257
|
+
const bumpThreads = useCallback(() => setThreadsVersion((v) => v + 1), []);
|
|
258
|
+
|
|
259
|
+
// Context getter kept in a ref so the session never re-renders because of it.
|
|
260
|
+
const contextRef = useRef<() => ChatRequestContext>(() => ({
|
|
261
|
+
focusDoc: null,
|
|
262
|
+
selection: null,
|
|
263
|
+
mentions: [],
|
|
264
|
+
}));
|
|
265
|
+
contextRef.current = () => buildChatContext({ focus, includeFocus, mentions });
|
|
266
|
+
const modelRef = useRef<string | null>(model);
|
|
267
|
+
modelRef.current = model;
|
|
268
|
+
|
|
269
|
+
// Creating a thread lazily on first send.
|
|
270
|
+
const startThread = useCallback(
|
|
271
|
+
async (text: string) => {
|
|
272
|
+
const res = await createThread(workspaceId);
|
|
273
|
+
setPendingText(text);
|
|
274
|
+
setFreshThread(true);
|
|
275
|
+
setThreadId(res.thread.id);
|
|
276
|
+
bumpThreads();
|
|
277
|
+
},
|
|
278
|
+
[workspaceId, bumpThreads],
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
const ui = useMemo<ChatUIValue>(
|
|
282
|
+
() => ({
|
|
283
|
+
workspaceId,
|
|
284
|
+
panel,
|
|
285
|
+
dispatch,
|
|
286
|
+
aiAvailable,
|
|
287
|
+
models,
|
|
288
|
+
tier,
|
|
289
|
+
model,
|
|
290
|
+
setModel,
|
|
291
|
+
threadId,
|
|
292
|
+
openThread,
|
|
293
|
+
newThread,
|
|
294
|
+
mentions,
|
|
295
|
+
addMention,
|
|
296
|
+
removeMention,
|
|
297
|
+
includeFocus,
|
|
298
|
+
setIncludeFocus,
|
|
299
|
+
focus,
|
|
300
|
+
threadsVersion,
|
|
301
|
+
bumpThreads,
|
|
302
|
+
}),
|
|
303
|
+
[
|
|
304
|
+
workspaceId,
|
|
305
|
+
panel,
|
|
306
|
+
aiAvailable,
|
|
307
|
+
models,
|
|
308
|
+
tier,
|
|
309
|
+
model,
|
|
310
|
+
setModel,
|
|
311
|
+
threadId,
|
|
312
|
+
openThread,
|
|
313
|
+
newThread,
|
|
314
|
+
mentions,
|
|
315
|
+
addMention,
|
|
316
|
+
removeMention,
|
|
317
|
+
includeFocus,
|
|
318
|
+
focus,
|
|
319
|
+
threadsVersion,
|
|
320
|
+
bumpThreads,
|
|
321
|
+
],
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
// The session subtree is keyed by thread and remounts when a chat starts or
|
|
325
|
+
// switches. Only the chat UI (see ChatSessionScope) lives inside it, so the
|
|
326
|
+
// editor and the rest of the app never remount because of chat state.
|
|
327
|
+
const renderSession = useCallback(
|
|
328
|
+
(scoped: React.ReactNode) =>
|
|
329
|
+
threadId ? (
|
|
330
|
+
<ChatSession
|
|
331
|
+
key={threadId}
|
|
332
|
+
workspaceId={workspaceId}
|
|
333
|
+
threadId={threadId}
|
|
334
|
+
fresh={freshThread}
|
|
335
|
+
pendingText={pendingText}
|
|
336
|
+
onPendingConsumed={() => setPendingText(null)}
|
|
337
|
+
getContext={() => contextRef.current()}
|
|
338
|
+
getModel={() => modelRef.current}
|
|
339
|
+
onThreadTouched={bumpThreads}
|
|
340
|
+
>
|
|
341
|
+
{scoped}
|
|
342
|
+
</ChatSession>
|
|
343
|
+
) : (
|
|
344
|
+
<EmptySession onFirstSend={startThread}>{scoped}</EmptySession>
|
|
345
|
+
),
|
|
346
|
+
[threadId, workspaceId, freshThread, pendingText, bumpThreads, startThread],
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
return (
|
|
350
|
+
<ChatUIContext.Provider value={ui}>
|
|
351
|
+
<SessionHostContext.Provider value={renderSession}>{children}</SessionHostContext.Provider>
|
|
352
|
+
</ChatUIContext.Provider>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const SessionHostContext = createContext<((scoped: React.ReactNode) => React.ReactNode) | null>(
|
|
357
|
+
null,
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Mounts the per-thread chat session around its children. Wrap only the chat UI
|
|
362
|
+
* (bar + panel) in this, never page content: the session remounts per thread.
|
|
363
|
+
*/
|
|
364
|
+
export function ChatSessionScope({ children }: { children: React.ReactNode }) {
|
|
365
|
+
const render = useContext(SessionHostContext);
|
|
366
|
+
if (!render) throw new Error("ChatSessionScope must be inside ChatProvider");
|
|
367
|
+
return <>{render(children)}</>;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// ---------------------------------------------------------------------------
|
|
371
|
+
|
|
372
|
+
function EmptySession({
|
|
373
|
+
onFirstSend,
|
|
374
|
+
children,
|
|
375
|
+
}: {
|
|
376
|
+
onFirstSend: (text: string) => Promise<void>;
|
|
377
|
+
children: React.ReactNode;
|
|
378
|
+
}) {
|
|
379
|
+
const [error, setError] = useState<Error | undefined>();
|
|
380
|
+
const [status, setStatus] = useState<ChatSessionValue["status"]>("ready");
|
|
381
|
+
const value = useMemo<ChatSessionValue>(
|
|
382
|
+
() => ({
|
|
383
|
+
threadId: null,
|
|
384
|
+
thread: null,
|
|
385
|
+
loading: false,
|
|
386
|
+
messages: [],
|
|
387
|
+
status,
|
|
388
|
+
error,
|
|
389
|
+
clearError: () => setError(undefined),
|
|
390
|
+
send: async (text) => {
|
|
391
|
+
setStatus("submitted");
|
|
392
|
+
try {
|
|
393
|
+
await onFirstSend(text);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
396
|
+
setStatus("error");
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
stop: () => {},
|
|
400
|
+
changes: {},
|
|
401
|
+
keep: async () => {},
|
|
402
|
+
undo: async () => {},
|
|
403
|
+
keepAll: async () => {},
|
|
404
|
+
undoAll: async () => {},
|
|
405
|
+
changeIdsForMessage: () => [],
|
|
406
|
+
}),
|
|
407
|
+
[onFirstSend, error, status],
|
|
408
|
+
);
|
|
409
|
+
return <ChatSessionContext.Provider value={value}>{children}</ChatSessionContext.Provider>;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
type SessionProps = {
|
|
413
|
+
workspaceId: string;
|
|
414
|
+
threadId: string;
|
|
415
|
+
fresh: boolean;
|
|
416
|
+
pendingText: string | null;
|
|
417
|
+
onPendingConsumed: () => void;
|
|
418
|
+
getContext: () => ChatRequestContext;
|
|
419
|
+
getModel: () => string | null;
|
|
420
|
+
onThreadTouched: () => void;
|
|
421
|
+
children: React.ReactNode;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/** Loads thread history (unless the thread was just created), then mounts useChat. */
|
|
425
|
+
function ChatSession(props: SessionProps) {
|
|
426
|
+
const { workspaceId, threadId, fresh } = props;
|
|
427
|
+
const [loaded, setLoaded] = useState(fresh);
|
|
428
|
+
const [thread, setThread] = useState<ChatThread | null>(null);
|
|
429
|
+
const [initialMessages, setInitialMessages] = useState<UIMessage[]>([]);
|
|
430
|
+
const [initialChanges, setInitialChanges] = useState<ChatChangeSummary[]>([]);
|
|
431
|
+
const [loadError, setLoadError] = useState<Error | undefined>();
|
|
432
|
+
|
|
433
|
+
useEffect(() => {
|
|
434
|
+
if (fresh) return;
|
|
435
|
+
let cancelled = false;
|
|
436
|
+
fetchThread(workspaceId, threadId)
|
|
437
|
+
.then((res) => {
|
|
438
|
+
if (cancelled) return;
|
|
439
|
+
setThread(res.thread);
|
|
440
|
+
setInitialMessages(res.messages as UIMessage[]);
|
|
441
|
+
setInitialChanges(res.changes);
|
|
442
|
+
setLoaded(true);
|
|
443
|
+
})
|
|
444
|
+
.catch((err: Error) => {
|
|
445
|
+
if (!cancelled) setLoadError(err);
|
|
446
|
+
});
|
|
447
|
+
return () => {
|
|
448
|
+
cancelled = true;
|
|
449
|
+
};
|
|
450
|
+
}, [workspaceId, threadId, fresh]);
|
|
451
|
+
|
|
452
|
+
if (!loaded) {
|
|
453
|
+
return (
|
|
454
|
+
<ChatSessionContext.Provider
|
|
455
|
+
value={{
|
|
456
|
+
threadId,
|
|
457
|
+
thread: null,
|
|
458
|
+
loading: !loadError,
|
|
459
|
+
messages: [],
|
|
460
|
+
status: loadError ? "error" : "ready",
|
|
461
|
+
error: loadError,
|
|
462
|
+
clearError: () => setLoadError(undefined),
|
|
463
|
+
send: async () => {},
|
|
464
|
+
stop: () => {},
|
|
465
|
+
changes: {},
|
|
466
|
+
keep: async () => {},
|
|
467
|
+
undo: async () => {},
|
|
468
|
+
keepAll: async () => {},
|
|
469
|
+
undoAll: async () => {},
|
|
470
|
+
changeIdsForMessage: () => [],
|
|
471
|
+
}}
|
|
472
|
+
>
|
|
473
|
+
{props.children}
|
|
474
|
+
</ChatSessionContext.Provider>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return (
|
|
479
|
+
<LiveSession
|
|
480
|
+
{...props}
|
|
481
|
+
thread={thread}
|
|
482
|
+
initialMessages={initialMessages}
|
|
483
|
+
initialChanges={initialChanges}
|
|
484
|
+
/>
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function LiveSession({
|
|
489
|
+
workspaceId,
|
|
490
|
+
threadId,
|
|
491
|
+
thread,
|
|
492
|
+
initialMessages,
|
|
493
|
+
initialChanges,
|
|
494
|
+
pendingText,
|
|
495
|
+
onPendingConsumed,
|
|
496
|
+
getContext,
|
|
497
|
+
getModel,
|
|
498
|
+
onThreadTouched,
|
|
499
|
+
children,
|
|
500
|
+
}: SessionProps & {
|
|
501
|
+
thread: ChatThread | null;
|
|
502
|
+
initialMessages: UIMessage[];
|
|
503
|
+
initialChanges: ChatChangeSummary[];
|
|
504
|
+
}) {
|
|
505
|
+
const { setAiEditingDocKey } = useEditorFocus();
|
|
506
|
+
const [changes, setChanges] = useState<Record<string, ChatChangeSummary>>(() =>
|
|
507
|
+
Object.fromEntries(initialChanges.map((c) => [c.id, c])),
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
const transport = useMemo(
|
|
511
|
+
() =>
|
|
512
|
+
new DefaultChatTransport<UIMessage>({
|
|
513
|
+
api: aiMessagesUrl(workspaceId, threadId),
|
|
514
|
+
credentials: apiCredentials(),
|
|
515
|
+
headers: apiHeaders(),
|
|
516
|
+
prepareSendMessagesRequest: ({ messages, body }) => ({
|
|
517
|
+
body: {
|
|
518
|
+
message: messages[messages.length - 1],
|
|
519
|
+
...(body ?? {}),
|
|
520
|
+
},
|
|
521
|
+
}),
|
|
522
|
+
}),
|
|
523
|
+
[workspaceId, threadId],
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
const chat = useChat<UIMessage>({
|
|
527
|
+
id: threadId,
|
|
528
|
+
messages: initialMessages,
|
|
529
|
+
transport,
|
|
530
|
+
onFinish: () => onThreadTouched(),
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
const { messages, status, sendMessage } = chat;
|
|
534
|
+
|
|
535
|
+
const send = useCallback(
|
|
536
|
+
async (text: string) => {
|
|
537
|
+
await sendMessage(
|
|
538
|
+
{ text },
|
|
539
|
+
{ body: { model: getModel(), context: getContext() } },
|
|
540
|
+
);
|
|
541
|
+
},
|
|
542
|
+
[sendMessage, getModel, getContext],
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
// Send the message that created this thread.
|
|
546
|
+
const sentPending = useRef(false);
|
|
547
|
+
useEffect(() => {
|
|
548
|
+
if (pendingText === null || sentPending.current) return;
|
|
549
|
+
sentPending.current = true;
|
|
550
|
+
onPendingConsumed();
|
|
551
|
+
void send(pendingText);
|
|
552
|
+
}, [pendingText, onPendingConsumed, send]);
|
|
553
|
+
|
|
554
|
+
// Watch tool parts: mark the focused doc as "AI editing" while a write tool
|
|
555
|
+
// targets it, and notify the editor/preview when a change lands.
|
|
556
|
+
const seenOutputs = useRef<Set<string> | null>(null);
|
|
557
|
+
useEffect(() => {
|
|
558
|
+
// History is already loaded when this session mounts. Ignore those tool
|
|
559
|
+
// results so an old commit does not clear the current working tree.
|
|
560
|
+
if (seenOutputs.current === null) {
|
|
561
|
+
const seeded = new Set<string>();
|
|
562
|
+
for (const message of messages) {
|
|
563
|
+
for (const part of message.parts ?? []) {
|
|
564
|
+
if (isToolUIPart(part) && part.state === "output-available") {
|
|
565
|
+
seeded.add(part.toolCallId);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
seenOutputs.current = seeded;
|
|
570
|
+
}
|
|
571
|
+
const seen = seenOutputs.current;
|
|
572
|
+
const streaming = status === "streaming" || status === "submitted";
|
|
573
|
+
const last = messages[messages.length - 1];
|
|
574
|
+
let editingKey: string | null = null;
|
|
575
|
+
if (last?.role === "assistant") {
|
|
576
|
+
for (const part of last.parts) {
|
|
577
|
+
if (!isToolUIPart(part)) continue;
|
|
578
|
+
const name = getToolName(part);
|
|
579
|
+
const write = isWriteTool(name);
|
|
580
|
+
const ref = write ? refFromInput(part.input) : null;
|
|
581
|
+
if (streaming && write && ref) editingKey = docKey(ref);
|
|
582
|
+
if (part.state === "output-available" && !seen.has(part.toolCallId)) {
|
|
583
|
+
seen.add(part.toolCallId);
|
|
584
|
+
const patches = treeStatusPatches(part.output);
|
|
585
|
+
if (patches.length > 0) publishTreePatches(workspaceId, patches);
|
|
586
|
+
const out = part.output as WriteToolOutput | undefined;
|
|
587
|
+
if (write && out?.ok) {
|
|
588
|
+
setChanges((prev) => ({ ...prev, [out.change.id]: out.change }));
|
|
589
|
+
if (patches.length === 0) {
|
|
590
|
+
if (ref) notifyDocChanged(ref);
|
|
591
|
+
notifyTreeChanged();
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
setAiEditingDocKey(streaming ? editingKey : null);
|
|
598
|
+
}, [messages, status, setAiEditingDocKey, workspaceId]);
|
|
599
|
+
|
|
600
|
+
useEffect(() => () => setAiEditingDocKey(null), [setAiEditingDocKey]);
|
|
601
|
+
|
|
602
|
+
const applyChangeResult = useCallback((change: ChatChangeSummary, notify: boolean) => {
|
|
603
|
+
setChanges((prev) => ({ ...prev, [change.id]: { ...prev[change.id], ...change } }));
|
|
604
|
+
if (notify) {
|
|
605
|
+
notifyDocChanged({ locale: change.locale, type: change.type, slug: change.slug });
|
|
606
|
+
notifyTreeChanged();
|
|
607
|
+
}
|
|
608
|
+
}, []);
|
|
609
|
+
|
|
610
|
+
const keep = useCallback(
|
|
611
|
+
async (changeId: string) => {
|
|
612
|
+
const res = await keepChange(workspaceId, changeId);
|
|
613
|
+
applyChangeResult(res.change, false);
|
|
614
|
+
},
|
|
615
|
+
[workspaceId, applyChangeResult],
|
|
616
|
+
);
|
|
617
|
+
const undo = useCallback(
|
|
618
|
+
async (changeId: string) => {
|
|
619
|
+
const res = await undoChange(workspaceId, changeId);
|
|
620
|
+
applyChangeResult(res.change, true);
|
|
621
|
+
},
|
|
622
|
+
[workspaceId, applyChangeResult],
|
|
623
|
+
);
|
|
624
|
+
const keepAll = useCallback(
|
|
625
|
+
async (messageId: string) => {
|
|
626
|
+
const res = await keepAllChanges(workspaceId, threadId, messageId);
|
|
627
|
+
for (const c of res.changes) applyChangeResult(c, false);
|
|
628
|
+
},
|
|
629
|
+
[workspaceId, threadId, applyChangeResult],
|
|
630
|
+
);
|
|
631
|
+
const undoAll = useCallback(
|
|
632
|
+
async (messageId: string) => {
|
|
633
|
+
const res = await undoAllChanges(workspaceId, threadId, messageId);
|
|
634
|
+
for (const c of res.changes) applyChangeResult(c, true);
|
|
635
|
+
},
|
|
636
|
+
[workspaceId, threadId, applyChangeResult],
|
|
637
|
+
);
|
|
638
|
+
|
|
639
|
+
const value = useMemo<ChatSessionValue>(
|
|
640
|
+
() => ({
|
|
641
|
+
threadId,
|
|
642
|
+
thread,
|
|
643
|
+
loading: false,
|
|
644
|
+
messages,
|
|
645
|
+
status,
|
|
646
|
+
error: chat.error,
|
|
647
|
+
clearError: chat.clearError,
|
|
648
|
+
send,
|
|
649
|
+
stop: chat.stop,
|
|
650
|
+
changes,
|
|
651
|
+
keep,
|
|
652
|
+
undo,
|
|
653
|
+
keepAll,
|
|
654
|
+
undoAll,
|
|
655
|
+
changeIdsForMessage: changeIdsInMessage,
|
|
656
|
+
}),
|
|
657
|
+
[threadId, thread, messages, status, chat.error, chat.clearError, send, chat.stop, changes, keep, undo, keepAll, undoAll],
|
|
658
|
+
);
|
|
659
|
+
|
|
660
|
+
return <ChatSessionContext.Provider value={value}>{children}</ChatSessionContext.Provider>;
|
|
661
|
+
}
|