palettecn 0.1.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/dist/index.mjs +10 -0
- package/dist/web/nitro.json +17 -0
- package/dist/web/public/assets/abap-BdvmRIgS.js +1 -0
- package/dist/web/public/assets/actionscript-3-et0rQaqm.js +1 -0
- package/dist/web/public/assets/ada-DPgrustg.js +1 -0
- package/dist/web/public/assets/andromeeda-DJl1yeV_.js +1 -0
- package/dist/web/public/assets/angular-html-Dm7s7tSx.js +1 -0
- package/dist/web/public/assets/angular-ts-B_ywTULt.js +1 -0
- package/dist/web/public/assets/apache-CFpsYX8S.js +1 -0
- package/dist/web/public/assets/apex-CN5n6pbI.js +1 -0
- package/dist/web/public/assets/apl-Dm11wHHc.js +1 -0
- package/dist/web/public/assets/applescript-JrY23hsL.js +1 -0
- package/dist/web/public/assets/ara-DR83hn3A.js +1 -0
- package/dist/web/public/assets/asciidoc-Dpu9XLB1.js +1 -0
- package/dist/web/public/assets/asm-BYI3A31V.js +1 -0
- package/dist/web/public/assets/astro-DP1naDCT.js +1 -0
- package/dist/web/public/assets/aurora-x-Nav5jnoQ.js +1 -0
- package/dist/web/public/assets/awk-BIoTx_w6.js +1 -0
- package/dist/web/public/assets/ayu-dark-H5QV5J7K.js +1 -0
- package/dist/web/public/assets/ayu-light-BrwTNGnU.js +1 -0
- package/dist/web/public/assets/ayu-mirage-Bg6FpF5w.js +1 -0
- package/dist/web/public/assets/ballerina-BFvDNd4T.js +1 -0
- package/dist/web/public/assets/bat-DtQkx7Ny.js +1 -0
- package/dist/web/public/assets/beancount-BIjKALa1.js +1 -0
- package/dist/web/public/assets/berry-BPkDN_EZ.js +1 -0
- package/dist/web/public/assets/bibtex-Dur2CNW6.js +1 -0
- package/dist/web/public/assets/bicep-BMz1bZ7m.js +1 -0
- package/dist/web/public/assets/bird2-91rdr9s7.js +1 -0
- package/dist/web/public/assets/blade-DD5O596X.js +1 -0
- package/dist/web/public/assets/bsl-FmB7U2qd.js +1 -0
- package/dist/web/public/assets/bundle-mjs-Bso3xn9x.js +1 -0
- package/dist/web/public/assets/c-DqqBLLyl.js +1 -0
- package/dist/web/public/assets/c3-CJTbEooS.js +1 -0
- package/dist/web/public/assets/cadence-C0GI7BZZ.js +1 -0
- package/dist/web/public/assets/cairo-B5JMmIC0.js +1 -0
- package/dist/web/public/assets/catppuccin-frappe-D76-cUjK.js +1 -0
- package/dist/web/public/assets/catppuccin-latte-DUHNJ_6_.js +1 -0
- package/dist/web/public/assets/catppuccin-macchiato-CFhPH2wd.js +1 -0
- package/dist/web/public/assets/catppuccin-mocha-BRD0cvUW.js +1 -0
- package/dist/web/public/assets/chunk-FRKYWMV7-DUkk3w4h.js +122 -0
- package/dist/web/public/assets/clarity-KgUVrNfC.js +1 -0
- package/dist/web/public/assets/clojure-BhQuoGIG.js +1 -0
- package/dist/web/public/assets/cmake-CA59gUFQ.js +1 -0
- package/dist/web/public/assets/cobol-CCFShgGZ.js +1 -0
- package/dist/web/public/assets/codeowners-CD36YqjJ.js +1 -0
- package/dist/web/public/assets/codeql-CrMosKUt.js +1 -0
- package/dist/web/public/assets/coffee-C-Mn3tBT.js +1 -0
- package/dist/web/public/assets/common-lisp-DYnOjAFz.js +1 -0
- package/dist/web/public/assets/components-DiZ1dSl3.js +77 -0
- package/dist/web/public/assets/coq-BaHtq3Qt.js +1 -0
- package/dist/web/public/assets/cpp-D8Y73ItU.js +1 -0
- package/dist/web/public/assets/crystal-CnXWqbxx.js +1 -0
- package/dist/web/public/assets/csharp-D6sghVPa.js +1 -0
- package/dist/web/public/assets/css-CUGjdPw_.js +1 -0
- package/dist/web/public/assets/csv-DuxyxUAI.js +1 -0
- package/dist/web/public/assets/cue-D9NRAX0_.js +1 -0
- package/dist/web/public/assets/cypher-HJRdtilF.js +1 -0
- package/dist/web/public/assets/d-B4Ont7_X.js +1 -0
- package/dist/web/public/assets/dark-plus-DZSBycyp.js +1 -0
- package/dist/web/public/assets/dart-Dp4asavE.js +1 -0
- package/dist/web/public/assets/dax-DBUubp6S.js +1 -0
- package/dist/web/public/assets/desktop-DQ0n6zIQ.js +1 -0
- package/dist/web/public/assets/diff-CFHlrffC.js +1 -0
- package/dist/web/public/assets/docker-BuefmsF5.js +1 -0
- package/dist/web/public/assets/dotenv-BKTsUQ_r.js +1 -0
- package/dist/web/public/assets/dracula-MOn9qacs.js +1 -0
- package/dist/web/public/assets/dracula-soft-C4r_sC_D.js +1 -0
- package/dist/web/public/assets/dream-maker-BNdv5lLS.js +1 -0
- package/dist/web/public/assets/edge-C-Mi8Oda.js +1 -0
- package/dist/web/public/assets/elixir-CTS5wQtX.js +1 -0
- package/dist/web/public/assets/elm-rM310x8D.js +1 -0
- package/dist/web/public/assets/emacs-lisp-D9FIGRtM.js +1 -0
- package/dist/web/public/assets/erb-oaGjGVGO.js +1 -0
- package/dist/web/public/assets/erlang-q4Mkyw3m.js +1 -0
- package/dist/web/public/assets/everforest-dark-CNa2QFRn.js +1 -0
- package/dist/web/public/assets/everforest-light-DRbUDqJT.js +1 -0
- package/dist/web/public/assets/fennel-DpqQTaVZ.js +1 -0
- package/dist/web/public/assets/field-1-Ujza0S5j.js +1 -0
- package/dist/web/public/assets/fish-hyk5x6Q4.js +1 -0
- package/dist/web/public/assets/fluent-DMll-MGX.js +1 -0
- package/dist/web/public/assets/fortran-fixed-form-BmdfKovV.js +1 -0
- package/dist/web/public/assets/fortran-free-form-MCAifii4.js +1 -0
- package/dist/web/public/assets/fsharp-DLlBn9Nl.js +1 -0
- package/dist/web/public/assets/gdresource-BzFzBRli.js +1 -0
- package/dist/web/public/assets/gdscript-D3R4J0Cv.js +1 -0
- package/dist/web/public/assets/gdshader-BAubtqqN.js +1 -0
- package/dist/web/public/assets/genie-BnIIX2pC.js +1 -0
- package/dist/web/public/assets/gherkin-CL3NUuB1.js +1 -0
- package/dist/web/public/assets/git-commit-BYPE8h85.js +1 -0
- package/dist/web/public/assets/git-rebase-Bmmgf6eN.js +1 -0
- package/dist/web/public/assets/github-dark-default-C6I2oE4c.js +1 -0
- package/dist/web/public/assets/github-dark-dimmed-DEqwxg6D.js +1 -0
- package/dist/web/public/assets/github-dark-high-contrast-DDt3j0cs.js +1 -0
- package/dist/web/public/assets/github-dark-oLN6SDKl.js +1 -0
- package/dist/web/public/assets/github-light-DaN-N2Gj.js +1 -0
- package/dist/web/public/assets/github-light-default-B3EwMbS7.js +1 -0
- package/dist/web/public/assets/github-light-high-contrast-Cl9D0f_e.js +1 -0
- package/dist/web/public/assets/gleam-Cvj8QRtQ.js +1 -0
- package/dist/web/public/assets/glimmer-js-CahbROb1.js +1 -0
- package/dist/web/public/assets/glimmer-ts-JMFYNbot.js +1 -0
- package/dist/web/public/assets/global-XWAvxWcA.css +2 -0
- package/dist/web/public/assets/glsl-BCuCNM3V.js +1 -0
- package/dist/web/public/assets/gn-DxCHSEMl.js +1 -0
- package/dist/web/public/assets/gnuplot-CkGXHK7B.js +1 -0
- package/dist/web/public/assets/go-B_NLCuTj.js +1 -0
- package/dist/web/public/assets/graphql-RXOfHGfI.js +1 -0
- package/dist/web/public/assets/groovy-DVge8oRs.js +1 -0
- package/dist/web/public/assets/gruvbox-dark-hard-BwZz1yni.js +1 -0
- package/dist/web/public/assets/gruvbox-dark-medium-Bqy6jkuO.js +1 -0
- package/dist/web/public/assets/gruvbox-dark-soft-DjUvyUfH.js +1 -0
- package/dist/web/public/assets/gruvbox-light-hard-BTLmfPdm.js +1 -0
- package/dist/web/public/assets/gruvbox-light-medium-DeWqsWs6.js +1 -0
- package/dist/web/public/assets/gruvbox-light-soft-BL8ld-1F.js +1 -0
- package/dist/web/public/assets/hack-BBQpwyf_.js +1 -0
- package/dist/web/public/assets/haml-mWELc9kh.js +1 -0
- package/dist/web/public/assets/handlebars-COrUo8cC.js +1 -0
- package/dist/web/public/assets/haskell-DRmM8XlQ.js +1 -0
- package/dist/web/public/assets/haxe-BEhq8ZEr.js +1 -0
- package/dist/web/public/assets/hcl-B5ZIaGS0.js +1 -0
- package/dist/web/public/assets/highlighted-body-TPN3WLV5-YJgGFx4e.js +1 -0
- package/dist/web/public/assets/hjson-B9uRLqIO.js +1 -0
- package/dist/web/public/assets/hlsl-Hv1kKjrS.js +1 -0
- package/dist/web/public/assets/horizon-ClXGBjWw.js +1 -0
- package/dist/web/public/assets/horizon-bright-CvUCr3ux.js +1 -0
- package/dist/web/public/assets/houston-NqkqG60q.js +1 -0
- package/dist/web/public/assets/html-cmigv1ou.js +1 -0
- package/dist/web/public/assets/html-derivative-B3me0pSu.js +1 -0
- package/dist/web/public/assets/http-BojM9cyU.js +1 -0
- package/dist/web/public/assets/hurl-BxEmMiGP.js +1 -0
- package/dist/web/public/assets/hxml-CoBuVbfs.js +1 -0
- package/dist/web/public/assets/hy-CeISYGGU.js +1 -0
- package/dist/web/public/assets/imba-xjcDFXUW.js +1 -0
- package/dist/web/public/assets/ini-D0ZCSj6e.js +1 -0
- package/dist/web/public/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/dist/web/public/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/dist/web/public/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/dist/web/public/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/dist/web/public/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/dist/web/public/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/dist/web/public/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/dist/web/public/assets/java-BvheClGI.js +1 -0
- package/dist/web/public/assets/javascript-DjlJORDg.js +1 -0
- package/dist/web/public/assets/jinja-Bi4sG72X.js +1 -0
- package/dist/web/public/assets/jison-BTz5Ik2Y.js +1 -0
- package/dist/web/public/assets/json-CiTd40Rg.js +1 -0
- package/dist/web/public/assets/json5-FR9EyF7a.js +1 -0
- package/dist/web/public/assets/jsonc-CHIeFfsD.js +1 -0
- package/dist/web/public/assets/jsonl-B4WQkwTf.js +1 -0
- package/dist/web/public/assets/jsonnet-vd-gzGkL.js +1 -0
- package/dist/web/public/assets/jssm-C_bj1LkZ.js +1 -0
- package/dist/web/public/assets/jsx-Bx-RZMFH.js +1 -0
- package/dist/web/public/assets/jsx-runtime-n8k0hwt8.js +1 -0
- package/dist/web/public/assets/julia-BKcIfSxk.js +1 -0
- package/dist/web/public/assets/just-IkZCagAs.js +1 -0
- package/dist/web/public/assets/kanagawa-dragon-B3Cz89vt.js +1 -0
- package/dist/web/public/assets/kanagawa-lotus-CRe_W5Ft.js +1 -0
- package/dist/web/public/assets/kanagawa-wave-BPqZ5XB7.js +1 -0
- package/dist/web/public/assets/kdl-BzL_Ak31.js +1 -0
- package/dist/web/public/assets/kotlin-BQQFk6ql.js +1 -0
- package/dist/web/public/assets/kusto-vWe6OLKV.js +1 -0
- package/dist/web/public/assets/laserwave-CwtvEUcj.js +1 -0
- package/dist/web/public/assets/latex-9N90_WFU.js +1 -0
- package/dist/web/public/assets/lean-CaqenOqv.js +1 -0
- package/dist/web/public/assets/less-CERnPzn6.js +1 -0
- package/dist/web/public/assets/light-plus-B9_M_OKq.js +1 -0
- package/dist/web/public/assets/liquid-CQLPDP7m.js +1 -0
- package/dist/web/public/assets/llvm-BylJXvm7.js +1 -0
- package/dist/web/public/assets/log-CBBcNcbO.js +1 -0
- package/dist/web/public/assets/logo-r-8Jc8Xk.js +1 -0
- package/dist/web/public/assets/lua-BBL6LXKd.js +1 -0
- package/dist/web/public/assets/luau-B2g7L-zP.js +1 -0
- package/dist/web/public/assets/main-0lKVDR64.css +2 -0
- package/dist/web/public/assets/main-CcNf0BOb.js +126 -0
- package/dist/web/public/assets/make-DK-HzJ2w.js +1 -0
- package/dist/web/public/assets/markdown-FgdsukgR.js +1 -0
- package/dist/web/public/assets/marko-CLZwt2N2.js +1 -0
- package/dist/web/public/assets/material-theme-DOJ9PS4O.js +1 -0
- package/dist/web/public/assets/material-theme-darker-DOurH5jT.js +1 -0
- package/dist/web/public/assets/material-theme-lighter-BfPWxCP6.js +1 -0
- package/dist/web/public/assets/material-theme-ocean-BcO5PKoq.js +1 -0
- package/dist/web/public/assets/material-theme-palenight-ClWQBDDd.js +1 -0
- package/dist/web/public/assets/matlab-DwyUVNXd.js +1 -0
- package/dist/web/public/assets/mdc-Bo8CRPg4.js +1 -0
- package/dist/web/public/assets/mdx-3EBShbsD.js +1 -0
- package/dist/web/public/assets/mermaid-ByG2-SLz.js +1 -0
- package/dist/web/public/assets/mermaid-O7DHMXV3-COAgR3aM.js +1 -0
- package/dist/web/public/assets/min-dark-ClJ2x5pc.js +1 -0
- package/dist/web/public/assets/min-light-BsOUz5iE.js +1 -0
- package/dist/web/public/assets/mipsasm-BKDtQCf3.js +1 -0
- package/dist/web/public/assets/mojo-DmEAK7iv.js +1 -0
- package/dist/web/public/assets/monokai-BKc3VADO.js +1 -0
- package/dist/web/public/assets/moonbit-Qm8v_cKN.js +1 -0
- package/dist/web/public/assets/move-CMectUPk.js +1 -0
- package/dist/web/public/assets/narrat-Bdm8NaK8.js +1 -0
- package/dist/web/public/assets/nextflow-BpSt05nC.js +1 -0
- package/dist/web/public/assets/nextflow-groovy-BZ-bqJ-u.js +1 -0
- package/dist/web/public/assets/nginx-ChZL5FWE.js +1 -0
- package/dist/web/public/assets/night-owl-CbFc5pXO.js +1 -0
- package/dist/web/public/assets/night-owl-light-zYbVCVuz.js +1 -0
- package/dist/web/public/assets/nim-5JnPAJWa.js +1 -0
- package/dist/web/public/assets/nix-P5P-2qHs.js +1 -0
- package/dist/web/public/assets/nord-C7hKGudV.js +1 -0
- package/dist/web/public/assets/nushell-DKPnC5RG.js +1 -0
- package/dist/web/public/assets/objective-c-BPwXtM0v.js +1 -0
- package/dist/web/public/assets/objective-cpp-CWYEdWNG.js +1 -0
- package/dist/web/public/assets/ocaml-CL7OJ02v.js +1 -0
- package/dist/web/public/assets/odin-Dtay25eA.js +1 -0
- package/dist/web/public/assets/one-dark-pro-CrdFNNwF.js +1 -0
- package/dist/web/public/assets/one-light-BUiz8X4B.js +1 -0
- package/dist/web/public/assets/openscad-WD4sXUUp.js +1 -0
- package/dist/web/public/assets/pascal-A6-MZnZ8.js +1 -0
- package/dist/web/public/assets/perl-Yq3AfnVV.js +1 -0
- package/dist/web/public/assets/php-CCj0foPx.js +1 -0
- package/dist/web/public/assets/pkl-cmPbg8fI.js +1 -0
- package/dist/web/public/assets/plastic-DtQ_LnDB.js +1 -0
- package/dist/web/public/assets/plsql-DwmuVd7q.js +1 -0
- package/dist/web/public/assets/po-CkVxkZaj.js +1 -0
- package/dist/web/public/assets/poimandres-Dt0xZuaa.js +1 -0
- package/dist/web/public/assets/polar-hStNz_W2.js +1 -0
- package/dist/web/public/assets/postcss-ZIk0AQ7M.js +1 -0
- package/dist/web/public/assets/powerquery-D0gqoHHD.js +1 -0
- package/dist/web/public/assets/powershell-DXB5HoVh.js +1 -0
- package/dist/web/public/assets/prisma-DmTrfxC0.js +1 -0
- package/dist/web/public/assets/prolog-CdoyriEj.js +1 -0
- package/dist/web/public/assets/proto-4MrN11dS.js +1 -0
- package/dist/web/public/assets/pug-svYJKDOQ.js +1 -0
- package/dist/web/public/assets/puppet-MEaLGpAP.js +1 -0
- package/dist/web/public/assets/purescript-CPxCorqB.js +1 -0
- package/dist/web/public/assets/python-f4fp5z0z.js +1 -0
- package/dist/web/public/assets/qml-BzEtWdqI.js +1 -0
- package/dist/web/public/assets/qmldir-DCjSceJ_.js +1 -0
- package/dist/web/public/assets/qss-BdM02NUc.js +1 -0
- package/dist/web/public/assets/r-luosIeJH.js +1 -0
- package/dist/web/public/assets/racket-D2tfa8Zc.js +1 -0
- package/dist/web/public/assets/raku-KeGPJVZg.js +1 -0
- package/dist/web/public/assets/razor-Bokxs4Qx.js +1 -0
- package/dist/web/public/assets/red-C0qZ-1lN.js +1 -0
- package/dist/web/public/assets/reg-DdnswvOj.js +1 -0
- package/dist/web/public/assets/regexp-CYC8h6V9.js +1 -0
- package/dist/web/public/assets/rel-RhzEfSRc.js +1 -0
- package/dist/web/public/assets/riscv-dS5TzX10.js +1 -0
- package/dist/web/public/assets/ron-CQjQSCVp.js +1 -0
- package/dist/web/public/assets/rose-pine-C89ViLdr.js +1 -0
- package/dist/web/public/assets/rose-pine-dawn-Dq2gf0yi.js +1 -0
- package/dist/web/public/assets/rose-pine-moon-CBDvXVs_.js +1 -0
- package/dist/web/public/assets/rosmsg-nvjuSIGu.js +1 -0
- package/dist/web/public/assets/routes-BXqJCOpL.js +542 -0
- package/dist/web/public/assets/rst-1xwvVGf7.js +1 -0
- package/dist/web/public/assets/ruby-Blad-eDx.js +1 -0
- package/dist/web/public/assets/rust-rV8q_xyI.js +1 -0
- package/dist/web/public/assets/sas-DUPWtptg.js +1 -0
- package/dist/web/public/assets/sass-CuxdoNN0.js +1 -0
- package/dist/web/public/assets/scala-Df4L7N3R.js +1 -0
- package/dist/web/public/assets/scheme-DalRmAPH.js +1 -0
- package/dist/web/public/assets/scss-CYQ8LEwP.js +1 -0
- package/dist/web/public/assets/sdbl-B_TmFnGf.js +1 -0
- package/dist/web/public/assets/shaderlab-DYEMDY3e.js +1 -0
- package/dist/web/public/assets/shellscript-DjKZ34ac.js +1 -0
- package/dist/web/public/assets/shellsession-C3kcnBnh.js +1 -0
- package/dist/web/public/assets/slack-dark-ak_jOeLl.js +1 -0
- package/dist/web/public/assets/slack-ochin-ByiYhLwu.js +1 -0
- package/dist/web/public/assets/smalltalk-DTTnjjZJ.js +1 -0
- package/dist/web/public/assets/snazzy-light-BBRYeY60.js +1 -0
- package/dist/web/public/assets/solarized-dark-BtoLnWkw.js +1 -0
- package/dist/web/public/assets/solarized-light-CtzUA7GI.js +1 -0
- package/dist/web/public/assets/solidity-CSIHEQ2t.js +1 -0
- package/dist/web/public/assets/soy-BN0uzUAI.js +1 -0
- package/dist/web/public/assets/sparql-B6k9tA6Q.js +1 -0
- package/dist/web/public/assets/splunk-DkRzN7V_.js +1 -0
- package/dist/web/public/assets/sql-Bx-WX28V.js +1 -0
- package/dist/web/public/assets/ssh-config-Bqp7ng33.js +1 -0
- package/dist/web/public/assets/stata-HAj7doU8.js +1 -0
- package/dist/web/public/assets/stylus-CdbCxDLX.js +1 -0
- package/dist/web/public/assets/surrealql-BkGf0I3k.js +1 -0
- package/dist/web/public/assets/svelte-DtWg6ssL.js +1 -0
- package/dist/web/public/assets/swift-yRu2dtgr.js +1 -0
- package/dist/web/public/assets/synthwave-84-2WIu6MHX.js +1 -0
- package/dist/web/public/assets/system-verilog-GUE_oP1V.js +1 -0
- package/dist/web/public/assets/systemd-FLIJAQZV.js +1 -0
- package/dist/web/public/assets/talonscript-DTR-8ILs.js +1 -0
- package/dist/web/public/assets/tasl-WHNWP-1F.js +1 -0
- package/dist/web/public/assets/tcl-BaBXNNp6.js +1 -0
- package/dist/web/public/assets/templ-Dc9vj00n.js +1 -0
- package/dist/web/public/assets/terraform-uJUFpr8t.js +1 -0
- package/dist/web/public/assets/tex-DA3dAz55.js +1 -0
- package/dist/web/public/assets/tokyo-night-BbogFqAr.js +1 -0
- package/dist/web/public/assets/toml-CyR4Gqq1.js +1 -0
- package/dist/web/public/assets/ts-tags-BD1j21LH.js +1 -0
- package/dist/web/public/assets/tsv-COLVYI6A.js +1 -0
- package/dist/web/public/assets/tsx-CFm2E6uK.js +1 -0
- package/dist/web/public/assets/turtle-PQwt4gkb.js +1 -0
- package/dist/web/public/assets/twig-DrUXy85s.js +1 -0
- package/dist/web/public/assets/typescript-Dy-5sXFx.js +1 -0
- package/dist/web/public/assets/typespec-Bb7qHV0g.js +1 -0
- package/dist/web/public/assets/typst-Bj_JElGz.js +1 -0
- package/dist/web/public/assets/v-BTkrtik4.js +1 -0
- package/dist/web/public/assets/vala-AXT1CI9v.js +1 -0
- package/dist/web/public/assets/vb-DzTKUgW8.js +1 -0
- package/dist/web/public/assets/verilog-aI3j5Xj8.js +1 -0
- package/dist/web/public/assets/vesper-BmnwIC_B.js +1 -0
- package/dist/web/public/assets/vhdl-4IgBB7vO.js +1 -0
- package/dist/web/public/assets/viml-D_XMKSR6.js +1 -0
- package/dist/web/public/assets/vitesse-black-DhmxIXiA.js +1 -0
- package/dist/web/public/assets/vitesse-dark-dvEH_9qt.js +1 -0
- package/dist/web/public/assets/vitesse-light-Ca0W2L1O.js +1 -0
- package/dist/web/public/assets/vue-DC_yTvy2.js +1 -0
- package/dist/web/public/assets/vue-html-Bp8x4gdt.js +1 -0
- package/dist/web/public/assets/vue-vine-ZcUkuUUp.js +1 -0
- package/dist/web/public/assets/vyper-Dz2f7-FK.js +1 -0
- package/dist/web/public/assets/wasm-CuXPCj65.js +1 -0
- package/dist/web/public/assets/wasm-DHkXUMsP.js +1 -0
- package/dist/web/public/assets/wenyan-BRAtM0Iv.js +1 -0
- package/dist/web/public/assets/wgsl-CMpn9jTa.js +1 -0
- package/dist/web/public/assets/wikitext-DRmBVmVA.js +1 -0
- package/dist/web/public/assets/wit-Drp_HLqJ.js +1 -0
- package/dist/web/public/assets/wolfram-C33umj7M.js +1 -0
- package/dist/web/public/assets/xml-BHoOtGbO.js +1 -0
- package/dist/web/public/assets/xsl-CN1PlFqm.js +1 -0
- package/dist/web/public/assets/yaml-DT0mpn8u.js +1 -0
- package/dist/web/public/assets/zenscript-BlYQ_Frf.js +1 -0
- package/dist/web/public/assets/zig-Buk7I0y-.js +1 -0
- package/dist/web/server/_chunks/ssr-renderer.mjs +15 -0
- package/dist/web/server/_libs/@ai-sdk/anthropic+[...].mjs +14021 -0
- package/dist/web/server/_libs/@ai-sdk/moonshotai+[...].mjs +898 -0
- package/dist/web/server/_libs/@ai-sdk/react+[...].mjs +8969 -0
- package/dist/web/server/_libs/@emotion/is-prop-valid+[...].mjs +34 -0
- package/dist/web/server/_libs/@floating-ui/core+[...].mjs +698 -0
- package/dist/web/server/_libs/@floating-ui/dom+[...].mjs +644 -0
- package/dist/web/server/_libs/@floating-ui/react-dom+[...].mjs +475 -0
- package/dist/web/server/_libs/@lobehub/icons+[...].mjs +3079 -0
- package/dist/web/server/_libs/@radix-ui/react-arrow+[...].mjs +184 -0
- package/dist/web/server/_libs/@radix-ui/react-collapsible+[...].mjs +374 -0
- package/dist/web/server/_libs/@radix-ui/react-dialog+[...].mjs +1503 -0
- package/dist/web/server/_libs/@radix-ui/react-menu+[...].mjs +1236 -0
- package/dist/web/server/_libs/@radix-ui/react-select+[...].mjs +1007 -0
- package/dist/web/server/_libs/@shikijs/core+[...].mjs +9017 -0
- package/dist/web/server/_libs/@shikijs/engine-javascript+[...].mjs +3159 -0
- package/dist/web/server/_libs/@streamdown/math+[...].mjs +37559 -0
- package/dist/web/server/_libs/@tanstack/react-router+[...].mjs +14074 -0
- package/dist/web/server/_libs/_.mjs +3 -0
- package/dist/web/server/_libs/_2.mjs +3 -0
- package/dist/web/server/_libs/_3.mjs +2 -0
- package/dist/web/server/_libs/_4.mjs +2 -0
- package/dist/web/server/_libs/ai-sdk__gateway+vercel__oidc.mjs +1255 -0
- package/dist/web/server/_libs/ai-sdk__google.mjs +1630 -0
- package/dist/web/server/_libs/ai-sdk__openai+zod.mjs +4951 -0
- package/dist/web/server/_libs/ai-sdk__provider-utils.mjs +411 -0
- package/dist/web/server/_libs/ai-sdk__provider.mjs +222 -0
- package/dist/web/server/_libs/bail.mjs +13 -0
- package/dist/web/server/_libs/character-entities.mjs +2135 -0
- package/dist/web/server/_libs/class-variance-authority+clsx.mjs +69 -0
- package/dist/web/server/_libs/color+[...].mjs +2185 -0
- package/dist/web/server/_libs/copy-text-to-clipboard.mjs +40 -0
- package/dist/web/server/_libs/d3-array.mjs +231 -0
- package/dist/web/server/_libs/d3-color.mjs +330 -0
- package/dist/web/server/_libs/d3-format.mjs +252 -0
- package/dist/web/server/_libs/d3-interpolate.mjs +207 -0
- package/dist/web/server/_libs/d3-path.mjs +77 -0
- package/dist/web/server/_libs/d3-scale+[...].mjs +1907 -0
- package/dist/web/server/_libs/d3-shape.mjs +818 -0
- package/dist/web/server/_libs/date-fns.mjs +3012 -0
- package/dist/web/server/_libs/date-fns__tz.mjs +249 -0
- package/dist/web/server/_libs/decimal.js-light.mjs +884 -0
- package/dist/web/server/_libs/decode-named-character-reference+[...].mjs +19 -0
- package/dist/web/server/_libs/dexie.mjs +3745 -0
- package/dist/web/server/_libs/escape-string-regexp.mjs +7 -0
- package/dist/web/server/_libs/estree-util-is-identifier-name.mjs +20 -0
- package/dist/web/server/_libs/eventemitter3.mjs +237 -0
- package/dist/web/server/_libs/extend.mjs +75 -0
- package/dist/web/server/_libs/fast-equals.mjs +423 -0
- package/dist/web/server/_libs/framer-motion+[...].mjs +9573 -0
- package/dist/web/server/_libs/fuzzysort.mjs +621 -0
- package/dist/web/server/_libs/h3+rou3+srvx.mjs +1158 -0
- package/dist/web/server/_libs/hast-util-raw+[...].mjs +800 -0
- package/dist/web/server/_libs/hast-util-sanitize.mjs +780 -0
- package/dist/web/server/_libs/hast-util-to-jsx-runtime+[...].mjs +853 -0
- package/dist/web/server/_libs/hookable.mjs +41 -0
- package/dist/web/server/_libs/html-url-attributes.mjs +44 -0
- package/dist/web/server/_libs/is-plain-obj.mjs +8 -0
- package/dist/web/server/_libs/lodash.mjs +4532 -0
- package/dist/web/server/_libs/lucide-react.mjs +605 -0
- package/dist/web/server/_libs/markdown-table.mjs +289 -0
- package/dist/web/server/_libs/marked.mjs +1511 -0
- package/dist/web/server/_libs/mdast-util-find-and-replace.mjs +198 -0
- package/dist/web/server/_libs/mdast-util-from-markdown+[...].mjs +8121 -0
- package/dist/web/server/_libs/mdast-util-gfm+[...].mjs +2060 -0
- package/dist/web/server/_libs/mdast-util-to-hast+[...].mjs +1770 -0
- package/dist/web/server/_libs/micromark-extension-gfm+[...].mjs +2235 -0
- package/dist/web/server/_libs/nanoid.mjs +26 -0
- package/dist/web/server/_libs/next-themes.mjs +124 -0
- package/dist/web/server/_libs/prop-types.mjs +69 -0
- package/dist/web/server/_libs/radix-ui__number.mjs +6 -0
- package/dist/web/server/_libs/radix-ui__primitive.mjs +9 -0
- package/dist/web/server/_libs/radix-ui__react-collection.mjs +80 -0
- package/dist/web/server/_libs/radix-ui__react-direction.mjs +11 -0
- package/dist/web/server/_libs/radix-ui__react-label.mjs +23 -0
- package/dist/web/server/_libs/radix-ui__react-menubar.mjs +400 -0
- package/dist/web/server/_libs/radix-ui__react-popover.mjs +251 -0
- package/dist/web/server/_libs/radix-ui__react-progress.mjs +81 -0
- package/dist/web/server/_libs/radix-ui__react-scroll-area.mjs +669 -0
- package/dist/web/server/_libs/radix-ui__react-separator.mjs +32 -0
- package/dist/web/server/_libs/radix-ui__react-slider.mjs +464 -0
- package/dist/web/server/_libs/radix-ui__react-switch.mjs +120 -0
- package/dist/web/server/_libs/radix-ui__react-tabs.mjs +145 -0
- package/dist/web/server/_libs/radix-ui__react-tooltip.mjs +494 -0
- package/dist/web/server/_libs/react-day-picker.mjs +3510 -0
- package/dist/web/server/_libs/react-is.mjs +48 -0
- package/dist/web/server/_libs/react-resizable-panels.mjs +1517 -0
- package/dist/web/server/_libs/react-smooth.mjs +1024 -0
- package/dist/web/server/_libs/recharts+[...].mjs +12998 -0
- package/dist/web/server/_libs/rehype-harden.mjs +210 -0
- package/dist/web/server/_libs/rehype-raw.mjs +37 -0
- package/dist/web/server/_libs/rehype-sanitize.mjs +27 -0
- package/dist/web/server/_libs/remark-gfm.mjs +34 -0
- package/dist/web/server/_libs/remark-parse.mjs +37 -0
- package/dist/web/server/_libs/remark-rehype.mjs +169 -0
- package/dist/web/server/_libs/remend.mjs +544 -0
- package/dist/web/server/_libs/scule.mjs +55 -0
- package/dist/web/server/_libs/shiki+streamdown__code.mjs +1748 -0
- package/dist/web/server/_libs/shiki.mjs +16 -0
- package/dist/web/server/_libs/shikijs__engine-oniguruma.mjs +387 -0
- package/dist/web/server/_libs/shikijs__langs.mjs +1357 -0
- package/dist/web/server/_libs/shikijs__themes.mjs +268 -0
- package/dist/web/server/_libs/sonner.mjs +909 -0
- package/dist/web/server/_libs/streamdown+[...].mjs +5842 -0
- package/dist/web/server/_libs/tanstack__history.mjs +342 -0
- package/dist/web/server/_libs/tanstack__query-core.mjs +2073 -0
- package/dist/web/server/_libs/tanstack__react-query.mjs +146 -0
- package/dist/web/server/_libs/tanstack__router-core.mjs +6 -0
- package/dist/web/server/_libs/tanstack__zod-adapter.mjs +16 -0
- package/dist/web/server/_libs/ufo.mjs +64 -0
- package/dist/web/server/_libs/ungap__structured-clone.mjs +197 -0
- package/dist/web/server/_libs/use-stick-to-bottom.mjs +410 -0
- package/dist/web/server/_libs/vercel__oidc.mjs +393 -0
- package/dist/web/server/_libs/zhipu-ai-provider.mjs +13483 -0
- package/dist/web/server/_libs/zustand.mjs +48 -0
- package/dist/web/server/_runtime.mjs +35 -0
- package/dist/web/server/_ssr/components-BzCiScpA.mjs +1452 -0
- package/dist/web/server/_ssr/dist-3Mu7PF0n.mjs +137 -0
- package/dist/web/server/_ssr/dist-BRaLXgxZ.mjs +17 -0
- package/dist/web/server/_ssr/field-1-agM60DBf.mjs +167 -0
- package/dist/web/server/_ssr/get-providers-BoYkp0Of.mjs +40 -0
- package/dist/web/server/_ssr/initialize-provider-B6W8V5Eg.mjs +19 -0
- package/dist/web/server/_ssr/model-list-CDFjdz2P.mjs +60 -0
- package/dist/web/server/_ssr/router-BmmOCtJZ.mjs +168 -0
- package/dist/web/server/_ssr/routes-CvlpZK4Q.mjs +2630 -0
- package/dist/web/server/_ssr/schemas-DsZ5O3zp.mjs +67 -0
- package/dist/web/server/_ssr/send-message-DUT1vRvx.mjs +135 -0
- package/dist/web/server/_ssr/ssr.mjs +5253 -0
- package/dist/web/server/_ssr/start-rewezkfD.mjs +4 -0
- package/dist/web/server/_ssr/submit-key-CcCv6-yy.mjs +62 -0
- package/dist/web/server/_ssr/suggestions-B0Uc3p7F.mjs +38 -0
- package/dist/web/server/_ssr/use-providers-Bwqg2U3N.mjs +1554 -0
- package/dist/web/server/_tanstack-start-manifest_v-BMIvh4y6.mjs +60 -0
- package/dist/web/server/index.mjs +2531 -0
- package/dist/web/server/node_modules/tslib/modules/index.js +70 -0
- package/dist/web/server/node_modules/tslib/modules/package.json +3 -0
- package/dist/web/server/node_modules/tslib/package.json +47 -0
- package/dist/web/server/node_modules/tslib/tslib.js +484 -0
- package/package.json +32 -0
|
@@ -0,0 +1,4951 @@
|
|
|
1
|
+
import { $ as InvalidResponseDataError, A as lazySchema, Ct as union, D as isNonNullable, G as validateTypes, I as parseProviderOptions, J as zodSchema, K as withUserAgentSuffix, L as postFormDataToApi, M as loadOptionalSetting, N as mediaTypeToExtension, O as isParsableJson, Q as InvalidPromptError, R as postJsonToApi, S as generateId, St as string, Tt as _coercedNumber, Z as APICallError, _ as createProviderToolFactoryWithOutputSchema, at as ZodNumber, b as downloadBlob, bt as record, c as convertToBase64, ct as _null, d as createBinaryResponseHandler, dt as boolean, f as createEventSourceResponseHandler, g as createProviderToolFactory, h as createJsonResponseHandler, ht as literal, j as loadApiKey, l as convertToFormData, lt as any, m as createJsonErrorResponseHandler, mt as lazy, o as combineHeaders, ot as _enum, pt as discriminatedUnion, q as withoutTrailingSlash, rt as UnsupportedFunctionalityError, s as convertBase64ToUint8Array, tt as TooManyEmbeddingValuesForCallError, ut as array, v as createToolNameMapping, vt as number$1, wt as unknown, yt as object } from "./@ai-sdk/anthropic+[...].mjs";
|
|
2
|
+
//#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/coerce.js
|
|
3
|
+
function number(params) {
|
|
4
|
+
return _coercedNumber(ZodNumber, params);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region ../../node_modules/.pnpm/@ai-sdk+openai@3.0.41_zod@4.3.6/node_modules/@ai-sdk/openai/dist/index.mjs
|
|
8
|
+
var openaiErrorDataSchema = object({ error: object({
|
|
9
|
+
message: string(),
|
|
10
|
+
type: string().nullish(),
|
|
11
|
+
param: any().nullish(),
|
|
12
|
+
code: union([string(), number$1()]).nullish()
|
|
13
|
+
}) });
|
|
14
|
+
var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
15
|
+
errorSchema: openaiErrorDataSchema,
|
|
16
|
+
errorToMessage: (data) => data.error.message
|
|
17
|
+
});
|
|
18
|
+
function getOpenAILanguageModelCapabilities(modelId) {
|
|
19
|
+
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
20
|
+
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
21
|
+
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
22
|
+
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
|
|
23
|
+
return {
|
|
24
|
+
supportsFlexProcessing,
|
|
25
|
+
supportsPriorityProcessing,
|
|
26
|
+
isReasoningModel,
|
|
27
|
+
systemMessageMode: isReasoningModel ? "developer" : "system",
|
|
28
|
+
supportsNonReasoningParameters
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function convertOpenAIChatUsage(usage) {
|
|
32
|
+
var _a, _b, _c, _d, _e, _f;
|
|
33
|
+
if (usage == null) return {
|
|
34
|
+
inputTokens: {
|
|
35
|
+
total: void 0,
|
|
36
|
+
noCache: void 0,
|
|
37
|
+
cacheRead: void 0,
|
|
38
|
+
cacheWrite: void 0
|
|
39
|
+
},
|
|
40
|
+
outputTokens: {
|
|
41
|
+
total: void 0,
|
|
42
|
+
text: void 0,
|
|
43
|
+
reasoning: void 0
|
|
44
|
+
},
|
|
45
|
+
raw: void 0
|
|
46
|
+
};
|
|
47
|
+
const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
|
|
48
|
+
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
49
|
+
const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
50
|
+
const reasoningTokens = (_f = (_e = usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
51
|
+
return {
|
|
52
|
+
inputTokens: {
|
|
53
|
+
total: promptTokens,
|
|
54
|
+
noCache: promptTokens - cachedTokens,
|
|
55
|
+
cacheRead: cachedTokens,
|
|
56
|
+
cacheWrite: void 0
|
|
57
|
+
},
|
|
58
|
+
outputTokens: {
|
|
59
|
+
total: completionTokens,
|
|
60
|
+
text: completionTokens - reasoningTokens,
|
|
61
|
+
reasoning: reasoningTokens
|
|
62
|
+
},
|
|
63
|
+
raw: usage
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function convertToOpenAIChatMessages({ prompt, systemMessageMode = "system" }) {
|
|
67
|
+
var _a;
|
|
68
|
+
const messages = [];
|
|
69
|
+
const warnings = [];
|
|
70
|
+
for (const { role, content } of prompt) switch (role) {
|
|
71
|
+
case "system":
|
|
72
|
+
switch (systemMessageMode) {
|
|
73
|
+
case "system":
|
|
74
|
+
messages.push({
|
|
75
|
+
role: "system",
|
|
76
|
+
content
|
|
77
|
+
});
|
|
78
|
+
break;
|
|
79
|
+
case "developer":
|
|
80
|
+
messages.push({
|
|
81
|
+
role: "developer",
|
|
82
|
+
content
|
|
83
|
+
});
|
|
84
|
+
break;
|
|
85
|
+
case "remove":
|
|
86
|
+
warnings.push({
|
|
87
|
+
type: "other",
|
|
88
|
+
message: "system messages are removed for this model"
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
default: {
|
|
92
|
+
const _exhaustiveCheck = systemMessageMode;
|
|
93
|
+
throw new Error(`Unsupported system message mode: ${_exhaustiveCheck}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case "user":
|
|
98
|
+
if (content.length === 1 && content[0].type === "text") {
|
|
99
|
+
messages.push({
|
|
100
|
+
role: "user",
|
|
101
|
+
content: content[0].text
|
|
102
|
+
});
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
messages.push({
|
|
106
|
+
role: "user",
|
|
107
|
+
content: content.map((part, index) => {
|
|
108
|
+
var _a2, _b, _c;
|
|
109
|
+
switch (part.type) {
|
|
110
|
+
case "text": return {
|
|
111
|
+
type: "text",
|
|
112
|
+
text: part.text
|
|
113
|
+
};
|
|
114
|
+
case "file": if (part.mediaType.startsWith("image/")) {
|
|
115
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
116
|
+
return {
|
|
117
|
+
type: "image_url",
|
|
118
|
+
image_url: {
|
|
119
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
120
|
+
detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
} else if (part.mediaType.startsWith("audio/")) {
|
|
124
|
+
if (part.data instanceof URL) throw new UnsupportedFunctionalityError({ functionality: "audio file parts with URLs" });
|
|
125
|
+
switch (part.mediaType) {
|
|
126
|
+
case "audio/wav": return {
|
|
127
|
+
type: "input_audio",
|
|
128
|
+
input_audio: {
|
|
129
|
+
data: convertToBase64(part.data),
|
|
130
|
+
format: "wav"
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
case "audio/mp3":
|
|
134
|
+
case "audio/mpeg": return {
|
|
135
|
+
type: "input_audio",
|
|
136
|
+
input_audio: {
|
|
137
|
+
data: convertToBase64(part.data),
|
|
138
|
+
format: "mp3"
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
default: throw new UnsupportedFunctionalityError({ functionality: `audio content parts with media type ${part.mediaType}` });
|
|
142
|
+
}
|
|
143
|
+
} else if (part.mediaType === "application/pdf") {
|
|
144
|
+
if (part.data instanceof URL) throw new UnsupportedFunctionalityError({ functionality: "PDF file parts with URLs" });
|
|
145
|
+
return {
|
|
146
|
+
type: "file",
|
|
147
|
+
file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
|
|
148
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
149
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
} else throw new UnsupportedFunctionalityError({ functionality: `file part media type ${part.mediaType}` });
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
case "assistant": {
|
|
158
|
+
let text = "";
|
|
159
|
+
const toolCalls = [];
|
|
160
|
+
for (const part of content) switch (part.type) {
|
|
161
|
+
case "text":
|
|
162
|
+
text += part.text;
|
|
163
|
+
break;
|
|
164
|
+
case "tool-call":
|
|
165
|
+
toolCalls.push({
|
|
166
|
+
id: part.toolCallId,
|
|
167
|
+
type: "function",
|
|
168
|
+
function: {
|
|
169
|
+
name: part.toolName,
|
|
170
|
+
arguments: JSON.stringify(part.input)
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
messages.push({
|
|
176
|
+
role: "assistant",
|
|
177
|
+
content: text,
|
|
178
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
179
|
+
});
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case "tool":
|
|
183
|
+
for (const toolResponse of content) {
|
|
184
|
+
if (toolResponse.type === "tool-approval-response") continue;
|
|
185
|
+
const output = toolResponse.output;
|
|
186
|
+
let contentValue;
|
|
187
|
+
switch (output.type) {
|
|
188
|
+
case "text":
|
|
189
|
+
case "error-text":
|
|
190
|
+
contentValue = output.value;
|
|
191
|
+
break;
|
|
192
|
+
case "execution-denied":
|
|
193
|
+
contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
|
|
194
|
+
break;
|
|
195
|
+
case "content":
|
|
196
|
+
case "json":
|
|
197
|
+
case "error-json":
|
|
198
|
+
contentValue = JSON.stringify(output.value);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
messages.push({
|
|
202
|
+
role: "tool",
|
|
203
|
+
tool_call_id: toolResponse.toolCallId,
|
|
204
|
+
content: contentValue
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
default: {
|
|
209
|
+
const _exhaustiveCheck = role;
|
|
210
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
messages,
|
|
215
|
+
warnings
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function getResponseMetadata({ id, model, created }) {
|
|
219
|
+
return {
|
|
220
|
+
id: id != null ? id : void 0,
|
|
221
|
+
modelId: model != null ? model : void 0,
|
|
222
|
+
timestamp: created ? /* @__PURE__ */ new Date(created * 1e3) : void 0
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function mapOpenAIFinishReason(finishReason) {
|
|
226
|
+
switch (finishReason) {
|
|
227
|
+
case "stop": return "stop";
|
|
228
|
+
case "length": return "length";
|
|
229
|
+
case "content_filter": return "content-filter";
|
|
230
|
+
case "function_call":
|
|
231
|
+
case "tool_calls": return "tool-calls";
|
|
232
|
+
default: return "other";
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
var openaiChatResponseSchema = lazySchema(() => zodSchema(object({
|
|
236
|
+
id: string().nullish(),
|
|
237
|
+
created: number$1().nullish(),
|
|
238
|
+
model: string().nullish(),
|
|
239
|
+
choices: array(object({
|
|
240
|
+
message: object({
|
|
241
|
+
role: literal("assistant").nullish(),
|
|
242
|
+
content: string().nullish(),
|
|
243
|
+
tool_calls: array(object({
|
|
244
|
+
id: string().nullish(),
|
|
245
|
+
type: literal("function"),
|
|
246
|
+
function: object({
|
|
247
|
+
name: string(),
|
|
248
|
+
arguments: string()
|
|
249
|
+
})
|
|
250
|
+
})).nullish(),
|
|
251
|
+
annotations: array(object({
|
|
252
|
+
type: literal("url_citation"),
|
|
253
|
+
url_citation: object({
|
|
254
|
+
start_index: number$1(),
|
|
255
|
+
end_index: number$1(),
|
|
256
|
+
url: string(),
|
|
257
|
+
title: string()
|
|
258
|
+
})
|
|
259
|
+
})).nullish()
|
|
260
|
+
}),
|
|
261
|
+
index: number$1(),
|
|
262
|
+
logprobs: object({ content: array(object({
|
|
263
|
+
token: string(),
|
|
264
|
+
logprob: number$1(),
|
|
265
|
+
top_logprobs: array(object({
|
|
266
|
+
token: string(),
|
|
267
|
+
logprob: number$1()
|
|
268
|
+
}))
|
|
269
|
+
})).nullish() }).nullish(),
|
|
270
|
+
finish_reason: string().nullish()
|
|
271
|
+
})),
|
|
272
|
+
usage: object({
|
|
273
|
+
prompt_tokens: number$1().nullish(),
|
|
274
|
+
completion_tokens: number$1().nullish(),
|
|
275
|
+
total_tokens: number$1().nullish(),
|
|
276
|
+
prompt_tokens_details: object({ cached_tokens: number$1().nullish() }).nullish(),
|
|
277
|
+
completion_tokens_details: object({
|
|
278
|
+
reasoning_tokens: number$1().nullish(),
|
|
279
|
+
accepted_prediction_tokens: number$1().nullish(),
|
|
280
|
+
rejected_prediction_tokens: number$1().nullish()
|
|
281
|
+
}).nullish()
|
|
282
|
+
}).nullish()
|
|
283
|
+
})));
|
|
284
|
+
var openaiChatChunkSchema = lazySchema(() => zodSchema(union([object({
|
|
285
|
+
id: string().nullish(),
|
|
286
|
+
created: number$1().nullish(),
|
|
287
|
+
model: string().nullish(),
|
|
288
|
+
choices: array(object({
|
|
289
|
+
delta: object({
|
|
290
|
+
role: _enum(["assistant"]).nullish(),
|
|
291
|
+
content: string().nullish(),
|
|
292
|
+
tool_calls: array(object({
|
|
293
|
+
index: number$1(),
|
|
294
|
+
id: string().nullish(),
|
|
295
|
+
type: literal("function").nullish(),
|
|
296
|
+
function: object({
|
|
297
|
+
name: string().nullish(),
|
|
298
|
+
arguments: string().nullish()
|
|
299
|
+
})
|
|
300
|
+
})).nullish(),
|
|
301
|
+
annotations: array(object({
|
|
302
|
+
type: literal("url_citation"),
|
|
303
|
+
url_citation: object({
|
|
304
|
+
start_index: number$1(),
|
|
305
|
+
end_index: number$1(),
|
|
306
|
+
url: string(),
|
|
307
|
+
title: string()
|
|
308
|
+
})
|
|
309
|
+
})).nullish()
|
|
310
|
+
}).nullish(),
|
|
311
|
+
logprobs: object({ content: array(object({
|
|
312
|
+
token: string(),
|
|
313
|
+
logprob: number$1(),
|
|
314
|
+
top_logprobs: array(object({
|
|
315
|
+
token: string(),
|
|
316
|
+
logprob: number$1()
|
|
317
|
+
}))
|
|
318
|
+
})).nullish() }).nullish(),
|
|
319
|
+
finish_reason: string().nullish(),
|
|
320
|
+
index: number$1()
|
|
321
|
+
})),
|
|
322
|
+
usage: object({
|
|
323
|
+
prompt_tokens: number$1().nullish(),
|
|
324
|
+
completion_tokens: number$1().nullish(),
|
|
325
|
+
total_tokens: number$1().nullish(),
|
|
326
|
+
prompt_tokens_details: object({ cached_tokens: number$1().nullish() }).nullish(),
|
|
327
|
+
completion_tokens_details: object({
|
|
328
|
+
reasoning_tokens: number$1().nullish(),
|
|
329
|
+
accepted_prediction_tokens: number$1().nullish(),
|
|
330
|
+
rejected_prediction_tokens: number$1().nullish()
|
|
331
|
+
}).nullish()
|
|
332
|
+
}).nullish()
|
|
333
|
+
}), openaiErrorDataSchema])));
|
|
334
|
+
var openaiLanguageModelChatOptions = lazySchema(() => zodSchema(object({
|
|
335
|
+
logitBias: record(number(), number$1()).optional(),
|
|
336
|
+
logprobs: union([boolean(), number$1()]).optional(),
|
|
337
|
+
parallelToolCalls: boolean().optional(),
|
|
338
|
+
user: string().optional(),
|
|
339
|
+
reasoningEffort: _enum([
|
|
340
|
+
"none",
|
|
341
|
+
"minimal",
|
|
342
|
+
"low",
|
|
343
|
+
"medium",
|
|
344
|
+
"high",
|
|
345
|
+
"xhigh"
|
|
346
|
+
]).optional(),
|
|
347
|
+
maxCompletionTokens: number$1().optional(),
|
|
348
|
+
store: boolean().optional(),
|
|
349
|
+
metadata: record(string().max(64), string().max(512)).optional(),
|
|
350
|
+
prediction: record(string(), any()).optional(),
|
|
351
|
+
serviceTier: _enum([
|
|
352
|
+
"auto",
|
|
353
|
+
"flex",
|
|
354
|
+
"priority",
|
|
355
|
+
"default"
|
|
356
|
+
]).optional(),
|
|
357
|
+
strictJsonSchema: boolean().optional(),
|
|
358
|
+
textVerbosity: _enum([
|
|
359
|
+
"low",
|
|
360
|
+
"medium",
|
|
361
|
+
"high"
|
|
362
|
+
]).optional(),
|
|
363
|
+
promptCacheKey: string().optional(),
|
|
364
|
+
promptCacheRetention: _enum(["in_memory", "24h"]).optional(),
|
|
365
|
+
safetyIdentifier: string().optional(),
|
|
366
|
+
systemMessageMode: _enum([
|
|
367
|
+
"system",
|
|
368
|
+
"developer",
|
|
369
|
+
"remove"
|
|
370
|
+
]).optional(),
|
|
371
|
+
forceReasoning: boolean().optional()
|
|
372
|
+
})));
|
|
373
|
+
function prepareChatTools({ tools, toolChoice }) {
|
|
374
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
375
|
+
const toolWarnings = [];
|
|
376
|
+
if (tools == null) return {
|
|
377
|
+
tools: void 0,
|
|
378
|
+
toolChoice: void 0,
|
|
379
|
+
toolWarnings
|
|
380
|
+
};
|
|
381
|
+
const openaiTools2 = [];
|
|
382
|
+
for (const tool of tools) switch (tool.type) {
|
|
383
|
+
case "function":
|
|
384
|
+
openaiTools2.push({
|
|
385
|
+
type: "function",
|
|
386
|
+
function: {
|
|
387
|
+
name: tool.name,
|
|
388
|
+
description: tool.description,
|
|
389
|
+
parameters: tool.inputSchema,
|
|
390
|
+
...tool.strict != null ? { strict: tool.strict } : {}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
break;
|
|
394
|
+
default:
|
|
395
|
+
toolWarnings.push({
|
|
396
|
+
type: "unsupported",
|
|
397
|
+
feature: `tool type: ${tool.type}`
|
|
398
|
+
});
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
if (toolChoice == null) return {
|
|
402
|
+
tools: openaiTools2,
|
|
403
|
+
toolChoice: void 0,
|
|
404
|
+
toolWarnings
|
|
405
|
+
};
|
|
406
|
+
const type = toolChoice.type;
|
|
407
|
+
switch (type) {
|
|
408
|
+
case "auto":
|
|
409
|
+
case "none":
|
|
410
|
+
case "required": return {
|
|
411
|
+
tools: openaiTools2,
|
|
412
|
+
toolChoice: type,
|
|
413
|
+
toolWarnings
|
|
414
|
+
};
|
|
415
|
+
case "tool": return {
|
|
416
|
+
tools: openaiTools2,
|
|
417
|
+
toolChoice: {
|
|
418
|
+
type: "function",
|
|
419
|
+
function: { name: toolChoice.toolName }
|
|
420
|
+
},
|
|
421
|
+
toolWarnings
|
|
422
|
+
};
|
|
423
|
+
default: throw new UnsupportedFunctionalityError({ functionality: `tool choice type: ${type}` });
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
var OpenAIChatLanguageModel = class {
|
|
427
|
+
constructor(modelId, config) {
|
|
428
|
+
this.specificationVersion = "v3";
|
|
429
|
+
this.supportedUrls = { "image/*": [/^https?:\/\/.*$/] };
|
|
430
|
+
this.modelId = modelId;
|
|
431
|
+
this.config = config;
|
|
432
|
+
}
|
|
433
|
+
get provider() {
|
|
434
|
+
return this.config.provider;
|
|
435
|
+
}
|
|
436
|
+
async getArgs({ prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, providerOptions }) {
|
|
437
|
+
var _a, _b, _c, _d, _e;
|
|
438
|
+
const warnings = [];
|
|
439
|
+
const openaiOptions = (_a = await parseProviderOptions({
|
|
440
|
+
provider: "openai",
|
|
441
|
+
providerOptions,
|
|
442
|
+
schema: openaiLanguageModelChatOptions
|
|
443
|
+
})) != null ? _a : {};
|
|
444
|
+
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
445
|
+
const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
446
|
+
if (topK != null) warnings.push({
|
|
447
|
+
type: "unsupported",
|
|
448
|
+
feature: "topK"
|
|
449
|
+
});
|
|
450
|
+
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages({
|
|
451
|
+
prompt,
|
|
452
|
+
systemMessageMode: (_c = openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
|
|
453
|
+
});
|
|
454
|
+
warnings.push(...messageWarnings);
|
|
455
|
+
const strictJsonSchema = (_d = openaiOptions.strictJsonSchema) != null ? _d : true;
|
|
456
|
+
const baseArgs = {
|
|
457
|
+
model: this.modelId,
|
|
458
|
+
logit_bias: openaiOptions.logitBias,
|
|
459
|
+
logprobs: openaiOptions.logprobs === true || typeof openaiOptions.logprobs === "number" ? true : void 0,
|
|
460
|
+
top_logprobs: typeof openaiOptions.logprobs === "number" ? openaiOptions.logprobs : typeof openaiOptions.logprobs === "boolean" ? openaiOptions.logprobs ? 0 : void 0 : void 0,
|
|
461
|
+
user: openaiOptions.user,
|
|
462
|
+
parallel_tool_calls: openaiOptions.parallelToolCalls,
|
|
463
|
+
max_tokens: maxOutputTokens,
|
|
464
|
+
temperature,
|
|
465
|
+
top_p: topP,
|
|
466
|
+
frequency_penalty: frequencyPenalty,
|
|
467
|
+
presence_penalty: presencePenalty,
|
|
468
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
469
|
+
type: "json_schema",
|
|
470
|
+
json_schema: {
|
|
471
|
+
schema: responseFormat.schema,
|
|
472
|
+
strict: strictJsonSchema,
|
|
473
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
474
|
+
description: responseFormat.description
|
|
475
|
+
}
|
|
476
|
+
} : { type: "json_object" } : void 0,
|
|
477
|
+
stop: stopSequences,
|
|
478
|
+
seed,
|
|
479
|
+
verbosity: openaiOptions.textVerbosity,
|
|
480
|
+
max_completion_tokens: openaiOptions.maxCompletionTokens,
|
|
481
|
+
store: openaiOptions.store,
|
|
482
|
+
metadata: openaiOptions.metadata,
|
|
483
|
+
prediction: openaiOptions.prediction,
|
|
484
|
+
reasoning_effort: openaiOptions.reasoningEffort,
|
|
485
|
+
service_tier: openaiOptions.serviceTier,
|
|
486
|
+
prompt_cache_key: openaiOptions.promptCacheKey,
|
|
487
|
+
prompt_cache_retention: openaiOptions.promptCacheRetention,
|
|
488
|
+
safety_identifier: openaiOptions.safetyIdentifier,
|
|
489
|
+
messages
|
|
490
|
+
};
|
|
491
|
+
if (isReasoningModel) {
|
|
492
|
+
if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
|
|
493
|
+
if (baseArgs.temperature != null) {
|
|
494
|
+
baseArgs.temperature = void 0;
|
|
495
|
+
warnings.push({
|
|
496
|
+
type: "unsupported",
|
|
497
|
+
feature: "temperature",
|
|
498
|
+
details: "temperature is not supported for reasoning models"
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (baseArgs.top_p != null) {
|
|
502
|
+
baseArgs.top_p = void 0;
|
|
503
|
+
warnings.push({
|
|
504
|
+
type: "unsupported",
|
|
505
|
+
feature: "topP",
|
|
506
|
+
details: "topP is not supported for reasoning models"
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
if (baseArgs.logprobs != null) {
|
|
510
|
+
baseArgs.logprobs = void 0;
|
|
511
|
+
warnings.push({
|
|
512
|
+
type: "other",
|
|
513
|
+
message: "logprobs is not supported for reasoning models"
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (baseArgs.frequency_penalty != null) {
|
|
518
|
+
baseArgs.frequency_penalty = void 0;
|
|
519
|
+
warnings.push({
|
|
520
|
+
type: "unsupported",
|
|
521
|
+
feature: "frequencyPenalty",
|
|
522
|
+
details: "frequencyPenalty is not supported for reasoning models"
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
if (baseArgs.presence_penalty != null) {
|
|
526
|
+
baseArgs.presence_penalty = void 0;
|
|
527
|
+
warnings.push({
|
|
528
|
+
type: "unsupported",
|
|
529
|
+
feature: "presencePenalty",
|
|
530
|
+
details: "presencePenalty is not supported for reasoning models"
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
if (baseArgs.logit_bias != null) {
|
|
534
|
+
baseArgs.logit_bias = void 0;
|
|
535
|
+
warnings.push({
|
|
536
|
+
type: "other",
|
|
537
|
+
message: "logitBias is not supported for reasoning models"
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
if (baseArgs.top_logprobs != null) {
|
|
541
|
+
baseArgs.top_logprobs = void 0;
|
|
542
|
+
warnings.push({
|
|
543
|
+
type: "other",
|
|
544
|
+
message: "topLogprobs is not supported for reasoning models"
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
if (baseArgs.max_tokens != null) {
|
|
548
|
+
if (baseArgs.max_completion_tokens == null) baseArgs.max_completion_tokens = baseArgs.max_tokens;
|
|
549
|
+
baseArgs.max_tokens = void 0;
|
|
550
|
+
}
|
|
551
|
+
} else if (this.modelId.startsWith("gpt-4o-search-preview") || this.modelId.startsWith("gpt-4o-mini-search-preview")) {
|
|
552
|
+
if (baseArgs.temperature != null) {
|
|
553
|
+
baseArgs.temperature = void 0;
|
|
554
|
+
warnings.push({
|
|
555
|
+
type: "unsupported",
|
|
556
|
+
feature: "temperature",
|
|
557
|
+
details: "temperature is not supported for the search preview models and has been removed."
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (openaiOptions.serviceTier === "flex" && !modelCapabilities.supportsFlexProcessing) {
|
|
562
|
+
warnings.push({
|
|
563
|
+
type: "unsupported",
|
|
564
|
+
feature: "serviceTier",
|
|
565
|
+
details: "flex processing is only available for o3, o4-mini, and gpt-5 models"
|
|
566
|
+
});
|
|
567
|
+
baseArgs.service_tier = void 0;
|
|
568
|
+
}
|
|
569
|
+
if (openaiOptions.serviceTier === "priority" && !modelCapabilities.supportsPriorityProcessing) {
|
|
570
|
+
warnings.push({
|
|
571
|
+
type: "unsupported",
|
|
572
|
+
feature: "serviceTier",
|
|
573
|
+
details: "priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"
|
|
574
|
+
});
|
|
575
|
+
baseArgs.service_tier = void 0;
|
|
576
|
+
}
|
|
577
|
+
const { tools: openaiTools2, toolChoice: openaiToolChoice, toolWarnings } = prepareChatTools({
|
|
578
|
+
tools,
|
|
579
|
+
toolChoice
|
|
580
|
+
});
|
|
581
|
+
return {
|
|
582
|
+
args: {
|
|
583
|
+
...baseArgs,
|
|
584
|
+
tools: openaiTools2,
|
|
585
|
+
tool_choice: openaiToolChoice
|
|
586
|
+
},
|
|
587
|
+
warnings: [...warnings, ...toolWarnings]
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
async doGenerate(options) {
|
|
591
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
592
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
593
|
+
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
594
|
+
url: this.config.url({
|
|
595
|
+
path: "/chat/completions",
|
|
596
|
+
modelId: this.modelId
|
|
597
|
+
}),
|
|
598
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
599
|
+
body,
|
|
600
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
601
|
+
successfulResponseHandler: createJsonResponseHandler(openaiChatResponseSchema),
|
|
602
|
+
abortSignal: options.abortSignal,
|
|
603
|
+
fetch: this.config.fetch
|
|
604
|
+
});
|
|
605
|
+
const choice = response.choices[0];
|
|
606
|
+
const content = [];
|
|
607
|
+
const text = choice.message.content;
|
|
608
|
+
if (text != null && text.length > 0) content.push({
|
|
609
|
+
type: "text",
|
|
610
|
+
text
|
|
611
|
+
});
|
|
612
|
+
for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) content.push({
|
|
613
|
+
type: "tool-call",
|
|
614
|
+
toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
|
|
615
|
+
toolName: toolCall.function.name,
|
|
616
|
+
input: toolCall.function.arguments
|
|
617
|
+
});
|
|
618
|
+
for (const annotation of (_c = choice.message.annotations) != null ? _c : []) content.push({
|
|
619
|
+
type: "source",
|
|
620
|
+
sourceType: "url",
|
|
621
|
+
id: generateId(),
|
|
622
|
+
url: annotation.url_citation.url,
|
|
623
|
+
title: annotation.url_citation.title
|
|
624
|
+
});
|
|
625
|
+
const completionTokenDetails = (_d = response.usage) == null ? void 0 : _d.completion_tokens_details;
|
|
626
|
+
(_e = response.usage) == null || _e.prompt_tokens_details;
|
|
627
|
+
const providerMetadata = { openai: {} };
|
|
628
|
+
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
|
629
|
+
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
630
|
+
if (((_f = choice.logprobs) == null ? void 0 : _f.content) != null) providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
631
|
+
return {
|
|
632
|
+
content,
|
|
633
|
+
finishReason: {
|
|
634
|
+
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
635
|
+
raw: (_g = choice.finish_reason) != null ? _g : void 0
|
|
636
|
+
},
|
|
637
|
+
usage: convertOpenAIChatUsage(response.usage),
|
|
638
|
+
request: { body },
|
|
639
|
+
response: {
|
|
640
|
+
...getResponseMetadata(response),
|
|
641
|
+
headers: responseHeaders,
|
|
642
|
+
body: rawResponse
|
|
643
|
+
},
|
|
644
|
+
warnings,
|
|
645
|
+
providerMetadata
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
async doStream(options) {
|
|
649
|
+
const { args, warnings } = await this.getArgs(options);
|
|
650
|
+
const body = {
|
|
651
|
+
...args,
|
|
652
|
+
stream: true,
|
|
653
|
+
stream_options: { include_usage: true }
|
|
654
|
+
};
|
|
655
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
656
|
+
url: this.config.url({
|
|
657
|
+
path: "/chat/completions",
|
|
658
|
+
modelId: this.modelId
|
|
659
|
+
}),
|
|
660
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
661
|
+
body,
|
|
662
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
663
|
+
successfulResponseHandler: createEventSourceResponseHandler(openaiChatChunkSchema),
|
|
664
|
+
abortSignal: options.abortSignal,
|
|
665
|
+
fetch: this.config.fetch
|
|
666
|
+
});
|
|
667
|
+
const toolCalls = [];
|
|
668
|
+
let finishReason = {
|
|
669
|
+
unified: "other",
|
|
670
|
+
raw: void 0
|
|
671
|
+
};
|
|
672
|
+
let usage = void 0;
|
|
673
|
+
let metadataExtracted = false;
|
|
674
|
+
let isActiveText = false;
|
|
675
|
+
const providerMetadata = { openai: {} };
|
|
676
|
+
return {
|
|
677
|
+
stream: response.pipeThrough(new TransformStream({
|
|
678
|
+
start(controller) {
|
|
679
|
+
controller.enqueue({
|
|
680
|
+
type: "stream-start",
|
|
681
|
+
warnings
|
|
682
|
+
});
|
|
683
|
+
},
|
|
684
|
+
transform(chunk, controller) {
|
|
685
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
686
|
+
if (options.includeRawChunks) controller.enqueue({
|
|
687
|
+
type: "raw",
|
|
688
|
+
rawValue: chunk.rawValue
|
|
689
|
+
});
|
|
690
|
+
if (!chunk.success) {
|
|
691
|
+
finishReason = {
|
|
692
|
+
unified: "error",
|
|
693
|
+
raw: void 0
|
|
694
|
+
};
|
|
695
|
+
controller.enqueue({
|
|
696
|
+
type: "error",
|
|
697
|
+
error: chunk.error
|
|
698
|
+
});
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
const value = chunk.value;
|
|
702
|
+
if ("error" in value) {
|
|
703
|
+
finishReason = {
|
|
704
|
+
unified: "error",
|
|
705
|
+
raw: void 0
|
|
706
|
+
};
|
|
707
|
+
controller.enqueue({
|
|
708
|
+
type: "error",
|
|
709
|
+
error: value.error
|
|
710
|
+
});
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (!metadataExtracted) {
|
|
714
|
+
const metadata = getResponseMetadata(value);
|
|
715
|
+
if (Object.values(metadata).some(Boolean)) {
|
|
716
|
+
metadataExtracted = true;
|
|
717
|
+
controller.enqueue({
|
|
718
|
+
type: "response-metadata",
|
|
719
|
+
...getResponseMetadata(value)
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
if (value.usage != null) {
|
|
724
|
+
usage = value.usage;
|
|
725
|
+
if (((_a = value.usage.completion_tokens_details) == null ? void 0 : _a.accepted_prediction_tokens) != null) providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
|
|
726
|
+
if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) providerMetadata.openai.rejectedPredictionTokens = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens;
|
|
727
|
+
}
|
|
728
|
+
const choice = value.choices[0];
|
|
729
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) finishReason = {
|
|
730
|
+
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
731
|
+
raw: choice.finish_reason
|
|
732
|
+
};
|
|
733
|
+
if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
734
|
+
if ((choice == null ? void 0 : choice.delta) == null) return;
|
|
735
|
+
const delta = choice.delta;
|
|
736
|
+
if (delta.content != null) {
|
|
737
|
+
if (!isActiveText) {
|
|
738
|
+
controller.enqueue({
|
|
739
|
+
type: "text-start",
|
|
740
|
+
id: "0"
|
|
741
|
+
});
|
|
742
|
+
isActiveText = true;
|
|
743
|
+
}
|
|
744
|
+
controller.enqueue({
|
|
745
|
+
type: "text-delta",
|
|
746
|
+
id: "0",
|
|
747
|
+
delta: delta.content
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
if (delta.tool_calls != null) for (const toolCallDelta of delta.tool_calls) {
|
|
751
|
+
const index = toolCallDelta.index;
|
|
752
|
+
if (toolCalls[index] == null) {
|
|
753
|
+
if (toolCallDelta.type != null && toolCallDelta.type !== "function") throw new InvalidResponseDataError({
|
|
754
|
+
data: toolCallDelta,
|
|
755
|
+
message: `Expected 'function' type.`
|
|
756
|
+
});
|
|
757
|
+
if (toolCallDelta.id == null) throw new InvalidResponseDataError({
|
|
758
|
+
data: toolCallDelta,
|
|
759
|
+
message: `Expected 'id' to be a string.`
|
|
760
|
+
});
|
|
761
|
+
if (((_f = toolCallDelta.function) == null ? void 0 : _f.name) == null) throw new InvalidResponseDataError({
|
|
762
|
+
data: toolCallDelta,
|
|
763
|
+
message: `Expected 'function.name' to be a string.`
|
|
764
|
+
});
|
|
765
|
+
controller.enqueue({
|
|
766
|
+
type: "tool-input-start",
|
|
767
|
+
id: toolCallDelta.id,
|
|
768
|
+
toolName: toolCallDelta.function.name
|
|
769
|
+
});
|
|
770
|
+
toolCalls[index] = {
|
|
771
|
+
id: toolCallDelta.id,
|
|
772
|
+
type: "function",
|
|
773
|
+
function: {
|
|
774
|
+
name: toolCallDelta.function.name,
|
|
775
|
+
arguments: (_g = toolCallDelta.function.arguments) != null ? _g : ""
|
|
776
|
+
},
|
|
777
|
+
hasFinished: false
|
|
778
|
+
};
|
|
779
|
+
const toolCall2 = toolCalls[index];
|
|
780
|
+
if (((_h = toolCall2.function) == null ? void 0 : _h.name) != null && ((_i = toolCall2.function) == null ? void 0 : _i.arguments) != null) {
|
|
781
|
+
if (toolCall2.function.arguments.length > 0) controller.enqueue({
|
|
782
|
+
type: "tool-input-delta",
|
|
783
|
+
id: toolCall2.id,
|
|
784
|
+
delta: toolCall2.function.arguments
|
|
785
|
+
});
|
|
786
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
787
|
+
controller.enqueue({
|
|
788
|
+
type: "tool-input-end",
|
|
789
|
+
id: toolCall2.id
|
|
790
|
+
});
|
|
791
|
+
controller.enqueue({
|
|
792
|
+
type: "tool-call",
|
|
793
|
+
toolCallId: (_j = toolCall2.id) != null ? _j : generateId(),
|
|
794
|
+
toolName: toolCall2.function.name,
|
|
795
|
+
input: toolCall2.function.arguments
|
|
796
|
+
});
|
|
797
|
+
toolCall2.hasFinished = true;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
const toolCall = toolCalls[index];
|
|
803
|
+
if (toolCall.hasFinished) continue;
|
|
804
|
+
if (((_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null) toolCall.function.arguments += (_m = (_l = toolCallDelta.function) == null ? void 0 : _l.arguments) != null ? _m : "";
|
|
805
|
+
controller.enqueue({
|
|
806
|
+
type: "tool-input-delta",
|
|
807
|
+
id: toolCall.id,
|
|
808
|
+
delta: (_n = toolCallDelta.function.arguments) != null ? _n : ""
|
|
809
|
+
});
|
|
810
|
+
if (((_o = toolCall.function) == null ? void 0 : _o.name) != null && ((_p = toolCall.function) == null ? void 0 : _p.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
811
|
+
controller.enqueue({
|
|
812
|
+
type: "tool-input-end",
|
|
813
|
+
id: toolCall.id
|
|
814
|
+
});
|
|
815
|
+
controller.enqueue({
|
|
816
|
+
type: "tool-call",
|
|
817
|
+
toolCallId: (_q = toolCall.id) != null ? _q : generateId(),
|
|
818
|
+
toolName: toolCall.function.name,
|
|
819
|
+
input: toolCall.function.arguments
|
|
820
|
+
});
|
|
821
|
+
toolCall.hasFinished = true;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
if (delta.annotations != null) for (const annotation of delta.annotations) controller.enqueue({
|
|
825
|
+
type: "source",
|
|
826
|
+
sourceType: "url",
|
|
827
|
+
id: generateId(),
|
|
828
|
+
url: annotation.url_citation.url,
|
|
829
|
+
title: annotation.url_citation.title
|
|
830
|
+
});
|
|
831
|
+
},
|
|
832
|
+
flush(controller) {
|
|
833
|
+
if (isActiveText) controller.enqueue({
|
|
834
|
+
type: "text-end",
|
|
835
|
+
id: "0"
|
|
836
|
+
});
|
|
837
|
+
controller.enqueue({
|
|
838
|
+
type: "finish",
|
|
839
|
+
finishReason,
|
|
840
|
+
usage: convertOpenAIChatUsage(usage),
|
|
841
|
+
...providerMetadata != null ? { providerMetadata } : {}
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
})),
|
|
845
|
+
request: { body },
|
|
846
|
+
response: { headers: responseHeaders }
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
function convertOpenAICompletionUsage(usage) {
|
|
851
|
+
var _a, _b, _c, _d;
|
|
852
|
+
if (usage == null) return {
|
|
853
|
+
inputTokens: {
|
|
854
|
+
total: void 0,
|
|
855
|
+
noCache: void 0,
|
|
856
|
+
cacheRead: void 0,
|
|
857
|
+
cacheWrite: void 0
|
|
858
|
+
},
|
|
859
|
+
outputTokens: {
|
|
860
|
+
total: void 0,
|
|
861
|
+
text: void 0,
|
|
862
|
+
reasoning: void 0
|
|
863
|
+
},
|
|
864
|
+
raw: void 0
|
|
865
|
+
};
|
|
866
|
+
const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
|
|
867
|
+
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
868
|
+
return {
|
|
869
|
+
inputTokens: {
|
|
870
|
+
total: (_c = usage.prompt_tokens) != null ? _c : void 0,
|
|
871
|
+
noCache: promptTokens,
|
|
872
|
+
cacheRead: void 0,
|
|
873
|
+
cacheWrite: void 0
|
|
874
|
+
},
|
|
875
|
+
outputTokens: {
|
|
876
|
+
total: (_d = usage.completion_tokens) != null ? _d : void 0,
|
|
877
|
+
text: completionTokens,
|
|
878
|
+
reasoning: void 0
|
|
879
|
+
},
|
|
880
|
+
raw: usage
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
function convertToOpenAICompletionPrompt({ prompt, user = "user", assistant = "assistant" }) {
|
|
884
|
+
let text = "";
|
|
885
|
+
if (prompt[0].role === "system") {
|
|
886
|
+
text += `${prompt[0].content}
|
|
887
|
+
|
|
888
|
+
`;
|
|
889
|
+
prompt = prompt.slice(1);
|
|
890
|
+
}
|
|
891
|
+
for (const { role, content } of prompt) switch (role) {
|
|
892
|
+
case "system": throw new InvalidPromptError({
|
|
893
|
+
message: "Unexpected system message in prompt: ${content}",
|
|
894
|
+
prompt
|
|
895
|
+
});
|
|
896
|
+
case "user": {
|
|
897
|
+
const userMessage = content.map((part) => {
|
|
898
|
+
switch (part.type) {
|
|
899
|
+
case "text": return part.text;
|
|
900
|
+
}
|
|
901
|
+
}).filter(Boolean).join("");
|
|
902
|
+
text += `${user}:
|
|
903
|
+
${userMessage}
|
|
904
|
+
|
|
905
|
+
`;
|
|
906
|
+
break;
|
|
907
|
+
}
|
|
908
|
+
case "assistant": {
|
|
909
|
+
const assistantMessage = content.map((part) => {
|
|
910
|
+
switch (part.type) {
|
|
911
|
+
case "text": return part.text;
|
|
912
|
+
case "tool-call": throw new UnsupportedFunctionalityError({ functionality: "tool-call messages" });
|
|
913
|
+
}
|
|
914
|
+
}).join("");
|
|
915
|
+
text += `${assistant}:
|
|
916
|
+
${assistantMessage}
|
|
917
|
+
|
|
918
|
+
`;
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
case "tool": throw new UnsupportedFunctionalityError({ functionality: "tool messages" });
|
|
922
|
+
default: {
|
|
923
|
+
const _exhaustiveCheck = role;
|
|
924
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
text += `${assistant}:
|
|
928
|
+
`;
|
|
929
|
+
return {
|
|
930
|
+
prompt: text,
|
|
931
|
+
stopSequences: [`
|
|
932
|
+
${user}:`]
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
function getResponseMetadata2({ id, model, created }) {
|
|
936
|
+
return {
|
|
937
|
+
id: id != null ? id : void 0,
|
|
938
|
+
modelId: model != null ? model : void 0,
|
|
939
|
+
timestamp: created != null ? /* @__PURE__ */ new Date(created * 1e3) : void 0
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
function mapOpenAIFinishReason2(finishReason) {
|
|
943
|
+
switch (finishReason) {
|
|
944
|
+
case "stop": return "stop";
|
|
945
|
+
case "length": return "length";
|
|
946
|
+
case "content_filter": return "content-filter";
|
|
947
|
+
case "function_call":
|
|
948
|
+
case "tool_calls": return "tool-calls";
|
|
949
|
+
default: return "other";
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
var openaiCompletionResponseSchema = lazySchema(() => zodSchema(object({
|
|
953
|
+
id: string().nullish(),
|
|
954
|
+
created: number$1().nullish(),
|
|
955
|
+
model: string().nullish(),
|
|
956
|
+
choices: array(object({
|
|
957
|
+
text: string(),
|
|
958
|
+
finish_reason: string(),
|
|
959
|
+
logprobs: object({
|
|
960
|
+
tokens: array(string()),
|
|
961
|
+
token_logprobs: array(number$1()),
|
|
962
|
+
top_logprobs: array(record(string(), number$1())).nullish()
|
|
963
|
+
}).nullish()
|
|
964
|
+
})),
|
|
965
|
+
usage: object({
|
|
966
|
+
prompt_tokens: number$1(),
|
|
967
|
+
completion_tokens: number$1(),
|
|
968
|
+
total_tokens: number$1()
|
|
969
|
+
}).nullish()
|
|
970
|
+
})));
|
|
971
|
+
var openaiCompletionChunkSchema = lazySchema(() => zodSchema(union([object({
|
|
972
|
+
id: string().nullish(),
|
|
973
|
+
created: number$1().nullish(),
|
|
974
|
+
model: string().nullish(),
|
|
975
|
+
choices: array(object({
|
|
976
|
+
text: string(),
|
|
977
|
+
finish_reason: string().nullish(),
|
|
978
|
+
index: number$1(),
|
|
979
|
+
logprobs: object({
|
|
980
|
+
tokens: array(string()),
|
|
981
|
+
token_logprobs: array(number$1()),
|
|
982
|
+
top_logprobs: array(record(string(), number$1())).nullish()
|
|
983
|
+
}).nullish()
|
|
984
|
+
})),
|
|
985
|
+
usage: object({
|
|
986
|
+
prompt_tokens: number$1(),
|
|
987
|
+
completion_tokens: number$1(),
|
|
988
|
+
total_tokens: number$1()
|
|
989
|
+
}).nullish()
|
|
990
|
+
}), openaiErrorDataSchema])));
|
|
991
|
+
var openaiLanguageModelCompletionOptions = lazySchema(() => zodSchema(object({
|
|
992
|
+
echo: boolean().optional(),
|
|
993
|
+
logitBias: record(string(), number$1()).optional(),
|
|
994
|
+
suffix: string().optional(),
|
|
995
|
+
user: string().optional(),
|
|
996
|
+
logprobs: union([boolean(), number$1()]).optional()
|
|
997
|
+
})));
|
|
998
|
+
var OpenAICompletionLanguageModel = class {
|
|
999
|
+
constructor(modelId, config) {
|
|
1000
|
+
this.specificationVersion = "v3";
|
|
1001
|
+
this.supportedUrls = {};
|
|
1002
|
+
this.modelId = modelId;
|
|
1003
|
+
this.config = config;
|
|
1004
|
+
}
|
|
1005
|
+
get providerOptionsName() {
|
|
1006
|
+
return this.config.provider.split(".")[0].trim();
|
|
1007
|
+
}
|
|
1008
|
+
get provider() {
|
|
1009
|
+
return this.config.provider;
|
|
1010
|
+
}
|
|
1011
|
+
async getArgs({ prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences: userStopSequences, responseFormat, tools, toolChoice, seed, providerOptions }) {
|
|
1012
|
+
const warnings = [];
|
|
1013
|
+
const openaiOptions = {
|
|
1014
|
+
...await parseProviderOptions({
|
|
1015
|
+
provider: "openai",
|
|
1016
|
+
providerOptions,
|
|
1017
|
+
schema: openaiLanguageModelCompletionOptions
|
|
1018
|
+
}),
|
|
1019
|
+
...await parseProviderOptions({
|
|
1020
|
+
provider: this.providerOptionsName,
|
|
1021
|
+
providerOptions,
|
|
1022
|
+
schema: openaiLanguageModelCompletionOptions
|
|
1023
|
+
})
|
|
1024
|
+
};
|
|
1025
|
+
if (topK != null) warnings.push({
|
|
1026
|
+
type: "unsupported",
|
|
1027
|
+
feature: "topK"
|
|
1028
|
+
});
|
|
1029
|
+
if (tools == null ? void 0 : tools.length) warnings.push({
|
|
1030
|
+
type: "unsupported",
|
|
1031
|
+
feature: "tools"
|
|
1032
|
+
});
|
|
1033
|
+
if (toolChoice != null) warnings.push({
|
|
1034
|
+
type: "unsupported",
|
|
1035
|
+
feature: "toolChoice"
|
|
1036
|
+
});
|
|
1037
|
+
if (responseFormat != null && responseFormat.type !== "text") warnings.push({
|
|
1038
|
+
type: "unsupported",
|
|
1039
|
+
feature: "responseFormat",
|
|
1040
|
+
details: "JSON response format is not supported."
|
|
1041
|
+
});
|
|
1042
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
|
|
1043
|
+
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
1044
|
+
return {
|
|
1045
|
+
args: {
|
|
1046
|
+
model: this.modelId,
|
|
1047
|
+
echo: openaiOptions.echo,
|
|
1048
|
+
logit_bias: openaiOptions.logitBias,
|
|
1049
|
+
logprobs: (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? 0 : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === false ? void 0 : openaiOptions == null ? void 0 : openaiOptions.logprobs,
|
|
1050
|
+
suffix: openaiOptions.suffix,
|
|
1051
|
+
user: openaiOptions.user,
|
|
1052
|
+
max_tokens: maxOutputTokens,
|
|
1053
|
+
temperature,
|
|
1054
|
+
top_p: topP,
|
|
1055
|
+
frequency_penalty: frequencyPenalty,
|
|
1056
|
+
presence_penalty: presencePenalty,
|
|
1057
|
+
seed,
|
|
1058
|
+
prompt: completionPrompt,
|
|
1059
|
+
stop: stop.length > 0 ? stop : void 0
|
|
1060
|
+
},
|
|
1061
|
+
warnings
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
async doGenerate(options) {
|
|
1065
|
+
var _a;
|
|
1066
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1067
|
+
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
1068
|
+
url: this.config.url({
|
|
1069
|
+
path: "/completions",
|
|
1070
|
+
modelId: this.modelId
|
|
1071
|
+
}),
|
|
1072
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1073
|
+
body: args,
|
|
1074
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1075
|
+
successfulResponseHandler: createJsonResponseHandler(openaiCompletionResponseSchema),
|
|
1076
|
+
abortSignal: options.abortSignal,
|
|
1077
|
+
fetch: this.config.fetch
|
|
1078
|
+
});
|
|
1079
|
+
const choice = response.choices[0];
|
|
1080
|
+
const providerMetadata = { openai: {} };
|
|
1081
|
+
if (choice.logprobs != null) providerMetadata.openai.logprobs = choice.logprobs;
|
|
1082
|
+
return {
|
|
1083
|
+
content: [{
|
|
1084
|
+
type: "text",
|
|
1085
|
+
text: choice.text
|
|
1086
|
+
}],
|
|
1087
|
+
usage: convertOpenAICompletionUsage(response.usage),
|
|
1088
|
+
finishReason: {
|
|
1089
|
+
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1090
|
+
raw: (_a = choice.finish_reason) != null ? _a : void 0
|
|
1091
|
+
},
|
|
1092
|
+
request: { body: args },
|
|
1093
|
+
response: {
|
|
1094
|
+
...getResponseMetadata2(response),
|
|
1095
|
+
headers: responseHeaders,
|
|
1096
|
+
body: rawResponse
|
|
1097
|
+
},
|
|
1098
|
+
providerMetadata,
|
|
1099
|
+
warnings
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
async doStream(options) {
|
|
1103
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1104
|
+
const body = {
|
|
1105
|
+
...args,
|
|
1106
|
+
stream: true,
|
|
1107
|
+
stream_options: { include_usage: true }
|
|
1108
|
+
};
|
|
1109
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1110
|
+
url: this.config.url({
|
|
1111
|
+
path: "/completions",
|
|
1112
|
+
modelId: this.modelId
|
|
1113
|
+
}),
|
|
1114
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1115
|
+
body,
|
|
1116
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1117
|
+
successfulResponseHandler: createEventSourceResponseHandler(openaiCompletionChunkSchema),
|
|
1118
|
+
abortSignal: options.abortSignal,
|
|
1119
|
+
fetch: this.config.fetch
|
|
1120
|
+
});
|
|
1121
|
+
let finishReason = {
|
|
1122
|
+
unified: "other",
|
|
1123
|
+
raw: void 0
|
|
1124
|
+
};
|
|
1125
|
+
const providerMetadata = { openai: {} };
|
|
1126
|
+
let usage = void 0;
|
|
1127
|
+
let isFirstChunk = true;
|
|
1128
|
+
return {
|
|
1129
|
+
stream: response.pipeThrough(new TransformStream({
|
|
1130
|
+
start(controller) {
|
|
1131
|
+
controller.enqueue({
|
|
1132
|
+
type: "stream-start",
|
|
1133
|
+
warnings
|
|
1134
|
+
});
|
|
1135
|
+
},
|
|
1136
|
+
transform(chunk, controller) {
|
|
1137
|
+
if (options.includeRawChunks) controller.enqueue({
|
|
1138
|
+
type: "raw",
|
|
1139
|
+
rawValue: chunk.rawValue
|
|
1140
|
+
});
|
|
1141
|
+
if (!chunk.success) {
|
|
1142
|
+
finishReason = {
|
|
1143
|
+
unified: "error",
|
|
1144
|
+
raw: void 0
|
|
1145
|
+
};
|
|
1146
|
+
controller.enqueue({
|
|
1147
|
+
type: "error",
|
|
1148
|
+
error: chunk.error
|
|
1149
|
+
});
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
const value = chunk.value;
|
|
1153
|
+
if ("error" in value) {
|
|
1154
|
+
finishReason = {
|
|
1155
|
+
unified: "error",
|
|
1156
|
+
raw: void 0
|
|
1157
|
+
};
|
|
1158
|
+
controller.enqueue({
|
|
1159
|
+
type: "error",
|
|
1160
|
+
error: value.error
|
|
1161
|
+
});
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (isFirstChunk) {
|
|
1165
|
+
isFirstChunk = false;
|
|
1166
|
+
controller.enqueue({
|
|
1167
|
+
type: "response-metadata",
|
|
1168
|
+
...getResponseMetadata2(value)
|
|
1169
|
+
});
|
|
1170
|
+
controller.enqueue({
|
|
1171
|
+
type: "text-start",
|
|
1172
|
+
id: "0"
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
if (value.usage != null) usage = value.usage;
|
|
1176
|
+
const choice = value.choices[0];
|
|
1177
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) finishReason = {
|
|
1178
|
+
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1179
|
+
raw: choice.finish_reason
|
|
1180
|
+
};
|
|
1181
|
+
if ((choice == null ? void 0 : choice.logprobs) != null) providerMetadata.openai.logprobs = choice.logprobs;
|
|
1182
|
+
if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) controller.enqueue({
|
|
1183
|
+
type: "text-delta",
|
|
1184
|
+
id: "0",
|
|
1185
|
+
delta: choice.text
|
|
1186
|
+
});
|
|
1187
|
+
},
|
|
1188
|
+
flush(controller) {
|
|
1189
|
+
if (!isFirstChunk) controller.enqueue({
|
|
1190
|
+
type: "text-end",
|
|
1191
|
+
id: "0"
|
|
1192
|
+
});
|
|
1193
|
+
controller.enqueue({
|
|
1194
|
+
type: "finish",
|
|
1195
|
+
finishReason,
|
|
1196
|
+
providerMetadata,
|
|
1197
|
+
usage: convertOpenAICompletionUsage(usage)
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
})),
|
|
1201
|
+
request: { body },
|
|
1202
|
+
response: { headers: responseHeaders }
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
var openaiEmbeddingModelOptions = lazySchema(() => zodSchema(object({
|
|
1207
|
+
dimensions: number$1().optional(),
|
|
1208
|
+
user: string().optional()
|
|
1209
|
+
})));
|
|
1210
|
+
var openaiTextEmbeddingResponseSchema = lazySchema(() => zodSchema(object({
|
|
1211
|
+
data: array(object({ embedding: array(number$1()) })),
|
|
1212
|
+
usage: object({ prompt_tokens: number$1() }).nullish()
|
|
1213
|
+
})));
|
|
1214
|
+
var OpenAIEmbeddingModel = class {
|
|
1215
|
+
constructor(modelId, config) {
|
|
1216
|
+
this.specificationVersion = "v3";
|
|
1217
|
+
this.maxEmbeddingsPerCall = 2048;
|
|
1218
|
+
this.supportsParallelCalls = true;
|
|
1219
|
+
this.modelId = modelId;
|
|
1220
|
+
this.config = config;
|
|
1221
|
+
}
|
|
1222
|
+
get provider() {
|
|
1223
|
+
return this.config.provider;
|
|
1224
|
+
}
|
|
1225
|
+
async doEmbed({ values, headers, abortSignal, providerOptions }) {
|
|
1226
|
+
var _a;
|
|
1227
|
+
if (values.length > this.maxEmbeddingsPerCall) throw new TooManyEmbeddingValuesForCallError({
|
|
1228
|
+
provider: this.provider,
|
|
1229
|
+
modelId: this.modelId,
|
|
1230
|
+
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1231
|
+
values
|
|
1232
|
+
});
|
|
1233
|
+
const openaiOptions = (_a = await parseProviderOptions({
|
|
1234
|
+
provider: "openai",
|
|
1235
|
+
providerOptions,
|
|
1236
|
+
schema: openaiEmbeddingModelOptions
|
|
1237
|
+
})) != null ? _a : {};
|
|
1238
|
+
const { responseHeaders, value: response, rawValue } = await postJsonToApi({
|
|
1239
|
+
url: this.config.url({
|
|
1240
|
+
path: "/embeddings",
|
|
1241
|
+
modelId: this.modelId
|
|
1242
|
+
}),
|
|
1243
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
1244
|
+
body: {
|
|
1245
|
+
model: this.modelId,
|
|
1246
|
+
input: values,
|
|
1247
|
+
encoding_format: "float",
|
|
1248
|
+
dimensions: openaiOptions.dimensions,
|
|
1249
|
+
user: openaiOptions.user
|
|
1250
|
+
},
|
|
1251
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1252
|
+
successfulResponseHandler: createJsonResponseHandler(openaiTextEmbeddingResponseSchema),
|
|
1253
|
+
abortSignal,
|
|
1254
|
+
fetch: this.config.fetch
|
|
1255
|
+
});
|
|
1256
|
+
return {
|
|
1257
|
+
warnings: [],
|
|
1258
|
+
embeddings: response.data.map((item) => item.embedding),
|
|
1259
|
+
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
1260
|
+
response: {
|
|
1261
|
+
headers: responseHeaders,
|
|
1262
|
+
body: rawValue
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
var openaiImageResponseSchema = lazySchema(() => zodSchema(object({
|
|
1268
|
+
created: number$1().nullish(),
|
|
1269
|
+
data: array(object({
|
|
1270
|
+
b64_json: string(),
|
|
1271
|
+
revised_prompt: string().nullish()
|
|
1272
|
+
})),
|
|
1273
|
+
background: string().nullish(),
|
|
1274
|
+
output_format: string().nullish(),
|
|
1275
|
+
size: string().nullish(),
|
|
1276
|
+
quality: string().nullish(),
|
|
1277
|
+
usage: object({
|
|
1278
|
+
input_tokens: number$1().nullish(),
|
|
1279
|
+
output_tokens: number$1().nullish(),
|
|
1280
|
+
total_tokens: number$1().nullish(),
|
|
1281
|
+
input_tokens_details: object({
|
|
1282
|
+
image_tokens: number$1().nullish(),
|
|
1283
|
+
text_tokens: number$1().nullish()
|
|
1284
|
+
}).nullish()
|
|
1285
|
+
}).nullish()
|
|
1286
|
+
})));
|
|
1287
|
+
var modelMaxImagesPerCall = {
|
|
1288
|
+
"dall-e-3": 1,
|
|
1289
|
+
"dall-e-2": 10,
|
|
1290
|
+
"gpt-image-1": 10,
|
|
1291
|
+
"gpt-image-1-mini": 10,
|
|
1292
|
+
"gpt-image-1.5": 10,
|
|
1293
|
+
"chatgpt-image-latest": 10
|
|
1294
|
+
};
|
|
1295
|
+
var defaultResponseFormatPrefixes = [
|
|
1296
|
+
"chatgpt-image-",
|
|
1297
|
+
"gpt-image-1-mini",
|
|
1298
|
+
"gpt-image-1.5",
|
|
1299
|
+
"gpt-image-1"
|
|
1300
|
+
];
|
|
1301
|
+
function hasDefaultResponseFormat(modelId) {
|
|
1302
|
+
return defaultResponseFormatPrefixes.some((prefix) => modelId.startsWith(prefix));
|
|
1303
|
+
}
|
|
1304
|
+
var OpenAIImageModel = class {
|
|
1305
|
+
constructor(modelId, config) {
|
|
1306
|
+
this.modelId = modelId;
|
|
1307
|
+
this.config = config;
|
|
1308
|
+
this.specificationVersion = "v3";
|
|
1309
|
+
}
|
|
1310
|
+
get maxImagesPerCall() {
|
|
1311
|
+
var _a;
|
|
1312
|
+
return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
|
|
1313
|
+
}
|
|
1314
|
+
get provider() {
|
|
1315
|
+
return this.config.provider;
|
|
1316
|
+
}
|
|
1317
|
+
async doGenerate({ prompt, files, mask, n, size, aspectRatio, seed, providerOptions, headers, abortSignal }) {
|
|
1318
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1319
|
+
const warnings = [];
|
|
1320
|
+
if (aspectRatio != null) warnings.push({
|
|
1321
|
+
type: "unsupported",
|
|
1322
|
+
feature: "aspectRatio",
|
|
1323
|
+
details: "This model does not support aspect ratio. Use `size` instead."
|
|
1324
|
+
});
|
|
1325
|
+
if (seed != null) warnings.push({
|
|
1326
|
+
type: "unsupported",
|
|
1327
|
+
feature: "seed"
|
|
1328
|
+
});
|
|
1329
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1330
|
+
if (files != null) {
|
|
1331
|
+
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
|
|
1332
|
+
url: this.config.url({
|
|
1333
|
+
path: "/images/edits",
|
|
1334
|
+
modelId: this.modelId
|
|
1335
|
+
}),
|
|
1336
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
1337
|
+
formData: convertToFormData({
|
|
1338
|
+
model: this.modelId,
|
|
1339
|
+
prompt,
|
|
1340
|
+
image: await Promise.all(files.map((file) => file.type === "file" ? new Blob([file.data instanceof Uint8Array ? new Blob([file.data], { type: file.mediaType }) : new Blob([convertBase64ToUint8Array(file.data)], { type: file.mediaType })], { type: file.mediaType }) : downloadBlob(file.url))),
|
|
1341
|
+
mask: mask != null ? await fileToBlob(mask) : void 0,
|
|
1342
|
+
n,
|
|
1343
|
+
size,
|
|
1344
|
+
...(_d = providerOptions.openai) != null ? _d : {}
|
|
1345
|
+
}),
|
|
1346
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1347
|
+
successfulResponseHandler: createJsonResponseHandler(openaiImageResponseSchema),
|
|
1348
|
+
abortSignal,
|
|
1349
|
+
fetch: this.config.fetch
|
|
1350
|
+
});
|
|
1351
|
+
return {
|
|
1352
|
+
images: response2.data.map((item) => item.b64_json),
|
|
1353
|
+
warnings,
|
|
1354
|
+
usage: response2.usage != null ? {
|
|
1355
|
+
inputTokens: (_e = response2.usage.input_tokens) != null ? _e : void 0,
|
|
1356
|
+
outputTokens: (_f = response2.usage.output_tokens) != null ? _f : void 0,
|
|
1357
|
+
totalTokens: (_g = response2.usage.total_tokens) != null ? _g : void 0
|
|
1358
|
+
} : void 0,
|
|
1359
|
+
response: {
|
|
1360
|
+
timestamp: currentDate,
|
|
1361
|
+
modelId: this.modelId,
|
|
1362
|
+
headers: responseHeaders2
|
|
1363
|
+
},
|
|
1364
|
+
providerMetadata: { openai: { images: response2.data.map((item, index) => {
|
|
1365
|
+
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
1366
|
+
return {
|
|
1367
|
+
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
1368
|
+
created: (_a2 = response2.created) != null ? _a2 : void 0,
|
|
1369
|
+
size: (_b2 = response2.size) != null ? _b2 : void 0,
|
|
1370
|
+
quality: (_c2 = response2.quality) != null ? _c2 : void 0,
|
|
1371
|
+
background: (_d2 = response2.background) != null ? _d2 : void 0,
|
|
1372
|
+
outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
|
|
1373
|
+
...distributeTokenDetails((_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details, index, response2.data.length)
|
|
1374
|
+
};
|
|
1375
|
+
}) } }
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1379
|
+
url: this.config.url({
|
|
1380
|
+
path: "/images/generations",
|
|
1381
|
+
modelId: this.modelId
|
|
1382
|
+
}),
|
|
1383
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
1384
|
+
body: {
|
|
1385
|
+
model: this.modelId,
|
|
1386
|
+
prompt,
|
|
1387
|
+
n,
|
|
1388
|
+
size,
|
|
1389
|
+
...(_h = providerOptions.openai) != null ? _h : {},
|
|
1390
|
+
...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
|
|
1391
|
+
},
|
|
1392
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1393
|
+
successfulResponseHandler: createJsonResponseHandler(openaiImageResponseSchema),
|
|
1394
|
+
abortSignal,
|
|
1395
|
+
fetch: this.config.fetch
|
|
1396
|
+
});
|
|
1397
|
+
return {
|
|
1398
|
+
images: response.data.map((item) => item.b64_json),
|
|
1399
|
+
warnings,
|
|
1400
|
+
usage: response.usage != null ? {
|
|
1401
|
+
inputTokens: (_i = response.usage.input_tokens) != null ? _i : void 0,
|
|
1402
|
+
outputTokens: (_j = response.usage.output_tokens) != null ? _j : void 0,
|
|
1403
|
+
totalTokens: (_k = response.usage.total_tokens) != null ? _k : void 0
|
|
1404
|
+
} : void 0,
|
|
1405
|
+
response: {
|
|
1406
|
+
timestamp: currentDate,
|
|
1407
|
+
modelId: this.modelId,
|
|
1408
|
+
headers: responseHeaders
|
|
1409
|
+
},
|
|
1410
|
+
providerMetadata: { openai: { images: response.data.map((item, index) => {
|
|
1411
|
+
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
1412
|
+
return {
|
|
1413
|
+
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
1414
|
+
created: (_a2 = response.created) != null ? _a2 : void 0,
|
|
1415
|
+
size: (_b2 = response.size) != null ? _b2 : void 0,
|
|
1416
|
+
quality: (_c2 = response.quality) != null ? _c2 : void 0,
|
|
1417
|
+
background: (_d2 = response.background) != null ? _d2 : void 0,
|
|
1418
|
+
outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
|
|
1419
|
+
...distributeTokenDetails((_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details, index, response.data.length)
|
|
1420
|
+
};
|
|
1421
|
+
}) } }
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
};
|
|
1425
|
+
function distributeTokenDetails(details, index, total) {
|
|
1426
|
+
if (details == null) return {};
|
|
1427
|
+
const result = {};
|
|
1428
|
+
if (details.image_tokens != null) {
|
|
1429
|
+
const base = Math.floor(details.image_tokens / total);
|
|
1430
|
+
const remainder = details.image_tokens - base * (total - 1);
|
|
1431
|
+
result.imageTokens = index === total - 1 ? remainder : base;
|
|
1432
|
+
}
|
|
1433
|
+
if (details.text_tokens != null) {
|
|
1434
|
+
const base = Math.floor(details.text_tokens / total);
|
|
1435
|
+
const remainder = details.text_tokens - base * (total - 1);
|
|
1436
|
+
result.textTokens = index === total - 1 ? remainder : base;
|
|
1437
|
+
}
|
|
1438
|
+
return result;
|
|
1439
|
+
}
|
|
1440
|
+
async function fileToBlob(file) {
|
|
1441
|
+
if (!file) return void 0;
|
|
1442
|
+
if (file.type === "url") return downloadBlob(file.url);
|
|
1443
|
+
const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array(file.data);
|
|
1444
|
+
return new Blob([data], { type: file.mediaType });
|
|
1445
|
+
}
|
|
1446
|
+
var applyPatchInputSchema = lazySchema(() => zodSchema(object({
|
|
1447
|
+
callId: string(),
|
|
1448
|
+
operation: discriminatedUnion("type", [
|
|
1449
|
+
object({
|
|
1450
|
+
type: literal("create_file"),
|
|
1451
|
+
path: string(),
|
|
1452
|
+
diff: string()
|
|
1453
|
+
}),
|
|
1454
|
+
object({
|
|
1455
|
+
type: literal("delete_file"),
|
|
1456
|
+
path: string()
|
|
1457
|
+
}),
|
|
1458
|
+
object({
|
|
1459
|
+
type: literal("update_file"),
|
|
1460
|
+
path: string(),
|
|
1461
|
+
diff: string()
|
|
1462
|
+
})
|
|
1463
|
+
])
|
|
1464
|
+
})));
|
|
1465
|
+
var applyPatchOutputSchema = lazySchema(() => zodSchema(object({
|
|
1466
|
+
status: _enum(["completed", "failed"]),
|
|
1467
|
+
output: string().optional()
|
|
1468
|
+
})));
|
|
1469
|
+
lazySchema(() => zodSchema(object({})));
|
|
1470
|
+
var applyPatch = createProviderToolFactoryWithOutputSchema({
|
|
1471
|
+
id: "openai.apply_patch",
|
|
1472
|
+
inputSchema: applyPatchInputSchema,
|
|
1473
|
+
outputSchema: applyPatchOutputSchema
|
|
1474
|
+
});
|
|
1475
|
+
var codeInterpreterInputSchema = lazySchema(() => zodSchema(object({
|
|
1476
|
+
code: string().nullish(),
|
|
1477
|
+
containerId: string()
|
|
1478
|
+
})));
|
|
1479
|
+
var codeInterpreterOutputSchema = lazySchema(() => zodSchema(object({ outputs: array(discriminatedUnion("type", [object({
|
|
1480
|
+
type: literal("logs"),
|
|
1481
|
+
logs: string()
|
|
1482
|
+
}), object({
|
|
1483
|
+
type: literal("image"),
|
|
1484
|
+
url: string()
|
|
1485
|
+
})])).nullish() })));
|
|
1486
|
+
var codeInterpreterArgsSchema = lazySchema(() => zodSchema(object({ container: union([string(), object({ fileIds: array(string()).optional() })]).optional() })));
|
|
1487
|
+
var codeInterpreterToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
1488
|
+
id: "openai.code_interpreter",
|
|
1489
|
+
inputSchema: codeInterpreterInputSchema,
|
|
1490
|
+
outputSchema: codeInterpreterOutputSchema
|
|
1491
|
+
});
|
|
1492
|
+
var codeInterpreter = (args = {}) => {
|
|
1493
|
+
return codeInterpreterToolFactory(args);
|
|
1494
|
+
};
|
|
1495
|
+
var customArgsSchema = lazySchema(() => zodSchema(object({
|
|
1496
|
+
name: string(),
|
|
1497
|
+
description: string().optional(),
|
|
1498
|
+
format: union([object({
|
|
1499
|
+
type: literal("grammar"),
|
|
1500
|
+
syntax: _enum(["regex", "lark"]),
|
|
1501
|
+
definition: string()
|
|
1502
|
+
}), object({ type: literal("text") })]).optional()
|
|
1503
|
+
})));
|
|
1504
|
+
var customToolFactory = createProviderToolFactory({
|
|
1505
|
+
id: "openai.custom",
|
|
1506
|
+
inputSchema: lazySchema(() => zodSchema(string()))
|
|
1507
|
+
});
|
|
1508
|
+
var customTool = (args) => customToolFactory(args);
|
|
1509
|
+
var comparisonFilterSchema = object({
|
|
1510
|
+
key: string(),
|
|
1511
|
+
type: _enum([
|
|
1512
|
+
"eq",
|
|
1513
|
+
"ne",
|
|
1514
|
+
"gt",
|
|
1515
|
+
"gte",
|
|
1516
|
+
"lt",
|
|
1517
|
+
"lte",
|
|
1518
|
+
"in",
|
|
1519
|
+
"nin"
|
|
1520
|
+
]),
|
|
1521
|
+
value: union([
|
|
1522
|
+
string(),
|
|
1523
|
+
number$1(),
|
|
1524
|
+
boolean(),
|
|
1525
|
+
array(string())
|
|
1526
|
+
])
|
|
1527
|
+
});
|
|
1528
|
+
var compoundFilterSchema = object({
|
|
1529
|
+
type: _enum(["and", "or"]),
|
|
1530
|
+
filters: array(union([comparisonFilterSchema, lazy(() => compoundFilterSchema)]))
|
|
1531
|
+
});
|
|
1532
|
+
var fileSearchArgsSchema = lazySchema(() => zodSchema(object({
|
|
1533
|
+
vectorStoreIds: array(string()),
|
|
1534
|
+
maxNumResults: number$1().optional(),
|
|
1535
|
+
ranking: object({
|
|
1536
|
+
ranker: string().optional(),
|
|
1537
|
+
scoreThreshold: number$1().optional()
|
|
1538
|
+
}).optional(),
|
|
1539
|
+
filters: union([comparisonFilterSchema, compoundFilterSchema]).optional()
|
|
1540
|
+
})));
|
|
1541
|
+
var fileSearchOutputSchema = lazySchema(() => zodSchema(object({
|
|
1542
|
+
queries: array(string()),
|
|
1543
|
+
results: array(object({
|
|
1544
|
+
attributes: record(string(), unknown()),
|
|
1545
|
+
fileId: string(),
|
|
1546
|
+
filename: string(),
|
|
1547
|
+
score: number$1(),
|
|
1548
|
+
text: string()
|
|
1549
|
+
})).nullable()
|
|
1550
|
+
})));
|
|
1551
|
+
var fileSearch = createProviderToolFactoryWithOutputSchema({
|
|
1552
|
+
id: "openai.file_search",
|
|
1553
|
+
inputSchema: object({}),
|
|
1554
|
+
outputSchema: fileSearchOutputSchema
|
|
1555
|
+
});
|
|
1556
|
+
var imageGenerationArgsSchema = lazySchema(() => zodSchema(object({
|
|
1557
|
+
background: _enum([
|
|
1558
|
+
"auto",
|
|
1559
|
+
"opaque",
|
|
1560
|
+
"transparent"
|
|
1561
|
+
]).optional(),
|
|
1562
|
+
inputFidelity: _enum(["low", "high"]).optional(),
|
|
1563
|
+
inputImageMask: object({
|
|
1564
|
+
fileId: string().optional(),
|
|
1565
|
+
imageUrl: string().optional()
|
|
1566
|
+
}).optional(),
|
|
1567
|
+
model: string().optional(),
|
|
1568
|
+
moderation: _enum(["auto"]).optional(),
|
|
1569
|
+
outputCompression: number$1().int().min(0).max(100).optional(),
|
|
1570
|
+
outputFormat: _enum([
|
|
1571
|
+
"png",
|
|
1572
|
+
"jpeg",
|
|
1573
|
+
"webp"
|
|
1574
|
+
]).optional(),
|
|
1575
|
+
partialImages: number$1().int().min(0).max(3).optional(),
|
|
1576
|
+
quality: _enum([
|
|
1577
|
+
"auto",
|
|
1578
|
+
"low",
|
|
1579
|
+
"medium",
|
|
1580
|
+
"high"
|
|
1581
|
+
]).optional(),
|
|
1582
|
+
size: _enum([
|
|
1583
|
+
"1024x1024",
|
|
1584
|
+
"1024x1536",
|
|
1585
|
+
"1536x1024",
|
|
1586
|
+
"auto"
|
|
1587
|
+
]).optional()
|
|
1588
|
+
}).strict()));
|
|
1589
|
+
var imageGenerationToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
1590
|
+
id: "openai.image_generation",
|
|
1591
|
+
inputSchema: lazySchema(() => zodSchema(object({}))),
|
|
1592
|
+
outputSchema: lazySchema(() => zodSchema(object({ result: string() })))
|
|
1593
|
+
});
|
|
1594
|
+
var imageGeneration = (args = {}) => {
|
|
1595
|
+
return imageGenerationToolFactory(args);
|
|
1596
|
+
};
|
|
1597
|
+
var localShellInputSchema = lazySchema(() => zodSchema(object({ action: object({
|
|
1598
|
+
type: literal("exec"),
|
|
1599
|
+
command: array(string()),
|
|
1600
|
+
timeoutMs: number$1().optional(),
|
|
1601
|
+
user: string().optional(),
|
|
1602
|
+
workingDirectory: string().optional(),
|
|
1603
|
+
env: record(string(), string()).optional()
|
|
1604
|
+
}) })));
|
|
1605
|
+
var localShellOutputSchema = lazySchema(() => zodSchema(object({ output: string() })));
|
|
1606
|
+
var localShell = createProviderToolFactoryWithOutputSchema({
|
|
1607
|
+
id: "openai.local_shell",
|
|
1608
|
+
inputSchema: localShellInputSchema,
|
|
1609
|
+
outputSchema: localShellOutputSchema
|
|
1610
|
+
});
|
|
1611
|
+
var shellInputSchema = lazySchema(() => zodSchema(object({ action: object({
|
|
1612
|
+
commands: array(string()),
|
|
1613
|
+
timeoutMs: number$1().optional(),
|
|
1614
|
+
maxOutputLength: number$1().optional()
|
|
1615
|
+
}) })));
|
|
1616
|
+
var shellOutputSchema = lazySchema(() => zodSchema(object({ output: array(object({
|
|
1617
|
+
stdout: string(),
|
|
1618
|
+
stderr: string(),
|
|
1619
|
+
outcome: discriminatedUnion("type", [object({ type: literal("timeout") }), object({
|
|
1620
|
+
type: literal("exit"),
|
|
1621
|
+
exitCode: number$1()
|
|
1622
|
+
})])
|
|
1623
|
+
})) })));
|
|
1624
|
+
var shellSkillsSchema = array(discriminatedUnion("type", [object({
|
|
1625
|
+
type: literal("skillReference"),
|
|
1626
|
+
skillId: string(),
|
|
1627
|
+
version: string().optional()
|
|
1628
|
+
}), object({
|
|
1629
|
+
type: literal("inline"),
|
|
1630
|
+
name: string(),
|
|
1631
|
+
description: string(),
|
|
1632
|
+
source: object({
|
|
1633
|
+
type: literal("base64"),
|
|
1634
|
+
mediaType: literal("application/zip"),
|
|
1635
|
+
data: string()
|
|
1636
|
+
})
|
|
1637
|
+
})])).optional();
|
|
1638
|
+
var shellArgsSchema = lazySchema(() => zodSchema(object({ environment: union([
|
|
1639
|
+
object({
|
|
1640
|
+
type: literal("containerAuto"),
|
|
1641
|
+
fileIds: array(string()).optional(),
|
|
1642
|
+
memoryLimit: _enum([
|
|
1643
|
+
"1g",
|
|
1644
|
+
"4g",
|
|
1645
|
+
"16g",
|
|
1646
|
+
"64g"
|
|
1647
|
+
]).optional(),
|
|
1648
|
+
networkPolicy: discriminatedUnion("type", [object({ type: literal("disabled") }), object({
|
|
1649
|
+
type: literal("allowlist"),
|
|
1650
|
+
allowedDomains: array(string()),
|
|
1651
|
+
domainSecrets: array(object({
|
|
1652
|
+
domain: string(),
|
|
1653
|
+
name: string(),
|
|
1654
|
+
value: string()
|
|
1655
|
+
})).optional()
|
|
1656
|
+
})]).optional(),
|
|
1657
|
+
skills: shellSkillsSchema
|
|
1658
|
+
}),
|
|
1659
|
+
object({
|
|
1660
|
+
type: literal("containerReference"),
|
|
1661
|
+
containerId: string()
|
|
1662
|
+
}),
|
|
1663
|
+
object({
|
|
1664
|
+
type: literal("local").optional(),
|
|
1665
|
+
skills: array(object({
|
|
1666
|
+
name: string(),
|
|
1667
|
+
description: string(),
|
|
1668
|
+
path: string()
|
|
1669
|
+
})).optional()
|
|
1670
|
+
})
|
|
1671
|
+
]).optional() })));
|
|
1672
|
+
var shell = createProviderToolFactoryWithOutputSchema({
|
|
1673
|
+
id: "openai.shell",
|
|
1674
|
+
inputSchema: shellInputSchema,
|
|
1675
|
+
outputSchema: shellOutputSchema
|
|
1676
|
+
});
|
|
1677
|
+
var webSearchArgsSchema = lazySchema(() => zodSchema(object({
|
|
1678
|
+
externalWebAccess: boolean().optional(),
|
|
1679
|
+
filters: object({ allowedDomains: array(string()).optional() }).optional(),
|
|
1680
|
+
searchContextSize: _enum([
|
|
1681
|
+
"low",
|
|
1682
|
+
"medium",
|
|
1683
|
+
"high"
|
|
1684
|
+
]).optional(),
|
|
1685
|
+
userLocation: object({
|
|
1686
|
+
type: literal("approximate"),
|
|
1687
|
+
country: string().optional(),
|
|
1688
|
+
city: string().optional(),
|
|
1689
|
+
region: string().optional(),
|
|
1690
|
+
timezone: string().optional()
|
|
1691
|
+
}).optional()
|
|
1692
|
+
})));
|
|
1693
|
+
var webSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
1694
|
+
id: "openai.web_search",
|
|
1695
|
+
inputSchema: lazySchema(() => zodSchema(object({}))),
|
|
1696
|
+
outputSchema: lazySchema(() => zodSchema(object({
|
|
1697
|
+
action: discriminatedUnion("type", [
|
|
1698
|
+
object({
|
|
1699
|
+
type: literal("search"),
|
|
1700
|
+
query: string().optional()
|
|
1701
|
+
}),
|
|
1702
|
+
object({
|
|
1703
|
+
type: literal("openPage"),
|
|
1704
|
+
url: string().nullish()
|
|
1705
|
+
}),
|
|
1706
|
+
object({
|
|
1707
|
+
type: literal("findInPage"),
|
|
1708
|
+
url: string().nullish(),
|
|
1709
|
+
pattern: string().nullish()
|
|
1710
|
+
})
|
|
1711
|
+
]).optional(),
|
|
1712
|
+
sources: array(discriminatedUnion("type", [object({
|
|
1713
|
+
type: literal("url"),
|
|
1714
|
+
url: string()
|
|
1715
|
+
}), object({
|
|
1716
|
+
type: literal("api"),
|
|
1717
|
+
name: string()
|
|
1718
|
+
})])).optional()
|
|
1719
|
+
})))
|
|
1720
|
+
});
|
|
1721
|
+
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
1722
|
+
var webSearchPreviewArgsSchema = lazySchema(() => zodSchema(object({
|
|
1723
|
+
searchContextSize: _enum([
|
|
1724
|
+
"low",
|
|
1725
|
+
"medium",
|
|
1726
|
+
"high"
|
|
1727
|
+
]).optional(),
|
|
1728
|
+
userLocation: object({
|
|
1729
|
+
type: literal("approximate"),
|
|
1730
|
+
country: string().optional(),
|
|
1731
|
+
city: string().optional(),
|
|
1732
|
+
region: string().optional(),
|
|
1733
|
+
timezone: string().optional()
|
|
1734
|
+
}).optional()
|
|
1735
|
+
})));
|
|
1736
|
+
var webSearchPreview = createProviderToolFactoryWithOutputSchema({
|
|
1737
|
+
id: "openai.web_search_preview",
|
|
1738
|
+
inputSchema: lazySchema(() => zodSchema(object({}))),
|
|
1739
|
+
outputSchema: lazySchema(() => zodSchema(object({ action: discriminatedUnion("type", [
|
|
1740
|
+
object({
|
|
1741
|
+
type: literal("search"),
|
|
1742
|
+
query: string().optional()
|
|
1743
|
+
}),
|
|
1744
|
+
object({
|
|
1745
|
+
type: literal("openPage"),
|
|
1746
|
+
url: string().nullish()
|
|
1747
|
+
}),
|
|
1748
|
+
object({
|
|
1749
|
+
type: literal("findInPage"),
|
|
1750
|
+
url: string().nullish(),
|
|
1751
|
+
pattern: string().nullish()
|
|
1752
|
+
})
|
|
1753
|
+
]).optional() })))
|
|
1754
|
+
});
|
|
1755
|
+
var jsonValueSchema = lazy(() => union([
|
|
1756
|
+
string(),
|
|
1757
|
+
number$1(),
|
|
1758
|
+
boolean(),
|
|
1759
|
+
_null(),
|
|
1760
|
+
array(jsonValueSchema),
|
|
1761
|
+
record(string(), jsonValueSchema)
|
|
1762
|
+
]));
|
|
1763
|
+
var mcpArgsSchema = lazySchema(() => zodSchema(object({
|
|
1764
|
+
serverLabel: string(),
|
|
1765
|
+
allowedTools: union([array(string()), object({
|
|
1766
|
+
readOnly: boolean().optional(),
|
|
1767
|
+
toolNames: array(string()).optional()
|
|
1768
|
+
})]).optional(),
|
|
1769
|
+
authorization: string().optional(),
|
|
1770
|
+
connectorId: string().optional(),
|
|
1771
|
+
headers: record(string(), string()).optional(),
|
|
1772
|
+
requireApproval: union([_enum(["always", "never"]), object({ never: object({ toolNames: array(string()).optional() }).optional() })]).optional(),
|
|
1773
|
+
serverDescription: string().optional(),
|
|
1774
|
+
serverUrl: string().optional()
|
|
1775
|
+
}).refine((v) => v.serverUrl != null || v.connectorId != null, "One of serverUrl or connectorId must be provided.")));
|
|
1776
|
+
var mcpToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
1777
|
+
id: "openai.mcp",
|
|
1778
|
+
inputSchema: lazySchema(() => zodSchema(object({}))),
|
|
1779
|
+
outputSchema: lazySchema(() => zodSchema(object({
|
|
1780
|
+
type: literal("call"),
|
|
1781
|
+
serverLabel: string(),
|
|
1782
|
+
name: string(),
|
|
1783
|
+
arguments: string(),
|
|
1784
|
+
output: string().nullish(),
|
|
1785
|
+
error: union([string(), jsonValueSchema]).optional()
|
|
1786
|
+
})))
|
|
1787
|
+
});
|
|
1788
|
+
var mcp = (args) => mcpToolFactory(args);
|
|
1789
|
+
var openaiTools = {
|
|
1790
|
+
applyPatch,
|
|
1791
|
+
customTool,
|
|
1792
|
+
codeInterpreter,
|
|
1793
|
+
fileSearch,
|
|
1794
|
+
imageGeneration,
|
|
1795
|
+
localShell,
|
|
1796
|
+
shell,
|
|
1797
|
+
webSearchPreview,
|
|
1798
|
+
webSearch,
|
|
1799
|
+
mcp
|
|
1800
|
+
};
|
|
1801
|
+
function convertOpenAIResponsesUsage(usage) {
|
|
1802
|
+
var _a, _b, _c, _d;
|
|
1803
|
+
if (usage == null) return {
|
|
1804
|
+
inputTokens: {
|
|
1805
|
+
total: void 0,
|
|
1806
|
+
noCache: void 0,
|
|
1807
|
+
cacheRead: void 0,
|
|
1808
|
+
cacheWrite: void 0
|
|
1809
|
+
},
|
|
1810
|
+
outputTokens: {
|
|
1811
|
+
total: void 0,
|
|
1812
|
+
text: void 0,
|
|
1813
|
+
reasoning: void 0
|
|
1814
|
+
},
|
|
1815
|
+
raw: void 0
|
|
1816
|
+
};
|
|
1817
|
+
const inputTokens = usage.input_tokens;
|
|
1818
|
+
const outputTokens = usage.output_tokens;
|
|
1819
|
+
const cachedTokens = (_b = (_a = usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
|
|
1820
|
+
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
1821
|
+
return {
|
|
1822
|
+
inputTokens: {
|
|
1823
|
+
total: inputTokens,
|
|
1824
|
+
noCache: inputTokens - cachedTokens,
|
|
1825
|
+
cacheRead: cachedTokens,
|
|
1826
|
+
cacheWrite: void 0
|
|
1827
|
+
},
|
|
1828
|
+
outputTokens: {
|
|
1829
|
+
total: outputTokens,
|
|
1830
|
+
text: outputTokens - reasoningTokens,
|
|
1831
|
+
reasoning: reasoningTokens
|
|
1832
|
+
},
|
|
1833
|
+
raw: usage
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
function isFileId(data, prefixes) {
|
|
1837
|
+
if (!prefixes) return false;
|
|
1838
|
+
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
1839
|
+
}
|
|
1840
|
+
async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMessageMode, providerOptionsName, fileIdPrefixes, store, hasConversation = false, hasLocalShellTool = false, hasShellTool = false, hasApplyPatchTool = false, customProviderToolNames }) {
|
|
1841
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1842
|
+
const input = [];
|
|
1843
|
+
const warnings = [];
|
|
1844
|
+
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
1845
|
+
for (const { role, content } of prompt) switch (role) {
|
|
1846
|
+
case "system":
|
|
1847
|
+
switch (systemMessageMode) {
|
|
1848
|
+
case "system":
|
|
1849
|
+
input.push({
|
|
1850
|
+
role: "system",
|
|
1851
|
+
content
|
|
1852
|
+
});
|
|
1853
|
+
break;
|
|
1854
|
+
case "developer":
|
|
1855
|
+
input.push({
|
|
1856
|
+
role: "developer",
|
|
1857
|
+
content
|
|
1858
|
+
});
|
|
1859
|
+
break;
|
|
1860
|
+
case "remove":
|
|
1861
|
+
warnings.push({
|
|
1862
|
+
type: "other",
|
|
1863
|
+
message: "system messages are removed for this model"
|
|
1864
|
+
});
|
|
1865
|
+
break;
|
|
1866
|
+
default: {
|
|
1867
|
+
const _exhaustiveCheck = systemMessageMode;
|
|
1868
|
+
throw new Error(`Unsupported system message mode: ${_exhaustiveCheck}`);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
break;
|
|
1872
|
+
case "user":
|
|
1873
|
+
input.push({
|
|
1874
|
+
role: "user",
|
|
1875
|
+
content: content.map((part, index) => {
|
|
1876
|
+
var _a2, _b2, _c2;
|
|
1877
|
+
switch (part.type) {
|
|
1878
|
+
case "text": return {
|
|
1879
|
+
type: "input_text",
|
|
1880
|
+
text: part.text
|
|
1881
|
+
};
|
|
1882
|
+
case "file": if (part.mediaType.startsWith("image/")) {
|
|
1883
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
1884
|
+
return {
|
|
1885
|
+
type: "input_image",
|
|
1886
|
+
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : { image_url: `data:${mediaType};base64,${convertToBase64(part.data)}` },
|
|
1887
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
|
|
1888
|
+
};
|
|
1889
|
+
} else if (part.mediaType === "application/pdf") {
|
|
1890
|
+
if (part.data instanceof URL) return {
|
|
1891
|
+
type: "input_file",
|
|
1892
|
+
file_url: part.data.toString()
|
|
1893
|
+
};
|
|
1894
|
+
return {
|
|
1895
|
+
type: "input_file",
|
|
1896
|
+
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
1897
|
+
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
1898
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
} else throw new UnsupportedFunctionalityError({ functionality: `file part media type ${part.mediaType}` });
|
|
1902
|
+
}
|
|
1903
|
+
})
|
|
1904
|
+
});
|
|
1905
|
+
break;
|
|
1906
|
+
case "assistant": {
|
|
1907
|
+
const reasoningMessages = {};
|
|
1908
|
+
for (const part of content) switch (part.type) {
|
|
1909
|
+
case "text": {
|
|
1910
|
+
const providerOpts = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName];
|
|
1911
|
+
const id = providerOpts == null ? void 0 : providerOpts.itemId;
|
|
1912
|
+
const phase = providerOpts == null ? void 0 : providerOpts.phase;
|
|
1913
|
+
if (hasConversation && id != null) break;
|
|
1914
|
+
if (store && id != null) {
|
|
1915
|
+
input.push({
|
|
1916
|
+
type: "item_reference",
|
|
1917
|
+
id
|
|
1918
|
+
});
|
|
1919
|
+
break;
|
|
1920
|
+
}
|
|
1921
|
+
input.push({
|
|
1922
|
+
role: "assistant",
|
|
1923
|
+
content: [{
|
|
1924
|
+
type: "output_text",
|
|
1925
|
+
text: part.text
|
|
1926
|
+
}],
|
|
1927
|
+
id,
|
|
1928
|
+
...phase != null && { phase }
|
|
1929
|
+
});
|
|
1930
|
+
break;
|
|
1931
|
+
}
|
|
1932
|
+
case "tool-call": {
|
|
1933
|
+
const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
|
|
1934
|
+
if (hasConversation && id != null) break;
|
|
1935
|
+
if (part.providerExecuted) {
|
|
1936
|
+
if (store && id != null) input.push({
|
|
1937
|
+
type: "item_reference",
|
|
1938
|
+
id
|
|
1939
|
+
});
|
|
1940
|
+
break;
|
|
1941
|
+
}
|
|
1942
|
+
if (store && id != null) {
|
|
1943
|
+
input.push({
|
|
1944
|
+
type: "item_reference",
|
|
1945
|
+
id
|
|
1946
|
+
});
|
|
1947
|
+
break;
|
|
1948
|
+
}
|
|
1949
|
+
const resolvedToolName = toolNameMapping.toProviderToolName(part.toolName);
|
|
1950
|
+
if (hasLocalShellTool && resolvedToolName === "local_shell") {
|
|
1951
|
+
const parsedInput = await validateTypes({
|
|
1952
|
+
value: part.input,
|
|
1953
|
+
schema: localShellInputSchema
|
|
1954
|
+
});
|
|
1955
|
+
input.push({
|
|
1956
|
+
type: "local_shell_call",
|
|
1957
|
+
call_id: part.toolCallId,
|
|
1958
|
+
id,
|
|
1959
|
+
action: {
|
|
1960
|
+
type: "exec",
|
|
1961
|
+
command: parsedInput.action.command,
|
|
1962
|
+
timeout_ms: parsedInput.action.timeoutMs,
|
|
1963
|
+
user: parsedInput.action.user,
|
|
1964
|
+
working_directory: parsedInput.action.workingDirectory,
|
|
1965
|
+
env: parsedInput.action.env
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
break;
|
|
1969
|
+
}
|
|
1970
|
+
if (hasShellTool && resolvedToolName === "shell") {
|
|
1971
|
+
const parsedInput = await validateTypes({
|
|
1972
|
+
value: part.input,
|
|
1973
|
+
schema: shellInputSchema
|
|
1974
|
+
});
|
|
1975
|
+
input.push({
|
|
1976
|
+
type: "shell_call",
|
|
1977
|
+
call_id: part.toolCallId,
|
|
1978
|
+
id,
|
|
1979
|
+
status: "completed",
|
|
1980
|
+
action: {
|
|
1981
|
+
commands: parsedInput.action.commands,
|
|
1982
|
+
timeout_ms: parsedInput.action.timeoutMs,
|
|
1983
|
+
max_output_length: parsedInput.action.maxOutputLength
|
|
1984
|
+
}
|
|
1985
|
+
});
|
|
1986
|
+
break;
|
|
1987
|
+
}
|
|
1988
|
+
if (hasApplyPatchTool && resolvedToolName === "apply_patch") {
|
|
1989
|
+
const parsedInput = await validateTypes({
|
|
1990
|
+
value: part.input,
|
|
1991
|
+
schema: applyPatchInputSchema
|
|
1992
|
+
});
|
|
1993
|
+
input.push({
|
|
1994
|
+
type: "apply_patch_call",
|
|
1995
|
+
call_id: parsedInput.callId,
|
|
1996
|
+
id,
|
|
1997
|
+
status: "completed",
|
|
1998
|
+
operation: parsedInput.operation
|
|
1999
|
+
});
|
|
2000
|
+
break;
|
|
2001
|
+
}
|
|
2002
|
+
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
2003
|
+
input.push({
|
|
2004
|
+
type: "custom_tool_call",
|
|
2005
|
+
call_id: part.toolCallId,
|
|
2006
|
+
name: resolvedToolName,
|
|
2007
|
+
input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
|
|
2008
|
+
id
|
|
2009
|
+
});
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
input.push({
|
|
2013
|
+
type: "function_call",
|
|
2014
|
+
call_id: part.toolCallId,
|
|
2015
|
+
name: resolvedToolName,
|
|
2016
|
+
arguments: JSON.stringify(part.input),
|
|
2017
|
+
id
|
|
2018
|
+
});
|
|
2019
|
+
break;
|
|
2020
|
+
}
|
|
2021
|
+
case "tool-result": {
|
|
2022
|
+
if (part.output.type === "execution-denied" || part.output.type === "json" && typeof part.output.value === "object" && part.output.value != null && "type" in part.output.value && part.output.value.type === "execution-denied") break;
|
|
2023
|
+
if (hasConversation) break;
|
|
2024
|
+
const resolvedResultToolName = toolNameMapping.toProviderToolName(part.toolName);
|
|
2025
|
+
if (hasShellTool && resolvedResultToolName === "shell") {
|
|
2026
|
+
if (part.output.type === "json") {
|
|
2027
|
+
const parsedOutput = await validateTypes({
|
|
2028
|
+
value: part.output.value,
|
|
2029
|
+
schema: shellOutputSchema
|
|
2030
|
+
});
|
|
2031
|
+
input.push({
|
|
2032
|
+
type: "shell_call_output",
|
|
2033
|
+
call_id: part.toolCallId,
|
|
2034
|
+
output: parsedOutput.output.map((item) => ({
|
|
2035
|
+
stdout: item.stdout,
|
|
2036
|
+
stderr: item.stderr,
|
|
2037
|
+
outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
|
|
2038
|
+
type: "exit",
|
|
2039
|
+
exit_code: item.outcome.exitCode
|
|
2040
|
+
}
|
|
2041
|
+
}))
|
|
2042
|
+
});
|
|
2043
|
+
}
|
|
2044
|
+
break;
|
|
2045
|
+
}
|
|
2046
|
+
if (store) {
|
|
2047
|
+
const itemId = (_i = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.itemId) != null ? _i : part.toolCallId;
|
|
2048
|
+
input.push({
|
|
2049
|
+
type: "item_reference",
|
|
2050
|
+
id: itemId
|
|
2051
|
+
});
|
|
2052
|
+
} else warnings.push({
|
|
2053
|
+
type: "other",
|
|
2054
|
+
message: `Results for OpenAI tool ${part.toolName} are not sent to the API when store is false`
|
|
2055
|
+
});
|
|
2056
|
+
break;
|
|
2057
|
+
}
|
|
2058
|
+
case "reasoning": {
|
|
2059
|
+
const providerOptions = await parseProviderOptions({
|
|
2060
|
+
provider: providerOptionsName,
|
|
2061
|
+
providerOptions: part.providerOptions,
|
|
2062
|
+
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
2063
|
+
});
|
|
2064
|
+
const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
|
|
2065
|
+
if (hasConversation && reasoningId != null) break;
|
|
2066
|
+
if (reasoningId != null) {
|
|
2067
|
+
const reasoningMessage = reasoningMessages[reasoningId];
|
|
2068
|
+
if (store) {
|
|
2069
|
+
if (reasoningMessage === void 0) {
|
|
2070
|
+
input.push({
|
|
2071
|
+
type: "item_reference",
|
|
2072
|
+
id: reasoningId
|
|
2073
|
+
});
|
|
2074
|
+
reasoningMessages[reasoningId] = {
|
|
2075
|
+
type: "reasoning",
|
|
2076
|
+
id: reasoningId,
|
|
2077
|
+
summary: []
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
} else {
|
|
2081
|
+
const summaryParts = [];
|
|
2082
|
+
if (part.text.length > 0) summaryParts.push({
|
|
2083
|
+
type: "summary_text",
|
|
2084
|
+
text: part.text
|
|
2085
|
+
});
|
|
2086
|
+
else if (reasoningMessage !== void 0) warnings.push({
|
|
2087
|
+
type: "other",
|
|
2088
|
+
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2089
|
+
});
|
|
2090
|
+
if (reasoningMessage === void 0) {
|
|
2091
|
+
reasoningMessages[reasoningId] = {
|
|
2092
|
+
type: "reasoning",
|
|
2093
|
+
id: reasoningId,
|
|
2094
|
+
encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
|
|
2095
|
+
summary: summaryParts
|
|
2096
|
+
};
|
|
2097
|
+
input.push(reasoningMessages[reasoningId]);
|
|
2098
|
+
} else {
|
|
2099
|
+
reasoningMessage.summary.push(...summaryParts);
|
|
2100
|
+
if ((providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent) != null) reasoningMessage.encrypted_content = providerOptions.reasoningEncryptedContent;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
} else {
|
|
2104
|
+
const encryptedContent = providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent;
|
|
2105
|
+
if (encryptedContent != null) {
|
|
2106
|
+
const summaryParts = [];
|
|
2107
|
+
if (part.text.length > 0) summaryParts.push({
|
|
2108
|
+
type: "summary_text",
|
|
2109
|
+
text: part.text
|
|
2110
|
+
});
|
|
2111
|
+
input.push({
|
|
2112
|
+
type: "reasoning",
|
|
2113
|
+
encrypted_content: encryptedContent,
|
|
2114
|
+
summary: summaryParts
|
|
2115
|
+
});
|
|
2116
|
+
} else warnings.push({
|
|
2117
|
+
type: "other",
|
|
2118
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
break;
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
break;
|
|
2125
|
+
}
|
|
2126
|
+
case "tool":
|
|
2127
|
+
for (const part of content) {
|
|
2128
|
+
if (part.type === "tool-approval-response") {
|
|
2129
|
+
const approvalResponse = part;
|
|
2130
|
+
if (processedApprovalIds.has(approvalResponse.approvalId)) continue;
|
|
2131
|
+
processedApprovalIds.add(approvalResponse.approvalId);
|
|
2132
|
+
if (store) input.push({
|
|
2133
|
+
type: "item_reference",
|
|
2134
|
+
id: approvalResponse.approvalId
|
|
2135
|
+
});
|
|
2136
|
+
input.push({
|
|
2137
|
+
type: "mcp_approval_response",
|
|
2138
|
+
approval_request_id: approvalResponse.approvalId,
|
|
2139
|
+
approve: approvalResponse.approved
|
|
2140
|
+
});
|
|
2141
|
+
continue;
|
|
2142
|
+
}
|
|
2143
|
+
const output = part.output;
|
|
2144
|
+
if (output.type === "execution-denied") {
|
|
2145
|
+
if ((_k = (_j = output.providerOptions) == null ? void 0 : _j.openai) == null ? void 0 : _k.approvalId) continue;
|
|
2146
|
+
}
|
|
2147
|
+
const resolvedToolName = toolNameMapping.toProviderToolName(part.toolName);
|
|
2148
|
+
if (hasLocalShellTool && resolvedToolName === "local_shell" && output.type === "json") {
|
|
2149
|
+
const parsedOutput = await validateTypes({
|
|
2150
|
+
value: output.value,
|
|
2151
|
+
schema: localShellOutputSchema
|
|
2152
|
+
});
|
|
2153
|
+
input.push({
|
|
2154
|
+
type: "local_shell_call_output",
|
|
2155
|
+
call_id: part.toolCallId,
|
|
2156
|
+
output: parsedOutput.output
|
|
2157
|
+
});
|
|
2158
|
+
continue;
|
|
2159
|
+
}
|
|
2160
|
+
if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
|
|
2161
|
+
const parsedOutput = await validateTypes({
|
|
2162
|
+
value: output.value,
|
|
2163
|
+
schema: shellOutputSchema
|
|
2164
|
+
});
|
|
2165
|
+
input.push({
|
|
2166
|
+
type: "shell_call_output",
|
|
2167
|
+
call_id: part.toolCallId,
|
|
2168
|
+
output: parsedOutput.output.map((item) => ({
|
|
2169
|
+
stdout: item.stdout,
|
|
2170
|
+
stderr: item.stderr,
|
|
2171
|
+
outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
|
|
2172
|
+
type: "exit",
|
|
2173
|
+
exit_code: item.outcome.exitCode
|
|
2174
|
+
}
|
|
2175
|
+
}))
|
|
2176
|
+
});
|
|
2177
|
+
continue;
|
|
2178
|
+
}
|
|
2179
|
+
if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
|
|
2180
|
+
const parsedOutput = await validateTypes({
|
|
2181
|
+
value: output.value,
|
|
2182
|
+
schema: applyPatchOutputSchema
|
|
2183
|
+
});
|
|
2184
|
+
input.push({
|
|
2185
|
+
type: "apply_patch_call_output",
|
|
2186
|
+
call_id: part.toolCallId,
|
|
2187
|
+
status: parsedOutput.status,
|
|
2188
|
+
output: parsedOutput.output
|
|
2189
|
+
});
|
|
2190
|
+
continue;
|
|
2191
|
+
}
|
|
2192
|
+
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
2193
|
+
let outputValue;
|
|
2194
|
+
switch (output.type) {
|
|
2195
|
+
case "text":
|
|
2196
|
+
case "error-text":
|
|
2197
|
+
outputValue = output.value;
|
|
2198
|
+
break;
|
|
2199
|
+
case "execution-denied":
|
|
2200
|
+
outputValue = (_l = output.reason) != null ? _l : "Tool execution denied.";
|
|
2201
|
+
break;
|
|
2202
|
+
case "json":
|
|
2203
|
+
case "error-json":
|
|
2204
|
+
outputValue = JSON.stringify(output.value);
|
|
2205
|
+
break;
|
|
2206
|
+
case "content":
|
|
2207
|
+
outputValue = output.value.map((item) => {
|
|
2208
|
+
var _a2;
|
|
2209
|
+
switch (item.type) {
|
|
2210
|
+
case "text": return {
|
|
2211
|
+
type: "input_text",
|
|
2212
|
+
text: item.text
|
|
2213
|
+
};
|
|
2214
|
+
case "image-data": return {
|
|
2215
|
+
type: "input_image",
|
|
2216
|
+
image_url: `data:${item.mediaType};base64,${item.data}`
|
|
2217
|
+
};
|
|
2218
|
+
case "image-url": return {
|
|
2219
|
+
type: "input_image",
|
|
2220
|
+
image_url: item.url
|
|
2221
|
+
};
|
|
2222
|
+
case "file-data": return {
|
|
2223
|
+
type: "input_file",
|
|
2224
|
+
filename: (_a2 = item.filename) != null ? _a2 : "data",
|
|
2225
|
+
file_data: `data:${item.mediaType};base64,${item.data}`
|
|
2226
|
+
};
|
|
2227
|
+
default:
|
|
2228
|
+
warnings.push({
|
|
2229
|
+
type: "other",
|
|
2230
|
+
message: `unsupported custom tool content part type: ${item.type}`
|
|
2231
|
+
});
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
2234
|
+
}).filter(isNonNullable);
|
|
2235
|
+
break;
|
|
2236
|
+
default: outputValue = "";
|
|
2237
|
+
}
|
|
2238
|
+
input.push({
|
|
2239
|
+
type: "custom_tool_call_output",
|
|
2240
|
+
call_id: part.toolCallId,
|
|
2241
|
+
output: outputValue
|
|
2242
|
+
});
|
|
2243
|
+
continue;
|
|
2244
|
+
}
|
|
2245
|
+
let contentValue;
|
|
2246
|
+
switch (output.type) {
|
|
2247
|
+
case "text":
|
|
2248
|
+
case "error-text":
|
|
2249
|
+
contentValue = output.value;
|
|
2250
|
+
break;
|
|
2251
|
+
case "execution-denied":
|
|
2252
|
+
contentValue = (_m = output.reason) != null ? _m : "Tool execution denied.";
|
|
2253
|
+
break;
|
|
2254
|
+
case "json":
|
|
2255
|
+
case "error-json":
|
|
2256
|
+
contentValue = JSON.stringify(output.value);
|
|
2257
|
+
break;
|
|
2258
|
+
case "content":
|
|
2259
|
+
contentValue = output.value.map((item) => {
|
|
2260
|
+
var _a2;
|
|
2261
|
+
switch (item.type) {
|
|
2262
|
+
case "text": return {
|
|
2263
|
+
type: "input_text",
|
|
2264
|
+
text: item.text
|
|
2265
|
+
};
|
|
2266
|
+
case "image-data": return {
|
|
2267
|
+
type: "input_image",
|
|
2268
|
+
image_url: `data:${item.mediaType};base64,${item.data}`
|
|
2269
|
+
};
|
|
2270
|
+
case "image-url": return {
|
|
2271
|
+
type: "input_image",
|
|
2272
|
+
image_url: item.url
|
|
2273
|
+
};
|
|
2274
|
+
case "file-data": return {
|
|
2275
|
+
type: "input_file",
|
|
2276
|
+
filename: (_a2 = item.filename) != null ? _a2 : "data",
|
|
2277
|
+
file_data: `data:${item.mediaType};base64,${item.data}`
|
|
2278
|
+
};
|
|
2279
|
+
default:
|
|
2280
|
+
warnings.push({
|
|
2281
|
+
type: "other",
|
|
2282
|
+
message: `unsupported tool content part type: ${item.type}`
|
|
2283
|
+
});
|
|
2284
|
+
return;
|
|
2285
|
+
}
|
|
2286
|
+
}).filter(isNonNullable);
|
|
2287
|
+
break;
|
|
2288
|
+
}
|
|
2289
|
+
input.push({
|
|
2290
|
+
type: "function_call_output",
|
|
2291
|
+
call_id: part.toolCallId,
|
|
2292
|
+
output: contentValue
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
break;
|
|
2296
|
+
default: {
|
|
2297
|
+
const _exhaustiveCheck = role;
|
|
2298
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
return {
|
|
2302
|
+
input,
|
|
2303
|
+
warnings
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
var openaiResponsesReasoningProviderOptionsSchema = object({
|
|
2307
|
+
itemId: string().nullish(),
|
|
2308
|
+
reasoningEncryptedContent: string().nullish()
|
|
2309
|
+
});
|
|
2310
|
+
function mapOpenAIResponseFinishReason({ finishReason, hasFunctionCall }) {
|
|
2311
|
+
switch (finishReason) {
|
|
2312
|
+
case void 0:
|
|
2313
|
+
case null: return hasFunctionCall ? "tool-calls" : "stop";
|
|
2314
|
+
case "max_output_tokens": return "length";
|
|
2315
|
+
case "content_filter": return "content-filter";
|
|
2316
|
+
default: return hasFunctionCall ? "tool-calls" : "other";
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
var openaiResponsesChunkSchema = lazySchema(() => zodSchema(union([
|
|
2320
|
+
object({
|
|
2321
|
+
type: literal("response.output_text.delta"),
|
|
2322
|
+
item_id: string(),
|
|
2323
|
+
delta: string(),
|
|
2324
|
+
logprobs: array(object({
|
|
2325
|
+
token: string(),
|
|
2326
|
+
logprob: number$1(),
|
|
2327
|
+
top_logprobs: array(object({
|
|
2328
|
+
token: string(),
|
|
2329
|
+
logprob: number$1()
|
|
2330
|
+
}))
|
|
2331
|
+
})).nullish()
|
|
2332
|
+
}),
|
|
2333
|
+
object({
|
|
2334
|
+
type: _enum(["response.completed", "response.incomplete"]),
|
|
2335
|
+
response: object({
|
|
2336
|
+
incomplete_details: object({ reason: string() }).nullish(),
|
|
2337
|
+
usage: object({
|
|
2338
|
+
input_tokens: number$1(),
|
|
2339
|
+
input_tokens_details: object({ cached_tokens: number$1().nullish() }).nullish(),
|
|
2340
|
+
output_tokens: number$1(),
|
|
2341
|
+
output_tokens_details: object({ reasoning_tokens: number$1().nullish() }).nullish()
|
|
2342
|
+
}),
|
|
2343
|
+
service_tier: string().nullish()
|
|
2344
|
+
})
|
|
2345
|
+
}),
|
|
2346
|
+
object({
|
|
2347
|
+
type: literal("response.created"),
|
|
2348
|
+
response: object({
|
|
2349
|
+
id: string(),
|
|
2350
|
+
created_at: number$1(),
|
|
2351
|
+
model: string(),
|
|
2352
|
+
service_tier: string().nullish()
|
|
2353
|
+
})
|
|
2354
|
+
}),
|
|
2355
|
+
object({
|
|
2356
|
+
type: literal("response.output_item.added"),
|
|
2357
|
+
output_index: number$1(),
|
|
2358
|
+
item: discriminatedUnion("type", [
|
|
2359
|
+
object({
|
|
2360
|
+
type: literal("message"),
|
|
2361
|
+
id: string(),
|
|
2362
|
+
phase: _enum(["commentary", "final_answer"]).nullish()
|
|
2363
|
+
}),
|
|
2364
|
+
object({
|
|
2365
|
+
type: literal("reasoning"),
|
|
2366
|
+
id: string(),
|
|
2367
|
+
encrypted_content: string().nullish()
|
|
2368
|
+
}),
|
|
2369
|
+
object({
|
|
2370
|
+
type: literal("function_call"),
|
|
2371
|
+
id: string(),
|
|
2372
|
+
call_id: string(),
|
|
2373
|
+
name: string(),
|
|
2374
|
+
arguments: string()
|
|
2375
|
+
}),
|
|
2376
|
+
object({
|
|
2377
|
+
type: literal("web_search_call"),
|
|
2378
|
+
id: string(),
|
|
2379
|
+
status: string()
|
|
2380
|
+
}),
|
|
2381
|
+
object({
|
|
2382
|
+
type: literal("computer_call"),
|
|
2383
|
+
id: string(),
|
|
2384
|
+
status: string()
|
|
2385
|
+
}),
|
|
2386
|
+
object({
|
|
2387
|
+
type: literal("file_search_call"),
|
|
2388
|
+
id: string()
|
|
2389
|
+
}),
|
|
2390
|
+
object({
|
|
2391
|
+
type: literal("image_generation_call"),
|
|
2392
|
+
id: string()
|
|
2393
|
+
}),
|
|
2394
|
+
object({
|
|
2395
|
+
type: literal("code_interpreter_call"),
|
|
2396
|
+
id: string(),
|
|
2397
|
+
container_id: string(),
|
|
2398
|
+
code: string().nullable(),
|
|
2399
|
+
outputs: array(discriminatedUnion("type", [object({
|
|
2400
|
+
type: literal("logs"),
|
|
2401
|
+
logs: string()
|
|
2402
|
+
}), object({
|
|
2403
|
+
type: literal("image"),
|
|
2404
|
+
url: string()
|
|
2405
|
+
})])).nullable(),
|
|
2406
|
+
status: string()
|
|
2407
|
+
}),
|
|
2408
|
+
object({
|
|
2409
|
+
type: literal("mcp_call"),
|
|
2410
|
+
id: string(),
|
|
2411
|
+
status: string(),
|
|
2412
|
+
approval_request_id: string().nullish()
|
|
2413
|
+
}),
|
|
2414
|
+
object({
|
|
2415
|
+
type: literal("mcp_list_tools"),
|
|
2416
|
+
id: string()
|
|
2417
|
+
}),
|
|
2418
|
+
object({
|
|
2419
|
+
type: literal("mcp_approval_request"),
|
|
2420
|
+
id: string()
|
|
2421
|
+
}),
|
|
2422
|
+
object({
|
|
2423
|
+
type: literal("apply_patch_call"),
|
|
2424
|
+
id: string(),
|
|
2425
|
+
call_id: string(),
|
|
2426
|
+
status: _enum(["in_progress", "completed"]),
|
|
2427
|
+
operation: discriminatedUnion("type", [
|
|
2428
|
+
object({
|
|
2429
|
+
type: literal("create_file"),
|
|
2430
|
+
path: string(),
|
|
2431
|
+
diff: string()
|
|
2432
|
+
}),
|
|
2433
|
+
object({
|
|
2434
|
+
type: literal("delete_file"),
|
|
2435
|
+
path: string()
|
|
2436
|
+
}),
|
|
2437
|
+
object({
|
|
2438
|
+
type: literal("update_file"),
|
|
2439
|
+
path: string(),
|
|
2440
|
+
diff: string()
|
|
2441
|
+
})
|
|
2442
|
+
])
|
|
2443
|
+
}),
|
|
2444
|
+
object({
|
|
2445
|
+
type: literal("custom_tool_call"),
|
|
2446
|
+
id: string(),
|
|
2447
|
+
call_id: string(),
|
|
2448
|
+
name: string(),
|
|
2449
|
+
input: string()
|
|
2450
|
+
}),
|
|
2451
|
+
object({
|
|
2452
|
+
type: literal("shell_call"),
|
|
2453
|
+
id: string(),
|
|
2454
|
+
call_id: string(),
|
|
2455
|
+
status: _enum([
|
|
2456
|
+
"in_progress",
|
|
2457
|
+
"completed",
|
|
2458
|
+
"incomplete"
|
|
2459
|
+
]),
|
|
2460
|
+
action: object({ commands: array(string()) })
|
|
2461
|
+
}),
|
|
2462
|
+
object({
|
|
2463
|
+
type: literal("shell_call_output"),
|
|
2464
|
+
id: string(),
|
|
2465
|
+
call_id: string(),
|
|
2466
|
+
status: _enum([
|
|
2467
|
+
"in_progress",
|
|
2468
|
+
"completed",
|
|
2469
|
+
"incomplete"
|
|
2470
|
+
]),
|
|
2471
|
+
output: array(object({
|
|
2472
|
+
stdout: string(),
|
|
2473
|
+
stderr: string(),
|
|
2474
|
+
outcome: discriminatedUnion("type", [object({ type: literal("timeout") }), object({
|
|
2475
|
+
type: literal("exit"),
|
|
2476
|
+
exit_code: number$1()
|
|
2477
|
+
})])
|
|
2478
|
+
}))
|
|
2479
|
+
})
|
|
2480
|
+
])
|
|
2481
|
+
}),
|
|
2482
|
+
object({
|
|
2483
|
+
type: literal("response.output_item.done"),
|
|
2484
|
+
output_index: number$1(),
|
|
2485
|
+
item: discriminatedUnion("type", [
|
|
2486
|
+
object({
|
|
2487
|
+
type: literal("message"),
|
|
2488
|
+
id: string(),
|
|
2489
|
+
phase: _enum(["commentary", "final_answer"]).nullish()
|
|
2490
|
+
}),
|
|
2491
|
+
object({
|
|
2492
|
+
type: literal("reasoning"),
|
|
2493
|
+
id: string(),
|
|
2494
|
+
encrypted_content: string().nullish()
|
|
2495
|
+
}),
|
|
2496
|
+
object({
|
|
2497
|
+
type: literal("function_call"),
|
|
2498
|
+
id: string(),
|
|
2499
|
+
call_id: string(),
|
|
2500
|
+
name: string(),
|
|
2501
|
+
arguments: string(),
|
|
2502
|
+
status: literal("completed")
|
|
2503
|
+
}),
|
|
2504
|
+
object({
|
|
2505
|
+
type: literal("custom_tool_call"),
|
|
2506
|
+
id: string(),
|
|
2507
|
+
call_id: string(),
|
|
2508
|
+
name: string(),
|
|
2509
|
+
input: string(),
|
|
2510
|
+
status: literal("completed")
|
|
2511
|
+
}),
|
|
2512
|
+
object({
|
|
2513
|
+
type: literal("code_interpreter_call"),
|
|
2514
|
+
id: string(),
|
|
2515
|
+
code: string().nullable(),
|
|
2516
|
+
container_id: string(),
|
|
2517
|
+
outputs: array(discriminatedUnion("type", [object({
|
|
2518
|
+
type: literal("logs"),
|
|
2519
|
+
logs: string()
|
|
2520
|
+
}), object({
|
|
2521
|
+
type: literal("image"),
|
|
2522
|
+
url: string()
|
|
2523
|
+
})])).nullable()
|
|
2524
|
+
}),
|
|
2525
|
+
object({
|
|
2526
|
+
type: literal("image_generation_call"),
|
|
2527
|
+
id: string(),
|
|
2528
|
+
result: string()
|
|
2529
|
+
}),
|
|
2530
|
+
object({
|
|
2531
|
+
type: literal("web_search_call"),
|
|
2532
|
+
id: string(),
|
|
2533
|
+
status: string(),
|
|
2534
|
+
action: discriminatedUnion("type", [
|
|
2535
|
+
object({
|
|
2536
|
+
type: literal("search"),
|
|
2537
|
+
query: string().nullish(),
|
|
2538
|
+
sources: array(discriminatedUnion("type", [object({
|
|
2539
|
+
type: literal("url"),
|
|
2540
|
+
url: string()
|
|
2541
|
+
}), object({
|
|
2542
|
+
type: literal("api"),
|
|
2543
|
+
name: string()
|
|
2544
|
+
})])).nullish()
|
|
2545
|
+
}),
|
|
2546
|
+
object({
|
|
2547
|
+
type: literal("open_page"),
|
|
2548
|
+
url: string().nullish()
|
|
2549
|
+
}),
|
|
2550
|
+
object({
|
|
2551
|
+
type: literal("find_in_page"),
|
|
2552
|
+
url: string().nullish(),
|
|
2553
|
+
pattern: string().nullish()
|
|
2554
|
+
})
|
|
2555
|
+
]).nullish()
|
|
2556
|
+
}),
|
|
2557
|
+
object({
|
|
2558
|
+
type: literal("file_search_call"),
|
|
2559
|
+
id: string(),
|
|
2560
|
+
queries: array(string()),
|
|
2561
|
+
results: array(object({
|
|
2562
|
+
attributes: record(string(), union([
|
|
2563
|
+
string(),
|
|
2564
|
+
number$1(),
|
|
2565
|
+
boolean()
|
|
2566
|
+
])),
|
|
2567
|
+
file_id: string(),
|
|
2568
|
+
filename: string(),
|
|
2569
|
+
score: number$1(),
|
|
2570
|
+
text: string()
|
|
2571
|
+
})).nullish()
|
|
2572
|
+
}),
|
|
2573
|
+
object({
|
|
2574
|
+
type: literal("local_shell_call"),
|
|
2575
|
+
id: string(),
|
|
2576
|
+
call_id: string(),
|
|
2577
|
+
action: object({
|
|
2578
|
+
type: literal("exec"),
|
|
2579
|
+
command: array(string()),
|
|
2580
|
+
timeout_ms: number$1().optional(),
|
|
2581
|
+
user: string().optional(),
|
|
2582
|
+
working_directory: string().optional(),
|
|
2583
|
+
env: record(string(), string()).optional()
|
|
2584
|
+
})
|
|
2585
|
+
}),
|
|
2586
|
+
object({
|
|
2587
|
+
type: literal("computer_call"),
|
|
2588
|
+
id: string(),
|
|
2589
|
+
status: literal("completed")
|
|
2590
|
+
}),
|
|
2591
|
+
object({
|
|
2592
|
+
type: literal("mcp_call"),
|
|
2593
|
+
id: string(),
|
|
2594
|
+
status: string(),
|
|
2595
|
+
arguments: string(),
|
|
2596
|
+
name: string(),
|
|
2597
|
+
server_label: string(),
|
|
2598
|
+
output: string().nullish(),
|
|
2599
|
+
error: union([string(), object({
|
|
2600
|
+
type: string().optional(),
|
|
2601
|
+
code: union([number$1(), string()]).optional(),
|
|
2602
|
+
message: string().optional()
|
|
2603
|
+
}).loose()]).nullish(),
|
|
2604
|
+
approval_request_id: string().nullish()
|
|
2605
|
+
}),
|
|
2606
|
+
object({
|
|
2607
|
+
type: literal("mcp_list_tools"),
|
|
2608
|
+
id: string(),
|
|
2609
|
+
server_label: string(),
|
|
2610
|
+
tools: array(object({
|
|
2611
|
+
name: string(),
|
|
2612
|
+
description: string().optional(),
|
|
2613
|
+
input_schema: any(),
|
|
2614
|
+
annotations: record(string(), unknown()).optional()
|
|
2615
|
+
})),
|
|
2616
|
+
error: union([string(), object({
|
|
2617
|
+
type: string().optional(),
|
|
2618
|
+
code: union([number$1(), string()]).optional(),
|
|
2619
|
+
message: string().optional()
|
|
2620
|
+
}).loose()]).optional()
|
|
2621
|
+
}),
|
|
2622
|
+
object({
|
|
2623
|
+
type: literal("mcp_approval_request"),
|
|
2624
|
+
id: string(),
|
|
2625
|
+
server_label: string(),
|
|
2626
|
+
name: string(),
|
|
2627
|
+
arguments: string(),
|
|
2628
|
+
approval_request_id: string().optional()
|
|
2629
|
+
}),
|
|
2630
|
+
object({
|
|
2631
|
+
type: literal("apply_patch_call"),
|
|
2632
|
+
id: string(),
|
|
2633
|
+
call_id: string(),
|
|
2634
|
+
status: _enum(["in_progress", "completed"]),
|
|
2635
|
+
operation: discriminatedUnion("type", [
|
|
2636
|
+
object({
|
|
2637
|
+
type: literal("create_file"),
|
|
2638
|
+
path: string(),
|
|
2639
|
+
diff: string()
|
|
2640
|
+
}),
|
|
2641
|
+
object({
|
|
2642
|
+
type: literal("delete_file"),
|
|
2643
|
+
path: string()
|
|
2644
|
+
}),
|
|
2645
|
+
object({
|
|
2646
|
+
type: literal("update_file"),
|
|
2647
|
+
path: string(),
|
|
2648
|
+
diff: string()
|
|
2649
|
+
})
|
|
2650
|
+
])
|
|
2651
|
+
}),
|
|
2652
|
+
object({
|
|
2653
|
+
type: literal("shell_call"),
|
|
2654
|
+
id: string(),
|
|
2655
|
+
call_id: string(),
|
|
2656
|
+
status: _enum([
|
|
2657
|
+
"in_progress",
|
|
2658
|
+
"completed",
|
|
2659
|
+
"incomplete"
|
|
2660
|
+
]),
|
|
2661
|
+
action: object({ commands: array(string()) })
|
|
2662
|
+
}),
|
|
2663
|
+
object({
|
|
2664
|
+
type: literal("shell_call_output"),
|
|
2665
|
+
id: string(),
|
|
2666
|
+
call_id: string(),
|
|
2667
|
+
status: _enum([
|
|
2668
|
+
"in_progress",
|
|
2669
|
+
"completed",
|
|
2670
|
+
"incomplete"
|
|
2671
|
+
]),
|
|
2672
|
+
output: array(object({
|
|
2673
|
+
stdout: string(),
|
|
2674
|
+
stderr: string(),
|
|
2675
|
+
outcome: discriminatedUnion("type", [object({ type: literal("timeout") }), object({
|
|
2676
|
+
type: literal("exit"),
|
|
2677
|
+
exit_code: number$1()
|
|
2678
|
+
})])
|
|
2679
|
+
}))
|
|
2680
|
+
})
|
|
2681
|
+
])
|
|
2682
|
+
}),
|
|
2683
|
+
object({
|
|
2684
|
+
type: literal("response.function_call_arguments.delta"),
|
|
2685
|
+
item_id: string(),
|
|
2686
|
+
output_index: number$1(),
|
|
2687
|
+
delta: string()
|
|
2688
|
+
}),
|
|
2689
|
+
object({
|
|
2690
|
+
type: literal("response.custom_tool_call_input.delta"),
|
|
2691
|
+
item_id: string(),
|
|
2692
|
+
output_index: number$1(),
|
|
2693
|
+
delta: string()
|
|
2694
|
+
}),
|
|
2695
|
+
object({
|
|
2696
|
+
type: literal("response.image_generation_call.partial_image"),
|
|
2697
|
+
item_id: string(),
|
|
2698
|
+
output_index: number$1(),
|
|
2699
|
+
partial_image_b64: string()
|
|
2700
|
+
}),
|
|
2701
|
+
object({
|
|
2702
|
+
type: literal("response.code_interpreter_call_code.delta"),
|
|
2703
|
+
item_id: string(),
|
|
2704
|
+
output_index: number$1(),
|
|
2705
|
+
delta: string()
|
|
2706
|
+
}),
|
|
2707
|
+
object({
|
|
2708
|
+
type: literal("response.code_interpreter_call_code.done"),
|
|
2709
|
+
item_id: string(),
|
|
2710
|
+
output_index: number$1(),
|
|
2711
|
+
code: string()
|
|
2712
|
+
}),
|
|
2713
|
+
object({
|
|
2714
|
+
type: literal("response.output_text.annotation.added"),
|
|
2715
|
+
annotation: discriminatedUnion("type", [
|
|
2716
|
+
object({
|
|
2717
|
+
type: literal("url_citation"),
|
|
2718
|
+
start_index: number$1(),
|
|
2719
|
+
end_index: number$1(),
|
|
2720
|
+
url: string(),
|
|
2721
|
+
title: string()
|
|
2722
|
+
}),
|
|
2723
|
+
object({
|
|
2724
|
+
type: literal("file_citation"),
|
|
2725
|
+
file_id: string(),
|
|
2726
|
+
filename: string(),
|
|
2727
|
+
index: number$1()
|
|
2728
|
+
}),
|
|
2729
|
+
object({
|
|
2730
|
+
type: literal("container_file_citation"),
|
|
2731
|
+
container_id: string(),
|
|
2732
|
+
file_id: string(),
|
|
2733
|
+
filename: string(),
|
|
2734
|
+
start_index: number$1(),
|
|
2735
|
+
end_index: number$1()
|
|
2736
|
+
}),
|
|
2737
|
+
object({
|
|
2738
|
+
type: literal("file_path"),
|
|
2739
|
+
file_id: string(),
|
|
2740
|
+
index: number$1()
|
|
2741
|
+
})
|
|
2742
|
+
])
|
|
2743
|
+
}),
|
|
2744
|
+
object({
|
|
2745
|
+
type: literal("response.reasoning_summary_part.added"),
|
|
2746
|
+
item_id: string(),
|
|
2747
|
+
summary_index: number$1()
|
|
2748
|
+
}),
|
|
2749
|
+
object({
|
|
2750
|
+
type: literal("response.reasoning_summary_text.delta"),
|
|
2751
|
+
item_id: string(),
|
|
2752
|
+
summary_index: number$1(),
|
|
2753
|
+
delta: string()
|
|
2754
|
+
}),
|
|
2755
|
+
object({
|
|
2756
|
+
type: literal("response.reasoning_summary_part.done"),
|
|
2757
|
+
item_id: string(),
|
|
2758
|
+
summary_index: number$1()
|
|
2759
|
+
}),
|
|
2760
|
+
object({
|
|
2761
|
+
type: literal("response.apply_patch_call_operation_diff.delta"),
|
|
2762
|
+
item_id: string(),
|
|
2763
|
+
output_index: number$1(),
|
|
2764
|
+
delta: string(),
|
|
2765
|
+
obfuscation: string().nullish()
|
|
2766
|
+
}),
|
|
2767
|
+
object({
|
|
2768
|
+
type: literal("response.apply_patch_call_operation_diff.done"),
|
|
2769
|
+
item_id: string(),
|
|
2770
|
+
output_index: number$1(),
|
|
2771
|
+
diff: string()
|
|
2772
|
+
}),
|
|
2773
|
+
object({
|
|
2774
|
+
type: literal("error"),
|
|
2775
|
+
sequence_number: number$1(),
|
|
2776
|
+
error: object({
|
|
2777
|
+
type: string(),
|
|
2778
|
+
code: string(),
|
|
2779
|
+
message: string(),
|
|
2780
|
+
param: string().nullish()
|
|
2781
|
+
})
|
|
2782
|
+
}),
|
|
2783
|
+
object({ type: string() }).loose().transform((value) => ({
|
|
2784
|
+
type: "unknown_chunk",
|
|
2785
|
+
message: value.type
|
|
2786
|
+
}))
|
|
2787
|
+
])));
|
|
2788
|
+
var openaiResponsesResponseSchema = lazySchema(() => zodSchema(object({
|
|
2789
|
+
id: string().optional(),
|
|
2790
|
+
created_at: number$1().optional(),
|
|
2791
|
+
error: object({
|
|
2792
|
+
message: string(),
|
|
2793
|
+
type: string(),
|
|
2794
|
+
param: string().nullish(),
|
|
2795
|
+
code: string()
|
|
2796
|
+
}).nullish(),
|
|
2797
|
+
model: string().optional(),
|
|
2798
|
+
output: array(discriminatedUnion("type", [
|
|
2799
|
+
object({
|
|
2800
|
+
type: literal("message"),
|
|
2801
|
+
role: literal("assistant"),
|
|
2802
|
+
id: string(),
|
|
2803
|
+
phase: _enum(["commentary", "final_answer"]).nullish(),
|
|
2804
|
+
content: array(object({
|
|
2805
|
+
type: literal("output_text"),
|
|
2806
|
+
text: string(),
|
|
2807
|
+
logprobs: array(object({
|
|
2808
|
+
token: string(),
|
|
2809
|
+
logprob: number$1(),
|
|
2810
|
+
top_logprobs: array(object({
|
|
2811
|
+
token: string(),
|
|
2812
|
+
logprob: number$1()
|
|
2813
|
+
}))
|
|
2814
|
+
})).nullish(),
|
|
2815
|
+
annotations: array(discriminatedUnion("type", [
|
|
2816
|
+
object({
|
|
2817
|
+
type: literal("url_citation"),
|
|
2818
|
+
start_index: number$1(),
|
|
2819
|
+
end_index: number$1(),
|
|
2820
|
+
url: string(),
|
|
2821
|
+
title: string()
|
|
2822
|
+
}),
|
|
2823
|
+
object({
|
|
2824
|
+
type: literal("file_citation"),
|
|
2825
|
+
file_id: string(),
|
|
2826
|
+
filename: string(),
|
|
2827
|
+
index: number$1()
|
|
2828
|
+
}),
|
|
2829
|
+
object({
|
|
2830
|
+
type: literal("container_file_citation"),
|
|
2831
|
+
container_id: string(),
|
|
2832
|
+
file_id: string(),
|
|
2833
|
+
filename: string(),
|
|
2834
|
+
start_index: number$1(),
|
|
2835
|
+
end_index: number$1()
|
|
2836
|
+
}),
|
|
2837
|
+
object({
|
|
2838
|
+
type: literal("file_path"),
|
|
2839
|
+
file_id: string(),
|
|
2840
|
+
index: number$1()
|
|
2841
|
+
})
|
|
2842
|
+
]))
|
|
2843
|
+
}))
|
|
2844
|
+
}),
|
|
2845
|
+
object({
|
|
2846
|
+
type: literal("web_search_call"),
|
|
2847
|
+
id: string(),
|
|
2848
|
+
status: string(),
|
|
2849
|
+
action: discriminatedUnion("type", [
|
|
2850
|
+
object({
|
|
2851
|
+
type: literal("search"),
|
|
2852
|
+
query: string().nullish(),
|
|
2853
|
+
sources: array(discriminatedUnion("type", [object({
|
|
2854
|
+
type: literal("url"),
|
|
2855
|
+
url: string()
|
|
2856
|
+
}), object({
|
|
2857
|
+
type: literal("api"),
|
|
2858
|
+
name: string()
|
|
2859
|
+
})])).nullish()
|
|
2860
|
+
}),
|
|
2861
|
+
object({
|
|
2862
|
+
type: literal("open_page"),
|
|
2863
|
+
url: string().nullish()
|
|
2864
|
+
}),
|
|
2865
|
+
object({
|
|
2866
|
+
type: literal("find_in_page"),
|
|
2867
|
+
url: string().nullish(),
|
|
2868
|
+
pattern: string().nullish()
|
|
2869
|
+
})
|
|
2870
|
+
]).nullish()
|
|
2871
|
+
}),
|
|
2872
|
+
object({
|
|
2873
|
+
type: literal("file_search_call"),
|
|
2874
|
+
id: string(),
|
|
2875
|
+
queries: array(string()),
|
|
2876
|
+
results: array(object({
|
|
2877
|
+
attributes: record(string(), union([
|
|
2878
|
+
string(),
|
|
2879
|
+
number$1(),
|
|
2880
|
+
boolean()
|
|
2881
|
+
])),
|
|
2882
|
+
file_id: string(),
|
|
2883
|
+
filename: string(),
|
|
2884
|
+
score: number$1(),
|
|
2885
|
+
text: string()
|
|
2886
|
+
})).nullish()
|
|
2887
|
+
}),
|
|
2888
|
+
object({
|
|
2889
|
+
type: literal("code_interpreter_call"),
|
|
2890
|
+
id: string(),
|
|
2891
|
+
code: string().nullable(),
|
|
2892
|
+
container_id: string(),
|
|
2893
|
+
outputs: array(discriminatedUnion("type", [object({
|
|
2894
|
+
type: literal("logs"),
|
|
2895
|
+
logs: string()
|
|
2896
|
+
}), object({
|
|
2897
|
+
type: literal("image"),
|
|
2898
|
+
url: string()
|
|
2899
|
+
})])).nullable()
|
|
2900
|
+
}),
|
|
2901
|
+
object({
|
|
2902
|
+
type: literal("image_generation_call"),
|
|
2903
|
+
id: string(),
|
|
2904
|
+
result: string()
|
|
2905
|
+
}),
|
|
2906
|
+
object({
|
|
2907
|
+
type: literal("local_shell_call"),
|
|
2908
|
+
id: string(),
|
|
2909
|
+
call_id: string(),
|
|
2910
|
+
action: object({
|
|
2911
|
+
type: literal("exec"),
|
|
2912
|
+
command: array(string()),
|
|
2913
|
+
timeout_ms: number$1().optional(),
|
|
2914
|
+
user: string().optional(),
|
|
2915
|
+
working_directory: string().optional(),
|
|
2916
|
+
env: record(string(), string()).optional()
|
|
2917
|
+
})
|
|
2918
|
+
}),
|
|
2919
|
+
object({
|
|
2920
|
+
type: literal("function_call"),
|
|
2921
|
+
call_id: string(),
|
|
2922
|
+
name: string(),
|
|
2923
|
+
arguments: string(),
|
|
2924
|
+
id: string()
|
|
2925
|
+
}),
|
|
2926
|
+
object({
|
|
2927
|
+
type: literal("custom_tool_call"),
|
|
2928
|
+
call_id: string(),
|
|
2929
|
+
name: string(),
|
|
2930
|
+
input: string(),
|
|
2931
|
+
id: string()
|
|
2932
|
+
}),
|
|
2933
|
+
object({
|
|
2934
|
+
type: literal("computer_call"),
|
|
2935
|
+
id: string(),
|
|
2936
|
+
status: string().optional()
|
|
2937
|
+
}),
|
|
2938
|
+
object({
|
|
2939
|
+
type: literal("reasoning"),
|
|
2940
|
+
id: string(),
|
|
2941
|
+
encrypted_content: string().nullish(),
|
|
2942
|
+
summary: array(object({
|
|
2943
|
+
type: literal("summary_text"),
|
|
2944
|
+
text: string()
|
|
2945
|
+
}))
|
|
2946
|
+
}),
|
|
2947
|
+
object({
|
|
2948
|
+
type: literal("mcp_call"),
|
|
2949
|
+
id: string(),
|
|
2950
|
+
status: string(),
|
|
2951
|
+
arguments: string(),
|
|
2952
|
+
name: string(),
|
|
2953
|
+
server_label: string(),
|
|
2954
|
+
output: string().nullish(),
|
|
2955
|
+
error: union([string(), object({
|
|
2956
|
+
type: string().optional(),
|
|
2957
|
+
code: union([number$1(), string()]).optional(),
|
|
2958
|
+
message: string().optional()
|
|
2959
|
+
}).loose()]).nullish(),
|
|
2960
|
+
approval_request_id: string().nullish()
|
|
2961
|
+
}),
|
|
2962
|
+
object({
|
|
2963
|
+
type: literal("mcp_list_tools"),
|
|
2964
|
+
id: string(),
|
|
2965
|
+
server_label: string(),
|
|
2966
|
+
tools: array(object({
|
|
2967
|
+
name: string(),
|
|
2968
|
+
description: string().optional(),
|
|
2969
|
+
input_schema: any(),
|
|
2970
|
+
annotations: record(string(), unknown()).optional()
|
|
2971
|
+
})),
|
|
2972
|
+
error: union([string(), object({
|
|
2973
|
+
type: string().optional(),
|
|
2974
|
+
code: union([number$1(), string()]).optional(),
|
|
2975
|
+
message: string().optional()
|
|
2976
|
+
}).loose()]).optional()
|
|
2977
|
+
}),
|
|
2978
|
+
object({
|
|
2979
|
+
type: literal("mcp_approval_request"),
|
|
2980
|
+
id: string(),
|
|
2981
|
+
server_label: string(),
|
|
2982
|
+
name: string(),
|
|
2983
|
+
arguments: string(),
|
|
2984
|
+
approval_request_id: string().optional()
|
|
2985
|
+
}),
|
|
2986
|
+
object({
|
|
2987
|
+
type: literal("apply_patch_call"),
|
|
2988
|
+
id: string(),
|
|
2989
|
+
call_id: string(),
|
|
2990
|
+
status: _enum(["in_progress", "completed"]),
|
|
2991
|
+
operation: discriminatedUnion("type", [
|
|
2992
|
+
object({
|
|
2993
|
+
type: literal("create_file"),
|
|
2994
|
+
path: string(),
|
|
2995
|
+
diff: string()
|
|
2996
|
+
}),
|
|
2997
|
+
object({
|
|
2998
|
+
type: literal("delete_file"),
|
|
2999
|
+
path: string()
|
|
3000
|
+
}),
|
|
3001
|
+
object({
|
|
3002
|
+
type: literal("update_file"),
|
|
3003
|
+
path: string(),
|
|
3004
|
+
diff: string()
|
|
3005
|
+
})
|
|
3006
|
+
])
|
|
3007
|
+
}),
|
|
3008
|
+
object({
|
|
3009
|
+
type: literal("shell_call"),
|
|
3010
|
+
id: string(),
|
|
3011
|
+
call_id: string(),
|
|
3012
|
+
status: _enum([
|
|
3013
|
+
"in_progress",
|
|
3014
|
+
"completed",
|
|
3015
|
+
"incomplete"
|
|
3016
|
+
]),
|
|
3017
|
+
action: object({ commands: array(string()) })
|
|
3018
|
+
}),
|
|
3019
|
+
object({
|
|
3020
|
+
type: literal("shell_call_output"),
|
|
3021
|
+
id: string(),
|
|
3022
|
+
call_id: string(),
|
|
3023
|
+
status: _enum([
|
|
3024
|
+
"in_progress",
|
|
3025
|
+
"completed",
|
|
3026
|
+
"incomplete"
|
|
3027
|
+
]),
|
|
3028
|
+
output: array(object({
|
|
3029
|
+
stdout: string(),
|
|
3030
|
+
stderr: string(),
|
|
3031
|
+
outcome: discriminatedUnion("type", [object({ type: literal("timeout") }), object({
|
|
3032
|
+
type: literal("exit"),
|
|
3033
|
+
exit_code: number$1()
|
|
3034
|
+
})])
|
|
3035
|
+
}))
|
|
3036
|
+
})
|
|
3037
|
+
])).optional(),
|
|
3038
|
+
service_tier: string().nullish(),
|
|
3039
|
+
incomplete_details: object({ reason: string() }).nullish(),
|
|
3040
|
+
usage: object({
|
|
3041
|
+
input_tokens: number$1(),
|
|
3042
|
+
input_tokens_details: object({ cached_tokens: number$1().nullish() }).nullish(),
|
|
3043
|
+
output_tokens: number$1(),
|
|
3044
|
+
output_tokens_details: object({ reasoning_tokens: number$1().nullish() }).nullish()
|
|
3045
|
+
}).optional()
|
|
3046
|
+
})));
|
|
3047
|
+
var TOP_LOGPROBS_MAX = 20;
|
|
3048
|
+
var openaiLanguageModelResponsesOptionsSchema = lazySchema(() => zodSchema(object({
|
|
3049
|
+
conversation: string().nullish(),
|
|
3050
|
+
include: array(_enum([
|
|
3051
|
+
"reasoning.encrypted_content",
|
|
3052
|
+
"file_search_call.results",
|
|
3053
|
+
"message.output_text.logprobs"
|
|
3054
|
+
])).nullish(),
|
|
3055
|
+
instructions: string().nullish(),
|
|
3056
|
+
logprobs: union([boolean(), number$1().min(1).max(TOP_LOGPROBS_MAX)]).optional(),
|
|
3057
|
+
maxToolCalls: number$1().nullish(),
|
|
3058
|
+
metadata: any().nullish(),
|
|
3059
|
+
parallelToolCalls: boolean().nullish(),
|
|
3060
|
+
previousResponseId: string().nullish(),
|
|
3061
|
+
promptCacheKey: string().nullish(),
|
|
3062
|
+
promptCacheRetention: _enum(["in_memory", "24h"]).nullish(),
|
|
3063
|
+
reasoningEffort: string().nullish(),
|
|
3064
|
+
reasoningSummary: string().nullish(),
|
|
3065
|
+
safetyIdentifier: string().nullish(),
|
|
3066
|
+
serviceTier: _enum([
|
|
3067
|
+
"auto",
|
|
3068
|
+
"flex",
|
|
3069
|
+
"priority",
|
|
3070
|
+
"default"
|
|
3071
|
+
]).nullish(),
|
|
3072
|
+
store: boolean().nullish(),
|
|
3073
|
+
strictJsonSchema: boolean().nullish(),
|
|
3074
|
+
textVerbosity: _enum([
|
|
3075
|
+
"low",
|
|
3076
|
+
"medium",
|
|
3077
|
+
"high"
|
|
3078
|
+
]).nullish(),
|
|
3079
|
+
truncation: _enum(["auto", "disabled"]).nullish(),
|
|
3080
|
+
user: string().nullish(),
|
|
3081
|
+
systemMessageMode: _enum([
|
|
3082
|
+
"system",
|
|
3083
|
+
"developer",
|
|
3084
|
+
"remove"
|
|
3085
|
+
]).optional(),
|
|
3086
|
+
forceReasoning: boolean().optional()
|
|
3087
|
+
})));
|
|
3088
|
+
async function prepareResponsesTools({ tools, toolChoice, toolNameMapping, customProviderToolNames }) {
|
|
3089
|
+
var _a;
|
|
3090
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
3091
|
+
const toolWarnings = [];
|
|
3092
|
+
if (tools == null) return {
|
|
3093
|
+
tools: void 0,
|
|
3094
|
+
toolChoice: void 0,
|
|
3095
|
+
toolWarnings
|
|
3096
|
+
};
|
|
3097
|
+
const openaiTools2 = [];
|
|
3098
|
+
const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
|
|
3099
|
+
for (const tool of tools) switch (tool.type) {
|
|
3100
|
+
case "function":
|
|
3101
|
+
openaiTools2.push({
|
|
3102
|
+
type: "function",
|
|
3103
|
+
name: tool.name,
|
|
3104
|
+
description: tool.description,
|
|
3105
|
+
parameters: tool.inputSchema,
|
|
3106
|
+
...tool.strict != null ? { strict: tool.strict } : {}
|
|
3107
|
+
});
|
|
3108
|
+
break;
|
|
3109
|
+
case "provider":
|
|
3110
|
+
switch (tool.id) {
|
|
3111
|
+
case "openai.file_search": {
|
|
3112
|
+
const args = await validateTypes({
|
|
3113
|
+
value: tool.args,
|
|
3114
|
+
schema: fileSearchArgsSchema
|
|
3115
|
+
});
|
|
3116
|
+
openaiTools2.push({
|
|
3117
|
+
type: "file_search",
|
|
3118
|
+
vector_store_ids: args.vectorStoreIds,
|
|
3119
|
+
max_num_results: args.maxNumResults,
|
|
3120
|
+
ranking_options: args.ranking ? {
|
|
3121
|
+
ranker: args.ranking.ranker,
|
|
3122
|
+
score_threshold: args.ranking.scoreThreshold
|
|
3123
|
+
} : void 0,
|
|
3124
|
+
filters: args.filters
|
|
3125
|
+
});
|
|
3126
|
+
break;
|
|
3127
|
+
}
|
|
3128
|
+
case "openai.local_shell":
|
|
3129
|
+
openaiTools2.push({ type: "local_shell" });
|
|
3130
|
+
break;
|
|
3131
|
+
case "openai.shell": {
|
|
3132
|
+
const args = await validateTypes({
|
|
3133
|
+
value: tool.args,
|
|
3134
|
+
schema: shellArgsSchema
|
|
3135
|
+
});
|
|
3136
|
+
openaiTools2.push({
|
|
3137
|
+
type: "shell",
|
|
3138
|
+
...args.environment && { environment: mapShellEnvironment(args.environment) }
|
|
3139
|
+
});
|
|
3140
|
+
break;
|
|
3141
|
+
}
|
|
3142
|
+
case "openai.apply_patch":
|
|
3143
|
+
openaiTools2.push({ type: "apply_patch" });
|
|
3144
|
+
break;
|
|
3145
|
+
case "openai.web_search_preview": {
|
|
3146
|
+
const args = await validateTypes({
|
|
3147
|
+
value: tool.args,
|
|
3148
|
+
schema: webSearchPreviewArgsSchema
|
|
3149
|
+
});
|
|
3150
|
+
openaiTools2.push({
|
|
3151
|
+
type: "web_search_preview",
|
|
3152
|
+
search_context_size: args.searchContextSize,
|
|
3153
|
+
user_location: args.userLocation
|
|
3154
|
+
});
|
|
3155
|
+
break;
|
|
3156
|
+
}
|
|
3157
|
+
case "openai.web_search": {
|
|
3158
|
+
const args = await validateTypes({
|
|
3159
|
+
value: tool.args,
|
|
3160
|
+
schema: webSearchArgsSchema
|
|
3161
|
+
});
|
|
3162
|
+
openaiTools2.push({
|
|
3163
|
+
type: "web_search",
|
|
3164
|
+
filters: args.filters != null ? { allowed_domains: args.filters.allowedDomains } : void 0,
|
|
3165
|
+
external_web_access: args.externalWebAccess,
|
|
3166
|
+
search_context_size: args.searchContextSize,
|
|
3167
|
+
user_location: args.userLocation
|
|
3168
|
+
});
|
|
3169
|
+
break;
|
|
3170
|
+
}
|
|
3171
|
+
case "openai.code_interpreter": {
|
|
3172
|
+
const args = await validateTypes({
|
|
3173
|
+
value: tool.args,
|
|
3174
|
+
schema: codeInterpreterArgsSchema
|
|
3175
|
+
});
|
|
3176
|
+
openaiTools2.push({
|
|
3177
|
+
type: "code_interpreter",
|
|
3178
|
+
container: args.container == null ? {
|
|
3179
|
+
type: "auto",
|
|
3180
|
+
file_ids: void 0
|
|
3181
|
+
} : typeof args.container === "string" ? args.container : {
|
|
3182
|
+
type: "auto",
|
|
3183
|
+
file_ids: args.container.fileIds
|
|
3184
|
+
}
|
|
3185
|
+
});
|
|
3186
|
+
break;
|
|
3187
|
+
}
|
|
3188
|
+
case "openai.image_generation": {
|
|
3189
|
+
const args = await validateTypes({
|
|
3190
|
+
value: tool.args,
|
|
3191
|
+
schema: imageGenerationArgsSchema
|
|
3192
|
+
});
|
|
3193
|
+
openaiTools2.push({
|
|
3194
|
+
type: "image_generation",
|
|
3195
|
+
background: args.background,
|
|
3196
|
+
input_fidelity: args.inputFidelity,
|
|
3197
|
+
input_image_mask: args.inputImageMask ? {
|
|
3198
|
+
file_id: args.inputImageMask.fileId,
|
|
3199
|
+
image_url: args.inputImageMask.imageUrl
|
|
3200
|
+
} : void 0,
|
|
3201
|
+
model: args.model,
|
|
3202
|
+
moderation: args.moderation,
|
|
3203
|
+
partial_images: args.partialImages,
|
|
3204
|
+
quality: args.quality,
|
|
3205
|
+
output_compression: args.outputCompression,
|
|
3206
|
+
output_format: args.outputFormat,
|
|
3207
|
+
size: args.size
|
|
3208
|
+
});
|
|
3209
|
+
break;
|
|
3210
|
+
}
|
|
3211
|
+
case "openai.mcp": {
|
|
3212
|
+
const args = await validateTypes({
|
|
3213
|
+
value: tool.args,
|
|
3214
|
+
schema: mcpArgsSchema
|
|
3215
|
+
});
|
|
3216
|
+
const mapApprovalFilter = (filter) => ({ tool_names: filter.toolNames });
|
|
3217
|
+
const requireApproval = args.requireApproval;
|
|
3218
|
+
const requireApprovalParam = requireApproval == null ? void 0 : typeof requireApproval === "string" ? requireApproval : requireApproval.never != null ? { never: mapApprovalFilter(requireApproval.never) } : void 0;
|
|
3219
|
+
openaiTools2.push({
|
|
3220
|
+
type: "mcp",
|
|
3221
|
+
server_label: args.serverLabel,
|
|
3222
|
+
allowed_tools: Array.isArray(args.allowedTools) ? args.allowedTools : args.allowedTools ? {
|
|
3223
|
+
read_only: args.allowedTools.readOnly,
|
|
3224
|
+
tool_names: args.allowedTools.toolNames
|
|
3225
|
+
} : void 0,
|
|
3226
|
+
authorization: args.authorization,
|
|
3227
|
+
connector_id: args.connectorId,
|
|
3228
|
+
headers: args.headers,
|
|
3229
|
+
require_approval: requireApprovalParam != null ? requireApprovalParam : "never",
|
|
3230
|
+
server_description: args.serverDescription,
|
|
3231
|
+
server_url: args.serverUrl
|
|
3232
|
+
});
|
|
3233
|
+
break;
|
|
3234
|
+
}
|
|
3235
|
+
case "openai.custom": {
|
|
3236
|
+
const args = await validateTypes({
|
|
3237
|
+
value: tool.args,
|
|
3238
|
+
schema: customArgsSchema
|
|
3239
|
+
});
|
|
3240
|
+
openaiTools2.push({
|
|
3241
|
+
type: "custom",
|
|
3242
|
+
name: args.name,
|
|
3243
|
+
description: args.description,
|
|
3244
|
+
format: args.format
|
|
3245
|
+
});
|
|
3246
|
+
resolvedCustomProviderToolNames.add(args.name);
|
|
3247
|
+
break;
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
break;
|
|
3251
|
+
default:
|
|
3252
|
+
toolWarnings.push({
|
|
3253
|
+
type: "unsupported",
|
|
3254
|
+
feature: `function tool ${tool}`
|
|
3255
|
+
});
|
|
3256
|
+
break;
|
|
3257
|
+
}
|
|
3258
|
+
if (toolChoice == null) return {
|
|
3259
|
+
tools: openaiTools2,
|
|
3260
|
+
toolChoice: void 0,
|
|
3261
|
+
toolWarnings
|
|
3262
|
+
};
|
|
3263
|
+
const type = toolChoice.type;
|
|
3264
|
+
switch (type) {
|
|
3265
|
+
case "auto":
|
|
3266
|
+
case "none":
|
|
3267
|
+
case "required": return {
|
|
3268
|
+
tools: openaiTools2,
|
|
3269
|
+
toolChoice: type,
|
|
3270
|
+
toolWarnings
|
|
3271
|
+
};
|
|
3272
|
+
case "tool": {
|
|
3273
|
+
const resolvedToolName = (_a = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _a : toolChoice.toolName;
|
|
3274
|
+
return {
|
|
3275
|
+
tools: openaiTools2,
|
|
3276
|
+
toolChoice: resolvedToolName === "code_interpreter" || resolvedToolName === "file_search" || resolvedToolName === "image_generation" || resolvedToolName === "web_search_preview" || resolvedToolName === "web_search" || resolvedToolName === "mcp" || resolvedToolName === "apply_patch" ? { type: resolvedToolName } : resolvedCustomProviderToolNames.has(resolvedToolName) ? {
|
|
3277
|
+
type: "custom",
|
|
3278
|
+
name: resolvedToolName
|
|
3279
|
+
} : {
|
|
3280
|
+
type: "function",
|
|
3281
|
+
name: resolvedToolName
|
|
3282
|
+
},
|
|
3283
|
+
toolWarnings
|
|
3284
|
+
};
|
|
3285
|
+
}
|
|
3286
|
+
default: throw new UnsupportedFunctionalityError({ functionality: `tool choice type: ${type}` });
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
function mapShellEnvironment(environment) {
|
|
3290
|
+
if (environment.type === "containerReference") return {
|
|
3291
|
+
type: "container_reference",
|
|
3292
|
+
container_id: environment.containerId
|
|
3293
|
+
};
|
|
3294
|
+
if (environment.type === "containerAuto") {
|
|
3295
|
+
const env2 = environment;
|
|
3296
|
+
return {
|
|
3297
|
+
type: "container_auto",
|
|
3298
|
+
file_ids: env2.fileIds,
|
|
3299
|
+
memory_limit: env2.memoryLimit,
|
|
3300
|
+
network_policy: env2.networkPolicy == null ? void 0 : env2.networkPolicy.type === "disabled" ? { type: "disabled" } : {
|
|
3301
|
+
type: "allowlist",
|
|
3302
|
+
allowed_domains: env2.networkPolicy.allowedDomains,
|
|
3303
|
+
domain_secrets: env2.networkPolicy.domainSecrets
|
|
3304
|
+
},
|
|
3305
|
+
skills: mapShellSkills(env2.skills)
|
|
3306
|
+
};
|
|
3307
|
+
}
|
|
3308
|
+
return {
|
|
3309
|
+
type: "local",
|
|
3310
|
+
skills: environment.skills
|
|
3311
|
+
};
|
|
3312
|
+
}
|
|
3313
|
+
function mapShellSkills(skills) {
|
|
3314
|
+
return skills == null ? void 0 : skills.map((skill) => skill.type === "skillReference" ? {
|
|
3315
|
+
type: "skill_reference",
|
|
3316
|
+
skill_id: skill.skillId,
|
|
3317
|
+
version: skill.version
|
|
3318
|
+
} : {
|
|
3319
|
+
type: "inline",
|
|
3320
|
+
name: skill.name,
|
|
3321
|
+
description: skill.description,
|
|
3322
|
+
source: {
|
|
3323
|
+
type: "base64",
|
|
3324
|
+
media_type: skill.source.mediaType,
|
|
3325
|
+
data: skill.source.data
|
|
3326
|
+
}
|
|
3327
|
+
});
|
|
3328
|
+
}
|
|
3329
|
+
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
3330
|
+
var _a, _b;
|
|
3331
|
+
const mapping = {};
|
|
3332
|
+
for (const message of prompt) {
|
|
3333
|
+
if (message.role !== "assistant") continue;
|
|
3334
|
+
for (const part of message.content) {
|
|
3335
|
+
if (part.type !== "tool-call") continue;
|
|
3336
|
+
const approvalRequestId = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.approvalRequestId;
|
|
3337
|
+
if (approvalRequestId != null) mapping[approvalRequestId] = part.toolCallId;
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
return mapping;
|
|
3341
|
+
}
|
|
3342
|
+
var OpenAIResponsesLanguageModel = class {
|
|
3343
|
+
constructor(modelId, config) {
|
|
3344
|
+
this.specificationVersion = "v3";
|
|
3345
|
+
this.supportedUrls = {
|
|
3346
|
+
"image/*": [/^https?:\/\/.*$/],
|
|
3347
|
+
"application/pdf": [/^https?:\/\/.*$/]
|
|
3348
|
+
};
|
|
3349
|
+
this.modelId = modelId;
|
|
3350
|
+
this.config = config;
|
|
3351
|
+
}
|
|
3352
|
+
get provider() {
|
|
3353
|
+
return this.config.provider;
|
|
3354
|
+
}
|
|
3355
|
+
async getArgs({ maxOutputTokens, temperature, stopSequences, topP, topK, presencePenalty, frequencyPenalty, seed, prompt, providerOptions, tools, toolChoice, responseFormat }) {
|
|
3356
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
3357
|
+
const warnings = [];
|
|
3358
|
+
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
3359
|
+
if (topK != null) warnings.push({
|
|
3360
|
+
type: "unsupported",
|
|
3361
|
+
feature: "topK"
|
|
3362
|
+
});
|
|
3363
|
+
if (seed != null) warnings.push({
|
|
3364
|
+
type: "unsupported",
|
|
3365
|
+
feature: "seed"
|
|
3366
|
+
});
|
|
3367
|
+
if (presencePenalty != null) warnings.push({
|
|
3368
|
+
type: "unsupported",
|
|
3369
|
+
feature: "presencePenalty"
|
|
3370
|
+
});
|
|
3371
|
+
if (frequencyPenalty != null) warnings.push({
|
|
3372
|
+
type: "unsupported",
|
|
3373
|
+
feature: "frequencyPenalty"
|
|
3374
|
+
});
|
|
3375
|
+
if (stopSequences != null) warnings.push({
|
|
3376
|
+
type: "unsupported",
|
|
3377
|
+
feature: "stopSequences"
|
|
3378
|
+
});
|
|
3379
|
+
const providerOptionsName = this.config.provider.includes("azure") ? "azure" : "openai";
|
|
3380
|
+
let openaiOptions = await parseProviderOptions({
|
|
3381
|
+
provider: providerOptionsName,
|
|
3382
|
+
providerOptions,
|
|
3383
|
+
schema: openaiLanguageModelResponsesOptionsSchema
|
|
3384
|
+
});
|
|
3385
|
+
if (openaiOptions == null && providerOptionsName !== "openai") openaiOptions = await parseProviderOptions({
|
|
3386
|
+
provider: "openai",
|
|
3387
|
+
providerOptions,
|
|
3388
|
+
schema: openaiLanguageModelResponsesOptionsSchema
|
|
3389
|
+
});
|
|
3390
|
+
const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
|
|
3391
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) warnings.push({
|
|
3392
|
+
type: "unsupported",
|
|
3393
|
+
feature: "conversation",
|
|
3394
|
+
details: "conversation and previousResponseId cannot be used together"
|
|
3395
|
+
});
|
|
3396
|
+
const toolNameMapping = createToolNameMapping({
|
|
3397
|
+
tools,
|
|
3398
|
+
providerToolNames: {
|
|
3399
|
+
"openai.code_interpreter": "code_interpreter",
|
|
3400
|
+
"openai.file_search": "file_search",
|
|
3401
|
+
"openai.image_generation": "image_generation",
|
|
3402
|
+
"openai.local_shell": "local_shell",
|
|
3403
|
+
"openai.shell": "shell",
|
|
3404
|
+
"openai.web_search": "web_search",
|
|
3405
|
+
"openai.web_search_preview": "web_search_preview",
|
|
3406
|
+
"openai.mcp": "mcp",
|
|
3407
|
+
"openai.apply_patch": "apply_patch"
|
|
3408
|
+
},
|
|
3409
|
+
resolveProviderToolName: (tool) => tool.id === "openai.custom" ? tool.args.name : void 0
|
|
3410
|
+
});
|
|
3411
|
+
const customProviderToolNames = /* @__PURE__ */ new Set();
|
|
3412
|
+
const { tools: openaiTools2, toolChoice: openaiToolChoice, toolWarnings } = await prepareResponsesTools({
|
|
3413
|
+
tools,
|
|
3414
|
+
toolChoice,
|
|
3415
|
+
toolNameMapping,
|
|
3416
|
+
customProviderToolNames
|
|
3417
|
+
});
|
|
3418
|
+
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
3419
|
+
prompt,
|
|
3420
|
+
toolNameMapping,
|
|
3421
|
+
systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
|
|
3422
|
+
providerOptionsName,
|
|
3423
|
+
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
3424
|
+
store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
|
|
3425
|
+
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
3426
|
+
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
3427
|
+
hasShellTool: hasOpenAITool("openai.shell"),
|
|
3428
|
+
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
3429
|
+
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
3430
|
+
});
|
|
3431
|
+
warnings.push(...inputWarnings);
|
|
3432
|
+
const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
|
|
3433
|
+
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
3434
|
+
function addInclude(key) {
|
|
3435
|
+
if (include == null) include = [key];
|
|
3436
|
+
else if (!include.includes(key)) include = [...include, key];
|
|
3437
|
+
}
|
|
3438
|
+
function hasOpenAITool(id) {
|
|
3439
|
+
return (tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) != null;
|
|
3440
|
+
}
|
|
3441
|
+
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
|
|
3442
|
+
if (topLogprobs) addInclude("message.output_text.logprobs");
|
|
3443
|
+
const webSearchToolName = (_e = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview"))) == null ? void 0 : _e.name;
|
|
3444
|
+
if (webSearchToolName) addInclude("web_search_call.action.sources");
|
|
3445
|
+
if (hasOpenAITool("openai.code_interpreter")) addInclude("code_interpreter_call.outputs");
|
|
3446
|
+
const store = openaiOptions == null ? void 0 : openaiOptions.store;
|
|
3447
|
+
if (store === false && isReasoningModel) addInclude("reasoning.encrypted_content");
|
|
3448
|
+
const baseArgs = {
|
|
3449
|
+
model: this.modelId,
|
|
3450
|
+
input,
|
|
3451
|
+
temperature,
|
|
3452
|
+
top_p: topP,
|
|
3453
|
+
max_output_tokens: maxOutputTokens,
|
|
3454
|
+
...((responseFormat == null ? void 0 : responseFormat.type) === "json" || (openaiOptions == null ? void 0 : openaiOptions.textVerbosity)) && { text: {
|
|
3455
|
+
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && { format: responseFormat.schema != null ? {
|
|
3456
|
+
type: "json_schema",
|
|
3457
|
+
strict: strictJsonSchema,
|
|
3458
|
+
name: (_f = responseFormat.name) != null ? _f : "response",
|
|
3459
|
+
description: responseFormat.description,
|
|
3460
|
+
schema: responseFormat.schema
|
|
3461
|
+
} : { type: "json_object" } },
|
|
3462
|
+
...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && { verbosity: openaiOptions.textVerbosity }
|
|
3463
|
+
} },
|
|
3464
|
+
conversation: openaiOptions == null ? void 0 : openaiOptions.conversation,
|
|
3465
|
+
max_tool_calls: openaiOptions == null ? void 0 : openaiOptions.maxToolCalls,
|
|
3466
|
+
metadata: openaiOptions == null ? void 0 : openaiOptions.metadata,
|
|
3467
|
+
parallel_tool_calls: openaiOptions == null ? void 0 : openaiOptions.parallelToolCalls,
|
|
3468
|
+
previous_response_id: openaiOptions == null ? void 0 : openaiOptions.previousResponseId,
|
|
3469
|
+
store,
|
|
3470
|
+
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
3471
|
+
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
3472
|
+
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
3473
|
+
include,
|
|
3474
|
+
prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
|
|
3475
|
+
prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
|
|
3476
|
+
safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
|
|
3477
|
+
top_logprobs: topLogprobs,
|
|
3478
|
+
truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
|
|
3479
|
+
...isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && { reasoning: {
|
|
3480
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && { effort: openaiOptions.reasoningEffort },
|
|
3481
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && { summary: openaiOptions.reasoningSummary }
|
|
3482
|
+
} }
|
|
3483
|
+
};
|
|
3484
|
+
if (isReasoningModel) {
|
|
3485
|
+
if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
|
|
3486
|
+
if (baseArgs.temperature != null) {
|
|
3487
|
+
baseArgs.temperature = void 0;
|
|
3488
|
+
warnings.push({
|
|
3489
|
+
type: "unsupported",
|
|
3490
|
+
feature: "temperature",
|
|
3491
|
+
details: "temperature is not supported for reasoning models"
|
|
3492
|
+
});
|
|
3493
|
+
}
|
|
3494
|
+
if (baseArgs.top_p != null) {
|
|
3495
|
+
baseArgs.top_p = void 0;
|
|
3496
|
+
warnings.push({
|
|
3497
|
+
type: "unsupported",
|
|
3498
|
+
feature: "topP",
|
|
3499
|
+
details: "topP is not supported for reasoning models"
|
|
3500
|
+
});
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
} else {
|
|
3504
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) warnings.push({
|
|
3505
|
+
type: "unsupported",
|
|
3506
|
+
feature: "reasoningEffort",
|
|
3507
|
+
details: "reasoningEffort is not supported for non-reasoning models"
|
|
3508
|
+
});
|
|
3509
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) warnings.push({
|
|
3510
|
+
type: "unsupported",
|
|
3511
|
+
feature: "reasoningSummary",
|
|
3512
|
+
details: "reasoningSummary is not supported for non-reasoning models"
|
|
3513
|
+
});
|
|
3514
|
+
}
|
|
3515
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
|
|
3516
|
+
warnings.push({
|
|
3517
|
+
type: "unsupported",
|
|
3518
|
+
feature: "serviceTier",
|
|
3519
|
+
details: "flex processing is only available for o3, o4-mini, and gpt-5 models"
|
|
3520
|
+
});
|
|
3521
|
+
delete baseArgs.service_tier;
|
|
3522
|
+
}
|
|
3523
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" && !modelCapabilities.supportsPriorityProcessing) {
|
|
3524
|
+
warnings.push({
|
|
3525
|
+
type: "unsupported",
|
|
3526
|
+
feature: "serviceTier",
|
|
3527
|
+
details: "priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"
|
|
3528
|
+
});
|
|
3529
|
+
delete baseArgs.service_tier;
|
|
3530
|
+
}
|
|
3531
|
+
const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === "openai.shell")) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
|
|
3532
|
+
const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
|
|
3533
|
+
return {
|
|
3534
|
+
webSearchToolName,
|
|
3535
|
+
args: {
|
|
3536
|
+
...baseArgs,
|
|
3537
|
+
tools: openaiTools2,
|
|
3538
|
+
tool_choice: openaiToolChoice
|
|
3539
|
+
},
|
|
3540
|
+
warnings: [...warnings, ...toolWarnings],
|
|
3541
|
+
store,
|
|
3542
|
+
toolNameMapping,
|
|
3543
|
+
providerOptionsName,
|
|
3544
|
+
isShellProviderExecuted
|
|
3545
|
+
};
|
|
3546
|
+
}
|
|
3547
|
+
async doGenerate(options) {
|
|
3548
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
3549
|
+
const { args: body, warnings, webSearchToolName, toolNameMapping, providerOptionsName, isShellProviderExecuted } = await this.getArgs(options);
|
|
3550
|
+
const url = this.config.url({
|
|
3551
|
+
path: "/responses",
|
|
3552
|
+
modelId: this.modelId
|
|
3553
|
+
});
|
|
3554
|
+
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
3555
|
+
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
3556
|
+
url,
|
|
3557
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
3558
|
+
body,
|
|
3559
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
3560
|
+
successfulResponseHandler: createJsonResponseHandler(openaiResponsesResponseSchema),
|
|
3561
|
+
abortSignal: options.abortSignal,
|
|
3562
|
+
fetch: this.config.fetch
|
|
3563
|
+
});
|
|
3564
|
+
if (response.error) throw new APICallError({
|
|
3565
|
+
message: response.error.message,
|
|
3566
|
+
url,
|
|
3567
|
+
requestBodyValues: body,
|
|
3568
|
+
statusCode: 400,
|
|
3569
|
+
responseHeaders,
|
|
3570
|
+
responseBody: rawResponse,
|
|
3571
|
+
isRetryable: false
|
|
3572
|
+
});
|
|
3573
|
+
const content = [];
|
|
3574
|
+
const logprobs = [];
|
|
3575
|
+
let hasFunctionCall = false;
|
|
3576
|
+
for (const part of response.output) switch (part.type) {
|
|
3577
|
+
case "reasoning":
|
|
3578
|
+
if (part.summary.length === 0) part.summary.push({
|
|
3579
|
+
type: "summary_text",
|
|
3580
|
+
text: ""
|
|
3581
|
+
});
|
|
3582
|
+
for (const summary of part.summary) content.push({
|
|
3583
|
+
type: "reasoning",
|
|
3584
|
+
text: summary.text,
|
|
3585
|
+
providerMetadata: { [providerOptionsName]: {
|
|
3586
|
+
itemId: part.id,
|
|
3587
|
+
reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
|
|
3588
|
+
} }
|
|
3589
|
+
});
|
|
3590
|
+
break;
|
|
3591
|
+
case "image_generation_call":
|
|
3592
|
+
content.push({
|
|
3593
|
+
type: "tool-call",
|
|
3594
|
+
toolCallId: part.id,
|
|
3595
|
+
toolName: toolNameMapping.toCustomToolName("image_generation"),
|
|
3596
|
+
input: "{}",
|
|
3597
|
+
providerExecuted: true
|
|
3598
|
+
});
|
|
3599
|
+
content.push({
|
|
3600
|
+
type: "tool-result",
|
|
3601
|
+
toolCallId: part.id,
|
|
3602
|
+
toolName: toolNameMapping.toCustomToolName("image_generation"),
|
|
3603
|
+
result: { result: part.result }
|
|
3604
|
+
});
|
|
3605
|
+
break;
|
|
3606
|
+
case "local_shell_call":
|
|
3607
|
+
content.push({
|
|
3608
|
+
type: "tool-call",
|
|
3609
|
+
toolCallId: part.call_id,
|
|
3610
|
+
toolName: toolNameMapping.toCustomToolName("local_shell"),
|
|
3611
|
+
input: JSON.stringify({ action: part.action }),
|
|
3612
|
+
providerMetadata: { [providerOptionsName]: { itemId: part.id } }
|
|
3613
|
+
});
|
|
3614
|
+
break;
|
|
3615
|
+
case "shell_call":
|
|
3616
|
+
content.push({
|
|
3617
|
+
type: "tool-call",
|
|
3618
|
+
toolCallId: part.call_id,
|
|
3619
|
+
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
3620
|
+
input: JSON.stringify({ action: { commands: part.action.commands } }),
|
|
3621
|
+
...isShellProviderExecuted && { providerExecuted: true },
|
|
3622
|
+
providerMetadata: { [providerOptionsName]: { itemId: part.id } }
|
|
3623
|
+
});
|
|
3624
|
+
break;
|
|
3625
|
+
case "shell_call_output":
|
|
3626
|
+
content.push({
|
|
3627
|
+
type: "tool-result",
|
|
3628
|
+
toolCallId: part.call_id,
|
|
3629
|
+
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
3630
|
+
result: { output: part.output.map((item) => ({
|
|
3631
|
+
stdout: item.stdout,
|
|
3632
|
+
stderr: item.stderr,
|
|
3633
|
+
outcome: item.outcome.type === "exit" ? {
|
|
3634
|
+
type: "exit",
|
|
3635
|
+
exitCode: item.outcome.exit_code
|
|
3636
|
+
} : { type: "timeout" }
|
|
3637
|
+
})) }
|
|
3638
|
+
});
|
|
3639
|
+
break;
|
|
3640
|
+
case "message":
|
|
3641
|
+
for (const contentPart of part.content) {
|
|
3642
|
+
if (((_c = (_b = options.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.logprobs) && contentPart.logprobs) logprobs.push(contentPart.logprobs);
|
|
3643
|
+
const providerMetadata2 = {
|
|
3644
|
+
itemId: part.id,
|
|
3645
|
+
...part.phase != null && { phase: part.phase },
|
|
3646
|
+
...contentPart.annotations.length > 0 && { annotations: contentPart.annotations }
|
|
3647
|
+
};
|
|
3648
|
+
content.push({
|
|
3649
|
+
type: "text",
|
|
3650
|
+
text: contentPart.text,
|
|
3651
|
+
providerMetadata: { [providerOptionsName]: providerMetadata2 }
|
|
3652
|
+
});
|
|
3653
|
+
for (const annotation of contentPart.annotations) if (annotation.type === "url_citation") content.push({
|
|
3654
|
+
type: "source",
|
|
3655
|
+
sourceType: "url",
|
|
3656
|
+
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : generateId(),
|
|
3657
|
+
url: annotation.url,
|
|
3658
|
+
title: annotation.title
|
|
3659
|
+
});
|
|
3660
|
+
else if (annotation.type === "file_citation") content.push({
|
|
3661
|
+
type: "source",
|
|
3662
|
+
sourceType: "document",
|
|
3663
|
+
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId(),
|
|
3664
|
+
mediaType: "text/plain",
|
|
3665
|
+
title: annotation.filename,
|
|
3666
|
+
filename: annotation.filename,
|
|
3667
|
+
providerMetadata: { [providerOptionsName]: {
|
|
3668
|
+
type: annotation.type,
|
|
3669
|
+
fileId: annotation.file_id,
|
|
3670
|
+
index: annotation.index
|
|
3671
|
+
} }
|
|
3672
|
+
});
|
|
3673
|
+
else if (annotation.type === "container_file_citation") content.push({
|
|
3674
|
+
type: "source",
|
|
3675
|
+
sourceType: "document",
|
|
3676
|
+
id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId(),
|
|
3677
|
+
mediaType: "text/plain",
|
|
3678
|
+
title: annotation.filename,
|
|
3679
|
+
filename: annotation.filename,
|
|
3680
|
+
providerMetadata: { [providerOptionsName]: {
|
|
3681
|
+
type: annotation.type,
|
|
3682
|
+
fileId: annotation.file_id,
|
|
3683
|
+
containerId: annotation.container_id
|
|
3684
|
+
} }
|
|
3685
|
+
});
|
|
3686
|
+
else if (annotation.type === "file_path") content.push({
|
|
3687
|
+
type: "source",
|
|
3688
|
+
sourceType: "document",
|
|
3689
|
+
id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId(),
|
|
3690
|
+
mediaType: "application/octet-stream",
|
|
3691
|
+
title: annotation.file_id,
|
|
3692
|
+
filename: annotation.file_id,
|
|
3693
|
+
providerMetadata: { [providerOptionsName]: {
|
|
3694
|
+
type: annotation.type,
|
|
3695
|
+
fileId: annotation.file_id,
|
|
3696
|
+
index: annotation.index
|
|
3697
|
+
} }
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3700
|
+
break;
|
|
3701
|
+
case "function_call":
|
|
3702
|
+
hasFunctionCall = true;
|
|
3703
|
+
content.push({
|
|
3704
|
+
type: "tool-call",
|
|
3705
|
+
toolCallId: part.call_id,
|
|
3706
|
+
toolName: part.name,
|
|
3707
|
+
input: part.arguments,
|
|
3708
|
+
providerMetadata: { [providerOptionsName]: { itemId: part.id } }
|
|
3709
|
+
});
|
|
3710
|
+
break;
|
|
3711
|
+
case "custom_tool_call": {
|
|
3712
|
+
hasFunctionCall = true;
|
|
3713
|
+
const toolName = toolNameMapping.toCustomToolName(part.name);
|
|
3714
|
+
content.push({
|
|
3715
|
+
type: "tool-call",
|
|
3716
|
+
toolCallId: part.call_id,
|
|
3717
|
+
toolName,
|
|
3718
|
+
input: JSON.stringify(part.input),
|
|
3719
|
+
providerMetadata: { [providerOptionsName]: { itemId: part.id } }
|
|
3720
|
+
});
|
|
3721
|
+
break;
|
|
3722
|
+
}
|
|
3723
|
+
case "web_search_call":
|
|
3724
|
+
content.push({
|
|
3725
|
+
type: "tool-call",
|
|
3726
|
+
toolCallId: part.id,
|
|
3727
|
+
toolName: toolNameMapping.toCustomToolName(webSearchToolName != null ? webSearchToolName : "web_search"),
|
|
3728
|
+
input: JSON.stringify({}),
|
|
3729
|
+
providerExecuted: true
|
|
3730
|
+
});
|
|
3731
|
+
content.push({
|
|
3732
|
+
type: "tool-result",
|
|
3733
|
+
toolCallId: part.id,
|
|
3734
|
+
toolName: toolNameMapping.toCustomToolName(webSearchToolName != null ? webSearchToolName : "web_search"),
|
|
3735
|
+
result: mapWebSearchOutput(part.action)
|
|
3736
|
+
});
|
|
3737
|
+
break;
|
|
3738
|
+
case "mcp_call": {
|
|
3739
|
+
const toolCallId = part.approval_request_id != null ? (_p = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _p : part.id : part.id;
|
|
3740
|
+
const toolName = `mcp.${part.name}`;
|
|
3741
|
+
content.push({
|
|
3742
|
+
type: "tool-call",
|
|
3743
|
+
toolCallId,
|
|
3744
|
+
toolName,
|
|
3745
|
+
input: part.arguments,
|
|
3746
|
+
providerExecuted: true,
|
|
3747
|
+
dynamic: true
|
|
3748
|
+
});
|
|
3749
|
+
content.push({
|
|
3750
|
+
type: "tool-result",
|
|
3751
|
+
toolCallId,
|
|
3752
|
+
toolName,
|
|
3753
|
+
result: {
|
|
3754
|
+
type: "call",
|
|
3755
|
+
serverLabel: part.server_label,
|
|
3756
|
+
name: part.name,
|
|
3757
|
+
arguments: part.arguments,
|
|
3758
|
+
...part.output != null ? { output: part.output } : {},
|
|
3759
|
+
...part.error != null ? { error: part.error } : {}
|
|
3760
|
+
},
|
|
3761
|
+
providerMetadata: { [providerOptionsName]: { itemId: part.id } }
|
|
3762
|
+
});
|
|
3763
|
+
break;
|
|
3764
|
+
}
|
|
3765
|
+
case "mcp_list_tools": break;
|
|
3766
|
+
case "mcp_approval_request": {
|
|
3767
|
+
const approvalRequestId = (_q = part.approval_request_id) != null ? _q : part.id;
|
|
3768
|
+
const dummyToolCallId = (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId();
|
|
3769
|
+
const toolName = `mcp.${part.name}`;
|
|
3770
|
+
content.push({
|
|
3771
|
+
type: "tool-call",
|
|
3772
|
+
toolCallId: dummyToolCallId,
|
|
3773
|
+
toolName,
|
|
3774
|
+
input: part.arguments,
|
|
3775
|
+
providerExecuted: true,
|
|
3776
|
+
dynamic: true
|
|
3777
|
+
});
|
|
3778
|
+
content.push({
|
|
3779
|
+
type: "tool-approval-request",
|
|
3780
|
+
approvalId: approvalRequestId,
|
|
3781
|
+
toolCallId: dummyToolCallId
|
|
3782
|
+
});
|
|
3783
|
+
break;
|
|
3784
|
+
}
|
|
3785
|
+
case "computer_call":
|
|
3786
|
+
content.push({
|
|
3787
|
+
type: "tool-call",
|
|
3788
|
+
toolCallId: part.id,
|
|
3789
|
+
toolName: toolNameMapping.toCustomToolName("computer_use"),
|
|
3790
|
+
input: "",
|
|
3791
|
+
providerExecuted: true
|
|
3792
|
+
});
|
|
3793
|
+
content.push({
|
|
3794
|
+
type: "tool-result",
|
|
3795
|
+
toolCallId: part.id,
|
|
3796
|
+
toolName: toolNameMapping.toCustomToolName("computer_use"),
|
|
3797
|
+
result: {
|
|
3798
|
+
type: "computer_use_tool_result",
|
|
3799
|
+
status: part.status || "completed"
|
|
3800
|
+
}
|
|
3801
|
+
});
|
|
3802
|
+
break;
|
|
3803
|
+
case "file_search_call":
|
|
3804
|
+
content.push({
|
|
3805
|
+
type: "tool-call",
|
|
3806
|
+
toolCallId: part.id,
|
|
3807
|
+
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
3808
|
+
input: "{}",
|
|
3809
|
+
providerExecuted: true
|
|
3810
|
+
});
|
|
3811
|
+
content.push({
|
|
3812
|
+
type: "tool-result",
|
|
3813
|
+
toolCallId: part.id,
|
|
3814
|
+
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
3815
|
+
result: {
|
|
3816
|
+
queries: part.queries,
|
|
3817
|
+
results: (_v = (_u = part.results) == null ? void 0 : _u.map((result) => ({
|
|
3818
|
+
attributes: result.attributes,
|
|
3819
|
+
fileId: result.file_id,
|
|
3820
|
+
filename: result.filename,
|
|
3821
|
+
score: result.score,
|
|
3822
|
+
text: result.text
|
|
3823
|
+
}))) != null ? _v : null
|
|
3824
|
+
}
|
|
3825
|
+
});
|
|
3826
|
+
break;
|
|
3827
|
+
case "code_interpreter_call":
|
|
3828
|
+
content.push({
|
|
3829
|
+
type: "tool-call",
|
|
3830
|
+
toolCallId: part.id,
|
|
3831
|
+
toolName: toolNameMapping.toCustomToolName("code_interpreter"),
|
|
3832
|
+
input: JSON.stringify({
|
|
3833
|
+
code: part.code,
|
|
3834
|
+
containerId: part.container_id
|
|
3835
|
+
}),
|
|
3836
|
+
providerExecuted: true
|
|
3837
|
+
});
|
|
3838
|
+
content.push({
|
|
3839
|
+
type: "tool-result",
|
|
3840
|
+
toolCallId: part.id,
|
|
3841
|
+
toolName: toolNameMapping.toCustomToolName("code_interpreter"),
|
|
3842
|
+
result: { outputs: part.outputs }
|
|
3843
|
+
});
|
|
3844
|
+
break;
|
|
3845
|
+
case "apply_patch_call":
|
|
3846
|
+
content.push({
|
|
3847
|
+
type: "tool-call",
|
|
3848
|
+
toolCallId: part.call_id,
|
|
3849
|
+
toolName: toolNameMapping.toCustomToolName("apply_patch"),
|
|
3850
|
+
input: JSON.stringify({
|
|
3851
|
+
callId: part.call_id,
|
|
3852
|
+
operation: part.operation
|
|
3853
|
+
}),
|
|
3854
|
+
providerMetadata: { [providerOptionsName]: { itemId: part.id } }
|
|
3855
|
+
});
|
|
3856
|
+
break;
|
|
3857
|
+
}
|
|
3858
|
+
const providerMetadata = { [providerOptionsName]: {
|
|
3859
|
+
responseId: response.id,
|
|
3860
|
+
...logprobs.length > 0 ? { logprobs } : {},
|
|
3861
|
+
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {}
|
|
3862
|
+
} };
|
|
3863
|
+
const usage = response.usage;
|
|
3864
|
+
return {
|
|
3865
|
+
content,
|
|
3866
|
+
finishReason: {
|
|
3867
|
+
unified: mapOpenAIResponseFinishReason({
|
|
3868
|
+
finishReason: (_w = response.incomplete_details) == null ? void 0 : _w.reason,
|
|
3869
|
+
hasFunctionCall
|
|
3870
|
+
}),
|
|
3871
|
+
raw: (_y = (_x = response.incomplete_details) == null ? void 0 : _x.reason) != null ? _y : void 0
|
|
3872
|
+
},
|
|
3873
|
+
usage: convertOpenAIResponsesUsage(usage),
|
|
3874
|
+
request: { body },
|
|
3875
|
+
response: {
|
|
3876
|
+
id: response.id,
|
|
3877
|
+
timestamp: /* @__PURE__ */ new Date(response.created_at * 1e3),
|
|
3878
|
+
modelId: response.model,
|
|
3879
|
+
headers: responseHeaders,
|
|
3880
|
+
body: rawResponse
|
|
3881
|
+
},
|
|
3882
|
+
providerMetadata,
|
|
3883
|
+
warnings
|
|
3884
|
+
};
|
|
3885
|
+
}
|
|
3886
|
+
async doStream(options) {
|
|
3887
|
+
const { args: body, warnings, webSearchToolName, toolNameMapping, store, providerOptionsName, isShellProviderExecuted } = await this.getArgs(options);
|
|
3888
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
3889
|
+
url: this.config.url({
|
|
3890
|
+
path: "/responses",
|
|
3891
|
+
modelId: this.modelId
|
|
3892
|
+
}),
|
|
3893
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
3894
|
+
body: {
|
|
3895
|
+
...body,
|
|
3896
|
+
stream: true
|
|
3897
|
+
},
|
|
3898
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
3899
|
+
successfulResponseHandler: createEventSourceResponseHandler(openaiResponsesChunkSchema),
|
|
3900
|
+
abortSignal: options.abortSignal,
|
|
3901
|
+
fetch: this.config.fetch
|
|
3902
|
+
});
|
|
3903
|
+
const self = this;
|
|
3904
|
+
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
3905
|
+
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
3906
|
+
let finishReason = {
|
|
3907
|
+
unified: "other",
|
|
3908
|
+
raw: void 0
|
|
3909
|
+
};
|
|
3910
|
+
let usage = void 0;
|
|
3911
|
+
const logprobs = [];
|
|
3912
|
+
let responseId = null;
|
|
3913
|
+
const ongoingToolCalls = {};
|
|
3914
|
+
const ongoingAnnotations = [];
|
|
3915
|
+
let activeMessagePhase;
|
|
3916
|
+
let hasFunctionCall = false;
|
|
3917
|
+
const activeReasoning = {};
|
|
3918
|
+
let serviceTier;
|
|
3919
|
+
return {
|
|
3920
|
+
stream: response.pipeThrough(new TransformStream({
|
|
3921
|
+
start(controller) {
|
|
3922
|
+
controller.enqueue({
|
|
3923
|
+
type: "stream-start",
|
|
3924
|
+
warnings
|
|
3925
|
+
});
|
|
3926
|
+
},
|
|
3927
|
+
transform(chunk, controller) {
|
|
3928
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
3929
|
+
if (options.includeRawChunks) controller.enqueue({
|
|
3930
|
+
type: "raw",
|
|
3931
|
+
rawValue: chunk.rawValue
|
|
3932
|
+
});
|
|
3933
|
+
if (!chunk.success) {
|
|
3934
|
+
finishReason = {
|
|
3935
|
+
unified: "error",
|
|
3936
|
+
raw: void 0
|
|
3937
|
+
};
|
|
3938
|
+
controller.enqueue({
|
|
3939
|
+
type: "error",
|
|
3940
|
+
error: chunk.error
|
|
3941
|
+
});
|
|
3942
|
+
return;
|
|
3943
|
+
}
|
|
3944
|
+
const value = chunk.value;
|
|
3945
|
+
if (isResponseOutputItemAddedChunk(value)) {
|
|
3946
|
+
if (value.item.type === "function_call") {
|
|
3947
|
+
ongoingToolCalls[value.output_index] = {
|
|
3948
|
+
toolName: value.item.name,
|
|
3949
|
+
toolCallId: value.item.call_id
|
|
3950
|
+
};
|
|
3951
|
+
controller.enqueue({
|
|
3952
|
+
type: "tool-input-start",
|
|
3953
|
+
id: value.item.call_id,
|
|
3954
|
+
toolName: value.item.name
|
|
3955
|
+
});
|
|
3956
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
3957
|
+
const toolName = toolNameMapping.toCustomToolName(value.item.name);
|
|
3958
|
+
ongoingToolCalls[value.output_index] = {
|
|
3959
|
+
toolName,
|
|
3960
|
+
toolCallId: value.item.call_id
|
|
3961
|
+
};
|
|
3962
|
+
controller.enqueue({
|
|
3963
|
+
type: "tool-input-start",
|
|
3964
|
+
id: value.item.call_id,
|
|
3965
|
+
toolName
|
|
3966
|
+
});
|
|
3967
|
+
} else if (value.item.type === "web_search_call") {
|
|
3968
|
+
ongoingToolCalls[value.output_index] = {
|
|
3969
|
+
toolName: toolNameMapping.toCustomToolName(webSearchToolName != null ? webSearchToolName : "web_search"),
|
|
3970
|
+
toolCallId: value.item.id
|
|
3971
|
+
};
|
|
3972
|
+
controller.enqueue({
|
|
3973
|
+
type: "tool-input-start",
|
|
3974
|
+
id: value.item.id,
|
|
3975
|
+
toolName: toolNameMapping.toCustomToolName(webSearchToolName != null ? webSearchToolName : "web_search"),
|
|
3976
|
+
providerExecuted: true
|
|
3977
|
+
});
|
|
3978
|
+
controller.enqueue({
|
|
3979
|
+
type: "tool-input-end",
|
|
3980
|
+
id: value.item.id
|
|
3981
|
+
});
|
|
3982
|
+
controller.enqueue({
|
|
3983
|
+
type: "tool-call",
|
|
3984
|
+
toolCallId: value.item.id,
|
|
3985
|
+
toolName: toolNameMapping.toCustomToolName(webSearchToolName != null ? webSearchToolName : "web_search"),
|
|
3986
|
+
input: JSON.stringify({}),
|
|
3987
|
+
providerExecuted: true
|
|
3988
|
+
});
|
|
3989
|
+
} else if (value.item.type === "computer_call") {
|
|
3990
|
+
ongoingToolCalls[value.output_index] = {
|
|
3991
|
+
toolName: toolNameMapping.toCustomToolName("computer_use"),
|
|
3992
|
+
toolCallId: value.item.id
|
|
3993
|
+
};
|
|
3994
|
+
controller.enqueue({
|
|
3995
|
+
type: "tool-input-start",
|
|
3996
|
+
id: value.item.id,
|
|
3997
|
+
toolName: toolNameMapping.toCustomToolName("computer_use"),
|
|
3998
|
+
providerExecuted: true
|
|
3999
|
+
});
|
|
4000
|
+
} else if (value.item.type === "code_interpreter_call") {
|
|
4001
|
+
ongoingToolCalls[value.output_index] = {
|
|
4002
|
+
toolName: toolNameMapping.toCustomToolName("code_interpreter"),
|
|
4003
|
+
toolCallId: value.item.id,
|
|
4004
|
+
codeInterpreter: { containerId: value.item.container_id }
|
|
4005
|
+
};
|
|
4006
|
+
controller.enqueue({
|
|
4007
|
+
type: "tool-input-start",
|
|
4008
|
+
id: value.item.id,
|
|
4009
|
+
toolName: toolNameMapping.toCustomToolName("code_interpreter"),
|
|
4010
|
+
providerExecuted: true
|
|
4011
|
+
});
|
|
4012
|
+
controller.enqueue({
|
|
4013
|
+
type: "tool-input-delta",
|
|
4014
|
+
id: value.item.id,
|
|
4015
|
+
delta: `{"containerId":"${value.item.container_id}","code":"`
|
|
4016
|
+
});
|
|
4017
|
+
} else if (value.item.type === "file_search_call") controller.enqueue({
|
|
4018
|
+
type: "tool-call",
|
|
4019
|
+
toolCallId: value.item.id,
|
|
4020
|
+
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
4021
|
+
input: "{}",
|
|
4022
|
+
providerExecuted: true
|
|
4023
|
+
});
|
|
4024
|
+
else if (value.item.type === "image_generation_call") controller.enqueue({
|
|
4025
|
+
type: "tool-call",
|
|
4026
|
+
toolCallId: value.item.id,
|
|
4027
|
+
toolName: toolNameMapping.toCustomToolName("image_generation"),
|
|
4028
|
+
input: "{}",
|
|
4029
|
+
providerExecuted: true
|
|
4030
|
+
});
|
|
4031
|
+
else if (value.item.type === "mcp_call" || value.item.type === "mcp_list_tools" || value.item.type === "mcp_approval_request") {} else if (value.item.type === "apply_patch_call") {
|
|
4032
|
+
const { call_id: callId, operation } = value.item;
|
|
4033
|
+
ongoingToolCalls[value.output_index] = {
|
|
4034
|
+
toolName: toolNameMapping.toCustomToolName("apply_patch"),
|
|
4035
|
+
toolCallId: callId,
|
|
4036
|
+
applyPatch: {
|
|
4037
|
+
hasDiff: operation.type === "delete_file",
|
|
4038
|
+
endEmitted: operation.type === "delete_file"
|
|
4039
|
+
}
|
|
4040
|
+
};
|
|
4041
|
+
controller.enqueue({
|
|
4042
|
+
type: "tool-input-start",
|
|
4043
|
+
id: callId,
|
|
4044
|
+
toolName: toolNameMapping.toCustomToolName("apply_patch")
|
|
4045
|
+
});
|
|
4046
|
+
if (operation.type === "delete_file") {
|
|
4047
|
+
const inputString = JSON.stringify({
|
|
4048
|
+
callId,
|
|
4049
|
+
operation
|
|
4050
|
+
});
|
|
4051
|
+
controller.enqueue({
|
|
4052
|
+
type: "tool-input-delta",
|
|
4053
|
+
id: callId,
|
|
4054
|
+
delta: inputString
|
|
4055
|
+
});
|
|
4056
|
+
controller.enqueue({
|
|
4057
|
+
type: "tool-input-end",
|
|
4058
|
+
id: callId
|
|
4059
|
+
});
|
|
4060
|
+
} else controller.enqueue({
|
|
4061
|
+
type: "tool-input-delta",
|
|
4062
|
+
id: callId,
|
|
4063
|
+
delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
|
|
4064
|
+
});
|
|
4065
|
+
} else if (value.item.type === "shell_call") ongoingToolCalls[value.output_index] = {
|
|
4066
|
+
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
4067
|
+
toolCallId: value.item.call_id
|
|
4068
|
+
};
|
|
4069
|
+
else if (value.item.type === "shell_call_output") {} else if (value.item.type === "message") {
|
|
4070
|
+
ongoingAnnotations.splice(0, ongoingAnnotations.length);
|
|
4071
|
+
activeMessagePhase = (_a = value.item.phase) != null ? _a : void 0;
|
|
4072
|
+
controller.enqueue({
|
|
4073
|
+
type: "text-start",
|
|
4074
|
+
id: value.item.id,
|
|
4075
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4076
|
+
itemId: value.item.id,
|
|
4077
|
+
...value.item.phase != null && { phase: value.item.phase }
|
|
4078
|
+
} }
|
|
4079
|
+
});
|
|
4080
|
+
} else if (isResponseOutputItemAddedChunk(value) && value.item.type === "reasoning") {
|
|
4081
|
+
activeReasoning[value.item.id] = {
|
|
4082
|
+
encryptedContent: value.item.encrypted_content,
|
|
4083
|
+
summaryParts: { 0: "active" }
|
|
4084
|
+
};
|
|
4085
|
+
controller.enqueue({
|
|
4086
|
+
type: "reasoning-start",
|
|
4087
|
+
id: `${value.item.id}:0`,
|
|
4088
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4089
|
+
itemId: value.item.id,
|
|
4090
|
+
reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
4091
|
+
} }
|
|
4092
|
+
});
|
|
4093
|
+
}
|
|
4094
|
+
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
4095
|
+
if (value.item.type === "message") {
|
|
4096
|
+
const phase = (_c = value.item.phase) != null ? _c : activeMessagePhase;
|
|
4097
|
+
activeMessagePhase = void 0;
|
|
4098
|
+
controller.enqueue({
|
|
4099
|
+
type: "text-end",
|
|
4100
|
+
id: value.item.id,
|
|
4101
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4102
|
+
itemId: value.item.id,
|
|
4103
|
+
...phase != null && { phase },
|
|
4104
|
+
...ongoingAnnotations.length > 0 && { annotations: ongoingAnnotations }
|
|
4105
|
+
} }
|
|
4106
|
+
});
|
|
4107
|
+
} else if (value.item.type === "function_call") {
|
|
4108
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4109
|
+
hasFunctionCall = true;
|
|
4110
|
+
controller.enqueue({
|
|
4111
|
+
type: "tool-input-end",
|
|
4112
|
+
id: value.item.call_id
|
|
4113
|
+
});
|
|
4114
|
+
controller.enqueue({
|
|
4115
|
+
type: "tool-call",
|
|
4116
|
+
toolCallId: value.item.call_id,
|
|
4117
|
+
toolName: value.item.name,
|
|
4118
|
+
input: value.item.arguments,
|
|
4119
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
|
|
4120
|
+
});
|
|
4121
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
4122
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4123
|
+
hasFunctionCall = true;
|
|
4124
|
+
const toolName = toolNameMapping.toCustomToolName(value.item.name);
|
|
4125
|
+
controller.enqueue({
|
|
4126
|
+
type: "tool-input-end",
|
|
4127
|
+
id: value.item.call_id
|
|
4128
|
+
});
|
|
4129
|
+
controller.enqueue({
|
|
4130
|
+
type: "tool-call",
|
|
4131
|
+
toolCallId: value.item.call_id,
|
|
4132
|
+
toolName,
|
|
4133
|
+
input: JSON.stringify(value.item.input),
|
|
4134
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
|
|
4135
|
+
});
|
|
4136
|
+
} else if (value.item.type === "web_search_call") {
|
|
4137
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4138
|
+
controller.enqueue({
|
|
4139
|
+
type: "tool-result",
|
|
4140
|
+
toolCallId: value.item.id,
|
|
4141
|
+
toolName: toolNameMapping.toCustomToolName(webSearchToolName != null ? webSearchToolName : "web_search"),
|
|
4142
|
+
result: mapWebSearchOutput(value.item.action)
|
|
4143
|
+
});
|
|
4144
|
+
} else if (value.item.type === "computer_call") {
|
|
4145
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4146
|
+
controller.enqueue({
|
|
4147
|
+
type: "tool-input-end",
|
|
4148
|
+
id: value.item.id
|
|
4149
|
+
});
|
|
4150
|
+
controller.enqueue({
|
|
4151
|
+
type: "tool-call",
|
|
4152
|
+
toolCallId: value.item.id,
|
|
4153
|
+
toolName: toolNameMapping.toCustomToolName("computer_use"),
|
|
4154
|
+
input: "",
|
|
4155
|
+
providerExecuted: true
|
|
4156
|
+
});
|
|
4157
|
+
controller.enqueue({
|
|
4158
|
+
type: "tool-result",
|
|
4159
|
+
toolCallId: value.item.id,
|
|
4160
|
+
toolName: toolNameMapping.toCustomToolName("computer_use"),
|
|
4161
|
+
result: {
|
|
4162
|
+
type: "computer_use_tool_result",
|
|
4163
|
+
status: value.item.status || "completed"
|
|
4164
|
+
}
|
|
4165
|
+
});
|
|
4166
|
+
} else if (value.item.type === "file_search_call") {
|
|
4167
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4168
|
+
controller.enqueue({
|
|
4169
|
+
type: "tool-result",
|
|
4170
|
+
toolCallId: value.item.id,
|
|
4171
|
+
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
4172
|
+
result: {
|
|
4173
|
+
queries: value.item.queries,
|
|
4174
|
+
results: (_e = (_d = value.item.results) == null ? void 0 : _d.map((result) => ({
|
|
4175
|
+
attributes: result.attributes,
|
|
4176
|
+
fileId: result.file_id,
|
|
4177
|
+
filename: result.filename,
|
|
4178
|
+
score: result.score,
|
|
4179
|
+
text: result.text
|
|
4180
|
+
}))) != null ? _e : null
|
|
4181
|
+
}
|
|
4182
|
+
});
|
|
4183
|
+
} else if (value.item.type === "code_interpreter_call") {
|
|
4184
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4185
|
+
controller.enqueue({
|
|
4186
|
+
type: "tool-result",
|
|
4187
|
+
toolCallId: value.item.id,
|
|
4188
|
+
toolName: toolNameMapping.toCustomToolName("code_interpreter"),
|
|
4189
|
+
result: { outputs: value.item.outputs }
|
|
4190
|
+
});
|
|
4191
|
+
} else if (value.item.type === "image_generation_call") controller.enqueue({
|
|
4192
|
+
type: "tool-result",
|
|
4193
|
+
toolCallId: value.item.id,
|
|
4194
|
+
toolName: toolNameMapping.toCustomToolName("image_generation"),
|
|
4195
|
+
result: { result: value.item.result }
|
|
4196
|
+
});
|
|
4197
|
+
else if (value.item.type === "mcp_call") {
|
|
4198
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4199
|
+
const approvalRequestId = (_f = value.item.approval_request_id) != null ? _f : void 0;
|
|
4200
|
+
const aliasedToolCallId = approvalRequestId != null ? (_h = (_g = approvalRequestIdToDummyToolCallIdFromStream.get(approvalRequestId)) != null ? _g : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _h : value.item.id : value.item.id;
|
|
4201
|
+
const toolName = `mcp.${value.item.name}`;
|
|
4202
|
+
controller.enqueue({
|
|
4203
|
+
type: "tool-call",
|
|
4204
|
+
toolCallId: aliasedToolCallId,
|
|
4205
|
+
toolName,
|
|
4206
|
+
input: value.item.arguments,
|
|
4207
|
+
providerExecuted: true,
|
|
4208
|
+
dynamic: true
|
|
4209
|
+
});
|
|
4210
|
+
controller.enqueue({
|
|
4211
|
+
type: "tool-result",
|
|
4212
|
+
toolCallId: aliasedToolCallId,
|
|
4213
|
+
toolName,
|
|
4214
|
+
result: {
|
|
4215
|
+
type: "call",
|
|
4216
|
+
serverLabel: value.item.server_label,
|
|
4217
|
+
name: value.item.name,
|
|
4218
|
+
arguments: value.item.arguments,
|
|
4219
|
+
...value.item.output != null ? { output: value.item.output } : {},
|
|
4220
|
+
...value.item.error != null ? { error: value.item.error } : {}
|
|
4221
|
+
},
|
|
4222
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
|
|
4223
|
+
});
|
|
4224
|
+
} else if (value.item.type === "mcp_list_tools") ongoingToolCalls[value.output_index] = void 0;
|
|
4225
|
+
else if (value.item.type === "apply_patch_call") {
|
|
4226
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
4227
|
+
if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
|
|
4228
|
+
if (!toolCall.applyPatch.hasDiff) controller.enqueue({
|
|
4229
|
+
type: "tool-input-delta",
|
|
4230
|
+
id: toolCall.toolCallId,
|
|
4231
|
+
delta: escapeJSONDelta(value.item.operation.diff)
|
|
4232
|
+
});
|
|
4233
|
+
controller.enqueue({
|
|
4234
|
+
type: "tool-input-delta",
|
|
4235
|
+
id: toolCall.toolCallId,
|
|
4236
|
+
delta: "\"}}"
|
|
4237
|
+
});
|
|
4238
|
+
controller.enqueue({
|
|
4239
|
+
type: "tool-input-end",
|
|
4240
|
+
id: toolCall.toolCallId
|
|
4241
|
+
});
|
|
4242
|
+
toolCall.applyPatch.endEmitted = true;
|
|
4243
|
+
}
|
|
4244
|
+
if (toolCall && value.item.status === "completed") controller.enqueue({
|
|
4245
|
+
type: "tool-call",
|
|
4246
|
+
toolCallId: toolCall.toolCallId,
|
|
4247
|
+
toolName: toolNameMapping.toCustomToolName("apply_patch"),
|
|
4248
|
+
input: JSON.stringify({
|
|
4249
|
+
callId: value.item.call_id,
|
|
4250
|
+
operation: value.item.operation
|
|
4251
|
+
}),
|
|
4252
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
|
|
4253
|
+
});
|
|
4254
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4255
|
+
} else if (value.item.type === "mcp_approval_request") {
|
|
4256
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4257
|
+
const dummyToolCallId = (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId();
|
|
4258
|
+
const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : value.item.id;
|
|
4259
|
+
approvalRequestIdToDummyToolCallIdFromStream.set(approvalRequestId, dummyToolCallId);
|
|
4260
|
+
const toolName = `mcp.${value.item.name}`;
|
|
4261
|
+
controller.enqueue({
|
|
4262
|
+
type: "tool-call",
|
|
4263
|
+
toolCallId: dummyToolCallId,
|
|
4264
|
+
toolName,
|
|
4265
|
+
input: value.item.arguments,
|
|
4266
|
+
providerExecuted: true,
|
|
4267
|
+
dynamic: true
|
|
4268
|
+
});
|
|
4269
|
+
controller.enqueue({
|
|
4270
|
+
type: "tool-approval-request",
|
|
4271
|
+
approvalId: approvalRequestId,
|
|
4272
|
+
toolCallId: dummyToolCallId
|
|
4273
|
+
});
|
|
4274
|
+
} else if (value.item.type === "local_shell_call") {
|
|
4275
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4276
|
+
controller.enqueue({
|
|
4277
|
+
type: "tool-call",
|
|
4278
|
+
toolCallId: value.item.call_id,
|
|
4279
|
+
toolName: toolNameMapping.toCustomToolName("local_shell"),
|
|
4280
|
+
input: JSON.stringify({ action: {
|
|
4281
|
+
type: "exec",
|
|
4282
|
+
command: value.item.action.command,
|
|
4283
|
+
timeoutMs: value.item.action.timeout_ms,
|
|
4284
|
+
user: value.item.action.user,
|
|
4285
|
+
workingDirectory: value.item.action.working_directory,
|
|
4286
|
+
env: value.item.action.env
|
|
4287
|
+
} }),
|
|
4288
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
|
|
4289
|
+
});
|
|
4290
|
+
} else if (value.item.type === "shell_call") {
|
|
4291
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4292
|
+
controller.enqueue({
|
|
4293
|
+
type: "tool-call",
|
|
4294
|
+
toolCallId: value.item.call_id,
|
|
4295
|
+
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
4296
|
+
input: JSON.stringify({ action: { commands: value.item.action.commands } }),
|
|
4297
|
+
...isShellProviderExecuted && { providerExecuted: true },
|
|
4298
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
|
|
4299
|
+
});
|
|
4300
|
+
} else if (value.item.type === "shell_call_output") controller.enqueue({
|
|
4301
|
+
type: "tool-result",
|
|
4302
|
+
toolCallId: value.item.call_id,
|
|
4303
|
+
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
4304
|
+
result: { output: value.item.output.map((item) => ({
|
|
4305
|
+
stdout: item.stdout,
|
|
4306
|
+
stderr: item.stderr,
|
|
4307
|
+
outcome: item.outcome.type === "exit" ? {
|
|
4308
|
+
type: "exit",
|
|
4309
|
+
exitCode: item.outcome.exit_code
|
|
4310
|
+
} : { type: "timeout" }
|
|
4311
|
+
})) }
|
|
4312
|
+
});
|
|
4313
|
+
else if (value.item.type === "reasoning") {
|
|
4314
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
4315
|
+
const summaryPartIndices = Object.entries(activeReasoningPart.summaryParts).filter(([_, status]) => status === "active" || status === "can-conclude").map(([summaryIndex]) => summaryIndex);
|
|
4316
|
+
for (const summaryIndex of summaryPartIndices) controller.enqueue({
|
|
4317
|
+
type: "reasoning-end",
|
|
4318
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
4319
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4320
|
+
itemId: value.item.id,
|
|
4321
|
+
reasoningEncryptedContent: (_m = value.item.encrypted_content) != null ? _m : null
|
|
4322
|
+
} }
|
|
4323
|
+
});
|
|
4324
|
+
delete activeReasoning[value.item.id];
|
|
4325
|
+
}
|
|
4326
|
+
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
4327
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
4328
|
+
if (toolCall != null) controller.enqueue({
|
|
4329
|
+
type: "tool-input-delta",
|
|
4330
|
+
id: toolCall.toolCallId,
|
|
4331
|
+
delta: value.delta
|
|
4332
|
+
});
|
|
4333
|
+
} else if (isResponseCustomToolCallInputDeltaChunk(value)) {
|
|
4334
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
4335
|
+
if (toolCall != null) controller.enqueue({
|
|
4336
|
+
type: "tool-input-delta",
|
|
4337
|
+
id: toolCall.toolCallId,
|
|
4338
|
+
delta: value.delta
|
|
4339
|
+
});
|
|
4340
|
+
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
4341
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
4342
|
+
if (toolCall == null ? void 0 : toolCall.applyPatch) {
|
|
4343
|
+
controller.enqueue({
|
|
4344
|
+
type: "tool-input-delta",
|
|
4345
|
+
id: toolCall.toolCallId,
|
|
4346
|
+
delta: escapeJSONDelta(value.delta)
|
|
4347
|
+
});
|
|
4348
|
+
toolCall.applyPatch.hasDiff = true;
|
|
4349
|
+
}
|
|
4350
|
+
} else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
|
|
4351
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
4352
|
+
if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
|
|
4353
|
+
if (!toolCall.applyPatch.hasDiff) {
|
|
4354
|
+
controller.enqueue({
|
|
4355
|
+
type: "tool-input-delta",
|
|
4356
|
+
id: toolCall.toolCallId,
|
|
4357
|
+
delta: escapeJSONDelta(value.diff)
|
|
4358
|
+
});
|
|
4359
|
+
toolCall.applyPatch.hasDiff = true;
|
|
4360
|
+
}
|
|
4361
|
+
controller.enqueue({
|
|
4362
|
+
type: "tool-input-delta",
|
|
4363
|
+
id: toolCall.toolCallId,
|
|
4364
|
+
delta: "\"}}"
|
|
4365
|
+
});
|
|
4366
|
+
controller.enqueue({
|
|
4367
|
+
type: "tool-input-end",
|
|
4368
|
+
id: toolCall.toolCallId
|
|
4369
|
+
});
|
|
4370
|
+
toolCall.applyPatch.endEmitted = true;
|
|
4371
|
+
}
|
|
4372
|
+
} else if (isResponseImageGenerationCallPartialImageChunk(value)) controller.enqueue({
|
|
4373
|
+
type: "tool-result",
|
|
4374
|
+
toolCallId: value.item_id,
|
|
4375
|
+
toolName: toolNameMapping.toCustomToolName("image_generation"),
|
|
4376
|
+
result: { result: value.partial_image_b64 },
|
|
4377
|
+
preliminary: true
|
|
4378
|
+
});
|
|
4379
|
+
else if (isResponseCodeInterpreterCallCodeDeltaChunk(value)) {
|
|
4380
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
4381
|
+
if (toolCall != null) controller.enqueue({
|
|
4382
|
+
type: "tool-input-delta",
|
|
4383
|
+
id: toolCall.toolCallId,
|
|
4384
|
+
delta: escapeJSONDelta(value.delta)
|
|
4385
|
+
});
|
|
4386
|
+
} else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
|
|
4387
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
4388
|
+
if (toolCall != null) {
|
|
4389
|
+
controller.enqueue({
|
|
4390
|
+
type: "tool-input-delta",
|
|
4391
|
+
id: toolCall.toolCallId,
|
|
4392
|
+
delta: "\"}"
|
|
4393
|
+
});
|
|
4394
|
+
controller.enqueue({
|
|
4395
|
+
type: "tool-input-end",
|
|
4396
|
+
id: toolCall.toolCallId
|
|
4397
|
+
});
|
|
4398
|
+
controller.enqueue({
|
|
4399
|
+
type: "tool-call",
|
|
4400
|
+
toolCallId: toolCall.toolCallId,
|
|
4401
|
+
toolName: toolNameMapping.toCustomToolName("code_interpreter"),
|
|
4402
|
+
input: JSON.stringify({
|
|
4403
|
+
code: value.code,
|
|
4404
|
+
containerId: toolCall.codeInterpreter.containerId
|
|
4405
|
+
}),
|
|
4406
|
+
providerExecuted: true
|
|
4407
|
+
});
|
|
4408
|
+
}
|
|
4409
|
+
} else if (isResponseCreatedChunk(value)) {
|
|
4410
|
+
responseId = value.response.id;
|
|
4411
|
+
controller.enqueue({
|
|
4412
|
+
type: "response-metadata",
|
|
4413
|
+
id: value.response.id,
|
|
4414
|
+
timestamp: /* @__PURE__ */ new Date(value.response.created_at * 1e3),
|
|
4415
|
+
modelId: value.response.model
|
|
4416
|
+
});
|
|
4417
|
+
} else if (isTextDeltaChunk(value)) {
|
|
4418
|
+
controller.enqueue({
|
|
4419
|
+
type: "text-delta",
|
|
4420
|
+
id: value.item_id,
|
|
4421
|
+
delta: value.delta
|
|
4422
|
+
});
|
|
4423
|
+
if (((_o = (_n = options.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.logprobs) && value.logprobs) logprobs.push(value.logprobs);
|
|
4424
|
+
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
4425
|
+
if (value.summary_index > 0) {
|
|
4426
|
+
const activeReasoningPart = activeReasoning[value.item_id];
|
|
4427
|
+
activeReasoningPart.summaryParts[value.summary_index] = "active";
|
|
4428
|
+
for (const summaryIndex of Object.keys(activeReasoningPart.summaryParts)) if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
|
|
4429
|
+
controller.enqueue({
|
|
4430
|
+
type: "reasoning-end",
|
|
4431
|
+
id: `${value.item_id}:${summaryIndex}`,
|
|
4432
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item_id } }
|
|
4433
|
+
});
|
|
4434
|
+
activeReasoningPart.summaryParts[summaryIndex] = "concluded";
|
|
4435
|
+
}
|
|
4436
|
+
controller.enqueue({
|
|
4437
|
+
type: "reasoning-start",
|
|
4438
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
4439
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4440
|
+
itemId: value.item_id,
|
|
4441
|
+
reasoningEncryptedContent: (_q = (_p = activeReasoning[value.item_id]) == null ? void 0 : _p.encryptedContent) != null ? _q : null
|
|
4442
|
+
} }
|
|
4443
|
+
});
|
|
4444
|
+
}
|
|
4445
|
+
} else if (value.type === "response.reasoning_summary_text.delta") controller.enqueue({
|
|
4446
|
+
type: "reasoning-delta",
|
|
4447
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
4448
|
+
delta: value.delta,
|
|
4449
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item_id } }
|
|
4450
|
+
});
|
|
4451
|
+
else if (value.type === "response.reasoning_summary_part.done") if (store) {
|
|
4452
|
+
controller.enqueue({
|
|
4453
|
+
type: "reasoning-end",
|
|
4454
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
4455
|
+
providerMetadata: { [providerOptionsName]: { itemId: value.item_id } }
|
|
4456
|
+
});
|
|
4457
|
+
activeReasoning[value.item_id].summaryParts[value.summary_index] = "concluded";
|
|
4458
|
+
} else activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
|
|
4459
|
+
else if (isResponseFinishedChunk(value)) {
|
|
4460
|
+
finishReason = {
|
|
4461
|
+
unified: mapOpenAIResponseFinishReason({
|
|
4462
|
+
finishReason: (_r = value.response.incomplete_details) == null ? void 0 : _r.reason,
|
|
4463
|
+
hasFunctionCall
|
|
4464
|
+
}),
|
|
4465
|
+
raw: (_t = (_s = value.response.incomplete_details) == null ? void 0 : _s.reason) != null ? _t : void 0
|
|
4466
|
+
};
|
|
4467
|
+
usage = value.response.usage;
|
|
4468
|
+
if (typeof value.response.service_tier === "string") serviceTier = value.response.service_tier;
|
|
4469
|
+
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
4470
|
+
ongoingAnnotations.push(value.annotation);
|
|
4471
|
+
if (value.annotation.type === "url_citation") controller.enqueue({
|
|
4472
|
+
type: "source",
|
|
4473
|
+
sourceType: "url",
|
|
4474
|
+
id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId(),
|
|
4475
|
+
url: value.annotation.url,
|
|
4476
|
+
title: value.annotation.title
|
|
4477
|
+
});
|
|
4478
|
+
else if (value.annotation.type === "file_citation") controller.enqueue({
|
|
4479
|
+
type: "source",
|
|
4480
|
+
sourceType: "document",
|
|
4481
|
+
id: (_z = (_y = (_x = self.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : generateId(),
|
|
4482
|
+
mediaType: "text/plain",
|
|
4483
|
+
title: value.annotation.filename,
|
|
4484
|
+
filename: value.annotation.filename,
|
|
4485
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4486
|
+
type: value.annotation.type,
|
|
4487
|
+
fileId: value.annotation.file_id,
|
|
4488
|
+
index: value.annotation.index
|
|
4489
|
+
} }
|
|
4490
|
+
});
|
|
4491
|
+
else if (value.annotation.type === "container_file_citation") controller.enqueue({
|
|
4492
|
+
type: "source",
|
|
4493
|
+
sourceType: "document",
|
|
4494
|
+
id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId(),
|
|
4495
|
+
mediaType: "text/plain",
|
|
4496
|
+
title: value.annotation.filename,
|
|
4497
|
+
filename: value.annotation.filename,
|
|
4498
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4499
|
+
type: value.annotation.type,
|
|
4500
|
+
fileId: value.annotation.file_id,
|
|
4501
|
+
containerId: value.annotation.container_id
|
|
4502
|
+
} }
|
|
4503
|
+
});
|
|
4504
|
+
else if (value.annotation.type === "file_path") controller.enqueue({
|
|
4505
|
+
type: "source",
|
|
4506
|
+
sourceType: "document",
|
|
4507
|
+
id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId(),
|
|
4508
|
+
mediaType: "application/octet-stream",
|
|
4509
|
+
title: value.annotation.file_id,
|
|
4510
|
+
filename: value.annotation.file_id,
|
|
4511
|
+
providerMetadata: { [providerOptionsName]: {
|
|
4512
|
+
type: value.annotation.type,
|
|
4513
|
+
fileId: value.annotation.file_id,
|
|
4514
|
+
index: value.annotation.index
|
|
4515
|
+
} }
|
|
4516
|
+
});
|
|
4517
|
+
} else if (isErrorChunk(value)) controller.enqueue({
|
|
4518
|
+
type: "error",
|
|
4519
|
+
error: value
|
|
4520
|
+
});
|
|
4521
|
+
},
|
|
4522
|
+
flush(controller) {
|
|
4523
|
+
const providerMetadata = { [providerOptionsName]: {
|
|
4524
|
+
responseId,
|
|
4525
|
+
...logprobs.length > 0 ? { logprobs } : {},
|
|
4526
|
+
...serviceTier !== void 0 ? { serviceTier } : {}
|
|
4527
|
+
} };
|
|
4528
|
+
controller.enqueue({
|
|
4529
|
+
type: "finish",
|
|
4530
|
+
finishReason,
|
|
4531
|
+
usage: convertOpenAIResponsesUsage(usage),
|
|
4532
|
+
providerMetadata
|
|
4533
|
+
});
|
|
4534
|
+
}
|
|
4535
|
+
})),
|
|
4536
|
+
request: { body },
|
|
4537
|
+
response: { headers: responseHeaders }
|
|
4538
|
+
};
|
|
4539
|
+
}
|
|
4540
|
+
};
|
|
4541
|
+
function isTextDeltaChunk(chunk) {
|
|
4542
|
+
return chunk.type === "response.output_text.delta";
|
|
4543
|
+
}
|
|
4544
|
+
function isResponseOutputItemDoneChunk(chunk) {
|
|
4545
|
+
return chunk.type === "response.output_item.done";
|
|
4546
|
+
}
|
|
4547
|
+
function isResponseFinishedChunk(chunk) {
|
|
4548
|
+
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
4549
|
+
}
|
|
4550
|
+
function isResponseCreatedChunk(chunk) {
|
|
4551
|
+
return chunk.type === "response.created";
|
|
4552
|
+
}
|
|
4553
|
+
function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
4554
|
+
return chunk.type === "response.function_call_arguments.delta";
|
|
4555
|
+
}
|
|
4556
|
+
function isResponseCustomToolCallInputDeltaChunk(chunk) {
|
|
4557
|
+
return chunk.type === "response.custom_tool_call_input.delta";
|
|
4558
|
+
}
|
|
4559
|
+
function isResponseImageGenerationCallPartialImageChunk(chunk) {
|
|
4560
|
+
return chunk.type === "response.image_generation_call.partial_image";
|
|
4561
|
+
}
|
|
4562
|
+
function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
|
|
4563
|
+
return chunk.type === "response.code_interpreter_call_code.delta";
|
|
4564
|
+
}
|
|
4565
|
+
function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
|
|
4566
|
+
return chunk.type === "response.code_interpreter_call_code.done";
|
|
4567
|
+
}
|
|
4568
|
+
function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
|
|
4569
|
+
return chunk.type === "response.apply_patch_call_operation_diff.delta";
|
|
4570
|
+
}
|
|
4571
|
+
function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
|
|
4572
|
+
return chunk.type === "response.apply_patch_call_operation_diff.done";
|
|
4573
|
+
}
|
|
4574
|
+
function isResponseOutputItemAddedChunk(chunk) {
|
|
4575
|
+
return chunk.type === "response.output_item.added";
|
|
4576
|
+
}
|
|
4577
|
+
function isResponseAnnotationAddedChunk(chunk) {
|
|
4578
|
+
return chunk.type === "response.output_text.annotation.added";
|
|
4579
|
+
}
|
|
4580
|
+
function isErrorChunk(chunk) {
|
|
4581
|
+
return chunk.type === "error";
|
|
4582
|
+
}
|
|
4583
|
+
function mapWebSearchOutput(action) {
|
|
4584
|
+
var _a;
|
|
4585
|
+
if (action == null) return {};
|
|
4586
|
+
switch (action.type) {
|
|
4587
|
+
case "search": return {
|
|
4588
|
+
action: {
|
|
4589
|
+
type: "search",
|
|
4590
|
+
query: (_a = action.query) != null ? _a : void 0
|
|
4591
|
+
},
|
|
4592
|
+
...action.sources != null && { sources: action.sources }
|
|
4593
|
+
};
|
|
4594
|
+
case "open_page": return { action: {
|
|
4595
|
+
type: "openPage",
|
|
4596
|
+
url: action.url
|
|
4597
|
+
} };
|
|
4598
|
+
case "find_in_page": return { action: {
|
|
4599
|
+
type: "findInPage",
|
|
4600
|
+
url: action.url,
|
|
4601
|
+
pattern: action.pattern
|
|
4602
|
+
} };
|
|
4603
|
+
}
|
|
4604
|
+
}
|
|
4605
|
+
function escapeJSONDelta(delta) {
|
|
4606
|
+
return JSON.stringify(delta).slice(1, -1);
|
|
4607
|
+
}
|
|
4608
|
+
var openaiSpeechModelOptionsSchema = lazySchema(() => zodSchema(object({
|
|
4609
|
+
instructions: string().nullish(),
|
|
4610
|
+
speed: number$1().min(.25).max(4).default(1).nullish()
|
|
4611
|
+
})));
|
|
4612
|
+
var OpenAISpeechModel = class {
|
|
4613
|
+
constructor(modelId, config) {
|
|
4614
|
+
this.modelId = modelId;
|
|
4615
|
+
this.config = config;
|
|
4616
|
+
this.specificationVersion = "v3";
|
|
4617
|
+
}
|
|
4618
|
+
get provider() {
|
|
4619
|
+
return this.config.provider;
|
|
4620
|
+
}
|
|
4621
|
+
async getArgs({ text, voice = "alloy", outputFormat = "mp3", speed, instructions, language, providerOptions }) {
|
|
4622
|
+
const warnings = [];
|
|
4623
|
+
const openAIOptions = await parseProviderOptions({
|
|
4624
|
+
provider: "openai",
|
|
4625
|
+
providerOptions,
|
|
4626
|
+
schema: openaiSpeechModelOptionsSchema
|
|
4627
|
+
});
|
|
4628
|
+
const requestBody = {
|
|
4629
|
+
model: this.modelId,
|
|
4630
|
+
input: text,
|
|
4631
|
+
voice,
|
|
4632
|
+
response_format: "mp3",
|
|
4633
|
+
speed,
|
|
4634
|
+
instructions
|
|
4635
|
+
};
|
|
4636
|
+
if (outputFormat) if ([
|
|
4637
|
+
"mp3",
|
|
4638
|
+
"opus",
|
|
4639
|
+
"aac",
|
|
4640
|
+
"flac",
|
|
4641
|
+
"wav",
|
|
4642
|
+
"pcm"
|
|
4643
|
+
].includes(outputFormat)) requestBody.response_format = outputFormat;
|
|
4644
|
+
else warnings.push({
|
|
4645
|
+
type: "unsupported",
|
|
4646
|
+
feature: "outputFormat",
|
|
4647
|
+
details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
|
|
4648
|
+
});
|
|
4649
|
+
if (openAIOptions) {
|
|
4650
|
+
const speechModelOptions = {};
|
|
4651
|
+
for (const key in speechModelOptions) {
|
|
4652
|
+
const value = speechModelOptions[key];
|
|
4653
|
+
if (value !== void 0) requestBody[key] = value;
|
|
4654
|
+
}
|
|
4655
|
+
}
|
|
4656
|
+
if (language) warnings.push({
|
|
4657
|
+
type: "unsupported",
|
|
4658
|
+
feature: "language",
|
|
4659
|
+
details: `OpenAI speech models do not support language selection. Language parameter "${language}" was ignored.`
|
|
4660
|
+
});
|
|
4661
|
+
return {
|
|
4662
|
+
requestBody,
|
|
4663
|
+
warnings
|
|
4664
|
+
};
|
|
4665
|
+
}
|
|
4666
|
+
async doGenerate(options) {
|
|
4667
|
+
var _a, _b, _c;
|
|
4668
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4669
|
+
const { requestBody, warnings } = await this.getArgs(options);
|
|
4670
|
+
const { value: audio, responseHeaders, rawValue: rawResponse } = await postJsonToApi({
|
|
4671
|
+
url: this.config.url({
|
|
4672
|
+
path: "/audio/speech",
|
|
4673
|
+
modelId: this.modelId
|
|
4674
|
+
}),
|
|
4675
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
4676
|
+
body: requestBody,
|
|
4677
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
4678
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
4679
|
+
abortSignal: options.abortSignal,
|
|
4680
|
+
fetch: this.config.fetch
|
|
4681
|
+
});
|
|
4682
|
+
return {
|
|
4683
|
+
audio,
|
|
4684
|
+
warnings,
|
|
4685
|
+
request: { body: JSON.stringify(requestBody) },
|
|
4686
|
+
response: {
|
|
4687
|
+
timestamp: currentDate,
|
|
4688
|
+
modelId: this.modelId,
|
|
4689
|
+
headers: responseHeaders,
|
|
4690
|
+
body: rawResponse
|
|
4691
|
+
}
|
|
4692
|
+
};
|
|
4693
|
+
}
|
|
4694
|
+
};
|
|
4695
|
+
var openaiTranscriptionResponseSchema = lazySchema(() => zodSchema(object({
|
|
4696
|
+
text: string(),
|
|
4697
|
+
language: string().nullish(),
|
|
4698
|
+
duration: number$1().nullish(),
|
|
4699
|
+
words: array(object({
|
|
4700
|
+
word: string(),
|
|
4701
|
+
start: number$1(),
|
|
4702
|
+
end: number$1()
|
|
4703
|
+
})).nullish(),
|
|
4704
|
+
segments: array(object({
|
|
4705
|
+
id: number$1(),
|
|
4706
|
+
seek: number$1(),
|
|
4707
|
+
start: number$1(),
|
|
4708
|
+
end: number$1(),
|
|
4709
|
+
text: string(),
|
|
4710
|
+
tokens: array(number$1()),
|
|
4711
|
+
temperature: number$1(),
|
|
4712
|
+
avg_logprob: number$1(),
|
|
4713
|
+
compression_ratio: number$1(),
|
|
4714
|
+
no_speech_prob: number$1()
|
|
4715
|
+
})).nullish()
|
|
4716
|
+
})));
|
|
4717
|
+
var openAITranscriptionModelOptions = lazySchema(() => zodSchema(object({
|
|
4718
|
+
include: array(string()).optional(),
|
|
4719
|
+
language: string().optional(),
|
|
4720
|
+
prompt: string().optional(),
|
|
4721
|
+
temperature: number$1().min(0).max(1).default(0).optional(),
|
|
4722
|
+
timestampGranularities: array(_enum(["word", "segment"])).default(["segment"]).optional()
|
|
4723
|
+
})));
|
|
4724
|
+
var languageMap = {
|
|
4725
|
+
afrikaans: "af",
|
|
4726
|
+
arabic: "ar",
|
|
4727
|
+
armenian: "hy",
|
|
4728
|
+
azerbaijani: "az",
|
|
4729
|
+
belarusian: "be",
|
|
4730
|
+
bosnian: "bs",
|
|
4731
|
+
bulgarian: "bg",
|
|
4732
|
+
catalan: "ca",
|
|
4733
|
+
chinese: "zh",
|
|
4734
|
+
croatian: "hr",
|
|
4735
|
+
czech: "cs",
|
|
4736
|
+
danish: "da",
|
|
4737
|
+
dutch: "nl",
|
|
4738
|
+
english: "en",
|
|
4739
|
+
estonian: "et",
|
|
4740
|
+
finnish: "fi",
|
|
4741
|
+
french: "fr",
|
|
4742
|
+
galician: "gl",
|
|
4743
|
+
german: "de",
|
|
4744
|
+
greek: "el",
|
|
4745
|
+
hebrew: "he",
|
|
4746
|
+
hindi: "hi",
|
|
4747
|
+
hungarian: "hu",
|
|
4748
|
+
icelandic: "is",
|
|
4749
|
+
indonesian: "id",
|
|
4750
|
+
italian: "it",
|
|
4751
|
+
japanese: "ja",
|
|
4752
|
+
kannada: "kn",
|
|
4753
|
+
kazakh: "kk",
|
|
4754
|
+
korean: "ko",
|
|
4755
|
+
latvian: "lv",
|
|
4756
|
+
lithuanian: "lt",
|
|
4757
|
+
macedonian: "mk",
|
|
4758
|
+
malay: "ms",
|
|
4759
|
+
marathi: "mr",
|
|
4760
|
+
maori: "mi",
|
|
4761
|
+
nepali: "ne",
|
|
4762
|
+
norwegian: "no",
|
|
4763
|
+
persian: "fa",
|
|
4764
|
+
polish: "pl",
|
|
4765
|
+
portuguese: "pt",
|
|
4766
|
+
romanian: "ro",
|
|
4767
|
+
russian: "ru",
|
|
4768
|
+
serbian: "sr",
|
|
4769
|
+
slovak: "sk",
|
|
4770
|
+
slovenian: "sl",
|
|
4771
|
+
spanish: "es",
|
|
4772
|
+
swahili: "sw",
|
|
4773
|
+
swedish: "sv",
|
|
4774
|
+
tagalog: "tl",
|
|
4775
|
+
tamil: "ta",
|
|
4776
|
+
thai: "th",
|
|
4777
|
+
turkish: "tr",
|
|
4778
|
+
ukrainian: "uk",
|
|
4779
|
+
urdu: "ur",
|
|
4780
|
+
vietnamese: "vi",
|
|
4781
|
+
welsh: "cy"
|
|
4782
|
+
};
|
|
4783
|
+
var OpenAITranscriptionModel = class {
|
|
4784
|
+
constructor(modelId, config) {
|
|
4785
|
+
this.modelId = modelId;
|
|
4786
|
+
this.config = config;
|
|
4787
|
+
this.specificationVersion = "v3";
|
|
4788
|
+
}
|
|
4789
|
+
get provider() {
|
|
4790
|
+
return this.config.provider;
|
|
4791
|
+
}
|
|
4792
|
+
async getArgs({ audio, mediaType, providerOptions }) {
|
|
4793
|
+
const warnings = [];
|
|
4794
|
+
const openAIOptions = await parseProviderOptions({
|
|
4795
|
+
provider: "openai",
|
|
4796
|
+
providerOptions,
|
|
4797
|
+
schema: openAITranscriptionModelOptions
|
|
4798
|
+
});
|
|
4799
|
+
const formData = new FormData();
|
|
4800
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
4801
|
+
formData.append("model", this.modelId);
|
|
4802
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
4803
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }), `audio.${fileExtension}`);
|
|
4804
|
+
if (openAIOptions) {
|
|
4805
|
+
const transcriptionModelOptions = {
|
|
4806
|
+
include: openAIOptions.include,
|
|
4807
|
+
language: openAIOptions.language,
|
|
4808
|
+
prompt: openAIOptions.prompt,
|
|
4809
|
+
response_format: ["gpt-4o-transcribe", "gpt-4o-mini-transcribe"].includes(this.modelId) ? "json" : "verbose_json",
|
|
4810
|
+
temperature: openAIOptions.temperature,
|
|
4811
|
+
timestamp_granularities: openAIOptions.timestampGranularities
|
|
4812
|
+
};
|
|
4813
|
+
for (const [key, value] of Object.entries(transcriptionModelOptions)) if (value != null) if (Array.isArray(value)) for (const item of value) formData.append(`${key}[]`, String(item));
|
|
4814
|
+
else formData.append(key, String(value));
|
|
4815
|
+
}
|
|
4816
|
+
return {
|
|
4817
|
+
formData,
|
|
4818
|
+
warnings
|
|
4819
|
+
};
|
|
4820
|
+
}
|
|
4821
|
+
async doGenerate(options) {
|
|
4822
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4823
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4824
|
+
const { formData, warnings } = await this.getArgs(options);
|
|
4825
|
+
const { value: response, responseHeaders, rawValue: rawResponse } = await postFormDataToApi({
|
|
4826
|
+
url: this.config.url({
|
|
4827
|
+
path: "/audio/transcriptions",
|
|
4828
|
+
modelId: this.modelId
|
|
4829
|
+
}),
|
|
4830
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
4831
|
+
formData,
|
|
4832
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
4833
|
+
successfulResponseHandler: createJsonResponseHandler(openaiTranscriptionResponseSchema),
|
|
4834
|
+
abortSignal: options.abortSignal,
|
|
4835
|
+
fetch: this.config.fetch
|
|
4836
|
+
});
|
|
4837
|
+
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
4838
|
+
return {
|
|
4839
|
+
text: response.text,
|
|
4840
|
+
segments: (_g = (_f = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
|
|
4841
|
+
text: segment.text,
|
|
4842
|
+
startSecond: segment.start,
|
|
4843
|
+
endSecond: segment.end
|
|
4844
|
+
}))) != null ? _f : (_e = response.words) == null ? void 0 : _e.map((word) => ({
|
|
4845
|
+
text: word.word,
|
|
4846
|
+
startSecond: word.start,
|
|
4847
|
+
endSecond: word.end
|
|
4848
|
+
}))) != null ? _g : [],
|
|
4849
|
+
language,
|
|
4850
|
+
durationInSeconds: (_h = response.duration) != null ? _h : void 0,
|
|
4851
|
+
warnings,
|
|
4852
|
+
response: {
|
|
4853
|
+
timestamp: currentDate,
|
|
4854
|
+
modelId: this.modelId,
|
|
4855
|
+
headers: responseHeaders,
|
|
4856
|
+
body: rawResponse
|
|
4857
|
+
}
|
|
4858
|
+
};
|
|
4859
|
+
}
|
|
4860
|
+
};
|
|
4861
|
+
var VERSION = "3.0.41";
|
|
4862
|
+
function createOpenAI(options = {}) {
|
|
4863
|
+
var _a, _b;
|
|
4864
|
+
const baseURL = (_a = withoutTrailingSlash(loadOptionalSetting({
|
|
4865
|
+
settingValue: options.baseURL,
|
|
4866
|
+
environmentVariableName: "OPENAI_BASE_URL"
|
|
4867
|
+
}))) != null ? _a : "https://api.openai.com/v1";
|
|
4868
|
+
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
4869
|
+
const getHeaders = () => withUserAgentSuffix({
|
|
4870
|
+
Authorization: `Bearer ${loadApiKey({
|
|
4871
|
+
apiKey: options.apiKey,
|
|
4872
|
+
environmentVariableName: "OPENAI_API_KEY",
|
|
4873
|
+
description: "OpenAI"
|
|
4874
|
+
})}`,
|
|
4875
|
+
"OpenAI-Organization": options.organization,
|
|
4876
|
+
"OpenAI-Project": options.project,
|
|
4877
|
+
...options.headers
|
|
4878
|
+
}, `ai-sdk/openai/${VERSION}`);
|
|
4879
|
+
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
|
4880
|
+
provider: `${providerName}.chat`,
|
|
4881
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
4882
|
+
headers: getHeaders,
|
|
4883
|
+
fetch: options.fetch
|
|
4884
|
+
});
|
|
4885
|
+
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
4886
|
+
provider: `${providerName}.completion`,
|
|
4887
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
4888
|
+
headers: getHeaders,
|
|
4889
|
+
fetch: options.fetch
|
|
4890
|
+
});
|
|
4891
|
+
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
4892
|
+
provider: `${providerName}.embedding`,
|
|
4893
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
4894
|
+
headers: getHeaders,
|
|
4895
|
+
fetch: options.fetch
|
|
4896
|
+
});
|
|
4897
|
+
const createImageModel = (modelId) => new OpenAIImageModel(modelId, {
|
|
4898
|
+
provider: `${providerName}.image`,
|
|
4899
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
4900
|
+
headers: getHeaders,
|
|
4901
|
+
fetch: options.fetch
|
|
4902
|
+
});
|
|
4903
|
+
const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
|
|
4904
|
+
provider: `${providerName}.transcription`,
|
|
4905
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
4906
|
+
headers: getHeaders,
|
|
4907
|
+
fetch: options.fetch
|
|
4908
|
+
});
|
|
4909
|
+
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
4910
|
+
provider: `${providerName}.speech`,
|
|
4911
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
4912
|
+
headers: getHeaders,
|
|
4913
|
+
fetch: options.fetch
|
|
4914
|
+
});
|
|
4915
|
+
const createLanguageModel = (modelId) => {
|
|
4916
|
+
if (new.target) throw new Error("The OpenAI model function cannot be called with the new keyword.");
|
|
4917
|
+
return createResponsesModel(modelId);
|
|
4918
|
+
};
|
|
4919
|
+
const createResponsesModel = (modelId) => {
|
|
4920
|
+
return new OpenAIResponsesLanguageModel(modelId, {
|
|
4921
|
+
provider: `${providerName}.responses`,
|
|
4922
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
4923
|
+
headers: getHeaders,
|
|
4924
|
+
fetch: options.fetch,
|
|
4925
|
+
fileIdPrefixes: ["file-"]
|
|
4926
|
+
});
|
|
4927
|
+
};
|
|
4928
|
+
const provider = function(modelId) {
|
|
4929
|
+
return createLanguageModel(modelId);
|
|
4930
|
+
};
|
|
4931
|
+
provider.specificationVersion = "v3";
|
|
4932
|
+
provider.languageModel = createLanguageModel;
|
|
4933
|
+
provider.chat = createChatModel;
|
|
4934
|
+
provider.completion = createCompletionModel;
|
|
4935
|
+
provider.responses = createResponsesModel;
|
|
4936
|
+
provider.embedding = createEmbeddingModel;
|
|
4937
|
+
provider.embeddingModel = createEmbeddingModel;
|
|
4938
|
+
provider.textEmbedding = createEmbeddingModel;
|
|
4939
|
+
provider.textEmbeddingModel = createEmbeddingModel;
|
|
4940
|
+
provider.image = createImageModel;
|
|
4941
|
+
provider.imageModel = createImageModel;
|
|
4942
|
+
provider.transcription = createTranscriptionModel;
|
|
4943
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
4944
|
+
provider.speech = createSpeechModel;
|
|
4945
|
+
provider.speechModel = createSpeechModel;
|
|
4946
|
+
provider.tools = openaiTools;
|
|
4947
|
+
return provider;
|
|
4948
|
+
}
|
|
4949
|
+
createOpenAI();
|
|
4950
|
+
//#endregion
|
|
4951
|
+
export { createOpenAI as t };
|