@cloudflare/think 0.9.1 → 0.11.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 +10 -17
- package/dist/{chat-sdk-Bb93yaZh.js → chat-sdk-D6cUghsQ.js} +33 -8
- package/dist/chat-sdk-D6cUghsQ.js.map +1 -0
- package/dist/cli/index.js +718 -55
- package/dist/cli/index.js.map +1 -1
- package/dist/{codegen-CuPdJRpV.js → codegen-DlA2QQuU.js} +6 -38
- package/dist/codegen-DlA2QQuU.js.map +1 -0
- package/dist/{config-D512sQYg.d.ts → config-CD7hqncK.d.ts} +5 -5
- package/dist/extensions/index.js +1 -1
- package/dist/framework/index.d.ts +17 -62
- package/dist/framework/index.js +3 -57
- package/dist/{think-CwxWGsX1.d.ts → index-D_S5mETO.d.ts} +1643 -688
- package/dist/{manager-BPndMP_6.js → manager-CSk5htym.js} +7 -7
- package/dist/{manager-BPndMP_6.js.map → manager-CSk5htym.js.map} +1 -1
- package/dist/{manifest-CpB-xngB.d.ts → manifest-DK5HuGga.d.ts} +16 -18
- package/dist/messengers/index.d.ts +59 -55
- package/dist/messengers/index.js +2 -2
- package/dist/messengers/telegram.d.ts +4 -4
- package/dist/messengers/telegram.js +1 -1
- package/dist/react.d.ts +79 -0
- package/dist/react.js +28 -0
- package/dist/react.js.map +1 -0
- package/dist/server-entry.d.ts +1 -1
- package/dist/server-entry.js +1 -1
- package/dist/server-entry.js.map +1 -1
- package/dist/studio/assets/abap-CLvhMVsD.js +1 -0
- package/dist/studio/assets/actionscript-3--17pq3dv.js +1 -0
- package/dist/studio/assets/ada-C5qYipkI.js +1 -0
- package/dist/studio/assets/andromeeda-vGVdxbeo.js +1 -0
- package/dist/studio/assets/angular-html-D27LthTc.js +1 -0
- package/dist/studio/assets/angular-ts-DtNL2gQ7.js +1 -0
- package/dist/studio/assets/apache-U0d_L8uA.js +1 -0
- package/dist/studio/assets/apex-CGTLDQj6.js +1 -0
- package/dist/studio/assets/apl-BgEcDqM0.js +1 -0
- package/dist/studio/assets/applescript-CCn79oCD.js +1 -0
- package/dist/studio/assets/ara-4CJ0cIlV.js +1 -0
- package/dist/studio/assets/asciidoc-DE70LPWp.js +1 -0
- package/dist/studio/assets/asm-Cmm7eHzH.js +1 -0
- package/dist/studio/assets/astro-CstbRF9e.js +1 -0
- package/dist/studio/assets/aurora-x-CDeNXAV0.js +1 -0
- package/dist/studio/assets/awk-BWXHIvNe.js +1 -0
- package/dist/studio/assets/ayu-dark-DluEY0Gj.js +1 -0
- package/dist/studio/assets/ayu-light-C3h-C4tm.js +1 -0
- package/dist/studio/assets/ayu-mirage-Bqwy1Gya.js +1 -0
- package/dist/studio/assets/ballerina-B7ZEbQpA.js +1 -0
- package/dist/studio/assets/bat-Bo4NYOV-.js +1 -0
- package/dist/studio/assets/beancount-D-usSTwE.js +1 -0
- package/dist/studio/assets/berry-DKpUyyne.js +1 -0
- package/dist/studio/assets/bibtex-Ci_nEsc7.js +1 -0
- package/dist/studio/assets/bicep-CUHmPFLl.js +1 -0
- package/dist/studio/assets/bird2-C2hNVINV.js +1 -0
- package/dist/studio/assets/blade-CLG-7epG.js +1 -0
- package/dist/studio/assets/bsl-BkkzgIyY.js +1 -0
- package/dist/studio/assets/c-CssQqwxO.js +1 -0
- package/dist/studio/assets/c3-CnJL0r0V.js +1 -0
- package/dist/studio/assets/cadence-CQ2zXKGN.js +1 -0
- package/dist/studio/assets/cairo-DLTphjLi.js +1 -0
- package/dist/studio/assets/catppuccin-frappe-3VR1Za6u.js +1 -0
- package/dist/studio/assets/catppuccin-latte-DwIHMF0Q.js +1 -0
- package/dist/studio/assets/catppuccin-macchiato-DYnBP6_5.js +1 -0
- package/dist/studio/assets/catppuccin-mocha-DYhrFGRu.js +1 -0
- package/dist/studio/assets/clarity-SemFz856.js +1 -0
- package/dist/studio/assets/clojure-DqKBuwfJ.js +1 -0
- package/dist/studio/assets/cmake-Bj61d0ZC.js +1 -0
- package/dist/studio/assets/cobol-CjmzHCjg.js +1 -0
- package/dist/studio/assets/codeowners-C8r90Shi.js +1 -0
- package/dist/studio/assets/codeql-oeQT6MSM.js +1 -0
- package/dist/studio/assets/coffee-B_rqYPkp.js +1 -0
- package/dist/studio/assets/common-lisp-Cv5bFMCO.js +1 -0
- package/dist/studio/assets/coq-BrsZFFmf.js +1 -0
- package/dist/studio/assets/cpp-5YyZJlb7.js +1 -0
- package/dist/studio/assets/crystal-D7uKze0i.js +1 -0
- package/dist/studio/assets/csharp-Ct8U2NOr.js +1 -0
- package/dist/studio/assets/css-k9oPgg7G.js +1 -0
- package/dist/studio/assets/csv-Dx-8-gkx.js +1 -0
- package/dist/studio/assets/cue-CE9AQfxI.js +1 -0
- package/dist/studio/assets/cypher-ClKdZ_lG.js +1 -0
- package/dist/studio/assets/d-qD-0Kul2.js +1 -0
- package/dist/studio/assets/dark-plus-Cs2F2srj.js +1 -0
- package/dist/studio/assets/dart-DkHntEIa.js +1 -0
- package/dist/studio/assets/dax-BkyTk9wS.js +1 -0
- package/dist/studio/assets/desktop-Dlh5hvp9.js +1 -0
- package/dist/studio/assets/diff-woXpYk--.js +1 -0
- package/dist/studio/assets/docker-IyjqRm3v.js +1 -0
- package/dist/studio/assets/dotenv-_5a1GRtc.js +1 -0
- package/dist/studio/assets/dracula-BHWKrbxM.js +1 -0
- package/dist/studio/assets/dracula-soft-5eyTD99u.js +1 -0
- package/dist/studio/assets/dream-maker-DW3nJb8Q.js +1 -0
- package/dist/studio/assets/edge-CGgsSt0x.js +1 -0
- package/dist/studio/assets/elixir-BX_d5Evo.js +1 -0
- package/dist/studio/assets/elm-DENxDm5e.js +1 -0
- package/dist/studio/assets/emacs-lisp-C9PiwqqW.js +1 -0
- package/dist/studio/assets/erb-DvYOup03.js +1 -0
- package/dist/studio/assets/erlang-Cphh6RMH.js +1 -0
- package/dist/studio/assets/everforest-dark-sB-x3p7T.js +1 -0
- package/dist/studio/assets/everforest-light-Df2xbC6M.js +1 -0
- package/dist/studio/assets/fennel-DQxkIbk2.js +1 -0
- package/dist/studio/assets/fish-BJitypiv.js +1 -0
- package/dist/studio/assets/fluent-C03EYrpw.js +1 -0
- package/dist/studio/assets/fortran-fixed-form-DEKoE2YW.js +1 -0
- package/dist/studio/assets/fortran-free-form-CYNrtFtB.js +1 -0
- package/dist/studio/assets/fsharp-D13ZGOAj.js +1 -0
- package/dist/studio/assets/gdresource-C0sCabJj.js +1 -0
- package/dist/studio/assets/gdscript-Cp2uCuqX.js +1 -0
- package/dist/studio/assets/gdshader-CBce3t8t.js +1 -0
- package/dist/studio/assets/genie-CV2tkWYe.js +1 -0
- package/dist/studio/assets/gherkin-DExj1W_8.js +1 -0
- package/dist/studio/assets/git-commit-BSykSTBG.js +1 -0
- package/dist/studio/assets/git-rebase-BsAdTS5A.js +1 -0
- package/dist/studio/assets/github-dark-C-LZuMrd.js +1 -0
- package/dist/studio/assets/github-dark-default-DXG-b-1a.js +1 -0
- package/dist/studio/assets/github-dark-dimmed-Bx1FflLF.js +1 -0
- package/dist/studio/assets/github-dark-high-contrast-B_tTalzw.js +1 -0
- package/dist/studio/assets/github-light-EUqPIrTm.js +1 -0
- package/dist/studio/assets/github-light-default-BXViO-2h.js +1 -0
- package/dist/studio/assets/github-light-high-contrast-B68TUdTA.js +1 -0
- package/dist/studio/assets/gleam-CSRkHgEL.js +1 -0
- package/dist/studio/assets/glimmer-js-e0h98Z67.js +1 -0
- package/dist/studio/assets/glimmer-ts-C9s5Kv8m.js +1 -0
- package/dist/studio/assets/glsl-CCiyeTRs.js +1 -0
- package/dist/studio/assets/gn-ilITqXS6.js +1 -0
- package/dist/studio/assets/gnuplot-7GGW24-e.js +1 -0
- package/dist/studio/assets/go-BJwz_mda.js +1 -0
- package/dist/studio/assets/graphql-BRtHwsqk.js +1 -0
- package/dist/studio/assets/groovy-CacY0gHj.js +1 -0
- package/dist/studio/assets/gruvbox-dark-hard-C820rvS2.js +1 -0
- package/dist/studio/assets/gruvbox-dark-medium-BPjhmG05.js +1 -0
- package/dist/studio/assets/gruvbox-dark-soft-MrdJrrXF.js +1 -0
- package/dist/studio/assets/gruvbox-light-hard-BC_s9l72.js +1 -0
- package/dist/studio/assets/gruvbox-light-medium-BAWPOn9u.js +1 -0
- package/dist/studio/assets/gruvbox-light-soft-BSMLrYjP.js +1 -0
- package/dist/studio/assets/hack-Dnt0QXHh.js +1 -0
- package/dist/studio/assets/haml-EXGmzuB1.js +1 -0
- package/dist/studio/assets/handlebars-CzyBIDJE.js +1 -0
- package/dist/studio/assets/haskell-D8IpX4py.js +1 -0
- package/dist/studio/assets/haxe-OTjmBuCE.js +1 -0
- package/dist/studio/assets/hcl-Dh228itO.js +1 -0
- package/dist/studio/assets/highlighted-body-OFNGDK62-CQUFKLNu.js +1 -0
- package/dist/studio/assets/hjson-CxZEssPk.js +1 -0
- package/dist/studio/assets/hlsl-Cvrh5tZx.js +1 -0
- package/dist/studio/assets/horizon-CE9ld1lL.js +1 -0
- package/dist/studio/assets/horizon-bright-Br1oVSNq.js +1 -0
- package/dist/studio/assets/houston-CsvMBhTu.js +1 -0
- package/dist/studio/assets/html-BAT8b_VM.js +1 -0
- package/dist/studio/assets/html-derivative-7tkS-r6F.js +1 -0
- package/dist/studio/assets/http-Cgka02Qq.js +1 -0
- package/dist/studio/assets/hurl-Cbkh8WEw.js +1 -0
- package/dist/studio/assets/hxml-B0Qn7Nwc.js +1 -0
- package/dist/studio/assets/hy-CZbG8q4J.js +1 -0
- package/dist/studio/assets/imba-DsUTQ-LC.js +1 -0
- package/dist/studio/assets/index-D6n8vpkp.js +390 -0
- package/dist/studio/assets/index-DkGWw6ES.css +2 -0
- package/dist/studio/assets/ini-B5eOa1yu.js +1 -0
- package/dist/studio/assets/java-DrRKiUno.js +1 -0
- package/dist/studio/assets/javascript-9LAnHOxD.js +1 -0
- package/dist/studio/assets/jinja-CqRt4prs.js +1 -0
- package/dist/studio/assets/jison-BX-IOQpJ.js +1 -0
- package/dist/studio/assets/json-dOrE-En8.js +1 -0
- package/dist/studio/assets/json5-BR5RXkoi.js +1 -0
- package/dist/studio/assets/jsonc-CYpm1nAK.js +1 -0
- package/dist/studio/assets/jsonl-CmCQp5Yx.js +1 -0
- package/dist/studio/assets/jsonnet-CJTPZ8u_.js +1 -0
- package/dist/studio/assets/jssm-DXw9l8Rf.js +1 -0
- package/dist/studio/assets/jsx-BSTPfqWX.js +1 -0
- package/dist/studio/assets/julia-Dvz-BPmf.js +1 -0
- package/dist/studio/assets/just-BHQm0Atq.js +1 -0
- package/dist/studio/assets/kanagawa-dragon-CXtmUGW6.js +1 -0
- package/dist/studio/assets/kanagawa-lotus-BN08jTvb.js +1 -0
- package/dist/studio/assets/kanagawa-wave-CTweb8Dz.js +1 -0
- package/dist/studio/assets/kdl-CsD5j6eV.js +1 -0
- package/dist/studio/assets/kotlin-DhhofPvG.js +1 -0
- package/dist/studio/assets/kusto-BUv0MjJC.js +1 -0
- package/dist/studio/assets/laserwave-C_8bwKvT.js +1 -0
- package/dist/studio/assets/latex-CxdhxuXv.js +1 -0
- package/dist/studio/assets/lean-CewbzKMR.js +1 -0
- package/dist/studio/assets/less-DVTAwKKz.js +1 -0
- package/dist/studio/assets/light-plus-DVQuIRkW.js +1 -0
- package/dist/studio/assets/liquid-D-hM-Q_F.js +1 -0
- package/dist/studio/assets/llvm-Cm23YOpf.js +1 -0
- package/dist/studio/assets/log-BNLmms1o.js +1 -0
- package/dist/studio/assets/logo-Cluzi2Zq.js +1 -0
- package/dist/studio/assets/lua-5qtqjLHq.js +1 -0
- package/dist/studio/assets/luau-CNKltnaQ.js +1 -0
- package/dist/studio/assets/make-Dixweg8N.js +1 -0
- package/dist/studio/assets/markdown-BYOwaDjH.js +1 -0
- package/dist/studio/assets/marko-5FJaM2co.js +1 -0
- package/dist/studio/assets/material-theme-Bm3Qr25_.js +1 -0
- package/dist/studio/assets/material-theme-darker-2IIEA8gg.js +1 -0
- package/dist/studio/assets/material-theme-lighter-uhdI0v04.js +1 -0
- package/dist/studio/assets/material-theme-ocean-CHQ94UKr.js +1 -0
- package/dist/studio/assets/material-theme-palenight-B5W6OYN7.js +1 -0
- package/dist/studio/assets/matlab-D7qyCx1q.js +1 -0
- package/dist/studio/assets/mdc-BhYW7lCG.js +1 -0
- package/dist/studio/assets/mdx-DQZ5AkYe.js +1 -0
- package/dist/studio/assets/mermaid-Bk4SNUv9.js +1 -0
- package/dist/studio/assets/mermaid-GHXKKRXX-CWM2EB-u.js +1 -0
- package/dist/studio/assets/min-dark-BSWPekZh.js +1 -0
- package/dist/studio/assets/min-light-DDpmG2fV.js +1 -0
- package/dist/studio/assets/mipsasm-BMqwQI7S.js +1 -0
- package/dist/studio/assets/mojo-BgCJLMeH.js +1 -0
- package/dist/studio/assets/monokai-CdkpiU2Y.js +1 -0
- package/dist/studio/assets/moonbit-CaWjb8XO.js +1 -0
- package/dist/studio/assets/move-B1IS1UjX.js +1 -0
- package/dist/studio/assets/narrat-_X_XdTYD.js +1 -0
- package/dist/studio/assets/nextflow-Bbiyy34d.js +1 -0
- package/dist/studio/assets/nextflow-groovy-Dc_ddanL.js +1 -0
- package/dist/studio/assets/nginx-rtAXrRye.js +1 -0
- package/dist/studio/assets/night-owl-DhmEMT88.js +1 -0
- package/dist/studio/assets/night-owl-light-eJ-hLW7d.js +1 -0
- package/dist/studio/assets/nim-DQSmaN9U.js +1 -0
- package/dist/studio/assets/nix-IvuFDN5E.js +1 -0
- package/dist/studio/assets/nord-Cb4Vim4T.js +1 -0
- package/dist/studio/assets/nushell-DcLAeLz5.js +1 -0
- package/dist/studio/assets/objective-c-D1A_Heim.js +1 -0
- package/dist/studio/assets/objective-cpp-BsSzOQcm.js +1 -0
- package/dist/studio/assets/ocaml-O90oeIOV.js +1 -0
- package/dist/studio/assets/odin-B1RWQWA5.js +1 -0
- package/dist/studio/assets/one-dark-pro-CLwyXe_n.js +1 -0
- package/dist/studio/assets/one-light-D7Lr4KcI.js +1 -0
- package/dist/studio/assets/openscad-BUDT5pXO.js +1 -0
- package/dist/studio/assets/pascal-4ZHwLPI5.js +1 -0
- package/dist/studio/assets/perl-B54AdcaE.js +1 -0
- package/dist/studio/assets/php-DpvTxCny.js +1 -0
- package/dist/studio/assets/pkl-ot-7Btpt.js +1 -0
- package/dist/studio/assets/plastic-DQwYfKfQ.js +1 -0
- package/dist/studio/assets/plsql-DGHpHOYJ.js +1 -0
- package/dist/studio/assets/po-BiJDBrnU.js +1 -0
- package/dist/studio/assets/poimandres-DRFjx7u4.js +1 -0
- package/dist/studio/assets/polar-C7UOKdEL.js +1 -0
- package/dist/studio/assets/postcss-BXeXVLqQ.js +1 -0
- package/dist/studio/assets/powerquery-DNMTfnFr.js +1 -0
- package/dist/studio/assets/powershell-DshXNtvi.js +1 -0
- package/dist/studio/assets/prisma-BsRQq5mF.js +1 -0
- package/dist/studio/assets/prolog-iXnhIJG7.js +1 -0
- package/dist/studio/assets/proto-DB4EqR-F.js +1 -0
- package/dist/studio/assets/pug-Cyffw0Ho.js +1 -0
- package/dist/studio/assets/puppet-CDv2pdJW.js +1 -0
- package/dist/studio/assets/purescript-9MfHhQsQ.js +1 -0
- package/dist/studio/assets/python-gzcpVVnB.js +1 -0
- package/dist/studio/assets/qml-CxRetSkO.js +1 -0
- package/dist/studio/assets/qmldir-DCQb3MpD.js +1 -0
- package/dist/studio/assets/qss-Fe1Jh2GI.js +1 -0
- package/dist/studio/assets/r-CXWRxrXc.js +1 -0
- package/dist/studio/assets/racket-DcIDlBhZ.js +1 -0
- package/dist/studio/assets/raku-B3gFvitq.js +1 -0
- package/dist/studio/assets/razor-BJzI-zc9.js +1 -0
- package/dist/studio/assets/red-CJ3rzSJv.js +1 -0
- package/dist/studio/assets/reg-CRGYupPL.js +1 -0
- package/dist/studio/assets/regexp-dqxdfrnE.js +1 -0
- package/dist/studio/assets/rel-BtDbiS_P.js +1 -0
- package/dist/studio/assets/riscv-Ckw8ddFX.js +1 -0
- package/dist/studio/assets/ron-VUp2lXgN.js +1 -0
- package/dist/studio/assets/rose-pine-BthvhNj6.js +1 -0
- package/dist/studio/assets/rose-pine-dawn-Dg85fqjY.js +1 -0
- package/dist/studio/assets/rose-pine-moon-hon4tzzS.js +1 -0
- package/dist/studio/assets/rosmsg-CAekHB0j.js +1 -0
- package/dist/studio/assets/rst-BW7eKYj4.js +1 -0
- package/dist/studio/assets/ruby-D5Npyj8-.js +1 -0
- package/dist/studio/assets/rust-Cfkwpbl8.js +1 -0
- package/dist/studio/assets/sas-DZLppjul.js +1 -0
- package/dist/studio/assets/sass-DXrisJhu.js +1 -0
- package/dist/studio/assets/scala-DKOlJaKm.js +1 -0
- package/dist/studio/assets/scheme-DQCgrYNe.js +1 -0
- package/dist/studio/assets/scss-CbqoxyAe.js +1 -0
- package/dist/studio/assets/sdbl-bTVj8UrX.js +1 -0
- package/dist/studio/assets/shaderlab-TOUzSsQk.js +1 -0
- package/dist/studio/assets/shellscript-CFHqBeXu.js +1 -0
- package/dist/studio/assets/shellsession-CbZDA4Bf.js +1 -0
- package/dist/studio/assets/slack-dark-DnToyrRv.js +1 -0
- package/dist/studio/assets/slack-ochin-B2OO5cIa.js +1 -0
- package/dist/studio/assets/smalltalk-B16xEiuN.js +1 -0
- package/dist/studio/assets/snazzy-light-4G7pJPwS.js +1 -0
- package/dist/studio/assets/solarized-dark-DV17i1UV.js +1 -0
- package/dist/studio/assets/solarized-light-DSh2HLQt.js +1 -0
- package/dist/studio/assets/solidity-CKzVLygQ.js +1 -0
- package/dist/studio/assets/soy-PImjtV58.js +1 -0
- package/dist/studio/assets/sparql-D_iOobhT.js +1 -0
- package/dist/studio/assets/splunk-BC2Px7Mm.js +1 -0
- package/dist/studio/assets/sql-DhGo8urW.js +1 -0
- package/dist/studio/assets/ssh-config-BgfXC-Er.js +1 -0
- package/dist/studio/assets/stata-CjHWbU2v.js +1 -0
- package/dist/studio/assets/stylus-B6D30XZt.js +1 -0
- package/dist/studio/assets/surrealql-o8Qr4t56.js +1 -0
- package/dist/studio/assets/svelte-DlSIyEV1.js +1 -0
- package/dist/studio/assets/swift-DonLKvLd.js +1 -0
- package/dist/studio/assets/synthwave-84-nFMaYfgc.js +1 -0
- package/dist/studio/assets/system-verilog-DJ5XKQeo.js +1 -0
- package/dist/studio/assets/systemd-BxMlprV5.js +1 -0
- package/dist/studio/assets/talonscript-CohzipZa.js +1 -0
- package/dist/studio/assets/tasl-DMoTqEGO.js +1 -0
- package/dist/studio/assets/tcl-CZd0xW_V.js +1 -0
- package/dist/studio/assets/templ-qizfwU1w.js +1 -0
- package/dist/studio/assets/terraform-DswuEJGm.js +1 -0
- package/dist/studio/assets/tex-Ca7T661H.js +1 -0
- package/dist/studio/assets/tokyo-night-oM2G3aXe.js +1 -0
- package/dist/studio/assets/toml-CcmNWLt0.js +1 -0
- package/dist/studio/assets/ts-tags-DUmjLkgl.js +1 -0
- package/dist/studio/assets/tsv-sltzmVWM.js +1 -0
- package/dist/studio/assets/tsx-CfwgIqHW.js +1 -0
- package/dist/studio/assets/turtle-ByJddavk.js +1 -0
- package/dist/studio/assets/twig-D7NAYUBY.js +1 -0
- package/dist/studio/assets/typescript-Bbz9oX-P.js +1 -0
- package/dist/studio/assets/typespec-B88KGewJ.js +1 -0
- package/dist/studio/assets/typst-DI99ib-x.js +1 -0
- package/dist/studio/assets/v-DETTlOr0.js +1 -0
- package/dist/studio/assets/vala-zf12oZj6.js +1 -0
- package/dist/studio/assets/vb-Djn5o6TS.js +1 -0
- package/dist/studio/assets/verilog-CiiDBU1e.js +1 -0
- package/dist/studio/assets/vesper-D5bVUKB1.js +1 -0
- package/dist/studio/assets/vhdl-BroJfC0k.js +1 -0
- package/dist/studio/assets/viml-DvXPmvsu.js +1 -0
- package/dist/studio/assets/vitesse-black-fwtXNY1n.js +1 -0
- package/dist/studio/assets/vitesse-dark-BZCL-v6S.js +1 -0
- package/dist/studio/assets/vitesse-light-VbXTXTou.js +1 -0
- package/dist/studio/assets/vue-html-CcxTb_Jn.js +1 -0
- package/dist/studio/assets/vue-vYpz06zQ.js +1 -0
- package/dist/studio/assets/vue-vine-DW4RqCKF.js +1 -0
- package/dist/studio/assets/vyper-CgoNMtux.js +1 -0
- package/dist/studio/assets/wasm-BnjxR4X6.js +1 -0
- package/dist/studio/assets/wasm-ByWQv1Qj.js +1 -0
- package/dist/studio/assets/wenyan-C8pVoKbM.js +1 -0
- package/dist/studio/assets/wgsl-BsKzXJz4.js +1 -0
- package/dist/studio/assets/wikitext-ClFFjSW2.js +1 -0
- package/dist/studio/assets/wit-DdvCle-K.js +1 -0
- package/dist/studio/assets/wolfram-DLL8P-h_.js +1 -0
- package/dist/studio/assets/xml-R4LZ_u4f.js +1 -0
- package/dist/studio/assets/xsl-CS-xzp3L.js +1 -0
- package/dist/studio/assets/yaml-CqDWbYXd.js +1 -0
- package/dist/studio/assets/zenscript-BnlCZFoB.js +1 -0
- package/dist/studio/assets/zig-CMLA9XwU.js +1 -0
- package/dist/studio/index.html +23 -0
- package/dist/think.d.ts +2 -2
- package/dist/think.js +8292 -2
- package/dist/think.js.map +1 -0
- package/dist/tools/extensions.js +1 -1
- package/dist/tools/workspace.js +2 -2
- package/dist/tools/workspace.js.map +1 -1
- package/dist/{types-codegen-B6c5KpYH.js → types-codegen-C-9yeFao.js} +9 -33
- package/dist/types-codegen-C-9yeFao.js.map +1 -0
- package/dist/vite.d.ts +12 -5
- package/dist/vite.js +73 -1
- package/dist/vite.js.map +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/actions.md +297 -0
- package/docs/channels.md +185 -0
- package/docs/client-tools.md +233 -0
- package/docs/getting-started.md +314 -0
- package/docs/index.md +1272 -0
- package/docs/lifecycle-hooks.md +839 -0
- package/docs/messengers.md +197 -0
- package/docs/programmatic-submissions.md +206 -0
- package/docs/sub-agents.md +520 -0
- package/docs/tools.md +582 -0
- package/docs/workflows.md +217 -0
- package/package.json +57 -10
- package/dist/chat-sdk-Bb93yaZh.js.map +0 -1
- package/dist/codegen-CuPdJRpV.js.map +0 -1
- package/dist/framework/index.js.map +0 -1
- package/dist/think-2nHHEcY3.js +0 -6446
- package/dist/think-2nHHEcY3.js.map +0 -1
- package/dist/types-codegen-B6c5KpYH.js.map +0 -1
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../src/framework/virtual.ts","../src/vite.ts"],"sourcesContent":["export interface ThinkVirtualModule {\n id: string;\n resolvedId: string;\n matches(id: string): boolean;\n resolve(id: string): string | null;\n}\n\nexport function createVirtualModule(\n id: `virtual:think/${string}`\n): ThinkVirtualModule {\n const resolvedId = `\\0${id}`;\n return {\n id,\n resolvedId,\n matches(candidate) {\n return candidate === resolvedId;\n },\n resolve(candidate) {\n return candidate === id ? resolvedId : null;\n }\n };\n}\n","import agents from \"agents/vite\";\nimport type { Plugin, PluginOption, ResolvedConfig } from \"vite\";\nimport {\n createThinkWorkerConfig,\n diagnoseThinkWorkerConfig,\n mergeThinkWorkerConfig,\n createThinkWorkerDefaults,\n summarizeThinkManifest,\n type ThinkConfigMergeResult,\n type ThinkWorkerConfigDiagnostic\n} from \"./framework/config\";\nimport {\n generateThinkAgentsModule,\n generateThinkConfigModule,\n generateThinkEntry,\n generateThinkManifestModule,\n generateThinkRouterModule,\n generateThinkServerEntryModule\n} from \"./framework/codegen\";\nimport { createVirtualModule } from \"./framework/virtual\";\nimport type {\n ThinkFrameworkManifest,\n ThinkWorkerConfig,\n ThinkWorkerConfigOptions\n} from \"./framework/manifest\";\nimport {\n applyUserBindingNames,\n readWranglerConfig,\n resolveThinkManifest,\n watchWranglerConfigFiles\n} from \"./framework/project\";\n\nexport interface ThinkVitePluginOptions extends ThinkWorkerConfigOptions {\n files?: Record<string, string>;\n manifest?: ThinkFrameworkManifest;\n allowNonVirtualMain?: boolean;\n}\n\nconst virtualModules = {\n agents: createVirtualModule(\"virtual:think/agents\"),\n config: createVirtualModule(\"virtual:think/config\"),\n entry: createVirtualModule(\"virtual:think/entry\"),\n manifest: createVirtualModule(\"virtual:think/manifest\"),\n router: createVirtualModule(\"virtual:think/router\"),\n serverEntry: createVirtualModule(\"virtual:think/server-entry\")\n};\n\nexport const THINK_EXPERIMENTAL_NOTICE =\n \"The @cloudflare/think framework layer (Vite plugin and `think` CLI) is \" +\n \"experimental and may change or be removed in any release.\";\n\nexport function think(options: ThinkVitePluginOptions = {}): PluginOption[] {\n let config: ResolvedConfig | null = null;\n let manifest: ThinkFrameworkManifest | null = options.manifest ?? null;\n let warnedExperimental = false;\n\n const frameworkPlugin: Plugin = {\n name: \"@cloudflare/think\",\n enforce: \"pre\",\n configResolved(resolved) {\n config = resolved;\n },\n async buildStart() {\n if (!warnedExperimental) {\n warnedExperimental = true;\n this.warn(THINK_EXPERIMENTAL_NOTICE);\n }\n const root = config?.root ?? process.cwd();\n manifest = await resolveThinkManifest(options, root, (file) =>\n this.addWatchFile(file)\n );\n watchWranglerConfigFiles(root, (file) => this.addWatchFile(file));\n if (manifest.agents.length === 0) {\n this.warn(\n 'No Think agents discovered. Add an agent file such as \"agents/support.ts\" exporting a Think subclass or \"export default agent(...)\".'\n );\n } else {\n this.info(\n [\n \"Think framework manifest:\",\n ...summarizeThinkManifest(manifest)\n ].join(\"\\n\")\n );\n }\n const userConfigResult = await readWranglerConfig(root);\n if (userConfigResult.error) {\n this.warn(userConfigResult.error);\n }\n if (userConfigResult.config) {\n applyUserBindingNames(manifest, userConfigResult.config);\n const mergeResult = mergeThinkWorkerConfig(\n userConfigResult.config,\n createThinkWorkerDefaults(manifest, options)\n );\n for (const diagnostic of diagnoseThinkWorkerConfig(\n manifest,\n mergeResult.config,\n {\n allowNonVirtualMain: options.allowNonVirtualMain,\n routeConfig: userConfigResult.config\n }\n ).concat(mergeResult.diagnostics)) {\n reportDiagnostic(\n diagnostic,\n (message) => this.error(message),\n (message) => this.info(message),\n (message) => this.warn(message)\n );\n }\n } else {\n for (const diagnostic of diagnoseThinkWorkerConfig(\n manifest,\n createThinkWorkerDefaults(manifest, options),\n { allowNonVirtualMain: options.allowNonVirtualMain }\n )) {\n reportDiagnostic(\n diagnostic,\n (message) => this.error(message),\n (message) => this.info(message),\n (message) => this.warn(message)\n );\n }\n }\n },\n resolveId(id) {\n for (const virtualModule of Object.values(virtualModules)) {\n const resolved = virtualModule.resolve(id);\n if (resolved) return resolved;\n }\n return null;\n },\n async load(id) {\n const current =\n manifest ??\n (await resolveThinkManifest(options, config?.root ?? process.cwd()));\n if (virtualModules.agents.matches(id)) {\n return generateThinkAgentsModule(current);\n }\n if (virtualModules.config.matches(id)) {\n return generateThinkConfigModule(current);\n }\n if (virtualModules.entry.matches(id)) {\n return generateThinkEntry(current);\n }\n if (virtualModules.manifest.matches(id)) {\n return generateThinkManifestModule(current);\n }\n if (virtualModules.router.matches(id)) {\n return generateThinkRouterModule(current);\n }\n if (virtualModules.serverEntry.matches(id)) {\n return generateThinkServerEntryModule();\n }\n return null;\n }\n };\n\n return [...agents(), frameworkPlugin];\n}\n\nexport default think;\n\nexport async function createThinkViteManifest(\n options: ThinkVitePluginOptions = {},\n root = process.cwd()\n): Promise<ThinkFrameworkManifest> {\n return resolveThinkManifest(options, root);\n}\n\nexport async function createThinkViteWorkerConfig(\n options: ThinkVitePluginOptions = {},\n root = process.cwd()\n): Promise<ThinkWorkerConfig> {\n return (await createThinkViteWorkerConfigResult(options, root)).config;\n}\n\nexport async function createThinkViteWorkerConfigResult(\n options: ThinkVitePluginOptions = {},\n root = process.cwd()\n): Promise<ThinkConfigMergeResult> {\n const manifest = await resolveThinkManifest(options, root);\n const userConfig = await readWranglerConfig(root);\n if (!userConfig.config) {\n const config = createThinkWorkerConfig(manifest, options);\n return {\n config,\n diagnostics: diagnoseThinkWorkerConfig(manifest, config, {\n allowNonVirtualMain: options.allowNonVirtualMain\n })\n };\n }\n applyUserBindingNames(manifest, userConfig.config);\n const result = mergeThinkWorkerConfig(\n userConfig.config,\n createThinkWorkerDefaults(manifest, options)\n );\n return {\n config: result.config,\n diagnostics: [\n ...result.diagnostics,\n ...diagnoseThinkWorkerConfig(manifest, result.config, {\n allowNonVirtualMain: options.allowNonVirtualMain,\n routeConfig: userConfig.config\n })\n ]\n };\n}\n\nfunction reportDiagnostic(\n diagnostic: ThinkWorkerConfigDiagnostic,\n error: (message: string) => void,\n info: (message: string) => void,\n warn: (message: string) => void\n): void {\n const message = `[${diagnostic.code}] ${diagnostic.message}`;\n if (diagnostic.severity === \"error\") {\n error(message);\n return;\n }\n if (diagnostic.severity === \"info\") {\n info(message);\n return;\n }\n warn(message);\n}\n"],"mappings":";;;;AAOA,SAAgB,oBACd,IACoB;CACpB,MAAM,aAAa,KAAK;CACxB,OAAO;EACL;EACA;EACA,QAAQ,WAAW;GACjB,OAAO,cAAc;EACvB;EACA,QAAQ,WAAW;GACjB,OAAO,cAAc,KAAK,aAAa;EACzC;CACF;AACF;;;ACiBA,MAAM,iBAAiB;CACrB,QAAQ,oBAAoB,sBAAsB;CAClD,QAAQ,oBAAoB,sBAAsB;CAClD,OAAO,oBAAoB,qBAAqB;CAChD,UAAU,oBAAoB,wBAAwB;CACtD,QAAQ,oBAAoB,sBAAsB;CAClD,aAAa,oBAAoB,4BAA4B;AAC/D;AAEA,MAAa,4BACX;AAGF,SAAgB,MAAM,UAAkC,CAAC,GAAmB;CAC1E,IAAI,SAAgC;CACpC,IAAI,WAA0C,QAAQ,YAAY;CAClE,IAAI,qBAAqB;CAEzB,MAAM,kBAA0B;EAC9B,MAAM;EACN,SAAS;EACT,eAAe,UAAU;GACvB,SAAS;EACX;EACA,MAAM,aAAa;GACjB,IAAI,CAAC,oBAAoB;IACvB,qBAAqB;IACrB,KAAK,KAAK,yBAAyB;GACrC;GACA,MAAM,OAAO,QAAQ,QAAQ,QAAQ,IAAI;GACzC,WAAW,MAAM,qBAAqB,SAAS,OAAO,SACpD,KAAK,aAAa,IAAI,CACxB;GACA,yBAAyB,OAAO,SAAS,KAAK,aAAa,IAAI,CAAC;GAChE,IAAI,SAAS,OAAO,WAAW,GAC7B,KAAK,KACH,0IACF;QAEA,KAAK,KACH,CACE,6BAC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}
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/framework/virtual.ts","../src/vite.ts"],"sourcesContent":["export interface ThinkVirtualModule {\n id: string;\n resolvedId: string;\n matches(id: string): boolean;\n resolve(id: string): string | null;\n}\n\nexport function createVirtualModule(\n id: `virtual:think/${string}`\n): ThinkVirtualModule {\n const resolvedId = `\\0${id}`;\n return {\n id,\n resolvedId,\n matches(candidate) {\n return candidate === resolvedId;\n },\n resolve(candidate) {\n return candidate === id ? resolvedId : null;\n }\n };\n}\n","import { spawn, type ChildProcess } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport agents from \"agents/vite\";\nimport type { Plugin, PluginOption, ResolvedConfig, ViteDevServer } from \"vite\";\nimport {\n createThinkWorkerConfig,\n diagnoseThinkWorkerConfig,\n mergeThinkWorkerConfig,\n createThinkWorkerDefaults,\n summarizeThinkManifest,\n type ThinkConfigMergeResult,\n type ThinkWorkerConfigDiagnostic\n} from \"./framework/config\";\nimport {\n generateThinkAgentsModule,\n generateThinkConfigModule,\n generateThinkEntry,\n generateThinkManifestModule,\n generateThinkRouterModule,\n generateThinkServerEntryModule\n} from \"./framework/codegen\";\nimport { createVirtualModule } from \"./framework/virtual\";\nimport type {\n ThinkFrameworkManifest,\n ThinkWorkerConfig,\n ThinkWorkerConfigOptions\n} from \"./framework/manifest\";\nimport {\n applyUserBindingNames,\n readWranglerConfig,\n resolveThinkManifest,\n watchWranglerConfigFiles\n} from \"./framework/project\";\n\nexport interface ThinkVitePluginOptions extends ThinkWorkerConfigOptions {\n files?: Record<string, string>;\n manifest?: ThinkFrameworkManifest;\n allowNonVirtualMain?: boolean;\n /**\n * Register the dev-server `s` shortcut that launches Think Studio against the\n * running instance. Defaults to `true` (only active when the prebuilt Studio\n * bundle ships with this package and the dev server runs in an interactive\n * TTY).\n */\n studioShortcut?: boolean;\n}\n\n// This module is built to `dist/vite.js`, so the CLI entry and the prebuilt\n// Studio bundle are siblings under `dist/`.\nconst moduleDir = path.dirname(fileURLToPath(import.meta.url));\nconst STUDIO_INDEX = path.join(moduleDir, \"studio\", \"index.html\");\nconst CLI_ENTRY = path.join(moduleDir, \"cli\", \"index.js\");\n\n/** Derive `host`/`protocol` of the running dev server for `think studio`. */\nfunction devServerTarget(server: ViteDevServer): {\n host: string;\n secure: boolean;\n} {\n const local = server.resolvedUrls?.local?.[0];\n if (local) {\n try {\n const url = new URL(local);\n return { host: url.host, secure: url.protocol === \"https:\" };\n } catch {\n // fall through to the configured port\n }\n }\n const port = server.config.server.port ?? 5173;\n return { host: `localhost:${port}`, secure: false };\n}\n\nconst virtualModules = {\n agents: createVirtualModule(\"virtual:think/agents\"),\n config: createVirtualModule(\"virtual:think/config\"),\n entry: createVirtualModule(\"virtual:think/entry\"),\n manifest: createVirtualModule(\"virtual:think/manifest\"),\n router: createVirtualModule(\"virtual:think/router\"),\n serverEntry: createVirtualModule(\"virtual:think/server-entry\")\n};\n\nexport const THINK_EXPERIMENTAL_NOTICE =\n \"The @cloudflare/think framework layer (Vite plugin and `think` CLI) is \" +\n \"experimental and may change or be removed in any release.\";\n\nexport function think(options: ThinkVitePluginOptions = {}): PluginOption[] {\n let config: ResolvedConfig | null = null;\n let manifest: ThinkFrameworkManifest | null = options.manifest ?? null;\n let warnedExperimental = false;\n\n let studioChild: ChildProcess | null = null;\n\n const frameworkPlugin: Plugin = {\n name: \"@cloudflare/think\",\n enforce: \"pre\",\n configResolved(resolved) {\n config = resolved;\n },\n configureServer(server) {\n if (options.studioShortcut === false) return;\n\n const launchStudio = () => {\n // The Studio bundle + CLI ship in `dist`; guard for source checkouts\n // where the package hasn't been built.\n if (!existsSync(STUDIO_INDEX) || !existsSync(CLI_ENTRY)) {\n server.config.logger.warn(\n \"Think Studio isn't available — build @cloudflare/think to generate the Studio bundle.\"\n );\n return;\n }\n if (studioChild && studioChild.exitCode === null) {\n server.config.logger.info(\"Think Studio is already running.\");\n return;\n }\n const { host, secure } = devServerTarget(server);\n const args = [\n CLI_ENTRY,\n \"studio\",\n \"--host\",\n host,\n \"--root\",\n server.config.root\n ];\n if (secure) args.push(\"--protocol\", \"wss\");\n server.config.logger.info(`\\nLaunching Think Studio for ${host}…`);\n // Ignore the child's stdin so it doesn't contend with Vite's shortcut\n // readline; inherit stdout/stderr so its URL and logs are visible.\n studioChild = spawn(process.execPath, args, {\n stdio: [\"ignore\", \"inherit\", \"inherit\"]\n });\n studioChild.on(\"exit\", () => {\n studioChild = null;\n });\n studioChild.on(\"error\", (error) => {\n server.config.logger.error(\n `Failed to launch Think Studio: ${error.message}`\n );\n studioChild = null;\n });\n };\n\n const registerShortcut = () => {\n server.bindCLIShortcuts({\n customShortcuts: [\n {\n key: \"s\",\n description: \"open Think Studio\",\n action: () => launchStudio()\n }\n ]\n });\n };\n\n // `bindCLIShortcuts` is a no-op until `server.httpServer` is listening, so\n // register once it's up. Vite's own post-`listen` bind then merges custom\n // shortcuts on top of the defaults (via `_shortcutsState`), so `s` survives\n // alongside r/u/o/c/q.\n if (server.httpServer?.listening) registerShortcut();\n else server.httpServer?.once(\"listening\", registerShortcut);\n\n server.httpServer?.once(\"close\", () => {\n studioChild?.kill();\n studioChild = null;\n });\n },\n async buildStart() {\n if (!warnedExperimental) {\n warnedExperimental = true;\n this.warn(THINK_EXPERIMENTAL_NOTICE);\n }\n const root = config?.root ?? process.cwd();\n manifest = await resolveThinkManifest(options, root, (file) =>\n this.addWatchFile(file)\n );\n watchWranglerConfigFiles(root, (file) => this.addWatchFile(file));\n if (manifest.agents.length === 0) {\n this.warn(\n 'No Think agents discovered. Add an agent file such as \"agents/support.ts\" exporting a Think subclass or \"export default agent(...)\".'\n );\n } else {\n this.info(\n [\n \"Think framework manifest:\",\n ...summarizeThinkManifest(manifest)\n ].join(\"\\n\")\n );\n }\n const userConfigResult = await readWranglerConfig(root);\n if (userConfigResult.error) {\n this.warn(userConfigResult.error);\n }\n if (userConfigResult.config) {\n applyUserBindingNames(manifest, userConfigResult.config);\n const mergeResult = mergeThinkWorkerConfig(\n userConfigResult.config,\n createThinkWorkerDefaults(manifest, options)\n );\n for (const diagnostic of diagnoseThinkWorkerConfig(\n manifest,\n mergeResult.config,\n {\n allowNonVirtualMain: options.allowNonVirtualMain,\n routeConfig: userConfigResult.config\n }\n ).concat(mergeResult.diagnostics)) {\n reportDiagnostic(\n diagnostic,\n (message) => this.error(message),\n (message) => this.info(message),\n (message) => this.warn(message)\n );\n }\n } else {\n for (const diagnostic of diagnoseThinkWorkerConfig(\n manifest,\n createThinkWorkerDefaults(manifest, options),\n { allowNonVirtualMain: options.allowNonVirtualMain }\n )) {\n reportDiagnostic(\n diagnostic,\n (message) => this.error(message),\n (message) => this.info(message),\n (message) => this.warn(message)\n );\n }\n }\n },\n resolveId(id) {\n for (const virtualModule of Object.values(virtualModules)) {\n const resolved = virtualModule.resolve(id);\n if (resolved) return resolved;\n }\n return null;\n },\n async load(id) {\n const current =\n manifest ??\n (await resolveThinkManifest(options, config?.root ?? process.cwd()));\n if (virtualModules.agents.matches(id)) {\n return generateThinkAgentsModule(current);\n }\n if (virtualModules.config.matches(id)) {\n return generateThinkConfigModule(current);\n }\n if (virtualModules.entry.matches(id)) {\n return generateThinkEntry(current);\n }\n if (virtualModules.manifest.matches(id)) {\n return generateThinkManifestModule(current);\n }\n if (virtualModules.router.matches(id)) {\n return generateThinkRouterModule(current);\n }\n if (virtualModules.serverEntry.matches(id)) {\n return generateThinkServerEntryModule();\n }\n return null;\n }\n };\n\n return [...agents(), frameworkPlugin];\n}\n\nexport default think;\n\nexport async function createThinkViteManifest(\n options: ThinkVitePluginOptions = {},\n root = process.cwd()\n): Promise<ThinkFrameworkManifest> {\n return resolveThinkManifest(options, root);\n}\n\nexport async function createThinkViteWorkerConfig(\n options: ThinkVitePluginOptions = {},\n root = process.cwd()\n): Promise<ThinkWorkerConfig> {\n return (await createThinkViteWorkerConfigResult(options, root)).config;\n}\n\nexport async function createThinkViteWorkerConfigResult(\n options: ThinkVitePluginOptions = {},\n root = process.cwd()\n): Promise<ThinkConfigMergeResult> {\n const manifest = await resolveThinkManifest(options, root);\n const userConfig = await readWranglerConfig(root);\n if (!userConfig.config) {\n const config = createThinkWorkerConfig(manifest, options);\n return {\n config,\n diagnostics: diagnoseThinkWorkerConfig(manifest, config, {\n allowNonVirtualMain: options.allowNonVirtualMain\n })\n };\n }\n applyUserBindingNames(manifest, userConfig.config);\n const result = mergeThinkWorkerConfig(\n userConfig.config,\n createThinkWorkerDefaults(manifest, options)\n );\n return {\n config: result.config,\n diagnostics: [\n ...result.diagnostics,\n ...diagnoseThinkWorkerConfig(manifest, result.config, {\n allowNonVirtualMain: options.allowNonVirtualMain,\n routeConfig: userConfig.config\n })\n ]\n };\n}\n\nfunction reportDiagnostic(\n diagnostic: ThinkWorkerConfigDiagnostic,\n error: (message: string) => void,\n info: (message: string) => void,\n warn: (message: string) => void\n): void {\n const message = `[${diagnostic.code}] ${diagnostic.message}`;\n if (diagnostic.severity === \"error\") {\n error(message);\n return;\n }\n if (diagnostic.severity === \"info\") {\n info(message);\n return;\n }\n warn(message);\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,oBACd,IACoB;CACpB,MAAM,aAAa,KAAK;CACxB,OAAO;EACL;EACA;EACA,QAAQ,WAAW;GACjB,OAAO,cAAc;EACvB;EACA,QAAQ,WAAW;GACjB,OAAO,cAAc,KAAK,aAAa;EACzC;CACF;AACF;;;AC8BA,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;AAC7D,MAAM,eAAe,KAAK,KAAK,WAAW,UAAU,YAAY;AAChE,MAAM,YAAY,KAAK,KAAK,WAAW,OAAO,UAAU;;AAGxD,SAAS,gBAAgB,QAGvB;CACA,MAAM,QAAQ,OAAO,cAAc,QAAQ;CAC3C,IAAI,OACF,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,KAAK;EACzB,OAAO;GAAE,MAAM,IAAI;GAAM,QAAQ,IAAI,aAAa;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AAI,CAAC,WAAW,QAAQ;EACtB,MAAM,SAAS,wBAAwB,UAAU,OAAO;EACxD,OAAO;GACL;GACA,aAAa,0BAA0B,UAAU,QAAQ,EACvD,qBAAqB,QAAQ,oBAC/B,CAAC;EACH;CACF;CACA,sBAAsB,UAAU,WAAW,MAAM;CACjD,MAAM,SAAS,uBACb,WAAW,QACX,0BAA0B,UAAU,OAAO,CAC7C;CACA,OAAO;EACL,QAAQ,OAAO;EACf,aAAa,CACX,GAAG,OAAO,aACV,GAAG,0BAA0B,UAAU,OAAO,QAAQ;GACpD,qBAAqB,QAAQ;GAC7B,aAAa,WAAW;EAC1B,CAAC,CACH;CACF;AACF;AAEA,SAAS,iBACP,YACA,OACA,MACA,MACM;CACN,MAAM,UAAU,IAAI,WAAW,KAAK,IAAI,WAAW;CACnD,IAAI,WAAW,aAAa,SAAS;EACnC,MAAM,OAAO;EACb;CACF;CACA,IAAI,WAAW,aAAa,QAAQ;EAClC,KAAK,OAAO;EACZ;CACF;CACA,KAAK,OAAO;AACd"}
|
package/dist/workflows.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { on as Think, pn as ThinkSubmissionStatus } from "./index-D_S5mETO.js";
|
|
2
2
|
import { ZodObject, z } from "zod";
|
|
3
3
|
import { WorkflowEvent, WorkflowSleepDuration } from "cloudflare:workers";
|
|
4
4
|
import {
|
package/docs/actions.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Actions
|
|
2
|
+
|
|
3
|
+
> **Experimental.** The API surface may evolve before Think graduates out of
|
|
4
|
+
> experimental.
|
|
5
|
+
|
|
6
|
+
Actions are server-side tools with batteries included. Where a plain AI SDK
|
|
7
|
+
`tool()` is just a description, a schema, and an `execute` function, an
|
|
8
|
+
`action()` adds the things that are tedious and dangerous to get right by hand
|
|
9
|
+
for a tool that has real side effects:
|
|
10
|
+
|
|
11
|
+
- **Idempotency** — a durable ledger replays a settled result by a stable key
|
|
12
|
+
instead of re-running the side effect on a recovery retry.
|
|
13
|
+
- **Approvals** — gate a call behind a human, either inline (the turn waits) or
|
|
14
|
+
durably (the turn parks and resumes later, even from a dashboard with no live
|
|
15
|
+
socket).
|
|
16
|
+
- **Authorization** — declare the permissions a call requires and grant them
|
|
17
|
+
per-turn.
|
|
18
|
+
- **Reply attachments** — record advisory delivery metadata (a drafted email, a
|
|
19
|
+
card, a voice note) without changing what the model sees.
|
|
20
|
+
|
|
21
|
+
Actions compile into Think tools, so the model calls them exactly like any other
|
|
22
|
+
tool. Return them from `getActions()`; Think merges them into the tool set
|
|
23
|
+
alongside `getTools()`, workspace tools, extensions, and MCP tools.
|
|
24
|
+
|
|
25
|
+
## Define an action
|
|
26
|
+
|
|
27
|
+
Use the `action()` descriptor factory and return a map of actions from
|
|
28
|
+
`getActions()`. The map key is the tool name the model sees (unless you set
|
|
29
|
+
`name`). The `execute` input type is inferred from `inputSchema`:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Think, action } from "@cloudflare/think";
|
|
33
|
+
import { z } from "zod";
|
|
34
|
+
|
|
35
|
+
export class Support extends Think<Env> {
|
|
36
|
+
getActions() {
|
|
37
|
+
return {
|
|
38
|
+
refundOrder: action({
|
|
39
|
+
description: "Refund a customer order.",
|
|
40
|
+
inputSchema: z.object({
|
|
41
|
+
orderId: z.string(),
|
|
42
|
+
amountCents: z.number().int().positive()
|
|
43
|
+
}),
|
|
44
|
+
execute: async ({ orderId, amountCents }, ctx) => {
|
|
45
|
+
const result = await refund(orderId, amountCents);
|
|
46
|
+
return { refundId: result.id, status: result.status };
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The `execute` callback receives the validated input and an `ActionContext`:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
type ActionContext = {
|
|
58
|
+
agent: Think;
|
|
59
|
+
env: Cloudflare.Env;
|
|
60
|
+
requestId: string;
|
|
61
|
+
toolCallId: string;
|
|
62
|
+
messages: ReadonlyArray<ModelMessage>;
|
|
63
|
+
signal: AbortSignal; // aborts on turn cancel or after `timeoutMs`
|
|
64
|
+
attachReply(attachment: ReplyAttachment): void;
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The action output is normalized to JSON and truncated before it is shown to the
|
|
69
|
+
model (long outputs are capped). Anything thrown from `execute` becomes a
|
|
70
|
+
structured `{ error: { name, message } }` tool result rather than crashing the
|
|
71
|
+
turn. Each action has a default timeout of 30 seconds; override it per action
|
|
72
|
+
with `timeoutMs`.
|
|
73
|
+
|
|
74
|
+
### Actions versus plain tools
|
|
75
|
+
|
|
76
|
+
A plain `tool()` from `getTools()` still works and is the right choice for a
|
|
77
|
+
read-only or trivial tool. Reach for `action()` when a tool has side effects you
|
|
78
|
+
must not run twice, needs human approval, or needs declarative authorization —
|
|
79
|
+
the ledger, approval descriptors, default timeout, and structured error mapping
|
|
80
|
+
only apply to actions.
|
|
81
|
+
|
|
82
|
+
## Idempotency and the action ledger
|
|
83
|
+
|
|
84
|
+
When an action declares an `idempotencyKey`, Think records the settled result in
|
|
85
|
+
a durable ledger keyed by `action:<name>:<key>`. If the same key is seen again —
|
|
86
|
+
on a recovery retry, a reconnect, or a duplicate inbound event — Think returns
|
|
87
|
+
the stored result **without** re-running `execute`, so the side effect happens
|
|
88
|
+
at most once on the happy path.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
chargeInvoice: action({
|
|
92
|
+
description: "Charge an invoice.",
|
|
93
|
+
inputSchema: z.object({ invoiceId: z.string() }),
|
|
94
|
+
// Use a stable domain identifier — never a timestamp, request id, or random value.
|
|
95
|
+
idempotencyKey: ({ input }) => `invoice:${input.invoiceId}`,
|
|
96
|
+
execute: async ({ invoiceId }) => charge(invoiceId)
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`idempotencyKey` is a string, or a function `({ input, ctx }) => string`. Choose
|
|
101
|
+
a key that survives recovery retries — an order id, an inbound event id — and
|
|
102
|
+
not a value that changes per attempt. An action with no `idempotencyKey` falls
|
|
103
|
+
back to a per-`toolCallId` key, which only deduplicates within the same tool
|
|
104
|
+
call, not across retries.
|
|
105
|
+
|
|
106
|
+
### Pending rows and the retry lease
|
|
107
|
+
|
|
108
|
+
A ledger row is written as `pending` before `execute` runs and flipped to
|
|
109
|
+
`settled` on success (a thrown or timed-out `execute` deletes the row so the
|
|
110
|
+
call can be retried cleanly). If the isolate dies mid-execute, the row is left
|
|
111
|
+
`pending`. By default such a stale row is reclaimed and the action re-run once
|
|
112
|
+
the row is older than `actionLedgerPendingRetryLeaseMs` (default 5 minutes) —
|
|
113
|
+
**but only for actions that declare an explicit `idempotencyKey`**, since that
|
|
114
|
+
key is your assertion that re-running the keyed side effect is safe. A fresh
|
|
115
|
+
pending row (or one without an explicit key) instead returns an
|
|
116
|
+
`ActionPendingError` result so the model does not blindly retry an unknown
|
|
117
|
+
state. Set `actionLedgerPendingRetryLeaseMs = false` to disable reclaim entirely
|
|
118
|
+
and always surface `ActionPendingError` for a stale row.
|
|
119
|
+
|
|
120
|
+
## Approvals
|
|
121
|
+
|
|
122
|
+
Gate an action behind a human with `approval`. There are two mechanisms,
|
|
123
|
+
selected by `kind`.
|
|
124
|
+
|
|
125
|
+
### Approval-gated (the turn waits)
|
|
126
|
+
|
|
127
|
+
The default when you set `approval` without a `kind`. The action compiles to a
|
|
128
|
+
tool with the AI SDK `needsApproval` flag: the stream pauses with an
|
|
129
|
+
`approval-requested` part, the client approves or rejects, and the turn
|
|
130
|
+
continues inline. `execute` runs only after approval.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
deleteAccount: action({
|
|
134
|
+
description: "Permanently delete a user account.",
|
|
135
|
+
inputSchema: z.object({ userId: z.string() }),
|
|
136
|
+
approval: true, // or ({ input }) => input.userId !== currentUser
|
|
137
|
+
approvalSummary: "Delete an account",
|
|
138
|
+
approvalRisk: "high",
|
|
139
|
+
execute: async ({ userId }) => deleteAccount(userId)
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`approval` is a boolean or a predicate `({ input, ctx }) => boolean`, so you can
|
|
144
|
+
require approval only for risky inputs. `approvalSummary` and `approvalRisk`
|
|
145
|
+
(`"low" | "medium" | "high"`) populate the approval descriptor your UI renders.
|
|
146
|
+
|
|
147
|
+
### Durable-pause (the turn parks and resumes later)
|
|
148
|
+
|
|
149
|
+
Set `kind: "durable-pause"` when approval may take minutes or days and you do not
|
|
150
|
+
want to hold a connection open. The action parks into a durable store and the
|
|
151
|
+
turn ends; `execute` does not run yet. Resume later — from anywhere, including a
|
|
152
|
+
dashboard with no live WebSocket — with `approveExecution()` or
|
|
153
|
+
`rejectExecution()`:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
deploy: action({
|
|
157
|
+
description: "Deploy to production.",
|
|
158
|
+
inputSchema: z.object({ ref: z.string() }),
|
|
159
|
+
kind: "durable-pause",
|
|
160
|
+
approvalSummary: "Deploy to production",
|
|
161
|
+
approvalRisk: "high",
|
|
162
|
+
permissions: ["deploy:run"],
|
|
163
|
+
execute: async ({ ref }) => deploy(ref)
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
// List everything waiting on a human (cold-load reconciliation):
|
|
169
|
+
const pending = await agent.pendingApprovals();
|
|
170
|
+
// [{ executionId, source: "action" | "codemode", descriptor }]
|
|
171
|
+
|
|
172
|
+
// Approve or reject by execution id (idempotent — a second call is a no-op):
|
|
173
|
+
await agent.approveExecution(executionId);
|
|
174
|
+
await agent.rejectExecution(executionId, "Not this release");
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`approveExecution()` runs `execute` once and auto-continues the turn even if no
|
|
178
|
+
client is connected; `rejectExecution()` resolves the action without running it.
|
|
179
|
+
`pendingApprovals()` merges parked actions and paused Codemode executions, so a
|
|
180
|
+
single approval UI can drive both. (`durable-pause` requires an `approval`
|
|
181
|
+
policy — an action that would never park is rejected at definition time.)
|
|
182
|
+
|
|
183
|
+
Both approval-gated and durable-pause parts carry a stable
|
|
184
|
+
`ActionApprovalDescriptor` (`{ requestId, toolCallId, action, summary, input,
|
|
185
|
+
permissions, risk, kind }`) so your UI has everything it needs to render the
|
|
186
|
+
prompt.
|
|
187
|
+
|
|
188
|
+
## Authorization
|
|
189
|
+
|
|
190
|
+
Declare the permissions an action requires with `permissions`, then grant them
|
|
191
|
+
per turn. By default every turn is fully authorized, so authorization is opt-in.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
refundOrder: action({
|
|
195
|
+
description: "Refund a customer order.",
|
|
196
|
+
inputSchema: z.object({ orderId: z.string() }),
|
|
197
|
+
permissions: ["billing:refund"], // or ({ input }) => [...]
|
|
198
|
+
execute: async ({ orderId }) => refund(orderId)
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Override `authorizeTurn()` to decide, once per turn, which permissions are
|
|
203
|
+
granted. Returning a list narrows the grant; any action requiring a permission
|
|
204
|
+
outside the set is denied with a structured `ActionAuthorizationError` (the model
|
|
205
|
+
never calls `execute`):
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
export class Support extends Think<Env> {
|
|
209
|
+
override authorizeTurn(ctx: TurnContext): ActionAuthorizationDecision {
|
|
210
|
+
const role = (ctx.body as { role?: string })?.role;
|
|
211
|
+
if (role === "admin") return true; // full grant (the default)
|
|
212
|
+
return { allowed: true, grantedPermissions: ["billing:read"] };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`authorizeTurn()` returns `true` (full grant), `false` (deny all), or
|
|
218
|
+
`{ allowed, reason?, grantedPermissions? }`. For per-call logic, override
|
|
219
|
+
`authorizeAction(ctx)` instead — it receives the action name, kind, input, and
|
|
220
|
+
required and granted permissions.
|
|
221
|
+
|
|
222
|
+
## Reply attachments
|
|
223
|
+
|
|
224
|
+
An action can record advisory delivery metadata for the turn — a drafted email,
|
|
225
|
+
a card, a voice note — with `ctx.attachReply()`. Attachments never change the
|
|
226
|
+
tool output the model sees; they ride alongside the response for your delivery
|
|
227
|
+
layer to render.
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
draftReply: action({
|
|
231
|
+
description: "Draft an email reply.",
|
|
232
|
+
inputSchema: z.object({ to: z.string(), subject: z.string() }),
|
|
233
|
+
execute: async ({ to, subject }, ctx) => {
|
|
234
|
+
ctx.attachReply({ type: "email_draft", to: [to], subject });
|
|
235
|
+
return { drafted: true };
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Read the attachments after the turn from the `onChatResponse()` hook, or from the
|
|
241
|
+
`replyAttachments(requestId?)` getter:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
override async onChatResponse(result: ChatResponseResult) {
|
|
245
|
+
for (const attachment of result.attachments ?? []) {
|
|
246
|
+
// attachment.type === "email_draft" | "card" | "voice_note" | custom
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Attachments are JSON-normalized and deep-copied on read, capped per turn, and
|
|
252
|
+
discarded if the `execute` that recorded them fails. A ledger replay does not
|
|
253
|
+
re-fire attachments (the side effect already happened), and `attachReply()` is a
|
|
254
|
+
no-op when called from a `permissions`, `approval`, or `idempotencyKey` callback
|
|
255
|
+
— record attachments from `execute`.
|
|
256
|
+
|
|
257
|
+
A built-in `ReplyAttachment` covers `email_draft`, `card`, and `voice_note`; any
|
|
258
|
+
`{ type: string; ... }` shape is allowed for custom delivery. Override
|
|
259
|
+
[`renderAttachment()`](./channels.md#deliver-out-of-band) to turn an attachment
|
|
260
|
+
into a channel notice.
|
|
261
|
+
|
|
262
|
+
## Reference
|
|
263
|
+
|
|
264
|
+
### `action(config)`
|
|
265
|
+
|
|
266
|
+
| Field | Type | Required | Default | Description |
|
|
267
|
+
| ----------------- | ------------------------------------------------------------ | -------- | ------------- | --------------------------------------------------------------------------------------- |
|
|
268
|
+
| `description` | `string` | Yes | — | Tool description shown to the model. |
|
|
269
|
+
| `inputSchema` | `FlexibleSchema` (Zod or AI SDK `jsonSchema`) | Yes | — | Validates and types the `execute` input. |
|
|
270
|
+
| `execute` | `(input, ctx) => Output \| Promise<Output>` | Yes | — | The action body. Receives validated input and an `ActionContext`. |
|
|
271
|
+
| `name` | `string` | No | map key | Overrides the tool name. |
|
|
272
|
+
| `idempotencyKey` | `string \| ({ input, ctx }) => string` | No | per tool call | Stable key for ledger replay. Use a domain identifier. |
|
|
273
|
+
| `permissions` | `readonly string[] \| ({ input, ctx }) => readonly string[]` | No | none | Permissions this call requires (see Authorization). |
|
|
274
|
+
| `approval` | `boolean \| ({ input, ctx }) => boolean` | No | none | Gate the call behind a human. |
|
|
275
|
+
| `approvalSummary` | `string` | No | `description` | Human-readable summary in the approval descriptor. |
|
|
276
|
+
| `approvalRisk` | `"low" \| "medium" \| "high"` | No | — | Risk hint in the approval descriptor. |
|
|
277
|
+
| `kind` | `"server" \| "approval-gated" \| "durable-pause"` | No | inferred | `approval-gated` when `approval` is set, else `server`; set `durable-pause` explicitly. |
|
|
278
|
+
| `timeoutMs` | `number` | No | `30000` | Per-action execution timeout (also drives `ctx.signal`). |
|
|
279
|
+
|
|
280
|
+
### Hooks and methods on the agent
|
|
281
|
+
|
|
282
|
+
| Member | Description |
|
|
283
|
+
| --------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
284
|
+
| `getActions()` | Return the action descriptors to compile into tools. |
|
|
285
|
+
| `authorizeTurn(ctx)` | Decide granted permissions once per turn. Defaults to full grant. |
|
|
286
|
+
| `authorizeAction(ctx)` | Decide authorization per action call. Defaults to checking `authorizeTurn` grants. |
|
|
287
|
+
| `pendingApprovals(executionId?)` | List parked actions and paused Codemode executions awaiting approval. |
|
|
288
|
+
| `approveExecution(executionId)` | Approve a parked execution; runs `execute` and auto-continues the turn. |
|
|
289
|
+
| `rejectExecution(executionId, reason?)` | Reject a parked execution without running it. |
|
|
290
|
+
| `replyAttachments(requestId?)` | Read the advisory attachments recorded during a turn. |
|
|
291
|
+
| `actionLedgerPendingRetryLeaseMs` | Stale-pending reclaim window (default `300000`; `false` to disable). |
|
|
292
|
+
|
|
293
|
+
## Related
|
|
294
|
+
|
|
295
|
+
- [Tools](./tools.md) — workspace tools, code execution, and extensions.
|
|
296
|
+
- [Human in the Loop](https://github.com/cloudflare/agents/blob/main/docs/agents/human-in-the-loop.md) — the approval flow end to end.
|
|
297
|
+
- [Channels](./channels.md) — deliver attachments and out-of-band notices.
|
package/docs/channels.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Channels
|
|
2
|
+
|
|
3
|
+
> **Experimental.** The API surface may evolve before Think graduates out of
|
|
4
|
+
> experimental.
|
|
5
|
+
|
|
6
|
+
A channel is a surface a Think agent talks over: the browser WebSocket, a
|
|
7
|
+
messenger webhook (Telegram, Slack, and so on), voice, or your own custom
|
|
8
|
+
transport. Channels generalize [messengers](./messengers.md) into one vocabulary
|
|
9
|
+
so you can apply per-channel policy (a different system prompt, a narrowed tool
|
|
10
|
+
set, a step cap) and deliver out-of-band notices, regardless of the surface a
|
|
11
|
+
turn arrived on.
|
|
12
|
+
|
|
13
|
+
Every Think agent always has an implicit `web` channel (the WebSocket chat your
|
|
14
|
+
browser clients use). You declare additional channels — and override the `web`
|
|
15
|
+
policy — with `configureChannels()`. Messengers returned from `getMessengers()`
|
|
16
|
+
are automatically absorbed as `messenger` channels, so existing messenger apps
|
|
17
|
+
keep working unchanged.
|
|
18
|
+
|
|
19
|
+
## Configure channels
|
|
20
|
+
|
|
21
|
+
Override `configureChannels()` to return a map of channel id to
|
|
22
|
+
`ChannelDefinition`. The id is how you select the channel on a turn:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Think, messengerChannel } from "@cloudflare/think";
|
|
26
|
+
import { telegram } from "@chat-adapter/telegram";
|
|
27
|
+
|
|
28
|
+
export class Assistant extends Think<Env> {
|
|
29
|
+
configureChannels() {
|
|
30
|
+
return {
|
|
31
|
+
// Override policy for the built-in web channel.
|
|
32
|
+
web: {
|
|
33
|
+
kind: "web",
|
|
34
|
+
ingress: { transport: "websocket" },
|
|
35
|
+
instructions: "You are chatting in a web app. Use markdown freely."
|
|
36
|
+
},
|
|
37
|
+
// A voice channel with tighter limits.
|
|
38
|
+
voice: {
|
|
39
|
+
kind: "voice",
|
|
40
|
+
ingress: { transport: "voice" },
|
|
41
|
+
instructions: "Keep replies short and speakable. No markdown.",
|
|
42
|
+
maxTurns: 3
|
|
43
|
+
},
|
|
44
|
+
// A messenger channel (Chat SDK webhook).
|
|
45
|
+
telegram: messengerChannel(
|
|
46
|
+
telegram({
|
|
47
|
+
/* adapter config */
|
|
48
|
+
})
|
|
49
|
+
)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A `ChannelDefinition` has these fields:
|
|
56
|
+
|
|
57
|
+
| Field | Type | Description |
|
|
58
|
+
| -------------- | ------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
59
|
+
| `kind` | `"web" \| "messenger" \| "voice" \| "custom"` | The surface category. |
|
|
60
|
+
| `ingress` | `{ transport: "websocket" \| "voice" }` or a webhook messenger spec | How turns arrive. `messengerChannel()` builds the webhook form for you. |
|
|
61
|
+
| `instructions` | `string \| (ctx: ChannelContext) => string \| Promise<string>` | Prepended to the system prompt for turns on this channel. |
|
|
62
|
+
| `tools` | `(all: ToolSet) => ToolSet` | Narrow the assembled tool set for this channel (filter only — it cannot add tools). |
|
|
63
|
+
| `maxTurns` | `number` | Per-channel cap on model steps for a turn. |
|
|
64
|
+
| `capabilities` | `ChannelCapabilities` | Surface capabilities (streaming, message editing). Defaulted for `web`. |
|
|
65
|
+
| `conversation` | messenger conversation mode or resolver | Messenger thread routing (see [Messengers](./messengers.md)). |
|
|
66
|
+
| `delivery` | channel delivery policy | Messenger delivery policy. |
|
|
67
|
+
|
|
68
|
+
Use `messengerChannel()` to wrap a Chat SDK adapter definition as a `kind: "messenger"` channel. Add a `ThinkChannels` return type or `satisfies ThinkChannels` when you want compile-time checks for inline channel maps.
|
|
69
|
+
|
|
70
|
+
### Channel kinds
|
|
71
|
+
|
|
72
|
+
| Kind | Ingress | Notes |
|
|
73
|
+
| ----------- | --------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
74
|
+
| `web` | `{ transport: "websocket" }` | Always present. Declare it in `configureChannels()` only to set policy; you cannot remove it. |
|
|
75
|
+
| `messenger` | webhook (`messengerChannel(...)`) | Fed into the messenger runtime. Equivalent to a `getMessengers()` entry. |
|
|
76
|
+
| `voice` | `{ transport: "voice" }` | Applies policy and turn context; out-of-band delivery is not yet wired. |
|
|
77
|
+
| `custom` | app-defined | For your own transport. Same delivery limitations as `voice` today. |
|
|
78
|
+
|
|
79
|
+
## Per-channel policy
|
|
80
|
+
|
|
81
|
+
Channel policy is applied as an **overridable default** before
|
|
82
|
+
[`beforeTurn`](./lifecycle-hooks.md) runs, so a `beforeTurn` override still wins:
|
|
83
|
+
|
|
84
|
+
- `instructions` is prepended to the base system prompt for the turn.
|
|
85
|
+
- `tools` filters the assembled tool set (it can only remove tools — the
|
|
86
|
+
`getTools()` seam adds them).
|
|
87
|
+
- `maxTurns` caps model steps: `beforeTurn`'s `maxSteps` wins, then the channel
|
|
88
|
+
`maxTurns`, then the instance `maxSteps` default.
|
|
89
|
+
|
|
90
|
+
## Select a channel on a turn
|
|
91
|
+
|
|
92
|
+
Pass `channel` to [`runTurn()`](./index.md#runturn) (or `chat()`) to run a turn
|
|
93
|
+
on a specific channel. The channel id is stamped onto the user message, so a
|
|
94
|
+
continued or recovered turn re-resolves the same channel and re-applies its
|
|
95
|
+
policy:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
await this.runTurn({ input: "Read this out loud", channel: "voice" });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Inside a turn, the active channel is available as `this.activeChannel` (a
|
|
102
|
+
`ChannelContext` with `channelId`, `kind`, and messenger details when relevant).
|
|
103
|
+
A turn with no `channel` runs without a channel context and applies no channel
|
|
104
|
+
policy.
|
|
105
|
+
|
|
106
|
+
## Deliver out of band
|
|
107
|
+
|
|
108
|
+
`deliverNotice()` sends a message to a channel **without** starting a model turn.
|
|
109
|
+
Use it for status updates ("your import finished") or to surface an action's
|
|
110
|
+
[reply attachment](./actions.md#reply-attachments) — it does not run inference,
|
|
111
|
+
does not enter the turn queue, and is therefore safe to call from inside a tool's
|
|
112
|
+
`execute`:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
await this.deliverNotice("Your export is ready to download.");
|
|
116
|
+
|
|
117
|
+
await this.deliverNotice("Background research finished.", {
|
|
118
|
+
informModel: true // also record it in the transcript so the next turn knows
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
type DeliverNoticeOptions = {
|
|
124
|
+
channel?: string; // defaults to the active turn's channel, else "web"
|
|
125
|
+
informModel?: boolean; // also write to the model-visible transcript (default false)
|
|
126
|
+
kind?: "final" | "interim" | "notice" | "command"; // wire tag (default "notice")
|
|
127
|
+
thread?: string; // required for out-of-turn delivery to a multi-thread messenger
|
|
128
|
+
};
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Behavior depends on the target channel:
|
|
132
|
+
|
|
133
|
+
- **`web`** — the notice is always appended to the transcript (that is its only
|
|
134
|
+
render path). `informModel` then only controls the phrasing.
|
|
135
|
+
- **`messenger`** — the notice is posted to the provider. Out of turn, pass
|
|
136
|
+
`thread` to target a conversation. With `informModel: true`, it is also written
|
|
137
|
+
to the transcript.
|
|
138
|
+
- **`voice` / `custom`** — out-of-turn delivery throws, because these surfaces
|
|
139
|
+
have no delivery target yet.
|
|
140
|
+
|
|
141
|
+
Override `renderAttachment(attachment)` to turn an action reply attachment into a
|
|
142
|
+
notice; Think calls it at the end of a turn and delivers the rendered text as a
|
|
143
|
+
trailing `interim` notice. Return `undefined` to skip an attachment type.
|
|
144
|
+
|
|
145
|
+
## Relationship to messengers
|
|
146
|
+
|
|
147
|
+
`configureChannels()` wraps `getMessengers()` — it does not replace it. Each
|
|
148
|
+
`getMessengers()` entry becomes a `kind: "messenger"` channel, and everything in
|
|
149
|
+
the [Messengers](./messengers.md) guide (Telegram setup, webhook routing,
|
|
150
|
+
conversation targets, delivery and recovery) continues to apply. A channel id in
|
|
151
|
+
`configureChannels()` that collides with a `getMessengers()` id is an error. Keep
|
|
152
|
+
using `getMessengers()` for messenger-only apps; reach for `configureChannels()`
|
|
153
|
+
when you also want `web`/`voice`/`custom` policy or out-of-band notices.
|
|
154
|
+
|
|
155
|
+
## Observability
|
|
156
|
+
|
|
157
|
+
Channel activity is reported on the `channel` observability channel:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { subscribe } from "agents/observability";
|
|
161
|
+
|
|
162
|
+
const unsubscribe = subscribe("channel", (event) => {
|
|
163
|
+
// event.type is one of:
|
|
164
|
+
// "channel:resolved" — a turn resolved a registered channel
|
|
165
|
+
// "channel:delivered" — a turn's final reply was delivered
|
|
166
|
+
// "notice:delivered" — deliverNotice() succeeded
|
|
167
|
+
// "notice:failed" — deliverNotice() threw
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Reference
|
|
172
|
+
|
|
173
|
+
| Member | Description |
|
|
174
|
+
| ------------------------------- | --------------------------------------------------------------------------- |
|
|
175
|
+
| `configureChannels()` | Return the channel map. Defaults to `{}` (the implicit `web` channel only). |
|
|
176
|
+
| `deliverNotice(text, options?)` | Send an out-of-band message to a channel with no model turn. |
|
|
177
|
+
| `activeChannel` | The `ChannelContext` for the in-flight turn, or `undefined`. |
|
|
178
|
+
| `renderAttachment(attachment)` | Map a reply attachment to channel notice text (or `undefined` to skip). |
|
|
179
|
+
| `messengerChannel(definition)` | Wrap a Chat SDK adapter as a `kind: "messenger"` channel. |
|
|
180
|
+
|
|
181
|
+
## Related
|
|
182
|
+
|
|
183
|
+
- [Messengers](./messengers.md) — Chat SDK webhook setup and delivery in depth.
|
|
184
|
+
- [Actions](./actions.md) — record reply attachments for `renderAttachment()`.
|
|
185
|
+
- [Voice Agents](https://github.com/cloudflare/agents/blob/main/docs/voice/index.md) — real-time speech surfaces.
|