anycodex 0.0.3 → 0.0.4
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/bin.js +21 -9
- package/package.json +3 -60
- package/src/bin.ts +663 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +12 -0
- package/dist/app/assets/abap-BdImnpbu.js +0 -1
- package/dist/app/assets/actionscript-3-CoDkCxhg.js +0 -1
- package/dist/app/assets/ada-bCR0ucgS.js +0 -1
- package/dist/app/assets/andromeeda-C4gqWexZ.js +0 -1
- package/dist/app/assets/angular-html-DA-rfuFy.js +0 -1
- package/dist/app/assets/angular-ts-BrjP3tb8.js +0 -1
- package/dist/app/assets/apache-Pmp26Uib.js +0 -1
- package/dist/app/assets/apex-D8_7TLub.js +0 -1
- package/dist/app/assets/apl-CORt7UWP.js +0 -1
- package/dist/app/assets/applescript-Co6uUVPk.js +0 -1
- package/dist/app/assets/ara-BRHolxvo.js +0 -1
- package/dist/app/assets/asciidoc-Ve4PFQV2.js +0 -1
- package/dist/app/assets/asm-D_Q5rh1f.js +0 -1
- package/dist/app/assets/astro-HNnZUWAn.js +0 -1
- package/dist/app/assets/aurora-x-D-2ljcwZ.js +0 -1
- package/dist/app/assets/awk-DMzUqQB5.js +0 -1
- package/dist/app/assets/ayu-dark-DYE7WIF3.js +0 -1
- package/dist/app/assets/ayu-light-BA47KaF1.js +0 -1
- package/dist/app/assets/ayu-mirage-32ctXXKs.js +0 -1
- package/dist/app/assets/ballerina-BFfxhgS-.js +0 -1
- package/dist/app/assets/bat-BkioyH1T.js +0 -1
- package/dist/app/assets/beancount-k_qm7-4y.js +0 -1
- package/dist/app/assets/berry-uYugtg8r.js +0 -1
- package/dist/app/assets/bibtex-CHM0blh-.js +0 -1
- package/dist/app/assets/bicep-Bmn6On1c.js +0 -1
- package/dist/app/assets/bird2-BIv1doCn.js +0 -1
- package/dist/app/assets/blade-BjGOyj-B.js +0 -1
- package/dist/app/assets/bsl-BO_Y6i37.js +0 -1
- package/dist/app/assets/c-BIGW1oBm.js +0 -1
- package/dist/app/assets/c3-eo99z4R2.js +0 -1
- package/dist/app/assets/cadence-Bv_4Rxtq.js +0 -1
- package/dist/app/assets/cairo-KRGpt6FW.js +0 -1
- package/dist/app/assets/catppuccin-frappe-DFWUc33u.js +0 -1
- package/dist/app/assets/catppuccin-latte-C9dUb6Cb.js +0 -1
- package/dist/app/assets/catppuccin-macchiato-DQyhUUbL.js +0 -1
- package/dist/app/assets/catppuccin-mocha-D87Tk5Gz.js +0 -1
- package/dist/app/assets/clarity-D53aC0YG.js +0 -1
- package/dist/app/assets/clojure-P80f7IUj.js +0 -1
- package/dist/app/assets/cmake-D1j8_8rp.js +0 -1
- package/dist/app/assets/cobol-nBiQ_Alo.js +0 -1
- package/dist/app/assets/codeowners-Bp6g37R7.js +0 -1
- package/dist/app/assets/codeql-DsOJ9woJ.js +0 -1
- package/dist/app/assets/coffee-Ch7k5sss.js +0 -1
- package/dist/app/assets/common-lisp-Cg-RD9OK.js +0 -1
- package/dist/app/assets/coq-DkFqJrB1.js +0 -1
- package/dist/app/assets/cpp-CofmeUqb.js +0 -1
- package/dist/app/assets/crystal-DNxU26gB.js +0 -1
- package/dist/app/assets/csharp-COcwbKMJ.js +0 -1
- package/dist/app/assets/css-CLj8gQPS.js +0 -1
- package/dist/app/assets/csv-fuZLfV_i.js +0 -1
- package/dist/app/assets/cue-D82EKSYY.js +0 -1
- package/dist/app/assets/cypher-COkxafJQ.js +0 -1
- package/dist/app/assets/d-85-TOEBH.js +0 -1
- package/dist/app/assets/dark-plus-C3mMm8J8.js +0 -1
- package/dist/app/assets/dart-bE4Kk8sk.js +0 -1
- package/dist/app/assets/dax-CEL-wOlO.js +0 -1
- package/dist/app/assets/desktop-BmXAJ9_W.js +0 -1
- package/dist/app/assets/diff-D97Zzqfu.js +0 -1
- package/dist/app/assets/docker-BcOcwvcX.js +0 -1
- package/dist/app/assets/dotenv-Da5cRb03.js +0 -1
- package/dist/app/assets/dracula-BzJJZx-M.js +0 -1
- package/dist/app/assets/dracula-soft-BXkSAIEj.js +0 -1
- package/dist/app/assets/dream-maker-BtqSS_iP.js +0 -1
- package/dist/app/assets/edge-FbVlp4U3.js +0 -1
- package/dist/app/assets/elixir-CkH2-t6x.js +0 -1
- package/dist/app/assets/elm-DbKCFpqz.js +0 -1
- package/dist/app/assets/emacs-lisp-CXvaQtF9.js +0 -1
- package/dist/app/assets/erb-BYCe7drp.js +0 -1
- package/dist/app/assets/erlang-DsQrWhSR.js +0 -1
- package/dist/app/assets/everforest-dark-BgDCqdQA.js +0 -1
- package/dist/app/assets/everforest-light-C8M2exoo.js +0 -1
- package/dist/app/assets/fennel-BYunw83y.js +0 -1
- package/dist/app/assets/fish-BvzEVeQv.js +0 -1
- package/dist/app/assets/fluent-C4IJs8-o.js +0 -1
- package/dist/app/assets/fortran-fixed-form-CkoXwp7k.js +0 -1
- package/dist/app/assets/fortran-free-form-BxgE0vQu.js +0 -1
- package/dist/app/assets/fsharp-CXgrBDvD.js +0 -1
- package/dist/app/assets/gdresource-BOOCDP_w.js +0 -1
- package/dist/app/assets/gdscript-C5YyOfLZ.js +0 -1
- package/dist/app/assets/gdshader-DkwncUOv.js +0 -1
- package/dist/app/assets/genie-D0YGMca9.js +0 -1
- package/dist/app/assets/gherkin-DyxjwDmM.js +0 -1
- package/dist/app/assets/git-commit-F4YmCXRG.js +0 -1
- package/dist/app/assets/git-rebase-r7XF79zn.js +0 -1
- package/dist/app/assets/github-dark-DHJKELXO.js +0 -1
- package/dist/app/assets/github-dark-default-Cuk6v7N8.js +0 -1
- package/dist/app/assets/github-dark-dimmed-DH5Ifo-i.js +0 -1
- package/dist/app/assets/github-dark-high-contrast-E3gJ1_iC.js +0 -1
- package/dist/app/assets/github-light-DAi9KRSo.js +0 -1
- package/dist/app/assets/github-light-default-D7oLnXFd.js +0 -1
- package/dist/app/assets/github-light-high-contrast-BfjtVDDH.js +0 -1
- package/dist/app/assets/gleam-BspZqrRM.js +0 -1
- package/dist/app/assets/glimmer-js-ByusRIyA.js +0 -1
- package/dist/app/assets/glimmer-ts-BfAWNZQY.js +0 -1
- package/dist/app/assets/glsl-DplSGwfg.js +0 -1
- package/dist/app/assets/gn-n2N0HUVH.js +0 -1
- package/dist/app/assets/gnuplot-DdkO51Og.js +0 -1
- package/dist/app/assets/go-C27-OAKa.js +0 -1
- package/dist/app/assets/graphql-ChdNCCLP.js +0 -1
- package/dist/app/assets/groovy-gcz8RCvz.js +0 -1
- package/dist/app/assets/gruvbox-dark-hard-CFHQjOhq.js +0 -1
- package/dist/app/assets/gruvbox-dark-medium-GsRaNv29.js +0 -1
- package/dist/app/assets/gruvbox-dark-soft-CVdnzihN.js +0 -1
- package/dist/app/assets/gruvbox-light-hard-CH1njM8p.js +0 -1
- package/dist/app/assets/gruvbox-light-medium-DRw_LuNl.js +0 -1
- package/dist/app/assets/gruvbox-light-soft-hJgmCMqR.js +0 -1
- package/dist/app/assets/hack-i7_Ulhet.js +0 -1
- package/dist/app/assets/haml-D5jkg6IW.js +0 -1
- package/dist/app/assets/handlebars-BpdQsYii.js +0 -1
- package/dist/app/assets/haskell-Df6bDoY_.js +0 -1
- package/dist/app/assets/haxe-CzTSHFRz.js +0 -1
- package/dist/app/assets/hcl-BWvSN4gD.js +0 -1
- package/dist/app/assets/hjson-D5-asLiD.js +0 -1
- package/dist/app/assets/hlsl-D3lLCCz7.js +0 -1
- package/dist/app/assets/horizon-BUw7H-hv.js +0 -1
- package/dist/app/assets/horizon-bright-CUuTKBJd.js +0 -1
- package/dist/app/assets/houston-DnULxvSX.js +0 -1
- package/dist/app/assets/html-derivative-DlHx6ybY.js +0 -1
- package/dist/app/assets/html-pp8916En.js +0 -1
- package/dist/app/assets/http-jrhK8wxY.js +0 -1
- package/dist/app/assets/hurl-irOxFIW8.js +0 -1
- package/dist/app/assets/hxml-Bvhsp5Yf.js +0 -1
- package/dist/app/assets/hy-DFXneXwc.js +0 -1
- package/dist/app/assets/imba-DGztddWO.js +0 -1
- package/dist/app/assets/index-BBYiZjoU.js +0 -238
- package/dist/app/assets/index-DU8KNBjo.css +0 -32
- package/dist/app/assets/ini-BEwlwnbL.js +0 -1
- package/dist/app/assets/java-CylS5w8V.js +0 -1
- package/dist/app/assets/javascript-wDzz0qaB.js +0 -1
- package/dist/app/assets/jinja-f2NsQr07.js +0 -1
- package/dist/app/assets/jison-wvAkD_A8.js +0 -1
- package/dist/app/assets/json-Cp-IABpG.js +0 -1
- package/dist/app/assets/json5-C9tS-k6U.js +0 -1
- package/dist/app/assets/jsonc-Des-eS-w.js +0 -1
- package/dist/app/assets/jsonl-DcaNXYhu.js +0 -1
- package/dist/app/assets/jsonnet-DFQXde-d.js +0 -1
- package/dist/app/assets/jssm-C2t-YnRu.js +0 -1
- package/dist/app/assets/jsx-g9-lgVsj.js +0 -1
- package/dist/app/assets/julia-CxzCAyBv.js +0 -1
- package/dist/app/assets/just-VxiPbLrw.js +0 -1
- package/dist/app/assets/kanagawa-dragon-CkXjmgJE.js +0 -1
- package/dist/app/assets/kanagawa-lotus-CfQXZHmo.js +0 -1
- package/dist/app/assets/kanagawa-wave-DWedfzmr.js +0 -1
- package/dist/app/assets/kdl-DV7GczEv.js +0 -1
- package/dist/app/assets/kotlin-BdnUsdx6.js +0 -1
- package/dist/app/assets/kusto-wEQ09or8.js +0 -1
- package/dist/app/assets/laserwave-DUszq2jm.js +0 -1
- package/dist/app/assets/latex-CWtU0Tv5.js +0 -1
- package/dist/app/assets/lean-BZvkOJ9d.js +0 -1
- package/dist/app/assets/less-B1dDrJ26.js +0 -1
- package/dist/app/assets/light-plus-B7mTdjB0.js +0 -1
- package/dist/app/assets/liquid-C0sCDyMI.js +0 -1
- package/dist/app/assets/llvm-DjAJT7YJ.js +0 -1
- package/dist/app/assets/log-2UxHyX5q.js +0 -1
- package/dist/app/assets/logo-BtOb2qkB.js +0 -1
- package/dist/app/assets/lua-BaeVxFsk.js +0 -1
- package/dist/app/assets/luau-C-HG3fhB.js +0 -1
- package/dist/app/assets/make-CHLpvVh8.js +0 -1
- package/dist/app/assets/markdown-Cvjx9yec.js +0 -1
- package/dist/app/assets/marko-DjSrsDqO.js +0 -1
- package/dist/app/assets/material-theme-D5KoaKCx.js +0 -1
- package/dist/app/assets/material-theme-darker-BfHTSMKl.js +0 -1
- package/dist/app/assets/material-theme-lighter-B0m2ddpp.js +0 -1
- package/dist/app/assets/material-theme-ocean-CyktbL80.js +0 -1
- package/dist/app/assets/material-theme-palenight-Csfq5Kiy.js +0 -1
- package/dist/app/assets/matlab-D7o27uSR.js +0 -1
- package/dist/app/assets/mdc-DTYItulj.js +0 -1
- package/dist/app/assets/mdx-Cmh6b_Ma.js +0 -1
- package/dist/app/assets/mermaid-mWjccvbQ.js +0 -1
- package/dist/app/assets/min-dark-CafNBF8u.js +0 -1
- package/dist/app/assets/min-light-CTRr51gU.js +0 -1
- package/dist/app/assets/mipsasm-CKIfxQSi.js +0 -1
- package/dist/app/assets/mojo-rZm6bMo-.js +0 -1
- package/dist/app/assets/monokai-D4h5O-jR.js +0 -1
- package/dist/app/assets/moonbit-_H4v1dQx.js +0 -1
- package/dist/app/assets/move-IF9eRakj.js +0 -1
- package/dist/app/assets/narrat-DRg8JJMk.js +0 -1
- package/dist/app/assets/nextflow-C-mBbutL.js +0 -1
- package/dist/app/assets/nextflow-groovy-vE_lwT2v.js +0 -1
- package/dist/app/assets/nginx-BpAMiNFr.js +0 -1
- package/dist/app/assets/night-owl-C39BiMTA.js +0 -1
- package/dist/app/assets/night-owl-light-CMTm3GFP.js +0 -1
- package/dist/app/assets/nim-BIad80T-.js +0 -1
- package/dist/app/assets/nix-CwoSXNpI.js +0 -1
- package/dist/app/assets/nord-Ddv68eIx.js +0 -1
- package/dist/app/assets/nushell-Cz2AlsmD.js +0 -1
- package/dist/app/assets/objective-c-DXmwc3jG.js +0 -1
- package/dist/app/assets/objective-cpp-CLxacb5B.js +0 -1
- package/dist/app/assets/ocaml-C0hk2d4L.js +0 -1
- package/dist/app/assets/odin-BBf5iR-q.js +0 -1
- package/dist/app/assets/one-dark-pro-DVMEJ2y_.js +0 -1
- package/dist/app/assets/one-light-C3Wv6jpd.js +0 -1
- package/dist/app/assets/openscad-C4EeE6gA.js +0 -1
- package/dist/app/assets/pascal-D93ZcfNL.js +0 -1
- package/dist/app/assets/perl-NvoQZIq0.js +0 -1
- package/dist/app/assets/php-R6g_5hLQ.js +0 -1
- package/dist/app/assets/pkl-u5AG7uiY.js +0 -1
- package/dist/app/assets/plastic-3e1v2bzS.js +0 -1
- package/dist/app/assets/plsql-ChMvpjG-.js +0 -1
- package/dist/app/assets/po-BTJTHyun.js +0 -1
- package/dist/app/assets/poimandres-CS3Unz2-.js +0 -1
- package/dist/app/assets/polar-C0HS_06l.js +0 -1
- package/dist/app/assets/postcss-CXtECtnM.js +0 -1
- package/dist/app/assets/powerquery-CEu0bR-o.js +0 -1
- package/dist/app/assets/powershell-Dpen1YoG.js +0 -1
- package/dist/app/assets/prisma-Dd19v3D-.js +0 -1
- package/dist/app/assets/prolog-CbFg5uaA.js +0 -1
- package/dist/app/assets/proto-C7zT0LnQ.js +0 -1
- package/dist/app/assets/pug-DKIMFp6K.js +0 -1
- package/dist/app/assets/puppet-BMWR74SV.js +0 -1
- package/dist/app/assets/purescript-CklMAg4u.js +0 -1
- package/dist/app/assets/python-B6aJPvgy.js +0 -1
- package/dist/app/assets/qml-3beO22l8.js +0 -1
- package/dist/app/assets/qmldir-C8lEn-DE.js +0 -1
- package/dist/app/assets/qss-IeuSbFQv.js +0 -1
- package/dist/app/assets/r-Dspwwk_N.js +0 -1
- package/dist/app/assets/racket-BqYA7rlc.js +0 -1
- package/dist/app/assets/raku-DXvB9xmW.js +0 -1
- package/dist/app/assets/razor-BDqjjVU7.js +0 -1
- package/dist/app/assets/red-bN70gL4F.js +0 -1
- package/dist/app/assets/reg-C-SQnVFl.js +0 -1
- package/dist/app/assets/regexp-CDVJQ6XC.js +0 -1
- package/dist/app/assets/rel-C3B-1QV4.js +0 -1
- package/dist/app/assets/riscv-BM1_JUlF.js +0 -1
- package/dist/app/assets/ron-D8l8udqQ.js +0 -1
- package/dist/app/assets/rose-pine-dawn-DHQR4-dF.js +0 -1
- package/dist/app/assets/rose-pine-moon-D4_iv3hh.js +0 -1
- package/dist/app/assets/rose-pine-qdsjHGoJ.js +0 -1
- package/dist/app/assets/rosmsg-BJDFO7_C.js +0 -1
- package/dist/app/assets/rst-CRjBmOyv.js +0 -1
- package/dist/app/assets/ruby-Wjq7vjNf.js +0 -1
- package/dist/app/assets/rust-B1yitclQ.js +0 -1
- package/dist/app/assets/sas-cz2c8ADy.js +0 -1
- package/dist/app/assets/sass-Cj5Yp3dK.js +0 -1
- package/dist/app/assets/scala-C151Ov-r.js +0 -1
- package/dist/app/assets/scheme-C98Dy4si.js +0 -1
- package/dist/app/assets/scss-D5BDwBP9.js +0 -1
- package/dist/app/assets/sdbl-DVxCFoDh.js +0 -1
- package/dist/app/assets/shaderlab-Dg9Lc6iA.js +0 -1
- package/dist/app/assets/shellscript-Yzrsuije.js +0 -1
- package/dist/app/assets/shellsession-BADoaaVG.js +0 -1
- package/dist/app/assets/slack-dark-BthQWCQV.js +0 -1
- package/dist/app/assets/slack-ochin-DqwNpetd.js +0 -1
- package/dist/app/assets/smalltalk-BERRCDM3.js +0 -1
- package/dist/app/assets/snazzy-light-Bw305WKR.js +0 -1
- package/dist/app/assets/solarized-dark-DXbdFlpD.js +0 -1
- package/dist/app/assets/solarized-light-L9t79GZl.js +0 -1
- package/dist/app/assets/solidity-rGO070M0.js +0 -1
- package/dist/app/assets/soy-8wufbnw4.js +0 -1
- package/dist/app/assets/sparql-rVzFXLq3.js +0 -1
- package/dist/app/assets/splunk-BtCnVYZw.js +0 -1
- package/dist/app/assets/sql-BLtJtn59.js +0 -1
- package/dist/app/assets/ssh-config-_ykCGR6B.js +0 -1
- package/dist/app/assets/stata-BH5u7GGu.js +0 -1
- package/dist/app/assets/stylus-BEDo0Tqx.js +0 -1
- package/dist/app/assets/surrealql-Bq5Q-fJD.js +0 -1
- package/dist/app/assets/svelte-Cy7k_4gC.js +0 -1
- package/dist/app/assets/swift-D82vCrfD.js +0 -1
- package/dist/app/assets/synthwave-84-CbfX1IO0.js +0 -1
- package/dist/app/assets/system-verilog-CnnmHF94.js +0 -1
- package/dist/app/assets/systemd-4A_iFExJ.js +0 -1
- package/dist/app/assets/talonscript-CkByrt1z.js +0 -1
- package/dist/app/assets/tasl-QIJgUcNo.js +0 -1
- package/dist/app/assets/tcl-dwOrl1Do.js +0 -1
- package/dist/app/assets/templ-DhtptRzy.js +0 -1
- package/dist/app/assets/terraform-BETggiCN.js +0 -1
- package/dist/app/assets/tex-idrVyKtj.js +0 -1
- package/dist/app/assets/tokyo-night-hegEt444.js +0 -1
- package/dist/app/assets/toml-vGWfd6FD.js +0 -1
- package/dist/app/assets/ts-tags-DQrlYJgV.js +0 -1
- package/dist/app/assets/tsv-B_m7g4N7.js +0 -1
- package/dist/app/assets/tsx-COt5Ahok.js +0 -1
- package/dist/app/assets/turtle-BsS91CYL.js +0 -1
- package/dist/app/assets/twig-xg9kU7Mw.js +0 -1
- package/dist/app/assets/typescript-BPQ3VLAy.js +0 -1
- package/dist/app/assets/typespec-CAFt9gP4.js +0 -1
- package/dist/app/assets/typst-DHCkPAjA.js +0 -1
- package/dist/app/assets/v-BcVCzyr7.js +0 -1
- package/dist/app/assets/vala-CsfeWuGM.js +0 -1
- package/dist/app/assets/vb-D17OF-Vu.js +0 -1
- package/dist/app/assets/verilog-BQ8w6xss.js +0 -1
- package/dist/app/assets/vesper-DU1UobuO.js +0 -1
- package/dist/app/assets/vhdl-CeAyd5Ju.js +0 -1
- package/dist/app/assets/viml-CJc9bBzg.js +0 -1
- package/dist/app/assets/vitesse-black-Bkuqu6BP.js +0 -1
- package/dist/app/assets/vitesse-dark-D0r3Knsf.js +0 -1
- package/dist/app/assets/vitesse-light-CVO1_9PV.js +0 -1
- package/dist/app/assets/vue-D2xRrEX4.js +0 -1
- package/dist/app/assets/vue-html-AaS7Mt5G.js +0 -1
- package/dist/app/assets/vue-vine-BoDAl6tE.js +0 -1
- package/dist/app/assets/vyper-CDx5xZoG.js +0 -1
- package/dist/app/assets/wasm-CG6Dc4jp.js +0 -1
- package/dist/app/assets/wasm-MzD3tlZU.js +0 -1
- package/dist/app/assets/wenyan-BV7otONQ.js +0 -1
- package/dist/app/assets/wgsl-Dx-B1_4e.js +0 -1
- package/dist/app/assets/wikitext-BhOHFoWU.js +0 -1
- package/dist/app/assets/wit-5i3qLPDT.js +0 -1
- package/dist/app/assets/wolfram-lXgVvXCa.js +0 -1
- package/dist/app/assets/xml-sdJ4AIDG.js +0 -1
- package/dist/app/assets/xsl-CtQFsRM5.js +0 -1
- package/dist/app/assets/yaml-Buea-lGh.js +0 -1
- package/dist/app/assets/zenscript-DVFEvuxE.js +0 -1
- package/dist/app/assets/zig-VOosw3JB.js +0 -1
- package/dist/app/index.html +0 -13
- package/dist/chunk-6DDCZPRP.js +0 -1474
- package/dist/chunk-HULFFF7R.js +0 -25
- package/dist/chunk-KB4MYP36.js +0 -8
- package/dist/chunk-P23NZBHE.js +0 -5130
- package/dist/chunk-TDYQG5PB.js +0 -1621
- package/dist/chunk-XU2SE4LZ.js +0 -3864
- package/dist/chunk-XXVDY7BO.js +0 -53
- package/dist/chunk-ZXPWUU3S.js +0 -110
- package/dist/dist-GBG4FGPZ.js +0 -1806
- package/dist/dist-XGPL3ARQ.js +0 -94
- package/dist/glob-RMMK6FVW-M34I5XTP.js +0 -8
- package/dist/registry-VQVHAEPP-MGYPDXYJ.js +0 -13
- package/dist/schema-SOLWPA3E-CEUVS57H.js +0 -13
- package/dist/session-Q7S3ITUV-CECGQJC5.js +0 -18
- package/dist/storage-YSEEBFV7-N75L4HBF.js +0 -28
package/dist/chunk-TDYQG5PB.js
DELETED
|
@@ -1,1621 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
MessageID,
|
|
4
|
-
PartID,
|
|
5
|
-
SessionID
|
|
6
|
-
} from "./chunk-ZXPWUU3S.js";
|
|
7
|
-
import {
|
|
8
|
-
Log,
|
|
9
|
-
NamedError,
|
|
10
|
-
NotFoundError,
|
|
11
|
-
ProjectID,
|
|
12
|
-
join
|
|
13
|
-
} from "./chunk-6DDCZPRP.js";
|
|
14
|
-
import {
|
|
15
|
-
withStatics
|
|
16
|
-
} from "./chunk-KB4MYP36.js";
|
|
17
|
-
|
|
18
|
-
// ../agent/dist/chunk-FSDC4TEW.js
|
|
19
|
-
import { EventEmitter as EventEmitter2 } from "events";
|
|
20
|
-
import z6 from "zod";
|
|
21
|
-
import z from "zod";
|
|
22
|
-
import { Decimal } from "decimal.js";
|
|
23
|
-
import z5 from "zod";
|
|
24
|
-
import { EventEmitter } from "events";
|
|
25
|
-
import z4 from "zod";
|
|
26
|
-
import { APICallError, convertToModelMessages, LoadAPIKeyError } from "ai";
|
|
27
|
-
import z2 from "zod";
|
|
28
|
-
import { STATUS_CODES } from "http";
|
|
29
|
-
import { Schema } from "effect";
|
|
30
|
-
import z3 from "zod";
|
|
31
|
-
var Slug;
|
|
32
|
-
((Slug2) => {
|
|
33
|
-
const ADJECTIVES = [
|
|
34
|
-
"brave",
|
|
35
|
-
"calm",
|
|
36
|
-
"clever",
|
|
37
|
-
"cosmic",
|
|
38
|
-
"crisp",
|
|
39
|
-
"curious",
|
|
40
|
-
"eager",
|
|
41
|
-
"gentle",
|
|
42
|
-
"glowing",
|
|
43
|
-
"happy",
|
|
44
|
-
"hidden",
|
|
45
|
-
"jolly",
|
|
46
|
-
"kind",
|
|
47
|
-
"lucky",
|
|
48
|
-
"mighty",
|
|
49
|
-
"misty",
|
|
50
|
-
"neon",
|
|
51
|
-
"nimble",
|
|
52
|
-
"playful",
|
|
53
|
-
"proud",
|
|
54
|
-
"quick",
|
|
55
|
-
"quiet",
|
|
56
|
-
"shiny",
|
|
57
|
-
"silent",
|
|
58
|
-
"stellar",
|
|
59
|
-
"sunny",
|
|
60
|
-
"swift",
|
|
61
|
-
"tidy",
|
|
62
|
-
"witty"
|
|
63
|
-
];
|
|
64
|
-
const NOUNS = [
|
|
65
|
-
"cabin",
|
|
66
|
-
"cactus",
|
|
67
|
-
"canyon",
|
|
68
|
-
"circuit",
|
|
69
|
-
"comet",
|
|
70
|
-
"eagle",
|
|
71
|
-
"engine",
|
|
72
|
-
"falcon",
|
|
73
|
-
"forest",
|
|
74
|
-
"garden",
|
|
75
|
-
"harbor",
|
|
76
|
-
"island",
|
|
77
|
-
"knight",
|
|
78
|
-
"lagoon",
|
|
79
|
-
"meadow",
|
|
80
|
-
"moon",
|
|
81
|
-
"mountain",
|
|
82
|
-
"nebula",
|
|
83
|
-
"orchid",
|
|
84
|
-
"otter",
|
|
85
|
-
"panda",
|
|
86
|
-
"pixel",
|
|
87
|
-
"planet",
|
|
88
|
-
"river",
|
|
89
|
-
"rocket",
|
|
90
|
-
"sailor",
|
|
91
|
-
"squid",
|
|
92
|
-
"star",
|
|
93
|
-
"tiger",
|
|
94
|
-
"wizard",
|
|
95
|
-
"wolf"
|
|
96
|
-
];
|
|
97
|
-
function create() {
|
|
98
|
-
return [
|
|
99
|
-
ADJECTIVES[Math.floor(Math.random() * ADJECTIVES.length)],
|
|
100
|
-
NOUNS[Math.floor(Math.random() * NOUNS.length)]
|
|
101
|
-
].join("-");
|
|
102
|
-
}
|
|
103
|
-
Slug2.create = create;
|
|
104
|
-
})(Slug || (Slug = {}));
|
|
105
|
-
var Installation;
|
|
106
|
-
((Installation2) => {
|
|
107
|
-
Installation2.VERSION = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local";
|
|
108
|
-
Installation2.CHANNEL = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local";
|
|
109
|
-
Installation2.USER_AGENT = `claude-cli/2.1.77`;
|
|
110
|
-
function isPreview() {
|
|
111
|
-
return Installation2.CHANNEL !== "latest";
|
|
112
|
-
}
|
|
113
|
-
Installation2.isPreview = isPreview;
|
|
114
|
-
function isLocal() {
|
|
115
|
-
return Installation2.CHANNEL === "local";
|
|
116
|
-
}
|
|
117
|
-
Installation2.isLocal = isLocal;
|
|
118
|
-
Installation2.Info = z.object({
|
|
119
|
-
version: z.string(),
|
|
120
|
-
latest: z.string()
|
|
121
|
-
}).meta({ ref: "InstallationInfo" });
|
|
122
|
-
})(Installation || (Installation = {}));
|
|
123
|
-
var LSP;
|
|
124
|
-
((LSP2) => {
|
|
125
|
-
LSP2.Range = z2.object({
|
|
126
|
-
start: z2.object({
|
|
127
|
-
line: z2.number(),
|
|
128
|
-
character: z2.number()
|
|
129
|
-
}),
|
|
130
|
-
end: z2.object({
|
|
131
|
-
line: z2.number(),
|
|
132
|
-
character: z2.number()
|
|
133
|
-
})
|
|
134
|
-
}).meta({ ref: "LSPRange" });
|
|
135
|
-
LSP2.Diagnostic = {
|
|
136
|
-
pretty(d) {
|
|
137
|
-
return `${d.range.start.line}:${d.range.start.character} ${d.severity === 1 ? "error" : "warning"}: ${d.message}`;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
async function init() {
|
|
141
|
-
}
|
|
142
|
-
LSP2.init = init;
|
|
143
|
-
async function touchFile(_filepath, _wait) {
|
|
144
|
-
}
|
|
145
|
-
LSP2.touchFile = touchFile;
|
|
146
|
-
async function diagnostics() {
|
|
147
|
-
return /* @__PURE__ */ new Map();
|
|
148
|
-
}
|
|
149
|
-
LSP2.diagnostics = diagnostics;
|
|
150
|
-
async function hasClients(_file) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
LSP2.hasClients = hasClients;
|
|
154
|
-
async function definition(_position) {
|
|
155
|
-
return [];
|
|
156
|
-
}
|
|
157
|
-
LSP2.definition = definition;
|
|
158
|
-
async function references(_position) {
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
LSP2.references = references;
|
|
162
|
-
async function hover(_position) {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
LSP2.hover = hover;
|
|
166
|
-
async function documentSymbol(_uri) {
|
|
167
|
-
return [];
|
|
168
|
-
}
|
|
169
|
-
LSP2.documentSymbol = documentSymbol;
|
|
170
|
-
async function workspaceSymbol(_query) {
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
|
-
LSP2.workspaceSymbol = workspaceSymbol;
|
|
174
|
-
async function implementation(_position) {
|
|
175
|
-
return [];
|
|
176
|
-
}
|
|
177
|
-
LSP2.implementation = implementation;
|
|
178
|
-
async function prepareCallHierarchy(_position) {
|
|
179
|
-
return [];
|
|
180
|
-
}
|
|
181
|
-
LSP2.prepareCallHierarchy = prepareCallHierarchy;
|
|
182
|
-
async function incomingCalls(_position) {
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
LSP2.incomingCalls = incomingCalls;
|
|
186
|
-
async function outgoingCalls(_position) {
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
189
|
-
LSP2.outgoingCalls = outgoingCalls;
|
|
190
|
-
})(LSP || (LSP = {}));
|
|
191
|
-
function fn(schema, cb) {
|
|
192
|
-
const result = (input) => {
|
|
193
|
-
const parsed = schema.parse(input);
|
|
194
|
-
return cb(parsed);
|
|
195
|
-
};
|
|
196
|
-
result.force = (input) => cb(input);
|
|
197
|
-
result.schema = schema;
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
function iife(fn2) {
|
|
201
|
-
return fn2();
|
|
202
|
-
}
|
|
203
|
-
function defer(fn2) {
|
|
204
|
-
return {
|
|
205
|
-
[Symbol.dispose]() {
|
|
206
|
-
fn2();
|
|
207
|
-
},
|
|
208
|
-
[Symbol.asyncDispose]() {
|
|
209
|
-
return Promise.resolve(fn2());
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
var Token;
|
|
214
|
-
((Token2) => {
|
|
215
|
-
const CHARS_PER_TOKEN = 4;
|
|
216
|
-
function estimate(input) {
|
|
217
|
-
return Math.max(0, Math.round((input || "").length / CHARS_PER_TOKEN));
|
|
218
|
-
}
|
|
219
|
-
Token2.estimate = estimate;
|
|
220
|
-
})(Token || (Token = {}));
|
|
221
|
-
var ProviderError;
|
|
222
|
-
((ProviderError2) => {
|
|
223
|
-
const OVERFLOW_PATTERNS = [
|
|
224
|
-
/prompt is too long/i,
|
|
225
|
-
// Anthropic
|
|
226
|
-
/input is too long for requested model/i,
|
|
227
|
-
// Amazon Bedrock
|
|
228
|
-
/exceeds the context window/i,
|
|
229
|
-
// OpenAI (Completions + Responses API message text)
|
|
230
|
-
/input token count.*exceeds the maximum/i,
|
|
231
|
-
// Google (Gemini)
|
|
232
|
-
/maximum prompt length is \d+/i,
|
|
233
|
-
// xAI (Grok)
|
|
234
|
-
/reduce the length of the messages/i,
|
|
235
|
-
// Groq
|
|
236
|
-
/maximum context length is \d+ tokens/i,
|
|
237
|
-
// OpenRouter, DeepSeek
|
|
238
|
-
/exceeds the limit of \d+/i,
|
|
239
|
-
// GitHub Copilot
|
|
240
|
-
/exceeds the available context size/i,
|
|
241
|
-
// llama.cpp server
|
|
242
|
-
/greater than the context length/i,
|
|
243
|
-
// LM Studio
|
|
244
|
-
/context window exceeds limit/i,
|
|
245
|
-
// MiniMax
|
|
246
|
-
/exceeded model token limit/i,
|
|
247
|
-
// Kimi For Coding, Moonshot
|
|
248
|
-
/context[_ ]length[_ ]exceeded/i,
|
|
249
|
-
// Generic fallback
|
|
250
|
-
/request entity too large/i
|
|
251
|
-
// HTTP 413
|
|
252
|
-
];
|
|
253
|
-
function isOpenAiErrorRetryable(e) {
|
|
254
|
-
const status = e.statusCode;
|
|
255
|
-
if (!status) return e.isRetryable;
|
|
256
|
-
return status === 404 || e.isRetryable;
|
|
257
|
-
}
|
|
258
|
-
function isOverflow(message2) {
|
|
259
|
-
if (OVERFLOW_PATTERNS.some((p) => p.test(message2))) return true;
|
|
260
|
-
return /^4(00|13)\s*(status code)?\s*\(no body\)/i.test(message2);
|
|
261
|
-
}
|
|
262
|
-
function message(providerID, e) {
|
|
263
|
-
return iife(() => {
|
|
264
|
-
const msg = e.message;
|
|
265
|
-
if (msg === "") {
|
|
266
|
-
if (e.responseBody) return e.responseBody;
|
|
267
|
-
if (e.statusCode) {
|
|
268
|
-
const err = STATUS_CODES[e.statusCode];
|
|
269
|
-
if (err) return err;
|
|
270
|
-
}
|
|
271
|
-
return "Unknown error";
|
|
272
|
-
}
|
|
273
|
-
if (!e.responseBody || e.statusCode && msg !== STATUS_CODES[e.statusCode]) {
|
|
274
|
-
return msg;
|
|
275
|
-
}
|
|
276
|
-
try {
|
|
277
|
-
const body = JSON.parse(e.responseBody);
|
|
278
|
-
const errMsg = body.message || body.error || body.error?.message;
|
|
279
|
-
if (errMsg && typeof errMsg === "string") {
|
|
280
|
-
return `${msg}: ${errMsg}`;
|
|
281
|
-
}
|
|
282
|
-
} catch {
|
|
283
|
-
}
|
|
284
|
-
if (/^\s*<!doctype|^\s*<html/i.test(e.responseBody)) {
|
|
285
|
-
if (e.statusCode === 401) {
|
|
286
|
-
return "Unauthorized: request was blocked by a gateway or proxy. Your authentication token may be missing or expired \u2014 try running `opencode auth login <your provider URL>` to re-authenticate.";
|
|
287
|
-
}
|
|
288
|
-
if (e.statusCode === 403) {
|
|
289
|
-
return "Forbidden: request was blocked by a gateway or proxy. You may not have permission to access this resource \u2014 check your account and provider settings.";
|
|
290
|
-
}
|
|
291
|
-
return msg;
|
|
292
|
-
}
|
|
293
|
-
return `${msg}: ${e.responseBody}`;
|
|
294
|
-
}).trim();
|
|
295
|
-
}
|
|
296
|
-
function json(input) {
|
|
297
|
-
if (typeof input === "string") {
|
|
298
|
-
try {
|
|
299
|
-
const result = JSON.parse(input);
|
|
300
|
-
if (result && typeof result === "object") return result;
|
|
301
|
-
return void 0;
|
|
302
|
-
} catch {
|
|
303
|
-
return void 0;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
if (typeof input === "object" && input !== null) {
|
|
307
|
-
return input;
|
|
308
|
-
}
|
|
309
|
-
return void 0;
|
|
310
|
-
}
|
|
311
|
-
function parseStreamError(input) {
|
|
312
|
-
const body = json(input);
|
|
313
|
-
if (!body) return;
|
|
314
|
-
const responseBody = JSON.stringify(body);
|
|
315
|
-
if (body.type !== "error") return;
|
|
316
|
-
switch (body?.error?.code) {
|
|
317
|
-
case "context_length_exceeded":
|
|
318
|
-
return {
|
|
319
|
-
type: "context_overflow",
|
|
320
|
-
message: "Input exceeds context window of this model",
|
|
321
|
-
responseBody
|
|
322
|
-
};
|
|
323
|
-
case "insufficient_quota":
|
|
324
|
-
return {
|
|
325
|
-
type: "api_error",
|
|
326
|
-
message: "Quota exceeded. Check your plan and billing details.",
|
|
327
|
-
isRetryable: false,
|
|
328
|
-
responseBody
|
|
329
|
-
};
|
|
330
|
-
case "usage_not_included":
|
|
331
|
-
return {
|
|
332
|
-
type: "api_error",
|
|
333
|
-
message: "To use Codex with your ChatGPT plan, upgrade to Plus: https://chatgpt.com/explore/plus.",
|
|
334
|
-
isRetryable: false,
|
|
335
|
-
responseBody
|
|
336
|
-
};
|
|
337
|
-
case "invalid_prompt":
|
|
338
|
-
return {
|
|
339
|
-
type: "api_error",
|
|
340
|
-
message: typeof body?.error?.message === "string" ? body?.error?.message : "Invalid prompt.",
|
|
341
|
-
isRetryable: false,
|
|
342
|
-
responseBody
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
ProviderError2.parseStreamError = parseStreamError;
|
|
347
|
-
function parseAPICallError(input) {
|
|
348
|
-
const m = message(input.providerID, input.error);
|
|
349
|
-
if (isOverflow(m) || input.error.statusCode === 413) {
|
|
350
|
-
return {
|
|
351
|
-
type: "context_overflow",
|
|
352
|
-
message: m,
|
|
353
|
-
responseBody: input.error.responseBody
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
const metadata = input.error.url ? { url: input.error.url } : void 0;
|
|
357
|
-
return {
|
|
358
|
-
type: "api_error",
|
|
359
|
-
message: m,
|
|
360
|
-
statusCode: input.error.statusCode,
|
|
361
|
-
isRetryable: input.providerID.startsWith("openai") ? isOpenAiErrorRetryable(input.error) : input.error.isRetryable,
|
|
362
|
-
responseHeaders: input.error.responseHeaders,
|
|
363
|
-
responseBody: input.error.responseBody,
|
|
364
|
-
metadata
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
ProviderError2.parseAPICallError = parseAPICallError;
|
|
368
|
-
})(ProviderError || (ProviderError = {}));
|
|
369
|
-
var providerIdSchema = Schema.String.pipe(Schema.brand("ProviderID"));
|
|
370
|
-
var ProviderID = providerIdSchema.pipe(
|
|
371
|
-
withStatics((schema) => ({
|
|
372
|
-
make: (id) => schema.makeUnsafe(id),
|
|
373
|
-
zod: z3.string().pipe(z3.custom()),
|
|
374
|
-
// Well-known providers
|
|
375
|
-
opencode: schema.makeUnsafe("opencode"),
|
|
376
|
-
anthropic: schema.makeUnsafe("anthropic"),
|
|
377
|
-
openai: schema.makeUnsafe("openai"),
|
|
378
|
-
google: schema.makeUnsafe("google"),
|
|
379
|
-
googleVertex: schema.makeUnsafe("google-vertex"),
|
|
380
|
-
githubCopilot: schema.makeUnsafe("github-copilot"),
|
|
381
|
-
githubCopilotEnterprise: schema.makeUnsafe("github-copilot-enterprise"),
|
|
382
|
-
amazonBedrock: schema.makeUnsafe("amazon-bedrock"),
|
|
383
|
-
azure: schema.makeUnsafe("azure"),
|
|
384
|
-
openrouter: schema.makeUnsafe("openrouter"),
|
|
385
|
-
mistral: schema.makeUnsafe("mistral")
|
|
386
|
-
}))
|
|
387
|
-
);
|
|
388
|
-
var modelIdSchema = Schema.String.pipe(Schema.brand("ModelID"));
|
|
389
|
-
var ModelID = modelIdSchema.pipe(
|
|
390
|
-
withStatics((schema) => ({
|
|
391
|
-
make: (id) => schema.makeUnsafe(id),
|
|
392
|
-
zod: z3.string().pipe(z3.custom())
|
|
393
|
-
}))
|
|
394
|
-
);
|
|
395
|
-
var MessageV2;
|
|
396
|
-
((MessageV22) => {
|
|
397
|
-
function isMedia(mime) {
|
|
398
|
-
return mime.startsWith("image/") || mime === "application/pdf";
|
|
399
|
-
}
|
|
400
|
-
MessageV22.isMedia = isMedia;
|
|
401
|
-
MessageV22.OutputLengthError = NamedError.create("MessageOutputLengthError", z4.object({}));
|
|
402
|
-
MessageV22.AbortedError = NamedError.create("MessageAbortedError", z4.object({ message: z4.string() }));
|
|
403
|
-
MessageV22.StructuredOutputError = NamedError.create(
|
|
404
|
-
"StructuredOutputError",
|
|
405
|
-
z4.object({
|
|
406
|
-
message: z4.string(),
|
|
407
|
-
retries: z4.number()
|
|
408
|
-
})
|
|
409
|
-
);
|
|
410
|
-
MessageV22.AuthError = NamedError.create(
|
|
411
|
-
"ProviderAuthError",
|
|
412
|
-
z4.object({
|
|
413
|
-
providerID: z4.string(),
|
|
414
|
-
message: z4.string()
|
|
415
|
-
})
|
|
416
|
-
);
|
|
417
|
-
MessageV22.APIError = NamedError.create(
|
|
418
|
-
"APIError",
|
|
419
|
-
z4.object({
|
|
420
|
-
message: z4.string(),
|
|
421
|
-
statusCode: z4.number().optional(),
|
|
422
|
-
isRetryable: z4.boolean(),
|
|
423
|
-
responseHeaders: z4.record(z4.string(), z4.string()).optional(),
|
|
424
|
-
responseBody: z4.string().optional(),
|
|
425
|
-
metadata: z4.record(z4.string(), z4.string()).optional()
|
|
426
|
-
})
|
|
427
|
-
);
|
|
428
|
-
MessageV22.ContextOverflowError = NamedError.create(
|
|
429
|
-
"ContextOverflowError",
|
|
430
|
-
z4.object({ message: z4.string(), responseBody: z4.string().optional() })
|
|
431
|
-
);
|
|
432
|
-
MessageV22.OutputFormatText = z4.object({
|
|
433
|
-
type: z4.literal("text")
|
|
434
|
-
}).meta({
|
|
435
|
-
ref: "OutputFormatText"
|
|
436
|
-
});
|
|
437
|
-
MessageV22.OutputFormatJsonSchema = z4.object({
|
|
438
|
-
type: z4.literal("json_schema"),
|
|
439
|
-
schema: z4.record(z4.string(), z4.any()).meta({ ref: "JSONSchema" }),
|
|
440
|
-
retryCount: z4.number().int().min(0).default(2)
|
|
441
|
-
}).meta({
|
|
442
|
-
ref: "OutputFormatJsonSchema"
|
|
443
|
-
});
|
|
444
|
-
MessageV22.Format = z4.discriminatedUnion("type", [MessageV22.OutputFormatText, MessageV22.OutputFormatJsonSchema]).meta({
|
|
445
|
-
ref: "OutputFormat"
|
|
446
|
-
});
|
|
447
|
-
const PartBase = z4.object({
|
|
448
|
-
id: PartID.zod,
|
|
449
|
-
sessionID: SessionID.zod,
|
|
450
|
-
messageID: MessageID.zod
|
|
451
|
-
});
|
|
452
|
-
MessageV22.FileDiff = z4.object({
|
|
453
|
-
file: z4.string(),
|
|
454
|
-
before: z4.string(),
|
|
455
|
-
after: z4.string(),
|
|
456
|
-
additions: z4.number(),
|
|
457
|
-
deletions: z4.number(),
|
|
458
|
-
status: z4.enum(["added", "deleted", "modified"]).optional()
|
|
459
|
-
}).meta({
|
|
460
|
-
ref: "FileDiff"
|
|
461
|
-
});
|
|
462
|
-
MessageV22.PatchPart = PartBase.extend({
|
|
463
|
-
type: z4.literal("patch"),
|
|
464
|
-
hash: z4.string(),
|
|
465
|
-
files: z4.string().array()
|
|
466
|
-
}).meta({
|
|
467
|
-
ref: "PatchPart"
|
|
468
|
-
});
|
|
469
|
-
MessageV22.TextPart = PartBase.extend({
|
|
470
|
-
type: z4.literal("text"),
|
|
471
|
-
text: z4.string(),
|
|
472
|
-
synthetic: z4.boolean().optional(),
|
|
473
|
-
ignored: z4.boolean().optional(),
|
|
474
|
-
time: z4.object({
|
|
475
|
-
start: z4.number(),
|
|
476
|
-
end: z4.number().optional()
|
|
477
|
-
}).optional(),
|
|
478
|
-
metadata: z4.record(z4.string(), z4.any()).optional()
|
|
479
|
-
}).meta({
|
|
480
|
-
ref: "TextPart"
|
|
481
|
-
});
|
|
482
|
-
MessageV22.ReasoningPart = PartBase.extend({
|
|
483
|
-
type: z4.literal("reasoning"),
|
|
484
|
-
text: z4.string(),
|
|
485
|
-
metadata: z4.record(z4.string(), z4.any()).optional(),
|
|
486
|
-
time: z4.object({
|
|
487
|
-
start: z4.number(),
|
|
488
|
-
end: z4.number().optional()
|
|
489
|
-
})
|
|
490
|
-
}).meta({
|
|
491
|
-
ref: "ReasoningPart"
|
|
492
|
-
});
|
|
493
|
-
const FilePartSourceBase = z4.object({
|
|
494
|
-
text: z4.object({
|
|
495
|
-
value: z4.string(),
|
|
496
|
-
start: z4.number().int(),
|
|
497
|
-
end: z4.number().int()
|
|
498
|
-
}).meta({
|
|
499
|
-
ref: "FilePartSourceText"
|
|
500
|
-
})
|
|
501
|
-
});
|
|
502
|
-
MessageV22.FileSource = FilePartSourceBase.extend({
|
|
503
|
-
type: z4.literal("file"),
|
|
504
|
-
path: z4.string()
|
|
505
|
-
}).meta({
|
|
506
|
-
ref: "FileSource"
|
|
507
|
-
});
|
|
508
|
-
MessageV22.SymbolSource = FilePartSourceBase.extend({
|
|
509
|
-
type: z4.literal("symbol"),
|
|
510
|
-
path: z4.string(),
|
|
511
|
-
range: LSP.Range,
|
|
512
|
-
name: z4.string(),
|
|
513
|
-
kind: z4.number().int()
|
|
514
|
-
}).meta({
|
|
515
|
-
ref: "SymbolSource"
|
|
516
|
-
});
|
|
517
|
-
MessageV22.ResourceSource = FilePartSourceBase.extend({
|
|
518
|
-
type: z4.literal("resource"),
|
|
519
|
-
clientName: z4.string(),
|
|
520
|
-
uri: z4.string()
|
|
521
|
-
}).meta({
|
|
522
|
-
ref: "ResourceSource"
|
|
523
|
-
});
|
|
524
|
-
MessageV22.FilePartSource = z4.discriminatedUnion("type", [MessageV22.FileSource, MessageV22.SymbolSource, MessageV22.ResourceSource]).meta({
|
|
525
|
-
ref: "FilePartSource"
|
|
526
|
-
});
|
|
527
|
-
MessageV22.FilePart = PartBase.extend({
|
|
528
|
-
type: z4.literal("file"),
|
|
529
|
-
mime: z4.string(),
|
|
530
|
-
filename: z4.string().optional(),
|
|
531
|
-
url: z4.string(),
|
|
532
|
-
source: MessageV22.FilePartSource.optional()
|
|
533
|
-
}).meta({
|
|
534
|
-
ref: "FilePart"
|
|
535
|
-
});
|
|
536
|
-
MessageV22.AgentPart = PartBase.extend({
|
|
537
|
-
type: z4.literal("agent"),
|
|
538
|
-
name: z4.string(),
|
|
539
|
-
source: z4.object({
|
|
540
|
-
value: z4.string(),
|
|
541
|
-
start: z4.number().int(),
|
|
542
|
-
end: z4.number().int()
|
|
543
|
-
}).optional()
|
|
544
|
-
}).meta({
|
|
545
|
-
ref: "AgentPart"
|
|
546
|
-
});
|
|
547
|
-
MessageV22.CompactionPart = PartBase.extend({
|
|
548
|
-
type: z4.literal("compaction"),
|
|
549
|
-
auto: z4.boolean(),
|
|
550
|
-
overflow: z4.boolean().optional()
|
|
551
|
-
}).meta({
|
|
552
|
-
ref: "CompactionPart"
|
|
553
|
-
});
|
|
554
|
-
MessageV22.SubtaskPart = PartBase.extend({
|
|
555
|
-
type: z4.literal("subtask"),
|
|
556
|
-
prompt: z4.string(),
|
|
557
|
-
description: z4.string(),
|
|
558
|
-
agent: z4.string(),
|
|
559
|
-
model: z4.object({
|
|
560
|
-
providerID: ProviderID.zod,
|
|
561
|
-
modelID: ModelID.zod
|
|
562
|
-
}).optional(),
|
|
563
|
-
command: z4.string().optional()
|
|
564
|
-
}).meta({
|
|
565
|
-
ref: "SubtaskPart"
|
|
566
|
-
});
|
|
567
|
-
MessageV22.RetryPart = PartBase.extend({
|
|
568
|
-
type: z4.literal("retry"),
|
|
569
|
-
attempt: z4.number(),
|
|
570
|
-
error: MessageV22.APIError.Schema,
|
|
571
|
-
time: z4.object({
|
|
572
|
-
created: z4.number()
|
|
573
|
-
})
|
|
574
|
-
}).meta({
|
|
575
|
-
ref: "RetryPart"
|
|
576
|
-
});
|
|
577
|
-
MessageV22.StepStartPart = PartBase.extend({
|
|
578
|
-
type: z4.literal("step-start")
|
|
579
|
-
}).meta({
|
|
580
|
-
ref: "StepStartPart"
|
|
581
|
-
});
|
|
582
|
-
MessageV22.StepFinishPart = PartBase.extend({
|
|
583
|
-
type: z4.literal("step-finish"),
|
|
584
|
-
reason: z4.string(),
|
|
585
|
-
cost: z4.number(),
|
|
586
|
-
tokens: z4.object({
|
|
587
|
-
total: z4.number().optional(),
|
|
588
|
-
input: z4.number(),
|
|
589
|
-
output: z4.number(),
|
|
590
|
-
reasoning: z4.number(),
|
|
591
|
-
cache: z4.object({
|
|
592
|
-
read: z4.number(),
|
|
593
|
-
write: z4.number()
|
|
594
|
-
})
|
|
595
|
-
})
|
|
596
|
-
}).meta({
|
|
597
|
-
ref: "StepFinishPart"
|
|
598
|
-
});
|
|
599
|
-
MessageV22.ToolStatePending = z4.object({
|
|
600
|
-
status: z4.literal("pending"),
|
|
601
|
-
input: z4.record(z4.string(), z4.any()),
|
|
602
|
-
raw: z4.string()
|
|
603
|
-
}).meta({
|
|
604
|
-
ref: "ToolStatePending"
|
|
605
|
-
});
|
|
606
|
-
MessageV22.ToolStateRunning = z4.object({
|
|
607
|
-
status: z4.literal("running"),
|
|
608
|
-
input: z4.record(z4.string(), z4.any()),
|
|
609
|
-
title: z4.string().optional(),
|
|
610
|
-
metadata: z4.record(z4.string(), z4.any()).optional(),
|
|
611
|
-
time: z4.object({
|
|
612
|
-
start: z4.number()
|
|
613
|
-
})
|
|
614
|
-
}).meta({
|
|
615
|
-
ref: "ToolStateRunning"
|
|
616
|
-
});
|
|
617
|
-
MessageV22.ToolStateCompleted = z4.object({
|
|
618
|
-
status: z4.literal("completed"),
|
|
619
|
-
input: z4.record(z4.string(), z4.any()),
|
|
620
|
-
output: z4.string(),
|
|
621
|
-
title: z4.string(),
|
|
622
|
-
metadata: z4.record(z4.string(), z4.any()),
|
|
623
|
-
time: z4.object({
|
|
624
|
-
start: z4.number(),
|
|
625
|
-
end: z4.number(),
|
|
626
|
-
compacted: z4.number().optional()
|
|
627
|
-
}),
|
|
628
|
-
attachments: MessageV22.FilePart.array().optional()
|
|
629
|
-
}).meta({
|
|
630
|
-
ref: "ToolStateCompleted"
|
|
631
|
-
});
|
|
632
|
-
MessageV22.ToolStateError = z4.object({
|
|
633
|
-
status: z4.literal("error"),
|
|
634
|
-
input: z4.record(z4.string(), z4.any()),
|
|
635
|
-
error: z4.string(),
|
|
636
|
-
metadata: z4.record(z4.string(), z4.any()).optional(),
|
|
637
|
-
time: z4.object({
|
|
638
|
-
start: z4.number(),
|
|
639
|
-
end: z4.number()
|
|
640
|
-
})
|
|
641
|
-
}).meta({
|
|
642
|
-
ref: "ToolStateError"
|
|
643
|
-
});
|
|
644
|
-
MessageV22.ToolState = z4.discriminatedUnion("status", [MessageV22.ToolStatePending, MessageV22.ToolStateRunning, MessageV22.ToolStateCompleted, MessageV22.ToolStateError]).meta({
|
|
645
|
-
ref: "ToolState"
|
|
646
|
-
});
|
|
647
|
-
MessageV22.ToolPart = PartBase.extend({
|
|
648
|
-
type: z4.literal("tool"),
|
|
649
|
-
callID: z4.string(),
|
|
650
|
-
tool: z4.string(),
|
|
651
|
-
state: MessageV22.ToolState,
|
|
652
|
-
metadata: z4.record(z4.string(), z4.any()).optional()
|
|
653
|
-
}).meta({
|
|
654
|
-
ref: "ToolPart"
|
|
655
|
-
});
|
|
656
|
-
const Base = z4.object({
|
|
657
|
-
id: MessageID.zod,
|
|
658
|
-
sessionID: SessionID.zod
|
|
659
|
-
});
|
|
660
|
-
MessageV22.User = Base.extend({
|
|
661
|
-
role: z4.literal("user"),
|
|
662
|
-
time: z4.object({
|
|
663
|
-
created: z4.number()
|
|
664
|
-
}),
|
|
665
|
-
format: MessageV22.Format.optional(),
|
|
666
|
-
summary: z4.object({
|
|
667
|
-
title: z4.string().optional(),
|
|
668
|
-
body: z4.string().optional(),
|
|
669
|
-
diffs: MessageV22.FileDiff.array()
|
|
670
|
-
}).optional(),
|
|
671
|
-
agent: z4.string(),
|
|
672
|
-
model: z4.object({
|
|
673
|
-
providerID: ProviderID.zod,
|
|
674
|
-
modelID: ModelID.zod
|
|
675
|
-
}),
|
|
676
|
-
system: z4.string().optional(),
|
|
677
|
-
tools: z4.record(z4.string(), z4.boolean()).optional(),
|
|
678
|
-
variant: z4.string().optional()
|
|
679
|
-
}).meta({
|
|
680
|
-
ref: "UserMessage"
|
|
681
|
-
});
|
|
682
|
-
MessageV22.Part = z4.discriminatedUnion("type", [
|
|
683
|
-
MessageV22.TextPart,
|
|
684
|
-
MessageV22.SubtaskPart,
|
|
685
|
-
MessageV22.ReasoningPart,
|
|
686
|
-
MessageV22.FilePart,
|
|
687
|
-
MessageV22.ToolPart,
|
|
688
|
-
MessageV22.StepStartPart,
|
|
689
|
-
MessageV22.StepFinishPart,
|
|
690
|
-
MessageV22.PatchPart,
|
|
691
|
-
MessageV22.AgentPart,
|
|
692
|
-
MessageV22.RetryPart,
|
|
693
|
-
MessageV22.CompactionPart
|
|
694
|
-
]).meta({
|
|
695
|
-
ref: "Part"
|
|
696
|
-
});
|
|
697
|
-
MessageV22.Assistant = Base.extend({
|
|
698
|
-
role: z4.literal("assistant"),
|
|
699
|
-
time: z4.object({
|
|
700
|
-
created: z4.number(),
|
|
701
|
-
completed: z4.number().optional()
|
|
702
|
-
}),
|
|
703
|
-
error: z4.discriminatedUnion("name", [
|
|
704
|
-
MessageV22.AuthError.Schema,
|
|
705
|
-
NamedError.Unknown.Schema,
|
|
706
|
-
MessageV22.OutputLengthError.Schema,
|
|
707
|
-
MessageV22.AbortedError.Schema,
|
|
708
|
-
MessageV22.StructuredOutputError.Schema,
|
|
709
|
-
MessageV22.ContextOverflowError.Schema,
|
|
710
|
-
MessageV22.APIError.Schema
|
|
711
|
-
]).optional(),
|
|
712
|
-
parentID: MessageID.zod,
|
|
713
|
-
modelID: ModelID.zod,
|
|
714
|
-
providerID: ProviderID.zod,
|
|
715
|
-
/**
|
|
716
|
-
* @deprecated
|
|
717
|
-
*/
|
|
718
|
-
mode: z4.string(),
|
|
719
|
-
agent: z4.string(),
|
|
720
|
-
path: z4.object({
|
|
721
|
-
cwd: z4.string(),
|
|
722
|
-
root: z4.string()
|
|
723
|
-
}),
|
|
724
|
-
summary: z4.boolean().optional(),
|
|
725
|
-
cost: z4.number(),
|
|
726
|
-
tokens: z4.object({
|
|
727
|
-
total: z4.number().optional(),
|
|
728
|
-
input: z4.number(),
|
|
729
|
-
output: z4.number(),
|
|
730
|
-
reasoning: z4.number(),
|
|
731
|
-
cache: z4.object({
|
|
732
|
-
read: z4.number(),
|
|
733
|
-
write: z4.number()
|
|
734
|
-
})
|
|
735
|
-
}),
|
|
736
|
-
structured: z4.any().optional(),
|
|
737
|
-
variant: z4.string().optional(),
|
|
738
|
-
finish: z4.string().optional()
|
|
739
|
-
}).meta({
|
|
740
|
-
ref: "AssistantMessage"
|
|
741
|
-
});
|
|
742
|
-
MessageV22.Info = z4.discriminatedUnion("role", [MessageV22.User, MessageV22.Assistant]).meta({
|
|
743
|
-
ref: "Message"
|
|
744
|
-
});
|
|
745
|
-
MessageV22.WithParts = z4.object({
|
|
746
|
-
info: MessageV22.Info,
|
|
747
|
-
parts: z4.array(MessageV22.Part)
|
|
748
|
-
});
|
|
749
|
-
const Cursor = z4.object({
|
|
750
|
-
id: MessageID.zod,
|
|
751
|
-
time: z4.number()
|
|
752
|
-
});
|
|
753
|
-
MessageV22.cursor = {
|
|
754
|
-
encode(input) {
|
|
755
|
-
return Buffer.from(JSON.stringify(input)).toString("base64url");
|
|
756
|
-
},
|
|
757
|
-
decode(input) {
|
|
758
|
-
return Cursor.parse(JSON.parse(Buffer.from(input, "base64url").toString("utf8")));
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
const info = (row) => ({
|
|
762
|
-
...row.data,
|
|
763
|
-
id: row.id,
|
|
764
|
-
sessionID: row.session_id
|
|
765
|
-
});
|
|
766
|
-
const part = (row) => ({
|
|
767
|
-
...row.data,
|
|
768
|
-
id: row.id,
|
|
769
|
-
sessionID: row.session_id,
|
|
770
|
-
messageID: row.message_id
|
|
771
|
-
});
|
|
772
|
-
const olderFilter = (cursor2) => ({
|
|
773
|
-
op: "or",
|
|
774
|
-
conditions: [
|
|
775
|
-
{ op: "lt", field: "time_created", value: cursor2.time },
|
|
776
|
-
{ op: "and", conditions: [
|
|
777
|
-
{ op: "eq", field: "time_created", value: cursor2.time },
|
|
778
|
-
{ op: "lt", field: "id", value: cursor2.id }
|
|
779
|
-
] }
|
|
780
|
-
]
|
|
781
|
-
});
|
|
782
|
-
async function hydrate(context, rows) {
|
|
783
|
-
const ids = rows.map((row) => row.id);
|
|
784
|
-
const partByMessage = /* @__PURE__ */ new Map();
|
|
785
|
-
if (ids.length > 0) {
|
|
786
|
-
const partRows = context.db.findMany("part", {
|
|
787
|
-
filter: { op: "in", field: "message_id", values: ids },
|
|
788
|
-
orderBy: [{ field: "message_id", direction: "asc" }, { field: "id", direction: "asc" }]
|
|
789
|
-
});
|
|
790
|
-
for (const row of partRows) {
|
|
791
|
-
const next = part(row);
|
|
792
|
-
const list = partByMessage.get(row.message_id);
|
|
793
|
-
if (list) list.push(next);
|
|
794
|
-
else partByMessage.set(row.message_id, [next]);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
return rows.map((row) => ({
|
|
798
|
-
info: info(row),
|
|
799
|
-
parts: partByMessage.get(row.id) ?? []
|
|
800
|
-
}));
|
|
801
|
-
}
|
|
802
|
-
function toModelMessages(input, model, options) {
|
|
803
|
-
const result = [];
|
|
804
|
-
const toolNames = /* @__PURE__ */ new Set();
|
|
805
|
-
const supportsMediaInToolResults = (() => {
|
|
806
|
-
if (model.api.npm === "@ai-sdk/anthropic") return true;
|
|
807
|
-
if (model.api.npm === "@ai-sdk/openai") return true;
|
|
808
|
-
if (model.api.npm === "@ai-sdk/amazon-bedrock") return true;
|
|
809
|
-
if (model.api.npm === "@ai-sdk/google-vertex/anthropic") return true;
|
|
810
|
-
if (model.api.npm === "@ai-sdk/google") {
|
|
811
|
-
const id = model.api.id.toLowerCase();
|
|
812
|
-
return id.includes("gemini-3") && !id.includes("gemini-2");
|
|
813
|
-
}
|
|
814
|
-
return false;
|
|
815
|
-
})();
|
|
816
|
-
const toModelOutput = (output) => {
|
|
817
|
-
if (typeof output === "string") {
|
|
818
|
-
return { type: "text", value: output };
|
|
819
|
-
}
|
|
820
|
-
if (typeof output === "object") {
|
|
821
|
-
const outputObject = output;
|
|
822
|
-
const attachments = (outputObject.attachments ?? []).filter((attachment) => {
|
|
823
|
-
return attachment.url.startsWith("data:") && attachment.url.includes(",");
|
|
824
|
-
});
|
|
825
|
-
return {
|
|
826
|
-
type: "content",
|
|
827
|
-
value: [
|
|
828
|
-
{ type: "text", text: outputObject.text },
|
|
829
|
-
...attachments.map((attachment) => ({
|
|
830
|
-
type: "media",
|
|
831
|
-
mediaType: attachment.mime,
|
|
832
|
-
data: iife(() => {
|
|
833
|
-
const commaIndex = attachment.url.indexOf(",");
|
|
834
|
-
return commaIndex === -1 ? attachment.url : attachment.url.slice(commaIndex + 1);
|
|
835
|
-
})
|
|
836
|
-
}))
|
|
837
|
-
]
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
return { type: "json", value: output };
|
|
841
|
-
};
|
|
842
|
-
for (const msg of input) {
|
|
843
|
-
if (msg.parts.length === 0) continue;
|
|
844
|
-
if (msg.info.role === "user") {
|
|
845
|
-
const userMessage = {
|
|
846
|
-
id: msg.info.id,
|
|
847
|
-
role: "user",
|
|
848
|
-
parts: []
|
|
849
|
-
};
|
|
850
|
-
result.push(userMessage);
|
|
851
|
-
for (const part2 of msg.parts) {
|
|
852
|
-
if (part2.type === "text" && !part2.ignored)
|
|
853
|
-
userMessage.parts.push({
|
|
854
|
-
type: "text",
|
|
855
|
-
text: part2.text
|
|
856
|
-
});
|
|
857
|
-
if (part2.type === "file" && part2.mime !== "text/plain" && part2.mime !== "application/x-directory") {
|
|
858
|
-
if (options?.stripMedia && isMedia(part2.mime)) {
|
|
859
|
-
userMessage.parts.push({
|
|
860
|
-
type: "text",
|
|
861
|
-
text: `[Attached ${part2.mime}: ${part2.filename ?? "file"}]`
|
|
862
|
-
});
|
|
863
|
-
} else {
|
|
864
|
-
userMessage.parts.push({
|
|
865
|
-
type: "file",
|
|
866
|
-
url: part2.url,
|
|
867
|
-
mediaType: part2.mime,
|
|
868
|
-
filename: part2.filename
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
if (part2.type === "compaction") {
|
|
873
|
-
userMessage.parts.push({
|
|
874
|
-
type: "text",
|
|
875
|
-
text: "What did we do so far?"
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
if (part2.type === "subtask") {
|
|
879
|
-
userMessage.parts.push({
|
|
880
|
-
type: "text",
|
|
881
|
-
text: "The following tool was executed by the user"
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
if (msg.info.role === "assistant") {
|
|
887
|
-
const differentModel = `${model.providerID}/${model.id}` !== `${msg.info.providerID}/${msg.info.modelID}`;
|
|
888
|
-
const media = [];
|
|
889
|
-
if (msg.info.error && !(MessageV22.AbortedError.isInstance(msg.info.error) && msg.parts.some((part2) => part2.type !== "step-start" && part2.type !== "reasoning"))) {
|
|
890
|
-
continue;
|
|
891
|
-
}
|
|
892
|
-
const assistantMessage = {
|
|
893
|
-
id: msg.info.id,
|
|
894
|
-
role: "assistant",
|
|
895
|
-
parts: []
|
|
896
|
-
};
|
|
897
|
-
for (const part2 of msg.parts) {
|
|
898
|
-
if (part2.type === "text")
|
|
899
|
-
assistantMessage.parts.push({
|
|
900
|
-
type: "text",
|
|
901
|
-
text: part2.text,
|
|
902
|
-
...differentModel ? {} : { providerMetadata: part2.metadata }
|
|
903
|
-
});
|
|
904
|
-
if (part2.type === "step-start")
|
|
905
|
-
assistantMessage.parts.push({
|
|
906
|
-
type: "step-start"
|
|
907
|
-
});
|
|
908
|
-
if (part2.type === "tool") {
|
|
909
|
-
toolNames.add(part2.tool);
|
|
910
|
-
if (part2.state.status === "completed") {
|
|
911
|
-
const outputText = part2.state.time.compacted ? "[Old tool result content cleared]" : part2.state.output;
|
|
912
|
-
const attachments = part2.state.time.compacted || options?.stripMedia ? [] : part2.state.attachments ?? [];
|
|
913
|
-
const mediaAttachments = attachments.filter((a) => isMedia(a.mime));
|
|
914
|
-
const nonMediaAttachments = attachments.filter((a) => !isMedia(a.mime));
|
|
915
|
-
if (!supportsMediaInToolResults && mediaAttachments.length > 0) {
|
|
916
|
-
media.push(...mediaAttachments);
|
|
917
|
-
}
|
|
918
|
-
const finalAttachments = supportsMediaInToolResults ? attachments : nonMediaAttachments;
|
|
919
|
-
const output = finalAttachments.length > 0 ? {
|
|
920
|
-
text: outputText,
|
|
921
|
-
attachments: finalAttachments
|
|
922
|
-
} : outputText;
|
|
923
|
-
assistantMessage.parts.push({
|
|
924
|
-
type: "tool-" + part2.tool,
|
|
925
|
-
state: "output-available",
|
|
926
|
-
toolCallId: part2.callID,
|
|
927
|
-
input: part2.state.input,
|
|
928
|
-
output,
|
|
929
|
-
...differentModel ? {} : { callProviderMetadata: part2.metadata }
|
|
930
|
-
});
|
|
931
|
-
}
|
|
932
|
-
if (part2.state.status === "error")
|
|
933
|
-
assistantMessage.parts.push({
|
|
934
|
-
type: "tool-" + part2.tool,
|
|
935
|
-
state: "output-error",
|
|
936
|
-
toolCallId: part2.callID,
|
|
937
|
-
input: part2.state.input,
|
|
938
|
-
errorText: part2.state.error,
|
|
939
|
-
...differentModel ? {} : { callProviderMetadata: part2.metadata }
|
|
940
|
-
});
|
|
941
|
-
if (part2.state.status === "pending" || part2.state.status === "running")
|
|
942
|
-
assistantMessage.parts.push({
|
|
943
|
-
type: "tool-" + part2.tool,
|
|
944
|
-
state: "output-error",
|
|
945
|
-
toolCallId: part2.callID,
|
|
946
|
-
input: part2.state.input,
|
|
947
|
-
errorText: "[Tool execution was interrupted]",
|
|
948
|
-
...differentModel ? {} : { callProviderMetadata: part2.metadata }
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
if (part2.type === "reasoning") {
|
|
952
|
-
assistantMessage.parts.push({
|
|
953
|
-
type: "reasoning",
|
|
954
|
-
text: part2.text,
|
|
955
|
-
...differentModel ? {} : { providerMetadata: part2.metadata }
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
if (assistantMessage.parts.length > 0) {
|
|
960
|
-
result.push(assistantMessage);
|
|
961
|
-
if (media.length > 0) {
|
|
962
|
-
result.push({
|
|
963
|
-
id: MessageID.ascending(),
|
|
964
|
-
role: "user",
|
|
965
|
-
parts: [
|
|
966
|
-
{
|
|
967
|
-
type: "text",
|
|
968
|
-
text: "Attached image(s) from tool result:"
|
|
969
|
-
},
|
|
970
|
-
...media.map((attachment) => ({
|
|
971
|
-
type: "file",
|
|
972
|
-
url: attachment.url,
|
|
973
|
-
mediaType: attachment.mime
|
|
974
|
-
}))
|
|
975
|
-
]
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
const tools = Object.fromEntries(Array.from(toolNames).map((toolName) => [toolName, { toModelOutput }]));
|
|
982
|
-
return convertToModelMessages(
|
|
983
|
-
result.filter((msg) => msg.parts.some((part2) => part2.type !== "step-start")),
|
|
984
|
-
{
|
|
985
|
-
//@ts-expect-error (convertToModelMessages expects a ToolSet but only actually needs tools[name]?.toModelOutput)
|
|
986
|
-
tools
|
|
987
|
-
}
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
|
-
MessageV22.toModelMessages = toModelMessages;
|
|
991
|
-
async function page(context, input) {
|
|
992
|
-
const before = input.before ? MessageV22.cursor.decode(input.before) : void 0;
|
|
993
|
-
const conditions = [{ op: "eq", field: "session_id", value: input.sessionID }];
|
|
994
|
-
if (before) conditions.push(olderFilter(before));
|
|
995
|
-
const rows = context.db.findMany("message", {
|
|
996
|
-
filter: { op: "and", conditions },
|
|
997
|
-
orderBy: [{ field: "time_created", direction: "desc" }, { field: "id", direction: "desc" }],
|
|
998
|
-
limit: input.limit + 1
|
|
999
|
-
});
|
|
1000
|
-
if (rows.length === 0) {
|
|
1001
|
-
const row = context.db.findOne("session", { op: "eq", field: "id", value: input.sessionID });
|
|
1002
|
-
if (!row) throw new NotFoundError({ message: `Session not found: ${input.sessionID}` });
|
|
1003
|
-
return {
|
|
1004
|
-
items: [],
|
|
1005
|
-
more: false
|
|
1006
|
-
};
|
|
1007
|
-
}
|
|
1008
|
-
const more = rows.length > input.limit;
|
|
1009
|
-
const pg = more ? rows.slice(0, input.limit) : rows;
|
|
1010
|
-
const items = await hydrate(context, pg);
|
|
1011
|
-
items.reverse();
|
|
1012
|
-
const tail = pg.at(-1);
|
|
1013
|
-
return {
|
|
1014
|
-
items,
|
|
1015
|
-
more,
|
|
1016
|
-
cursor: more && tail ? MessageV22.cursor.encode({ id: tail.id, time: tail.time_created }) : void 0
|
|
1017
|
-
};
|
|
1018
|
-
}
|
|
1019
|
-
MessageV22.page = page;
|
|
1020
|
-
async function* stream(context, sessionID) {
|
|
1021
|
-
const size = 50;
|
|
1022
|
-
let before;
|
|
1023
|
-
while (true) {
|
|
1024
|
-
const next = await page(context, { sessionID, limit: size, before });
|
|
1025
|
-
if (next.items.length === 0) break;
|
|
1026
|
-
for (let i = next.items.length - 1; i >= 0; i--) {
|
|
1027
|
-
yield next.items[i];
|
|
1028
|
-
}
|
|
1029
|
-
if (!next.more || !next.cursor) break;
|
|
1030
|
-
before = next.cursor;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
MessageV22.stream = stream;
|
|
1034
|
-
async function parts(context, message_id) {
|
|
1035
|
-
const rows = context.db.findMany("part", {
|
|
1036
|
-
filter: { op: "eq", field: "message_id", value: message_id },
|
|
1037
|
-
orderBy: [{ field: "id", direction: "asc" }]
|
|
1038
|
-
});
|
|
1039
|
-
return rows.map(
|
|
1040
|
-
(row) => ({ ...row.data, id: row.id, sessionID: row.session_id, messageID: row.message_id })
|
|
1041
|
-
);
|
|
1042
|
-
}
|
|
1043
|
-
MessageV22.parts = parts;
|
|
1044
|
-
async function get(context, input) {
|
|
1045
|
-
const row = context.db.findOne(
|
|
1046
|
-
"message",
|
|
1047
|
-
{ op: "and", conditions: [{ op: "eq", field: "id", value: input.messageID }, { op: "eq", field: "session_id", value: input.sessionID }] }
|
|
1048
|
-
);
|
|
1049
|
-
if (!row) throw new NotFoundError({ message: `Message not found: ${input.messageID}` });
|
|
1050
|
-
return {
|
|
1051
|
-
info: info(row),
|
|
1052
|
-
parts: await parts(context, input.messageID)
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
|
-
MessageV22.get = get;
|
|
1056
|
-
async function filterCompacted(stream2) {
|
|
1057
|
-
const result = [];
|
|
1058
|
-
const completed = /* @__PURE__ */ new Set();
|
|
1059
|
-
for await (const msg of stream2) {
|
|
1060
|
-
result.push(msg);
|
|
1061
|
-
if (msg.info.role === "user" && completed.has(msg.info.id) && msg.parts.some((part2) => part2.type === "compaction"))
|
|
1062
|
-
break;
|
|
1063
|
-
if (msg.info.role === "assistant" && msg.info.summary && msg.info.finish && !msg.info.error)
|
|
1064
|
-
completed.add(msg.info.parentID);
|
|
1065
|
-
}
|
|
1066
|
-
result.reverse();
|
|
1067
|
-
return result;
|
|
1068
|
-
}
|
|
1069
|
-
MessageV22.filterCompacted = filterCompacted;
|
|
1070
|
-
function fromError(e, ctx) {
|
|
1071
|
-
switch (true) {
|
|
1072
|
-
case (e instanceof DOMException && e.name === "AbortError"):
|
|
1073
|
-
return new MessageV22.AbortedError(
|
|
1074
|
-
{ message: e.message },
|
|
1075
|
-
{
|
|
1076
|
-
cause: e
|
|
1077
|
-
}
|
|
1078
|
-
).toObject();
|
|
1079
|
-
case MessageV22.OutputLengthError.isInstance(e):
|
|
1080
|
-
return e;
|
|
1081
|
-
case LoadAPIKeyError.isInstance(e):
|
|
1082
|
-
return new MessageV22.AuthError(
|
|
1083
|
-
{
|
|
1084
|
-
providerID: ctx.providerID,
|
|
1085
|
-
message: e.message
|
|
1086
|
-
},
|
|
1087
|
-
{ cause: e }
|
|
1088
|
-
).toObject();
|
|
1089
|
-
case e?.code === "ECONNRESET":
|
|
1090
|
-
return new MessageV22.APIError(
|
|
1091
|
-
{
|
|
1092
|
-
message: "Connection reset by server",
|
|
1093
|
-
isRetryable: true,
|
|
1094
|
-
metadata: {
|
|
1095
|
-
code: e.code ?? "",
|
|
1096
|
-
syscall: e.syscall ?? "",
|
|
1097
|
-
message: e.message ?? ""
|
|
1098
|
-
}
|
|
1099
|
-
},
|
|
1100
|
-
{ cause: e }
|
|
1101
|
-
).toObject();
|
|
1102
|
-
case APICallError.isInstance(e):
|
|
1103
|
-
const parsed = ProviderError.parseAPICallError({
|
|
1104
|
-
providerID: ctx.providerID,
|
|
1105
|
-
error: e
|
|
1106
|
-
});
|
|
1107
|
-
if (parsed.type === "context_overflow") {
|
|
1108
|
-
return new MessageV22.ContextOverflowError(
|
|
1109
|
-
{
|
|
1110
|
-
message: parsed.message,
|
|
1111
|
-
responseBody: parsed.responseBody
|
|
1112
|
-
},
|
|
1113
|
-
{ cause: e }
|
|
1114
|
-
).toObject();
|
|
1115
|
-
}
|
|
1116
|
-
return new MessageV22.APIError(
|
|
1117
|
-
{
|
|
1118
|
-
message: parsed.message,
|
|
1119
|
-
statusCode: parsed.statusCode,
|
|
1120
|
-
isRetryable: parsed.isRetryable,
|
|
1121
|
-
responseHeaders: parsed.responseHeaders,
|
|
1122
|
-
responseBody: parsed.responseBody,
|
|
1123
|
-
metadata: parsed.metadata
|
|
1124
|
-
},
|
|
1125
|
-
{ cause: e }
|
|
1126
|
-
).toObject();
|
|
1127
|
-
case e instanceof Error:
|
|
1128
|
-
return new NamedError.Unknown({ message: e.toString() }, { cause: e }).toObject();
|
|
1129
|
-
default:
|
|
1130
|
-
try {
|
|
1131
|
-
const parsed2 = ProviderError.parseStreamError(e);
|
|
1132
|
-
if (parsed2) {
|
|
1133
|
-
if (parsed2.type === "context_overflow") {
|
|
1134
|
-
return new MessageV22.ContextOverflowError(
|
|
1135
|
-
{
|
|
1136
|
-
message: parsed2.message,
|
|
1137
|
-
responseBody: parsed2.responseBody
|
|
1138
|
-
},
|
|
1139
|
-
{ cause: e }
|
|
1140
|
-
).toObject();
|
|
1141
|
-
}
|
|
1142
|
-
return new MessageV22.APIError(
|
|
1143
|
-
{
|
|
1144
|
-
message: parsed2.message,
|
|
1145
|
-
isRetryable: parsed2.isRetryable,
|
|
1146
|
-
responseBody: parsed2.responseBody
|
|
1147
|
-
},
|
|
1148
|
-
{
|
|
1149
|
-
cause: e
|
|
1150
|
-
}
|
|
1151
|
-
).toObject();
|
|
1152
|
-
}
|
|
1153
|
-
} catch {
|
|
1154
|
-
}
|
|
1155
|
-
return new NamedError.Unknown({ message: JSON.stringify(e) }, { cause: e }).toObject();
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
MessageV22.fromError = fromError;
|
|
1159
|
-
})(MessageV2 || (MessageV2 = {}));
|
|
1160
|
-
var MemoryService = class extends EventEmitter {
|
|
1161
|
-
constructor(context) {
|
|
1162
|
-
super();
|
|
1163
|
-
this.context = context;
|
|
1164
|
-
}
|
|
1165
|
-
async updateMessage(msg) {
|
|
1166
|
-
const time_created = msg.time.created;
|
|
1167
|
-
const { id, sessionID, ...data } = msg;
|
|
1168
|
-
this.context.db.upsert(
|
|
1169
|
-
"message",
|
|
1170
|
-
{ id, session_id: sessionID, time_created, data },
|
|
1171
|
-
["id"],
|
|
1172
|
-
{ data }
|
|
1173
|
-
);
|
|
1174
|
-
this.emit("message.updated", { info: msg });
|
|
1175
|
-
return msg;
|
|
1176
|
-
}
|
|
1177
|
-
async removeMessage(input) {
|
|
1178
|
-
this.context.db.remove(
|
|
1179
|
-
"message",
|
|
1180
|
-
{ op: "and", conditions: [{ op: "eq", field: "id", value: input.messageID }, { op: "eq", field: "session_id", value: input.sessionID }] }
|
|
1181
|
-
);
|
|
1182
|
-
this.emit("message.removed", {
|
|
1183
|
-
sessionID: input.sessionID,
|
|
1184
|
-
messageID: input.messageID
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
async removePart(input) {
|
|
1188
|
-
this.context.db.remove(
|
|
1189
|
-
"part",
|
|
1190
|
-
{ op: "and", conditions: [{ op: "eq", field: "id", value: input.partID }, { op: "eq", field: "session_id", value: input.sessionID }] }
|
|
1191
|
-
);
|
|
1192
|
-
this.emit("message.part.removed", {
|
|
1193
|
-
sessionID: input.sessionID,
|
|
1194
|
-
messageID: input.messageID,
|
|
1195
|
-
partID: input.partID
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
async updatePart(part) {
|
|
1199
|
-
const { id, messageID, sessionID, ...data } = part;
|
|
1200
|
-
const time = Date.now();
|
|
1201
|
-
this.context.db.upsert(
|
|
1202
|
-
"part",
|
|
1203
|
-
{ id, message_id: messageID, session_id: sessionID, time_created: time, data },
|
|
1204
|
-
["id"],
|
|
1205
|
-
{ data }
|
|
1206
|
-
);
|
|
1207
|
-
this.emit("message.part.updated", { part: structuredClone(part) });
|
|
1208
|
-
return part;
|
|
1209
|
-
}
|
|
1210
|
-
async updatePartDelta(input) {
|
|
1211
|
-
this.emit("message.part.delta", input);
|
|
1212
|
-
}
|
|
1213
|
-
async messages(input) {
|
|
1214
|
-
const result = [];
|
|
1215
|
-
for await (const msg of MessageV2.stream(this.context, input.sessionID)) {
|
|
1216
|
-
if (input.limit && result.length >= input.limit) break;
|
|
1217
|
-
result.push(msg);
|
|
1218
|
-
}
|
|
1219
|
-
result.reverse();
|
|
1220
|
-
return result;
|
|
1221
|
-
}
|
|
1222
|
-
};
|
|
1223
|
-
var Memory;
|
|
1224
|
-
((Memory2) => {
|
|
1225
|
-
Memory2.getUsage = fn(
|
|
1226
|
-
z5.object({
|
|
1227
|
-
model: z5.custom(),
|
|
1228
|
-
usage: z5.custom(),
|
|
1229
|
-
metadata: z5.custom().optional()
|
|
1230
|
-
}),
|
|
1231
|
-
(input) => {
|
|
1232
|
-
const safe = (value) => {
|
|
1233
|
-
if (!Number.isFinite(value)) return 0;
|
|
1234
|
-
return value;
|
|
1235
|
-
};
|
|
1236
|
-
const inputTokens = safe(input.usage.inputTokens ?? 0);
|
|
1237
|
-
const outputTokens = safe(input.usage.outputTokens ?? 0);
|
|
1238
|
-
const reasoningTokens = safe(input.usage.reasoningTokens ?? 0);
|
|
1239
|
-
const cacheReadInputTokens = safe(input.usage.cachedInputTokens ?? 0);
|
|
1240
|
-
const cacheWriteInputTokens = safe(
|
|
1241
|
-
input.metadata?.["anthropic"]?.["cacheCreationInputTokens"] ?? // @ts-expect-error
|
|
1242
|
-
input.metadata?.["bedrock"]?.["usage"]?.["cacheWriteInputTokens"] ?? // @ts-expect-error
|
|
1243
|
-
input.metadata?.["venice"]?.["usage"]?.["cacheCreationInputTokens"] ?? 0
|
|
1244
|
-
);
|
|
1245
|
-
const excludesCachedTokens = !!(input.metadata?.["anthropic"] || input.metadata?.["bedrock"]);
|
|
1246
|
-
const adjustedInputTokens = safe(
|
|
1247
|
-
excludesCachedTokens ? inputTokens : inputTokens - cacheReadInputTokens - cacheWriteInputTokens
|
|
1248
|
-
);
|
|
1249
|
-
const total = iife(() => {
|
|
1250
|
-
if (input.model.api.npm === "@ai-sdk/anthropic" || input.model.api.npm === "@ai-sdk/amazon-bedrock" || input.model.api.npm === "@ai-sdk/google-vertex/anthropic") {
|
|
1251
|
-
return adjustedInputTokens + outputTokens + cacheReadInputTokens + cacheWriteInputTokens;
|
|
1252
|
-
}
|
|
1253
|
-
return input.usage.totalTokens;
|
|
1254
|
-
});
|
|
1255
|
-
const tokens = {
|
|
1256
|
-
total,
|
|
1257
|
-
input: adjustedInputTokens,
|
|
1258
|
-
output: outputTokens,
|
|
1259
|
-
reasoning: reasoningTokens,
|
|
1260
|
-
cache: {
|
|
1261
|
-
write: cacheWriteInputTokens,
|
|
1262
|
-
read: cacheReadInputTokens
|
|
1263
|
-
}
|
|
1264
|
-
};
|
|
1265
|
-
const costInfo = input.model.cost?.experimentalOver200K && tokens.input + tokens.cache.read > 2e5 ? input.model.cost.experimentalOver200K : input.model.cost;
|
|
1266
|
-
return {
|
|
1267
|
-
cost: safe(
|
|
1268
|
-
new Decimal(0).add(new Decimal(tokens.input).mul(costInfo?.input ?? 0).div(1e6)).add(new Decimal(tokens.output).mul(costInfo?.output ?? 0).div(1e6)).add(new Decimal(tokens.cache.read).mul(costInfo?.cache?.read ?? 0).div(1e6)).add(new Decimal(tokens.cache.write).mul(costInfo?.cache?.write ?? 0).div(1e6)).add(new Decimal(tokens.reasoning).mul(costInfo?.output ?? 0).div(1e6)).toNumber()
|
|
1269
|
-
),
|
|
1270
|
-
tokens
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
);
|
|
1274
|
-
})(Memory || (Memory = {}));
|
|
1275
|
-
var WorkspaceID = { zod: z6.string() };
|
|
1276
|
-
var WorkspaceContext = { workspaceID: void 0 };
|
|
1277
|
-
var log = Log.create({ service: "session" });
|
|
1278
|
-
var parentTitlePrefix = "New session - ";
|
|
1279
|
-
var childTitlePrefix = "Child session - ";
|
|
1280
|
-
function createDefaultTitle(isChild = false) {
|
|
1281
|
-
return (isChild ? childTitlePrefix : parentTitlePrefix) + (/* @__PURE__ */ new Date()).toISOString();
|
|
1282
|
-
}
|
|
1283
|
-
function fromRow(row) {
|
|
1284
|
-
const summary = row.summary_additions !== null || row.summary_deletions !== null || row.summary_files !== null ? {
|
|
1285
|
-
additions: row.summary_additions ?? 0,
|
|
1286
|
-
deletions: row.summary_deletions ?? 0,
|
|
1287
|
-
files: row.summary_files ?? 0,
|
|
1288
|
-
diffs: row.summary_diffs ?? void 0
|
|
1289
|
-
} : void 0;
|
|
1290
|
-
return {
|
|
1291
|
-
id: row.id,
|
|
1292
|
-
slug: row.slug,
|
|
1293
|
-
projectID: row.project_id,
|
|
1294
|
-
workspaceID: row.workspace_id ?? void 0,
|
|
1295
|
-
directory: row.directory,
|
|
1296
|
-
parentID: row.parent_id ?? void 0,
|
|
1297
|
-
title: row.title,
|
|
1298
|
-
version: row.version,
|
|
1299
|
-
summary,
|
|
1300
|
-
revert: row.revert ?? void 0,
|
|
1301
|
-
time: {
|
|
1302
|
-
created: row.time_created,
|
|
1303
|
-
updated: row.time_updated,
|
|
1304
|
-
compacting: row.time_compacting ?? void 0,
|
|
1305
|
-
archived: row.time_archived ?? void 0
|
|
1306
|
-
}
|
|
1307
|
-
};
|
|
1308
|
-
}
|
|
1309
|
-
function toRow(info) {
|
|
1310
|
-
return {
|
|
1311
|
-
id: info.id,
|
|
1312
|
-
project_id: info.projectID,
|
|
1313
|
-
workspace_id: info.workspaceID,
|
|
1314
|
-
parent_id: info.parentID,
|
|
1315
|
-
slug: info.slug,
|
|
1316
|
-
directory: info.directory,
|
|
1317
|
-
title: info.title,
|
|
1318
|
-
version: info.version,
|
|
1319
|
-
share_url: void 0,
|
|
1320
|
-
summary_additions: info.summary?.additions,
|
|
1321
|
-
summary_deletions: info.summary?.deletions,
|
|
1322
|
-
summary_files: info.summary?.files,
|
|
1323
|
-
summary_diffs: info.summary?.diffs,
|
|
1324
|
-
revert: info.revert ?? null,
|
|
1325
|
-
time_created: info.time.created,
|
|
1326
|
-
time_updated: info.time.updated,
|
|
1327
|
-
time_compacting: info.time.compacting,
|
|
1328
|
-
time_archived: info.time.archived
|
|
1329
|
-
};
|
|
1330
|
-
}
|
|
1331
|
-
var SessionService = class extends EventEmitter2 {
|
|
1332
|
-
constructor(ctx) {
|
|
1333
|
-
super();
|
|
1334
|
-
this.ctx = ctx;
|
|
1335
|
-
}
|
|
1336
|
-
static isDefaultTitle(title) {
|
|
1337
|
-
return new RegExp(
|
|
1338
|
-
`^(${parentTitlePrefix}|${childTitlePrefix})\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$`
|
|
1339
|
-
).test(title);
|
|
1340
|
-
}
|
|
1341
|
-
static fromRow = fromRow;
|
|
1342
|
-
static toRow = toRow;
|
|
1343
|
-
static getUsage = Memory.getUsage;
|
|
1344
|
-
async create(input) {
|
|
1345
|
-
return this.createNext({
|
|
1346
|
-
parentID: input?.parentID,
|
|
1347
|
-
directory: this.ctx.directory,
|
|
1348
|
-
title: input?.title,
|
|
1349
|
-
workspaceID: input?.workspaceID
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
async touch(sessionID) {
|
|
1353
|
-
const now = Date.now();
|
|
1354
|
-
{
|
|
1355
|
-
const row = this.ctx.db.update(
|
|
1356
|
-
"session",
|
|
1357
|
-
{ op: "eq", field: "id", value: sessionID },
|
|
1358
|
-
{ time_updated: now }
|
|
1359
|
-
);
|
|
1360
|
-
if (!row) throw new NotFoundError({ message: `Session not found: ${sessionID}` });
|
|
1361
|
-
const info = fromRow(row);
|
|
1362
|
-
this.emit("session.updated", { info });
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
async createNext(input) {
|
|
1366
|
-
const result = {
|
|
1367
|
-
id: SessionID.descending(input.id),
|
|
1368
|
-
slug: Slug.create(),
|
|
1369
|
-
version: Installation.VERSION,
|
|
1370
|
-
projectID: this.ctx.project.id,
|
|
1371
|
-
directory: input.directory,
|
|
1372
|
-
workspaceID: input.workspaceID,
|
|
1373
|
-
parentID: input.parentID,
|
|
1374
|
-
title: input.title ?? createDefaultTitle(!!input.parentID),
|
|
1375
|
-
time: {
|
|
1376
|
-
created: Date.now(),
|
|
1377
|
-
updated: Date.now()
|
|
1378
|
-
}
|
|
1379
|
-
};
|
|
1380
|
-
log.info("created", result);
|
|
1381
|
-
{
|
|
1382
|
-
this.ctx.db.insert("session", toRow(result));
|
|
1383
|
-
this.emit("session.created", { info: result });
|
|
1384
|
-
}
|
|
1385
|
-
this.emit("session.updated", { info: result });
|
|
1386
|
-
return result;
|
|
1387
|
-
}
|
|
1388
|
-
plan(input) {
|
|
1389
|
-
const base = this.ctx.project.vcs ? join(this.ctx.worktree, ".opencode", "plans") : join(this.ctx.dataPath, "plans");
|
|
1390
|
-
return join(base, [input.time.created, input.slug].join("-") + ".md");
|
|
1391
|
-
}
|
|
1392
|
-
async get(id) {
|
|
1393
|
-
const row = this.ctx.db.findOne("session", { op: "eq", field: "id", value: id });
|
|
1394
|
-
if (!row) throw new NotFoundError({ message: `Session not found: ${id}` });
|
|
1395
|
-
return fromRow(row);
|
|
1396
|
-
}
|
|
1397
|
-
async setTitle(input) {
|
|
1398
|
-
const row = this.ctx.db.update(
|
|
1399
|
-
"session",
|
|
1400
|
-
{ op: "eq", field: "id", value: input.sessionID },
|
|
1401
|
-
{ title: input.title }
|
|
1402
|
-
);
|
|
1403
|
-
if (!row) throw new NotFoundError({ message: `Session not found: ${input.sessionID}` });
|
|
1404
|
-
const info = fromRow(row);
|
|
1405
|
-
this.emit("session.updated", { info });
|
|
1406
|
-
return info;
|
|
1407
|
-
}
|
|
1408
|
-
async messages(input) {
|
|
1409
|
-
return this.ctx.memory.messages(input);
|
|
1410
|
-
}
|
|
1411
|
-
*list(input) {
|
|
1412
|
-
const project = this.ctx.project;
|
|
1413
|
-
const conditions = [{ op: "eq", field: "project_id", value: project.id }];
|
|
1414
|
-
if (WorkspaceContext.workspaceID) {
|
|
1415
|
-
conditions.push({ op: "eq", field: "workspace_id", value: WorkspaceContext.workspaceID });
|
|
1416
|
-
}
|
|
1417
|
-
if (input?.directory) {
|
|
1418
|
-
conditions.push({ op: "eq", field: "directory", value: input.directory });
|
|
1419
|
-
}
|
|
1420
|
-
if (input?.roots) {
|
|
1421
|
-
conditions.push({ op: "isNull", field: "parent_id" });
|
|
1422
|
-
}
|
|
1423
|
-
if (input?.start) {
|
|
1424
|
-
conditions.push({ op: "gte", field: "time_updated", value: input.start });
|
|
1425
|
-
}
|
|
1426
|
-
if (input?.search) {
|
|
1427
|
-
conditions.push({ op: "like", field: "title", value: `%${input.search}%` });
|
|
1428
|
-
}
|
|
1429
|
-
const limit = input?.limit ?? 100;
|
|
1430
|
-
const rows = this.ctx.db.findMany("session", {
|
|
1431
|
-
filter: { op: "and", conditions },
|
|
1432
|
-
orderBy: [{ field: "time_updated", direction: "desc" }],
|
|
1433
|
-
limit
|
|
1434
|
-
});
|
|
1435
|
-
for (const row of rows) {
|
|
1436
|
-
yield fromRow(row);
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
*listGlobal(input) {
|
|
1440
|
-
const conditions = [];
|
|
1441
|
-
if (input?.directory) {
|
|
1442
|
-
conditions.push({ op: "eq", field: "directory", value: input.directory });
|
|
1443
|
-
}
|
|
1444
|
-
if (input?.roots) {
|
|
1445
|
-
conditions.push({ op: "isNull", field: "parent_id" });
|
|
1446
|
-
}
|
|
1447
|
-
if (input?.start) {
|
|
1448
|
-
conditions.push({ op: "gte", field: "time_updated", value: input.start });
|
|
1449
|
-
}
|
|
1450
|
-
if (input?.cursor) {
|
|
1451
|
-
conditions.push({ op: "lt", field: "time_updated", value: input.cursor });
|
|
1452
|
-
}
|
|
1453
|
-
if (input?.search) {
|
|
1454
|
-
conditions.push({ op: "like", field: "title", value: `%${input.search}%` });
|
|
1455
|
-
}
|
|
1456
|
-
if (!input?.archived) {
|
|
1457
|
-
conditions.push({ op: "isNull", field: "time_archived" });
|
|
1458
|
-
}
|
|
1459
|
-
const limit = input?.limit ?? 100;
|
|
1460
|
-
const rows = this.ctx.db.findMany("session", {
|
|
1461
|
-
filter: conditions.length > 0 ? { op: "and", conditions } : void 0,
|
|
1462
|
-
orderBy: [{ field: "time_updated", direction: "desc" }, { field: "id", direction: "desc" }],
|
|
1463
|
-
limit
|
|
1464
|
-
});
|
|
1465
|
-
const ids = [...new Set(rows.map((row) => row.project_id))];
|
|
1466
|
-
const projects = /* @__PURE__ */ new Map();
|
|
1467
|
-
if (ids.length > 0) {
|
|
1468
|
-
const items = this.ctx.db.findMany("project", {
|
|
1469
|
-
filter: { op: "in", field: "id", values: ids },
|
|
1470
|
-
select: ["id", "name", "worktree"]
|
|
1471
|
-
});
|
|
1472
|
-
for (const item of items) {
|
|
1473
|
-
projects.set(item.id, {
|
|
1474
|
-
id: item.id,
|
|
1475
|
-
name: item.name ?? void 0,
|
|
1476
|
-
worktree: item.worktree
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
for (const row of rows) {
|
|
1481
|
-
const project = projects.get(row.project_id) ?? null;
|
|
1482
|
-
yield { ...fromRow(row), project };
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
async updateMessage(msg) {
|
|
1486
|
-
return this.ctx.memory.updateMessage(msg);
|
|
1487
|
-
}
|
|
1488
|
-
async removeMessage(input) {
|
|
1489
|
-
return this.ctx.memory.removeMessage(input);
|
|
1490
|
-
}
|
|
1491
|
-
async removePart(input) {
|
|
1492
|
-
return this.ctx.memory.removePart(input);
|
|
1493
|
-
}
|
|
1494
|
-
async updatePart(part) {
|
|
1495
|
-
return this.ctx.memory.updatePart(part);
|
|
1496
|
-
}
|
|
1497
|
-
async updatePartDelta(input) {
|
|
1498
|
-
return this.ctx.memory.updatePartDelta(input);
|
|
1499
|
-
}
|
|
1500
|
-
updateTodo(input) {
|
|
1501
|
-
this.ctx.db.transaction((tx) => {
|
|
1502
|
-
tx.remove("todo", { op: "eq", field: "session_id", value: input.sessionID });
|
|
1503
|
-
if (input.todos.length === 0) return;
|
|
1504
|
-
for (const [position, todo] of input.todos.entries()) {
|
|
1505
|
-
tx.insert("todo", {
|
|
1506
|
-
session_id: input.sessionID,
|
|
1507
|
-
content: todo.content,
|
|
1508
|
-
status: todo.status,
|
|
1509
|
-
priority: todo.priority,
|
|
1510
|
-
position
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
this.emit("todo.updated", input);
|
|
1515
|
-
}
|
|
1516
|
-
getTodo(sessionID) {
|
|
1517
|
-
const rows = this.ctx.db.findMany("todo", {
|
|
1518
|
-
filter: { op: "eq", field: "session_id", value: sessionID },
|
|
1519
|
-
orderBy: [{ field: "position", direction: "asc" }]
|
|
1520
|
-
});
|
|
1521
|
-
return rows.map((row) => ({
|
|
1522
|
-
content: row.content,
|
|
1523
|
-
status: row.status,
|
|
1524
|
-
priority: row.priority
|
|
1525
|
-
}));
|
|
1526
|
-
}
|
|
1527
|
-
};
|
|
1528
|
-
var Session;
|
|
1529
|
-
((Session2) => {
|
|
1530
|
-
Session2.Info = z6.object({
|
|
1531
|
-
id: SessionID.zod,
|
|
1532
|
-
slug: z6.string(),
|
|
1533
|
-
projectID: ProjectID.zod,
|
|
1534
|
-
workspaceID: WorkspaceID.zod.optional(),
|
|
1535
|
-
directory: z6.string(),
|
|
1536
|
-
parentID: SessionID.zod.optional(),
|
|
1537
|
-
summary: z6.object({
|
|
1538
|
-
additions: z6.number(),
|
|
1539
|
-
deletions: z6.number(),
|
|
1540
|
-
files: z6.number(),
|
|
1541
|
-
diffs: MessageV2.FileDiff.array().optional()
|
|
1542
|
-
}).optional(),
|
|
1543
|
-
title: z6.string(),
|
|
1544
|
-
version: z6.string(),
|
|
1545
|
-
time: z6.object({
|
|
1546
|
-
created: z6.number(),
|
|
1547
|
-
updated: z6.number(),
|
|
1548
|
-
compacting: z6.number().optional(),
|
|
1549
|
-
archived: z6.number().optional()
|
|
1550
|
-
}),
|
|
1551
|
-
revert: z6.object({
|
|
1552
|
-
messageID: MessageID.zod,
|
|
1553
|
-
partID: PartID.zod.optional(),
|
|
1554
|
-
diff: z6.string().optional()
|
|
1555
|
-
}).optional()
|
|
1556
|
-
}).meta({
|
|
1557
|
-
ref: "Session"
|
|
1558
|
-
});
|
|
1559
|
-
Session2.ProjectInfo = z6.object({
|
|
1560
|
-
id: ProjectID.zod,
|
|
1561
|
-
name: z6.string().optional(),
|
|
1562
|
-
worktree: z6.string()
|
|
1563
|
-
}).meta({
|
|
1564
|
-
ref: "ProjectSummary"
|
|
1565
|
-
});
|
|
1566
|
-
Session2.GlobalInfo = Session2.Info.extend({
|
|
1567
|
-
project: Session2.ProjectInfo.nullable()
|
|
1568
|
-
}).meta({
|
|
1569
|
-
ref: "GlobalSession"
|
|
1570
|
-
});
|
|
1571
|
-
class BusyError extends Error {
|
|
1572
|
-
constructor(sessionID) {
|
|
1573
|
-
super(`Session ${sessionID} is busy`);
|
|
1574
|
-
this.sessionID = sessionID;
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
Session2.BusyError = BusyError;
|
|
1578
|
-
})(Session || (Session = {}));
|
|
1579
|
-
var SessionStatus;
|
|
1580
|
-
((SessionStatus2) => {
|
|
1581
|
-
SessionStatus2.Info = z6.union([
|
|
1582
|
-
z6.object({
|
|
1583
|
-
type: z6.literal("idle")
|
|
1584
|
-
}),
|
|
1585
|
-
z6.object({
|
|
1586
|
-
type: z6.literal("retry"),
|
|
1587
|
-
attempt: z6.number(),
|
|
1588
|
-
message: z6.string(),
|
|
1589
|
-
next: z6.number()
|
|
1590
|
-
}),
|
|
1591
|
-
z6.object({
|
|
1592
|
-
type: z6.literal("busy")
|
|
1593
|
-
})
|
|
1594
|
-
]).meta({
|
|
1595
|
-
ref: "SessionStatus"
|
|
1596
|
-
});
|
|
1597
|
-
})(SessionStatus || (SessionStatus = {}));
|
|
1598
|
-
var Todo;
|
|
1599
|
-
((Todo2) => {
|
|
1600
|
-
Todo2.Info = z6.object({
|
|
1601
|
-
content: z6.string().describe("Brief description of the task"),
|
|
1602
|
-
status: z6.string().describe("Current status of the task: pending, in_progress, completed, cancelled"),
|
|
1603
|
-
priority: z6.string().describe("Priority level of the task: high, medium, low")
|
|
1604
|
-
}).meta({ ref: "Todo" });
|
|
1605
|
-
})(Todo || (Todo = {}));
|
|
1606
|
-
|
|
1607
|
-
export {
|
|
1608
|
-
Installation,
|
|
1609
|
-
LSP,
|
|
1610
|
-
iife,
|
|
1611
|
-
defer,
|
|
1612
|
-
Token,
|
|
1613
|
-
ProviderID,
|
|
1614
|
-
ModelID,
|
|
1615
|
-
MessageV2,
|
|
1616
|
-
MemoryService,
|
|
1617
|
-
SessionService,
|
|
1618
|
-
Session,
|
|
1619
|
-
SessionStatus,
|
|
1620
|
-
Todo
|
|
1621
|
-
};
|