@cloudflare/think 0.15.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -44
- package/dist/{chat-sdk-iuBa-CGM.js → chat-sdk-C8BvREXn.js} +16 -9
- package/dist/chat-sdk-C8BvREXn.js.map +1 -0
- package/dist/{index-s3Pl812H.d.ts → index-B7zEkBBM.d.ts} +138 -124
- package/dist/messengers/index.d.ts +15 -17
- package/dist/messengers/index.js +2 -2
- package/dist/messengers/telegram.d.ts +1 -1
- package/dist/messengers/telegram.js +1 -1
- package/dist/think.d.ts +1 -1
- package/dist/think.js +52 -39
- package/dist/think.js.map +1 -1
- package/dist/tools/workspace.js +13 -1
- package/dist/tools/workspace.js.map +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/index.md +52 -493
- package/docs/lifecycle-hooks.md +24 -0
- package/docs/sub-agents.md +7 -19
- package/docs/tools.md +3 -3
- package/package.json +6 -39
- package/dist/chat-sdk-iuBa-CGM.js.map +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -1304
- package/dist/cli/index.js.map +0 -1
- package/dist/codegen-DlA2QQuU.js +0 -109
- package/dist/codegen-DlA2QQuU.js.map +0 -1
- package/dist/config-CD7hqncK.d.ts +0 -71
- package/dist/framework/index.d.ts +0 -170
- package/dist/framework/index.js +0 -4
- package/dist/manifest-DK5HuGga.d.ts +0 -141
- package/dist/project-BHurFdu4.js +0 -685
- package/dist/project-BHurFdu4.js.map +0 -1
- package/dist/server-entry.d.ts +0 -120
- package/dist/server-entry.js +0 -266
- package/dist/server-entry.js.map +0 -1
- package/dist/studio/assets/abap-CLvhMVsD.js +0 -1
- package/dist/studio/assets/actionscript-3--17pq3dv.js +0 -1
- package/dist/studio/assets/ada-C5qYipkI.js +0 -1
- package/dist/studio/assets/andromeeda-vGVdxbeo.js +0 -1
- package/dist/studio/assets/angular-html-B26lsrRw.js +0 -1
- package/dist/studio/assets/angular-ts-B0BTTyHo.js +0 -1
- package/dist/studio/assets/apache-U0d_L8uA.js +0 -1
- package/dist/studio/assets/apex-CGTLDQj6.js +0 -1
- package/dist/studio/assets/apl-W5hJk0fj.js +0 -1
- package/dist/studio/assets/applescript-CCn79oCD.js +0 -1
- package/dist/studio/assets/ara-4CJ0cIlV.js +0 -1
- package/dist/studio/assets/asciidoc-DE70LPWp.js +0 -1
- package/dist/studio/assets/asm-Cmm7eHzH.js +0 -1
- package/dist/studio/assets/astro-ChkXCqsA.js +0 -1
- package/dist/studio/assets/aurora-x-CDeNXAV0.js +0 -1
- package/dist/studio/assets/awk-BWXHIvNe.js +0 -1
- package/dist/studio/assets/ayu-dark-DluEY0Gj.js +0 -1
- package/dist/studio/assets/ayu-light-C3h-C4tm.js +0 -1
- package/dist/studio/assets/ayu-mirage-Bqwy1Gya.js +0 -1
- package/dist/studio/assets/ballerina-B7ZEbQpA.js +0 -1
- package/dist/studio/assets/bat-Bo4NYOV-.js +0 -1
- package/dist/studio/assets/beancount-D-usSTwE.js +0 -1
- package/dist/studio/assets/berry-DKpUyyne.js +0 -1
- package/dist/studio/assets/bibtex-Ci_nEsc7.js +0 -1
- package/dist/studio/assets/bicep-CUHmPFLl.js +0 -1
- package/dist/studio/assets/bird2-C2hNVINV.js +0 -1
- package/dist/studio/assets/blade-Dy0zTtr6.js +0 -1
- package/dist/studio/assets/bsl-BkkzgIyY.js +0 -1
- package/dist/studio/assets/c-DOHYbsuN.js +0 -1
- package/dist/studio/assets/c3-CnJL0r0V.js +0 -1
- package/dist/studio/assets/cadence-CQ2zXKGN.js +0 -1
- package/dist/studio/assets/cairo-DLTphjLi.js +0 -1
- package/dist/studio/assets/catppuccin-frappe-3VR1Za6u.js +0 -1
- package/dist/studio/assets/catppuccin-latte-DwIHMF0Q.js +0 -1
- package/dist/studio/assets/catppuccin-macchiato-DYnBP6_5.js +0 -1
- package/dist/studio/assets/catppuccin-mocha-DYhrFGRu.js +0 -1
- package/dist/studio/assets/clarity-SemFz856.js +0 -1
- package/dist/studio/assets/clojure-DqKBuwfJ.js +0 -1
- package/dist/studio/assets/cmake-Bj61d0ZC.js +0 -1
- package/dist/studio/assets/cobol-DtGo7U_-.js +0 -1
- package/dist/studio/assets/codeowners-C8r90Shi.js +0 -1
- package/dist/studio/assets/codeql-oeQT6MSM.js +0 -1
- package/dist/studio/assets/coffee-Uf9fkZqI.js +0 -1
- package/dist/studio/assets/common-lisp-Cv5bFMCO.js +0 -1
- package/dist/studio/assets/coq-BrsZFFmf.js +0 -1
- package/dist/studio/assets/cpp-CVwmol0l.js +0 -1
- package/dist/studio/assets/crystal-ChHObCtF.js +0 -1
- package/dist/studio/assets/csharp-Ct8U2NOr.js +0 -1
- package/dist/studio/assets/css-DYjZAj5w.js +0 -1
- package/dist/studio/assets/csv-Dx-8-gkx.js +0 -1
- package/dist/studio/assets/cue-CE9AQfxI.js +0 -1
- package/dist/studio/assets/cypher-ClKdZ_lG.js +0 -1
- package/dist/studio/assets/d-qD-0Kul2.js +0 -1
- package/dist/studio/assets/dark-plus-Cs2F2srj.js +0 -1
- package/dist/studio/assets/dart-DkHntEIa.js +0 -1
- package/dist/studio/assets/dax-BkyTk9wS.js +0 -1
- package/dist/studio/assets/desktop-Dlh5hvp9.js +0 -1
- package/dist/studio/assets/diff-woXpYk--.js +0 -1
- package/dist/studio/assets/docker-IyjqRm3v.js +0 -1
- package/dist/studio/assets/dotenv-_5a1GRtc.js +0 -1
- package/dist/studio/assets/dracula-BHWKrbxM.js +0 -1
- package/dist/studio/assets/dracula-soft-5eyTD99u.js +0 -1
- package/dist/studio/assets/dream-maker-DW3nJb8Q.js +0 -1
- package/dist/studio/assets/edge-C2J43zbu.js +0 -1
- package/dist/studio/assets/elixir-B7WZ8XhB.js +0 -1
- package/dist/studio/assets/elm-PN4qGuR2.js +0 -1
- package/dist/studio/assets/emacs-lisp-C9PiwqqW.js +0 -1
- package/dist/studio/assets/erb-CkbjE2OZ.js +0 -1
- package/dist/studio/assets/erlang-Cphh6RMH.js +0 -1
- package/dist/studio/assets/everforest-dark-sB-x3p7T.js +0 -1
- package/dist/studio/assets/everforest-light-Df2xbC6M.js +0 -1
- package/dist/studio/assets/fennel-DQxkIbk2.js +0 -1
- package/dist/studio/assets/fish-BJitypiv.js +0 -1
- package/dist/studio/assets/fluent-C03EYrpw.js +0 -1
- package/dist/studio/assets/fortran-fixed-form-DEKoE2YW.js +0 -1
- package/dist/studio/assets/fortran-free-form-CYNrtFtB.js +0 -1
- package/dist/studio/assets/fsharp-D13ZGOAj.js +0 -1
- package/dist/studio/assets/gdresource-C0sCabJj.js +0 -1
- package/dist/studio/assets/gdscript-Cp2uCuqX.js +0 -1
- package/dist/studio/assets/gdshader-CBce3t8t.js +0 -1
- package/dist/studio/assets/genie-CV2tkWYe.js +0 -1
- package/dist/studio/assets/gherkin-DExj1W_8.js +0 -1
- package/dist/studio/assets/git-commit-BSykSTBG.js +0 -1
- package/dist/studio/assets/git-rebase-CsGmQhFO.js +0 -1
- package/dist/studio/assets/github-dark-C-LZuMrd.js +0 -1
- package/dist/studio/assets/github-dark-default-DXG-b-1a.js +0 -1
- package/dist/studio/assets/github-dark-dimmed-Bx1FflLF.js +0 -1
- package/dist/studio/assets/github-dark-high-contrast-B_tTalzw.js +0 -1
- package/dist/studio/assets/github-light-EUqPIrTm.js +0 -1
- package/dist/studio/assets/github-light-default-BXViO-2h.js +0 -1
- package/dist/studio/assets/github-light-high-contrast-B68TUdTA.js +0 -1
- package/dist/studio/assets/gleam-CSRkHgEL.js +0 -1
- package/dist/studio/assets/glimmer-js-D85-ZYXa.js +0 -1
- package/dist/studio/assets/glimmer-ts-B_0SLVPe.js +0 -1
- package/dist/studio/assets/glsl-BE5n0T0t.js +0 -1
- package/dist/studio/assets/gn-ilITqXS6.js +0 -1
- package/dist/studio/assets/gnuplot-7GGW24-e.js +0 -1
- package/dist/studio/assets/go-BJwz_mda.js +0 -1
- package/dist/studio/assets/graphql-BVcCJEBO.js +0 -1
- package/dist/studio/assets/groovy-CacY0gHj.js +0 -1
- package/dist/studio/assets/gruvbox-dark-hard-C820rvS2.js +0 -1
- package/dist/studio/assets/gruvbox-dark-medium-BPjhmG05.js +0 -1
- package/dist/studio/assets/gruvbox-dark-soft-MrdJrrXF.js +0 -1
- package/dist/studio/assets/gruvbox-light-hard-BC_s9l72.js +0 -1
- package/dist/studio/assets/gruvbox-light-medium-BAWPOn9u.js +0 -1
- package/dist/studio/assets/gruvbox-light-soft-BSMLrYjP.js +0 -1
- package/dist/studio/assets/hack-CyUu15_C.js +0 -1
- package/dist/studio/assets/haml-Dj54pugT.js +0 -1
- package/dist/studio/assets/handlebars-l3llPaCT.js +0 -1
- package/dist/studio/assets/haskell-D8IpX4py.js +0 -1
- package/dist/studio/assets/haxe-OTjmBuCE.js +0 -1
- package/dist/studio/assets/hcl-Dh228itO.js +0 -1
- package/dist/studio/assets/highlighted-body-OFNGDK62-D_z62he-.js +0 -1
- package/dist/studio/assets/hjson-CxZEssPk.js +0 -1
- package/dist/studio/assets/hlsl-Cvrh5tZx.js +0 -1
- package/dist/studio/assets/horizon-CE9ld1lL.js +0 -1
- package/dist/studio/assets/horizon-bright-Br1oVSNq.js +0 -1
- package/dist/studio/assets/houston-CsvMBhTu.js +0 -1
- package/dist/studio/assets/html--Tmh4628.js +0 -1
- package/dist/studio/assets/html-derivative-B0Q_m8BM.js +0 -1
- package/dist/studio/assets/http-BXKW9YQL.js +0 -1
- package/dist/studio/assets/hurl-C60QjgUE.js +0 -1
- package/dist/studio/assets/hxml-B0Qn7Nwc.js +0 -1
- package/dist/studio/assets/hy-CZbG8q4J.js +0 -1
- package/dist/studio/assets/imba-DsUTQ-LC.js +0 -1
- package/dist/studio/assets/index-Cd4PgOFu.js +0 -390
- package/dist/studio/assets/index-DkGWw6ES.css +0 -2
- package/dist/studio/assets/ini-B5eOa1yu.js +0 -1
- package/dist/studio/assets/java-aXeLcVht.js +0 -1
- package/dist/studio/assets/javascript-BQcRH4fE.js +0 -1
- package/dist/studio/assets/jinja-DGNUkEt-.js +0 -1
- package/dist/studio/assets/jison-DwfSvoKv.js +0 -1
- package/dist/studio/assets/json-B0ukOVyl.js +0 -1
- package/dist/studio/assets/json5-BR5RXkoi.js +0 -1
- package/dist/studio/assets/jsonc-CYpm1nAK.js +0 -1
- package/dist/studio/assets/jsonl-CmCQp5Yx.js +0 -1
- package/dist/studio/assets/jsonnet-CJTPZ8u_.js +0 -1
- package/dist/studio/assets/jssm-DXw9l8Rf.js +0 -1
- package/dist/studio/assets/jsx-CzJUnsSO.js +0 -1
- package/dist/studio/assets/julia-D8zt_FEP.js +0 -1
- package/dist/studio/assets/just-nn4e9Gpd.js +0 -1
- package/dist/studio/assets/kanagawa-dragon-CXtmUGW6.js +0 -1
- package/dist/studio/assets/kanagawa-lotus-BN08jTvb.js +0 -1
- package/dist/studio/assets/kanagawa-wave-CTweb8Dz.js +0 -1
- package/dist/studio/assets/kdl-CsD5j6eV.js +0 -1
- package/dist/studio/assets/kotlin-DhhofPvG.js +0 -1
- package/dist/studio/assets/kusto-BUv0MjJC.js +0 -1
- package/dist/studio/assets/laserwave-C_8bwKvT.js +0 -1
- package/dist/studio/assets/latex-OBwqlec5.js +0 -1
- package/dist/studio/assets/lean-CewbzKMR.js +0 -1
- package/dist/studio/assets/less-DVTAwKKz.js +0 -1
- package/dist/studio/assets/light-plus-DVQuIRkW.js +0 -1
- package/dist/studio/assets/liquid-CktG-Iuw.js +0 -1
- package/dist/studio/assets/llvm-Cm23YOpf.js +0 -1
- package/dist/studio/assets/log-BNLmms1o.js +0 -1
- package/dist/studio/assets/logo-Cluzi2Zq.js +0 -1
- package/dist/studio/assets/lua-ZqavSetL.js +0 -1
- package/dist/studio/assets/luau-CNKltnaQ.js +0 -1
- package/dist/studio/assets/make-Dixweg8N.js +0 -1
- package/dist/studio/assets/markdown-BYOwaDjH.js +0 -1
- package/dist/studio/assets/marko-CxDLRfNz.js +0 -1
- package/dist/studio/assets/material-theme-Bm3Qr25_.js +0 -1
- package/dist/studio/assets/material-theme-darker-2IIEA8gg.js +0 -1
- package/dist/studio/assets/material-theme-lighter-uhdI0v04.js +0 -1
- package/dist/studio/assets/material-theme-ocean-CHQ94UKr.js +0 -1
- package/dist/studio/assets/material-theme-palenight-B5W6OYN7.js +0 -1
- package/dist/studio/assets/matlab-D7qyCx1q.js +0 -1
- package/dist/studio/assets/mdc-COZbBQqS.js +0 -1
- package/dist/studio/assets/mdx-DQZ5AkYe.js +0 -1
- package/dist/studio/assets/mermaid-Bk4SNUv9.js +0 -1
- package/dist/studio/assets/mermaid-GHXKKRXX-ChY6AJ7l.js +0 -1
- package/dist/studio/assets/min-dark-BSWPekZh.js +0 -1
- package/dist/studio/assets/min-light-DDpmG2fV.js +0 -1
- package/dist/studio/assets/mipsasm-BMqwQI7S.js +0 -1
- package/dist/studio/assets/mojo-BgCJLMeH.js +0 -1
- package/dist/studio/assets/monokai-CdkpiU2Y.js +0 -1
- package/dist/studio/assets/moonbit-CaWjb8XO.js +0 -1
- package/dist/studio/assets/move-B1IS1UjX.js +0 -1
- package/dist/studio/assets/narrat-_X_XdTYD.js +0 -1
- package/dist/studio/assets/nextflow-Bbiyy34d.js +0 -1
- package/dist/studio/assets/nextflow-groovy-Dc_ddanL.js +0 -1
- package/dist/studio/assets/nginx-DB8A8-iZ.js +0 -1
- package/dist/studio/assets/night-owl-DhmEMT88.js +0 -1
- package/dist/studio/assets/night-owl-light-eJ-hLW7d.js +0 -1
- package/dist/studio/assets/nim-Cs5VB9QZ.js +0 -1
- package/dist/studio/assets/nix-IvuFDN5E.js +0 -1
- package/dist/studio/assets/nord-Cb4Vim4T.js +0 -1
- package/dist/studio/assets/nushell-DcLAeLz5.js +0 -1
- package/dist/studio/assets/objective-c-D1A_Heim.js +0 -1
- package/dist/studio/assets/objective-cpp-BsSzOQcm.js +0 -1
- package/dist/studio/assets/ocaml-O90oeIOV.js +0 -1
- package/dist/studio/assets/odin-B1RWQWA5.js +0 -1
- package/dist/studio/assets/one-dark-pro-CLwyXe_n.js +0 -1
- package/dist/studio/assets/one-light-D7Lr4KcI.js +0 -1
- package/dist/studio/assets/openscad-BUDT5pXO.js +0 -1
- package/dist/studio/assets/pascal-4ZHwLPI5.js +0 -1
- package/dist/studio/assets/perl-pV-3Dli_.js +0 -1
- package/dist/studio/assets/php-CFSq0mhc.js +0 -1
- package/dist/studio/assets/pkl-ot-7Btpt.js +0 -1
- package/dist/studio/assets/plastic-DQwYfKfQ.js +0 -1
- package/dist/studio/assets/plsql-DGHpHOYJ.js +0 -1
- package/dist/studio/assets/po-BiJDBrnU.js +0 -1
- package/dist/studio/assets/poimandres-DRFjx7u4.js +0 -1
- package/dist/studio/assets/polar-C7UOKdEL.js +0 -1
- package/dist/studio/assets/postcss-BXeXVLqQ.js +0 -1
- package/dist/studio/assets/powerquery-DNMTfnFr.js +0 -1
- package/dist/studio/assets/powershell-DshXNtvi.js +0 -1
- package/dist/studio/assets/prisma-BsRQq5mF.js +0 -1
- package/dist/studio/assets/prolog-iXnhIJG7.js +0 -1
- package/dist/studio/assets/proto-DB4EqR-F.js +0 -1
- package/dist/studio/assets/pug-DuCfu-AK.js +0 -1
- package/dist/studio/assets/puppet-CDv2pdJW.js +0 -1
- package/dist/studio/assets/purescript-9MfHhQsQ.js +0 -1
- package/dist/studio/assets/python-gzcpVVnB.js +0 -1
- package/dist/studio/assets/qml-Gqte1OeW.js +0 -1
- package/dist/studio/assets/qmldir-DCQb3MpD.js +0 -1
- package/dist/studio/assets/qss-Fe1Jh2GI.js +0 -1
- package/dist/studio/assets/r-B8XqafmU.js +0 -1
- package/dist/studio/assets/racket-DcIDlBhZ.js +0 -1
- package/dist/studio/assets/raku-B3gFvitq.js +0 -1
- package/dist/studio/assets/razor-HyK7qWun.js +0 -1
- package/dist/studio/assets/red-CJ3rzSJv.js +0 -1
- package/dist/studio/assets/reg-CRGYupPL.js +0 -1
- package/dist/studio/assets/regexp-Bdipf9Ks.js +0 -1
- package/dist/studio/assets/rel-BtDbiS_P.js +0 -1
- package/dist/studio/assets/riscv-Ckw8ddFX.js +0 -1
- package/dist/studio/assets/ron-VUp2lXgN.js +0 -1
- package/dist/studio/assets/rose-pine-BthvhNj6.js +0 -1
- package/dist/studio/assets/rose-pine-dawn-Dg85fqjY.js +0 -1
- package/dist/studio/assets/rose-pine-moon-hon4tzzS.js +0 -1
- package/dist/studio/assets/rosmsg-CAekHB0j.js +0 -1
- package/dist/studio/assets/rst-DtdOQB-0.js +0 -1
- package/dist/studio/assets/ruby-DOExsDws.js +0 -1
- package/dist/studio/assets/rust-Cfkwpbl8.js +0 -1
- package/dist/studio/assets/sas-BLRRJVWF.js +0 -1
- package/dist/studio/assets/sass-DXrisJhu.js +0 -1
- package/dist/studio/assets/scala-DKOlJaKm.js +0 -1
- package/dist/studio/assets/scheme-DQCgrYNe.js +0 -1
- package/dist/studio/assets/scss-BILH_sWZ.js +0 -1
- package/dist/studio/assets/sdbl-bTVj8UrX.js +0 -1
- package/dist/studio/assets/shaderlab-TOUzSsQk.js +0 -1
- package/dist/studio/assets/shellscript-CC2KTOv4.js +0 -1
- package/dist/studio/assets/shellsession-CiGs-_qT.js +0 -1
- package/dist/studio/assets/slack-dark-DnToyrRv.js +0 -1
- package/dist/studio/assets/slack-ochin-B2OO5cIa.js +0 -1
- package/dist/studio/assets/smalltalk-B16xEiuN.js +0 -1
- package/dist/studio/assets/snazzy-light-4G7pJPwS.js +0 -1
- package/dist/studio/assets/solarized-dark-DV17i1UV.js +0 -1
- package/dist/studio/assets/solarized-light-DSh2HLQt.js +0 -1
- package/dist/studio/assets/solidity-CKzVLygQ.js +0 -1
- package/dist/studio/assets/soy-QSSlYQhf.js +0 -1
- package/dist/studio/assets/sparql-D_iOobhT.js +0 -1
- package/dist/studio/assets/splunk-BC2Px7Mm.js +0 -1
- package/dist/studio/assets/sql-CPD_IP3i.js +0 -1
- package/dist/studio/assets/ssh-config-BgfXC-Er.js +0 -1
- package/dist/studio/assets/stata-jhUDP248.js +0 -1
- package/dist/studio/assets/stylus-B6D30XZt.js +0 -1
- package/dist/studio/assets/surrealql-CEI1vHaO.js +0 -1
- package/dist/studio/assets/svelte-BqMghnvQ.js +0 -1
- package/dist/studio/assets/swift-DonLKvLd.js +0 -1
- package/dist/studio/assets/synthwave-84-nFMaYfgc.js +0 -1
- package/dist/studio/assets/system-verilog-DJ5XKQeo.js +0 -1
- package/dist/studio/assets/systemd-BxMlprV5.js +0 -1
- package/dist/studio/assets/talonscript-CohzipZa.js +0 -1
- package/dist/studio/assets/tasl-DMoTqEGO.js +0 -1
- package/dist/studio/assets/tcl-CZd0xW_V.js +0 -1
- package/dist/studio/assets/templ-DhMt3Gd_.js +0 -1
- package/dist/studio/assets/terraform-DswuEJGm.js +0 -1
- package/dist/studio/assets/tex-B2oLGu4M.js +0 -1
- package/dist/studio/assets/tokyo-night-oM2G3aXe.js +0 -1
- package/dist/studio/assets/toml-CcmNWLt0.js +0 -1
- package/dist/studio/assets/ts-tags-DbXbAuWo.js +0 -1
- package/dist/studio/assets/tsv-sltzmVWM.js +0 -1
- package/dist/studio/assets/tsx-BWdjt-eB.js +0 -1
- package/dist/studio/assets/turtle-ByJddavk.js +0 -1
- package/dist/studio/assets/twig-b7sZE9-Z.js +0 -1
- package/dist/studio/assets/typescript-B5gQukXY.js +0 -1
- package/dist/studio/assets/typespec-B88KGewJ.js +0 -1
- package/dist/studio/assets/typst-DI99ib-x.js +0 -1
- package/dist/studio/assets/v-DETTlOr0.js +0 -1
- package/dist/studio/assets/vala-zf12oZj6.js +0 -1
- package/dist/studio/assets/vb-Djn5o6TS.js +0 -1
- package/dist/studio/assets/verilog-CiiDBU1e.js +0 -1
- package/dist/studio/assets/vesper-D5bVUKB1.js +0 -1
- package/dist/studio/assets/vhdl-BroJfC0k.js +0 -1
- package/dist/studio/assets/viml-DvXPmvsu.js +0 -1
- package/dist/studio/assets/vitesse-black-fwtXNY1n.js +0 -1
- package/dist/studio/assets/vitesse-dark-BZCL-v6S.js +0 -1
- package/dist/studio/assets/vitesse-light-VbXTXTou.js +0 -1
- package/dist/studio/assets/vue-DGv3yRD9.js +0 -1
- package/dist/studio/assets/vue-html-Cx5Ph-Io.js +0 -1
- package/dist/studio/assets/vue-vine-G05O51ag.js +0 -1
- package/dist/studio/assets/vyper-CgoNMtux.js +0 -1
- package/dist/studio/assets/wasm-BnjxR4X6.js +0 -1
- package/dist/studio/assets/wasm-ByWQv1Qj.js +0 -1
- package/dist/studio/assets/wenyan-C8pVoKbM.js +0 -1
- package/dist/studio/assets/wgsl-BsKzXJz4.js +0 -1
- package/dist/studio/assets/wikitext-ClFFjSW2.js +0 -1
- package/dist/studio/assets/wit-DdvCle-K.js +0 -1
- package/dist/studio/assets/wolfram-DLL8P-h_.js +0 -1
- package/dist/studio/assets/xml-Bd8eSLdt.js +0 -1
- package/dist/studio/assets/xsl-DVLXYJQL.js +0 -1
- package/dist/studio/assets/yaml-CO0sPwby.js +0 -1
- package/dist/studio/assets/zenscript-BnlCZFoB.js +0 -1
- package/dist/studio/assets/zig-CMLA9XwU.js +0 -1
- package/dist/studio/index.html +0 -23
- package/dist/types-codegen-C-9yeFao.js +0 -101
- package/dist/types-codegen-C-9yeFao.js.map +0 -1
- package/dist/vite.d.ts +0 -46
- package/dist/vite.js +0 -193
- package/dist/vite.js.map +0 -1
package/dist/cli/index.js
DELETED
|
@@ -1,1304 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { a as readWranglerConfig, c as createThinkWorkerConfig, h as discoverThinkApp, i as readProjectFiles, m as summarizeThinkManifest, n as createThinkProject, o as resolveThinkManifest, t as applyUserBindingNames } from "../project-BHurFdu4.js";
|
|
3
|
-
import { n as isThinkGeneratedFile, t as generateThinkTypes } from "../types-codegen-C-9yeFao.js";
|
|
4
|
-
import { CHAT_MESSAGE_TYPES } from "agents/chat";
|
|
5
|
-
import { access, mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import yargs from "yargs";
|
|
8
|
-
import { hideBin } from "yargs/helpers";
|
|
9
|
-
import { fileExists, gitOutcomeMessage, initCommand, initializeGit, looksLikeThinkApp, packageName, readTextIfExists, runNpmInstall } from "create-think";
|
|
10
|
-
import { AgentClient } from "agents/client";
|
|
11
|
-
import { spawn } from "node:child_process";
|
|
12
|
-
import { createReadStream } from "node:fs";
|
|
13
|
-
import { createServer } from "node:http";
|
|
14
|
-
import { fileURLToPath } from "node:url";
|
|
15
|
-
//#region src/cli/init.ts
|
|
16
|
-
const VITE_CONFIG_FILES = [
|
|
17
|
-
"vite.config.ts",
|
|
18
|
-
"vite.config.mts",
|
|
19
|
-
"vite.config.js",
|
|
20
|
-
"vite.config.mjs"
|
|
21
|
-
];
|
|
22
|
-
/**
|
|
23
|
-
* `think init` has two modes:
|
|
24
|
-
*
|
|
25
|
-
* - New project: when a `--template` is given, or when the command is run
|
|
26
|
-
* outside an existing npm project. Delegates to `create-think`, which fetches
|
|
27
|
-
* a complete starter template (no framework dependency required at runtime).
|
|
28
|
-
* - Augment in place: when run inside an existing npm project with no
|
|
29
|
-
* `--template`. Adds Think framework files (agent, Vite/Wrangler config,
|
|
30
|
-
* generated types) and merges dependencies into the current project.
|
|
31
|
-
*/
|
|
32
|
-
async function initCommand$1(options) {
|
|
33
|
-
const baseRoot = path.resolve(options.root ?? process.cwd());
|
|
34
|
-
const insideExistingProject = !options.directory && await fileExists(path.join(baseRoot, "package.json"));
|
|
35
|
-
if (Boolean(options.template) || !insideExistingProject) {
|
|
36
|
-
await initCommand(options);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
await augmentExistingProject(baseRoot, options);
|
|
40
|
-
}
|
|
41
|
-
async function augmentExistingProject(root, options) {
|
|
42
|
-
const projectName = packageName(options.name ?? path.basename(root));
|
|
43
|
-
if (await looksLikeThinkApp(root)) {
|
|
44
|
-
console.log(["This already looks like a Think app.", "Try `think inspect` to review the manifest or `think types` to refresh generated declarations."].join("\n"));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const migrationReason = await unsafeMigrationReason(root);
|
|
48
|
-
if (migrationReason) throw new Error([
|
|
49
|
-
"This directory already has Vite or Wrangler configuration, so `think init` will not migrate it automatically yet.",
|
|
50
|
-
migrationReason,
|
|
51
|
-
"Start a new Think app with `npm create think`, or add `@cloudflare/think/vite` and Think framework files manually."
|
|
52
|
-
].join("\n"));
|
|
53
|
-
const plan = await createInitPlan({
|
|
54
|
-
root,
|
|
55
|
-
projectName,
|
|
56
|
-
routePrefix: options.routePrefix
|
|
57
|
-
});
|
|
58
|
-
const skipped = await existingPlanFiles(plan);
|
|
59
|
-
if (options.dryRun) {
|
|
60
|
-
printDryRun(plan, skipped, options.install ?? true);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
await writePlannedFiles(plan, skipped);
|
|
64
|
-
const gitOutcome = await initializeGit(root, {
|
|
65
|
-
gitRunner: options.gitRunner,
|
|
66
|
-
isInsideGitRepo: options.isInsideGitRepo
|
|
67
|
-
});
|
|
68
|
-
if (options.install ?? true) await (options.installRunner ?? runNpmInstall)(root);
|
|
69
|
-
printSuccess(plan, skipped, options.install ?? true, gitOutcome);
|
|
70
|
-
}
|
|
71
|
-
async function createInitPlan(options) {
|
|
72
|
-
const sourceFiles = {
|
|
73
|
-
"agents/assistant/agent.ts": agentSource(),
|
|
74
|
-
"agents/assistant/skills/project-helper/SKILL.md": starterSkillSource()
|
|
75
|
-
};
|
|
76
|
-
const manifest = discoverThinkApp({
|
|
77
|
-
root: options.root,
|
|
78
|
-
routePrefix: options.routePrefix,
|
|
79
|
-
files: sourceFiles
|
|
80
|
-
});
|
|
81
|
-
const workerConfig = createThinkWorkerConfig(manifest, {
|
|
82
|
-
name: options.projectName,
|
|
83
|
-
routePrefix: options.routePrefix
|
|
84
|
-
});
|
|
85
|
-
workerConfig.ai = { binding: "AI" };
|
|
86
|
-
workerConfig.worker_loaders = [{ binding: "LOADER" }];
|
|
87
|
-
const typeFiles = generateThinkTypes(manifest, {
|
|
88
|
-
files: sourceFiles,
|
|
89
|
-
typesFile: "think.d.ts"
|
|
90
|
-
});
|
|
91
|
-
return {
|
|
92
|
-
root: options.root,
|
|
93
|
-
projectName: options.projectName,
|
|
94
|
-
packageJsonPath: "package.json",
|
|
95
|
-
files: [
|
|
96
|
-
{
|
|
97
|
-
path: "package.json",
|
|
98
|
-
content: packageJsonSource(options.projectName),
|
|
99
|
-
merge: "package-json"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
path: "vite.config.ts",
|
|
103
|
-
content: viteConfig(options.routePrefix)
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
path: "wrangler.jsonc",
|
|
107
|
-
content: `${JSON.stringify(workerConfig, null, 2)}\n`
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
path: "tsconfig.json",
|
|
111
|
-
content: tsconfig()
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
path: ".gitignore",
|
|
115
|
-
content: gitignore()
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
path: ".oxlintrc.json",
|
|
119
|
-
content: oxlintConfig()
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
path: ".oxfmtrc.json",
|
|
123
|
-
content: oxfmtConfig()
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
path: "agents/assistant/agent.ts",
|
|
127
|
-
content: sourceFiles["agents/assistant/agent.ts"]
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
path: "agents/assistant/skills/project-helper/SKILL.md",
|
|
131
|
-
content: sourceFiles["agents/assistant/skills/project-helper/SKILL.md"]
|
|
132
|
-
},
|
|
133
|
-
...typeFiles
|
|
134
|
-
]
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
async function existingPlanFiles(plan) {
|
|
138
|
-
const existing = /* @__PURE__ */ new Set();
|
|
139
|
-
for (const file of plan.files) {
|
|
140
|
-
if (file.merge === "package-json") continue;
|
|
141
|
-
if (await fileExists(path.join(plan.root, file.path))) existing.add(file.path);
|
|
142
|
-
}
|
|
143
|
-
return existing;
|
|
144
|
-
}
|
|
145
|
-
async function writePlannedFiles(plan, skip) {
|
|
146
|
-
await mkdir(plan.root, { recursive: true });
|
|
147
|
-
for (const file of plan.files) {
|
|
148
|
-
if (skip.has(file.path)) continue;
|
|
149
|
-
const absolute = path.join(plan.root, file.path);
|
|
150
|
-
await mkdir(path.dirname(absolute), { recursive: true });
|
|
151
|
-
await writeFile(absolute, file.merge === "package-json" ? await mergePackageJson(absolute, file.content) : file.content, "utf8");
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
async function mergePackageJson(absolutePath, generatedContent) {
|
|
155
|
-
const generated = JSON.parse(generatedContent);
|
|
156
|
-
const existingSource = await readTextIfExists(absolutePath);
|
|
157
|
-
if (!existingSource) return generatedContent;
|
|
158
|
-
const existing = JSON.parse(existingSource);
|
|
159
|
-
return `${JSON.stringify(mergePackageJsonData(existing, generated), null, 2)}\n`;
|
|
160
|
-
}
|
|
161
|
-
function mergePackageJsonData(existing, generated) {
|
|
162
|
-
return {
|
|
163
|
-
...generated,
|
|
164
|
-
...existing,
|
|
165
|
-
type: generated.type ?? existing.type,
|
|
166
|
-
scripts: {
|
|
167
|
-
...generated.scripts,
|
|
168
|
-
...existing.scripts
|
|
169
|
-
},
|
|
170
|
-
dependencies: {
|
|
171
|
-
...generated.dependencies,
|
|
172
|
-
...existing.dependencies
|
|
173
|
-
},
|
|
174
|
-
devDependencies: {
|
|
175
|
-
...generated.devDependencies,
|
|
176
|
-
...existing.devDependencies
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
async function unsafeMigrationReason(root) {
|
|
181
|
-
for (const file of [
|
|
182
|
-
...VITE_CONFIG_FILES,
|
|
183
|
-
"wrangler.jsonc",
|
|
184
|
-
"wrangler.json",
|
|
185
|
-
"wrangler.toml"
|
|
186
|
-
]) if (await fileExists(path.join(root, file))) return `Found existing ${file}.`;
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
function printDryRun(plan, skipped, install) {
|
|
190
|
-
const lines = ["Think init would add to the current project:", ...plan.files.filter((file) => !skipped.has(file.path)).map((file) => `- ${file.path}`)];
|
|
191
|
-
if (skipped.size > 0) lines.push("", "Would keep your existing files (left unchanged):", ...[...skipped].map((file) => `- ${file}`));
|
|
192
|
-
lines.push("Would initialize a git repository (skipped if already inside one).", install ? "Would run: npm install" : "Would skip dependency install.");
|
|
193
|
-
console.log(lines.join("\n"));
|
|
194
|
-
}
|
|
195
|
-
function printSuccess(plan, skipped, install, gitOutcome) {
|
|
196
|
-
const lines = [
|
|
197
|
-
`Added Think to ${plan.root}.`,
|
|
198
|
-
gitOutcomeMessage(gitOutcome),
|
|
199
|
-
install ? "Installed npm dependencies." : "Skipped npm install."
|
|
200
|
-
];
|
|
201
|
-
if (skipped.size > 0) lines.push("", "Kept your existing files (not overwritten):", ...[...skipped].map((file) => `- ${file}`), "Reconcile them with Think's expected setup if the app does not build.");
|
|
202
|
-
lines.push("", "Next steps:", "- Edit agents/assistant/agent.ts to customize the model, prompt, skills, and schedules", "- npm run dev", "- npm run types", "- npm run deploy");
|
|
203
|
-
console.log(lines.join("\n"));
|
|
204
|
-
}
|
|
205
|
-
const FRAMEWORK_DEPENDENCIES = {
|
|
206
|
-
"@cloudflare/think": "latest",
|
|
207
|
-
agents: "latest"
|
|
208
|
-
};
|
|
209
|
-
const THIRD_PARTY_DEPENDENCIES = { ai: "^7.0.0" };
|
|
210
|
-
const THIRD_PARTY_DEV_DEPENDENCIES = {
|
|
211
|
-
"@cloudflare/vite-plugin": "^1.42.3",
|
|
212
|
-
"@cloudflare/workers-types": "^4.20260629.1",
|
|
213
|
-
oxfmt: "^0.56.0",
|
|
214
|
-
oxlint: "^1.71.0",
|
|
215
|
-
typescript: "^6.0.3",
|
|
216
|
-
vite: "^8.1.0",
|
|
217
|
-
wrangler: "^4.105.0"
|
|
218
|
-
};
|
|
219
|
-
function packageJsonSource(projectName) {
|
|
220
|
-
return `${JSON.stringify({
|
|
221
|
-
name: projectName,
|
|
222
|
-
private: true,
|
|
223
|
-
type: "module",
|
|
224
|
-
scripts: {
|
|
225
|
-
dev: "vite dev",
|
|
226
|
-
build: "vite build",
|
|
227
|
-
deploy: "vite build && wrangler deploy",
|
|
228
|
-
types: "think types --all",
|
|
229
|
-
format: "oxfmt --write .",
|
|
230
|
-
"format:check": "oxfmt --check .",
|
|
231
|
-
lint: "oxlint .",
|
|
232
|
-
typecheck: "tsc --noEmit",
|
|
233
|
-
check: "npm run format:check && npm run lint && npm run typecheck"
|
|
234
|
-
},
|
|
235
|
-
dependencies: {
|
|
236
|
-
...FRAMEWORK_DEPENDENCIES,
|
|
237
|
-
...THIRD_PARTY_DEPENDENCIES
|
|
238
|
-
},
|
|
239
|
-
devDependencies: { ...THIRD_PARTY_DEV_DEPENDENCIES }
|
|
240
|
-
}, null, 2)}\n`;
|
|
241
|
-
}
|
|
242
|
-
function viteConfig(routePrefix) {
|
|
243
|
-
return [
|
|
244
|
-
`import { cloudflare } from "@cloudflare/vite-plugin";`,
|
|
245
|
-
`import { think } from "@cloudflare/think/vite";`,
|
|
246
|
-
`import { defineConfig } from "vite";`,
|
|
247
|
-
"",
|
|
248
|
-
"export default defineConfig({",
|
|
249
|
-
` plugins: [think${routePrefix ? `({ routePrefix: ${JSON.stringify(routePrefix)} })` : "()"}, cloudflare()]`,
|
|
250
|
-
"});",
|
|
251
|
-
""
|
|
252
|
-
].join("\n");
|
|
253
|
-
}
|
|
254
|
-
function agentSource() {
|
|
255
|
-
return [
|
|
256
|
-
`import { Think, skills } from "@cloudflare/think";`,
|
|
257
|
-
`import bundledSkills from "agents:skills";`,
|
|
258
|
-
"",
|
|
259
|
-
"export class Assistant extends Think<Env> {",
|
|
260
|
-
" override getModel() {",
|
|
261
|
-
" // Resolved via the built-in workers-ai-provider off env.AI. Use a",
|
|
262
|
-
" // \"@cf/...\" id for Workers AI, or a \"provider/model\" slug like",
|
|
263
|
-
" // \"openai/gpt-5.5\" to route through AI Gateway.",
|
|
264
|
-
" return \"@cf/moonshotai/kimi-k2.7-code\";",
|
|
265
|
-
" }",
|
|
266
|
-
"",
|
|
267
|
-
" override getSystemPrompt() {",
|
|
268
|
-
" return \"You are a helpful assistant. Keep answers clear, practical, and concise.\";",
|
|
269
|
-
" }",
|
|
270
|
-
"",
|
|
271
|
-
" override getSkills() {",
|
|
272
|
-
" return [bundledSkills];",
|
|
273
|
-
" }",
|
|
274
|
-
"",
|
|
275
|
-
" override getSkillScriptRunner() {",
|
|
276
|
-
" return skills.runner({",
|
|
277
|
-
" loader: this.env.LOADER,",
|
|
278
|
-
" workspaceInstance: this.workspace",
|
|
279
|
-
" });",
|
|
280
|
-
" }",
|
|
281
|
-
"}",
|
|
282
|
-
""
|
|
283
|
-
].join("\n");
|
|
284
|
-
}
|
|
285
|
-
function starterSkillSource() {
|
|
286
|
-
return [
|
|
287
|
-
"---",
|
|
288
|
-
"name: project-helper",
|
|
289
|
-
"description: Help users plan and explain small project changes. Use when the user asks for implementation guidance, debugging steps, or a concise project plan.",
|
|
290
|
-
"---",
|
|
291
|
-
"",
|
|
292
|
-
"# Project Helper",
|
|
293
|
-
"",
|
|
294
|
-
"Use this skill to give practical, action-oriented project help.",
|
|
295
|
-
"",
|
|
296
|
-
"## Instructions",
|
|
297
|
-
"",
|
|
298
|
-
"1. Restate the user's goal in one sentence.",
|
|
299
|
-
"2. Identify the smallest useful next step.",
|
|
300
|
-
"3. Call out any important risk or missing context.",
|
|
301
|
-
"4. Keep the answer concise and easy to act on.",
|
|
302
|
-
""
|
|
303
|
-
].join("\n");
|
|
304
|
-
}
|
|
305
|
-
function tsconfig() {
|
|
306
|
-
return `${JSON.stringify({
|
|
307
|
-
compilerOptions: {
|
|
308
|
-
target: "ES2021",
|
|
309
|
-
module: "ES2022",
|
|
310
|
-
moduleResolution: "bundler",
|
|
311
|
-
strict: true,
|
|
312
|
-
verbatimModuleSyntax: true,
|
|
313
|
-
types: ["@cloudflare/workers-types"]
|
|
314
|
-
},
|
|
315
|
-
include: [
|
|
316
|
-
"agents",
|
|
317
|
-
"think.d.ts",
|
|
318
|
-
"vite.config.ts"
|
|
319
|
-
]
|
|
320
|
-
}, null, 2)}\n`;
|
|
321
|
-
}
|
|
322
|
-
function gitignore() {
|
|
323
|
-
return `# Logs
|
|
324
|
-
logs
|
|
325
|
-
*.log
|
|
326
|
-
npm-debug.log*
|
|
327
|
-
yarn-debug.log*
|
|
328
|
-
yarn-error.log*
|
|
329
|
-
lerna-debug.log*
|
|
330
|
-
|
|
331
|
-
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
332
|
-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
333
|
-
|
|
334
|
-
# Runtime data
|
|
335
|
-
pids
|
|
336
|
-
*.pid
|
|
337
|
-
*.seed
|
|
338
|
-
*.pid.lock
|
|
339
|
-
|
|
340
|
-
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
341
|
-
lib-cov
|
|
342
|
-
|
|
343
|
-
# Coverage directory used by tools like istanbul
|
|
344
|
-
coverage
|
|
345
|
-
*.lcov
|
|
346
|
-
|
|
347
|
-
# nyc test coverage
|
|
348
|
-
.nyc_output
|
|
349
|
-
|
|
350
|
-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
351
|
-
.grunt
|
|
352
|
-
|
|
353
|
-
# Bower dependency directory (https://bower.io/)
|
|
354
|
-
bower_components
|
|
355
|
-
|
|
356
|
-
# node-waf configuration
|
|
357
|
-
.lock-wscript
|
|
358
|
-
|
|
359
|
-
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
360
|
-
build/Release
|
|
361
|
-
|
|
362
|
-
# Dependency directories
|
|
363
|
-
node_modules/
|
|
364
|
-
jspm_packages/
|
|
365
|
-
|
|
366
|
-
# Snowpack dependency directory (https://snowpack.dev/)
|
|
367
|
-
web_modules/
|
|
368
|
-
|
|
369
|
-
# TypeScript cache
|
|
370
|
-
*.tsbuildinfo
|
|
371
|
-
|
|
372
|
-
# Optional npm cache directory
|
|
373
|
-
.npm
|
|
374
|
-
|
|
375
|
-
# Optional eslint cache
|
|
376
|
-
.eslintcache
|
|
377
|
-
|
|
378
|
-
# Optional stylelint cache
|
|
379
|
-
.stylelintcache
|
|
380
|
-
|
|
381
|
-
# Optional REPL history
|
|
382
|
-
.node_repl_history
|
|
383
|
-
|
|
384
|
-
# Output of 'npm pack'
|
|
385
|
-
*.tgz
|
|
386
|
-
|
|
387
|
-
# Yarn Integrity file
|
|
388
|
-
.yarn-integrity
|
|
389
|
-
|
|
390
|
-
# dotenv environment variable files
|
|
391
|
-
.env
|
|
392
|
-
.env.*
|
|
393
|
-
!.env.example
|
|
394
|
-
|
|
395
|
-
# parcel-bundler cache (https://parceljs.org/)
|
|
396
|
-
.cache
|
|
397
|
-
.parcel-cache
|
|
398
|
-
|
|
399
|
-
# Next.js build output
|
|
400
|
-
.next
|
|
401
|
-
out
|
|
402
|
-
|
|
403
|
-
# Nuxt.js build / generate output
|
|
404
|
-
.nuxt
|
|
405
|
-
dist
|
|
406
|
-
.output
|
|
407
|
-
|
|
408
|
-
# Gatsby files
|
|
409
|
-
.cache/
|
|
410
|
-
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
411
|
-
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
412
|
-
# public
|
|
413
|
-
|
|
414
|
-
# vuepress build output
|
|
415
|
-
.vuepress/dist
|
|
416
|
-
|
|
417
|
-
# vuepress v2.x temp directory
|
|
418
|
-
.temp
|
|
419
|
-
|
|
420
|
-
# Sveltekit cache directory
|
|
421
|
-
.svelte-kit/
|
|
422
|
-
|
|
423
|
-
# vitepress build output
|
|
424
|
-
**/.vitepress/dist
|
|
425
|
-
|
|
426
|
-
# vitepress cache directory
|
|
427
|
-
**/.vitepress/cache
|
|
428
|
-
|
|
429
|
-
# Docusaurus cache and generated files
|
|
430
|
-
.docusaurus
|
|
431
|
-
|
|
432
|
-
# Serverless directories
|
|
433
|
-
.serverless/
|
|
434
|
-
|
|
435
|
-
# FuseBox cache
|
|
436
|
-
.fusebox/
|
|
437
|
-
|
|
438
|
-
# DynamoDB Local files
|
|
439
|
-
.dynamodb/
|
|
440
|
-
|
|
441
|
-
# Firebase cache directory
|
|
442
|
-
.firebase/
|
|
443
|
-
|
|
444
|
-
# TernJS port file
|
|
445
|
-
.tern-port
|
|
446
|
-
|
|
447
|
-
# Stores VSCode versions used for testing VSCode extensions
|
|
448
|
-
.vscode-test
|
|
449
|
-
|
|
450
|
-
# pnpm
|
|
451
|
-
.pnpm-store
|
|
452
|
-
|
|
453
|
-
# yarn v3
|
|
454
|
-
.pnp.*
|
|
455
|
-
.yarn/*
|
|
456
|
-
!.yarn/patches
|
|
457
|
-
!.yarn/plugins
|
|
458
|
-
!.yarn/releases
|
|
459
|
-
!.yarn/sdks
|
|
460
|
-
!.yarn/versions
|
|
461
|
-
|
|
462
|
-
# Vite files
|
|
463
|
-
vite.config.js.timestamp-*
|
|
464
|
-
vite.config.ts.timestamp-*
|
|
465
|
-
.vite/
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
.wrangler
|
|
469
|
-
.dev.vars
|
|
470
|
-
.DS_Store
|
|
471
|
-
`;
|
|
472
|
-
}
|
|
473
|
-
function oxlintConfig() {
|
|
474
|
-
return `${JSON.stringify({
|
|
475
|
-
$schema: "./node_modules/oxlint/configuration_schema.json",
|
|
476
|
-
plugins: [
|
|
477
|
-
"react",
|
|
478
|
-
"jsx-a11y",
|
|
479
|
-
"typescript"
|
|
480
|
-
],
|
|
481
|
-
categories: { correctness: "error" },
|
|
482
|
-
rules: {
|
|
483
|
-
"no-explicit-any": "error",
|
|
484
|
-
"typescript/no-deprecated": "warn",
|
|
485
|
-
"react-hooks/exhaustive-deps": "warn",
|
|
486
|
-
"no-unused-vars": ["error", {
|
|
487
|
-
argsIgnorePattern: "^_",
|
|
488
|
-
varsIgnorePattern: "^_",
|
|
489
|
-
caughtErrorsIgnorePattern: "^_"
|
|
490
|
-
}]
|
|
491
|
-
},
|
|
492
|
-
ignorePatterns: ["**/env.d.ts", "**/think.d.ts"]
|
|
493
|
-
}, null, 2)}\n`;
|
|
494
|
-
}
|
|
495
|
-
function oxfmtConfig() {
|
|
496
|
-
return `${JSON.stringify({
|
|
497
|
-
$schema: "./node_modules/oxfmt/configuration_schema.json",
|
|
498
|
-
trailingComma: "none",
|
|
499
|
-
printWidth: 80,
|
|
500
|
-
experimentalSortPackageJson: false,
|
|
501
|
-
ignorePatterns: ["**/think.d.ts"]
|
|
502
|
-
}, null, 2)}\n`;
|
|
503
|
-
}
|
|
504
|
-
//#endregion
|
|
505
|
-
//#region src/cli/inspect.ts
|
|
506
|
-
async function inspectCommand(options) {
|
|
507
|
-
const root = path.resolve(options.root ?? process.cwd());
|
|
508
|
-
const project = await createThinkProject({
|
|
509
|
-
routePrefix: options.routePrefix,
|
|
510
|
-
allowNonVirtualMain: options.allowNonVirtualMain
|
|
511
|
-
}, root);
|
|
512
|
-
if (options.json) {
|
|
513
|
-
console.log(JSON.stringify({
|
|
514
|
-
root,
|
|
515
|
-
manifest: project.manifest,
|
|
516
|
-
workerConfig: project.workerConfig,
|
|
517
|
-
diagnostics: project.diagnostics,
|
|
518
|
-
wranglerConfig: {
|
|
519
|
-
path: project.wranglerConfig.path,
|
|
520
|
-
parsed: Boolean(project.wranglerConfig.config),
|
|
521
|
-
error: project.wranglerConfig.error
|
|
522
|
-
}
|
|
523
|
-
}, null, 2));
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const lines = [
|
|
527
|
-
"Think inspect",
|
|
528
|
-
`Root: ${root}`,
|
|
529
|
-
"",
|
|
530
|
-
...summarizeThinkManifest(project.manifest),
|
|
531
|
-
"",
|
|
532
|
-
`Route prefix: ${project.manifest.routePrefix}`,
|
|
533
|
-
`App entry: ${project.manifest.appEntrypoint ?? "none"}`,
|
|
534
|
-
`Wrangler config: ${project.wranglerConfig.path ?? "not found"}`,
|
|
535
|
-
"",
|
|
536
|
-
"Features:",
|
|
537
|
-
...formatFeatures(project.manifest),
|
|
538
|
-
"",
|
|
539
|
-
"Route surfaces:",
|
|
540
|
-
...formatRouteSurfaces(project.manifest.routeSurfaces),
|
|
541
|
-
"",
|
|
542
|
-
"Schedules:",
|
|
543
|
-
...formatNamedFacts(project.manifest.schedules),
|
|
544
|
-
"",
|
|
545
|
-
"Messengers:",
|
|
546
|
-
...formatNamedFacts(project.manifest.messengers),
|
|
547
|
-
"",
|
|
548
|
-
"Tools:",
|
|
549
|
-
...formatNamedFacts(project.manifest.tools),
|
|
550
|
-
"",
|
|
551
|
-
"Platform requirements:",
|
|
552
|
-
...formatPlatformRequirements(project.manifest),
|
|
553
|
-
"",
|
|
554
|
-
"Expected top-level Durable Objects:",
|
|
555
|
-
...formatBindings(project.manifest.bindings),
|
|
556
|
-
"",
|
|
557
|
-
"Diagnostics:",
|
|
558
|
-
...formatDiagnostics(project.diagnostics)
|
|
559
|
-
];
|
|
560
|
-
if (project.wranglerConfig.error) lines.push("", `[warning] ${project.wranglerConfig.error}`);
|
|
561
|
-
console.log(lines.join("\n"));
|
|
562
|
-
}
|
|
563
|
-
function formatBindings(bindings) {
|
|
564
|
-
if (bindings.length === 0) return ["- none"];
|
|
565
|
-
return bindings.map((binding) => `- ${binding.name} -> class ${binding.className}`);
|
|
566
|
-
}
|
|
567
|
-
function formatFeatures(manifest) {
|
|
568
|
-
if (manifest.features.length === 0) return ["- none"];
|
|
569
|
-
return manifest.agents.flatMap((agent) => {
|
|
570
|
-
if (agent.features.length === 0 && agent.env.length === 0) return [];
|
|
571
|
-
return [`- ${agent.id}: ${[agent.features.length ? `features ${agent.features.join(", ")}` : null, agent.env.length ? `env ${agent.env.join(", ")}` : null].filter(Boolean).join(" | ") || "none"}`];
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
function formatRouteSurfaces(surfaces) {
|
|
575
|
-
if (surfaces.length === 0) return ["- none"];
|
|
576
|
-
return surfaces.map((surface) => `- ${surface.kind} ${surface.id}: ${surface.pattern}${surface.requiredRunWorkerFirst ? " | requires run_worker_first" : ""}`);
|
|
577
|
-
}
|
|
578
|
-
function formatNamedFacts(facts) {
|
|
579
|
-
if (facts.length === 0) return ["- none"];
|
|
580
|
-
return facts.map((fact) => `- ${fact.id}${fact.agent ? ` | agent ${fact.agent}` : ""}${fact.sourcePath ? ` | ${fact.sourcePath}` : ""}`);
|
|
581
|
-
}
|
|
582
|
-
function formatPlatformRequirements(manifest) {
|
|
583
|
-
if (manifest.platformRequirements.length === 0) return ["- none"];
|
|
584
|
-
return manifest.platformRequirements.map((requirement) => `- ${requirement.kind} ${requirement.binding}${requirement.agent ? ` | agent ${requirement.agent}` : ""} | ${requirement.reason}`);
|
|
585
|
-
}
|
|
586
|
-
function formatDiagnostics(diagnostics) {
|
|
587
|
-
if (diagnostics.length === 0) return ["- none"];
|
|
588
|
-
return diagnostics.map((diagnostic) => `- ${severityLabel(diagnostic.severity)} [${diagnostic.code}] ${diagnostic.message}`);
|
|
589
|
-
}
|
|
590
|
-
function severityLabel(severity) {
|
|
591
|
-
return severity.toUpperCase();
|
|
592
|
-
}
|
|
593
|
-
//#endregion
|
|
594
|
-
//#region src/cli/target.ts
|
|
595
|
-
/**
|
|
596
|
-
* Browser-safe, IO-free helpers for turning loose connection inputs (a remote
|
|
597
|
-
* `url` or a local `host`, an agent id, an instance, a token, extra query
|
|
598
|
-
* params) into the concrete `{ host, protocol, basePath, query }` an
|
|
599
|
-
* `AgentClient`/`useAgent` needs.
|
|
600
|
-
*
|
|
601
|
-
* This module is deliberately dependency-free so it can be imported by both the
|
|
602
|
-
* Node-side runtime CLI (`connect.ts`) and the browser Studio app. The
|
|
603
|
-
* manifest-aware resolution (friendly agent ids/aliases) lives in `connect.ts`;
|
|
604
|
-
* everything here is pure string math.
|
|
605
|
-
*/
|
|
606
|
-
/**
|
|
607
|
-
* Mirror the default `routeAgentRequest` segment derivation so a raw agent name
|
|
608
|
-
* (e.g. a class name) maps to the same route the server exposes.
|
|
609
|
-
*/
|
|
610
|
-
function camelCaseToKebabCase(str) {
|
|
611
|
-
if (str === str.toUpperCase() && str !== str.toLowerCase()) return str.toLowerCase().replace(/_/g, "-");
|
|
612
|
-
let kebabified = str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
613
|
-
kebabified = kebabified.startsWith("-") ? kebabified.slice(1) : kebabified;
|
|
614
|
-
return kebabified.replace(/_/g, "-").replace(/-$/, "");
|
|
615
|
-
}
|
|
616
|
-
/** Normalize a route prefix to a slash-free segment (default `agents`). */
|
|
617
|
-
function normalizeRoutePrefix(routePrefix) {
|
|
618
|
-
return (routePrefix ?? "/agents").replace(/^\/+|\/+$/g, "") || "agents";
|
|
619
|
-
}
|
|
620
|
-
function parseQuery(query, token) {
|
|
621
|
-
const result = {};
|
|
622
|
-
if (token) result.token = token;
|
|
623
|
-
if (!query) return result;
|
|
624
|
-
if (Array.isArray(query)) {
|
|
625
|
-
for (const pair of query) {
|
|
626
|
-
const eq = pair.indexOf("=");
|
|
627
|
-
if (eq <= 0) throw new Error(`Invalid query "${pair}" (expected key=value).`);
|
|
628
|
-
result[pair.slice(0, eq)] = pair.slice(eq + 1);
|
|
629
|
-
}
|
|
630
|
-
return result;
|
|
631
|
-
}
|
|
632
|
-
for (const [key, value] of Object.entries(query)) result[key] = value;
|
|
633
|
-
return result;
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Resolve host/protocol/basePath/query from loose inputs. Pure (no IO), so it
|
|
637
|
-
* is safe in the browser and trivially unit-testable.
|
|
638
|
-
*/
|
|
639
|
-
function deriveWsTarget(input) {
|
|
640
|
-
const instance = input.instance?.trim() || "default";
|
|
641
|
-
const prefix = normalizeRoutePrefix(input.routePrefix);
|
|
642
|
-
let host;
|
|
643
|
-
let protocol;
|
|
644
|
-
if (input.url) {
|
|
645
|
-
let origin;
|
|
646
|
-
try {
|
|
647
|
-
origin = new URL(input.url);
|
|
648
|
-
} catch {
|
|
649
|
-
throw new Error(`Invalid url "${input.url}" (expected a full origin).`);
|
|
650
|
-
}
|
|
651
|
-
if (!origin.host) throw new Error(`Invalid url "${input.url}" (missing host — include a scheme, e.g. https://host).`);
|
|
652
|
-
host = origin.host;
|
|
653
|
-
protocol = input.protocol === "ws" || input.protocol === "wss" ? input.protocol : origin.protocol === "https:" || origin.protocol === "wss:" ? "wss" : "ws";
|
|
654
|
-
} else {
|
|
655
|
-
host = input.host?.trim() || "localhost:5173";
|
|
656
|
-
protocol = input.protocol === "wss" ? "wss" : "ws";
|
|
657
|
-
}
|
|
658
|
-
const segment = input.canonicalAgent ? input.agent : camelCaseToKebabCase(input.agent);
|
|
659
|
-
const basePath = [
|
|
660
|
-
prefix,
|
|
661
|
-
encodeURIComponent(segment),
|
|
662
|
-
encodeURIComponent(instance)
|
|
663
|
-
].join("/");
|
|
664
|
-
return {
|
|
665
|
-
host,
|
|
666
|
-
protocol,
|
|
667
|
-
basePath,
|
|
668
|
-
query: parseQuery(input.query, input.token),
|
|
669
|
-
instance,
|
|
670
|
-
segment
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
//#endregion
|
|
674
|
-
//#region src/cli/connect.ts
|
|
675
|
-
function findTopLevelAgent(manifest, agent) {
|
|
676
|
-
return manifest.agents.find((entry) => entry.kind === "top-level" && (entry.id === agent || entry.bindingName === agent || entry.className === agent || entry.aliases.includes(agent)));
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Resolve target/URL/auth details from CLI options. Pure (no IO) so it can be
|
|
680
|
-
* unit-tested with a synthetic manifest. The manifest, when supplied, lets the
|
|
681
|
-
* CLI accept friendly agent ids/aliases and honor a custom route prefix; when
|
|
682
|
-
* the agent isn't found we treat it as a literal route segment (kebab-cased to
|
|
683
|
-
* match the default `routeAgentRequest` behavior) so the CLI also works against
|
|
684
|
-
* an arbitrary deployed worker. The browser-safe URL/query math lives in
|
|
685
|
-
* {@link deriveWsTarget}; this layer only adds manifest awareness.
|
|
686
|
-
*/
|
|
687
|
-
function resolveTarget(input) {
|
|
688
|
-
const topLevel = input.manifest ? findTopLevelAgent(input.manifest, input.agent) : void 0;
|
|
689
|
-
const matchedManifest = topLevel !== void 0;
|
|
690
|
-
const derived = deriveWsTarget({
|
|
691
|
-
agent: topLevel ? topLevel.id : input.agent,
|
|
692
|
-
canonicalAgent: topLevel !== void 0,
|
|
693
|
-
instance: input.instance,
|
|
694
|
-
url: input.url,
|
|
695
|
-
host: input.host,
|
|
696
|
-
protocol: input.protocol,
|
|
697
|
-
token: input.token,
|
|
698
|
-
query: input.query,
|
|
699
|
-
routePrefix: input.routePrefix
|
|
700
|
-
});
|
|
701
|
-
return {
|
|
702
|
-
host: derived.host,
|
|
703
|
-
protocol: derived.protocol,
|
|
704
|
-
basePath: derived.basePath,
|
|
705
|
-
query: derived.query,
|
|
706
|
-
agent: input.agent,
|
|
707
|
-
instance: derived.instance,
|
|
708
|
-
matchedManifest
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
async function loadManifest(root, routePrefix) {
|
|
712
|
-
try {
|
|
713
|
-
return await resolveThinkManifest({ routePrefix }, path.resolve(root ?? process.cwd()));
|
|
714
|
-
} catch {
|
|
715
|
-
return null;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
const DEFAULT_CONNECT_TIMEOUT_MS = 15e3;
|
|
719
|
-
/**
|
|
720
|
-
* Resolve once the client receives its identity handshake, or reject after
|
|
721
|
-
* `timeoutMs` (covers unreachable hosts, which otherwise retry silently).
|
|
722
|
-
*/
|
|
723
|
-
function waitForClientReady(client, timeoutMs = DEFAULT_CONNECT_TIMEOUT_MS) {
|
|
724
|
-
return new Promise((resolve, reject) => {
|
|
725
|
-
let settled = false;
|
|
726
|
-
const timer = setTimeout(() => {
|
|
727
|
-
if (settled) return;
|
|
728
|
-
settled = true;
|
|
729
|
-
reject(/* @__PURE__ */ new Error(`Timed out after ${timeoutMs}ms connecting to the agent. Check the host/url, that the dev server or worker is running, and the token.`));
|
|
730
|
-
}, timeoutMs);
|
|
731
|
-
client.ready.then(() => {
|
|
732
|
-
if (settled) return;
|
|
733
|
-
settled = true;
|
|
734
|
-
clearTimeout(timer);
|
|
735
|
-
resolve();
|
|
736
|
-
}, (error) => {
|
|
737
|
-
if (settled) return;
|
|
738
|
-
settled = true;
|
|
739
|
-
clearTimeout(timer);
|
|
740
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Resolve a target (loading the local manifest when present) and open a
|
|
746
|
-
* connected {@link AgentClient} backed by Node's global `WebSocket`.
|
|
747
|
-
*/
|
|
748
|
-
async function connectToThinkAgent(options) {
|
|
749
|
-
const WebSocketImpl = globalThis.WebSocket;
|
|
750
|
-
if (typeof WebSocketImpl !== "function") throw new Error("No global WebSocket found. The `think` runtime CLI requires Node.js 24+ (which provides a built-in WebSocket).");
|
|
751
|
-
const manifest = await loadManifest(options.root, options.routePrefix);
|
|
752
|
-
const target = resolveTarget({
|
|
753
|
-
...options,
|
|
754
|
-
manifest
|
|
755
|
-
});
|
|
756
|
-
return {
|
|
757
|
-
client: new AgentClient({
|
|
758
|
-
agent: target.agent,
|
|
759
|
-
name: target.instance,
|
|
760
|
-
basePath: target.basePath,
|
|
761
|
-
host: target.host,
|
|
762
|
-
protocol: target.protocol,
|
|
763
|
-
query: target.query,
|
|
764
|
-
WebSocket: WebSocketImpl
|
|
765
|
-
}),
|
|
766
|
-
target
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
//#endregion
|
|
770
|
-
//#region src/cli/state.ts
|
|
771
|
-
const SNAPSHOT_WAIT_MS = 1e3;
|
|
772
|
-
function delay(ms) {
|
|
773
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
774
|
-
}
|
|
775
|
-
function messageText(message) {
|
|
776
|
-
let text = "";
|
|
777
|
-
for (const part of message.parts) if (part.type === "text") text += part.text;
|
|
778
|
-
return text;
|
|
779
|
-
}
|
|
780
|
-
async function stateCommand(options) {
|
|
781
|
-
const { client, target } = await connectToThinkAgent(options);
|
|
782
|
-
const socket = client;
|
|
783
|
-
let messages = [];
|
|
784
|
-
let gotSnapshot = false;
|
|
785
|
-
const listener = (event) => {
|
|
786
|
-
if (typeof event.data !== "string") return;
|
|
787
|
-
let frame;
|
|
788
|
-
try {
|
|
789
|
-
frame = JSON.parse(event.data);
|
|
790
|
-
} catch {
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
if (frame.type === CHAT_MESSAGE_TYPES.CHAT_MESSAGES && Array.isArray(frame.messages)) {
|
|
794
|
-
messages = frame.messages;
|
|
795
|
-
gotSnapshot = true;
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
socket.addEventListener("message", listener);
|
|
799
|
-
try {
|
|
800
|
-
await waitForClientReady(client);
|
|
801
|
-
} catch (error) {
|
|
802
|
-
socket.removeEventListener("message", listener);
|
|
803
|
-
client.close();
|
|
804
|
-
throw error;
|
|
805
|
-
}
|
|
806
|
-
const deadline = Date.now() + SNAPSHOT_WAIT_MS;
|
|
807
|
-
while (!gotSnapshot && Date.now() < deadline) await delay(50);
|
|
808
|
-
socket.removeEventListener("message", listener);
|
|
809
|
-
const limit = options.limit ?? 10;
|
|
810
|
-
const recent = limit > 0 ? messages.slice(-limit) : messages;
|
|
811
|
-
if (options.json) {
|
|
812
|
-
console.log(JSON.stringify({
|
|
813
|
-
agent: client.agent,
|
|
814
|
-
name: client.name,
|
|
815
|
-
state: client.state ?? null,
|
|
816
|
-
messages: recent
|
|
817
|
-
}, null, 2));
|
|
818
|
-
client.close();
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
const lines = [
|
|
822
|
-
"Think state",
|
|
823
|
-
`Endpoint: ${target.protocol === "wss" ? "https" : "http"}://${target.host}/${target.basePath}`,
|
|
824
|
-
`Agent: ${client.agent}`,
|
|
825
|
-
`Instance: ${client.name}`,
|
|
826
|
-
"",
|
|
827
|
-
"State:",
|
|
828
|
-
client.state === void 0 ? "- none" : indent(JSON.stringify(client.state, null, 2)),
|
|
829
|
-
"",
|
|
830
|
-
`Recent messages (${recent.length}):`,
|
|
831
|
-
...recent.length === 0 ? ["- none"] : recent.map((message) => {
|
|
832
|
-
const text = messageText(message).trim();
|
|
833
|
-
return `- ${message.role}: ${text || "(no text)"}`;
|
|
834
|
-
})
|
|
835
|
-
];
|
|
836
|
-
console.log(lines.join("\n"));
|
|
837
|
-
client.close();
|
|
838
|
-
}
|
|
839
|
-
function indent(value) {
|
|
840
|
-
return value.split("\n").map((line) => ` ${line}`).join("\n");
|
|
841
|
-
}
|
|
842
|
-
//#endregion
|
|
843
|
-
//#region src/cli/studio-config.ts
|
|
844
|
-
/**
|
|
845
|
-
* Build the `/__studio/config.json` payload from the resolved target and the
|
|
846
|
-
* (optional) local manifest. Pure so it can be unit-tested directly.
|
|
847
|
-
*/
|
|
848
|
-
function buildStudioConfig(input) {
|
|
849
|
-
const agents = (input.manifest?.agents ?? []).filter((entry) => entry.kind === "top-level").map((entry) => ({
|
|
850
|
-
id: entry.id,
|
|
851
|
-
label: entry.bindingName || entry.id
|
|
852
|
-
}));
|
|
853
|
-
return {
|
|
854
|
-
target: input.target,
|
|
855
|
-
agents
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
//#endregion
|
|
859
|
-
//#region src/cli/studio.ts
|
|
860
|
-
const CONTENT_TYPES = {
|
|
861
|
-
".html": "text/html; charset=utf-8",
|
|
862
|
-
".js": "text/javascript; charset=utf-8",
|
|
863
|
-
".mjs": "text/javascript; charset=utf-8",
|
|
864
|
-
".css": "text/css; charset=utf-8",
|
|
865
|
-
".json": "application/json; charset=utf-8",
|
|
866
|
-
".svg": "image/svg+xml",
|
|
867
|
-
".png": "image/png",
|
|
868
|
-
".jpg": "image/jpeg",
|
|
869
|
-
".jpeg": "image/jpeg",
|
|
870
|
-
".gif": "image/gif",
|
|
871
|
-
".ico": "image/x-icon",
|
|
872
|
-
".woff": "font/woff",
|
|
873
|
-
".woff2": "font/woff2",
|
|
874
|
-
".map": "application/json; charset=utf-8"
|
|
875
|
-
};
|
|
876
|
-
function studioDistDir() {
|
|
877
|
-
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../studio");
|
|
878
|
-
}
|
|
879
|
-
async function loadManifestAgents(root, routePrefix) {
|
|
880
|
-
try {
|
|
881
|
-
return await resolveThinkManifest({ routePrefix }, path.resolve(root ?? process.cwd()));
|
|
882
|
-
} catch {
|
|
883
|
-
return null;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
function buildTarget(options) {
|
|
887
|
-
const target = {};
|
|
888
|
-
if (options.url) target.url = options.url;
|
|
889
|
-
if (options.host) target.host = options.host;
|
|
890
|
-
if (options.protocol === "ws" || options.protocol === "wss") target.protocol = options.protocol;
|
|
891
|
-
if (options.token) target.token = options.token;
|
|
892
|
-
if (options.agent) target.agent = options.agent;
|
|
893
|
-
if (options.instance) target.instance = options.instance;
|
|
894
|
-
if (options.routePrefix) target.routePrefix = options.routePrefix;
|
|
895
|
-
return target;
|
|
896
|
-
}
|
|
897
|
-
function openBrowser(url) {
|
|
898
|
-
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
899
|
-
try {
|
|
900
|
-
const child = spawn(command, [url], {
|
|
901
|
-
stdio: "ignore",
|
|
902
|
-
detached: true,
|
|
903
|
-
shell: process.platform === "win32"
|
|
904
|
-
});
|
|
905
|
-
child.on("error", () => {});
|
|
906
|
-
child.unref();
|
|
907
|
-
} catch {}
|
|
908
|
-
}
|
|
909
|
-
/** Resolve a file under `root`, guarding against path traversal. */
|
|
910
|
-
function safeResolve(root, urlPath) {
|
|
911
|
-
let decoded;
|
|
912
|
-
try {
|
|
913
|
-
decoded = decodeURIComponent(urlPath.split("?")[0]);
|
|
914
|
-
} catch {
|
|
915
|
-
return null;
|
|
916
|
-
}
|
|
917
|
-
const resolved = path.resolve(root, `.${decoded}`);
|
|
918
|
-
if (resolved !== root && !resolved.startsWith(root + path.sep)) return null;
|
|
919
|
-
return resolved;
|
|
920
|
-
}
|
|
921
|
-
async function studioCommand(options) {
|
|
922
|
-
const distDir = studioDistDir();
|
|
923
|
-
try {
|
|
924
|
-
await stat(path.join(distDir, "index.html"));
|
|
925
|
-
} catch {
|
|
926
|
-
throw new Error(`Think Studio assets were not found at ${distDir}. Reinstall @cloudflare/think (the published package ships the prebuilt Studio), or run the package build.`);
|
|
927
|
-
}
|
|
928
|
-
const manifest = await loadManifestAgents(options.root, options.routePrefix);
|
|
929
|
-
const config = buildStudioConfig({
|
|
930
|
-
target: buildTarget(options),
|
|
931
|
-
manifest
|
|
932
|
-
});
|
|
933
|
-
const configJson = JSON.stringify(config);
|
|
934
|
-
const server = createServer((req, res) => {
|
|
935
|
-
const urlPath = req.url ?? "/";
|
|
936
|
-
if (urlPath === "/__studio/config.json") {
|
|
937
|
-
res.writeHead(200, {
|
|
938
|
-
"content-type": "application/json; charset=utf-8",
|
|
939
|
-
"cache-control": "no-store"
|
|
940
|
-
});
|
|
941
|
-
res.end(configJson);
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
const rawPath = urlPath.split("?")[0];
|
|
945
|
-
const candidate = rawPath === "/" ? path.join(distDir, "index.html") : safeResolve(distDir, rawPath);
|
|
946
|
-
const serve = (filePath) => {
|
|
947
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
948
|
-
const stream = createReadStream(filePath);
|
|
949
|
-
stream.on("error", () => {
|
|
950
|
-
if (res.headersSent) res.destroy();
|
|
951
|
-
else {
|
|
952
|
-
res.writeHead(500);
|
|
953
|
-
res.end("Internal error");
|
|
954
|
-
}
|
|
955
|
-
});
|
|
956
|
-
stream.once("open", () => {
|
|
957
|
-
res.writeHead(200, { "content-type": CONTENT_TYPES[ext] ?? "application/octet-stream" });
|
|
958
|
-
stream.pipe(res);
|
|
959
|
-
});
|
|
960
|
-
};
|
|
961
|
-
if (!candidate) {
|
|
962
|
-
res.writeHead(404);
|
|
963
|
-
res.end("Not found");
|
|
964
|
-
return;
|
|
965
|
-
}
|
|
966
|
-
stat(candidate).then((s) => {
|
|
967
|
-
if (s.isFile()) serve(candidate);
|
|
968
|
-
else serve(path.join(distDir, "index.html"));
|
|
969
|
-
}).catch(() => serve(path.join(distDir, "index.html")));
|
|
970
|
-
});
|
|
971
|
-
const studioUrl = `http://localhost:${await listen(server, options.port ?? 4321)}/`;
|
|
972
|
-
console.log(`Think Studio running at ${studioUrl}`);
|
|
973
|
-
console.log("Press Ctrl+C to stop.");
|
|
974
|
-
if (options.open !== false) openBrowser(studioUrl);
|
|
975
|
-
await new Promise((resolve) => {
|
|
976
|
-
const shutdown = () => {
|
|
977
|
-
server.close(() => resolve());
|
|
978
|
-
};
|
|
979
|
-
process.once("SIGINT", shutdown);
|
|
980
|
-
process.once("SIGTERM", shutdown);
|
|
981
|
-
});
|
|
982
|
-
}
|
|
983
|
-
/** Listen on `startPort`, advancing on EADDRINUSE up to 20 ports. */
|
|
984
|
-
function listen(server, startPort) {
|
|
985
|
-
return new Promise((resolve, reject) => {
|
|
986
|
-
let attempt = 0;
|
|
987
|
-
const tryPort = (port) => {
|
|
988
|
-
const onError = (err) => {
|
|
989
|
-
if (err.code === "EADDRINUSE" && attempt < 20) {
|
|
990
|
-
attempt += 1;
|
|
991
|
-
tryPort(port + 1);
|
|
992
|
-
} else reject(err);
|
|
993
|
-
};
|
|
994
|
-
server.once("error", onError);
|
|
995
|
-
server.listen(port, "127.0.0.1", () => {
|
|
996
|
-
server.removeListener("error", onError);
|
|
997
|
-
const address = server.address();
|
|
998
|
-
resolve(typeof address === "object" && address ? address.port : port);
|
|
999
|
-
});
|
|
1000
|
-
};
|
|
1001
|
-
tryPort(startPort);
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
//#endregion
|
|
1005
|
-
//#region src/cli/types.ts
|
|
1006
|
-
async function typesCommand(options) {
|
|
1007
|
-
const root = path.resolve(options.root ?? process.cwd());
|
|
1008
|
-
const typesFile = normalizePath(options.typesFile ?? "think.d.ts");
|
|
1009
|
-
const wranglerEnvFile = normalizePath(options.wranglerEnvFile ?? "env.d.ts");
|
|
1010
|
-
const files = await readProjectFiles(root, "agents");
|
|
1011
|
-
const manifest = await resolveThinkManifest({
|
|
1012
|
-
files,
|
|
1013
|
-
routePrefix: options.routePrefix
|
|
1014
|
-
}, root);
|
|
1015
|
-
const wranglerConfig = await readWranglerConfig(root);
|
|
1016
|
-
if (wranglerConfig.config) applyUserBindingNames(manifest, wranglerConfig.config);
|
|
1017
|
-
if (options.all && !options.dryRun && !options.check) await runWranglerTypes(root, wranglerEnvFile, options.wranglerArgs ?? []);
|
|
1018
|
-
const generated = generateThinkTypes(manifest, {
|
|
1019
|
-
files,
|
|
1020
|
-
typesFile
|
|
1021
|
-
});
|
|
1022
|
-
if (options.dryRun) {
|
|
1023
|
-
console.log(["Think types would update:", ...generated.map((file) => `- ${file.path}`)].join("\n"));
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
if (options.check) {
|
|
1027
|
-
const stale = await findStaleFiles(root, generated);
|
|
1028
|
-
if (stale.length > 0) throw new Error([
|
|
1029
|
-
"Think generated types are out of date.",
|
|
1030
|
-
"Run `think types` to update:",
|
|
1031
|
-
...stale.map((file) => `- ${file}`)
|
|
1032
|
-
].join("\n"));
|
|
1033
|
-
console.log("Think generated types are up to date.");
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
|
-
for (const file of generated) await writeGeneratedFile(root, file);
|
|
1037
|
-
console.log(["Generated Think types:", ...generated.map((file) => `- ${file.path}`)].join("\n"));
|
|
1038
|
-
}
|
|
1039
|
-
async function findStaleFiles(root, files) {
|
|
1040
|
-
const stale = [];
|
|
1041
|
-
for (const file of files) {
|
|
1042
|
-
const expected = await expectedFileContent(root, file);
|
|
1043
|
-
if (await readTextIfExists$1(path.join(root, file.path)) !== expected) stale.push(file.path);
|
|
1044
|
-
}
|
|
1045
|
-
return stale;
|
|
1046
|
-
}
|
|
1047
|
-
async function writeGeneratedFile(root, file) {
|
|
1048
|
-
const absolute = path.join(root, file.path);
|
|
1049
|
-
const expected = await expectedFileContent(root, file);
|
|
1050
|
-
await mkdir(path.dirname(absolute), { recursive: true });
|
|
1051
|
-
await writeFile(absolute, expected, "utf8");
|
|
1052
|
-
}
|
|
1053
|
-
async function expectedFileContent(root, file) {
|
|
1054
|
-
const current = await readTextIfExists$1(path.join(root, file.path));
|
|
1055
|
-
if (current && !isThinkGeneratedFile(current)) throw new Error(`${file.path} already exists and is not Think-generated; pass a different output path or replace it with a Think-generated file.`);
|
|
1056
|
-
return file.content;
|
|
1057
|
-
}
|
|
1058
|
-
async function readTextIfExists$1(file) {
|
|
1059
|
-
try {
|
|
1060
|
-
return await readFile(file, "utf8");
|
|
1061
|
-
} catch (error) {
|
|
1062
|
-
if (isMissingFileError(error)) return null;
|
|
1063
|
-
throw error;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
async function runWranglerTypes(root, envFile, passthroughArgs) {
|
|
1067
|
-
const command = await resolveWranglerCommand(root);
|
|
1068
|
-
const args = [
|
|
1069
|
-
"types",
|
|
1070
|
-
envFile,
|
|
1071
|
-
...defaultWranglerTypeArgs(passthroughArgs),
|
|
1072
|
-
...passthroughArgs
|
|
1073
|
-
];
|
|
1074
|
-
await new Promise((resolve, reject) => {
|
|
1075
|
-
const child = spawn(command, args, {
|
|
1076
|
-
cwd: root,
|
|
1077
|
-
stdio: "inherit"
|
|
1078
|
-
});
|
|
1079
|
-
child.on("error", (error) => {
|
|
1080
|
-
reject(/* @__PURE__ */ new Error(`Could not run Wrangler to generate platform types. Install wrangler in this project, or run \`think types\` without --all to generate only Think declarations.\n\n${error.message}`));
|
|
1081
|
-
});
|
|
1082
|
-
child.on("exit", (code) => {
|
|
1083
|
-
if (code === 0) {
|
|
1084
|
-
resolve();
|
|
1085
|
-
return;
|
|
1086
|
-
}
|
|
1087
|
-
reject(/* @__PURE__ */ new Error(`Wrangler type generation failed with exit code ${code ?? "unknown"}. Fix the Wrangler error above, or run \`think types\` without --all if you intentionally want only Think declarations.`));
|
|
1088
|
-
});
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
function defaultWranglerTypeArgs(args) {
|
|
1092
|
-
return args.some((arg) => arg === "--include-runtime" || arg.startsWith("--include-runtime=")) ? [] : ["--include-runtime", "false"];
|
|
1093
|
-
}
|
|
1094
|
-
async function resolveWranglerCommand(root) {
|
|
1095
|
-
const executable = process.platform === "win32" ? "wrangler.cmd" : "wrangler";
|
|
1096
|
-
const local = path.join(root, "node_modules", ".bin", executable);
|
|
1097
|
-
try {
|
|
1098
|
-
await access(local);
|
|
1099
|
-
return local;
|
|
1100
|
-
} catch {
|
|
1101
|
-
return executable;
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
function normalizePath(file) {
|
|
1105
|
-
return file.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
1106
|
-
}
|
|
1107
|
-
function isMissingFileError(error) {
|
|
1108
|
-
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
1109
|
-
}
|
|
1110
|
-
//#endregion
|
|
1111
|
-
//#region src/cli/create.ts
|
|
1112
|
-
function connectionOptions(cmd) {
|
|
1113
|
-
return cmd.positional("agent", {
|
|
1114
|
-
type: "string",
|
|
1115
|
-
describe: "Agent id/alias (from the manifest) or a raw route segment"
|
|
1116
|
-
}).positional("instance", {
|
|
1117
|
-
type: "string",
|
|
1118
|
-
describe: "Agent instance name",
|
|
1119
|
-
default: "default"
|
|
1120
|
-
}).option("url", {
|
|
1121
|
-
type: "string",
|
|
1122
|
-
describe: "Remote origin, e.g. https://app.example.com (implies wss)"
|
|
1123
|
-
}).option("host", {
|
|
1124
|
-
type: "string",
|
|
1125
|
-
describe: "Local host[:port] (default: localhost:5173)"
|
|
1126
|
-
}).option("protocol", {
|
|
1127
|
-
type: "string",
|
|
1128
|
-
choices: ["ws", "wss"],
|
|
1129
|
-
describe: "Override the WebSocket protocol"
|
|
1130
|
-
}).option("token", {
|
|
1131
|
-
type: "string",
|
|
1132
|
-
describe: "Auth token, sent as the `token` query param"
|
|
1133
|
-
}).option("query", {
|
|
1134
|
-
type: "string",
|
|
1135
|
-
array: true,
|
|
1136
|
-
describe: "Extra query params as key=value (repeatable)"
|
|
1137
|
-
}).option("root", {
|
|
1138
|
-
type: "string",
|
|
1139
|
-
describe: "Project root used to discover the Think manifest",
|
|
1140
|
-
default: process.cwd()
|
|
1141
|
-
}).option("route-prefix", {
|
|
1142
|
-
type: "string",
|
|
1143
|
-
describe: "Override the Think route prefix"
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
function createCli(argv = process.argv) {
|
|
1147
|
-
return yargs(hideBin(argv)).parserConfiguration({ "populate--": true }).scriptName("think").usage("$0 <command> [options]").command("init [directory]", "Scaffold a new Think app from a starter template, or add Think to the current project", (cmd) => cmd.positional("directory", {
|
|
1148
|
-
type: "string",
|
|
1149
|
-
describe: "Target directory to initialize. Omit to choose interactively."
|
|
1150
|
-
}).option("root", {
|
|
1151
|
-
type: "string",
|
|
1152
|
-
describe: "Base directory for initialization",
|
|
1153
|
-
default: process.cwd()
|
|
1154
|
-
}).option("name", {
|
|
1155
|
-
type: "string",
|
|
1156
|
-
describe: "Package and Worker name for the generated app"
|
|
1157
|
-
}).option("template", {
|
|
1158
|
-
type: "string",
|
|
1159
|
-
describe: "Starter template to scaffold (omit to choose)"
|
|
1160
|
-
}).option("ref", {
|
|
1161
|
-
type: "string",
|
|
1162
|
-
describe: "Git ref to fetch remote templates from"
|
|
1163
|
-
}).option("route-prefix", {
|
|
1164
|
-
type: "string",
|
|
1165
|
-
describe: "Think route prefix when adding Think to an existing project"
|
|
1166
|
-
}).option("yes", {
|
|
1167
|
-
alias: "y",
|
|
1168
|
-
type: "boolean",
|
|
1169
|
-
describe: "Use defaults and skip prompts",
|
|
1170
|
-
default: false
|
|
1171
|
-
}).option("install", {
|
|
1172
|
-
type: "boolean",
|
|
1173
|
-
describe: "Run npm install after writing files",
|
|
1174
|
-
default: true
|
|
1175
|
-
}).option("dry-run", {
|
|
1176
|
-
type: "boolean",
|
|
1177
|
-
describe: "Print files that would be written without writing them",
|
|
1178
|
-
default: false
|
|
1179
|
-
}), async (args) => {
|
|
1180
|
-
await initCommand$1({
|
|
1181
|
-
root: args.root,
|
|
1182
|
-
directory: args.directory,
|
|
1183
|
-
name: args.name,
|
|
1184
|
-
template: args.template,
|
|
1185
|
-
ref: args.ref,
|
|
1186
|
-
routePrefix: args.routePrefix,
|
|
1187
|
-
yes: args.yes,
|
|
1188
|
-
install: args.install,
|
|
1189
|
-
dryRun: args.dryRun
|
|
1190
|
-
});
|
|
1191
|
-
}).command("inspect", "Inspect the Think app manifest, routing, bindings, and diagnostics", (cmd) => cmd.option("root", {
|
|
1192
|
-
type: "string",
|
|
1193
|
-
describe: "Project root to inspect",
|
|
1194
|
-
default: process.cwd()
|
|
1195
|
-
}).option("json", {
|
|
1196
|
-
type: "boolean",
|
|
1197
|
-
describe: "Print machine-readable JSON output",
|
|
1198
|
-
default: false
|
|
1199
|
-
}).option("route-prefix", {
|
|
1200
|
-
type: "string",
|
|
1201
|
-
describe: "Override the Think route prefix"
|
|
1202
|
-
}).option("allow-non-virtual-main", {
|
|
1203
|
-
type: "boolean",
|
|
1204
|
-
describe: "Do not report non-virtual Wrangler main as an error during inspection",
|
|
1205
|
-
default: false
|
|
1206
|
-
}), async (args) => {
|
|
1207
|
-
await inspectCommand({
|
|
1208
|
-
root: args.root,
|
|
1209
|
-
json: args.json,
|
|
1210
|
-
routePrefix: args.routePrefix,
|
|
1211
|
-
allowNonVirtualMain: args.allowNonVirtualMain
|
|
1212
|
-
});
|
|
1213
|
-
}).command("types", "Generate Think TypeScript declarations", (cmd) => cmd.option("root", {
|
|
1214
|
-
type: "string",
|
|
1215
|
-
describe: "Project root to generate types for",
|
|
1216
|
-
default: process.cwd()
|
|
1217
|
-
}).option("types-file", {
|
|
1218
|
-
type: "string",
|
|
1219
|
-
describe: "Think declaration file to generate",
|
|
1220
|
-
default: "think.d.ts"
|
|
1221
|
-
}).option("all", {
|
|
1222
|
-
type: "boolean",
|
|
1223
|
-
describe: "Also run Wrangler type generation before Think typegen",
|
|
1224
|
-
default: false
|
|
1225
|
-
}).option("wrangler-env-file", {
|
|
1226
|
-
type: "string",
|
|
1227
|
-
describe: "Wrangler env declaration file to generate with --all",
|
|
1228
|
-
default: "env.d.ts"
|
|
1229
|
-
}).option("route-prefix", {
|
|
1230
|
-
type: "string",
|
|
1231
|
-
describe: "Override the Think route prefix"
|
|
1232
|
-
}).option("dry-run", {
|
|
1233
|
-
type: "boolean",
|
|
1234
|
-
describe: "Print files that would be written without writing them",
|
|
1235
|
-
default: false
|
|
1236
|
-
}).option("check", {
|
|
1237
|
-
type: "boolean",
|
|
1238
|
-
describe: "Check generated Think types without modifying files",
|
|
1239
|
-
default: false
|
|
1240
|
-
}), async (args) => {
|
|
1241
|
-
await typesCommand({
|
|
1242
|
-
root: args.root,
|
|
1243
|
-
typesFile: args.typesFile,
|
|
1244
|
-
wranglerEnvFile: args.wranglerEnvFile,
|
|
1245
|
-
routePrefix: args.routePrefix,
|
|
1246
|
-
all: args.all,
|
|
1247
|
-
dryRun: args.dryRun,
|
|
1248
|
-
check: args.check,
|
|
1249
|
-
wranglerArgs: Array.isArray(args["--"]) ? args["--"].map(String) : []
|
|
1250
|
-
});
|
|
1251
|
-
}).command("studio [agent] [instance]", "Launch Think Studio — a local web app to chat with and inspect a running Think instance (local or remote)", (cmd) => connectionOptions(cmd).option("port", {
|
|
1252
|
-
type: "number",
|
|
1253
|
-
describe: "Port for the local Studio server",
|
|
1254
|
-
default: 4321
|
|
1255
|
-
}).option("open", {
|
|
1256
|
-
type: "boolean",
|
|
1257
|
-
describe: "Open the browser automatically",
|
|
1258
|
-
default: true
|
|
1259
|
-
}), async (args) => {
|
|
1260
|
-
await studioCommand({
|
|
1261
|
-
agent: args.agent,
|
|
1262
|
-
instance: args.instance,
|
|
1263
|
-
url: args.url,
|
|
1264
|
-
host: args.host,
|
|
1265
|
-
protocol: args.protocol,
|
|
1266
|
-
token: args.token,
|
|
1267
|
-
query: args.query,
|
|
1268
|
-
root: args.root,
|
|
1269
|
-
routePrefix: args.routePrefix,
|
|
1270
|
-
port: args.port,
|
|
1271
|
-
open: args.open
|
|
1272
|
-
});
|
|
1273
|
-
}).command("state <agent> [instance]", "Print a running Think agent's identity, state, and recent history (read-only)", (cmd) => connectionOptions(cmd).option("json", {
|
|
1274
|
-
type: "boolean",
|
|
1275
|
-
describe: "Print machine-readable JSON output",
|
|
1276
|
-
default: false
|
|
1277
|
-
}).option("limit", {
|
|
1278
|
-
type: "number",
|
|
1279
|
-
describe: "Number of recent messages to include",
|
|
1280
|
-
default: 10
|
|
1281
|
-
}), async (args) => {
|
|
1282
|
-
await stateCommand({
|
|
1283
|
-
agent: args.agent,
|
|
1284
|
-
instance: args.instance,
|
|
1285
|
-
url: args.url,
|
|
1286
|
-
host: args.host,
|
|
1287
|
-
protocol: args.protocol,
|
|
1288
|
-
token: args.token,
|
|
1289
|
-
query: args.query,
|
|
1290
|
-
root: args.root,
|
|
1291
|
-
routePrefix: args.routePrefix,
|
|
1292
|
-
json: args.json,
|
|
1293
|
-
limit: args.limit
|
|
1294
|
-
});
|
|
1295
|
-
}).demandCommand(1, "Please provide a command").strict().help();
|
|
1296
|
-
}
|
|
1297
|
-
//#endregion
|
|
1298
|
-
//#region src/cli/index.ts
|
|
1299
|
-
console.warn("The `think` CLI is part of the experimental @cloudflare/think framework layer and may change or be removed in any release.");
|
|
1300
|
-
createCli().parse();
|
|
1301
|
-
//#endregion
|
|
1302
|
-
export {};
|
|
1303
|
-
|
|
1304
|
-
//# sourceMappingURL=index.js.map
|